|
|
bf760f |
diff -up openssl-3.0.0/providers/fips/self_test.c.embed-hmac openssl-3.0.0/providers/fips/self_test.c
|
|
|
bf760f |
--- openssl-3.0.0/providers/fips/self_test.c.embed-hmac 2021-11-16 13:57:05.127171056 +0100
|
|
|
bf760f |
+++ openssl-3.0.0/providers/fips/self_test.c 2021-11-16 14:07:21.963412455 +0100
|
|
|
bf760f |
@@ -171,11 +171,27 @@ DEP_FINI_ATTRIBUTE void cleanup(void)
|
|
|
bf760f |
}
|
|
|
bf760f |
#endif
|
|
|
bf760f |
|
|
|
bf760f |
+#define HMAC_LEN 32
|
|
|
bf760f |
+/*
|
|
|
bf760f |
+ * The __attribute__ ensures we've created the .rodata1 section
|
|
|
bf760f |
+ * static ensures it's zero filled
|
|
|
bf760f |
+*/
|
|
|
bf760f |
+static const unsigned char __attribute__ ((section (".rodata1"))) fips_hmac_container[HMAC_LEN] = {0};
|
|
|
bf760f |
+
|
|
|
bf760f |
/*
|
|
|
bf760f |
* Calculate the HMAC SHA256 of data read using a BIO and read_cb, and verify
|
|
|
bf760f |
* the result matches the expected value.
|
|
|
bf760f |
* Return 1 if verified, or 0 if it fails.
|
|
|
bf760f |
*/
|
|
|
bf760f |
+#ifndef __USE_GNU
|
|
|
bf760f |
+#define __USE_GNU
|
|
|
bf760f |
+#include <dlfcn.h>
|
|
|
bf760f |
+#undef __USE_GNU
|
|
|
bf760f |
+#else
|
|
|
bf760f |
+#include <dlfcn.h>
|
|
|
bf760f |
+#endif
|
|
|
bf760f |
+#include <link.h>
|
|
|
bf760f |
+
|
|
|
bf760f |
static int verify_integrity(OSSL_CORE_BIO *bio, OSSL_FUNC_BIO_read_ex_fn read_ex_cb,
|
|
|
bf760f |
unsigned char *expected, size_t expected_len,
|
|
|
bf760f |
OSSL_LIB_CTX *libctx, OSSL_SELF_TEST *ev,
|
|
|
bf760f |
@@ -183,14 +199,26 @@ static int verify_integrity(OSSL_CORE_BI
|
|
|
bf760f |
{
|
|
|
bf760f |
int ret = 0, status;
|
|
|
bf760f |
unsigned char out[MAX_MD_SIZE];
|
|
|
bf760f |
- unsigned char buf[INTEGRITY_BUF_SIZE];
|
|
|
bf760f |
+ unsigned char buf[INTEGRITY_BUF_SIZE+HMAC_LEN];
|
|
|
bf760f |
size_t bytes_read = 0, out_len = 0;
|
|
|
bf760f |
EVP_MAC *mac = NULL;
|
|
|
bf760f |
EVP_MAC_CTX *ctx = NULL;
|
|
|
bf760f |
OSSL_PARAM params[2], *p = params;
|
|
|
bf760f |
+ Dl_info info;
|
|
|
bf760f |
+ void *extra_info = NULL;
|
|
|
bf760f |
+ struct link_map *lm = NULL;
|
|
|
bf760f |
+ unsigned long paddr;
|
|
|
bf760f |
+ unsigned long off = 0;
|
|
|
bf760f |
+ int have_rest = 0;
|
|
|
bf760f |
|
|
|
bf760f |
OSSL_SELF_TEST_onbegin(ev, event_type, OSSL_SELF_TEST_DESC_INTEGRITY_HMAC);
|
|
|
bf760f |
|
|
|
bf760f |
+ if (!dladdr1 ((const void *)fips_hmac_container,
|
|
|
bf760f |
+ &info, &extra_info, RTLD_DL_LINKMAP))
|
|
|
bf760f |
+ goto err;
|
|
|
bf760f |
+ lm = extra_info;
|
|
|
bf760f |
+ paddr = (unsigned long)fips_hmac_container - lm->l_addr;
|
|
|
bf760f |
+
|
|
|
bf760f |
mac = EVP_MAC_fetch(libctx, MAC_NAME, NULL);
|
|
|
bf760f |
if (mac == NULL)
|
|
|
bf760f |
goto err;
|
|
|
bf760f |
@@ -204,12 +233,53 @@ static int verify_integrity(OSSL_CORE_BI
|
|
|
bf760f |
if (!EVP_MAC_init(ctx, fixed_key, sizeof(fixed_key), params))
|
|
|
bf760f |
goto err;
|
|
|
bf760f |
|
|
|
bf760f |
+ status = read_ex_cb(bio, buf, HMAC_LEN, &bytes_read);
|
|
|
bf760f |
+ if (status != 1 || bytes_read != HMAC_LEN)
|
|
|
bf760f |
+ goto err;
|
|
|
bf760f |
+ off += HMAC_LEN;
|
|
|
bf760f |
+
|
|
|
bf760f |
while (1) {
|
|
|
bf760f |
- status = read_ex_cb(bio, buf, sizeof(buf), &bytes_read);
|
|
|
bf760f |
- if (status != 1)
|
|
|
bf760f |
+ status = read_ex_cb(bio, buf+HMAC_LEN, INTEGRITY_BUF_SIZE, &bytes_read);
|
|
|
bf760f |
+ if (status != 1) {
|
|
|
bf760f |
+ have_rest = 1;
|
|
|
bf760f |
+ break;
|
|
|
bf760f |
+ }
|
|
|
bf760f |
+
|
|
|
bf760f |
+ if (bytes_read == INTEGRITY_BUF_SIZE) { /* Full block */
|
|
|
bf760f |
+ /* Logic:
|
|
|
bf760f |
+ * We have HMAC_LEN (read before) + INTEGRITY_BUF_SIZE (read now) in buffer
|
|
|
bf760f |
+ * We calculate HMAC from first INTEGRITY_BUF_SIZE bytes
|
|
|
bf760f |
+ * and move last HMAC_LEN bytes to the beginning of the buffer
|
|
|
bf760f |
+ *
|
|
|
bf760f |
+ * If we have read (a part of) buffer fips_hmac_container
|
|
|
bf760f |
+ * we should replace it with zeros.
|
|
|
bf760f |
+ * If it is inside our current buffer, we will update now.
|
|
|
bf760f |
+ * If it intersects the upper bound, we will clean up on the next step.
|
|
|
bf760f |
+ */
|
|
|
bf760f |
+ if (off - HMAC_LEN <= paddr && paddr <= off + bytes_read)
|
|
|
bf760f |
+ memset (buf + HMAC_LEN + paddr - off, 0, HMAC_LEN);
|
|
|
bf760f |
+ off += bytes_read;
|
|
|
bf760f |
+
|
|
|
bf760f |
+ if (!EVP_MAC_update(ctx, buf, bytes_read))
|
|
|
bf760f |
+ goto err;
|
|
|
bf760f |
+ memcpy (buf, buf+INTEGRITY_BUF_SIZE, HMAC_LEN);
|
|
|
bf760f |
+ } else { /* Final block */
|
|
|
bf760f |
+ /* Logic is basically the same as in previous branch
|
|
|
bf760f |
+ * but we calculate HMAC from HMAC_LEN (rest of previous step)
|
|
|
bf760f |
+ * and bytes_read read on this step
|
|
|
bf760f |
+ * */
|
|
|
bf760f |
+ if (off - HMAC_LEN <= paddr && paddr <= off + bytes_read)
|
|
|
bf760f |
+ memset (buf + HMAC_LEN + paddr - off, 0, HMAC_LEN);
|
|
|
bf760f |
+ if (!EVP_MAC_update(ctx, buf, bytes_read+HMAC_LEN))
|
|
|
bf760f |
+ goto err;
|
|
|
bf760f |
+ off += bytes_read;
|
|
|
bf760f |
break;
|
|
|
bf760f |
- if (!EVP_MAC_update(ctx, buf, bytes_read))
|
|
|
bf760f |
+ }
|
|
|
bf760f |
+ }
|
|
|
bf760f |
+ if (have_rest) {
|
|
|
bf760f |
+ if (!EVP_MAC_update(ctx, buf, HMAC_LEN))
|
|
|
bf760f |
goto err;
|
|
|
bf760f |
+ off += HMAC_LEN;
|
|
|
bf760f |
}
|
|
|
bf760f |
if (!EVP_MAC_final(ctx, out, &out_len, sizeof(out)))
|
|
|
bf760f |
goto err;
|
|
|
bf760f |
@@ -284,8 +358,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS
|
|
|
bf760f |
CRYPTO_THREAD_unlock(fips_state_lock);
|
|
|
bf760f |
}
|
|
|
bf760f |
|
|
|
bf760f |
- if (st == NULL
|
|
|
bf760f |
- || st->module_checksum_data == NULL) {
|
|
|
bf760f |
+ if (st == NULL) {
|
|
|
bf760f |
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_CONFIG_DATA);
|
|
|
bf760f |
goto end;
|
|
|
bf760f |
}
|
|
|
bf760f |
@@ -294,8 +367,9 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS
|
|
|
bf760f |
if (ev == NULL)
|
|
|
bf760f |
goto end;
|
|
|
bf760f |
|
|
|
bf760f |
- module_checksum = OPENSSL_hexstr2buf(st->module_checksum_data,
|
|
|
bf760f |
- &checksum_len);
|
|
|
bf760f |
+ module_checksum = fips_hmac_container;
|
|
|
bf760f |
+ checksum_len = sizeof(fips_hmac_container);
|
|
|
bf760f |
+
|
|
|
bf760f |
if (module_checksum == NULL) {
|
|
|
bf760f |
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CONFIG_DATA);
|
|
|
bf760f |
goto end;
|
|
|
bf760f |
@@ -357,7 +431,6 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS
|
|
|
bf760f |
ok = 1;
|
|
|
bf760f |
end:
|
|
|
bf760f |
OSSL_SELF_TEST_free(ev);
|
|
|
bf760f |
- OPENSSL_free(module_checksum);
|
|
|
bf760f |
OPENSSL_free(indicator_checksum);
|
|
|
bf760f |
|
|
|
bf760f |
if (st != NULL) {
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/00-prep_fipsmodule_cnf.t openssl-3.0.0-xxx/test/recipes/00-prep_fipsmodule_cnf.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/00-prep_fipsmodule_cnf.t 2021-09-07 13:46:32.000000000 +0200
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/00-prep_fipsmodule_cnf.t 2021-11-18 09:39:53.386817874 +0100
|
|
|
bf760f |
@@ -20,7 +20,7 @@
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
use platform;
|
|
|
bf760f |
|
|
|
bf760f |
-my $no_check = disabled("fips");
|
|
|
bf760f |
+my $no_check = 1;
|
|
|
bf760f |
plan skip_all => "FIPS module config file only supported in a fips build"
|
|
|
bf760f |
if $no_check;
|
|
|
bf760f |
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/01-test_fipsmodule_cnf.t openssl-3.0.0-xxx/test/recipes/01-test_fipsmodule_cnf.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/01-test_fipsmodule_cnf.t 2021-09-07 13:46:32.000000000 +0200
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/01-test_fipsmodule_cnf.t 2021-11-18 09:59:02.315619486 +0100
|
|
|
bf760f |
@@ -23,7 +23,7 @@
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
use platform;
|
|
|
bf760f |
|
|
|
bf760f |
-my $no_check = disabled("fips");
|
|
|
bf760f |
+my $no_check = 1;
|
|
|
bf760f |
plan skip_all => "Test only supported in a fips build"
|
|
|
bf760f |
if $no_check;
|
|
|
bf760f |
plan tests => 1;
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/03-test_fipsinstall.t openssl-3.0.0-xxx/test/recipes/03-test_fipsinstall.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/03-test_fipsinstall.t 2021-09-07 13:46:32.000000000 +0200
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/03-test_fipsinstall.t 2021-11-18 09:59:55.365072074 +0100
|
|
|
bf760f |
@@ -22,7 +22,7 @@
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
use platform;
|
|
|
bf760f |
|
|
|
bf760f |
-plan skip_all => "Test only supported in a fips build" if disabled("fips");
|
|
|
bf760f |
+plan skip_all => "Test only supported in a fips build" if 1;
|
|
|
bf760f |
|
|
|
bf760f |
plan tests => 29;
|
|
|
bf760f |
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/30-test_defltfips.t openssl-3.0.0-xxx/test/recipes/30-test_defltfips.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/30-test_defltfips.t 2021-09-07 13:46:32.000000000 +0200
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/30-test_defltfips.t 2021-11-18 10:22:54.179659682 +0100
|
|
|
bf760f |
@@ -21,7 +21,7 @@
|
|
|
bf760f |
use lib srctop_dir('Configurations');
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
|
|
|
bf760f |
-my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
+my $no_fips = 1; #disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
|
|
|
bf760f |
plan tests =>
|
|
|
bf760f |
($no_fips ? 1 : 5);
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/80-test_ssl_new.t openssl-3.0.0-xxx/test/recipes/80-test_ssl_new.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/80-test_ssl_new.t 2021-09-07 13:46:32.000000000 +0200
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/80-test_ssl_new.t 2021-11-18 10:18:53.391721164 +0100
|
|
|
bf760f |
@@ -23,7 +23,7 @@
|
|
|
bf760f |
use lib srctop_dir('Configurations');
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
|
|
|
bf760f |
-my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
+my $no_fips = 1; #disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
|
|
|
bf760f |
$ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs");
|
|
|
bf760f |
|
|
|
bf760f |
diff -ruN openssl-3.0.0/test/recipes/90-test_sslapi.t openssl-3.0.0-xxx/test/recipes/90-test_sslapi.t
|
|
|
bf760f |
--- openssl-3.0.0/test/recipes/90-test_sslapi.t 2021-11-18 10:32:17.734196705 +0100
|
|
|
bf760f |
+++ openssl-3.0.0-xxx/test/recipes/90-test_sslapi.t 2021-11-18 10:18:30.695538445 +0100
|
|
|
bf760f |
@@ -18,7 +18,7 @@
|
|
|
bf760f |
use lib srctop_dir('Configurations');
|
|
|
bf760f |
use lib bldtop_dir('.');
|
|
|
bf760f |
|
|
|
bf760f |
-my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
+my $no_fips = 1; #disabled('fips') || ($ENV{NO_FIPS} // 0);
|
|
|
bf760f |
|
|
|
bf760f |
plan skip_all => "No TLS/SSL protocols are supported by this OpenSSL build"
|
|
|
bf760f |
if alldisabled(grep { $_ ne "ssl3" } available_protocols("tls"));
|
|
|
bf760f |
--- /dev/null 2021-11-16 15:27:32.915000000 +0100
|
|
|
bf760f |
+++ openssl-3.0.0/test/fipsmodule.cnf 2021-11-18 11:15:34.538060408 +0100
|
|
|
bf760f |
@@ -0,0 +1,2 @@
|
|
|
bf760f |
+[fips_sect]
|
|
|
bf760f |
+activate = 1
|