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

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