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

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