Skip to content

Commit

Permalink
Fixed verification issues and added test sign files
Browse files Browse the repository at this point in the history
  • Loading branch information
micahsnyder committed Dec 10, 2024
1 parent dc6eace commit f46ce45
Show file tree
Hide file tree
Showing 28 changed files with 600 additions and 202 deletions.
36 changes: 25 additions & 11 deletions clamd/clamd.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ int main(int argc, char **argv)
pid_t mainpid = 0;
mode_t old_umask = 0;
const char *user_name = NULL;
char *cvdcertsdir = NULL;
STATBUF statbuf;

if (check_flevel())
exit(1);
Expand Down Expand Up @@ -577,20 +579,32 @@ int main(int argc, char **argv)
}
}

if ((opt = optget(opts, "certsdir"))->enabled) {
if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, opt->strarg))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));
ret = 1;
break;
}
} else {
if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, CERTSDIR))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));
ret = 1;
break;
cvdcertsdir = optget(opts, "cvdcertsdir")->strarg;
if (NULL == cvdcertsdir) {
// Check if the CVD_CERTS_DIR environment variable is set
cvdcertsdir = getenv("CVD_CERTS_DIR");

// If not, use the default value
if (NULL == cvdcertsdir) {
cvdcertsdir = CERTSDIR;
}
}

if (LSTAT(cvdcertsdir, &statbuf) == -1) {
logg(LOGG_ERROR,
"ClamAV CA certificates directory is missing: %s\n"
"It should have been provided as a part of installation.",
cvdcertsdir);
ret = 1;
break;
}

if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, cvdcertsdir))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));
ret = 1;
break;
}

cl_engine_set_clcb_hash(engine, hash_callback);

cl_engine_set_clcb_virus_found(engine, clamd_virus_found_cb);
Expand Down
4 changes: 4 additions & 0 deletions clamscan/clamscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ void help(void)
mprintf(LOGG_INFO, " --pcre-recmatch-limit=#n Maximum recursive calls to the PCRE match function.\n");
mprintf(LOGG_INFO, " --pcre-max-filesize=#n Maximum size file to perform PCRE subsig matching.\n");
mprintf(LOGG_INFO, " --disable-cache Disable caching and cache checks for hash sums of scanned files.\n");
mprintf(LOGG_INFO, " --cvdcertsdir=DIRECTORY Specify a directory containing the root\n");
mprintf(LOGG_INFO, " CA cert needed to verify detached CVD digital signatures.\n");
mprintf(LOGG_INFO, " If not provided, then clamscan will look in:\n");
mprintf(LOGG_INFO, " " CERTSDIR "\n");
mprintf(LOGG_INFO, "\n");
mprintf(LOGG_INFO, "Pass in - as the filename for stdin.\n");
mprintf(LOGG_INFO, "\n");
Expand Down
37 changes: 26 additions & 11 deletions clamscan/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ int scanmanager(const struct optstruct *opts)
struct engine_free_progress engine_free_progress_ctx = {0};
#endif

char *cvdcertsdir = NULL;
STATBUF statbuf;

/* Initialize scan options struct */
memset(&options, 0, sizeof(struct cl_scan_options));

Expand Down Expand Up @@ -1249,20 +1252,32 @@ int scanmanager(const struct optstruct *opts)
}
}

if ((opt = optget(opts, "certsdir"))->enabled) {
if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, opt->strarg))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));
cvdcertsdir = optget(opts, "cvdcertsdir")->strarg;
if (NULL == cvdcertsdir) {
// Check if the CVD_CERTS_DIR environment variable is set
cvdcertsdir = getenv("CVD_CERTS_DIR");

ret = 2;
goto done;
// If not, use the default value
if (NULL == cvdcertsdir) {
cvdcertsdir = CERTSDIR;
}
} else {
if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, CERTSDIR))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));
}

ret = 2;
goto done;
}
if (LSTAT(cvdcertsdir, &statbuf) == -1) {
logg(LOGG_ERROR,
"ClamAV CA certificates directory is missing: %s\n"
"It should have been provided as a part of installation.",
cvdcertsdir);

ret = 2;
goto done;
}

if ((ret = cl_engine_set_str(engine, CL_ENGINE_CERTSDIR, cvdcertsdir))) {
logg(LOGG_ERROR, "cli_engine_set_str(CL_ENGINE_CERTSDIR) failed: %s\n", cl_strerror(ret));

ret = 2;
goto done;
}

if ((opt = optget(opts, "database"))->active) {
Expand Down
2 changes: 1 addition & 1 deletion common/optparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const struct clam_option __clam_options[] = {

{"DatabaseDirectory", "datadir", 0, CLOPT_TYPE_STRING, NULL, -1, CONST_DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_SIGTOOL, "This option allows you to change the default database directory.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/var/lib/clamav"},

{"CVDCertsDirectory", "certsdir", 0, CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_SIGTOOL, "This option allows you to change the default ClamAV CA certificates directory used to verify database external digital signatures.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/etc/clamav/certs"},
{"CVDCertsDirectory", "cvdcertsdir", 0, CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN | OPT_FRESHCLAM | OPT_SIGTOOL, "This option allows you to change the default ClamAV CA certificates directory used to verify database external digital signatures.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/etc/clamav/certs"},

{"OfficialDatabaseOnly", "official-db-only", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN, "Only load the official signatures published by the ClamAV project.", "no"},

Expand Down
14 changes: 14 additions & 0 deletions etc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ if(ENABLE_MILTER)
${APP_CONFIG_DIRECTORY}
COMPONENT programs)
endif()

#
# clamav certs directory and root CA cert
#

# Create the certs directory. This is where the root CA cert will be installed.
# Then copy the root CA cert to the certs directory.
install(DIRECTORY DESTINATION ${CERTS_DIRECTORY} COMPONENT programs)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/certs/ca.crt
DESTINATION
${CERTS_DIRECTORY}
COMPONENT programs)
31 changes: 31 additions & 0 deletions etc/certs/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFTzCCAzcCFG9bzRiWhD7GrtKN5++v9AZJaJ0sMA0GCSqGSIb3DQEBCwUAMGQx
CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNRDEPMA0GA1UEBwwGTGF1cmVsMQ4wDAYD
VQQKDAVDaXNjbzEOMAwGA1UECwwFVGFsb3MxFzAVBgNVBAMMDkNsYW1BViBSb290
IENBMB4XDTI0MTAyNDE3MjcyNVoXDTI2MTAyNDE3MjcyNVowZDELMAkGA1UEBhMC
VVMxCzAJBgNVBAgMAk1EMQ8wDQYDVQQHDAZMYXVyZWwxDjAMBgNVBAoMBUNpc2Nv
MQ4wDAYDVQQLDAVUYWxvczEXMBUGA1UEAwwOQ2xhbUFWIFJvb3QgQ0EwggIiMA0G
CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDNp2WpxPv42Of3yiFUA8Bq6OiPDtjO
bBfPcffqcx1rtsjlgsyXPLr709+ktjdPOrlOAmkuZXUnWeQ6VMltxfUiz0uzMOpV
WR8tEQSaGLR4CBdEe8srnojB7Uwx0x8BEWzROUBBlXdDJjTteEomLduXYaRxoXc3
S0qxIFx4jL4lfgj1uA8GCdT7oLdWK1gmmc6yijmZyLygh02b660vz8t8pTFp6dWC
zktl4IpnYenktF5mtldfORtdJsBK6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sQOOHAefzTM+Zig0ip6yL
qEHRtMbqcYAb8QKzRh7OoVgENrZgtKPbM/RmmXyxCDaj4p8yGsT2wVgekTYgZgs/
571h1ecLkL4h0vaq5BtDjW/Drg==
-----END CERTIFICATE-----
11 changes: 10 additions & 1 deletion freshclam/freshclam.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,16 @@ static fc_error_t initialize(struct optstruct *opts)
* Verify that the clamav ca certificates directory exists.
* Create certs directory if missing.
*/
fcConfig.certsDirectory = optget(opts, "certsdir")->strarg;
fcConfig.certsDirectory = optget(opts, "cvdcertsdir")->strarg;
if (NULL == fcConfig.certsDirectory) {
// Check if the CVD_CERTS_DIR environment variable is set
fcConfig.certsDirectory = getenv("CVD_CERTS_DIR");

// If not, use the default value
if (NULL == fcConfig.certsDirectory) {
fcConfig.certsDirectory = CERTSDIR;
}
}

if (LSTAT(fcConfig.certsDirectory, &statbuf) == -1) {
logg(LOGG_ERROR,
Expand Down
Loading

0 comments on commit f46ce45

Please sign in to comment.