Blame SOURCES/0033-FIPS-embed-hmac.patch

3da501
diff -up openssl-3.0.7/providers/fips/self_test.c.embed-hmac openssl-3.0.7/providers/fips/self_test.c
3da501
--- openssl-3.0.7/providers/fips/self_test.c.embed-hmac	2023-01-05 10:03:44.864869710 +0100
3da501
+++ openssl-3.0.7/providers/fips/self_test.c	2023-01-05 10:15:17.041606472 +0100
3da501
@@ -172,11 +172,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,
3da501
@@ -189,9 +205,20 @@ static int verify_integrity(OSSL_CORE_BI
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
 
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;
3da501
@@ -205,13 +233,42 @@ static int verify_integrity(OSSL_CORE_BI
bf760f
     if (!EVP_MAC_init(ctx, fixed_key, sizeof(fixed_key), params))
bf760f
         goto err;
bf760f
 
3da501
-    while (1) {
bf760f
-        status = read_ex_cb(bio, buf, sizeof(buf), &bytes_read);
3da501
+    while ((off + INTEGRITY_BUF_SIZE) <= paddr) {
3da501
+        status = read_ex_cb(bio, buf, INTEGRITY_BUF_SIZE, &bytes_read);
3da501
         if (status != 1)
bf760f
             break;
3da501
         if (!EVP_MAC_update(ctx, buf, bytes_read))
bf760f
             goto err;
3da501
+	off += bytes_read;
bf760f
     }
3da501
+
3da501
+    if (off + INTEGRITY_BUF_SIZE > paddr) {
3da501
+        int delta = paddr - off;
3da501
+        status = read_ex_cb(bio, buf, delta, &bytes_read);
3da501
+        if (status != 1)
3da501
+            goto err;
3da501
+        if (!EVP_MAC_update(ctx, buf, bytes_read))
3da501
+            goto err;
3da501
+	off += bytes_read;
3da501
+
3da501
+        status = read_ex_cb(bio, buf, HMAC_LEN, &bytes_read);
3da501
+        memset(buf, 0, HMAC_LEN);
3da501
+        if (status != 1)
3da501
+            goto err;
3da501
+        if (!EVP_MAC_update(ctx, buf, bytes_read))
3da501
+            goto err;
3da501
+	off += bytes_read;
3da501
+    }
3da501
+
3da501
+    while (bytes_read > 0) {
3da501
+        status = read_ex_cb(bio, buf, INTEGRITY_BUF_SIZE, &bytes_read);
3da501
+        if (status != 1)
3da501
+            break;
3da501
+        if (!EVP_MAC_update(ctx, buf, bytes_read))
3da501
+            goto err;
3da501
+	off += bytes_read;
3da501
+    }
3da501
+
bf760f
     if (!EVP_MAC_final(ctx, out, &out_len, sizeof(out)))
bf760f
         goto err;
3da501
 
3da501
@@ -285,8 +342,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
     }
3da501
@@ -305,8 +361,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;
3da501
@@ -356,7 +413,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