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

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