Blame SOURCES/libgcrypt-1.8.5-fips-module.patch

150a03
diff -up libgcrypt-1.8.5/src/fips.c.fips-module libgcrypt-1.8.5/src/fips.c
150a03
--- libgcrypt-1.8.5/src/fips.c.fips-module	2020-04-20 19:07:45.924919645 +0200
150a03
+++ libgcrypt-1.8.5/src/fips.c	2020-04-20 19:10:33.690722470 +0200
150a03
@@ -35,10 +35,6 @@
150a03
 #include "hmac256.h"
150a03
 
150a03
 
150a03
-/* The name of the file used to force libgcrypt into fips mode. */
150a03
-#define FIPS_FORCE_FILE "/etc/gcrypt/fips_enabled"
150a03
-
150a03
-
150a03
 /* The states of the finite state machine used in fips mode.  */
150a03
 enum module_states
150a03
   {
150a03
@@ -122,54 +118,6 @@ _gcry_initialize_fips_mode (int force)
150a03
       goto leave;
150a03
     }
150a03
 
150a03
-  /* For testing the system it is useful to override the system
150a03
-     provided detection of the FIPS mode and force FIPS mode using a
150a03
-     file.  The filename is hardwired so that there won't be any
150a03
-     confusion on whether /etc/gcrypt/ or /usr/local/etc/gcrypt/ is
150a03
-     actually used.  The file itself may be empty.  */
150a03
-  if ( !access (FIPS_FORCE_FILE, F_OK) )
150a03
-    {
150a03
-      gcry_assert (!no_fips_mode_required);
150a03
-      goto leave;
150a03
-    }
150a03
-
150a03
-  /* Checking based on /proc file properties.  */
150a03
-  {
150a03
-    static const char procfname[] = "/proc/sys/crypto/fips_enabled";
150a03
-    FILE *fp;
150a03
-    int saved_errno;
150a03
-
150a03
-    fp = fopen (procfname, "r");
150a03
-    if (fp)
150a03
-      {
150a03
-        char line[256];
150a03
-
150a03
-        if (fgets (line, sizeof line, fp) && atoi (line))
150a03
-          {
150a03
-            /* System is in fips mode.  */
150a03
-            fclose (fp);
150a03
-            gcry_assert (!no_fips_mode_required);
150a03
-            goto leave;
150a03
-          }
150a03
-        fclose (fp);
150a03
-      }
150a03
-    else if ((saved_errno = errno) != ENOENT
150a03
-             && saved_errno != EACCES
150a03
-             && !access ("/proc/version", F_OK) )
150a03
-      {
150a03
-        /* Problem reading the fips file despite that we have the proc
150a03
-           file system.  We better stop right away. */
150a03
-        log_info ("FATAL: error reading `%s' in libgcrypt: %s\n",
150a03
-                  procfname, strerror (saved_errno));
150a03
-#ifdef HAVE_SYSLOG
150a03
-        syslog (LOG_USER|LOG_ERR, "Libgcrypt error: "
150a03
-                "reading `%s' failed: %s - abort",
150a03
-                procfname, strerror (saved_errno));
150a03
-#endif /*HAVE_SYSLOG*/
150a03
-        abort ();
150a03
-      }
150a03
-  }
150a03
-
150a03
   /* Fips not not requested, set flag.  */
150a03
   no_fips_mode_required = 1;
150a03
 
150a03
diff -up libgcrypt-1.8.5/src/g10lib.h.fips-module libgcrypt-1.8.5/src/g10lib.h
150a03
--- libgcrypt-1.8.5/src/g10lib.h.fips-module	2020-04-20 19:07:45.918919759 +0200
150a03
+++ libgcrypt-1.8.5/src/g10lib.h	2020-04-20 19:11:05.003125740 +0200
150a03
@@ -422,6 +422,9 @@ gpg_err_code_t _gcry_sexp_vextract_param
150a03
 
150a03
 /*-- fips.c --*/
150a03
 
150a03
+/* The name of the file used to force libgcrypt into fips mode. */
150a03
+#define FIPS_FORCE_FILE "/etc/gcrypt/fips_enabled"
150a03
+
150a03
 void _gcry_initialize_fips_mode (int force);
150a03
 
150a03
 int _gcry_fips_mode (void);
150a03
diff -up libgcrypt-1.8.5/src/global.c.fips-module libgcrypt-1.8.5/src/global.c
150a03
--- libgcrypt-1.8.5/src/global.c.fips-module	2020-04-20 19:07:45.919919741 +0200
150a03
+++ libgcrypt-1.8.5/src/global.c	2020-04-20 19:07:45.950919149 +0200
150a03
@@ -160,6 +160,53 @@ void __attribute__ ((constructor)) _gcry
150a03
   rv = access (FIPS_MODULE_PATH, F_OK);
150a03
   if (rv < 0 && errno != ENOENT)
150a03
     rv = 0;
150a03
+ 
150a03
+  /* For testing the system it is useful to override the system
150a03
+     provided detection of the FIPS mode and force FIPS mode using a
150a03
+     file.  The filename is hardwired so that there won't be any
150a03
+     confusion on whether /etc/gcrypt/ or /usr/local/etc/gcrypt/ is
150a03
+     actually used.  The file itself may be empty.  */
150a03
+  if ( !access (FIPS_FORCE_FILE, F_OK) )
150a03
+    {
150a03
+      rv = 0;
150a03
+      force_fips_mode = 1;
150a03
+    }
150a03
+
150a03
+  /* Checking based on /proc file properties.  */
150a03
+  {
150a03
+    static const char procfname[] = "/proc/sys/crypto/fips_enabled";
150a03
+    FILE *fp;
150a03
+    int saved_errno;
150a03
+
150a03
+    fp = fopen (procfname, "r");
150a03
+    if (fp)
150a03
+      {
150a03
+        char line[256];
150a03
+
150a03
+        if (fgets (line, sizeof line, fp) && atoi (line))
150a03
+          {
150a03
+            /* System is in fips mode.  */
150a03
+            rv = 0;
150a03
+            force_fips_mode = 1;
150a03
+          }
150a03
+        fclose (fp);
150a03
+      }
150a03
+    else if ((saved_errno = errno) != ENOENT
150a03
+             && saved_errno != EACCES
150a03
+             && !access ("/proc/version", F_OK) )
150a03
+      {
150a03
+        /* Problem reading the fips file despite that we have the proc
150a03
+           file system.  We better stop right away. */
150a03
+        log_info ("FATAL: error reading `%s' in libgcrypt: %s\n",
150a03
+                  procfname, strerror (saved_errno));
150a03
+#ifdef HAVE_SYSLOG
150a03
+        syslog (LOG_USER|LOG_ERR, "Libgcrypt error: "
150a03
+                "reading `%s' failed: %s - abort",
150a03
+                procfname, strerror (saved_errno));
150a03
+#endif /*HAVE_SYSLOG*/
150a03
+        abort ();
150a03
+      }
150a03
+  }
150a03
 
150a03
   if (!rv)
150a03
     {