Blame SOURCES/openssl-1.1.1-disable-fips.patch

97bb94
Disable FIPS mode
97bb94
97bb94
FIPS mode is not supported for compat-openssl11. Apply a minimal patch
97bb94
that will reject explicit enabling of FIPS mode and disable automatic
97bb94
activation of FIPS mode.
97bb94
97bb94
To avoid regressions, keep the rest of the library as it was.
97bb94
97bb94
diff -up openssl-1.1.1k/crypto/fips/fips.c.disable-fips openssl-1.1.1k/crypto/fips/fips.c
97bb94
--- openssl-1.1.1k/crypto/fips/fips.c.disable-fips	2022-05-30 17:05:28.604500582 +0200
97bb94
+++ openssl-1.1.1k/crypto/fips/fips.c	2022-05-30 17:09:46.129110042 +0200
97bb94
@@ -405,13 +405,8 @@ static int verify_checksums(void)
97bb94
 
97bb94
 int FIPS_module_installed(void)
97bb94
 {
97bb94
-    int rv;
97bb94
-    rv = access(FIPS_MODULE_PATH, F_OK);
97bb94
-    if (rv < 0 && errno != ENOENT)
97bb94
-        rv = 0;
97bb94
-
97bb94
     /* Installed == true */
97bb94
-    return !rv || FIPS_module_mode();
97bb94
+    return 0;
97bb94
 }
97bb94
 
97bb94
 int FIPS_module_mode_set(int onoff)
97bb94
diff -up openssl-1.1.1k/crypto/o_fips.c.disable-fips openssl-1.1.1k/crypto/o_fips.c
97bb94
--- openssl-1.1.1k/crypto/o_fips.c.disable-fips	2022-05-30 17:05:37.411658179 +0200
97bb94
+++ openssl-1.1.1k/crypto/o_fips.c	2022-05-30 17:06:25.279514707 +0200
97bb94
@@ -12,24 +12,14 @@
97bb94
 
97bb94
 int FIPS_mode(void)
97bb94
 {
97bb94
-#ifdef OPENSSL_FIPS
97bb94
-    return FIPS_module_mode();
97bb94
-#else
97bb94
     /* This version of the library does not support FIPS mode. */
97bb94
     return 0;
97bb94
-#endif
97bb94
 }
97bb94
 
97bb94
 int FIPS_mode_set(int r)
97bb94
 {
97bb94
-#ifdef OPENSSL_FIPS
97bb94
-    if (r && FIPS_module_mode()) /* can be implicitly initialized by OPENSSL_init() */
97bb94
-        return 1;
97bb94
-    return FIPS_module_mode_set(r);
97bb94
-#else
97bb94
     if (r == 0)
97bb94
         return 1;
97bb94
     CRYPTOerr(CRYPTO_F_FIPS_MODE_SET, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED);
97bb94
     return 0;
97bb94
-#endif
97bb94
 }
97bb94
diff -up openssl-1.1.1k/crypto/o_init.c.disable-fips openssl-1.1.1k/crypto/o_init.c
97bb94
--- openssl-1.1.1k/crypto/o_init.c.disable-fips	2022-05-30 17:06:58.250104676 +0200
97bb94
+++ openssl-1.1.1k/crypto/o_init.c	2022-05-30 17:17:12.369135344 +0200
97bb94
@@ -7,55 +7,9 @@
97bb94
  * https://www.openssl.org/source/license.html
97bb94
  */
97bb94
 
97bb94
-/* for secure_getenv */
97bb94
-#define _GNU_SOURCE
97bb94
 #include "e_os.h"
97bb94
 #include <openssl/err.h>
97bb94
 #ifdef OPENSSL_FIPS
97bb94
-# include <sys/types.h>
97bb94
-# include <sys/stat.h>
97bb94
-# include <fcntl.h>
97bb94
-# include <unistd.h>
97bb94
-# include <errno.h>
97bb94
-# include <stdlib.h>
97bb94
-# include <openssl/rand.h>
97bb94
-# include <openssl/fips.h>
97bb94
-# include "crypto/fips.h"
97bb94
-
97bb94
-# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
97bb94
-
97bb94
-static void init_fips_mode(void)
97bb94
-{
97bb94
-    char buf[2] = "0";
97bb94
-    int fd;
97bb94
-
97bb94
-    if (secure_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
97bb94
-        buf[0] = '1';
97bb94
-    } else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
97bb94
-        while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
97bb94
-        close(fd);
97bb94
-    }
97bb94
-
97bb94
-    if (buf[0] != '1' && !FIPS_module_installed())
97bb94
-        return;
97bb94
-
97bb94
-    /* Ensure the selftests always run */
97bb94
-    /* XXX: TO SOLVE - premature initialization due to selftests */
97bb94
-    FIPS_mode_set(1);
97bb94
-
97bb94
-    /* Failure reading the fips mode switch file means just not
97bb94
-     * switching into FIPS mode. We would break too many things
97bb94
-     * otherwise..
97bb94
-     */
97bb94
-
97bb94
-    if (buf[0] != '1') {
97bb94
-        /* drop down to non-FIPS mode if it is not requested */
97bb94
-        FIPS_mode_set(0);
97bb94
-    } else {
97bb94
-        /* abort if selftest failed */
97bb94
-        FIPS_selftest_check();
97bb94
-    }
97bb94
-}
97bb94
 
97bb94
 /*
97bb94
  * Perform FIPS module power on selftest and automatic FIPS mode switch.
97bb94
@@ -63,11 +17,6 @@ static void init_fips_mode(void)
97bb94
 
97bb94
 void __attribute__ ((constructor)) OPENSSL_init_library(void)
97bb94
 {
97bb94
-    static int done = 0;
97bb94
-    if (done)
97bb94
-        return;
97bb94
-    done = 1;
97bb94
-    init_fips_mode();
97bb94
 }
97bb94
 #endif
97bb94