-
Notifications
You must be signed in to change notification settings - Fork 712
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
- Add external FIPS 140-2 / 140-3 compliant signatures for the Clam Databases. #1344
Changes from 1 commit
d233429
d64161d
e6d93ef
bc057fe
90ed3bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2013-2024 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
* Copyright (C) 2011-2013 Sourcefire, Inc. | ||
* | ||
* Authors: aCaB | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef __CRYPTO_H | ||
#define __CRYPTO_H | ||
#include <openssl/opensslv.h> | ||
|
||
void cli_setup_fips_configuration(void); | ||
int cli_get_fips_mode(void); | ||
|
||
#if OPENSSL_VERSION_MAJOR == 1 | ||
RSA *cli_build_ext_signing_key(void); | ||
#elif OPENSSL_VERSION_MAJOR == 3 | ||
EVP_PKEY *cli_build_ext_signing_key(void); | ||
#else | ||
#error "Unsupported OpenSSL version" | ||
Check failure on line 34 in libclamav/crypto.h GitHub Actions / build-windows
|
||
#endif | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,13 @@ | |
#include "others.h" | ||
#include "dsig.h" | ||
#include "str.h" | ||
#include "crypto.h" | ||
#include "cvd.h" | ||
#include "readdb.h" | ||
#include "default.h" | ||
|
||
#include <openssl/rsa.h> | ||
|
||
#define TAR_BLOCKSIZE 512 | ||
|
||
static void cli_untgz_cleanup(char *path, gzFile infile, FILE *outfile, int fdd) | ||
|
@@ -627,6 +630,14 @@ cl_error_t cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, | |
|
||
cli_dbgmsg("in cli_cvdload()\n"); | ||
|
||
// FIPS verification MUST preclude other verification if in FIPS mode. | ||
if (cli_get_fips_mode()) { | ||
ret = cli_sigver_external(filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call should not be guarded by cli_fips_mode, external signature file should be preferred if present. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I concur. If we're going to add a better way to validate signing, it should be preferred. We should only fallback to the legacy signature verification if A. the new-style signature is not present and B. not FIPS-mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than adding comments all over the code to this extent. Every place that guards the validation/fetching of the external signature file with cli_fips_mode should be removed so that the new format is the default and only trusted signature in versions that support it. |
||
if (ret != CL_SUCCESS) { | ||
return ret; | ||
} | ||
} | ||
|
||
/* verify */ | ||
if ((ret = cli_cvdverify(fs, &cvd, dbtype))) | ||
return ret; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this PR is much bigger than #959, but this section of code appears to be the same as that PR. Is this introducing the same issues as that, and would this have the same potential memory leak mentioned on that PR? I didn't see any added calls to EVP_MD_free in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi David! So per the OpenSSL documentation, we don't really need to worry about freeing this. The first element of the OpenSSL documentation I want to cite is:
So, we're really dealing with a reference count. While this means it's not really an issue, I also like to be tidy with reference counts, but that leads to the second section of documentation I wanted to highlight:
So, we should free when using EVP_MD_fetch. However we also have:
So, now we do not have to free when using EVP_get_digestbyname. Terribly confusing. That said, I've added the logic to free according to the documentation. Please see the updated commit.
I also added ECC secp521r1 support for NIST Approved Elliptical Curve signing, as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I appreciate the detailed explanation. I agree, that documentation seems inconsistent with itself.