Commit graph

30 commits

Author SHA1 Message Date
Valerie Snyder
8e1fb0009b
Tests: clamscan --fips-limits for CVD loading
Add test to ensure CVD loading fails with --fips-limits flag unless you
provide the .cvd.sign file.

Also provide .sign files in freshclam tests because they'll be needed to
pass if building in a fips-enabled environment.
2025-08-14 22:40:45 -04:00
rma-x
0e5d12295e
Tests: Fix freshclam test race condition
There is a race condition in the freshclam tests that triggers when the next server
starts quicker than the previous one exits after signaling it asynchronously.

This fix waits for the mockup server process to exit before moving on.

Resolves: https://github.com/Cisco-Talos/clamav/issues/1512
2025-05-30 14:06:00 -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
e06cf177e7
Tests: remove unused Python modules from freshclam tests
The 'cgi' module is deprecrated and will be removed in Python 3.13.
We weren't using it anyways.

Fixes: https://github.com/Cisco-Talos/clamav/issues/1327
2024-08-28 15:09:12 -04:00
Micah Snyder
9cb28e51e6 Bump copyright dates for 2024 2024-01-22 11:27:17 -05:00
RainRat
1b17e20571
Fix typos (no functional changes) 2024-01-19 09:08:36 -08:00
RainRat
caf324e544
Fix typos (no functional changes) 2023-11-26 18:01:19 -05:00
Arjen de Korte
629c018f0a
Tests: Bypass issue checking debug message in freshclam test
Somehow the LOGG_DEBUG-level message used to verify correct behavior
in one of the freshclam tests is not written to stdout when testing
on some Fedora systems.

This commit changes the test to verify correct behavior by checking
for a different message that is LOGG_INFO-level, and is consistently
written to stdout.

Further investigation required to find out why debug messages aren't
always written to stdout.
2023-04-21 14:41:16 -07:00
Micah Snyder
66dbaf3720 Tests: Add sigtool tests for correct CDIFF UNLINK functionality
Also includes:
- A sigtool test to verify that Rust log macros are working.
- Changing the freshclam tests to use --no-dns so they run faster
  when DNS isn't working (e.g. no internet).
2023-04-17 11:48:07 -07:00
Micah Snyder
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
Micah Snyder
9e257950f0 Test: Add test for incremental update twice in a row
This is a regression test to ensure that freshclam can update from a CVD
to a CLD, and then update from the CLD to a (newer) CLD.
2022-11-04 15:47:37 -07:00
Micah Snyder
a9bb5e37a5 Correct stdout/stderr expectations for freshclam tests
Improvements to the logg() API appear to have corrected a bug wherein
debug/warning/error messages were writing to stdout instead of stderr.

Now that they're going to stderr correctly, this fixes the test to match.
2022-02-23 16:32:26 -07:00
micasnyd
140c88aa4e Bump copyright for 2022
Includes minor format corrections.
2022-01-09 14:23:25 -07:00
krnick
656f4da6f6 Tests: Hoist repeated code outside if statement 2021-11-22 16:35:47 -08:00
Micah Snyder
985f0e9d7c test: extend freshclam 403 test to test cool-down
Extends the existing freshclam 403 test to check if a repeated freshclam
403 response outputs the cool-down message instead of the original 403
response message.
2021-10-29 19:34:01 -07:00
Micah Snyder
7b77717b40 test: freshclam cdiff test tuning
There is a bug where freshclam fails to detect if a downloaded CDIFF is
empty. In 0.103 this, combined with a CDN caching issue could result in
freshclam downloading a daily.cvd but failing to update, putting it in a
sort of infinite loop. In 0.104 this issue manifests slightly
differently, requiring freshclam to run up to 3x before you get over the
empty-CVD hump and are back to normal updates.

This commit updates an existing cdiff test with the zero-byte cdiff + an
out-of-date CVD to confirm the bug. The following commit will fix it.
2021-10-07 17:40:42 -07:00
Micah Snyder
8cfaf5f5f6 Test: CDIFF update with UNC paths (Windows)
This is a regression test for https://github.com/Cisco-Talos/clamav/pull/226
2021-08-16 12:10:11 -07:00
Micah Snyder
8557bc7a65 Test: python 3.5 compatibility fix
Python 3.5 compatibility fixes for Debian 9, etc that lack 3.6+.

Change a python f-string to an old-style `"".format()`.

Convert Path objects to strings for older `shutil` APIs that don't
accept Paths.
2021-07-17 15:27:36 -07:00
Micah Snyder
201e1b12a7 XOR test files; clean up tests directory
The split test files are flagged by some AV's because they look like
broken executables. Instead of splitting the test files to prevent
detections, we should encrypt them. This commit replaces the "reassemble
testfiles" script with a basic "XOR testfiles" script that can be used
to encrypt or decrypt test files. This commit also of course then
replaces all the split files with xor'ed files.

The test and unit_tests directories were a bit of a mess, so I
reorganized them all into unit_tests with all of the test files placed
under "unit_tests/input" using subdirectories for different types of files.
2021-07-17 10:39:27 -07:00
Micah Snyder
ee8a62baf7 Test: freshclam w/ zero-byte cdiff & cvd out-of-date
Add a test where freshclam received a zero-byte cdiff to trigger a whole
CVD database download, and the CVD served is older than advertised.

This is a regression test for a bug found & fixed by Andrew Williams.
2021-06-23 18:28:23 -04:00
Micah Snyder
cbe60b30b0 Test: Basic freshclam CDIFF tests
Adds 3 tests to validate that:

1. a CDIFF update works

2. a CDIFF partial update (with 1 missing CDIFF) works
   and that a subsequent update is ok with being 1 behind

3. a CDIFF partial update (with 2 missing CDIFFs) works
   and that a subsequent update will try to get the WHOLE CVD -
   because being 2+ CDIFFs behind without any update isn't good enough.

Also fixed a minor bug so that the database name is properly displayed
when a partial update occurs instead of displaying "(null)".

Also changed the freshclam test port to 8001 to deconflict with
CVD-Update, in case that's running in the background.

TODO: Make the tests smarter so they find an open port instead of
hoping that 8001 is available.
2021-06-22 18:56:01 -07:00
Micah Snyder
535867e12f FreshClam: rename mirrors.dat to freshclam.dat
Some users have scripts set up from long ago to delete mirrors.dat if
FreshClam failed. We used to recommend this if people had technical
issues because mirrors.dat would store a bunch of entries indicating
that all of their regional mirrors were failing and then FreshClam would
give up.

The new freshclam DAT file no longer stores that kind of information.
Deleting the DAT file is no longer sound advice.
We very much want the UUID, which is generated when creating the DAT
file, to persist between runs. So unless people go and change the
scripts to delete freshclam.dat instead, this commit should resolve the
concern.
2021-06-01 18:19:12 -07:00
Micah Snyder (micasnyd)
4f51994fad FreshClam: Fix tests, configs for IPv6-only systems
Some config settings and some tests hardcoded 127.0.0.1. This switches
to localhost, they'll work for systems that don't support IPv4.
2021-05-27 16:52:58 -07:00
Micah Snyder
6039c8956d Tests: Enable freshclam tests to pass as root
If you test in a docker container and don't create a user/switch to run
as something other than root, than the tests will fail.

Default freshclam behavior is to drop to run as the "clamav" user when
run as root. This change sets the DatabaseOwner to the current user, so
it the tests will pass when run as root.
2021-05-19 14:20:59 -07:00
Micah Snyder
62ad885315 Tests: fix python warnings in freshclam tests
The WebServerHandler classes used for the tests have a "Test_" prefix
which causes pytest to print some warnings thinking they're special test
classes. This commit gets rid of the warnings.
2021-05-11 15:36:22 -07:00
Micah Snyder
46fd3f631a FreshClam: Error handling fixes per code review 2021-04-05 12:29:03 -07:00
Micah Snyder
24d83f43b0 Test: freshclam 429 and 403 behavior
When running ctest, Windows users may be prompted to allow the freshclam
test to access the network, so that it can host the mock database
mirror.
2021-04-05 12:29:02 -07:00
Micah Snyder
4759e4b3d3 ctest: Support Python 3.5
Python 3.6 is not available on Debian 9 and other older LTS releases.
This patch removes use of Python f-strings which were introduced in
Python 3.6 so as to support Python 3.5.

TODO: Revert this commit when Debian 9 dies or gets f-string support
(whichver comes first).
2021-02-25 11:41:28 -08:00
Micah Snyder
2552cfd0d1 CMake: Add CTest support to match Autotools checks
An ENABLE_TESTS CMake option is provided so that users can disable
testing if they don't want it. Instructions for how to use this
included in the INSTALL.cmake.md file.

If you run `ctest`, each testcase will write out a log file to the
<build>/unit_tests directory.

As with Autotools' make check, the test files are from test/.split
and unit_tests/.split files, but for CMake these are generated at
build time instead of at test time.

On Posix systems, sets the LD_LIBRARY_PATH so that ClamAV-compiled
libraries can be loaded when running tests.

On Windows systems, CTest will identify and collect all library
dependencies and assemble a temporarily install under the
build/unit_tests directory so that the libraries can be loaded when
running tests.

The same feature is used on Windows when using CMake to install to
collect all DLL dependencies so that users don't have to install them
manually afterwards.

Each of the CTest tests are run using a custom wrapper around Python's
unittest framework, which is also responsible for finding and inserting
valgrind into the valgrind tests on Posix systems.

Unlike with Autotools, the CMake CTest Valgrind-tests are enabled by
default, if Valgrind can be found. There's no need to set VG=1.
CTest's memcheck module is NOT supported, because we use Python to
orchestrate our tests.

Added a bunch of Windows compatibility changes to the unit tests.
These were primarily changing / to PATHSEP and making adjustments
to use Win32 C headers and ifdef out the POSIX ones which aren't
available on Windows. Also disabled a bunch of tests on Win32
that don't work on Windows, notably the mmap ones and FD-passing
(i.e. FILEDES) ones.

Add JSON_C_HAVE_INTTYPES_H definition to clamav-config.h to eliminate
warnings on Windows where json.h is included after inttypes.h because
json-c's inttypes replacement relies on it.
This is a it of a hack and may be removed if json-c fixes their
inttypes header stuff in the future.

Add preprocessor definitions on Windows to disable MSVC warnings about
CRT secure and nonstandard functions. While there may be a better
solution, this is needed to be able to see other more serious warnings.

Add missing file comment block and copyright statement for clamsubmit.c.
Also change json-c/json.h include filename to json.h in clamsubmit.c.
The directory name is not required.

Changed the hash table data integer type from long, which is poorly
defined, to size_t -- which is capable of storing a pointer. Fixed a
bunch of casts regarding this variable to eliminate warnings.

Fixed two bugs causing utf8 encoding unit tests to fail on Windows:
- The in_size variable should be the number of bytes, not the character
  count. This was was causing the SHIFT_JIS (japanese codepage) to UTF8
  transcoding test to only transcode half the bytes.
- It turns out that the MultiByteToWideChar() API can't transcode
  UTF16-BE to UTF16-LE. The solution is to just iterate over the buffer
  and flip the bytes on each uint16_t. This but was causing the UTF16-BE
  to UTF8 tests to fail.

I also split up the utf8 transcoding tests into separate tests so I
could see all of the failures instead of just the first one.

Added a flags parameter to the unit test function to open testfiles
because it turns out that on Windows if a file contains the \r\n it will
replace it with just \n if you opened the file as a text file instead of
as binary. However, if we open the CBC files as binary, then a bunch of
bytecode tests fail. So I've changed the tests to open the CBC files in
the bytecode tests as text files and open all other files as binary.

Ported the feature tests from shell scripts to Python using a modified
version of our QA test-framework, which is largely compatible and will
allow us to migrate some QA tests into this repo. I'd like to add GitHub
Actions pipelines in the future so that all public PR's get some testing
before anyone has to manually review them.

The clamd --log option was missing from the help string, though it
definitely works. I've added it in this commit.
It appears that clamd.c was never clang-format'd, so this commit also
reformats clamd.c.

Some of the check_clamd tests expected the path returned by clamd to
match character for character with original path sent to clamd. However,
as we now evaluate real paths before a scan, the path returned by clamd
isn't going to match the relative (and possibly symlink-ridden) path
passed to clamdscan. I fixed this test by changing the test to search
for the basename: <signature> FOUND within the response instead of
matching the exact path.

Autotools: Link check_clamd with libclamav so we can use our utility
functions in check_clamd.c.
2021-02-25 11:41:26 -08:00