Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clam 2677 2678 FIPS compliant CVD codesigning #1417

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

val-ms
Copy link
Contributor

@val-ms val-ms commented Dec 11, 2024

Add FIPS-compliant CVD signing and verification.

This change bears similarities to #1344, adding external code signing signature files (.cvd.sign) to accompany existing .cvd databases.

The .sign take a form similar to other clamav signatures where comment lines start with a # and all other lines are signatures. Each signature line takes the form:

min_flevel : max_flevel (optional) : sig_format : public_key_fingerprint : signature_text

min_flevel:  the minimum flevel required to support the signature format.
max_flevel:  the maximum flevel supporting the signature format. This is optional, and may be empty. 
signature_format:  for the initial implementation, it must be: "pkcs7-pem".
signature_text:  must be printable ascii with no new lines. If "sig_format" is "pkcs7-pem" it is the base64 encoded part of the a PEM signature (aka header and footer removed) with all new-lines removed. if additional formats are added, this field would be used to store things like the hash of the file, the algorithm, plus any other required signing details. 

Adds X509 certificate chain based signing with PKCS7-PEM external signatures distributed alongside CVD's in a custom .cvd.sign format.

Adds a Rust implementation for parsing, verifying, and unpacking CVD files.

Now installs a 'certs' directory in the app config directory (e.g. /etc/certs). The install location is configurable.
The CMake option to configure the CVD certs directory is:
-D CVD_CERTS_DIRECTORY=PATH

New options to set an alternative CVD certs directory:

  • Commandline for freshclam, clamd, clamscan, and sigtool is:
    --cvdcertsdir PATH
  • Env variable for freshclam, clamd, clamscan, and sigtool is:
    CVD_CERTS_DIR
  • Config option for freshclam and clamd is:
    CVDCertsDirectory PATH

Sigtool:

  • Add sign/verify commands.
  • Also verify CDIFF external digital signatures when applying CDIFFs.
  • Place commonly used commands at the top of --help string.
  • Fix up manpage.

Freshclam:

  • Will try to download .sign files to verify CVDs and CDIFFs.
  • Fix an issue where making a CLD would only include the CFG file for daily and not if patching any other database.

libclamav.so:

  • Bump version to 13:0:1 (aka 12.1.0).
  • Also remove libclamav.map versioning.
    Resolves: libclamav.map: Remove CLAMAV_1.0.0…CLAMAV_0.104.0 #1304
  • Add two new API's to the public clamav.h header:
    extern cl_error_t cl_cvdverify_ex(const char *file,
                                      const char *certs_directory);
    
    extern cl_error_t cl_cvdunpack_ex(const char *file,
                                      const char *dir,
                                      bool dont_verify,
                                      const char *certs_directory);
    The original cl_cvdverify and cl_cvdunpack are deprecated.
  • Add cl_engine_field enum option CL_ENGINE_CVDCERTSDIR.
    You may set this option with cl_engine_set_str and get it with cl_engine_get_str, to override the compiled in default CVD certs directory.

libfreshclam.so: Bump version to 4:0:0 (aka 4.0.0).

Adds sigtool sign/verify tests and test certs.

Make it so downloadFile doesn't throw a warning if the server doesn't have the .sign file.

Replace use of md5-based FP signatures in the unit tests with sha256-based FP signatures because the md5 implementation used by Python may be disabled in FIPS mode.

Fixes: #564
Fixes: #1411

Replaces: #1344

}

/* For actual .cvd files, verify the digital signature. */
if (dbtype == CVD_TYPE_CVD) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also check this for CUD? Probably. This would be a case where database is not signed with old MD5-RSA, and only signed with external PKCS7 sig.

if (!cvd_verify(
cvd,
engine->certs_directory,
false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider if we want to make a config or commandline option to disable the older md5-based RSA checks, or simply let it fail if FIPS is enabled and the cert-based method doesn't work/isn't available.

I think it's okay either way.

@val-ms
Copy link
Contributor Author

val-ms commented Dec 17, 2024

sigtool --sign: After debug-logging the certs for the cert stack, should info-print:

  • cert Serial
  • CommonName
  • the issuer commonName (if an issuer exists)

@val-ms
Copy link
Contributor Author

val-ms commented Dec 17, 2024

For verifying,

  1. Load all ca certs from the ca certs directory into the x509 store and put the x509 store into the Verifier.

  2. The Verifier should be stored in the cl_engine.

Edit: done.

@val-ms val-ms marked this pull request as ready for review January 2, 2025 15:13
@val-ms val-ms changed the title Work in progress: Clam 2677 2678 codesigning Clam 2677 2678 FIPS compliant CVD codesigning Jan 2, 2025
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from b371edd to 587862b Compare January 2, 2025 15:32
@rsundriyal rsundriyal self-requested a review January 10, 2025 15:41
rsundriyal
rsundriyal previously approved these changes Jan 10, 2025
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch 2 times, most recently from ecb0010 to d5e6d20 Compare January 19, 2025 20:18
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from baf2d07 to 52f7df5 Compare February 18, 2025 03:09
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from 62d6d94 to 7cc5197 Compare February 26, 2025 20:19
@val-ms val-ms changed the base branch from main to CLAM-2726-1.5-beta March 24, 2025 22:13
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from 7cc5197 to 49f248d Compare March 25, 2025 15:00
@val-ms val-ms changed the base branch from CLAM-2726-1.5-beta to main March 25, 2025 23:53
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch 2 times, most recently from b20dcd4 to b75134f Compare March 26, 2025 23:28
Add X509 certificate chain based signing with PKCS7-PEM external
signatures distributed alongside CVD's in a custom .cvd.sign format.
This new signing and verification mechanism is primarily in support
of FIPS compliance.

Fixes: Cisco-Talos#564

Add a Rust implementation for parsing, verifying, and unpacking CVD
files.

Now installs a 'certs' directory in the app config directory
(e.g. <prefix>/etc/certs). The install location is configurable.
The CMake option to configure the CVD certs directory is:
  `-D CVD_CERTS_DIRECTORY=PATH`

New options to set an alternative CVD certs directory:
- Commandline for freshclam, clamd, clamscan, and sigtool is:
  `--cvdcertsdir PATH`
- Env variable for freshclam, clamd, clamscan, and sigtool is:
  `CVD_CERTS_DIR`
- Config option for freshclam and clamd is:
  `CVDCertsDirectory PATH`

Sigtool:
- Add sign/verify commands.
- Also verify CDIFF external digital signatures when applying CDIFFs.
- Place commonly used commands at the top of --help string.
- Fix up manpage.

Freshclam:
- Will try to download .sign files to verify CVDs and CDIFFs.
- Fix an issue where making a CLD would only include the CFG file for
daily and not if patching any other database.

libclamav.so:
- Bump version to 13:0:1 (aka 12.1.0).
- Also remove libclamav.map versioning.
  Resolves: Cisco-Talos#1304
- Add two new API's to the public clamav.h header:
  ```c
  extern cl_error_t cl_cvdverify_ex(const char *file,
                                    const char *certs_directory);

  extern cl_error_t cl_cvdunpack_ex(const char *file,
                                    const char *dir,
                                    bool dont_verify,
                                    const char *certs_directory);
  ```
  The original `cl_cvdverify` and `cl_cvdunpack` are deprecated.
- Add `cl_engine_field` enum option `CL_ENGINE_CVDCERTSDIR`.
  You may set this option with `cl_engine_set_str` and get it
  with `cl_engine_get_str`, to override the compiled in default
  CVD certs directory.

libfreshclam.so: Bump version to 4:0:0 (aka 4.0.0).

Add sigtool sign/verify tests and test certs.

Make it so downloadFile doesn't throw a warning if the server
doesn't have the .sign file.

Replace use of md5-based FP signatures in the unit tests with
sha256-based FP signatures because the md5 implementation used
by Python may be disabled in FIPS mode.
Fixes: Cisco-Talos#1411

CMake: Add logic to enable the Rust openssl-sys / openssl-rs crates
to build against the same OpenSSL library as is used for the C build.
The Rust unit test application must also link directly with libcrypto
and libssl.

Fix some log messages with missing new lines.

Fix missing environment variable notes in --help messages and manpages.

Deconflict CONFDIR/DATADIR/CERTSDIR variable names that are defined in
clamav-config.h.in for libclamav from variable that had the same name
for use in clamav applications that use the optparser.

The 'clamav-test' certs for the unit tests will live for 10 years.
The 'clamav-beta.crt' public cert will only live for 120 days and will
be replaced before the stable release with a production 'clamav.crt'.
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from b75134f to 6619062 Compare March 26, 2025 23:55
@val-ms val-ms force-pushed the CLAM-2677-2678-codesigning branch from 6619062 to 272e84e Compare March 27, 2025 00:00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidating out-of-date version markers seems clear, but shouldn't CLAMAV_PUBLIC remain? Maybe moved to new line 71?

Copy link
Contributor Author

@val-ms val-ms Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does remain (it's line 1). You're looking at the equivalent of html closing tag (a la </CLAMAV_PUBLIC>).

Ref: how we used to do it back in 0.103 https://github.com/Cisco-Talos/clamav/blob/rel/0.103/libclamav/libclamav.map

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just a bookend to line 1. Nevermind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for beta, will be root CA only for release.

@val-ms val-ms merged commit 1b32e8d into Cisco-Talos:main Mar 28, 2025
22 of 24 checks passed
@val-ms val-ms deleted the CLAM-2677-2678-codesigning branch March 28, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants