Blame SOURCES/enable-fips-when-system-is-in-fips-mode.patch

74fc46
diff -up nss/lib/pk11wrap/pk11pars.c.852023_enable_fips_when_in_fips_mode nss/lib/pk11wrap/pk11pars.c
294c78
--- nss/lib/pk11wrap/pk11pars.c.852023_enable_fips_when_in_fips_mode	2018-03-05 16:58:32.000000000 +0100
294c78
+++ nss/lib/pk11wrap/pk11pars.c	2018-03-09 17:24:39.815838810 +0100
294c78
@@ -671,6 +671,10 @@ SECMOD_CreateModuleEx(const char *librar
74fc46
 
74fc46
     mod->internal = NSSUTIL_ArgHasFlag("flags", "internal", nssc);
74fc46
     mod->isFIPS = NSSUTIL_ArgHasFlag("flags", "FIPS", nssc);
74fc46
+    /* if the system FIPS mode is enabled, force FIPS to be on */
74fc46
+    if (SECMOD_GetSystemFIPSEnabled()) {
74fc46
+	mod->isFIPS = PR_TRUE;
74fc46
+    }
74fc46
     mod->isCritical = NSSUTIL_ArgHasFlag("flags", "critical", nssc);
74fc46
     slotParams = NSSUTIL_ArgGetParamValue("slotParams", nssc);
74fc46
     mod->slotInfo = NSSUTIL_ArgParseSlotInfo(mod->arena, slotParams,
74fc46
diff -up nss/lib/pk11wrap/pk11util.c.852023_enable_fips_when_in_fips_mode nss/lib/pk11wrap/pk11util.c
294c78
--- nss/lib/pk11wrap/pk11util.c.852023_enable_fips_when_in_fips_mode	2018-03-05 16:58:32.000000000 +0100
294c78
+++ nss/lib/pk11wrap/pk11util.c	2018-03-09 17:25:46.804347730 +0100
294c78
@@ -95,6 +95,26 @@ SECMOD_Shutdown()
74fc46
     return SECSuccess;
74fc46
 }
74fc46
 
74fc46
+int SECMOD_GetSystemFIPSEnabled(void) {
74fc46
+#ifdef LINUX
74fc46
+    FILE *f;
74fc46
+    char d;
74fc46
+    size_t size;
74fc46
+
74fc46
+    f = fopen("/proc/sys/crypto/fips_enabled", "r");
74fc46
+    if (!f)
74fc46
+        return 0;
74fc46
+
74fc46
+    size = fread(&d, 1, 1, f);
74fc46
+    fclose(f);
74fc46
+    if (size != 1)
74fc46
+        return 0;
74fc46
+    if (d == '1')
74fc46
+        return 1;
74fc46
+#endif
74fc46
+    return 0;
74fc46
+}
74fc46
+
74fc46
 /*
74fc46
  * retrieve the internal module
74fc46
  */
294c78
@@ -428,7 +448,7 @@ SECMOD_DeleteInternalModule(const char *
74fc46
     SECMODModuleList **mlpp;
74fc46
     SECStatus rv = SECFailure;
74fc46
 
74fc46
-    if (pendingModule) {
74fc46
+    if (SECMOD_GetSystemFIPSEnabled() || pendingModule) {
74fc46
         PORT_SetError(SEC_ERROR_MODULE_STUCK);
74fc46
         return rv;
74fc46
     }
294c78
@@ -963,7 +983,7 @@ SECMOD_CanDeleteInternalModule(void)
294c78
 #ifdef NSS_FIPS_DISABLED
294c78
     return PR_FALSE;
294c78
 #else
74fc46
-    return (PRBool)(pendingModule == NULL);
74fc46
+    return (PRBool) ((pendingModule == NULL) && !SECMOD_GetSystemFIPSEnabled());
294c78
 #endif
74fc46
 }
74fc46
 
74fc46
diff -up nss/lib/pk11wrap/secmodi.h.852023_enable_fips_when_in_fips_mode nss/lib/pk11wrap/secmodi.h
294c78
--- nss/lib/pk11wrap/secmodi.h.852023_enable_fips_when_in_fips_mode	2018-03-05 16:58:32.000000000 +0100
294c78
+++ nss/lib/pk11wrap/secmodi.h	2018-03-09 17:24:39.816838788 +0100
74fc46
@@ -115,6 +115,13 @@ PK11SymKey *pk11_TokenKeyGenWithFlagsAnd
74fc46
 CK_MECHANISM_TYPE pk11_GetPBECryptoMechanism(SECAlgorithmID *algid,
74fc46
                                              SECItem **param, SECItem *pwd, PRBool faulty3DES);
74fc46
 
74fc46
+/* Get the state of the system FIPS mode */
74fc46
+/* NSS uses this to force FIPS mode if the system bit is on. Applications which
74fc46
+ * use the SECMOD_CanDeleteInteral() to check to see if they can switch to or
74fc46
+ * from FIPS mode will automatically be told that they can't swith out of FIPS
74fc46
+ * mode */
74fc46
+int SECMOD_GetSystemFIPSEnabled();
74fc46
+
74fc46
 extern void pk11sdr_Init(void);
74fc46
 extern void pk11sdr_Shutdown(void);
74fc46