Commit graph

34 commits

Author SHA1 Message Date
Valerie Snyder
13c4788f36
FIPS & FIPS-like limits on hash algs for cryptographic uses
ClamAV will not function when using a FIPS-enabled OpenSSL 3.x.
This is because ClamAV uses MD5 and SHA1 algorithms for a variety of
purposes including matching for malware detection, matching to prevent
false positives on known-clean files, and for verification of MD5-based
RSA digital signatures for determining CVD (signature database archive)
authenticity.

Interestingly, FIPS had been intentionally bypassed when creating hashes
based whole buffers and whole files (by descriptor or `FILE`-pointer):
78d4a9985a
Note: this bypassed FIPS the 1.x way with:
`EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);`

It was NOT disabled when using `cl_hash_init()` / `cl_update_hash()` /
`cl_finish_hash()`. That likely worked by coincidence in that the hash
was already calculated most of the time. It certainly would have made
use of those functions if the hash had not been calculated prior:
78d4a9985a/libclamav/matcher.c (L743)

Regardless, bypassing FIPS entirely is not the correct solution.
The FIPS restrictions against using MD5 and SHA1 are valid, particularly
when verifying CVD digital siganatures, but also I think when using a
hash to determine if the file is known-clean (i.e. the "clean cache" and
also MD5-based and SHA1-based FP signatures).

This commit extends the work to bypass FIPS using the newer 3.x method:
`md = EVP_MD_fetch(NULL, alg, "-fips");`

It does this for the legacy `cl_hash*()` functions including
`cl_hash_init()` / `cl_update_hash()` / `cl_finish_hash()`.
It also introduces extended versions that allow the caller to choose if
they want to bypass FIPS:
- `cl_hash_data_ex()`
- `cl_hash_init_ex()`
- `cl_update_hash_ex()`
- `cl_finish_hash_ex()`
- `cl_hash_destroy_ex()`
- `cl_hash_file_fd_ex()`
See the `flags` parameter for each.

Ironically, this commit does NOT use the new functions at this time.
The rational is that ClamAV may need MD5, SHA1, and SHA-256 hashes of
the same files both for determining if the file is malware, and for
determining if the file is clean.

So instead, this commit will do a checks when:

1. Creating a new ClamAV scanning engine. If FIPS-mode enabled, it will
   automatically toggle the "FIPS limits" engine option.
   When loading signatures, if the engine "FIPS limits" option is enabled,
   then MD5 and SHA1 FP signatures will be skipped.

2. Before verifying a CVD (e.g. also for loading, unpacking when
   verification enabled).
   If "FIPS limits" or FIPS-mode are enabled, then the legacy MD5-based RSA
   method is disabled.

   Note: This commit also refactors the interface for `cl_cvdverify_ex()`
   and `cl_cvdunpack_ex()` so they take a `flags` parameters, rather than a
   single `bool`. As these functions are new in this version, it does not
   break the ABI.

The cache was already switched to use SHA2-256, so that's not a concern
for checking FIPS-mode / FIPS limits options.

This adds an option for `freshclam.conf` and `clamd.conf`:

   FIPSCryptoHashLimits yes

And an equivalent command-line option for `clamscan` and `sigtool`:

   --fips-limits

You may programmatically enable FIPS-limits for a ClamAV engine like this:
```C
   cl_engine_set_num(engine, CL_ENGINE_FIPS_LIMITS, 1);
```

CLAM-2792
2025-08-14 22:39:15 -04:00
Val Snyder
8d485b9bfd
FIPS-compliant CVD signing and verification
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: https://github.com/Cisco-Talos/clamav/issues/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: https://github.com/Cisco-Talos/clamav/issues/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: https://github.com/Cisco-Talos/clamav/issues/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'.
2025-03-26 19:33:25 -04:00
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Micah Snyder
9cb28e51e6 Bump copyright dates for 2024 2024-01-22 11:27:17 -05:00
Micah Snyder
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
Micah Snyder
8340e55660 Tests: unit tests for cl_load(), cl_cvdverify(), cl_cvdunpack()
Some basic testing is needed for the new cl_cvdunpack() API, so this
commit adds basic unit tests for that.

For reasons unknown, a number of cl_* API's have stubs for unit tests
that weren't filled out.  The CVD load/verify ones in particular
required access to a signed CVD.  We actually ship a very basic signed
CVD with the databases now, so I added tests for those while I was at it.
2022-10-12 21:46:54 -07:00
Micah Snyder
54b69ec431 Freshclam, Sigtool: use public CVD unpack API
In the interest of using the public API's as much as possible for our
own applications (dog-fooding the API), this commit swaps sigtool and
freshclam `cli_cvdunpack()` calls to `cl_cvdunpack()`.
2022-10-12 21:46:54 -07:00
micasnyd
140c88aa4e Bump copyright for 2022
Includes minor format corrections.
2022-01-09 14:23:25 -07:00
Micah Snyder (micasnyd)
b9ca6ea103 Update copyright dates for 2021
Also fixes up clang-format.
2021-03-19 15:12:26 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
6289eda8e0 Eliminating AUTHORS file, and moving acknowledgements for various source code contributions to the file comment blocks for the individual files, as appropriate. 2018-03-06 17:44:05 -05:00
Micah Snyder
14e2247bd2 updating the copyright for a number of tiles. 2017-08-09 14:28:47 -04:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Shawn Webb
da6e06dd68 Provide further abstractions to the OpenSSL integration work 2014-02-28 12:12:30 -05:00
Shawn Webb
a1cbd793f3 Fix all memory leaks introduce by OpenSSL backport. 2014-02-12 17:42:48 -05:00
Shawn Webb
7fb5036fb2 Make Valgrind happy. Rely less on EVP_MD_CTX_create. 2014-02-08 01:42:41 -05:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
Török Edvin
3afedd0761 fix GCC warnings.
especially the one about gzFile vs gzFile*, gzopen returns gzFile!
2012-05-30 13:37:32 +03:00
Tomasz Kojm
cdddd014ff sigtool: add support for building unsigned dbs (--unsigned)
libclamav: handle unsigned db files (.cud)
2011-05-10 21:29:49 +02:00
Tomasz Kojm
f820268196 freshclam: detect and fix corruptions of existing db files 2011-01-17 19:06:57 +01:00
Tomasz Kojm
02e46f3fdb libclamav: avoid loading duplicate databases (bb#1962) 2010-04-22 18:04:01 +02:00
Tomasz Kojm
de351ee1bc libclamav: handle digitally signed .info files 2010-01-25 13:28:19 +01:00
Török Edvin
be43f951c6 BytecodeSecurity setting. 2010-01-22 16:50:35 +02:00
Tomasz Kojm
ace26bfe08 libclamav: check .info files while loading CVD/CLD 2010-01-20 22:10:56 +01:00
Tomasz Kojm
a6a9845602 libclamav: improve loading speed of compressed databases (bb#1105) 2009-07-28 20:23:31 +02:00
Tomasz Kojm
afff80efb9 libclamav, shared: minor cleanups; fix handling of long file names (bb#1349)
git-svn: trunk@4670
2009-02-03 18:47:18 +00:00
Tomasz Kojm
15850fc6d4 simplify the code; don't free 'engine'
git-svn-id: file:///var/lib/svn/clamav-devel/branches/newapi@4380 77e5149b-7576-45b1-b177-96237e5ba77b
2008-11-11 21:23:34 +00:00
Tomasz Kojm
ac1b219cf1 libclamav, clamd: always return correct db version in VERSION (bb#1168)
git-svn: trunk@4332
2008-11-04 18:45:48 +00:00
Tomasz Kojm
e8ae4fae02 faster loading of uncompressed .cld files
git-svn: trunk@3854
2008-05-18 21:32:27 +00:00
Tomasz Kojm
2023340a41 update copyrights and stick more files to GPLv2; move and add more credits to the AUTHORS file; add COPYING.BSD
git-svn: trunk@3749
2008-04-02 15:24:51 +00:00
Tomasz Kojm
9d193ff26c add support for .cld containers
git-svn: trunk@3444
2007-12-19 22:06:32 +00:00
Tomasz Kojm
bb34cb31fe update some copyrights and stick to GPL v2
git-svn: trunk@3003
2007-03-31 20:31:04 +00:00
Sven Strickroth
a99111f050 remove old CVS-stuff and make the repository look more like SVN
git-svn: trunk@2755
2007-02-17 19:02:20 +00:00
Renamed from clamav-devel/libclamav/cvd.h (Browse further)