diff -up nss/lib/pk11wrap/pk11pars.c.fips nss/lib/pk11wrap/pk11pars.c --- nss/lib/pk11wrap/pk11pars.c.fips 2013-05-28 14:43:24.000000000 -0700 +++ nss/lib/pk11wrap/pk11pars.c 2013-07-10 18:54:16.733465910 -0700 @@ -150,6 +150,10 @@ SECMOD_CreateModule(const char *library, } mod->internal = NSSUTIL_ArgHasFlag("flags","internal",nssc); mod->isFIPS = NSSUTIL_ArgHasFlag("flags","FIPS",nssc); + /* if the system FIPS mode is enabled, force FIPS to be on */ + if (SECMOD_GetSystemFIPSEnabled()) { + mod->isFIPS = PR_TRUE; + } mod->isCritical = NSSUTIL_ArgHasFlag("flags","critical",nssc); slotParams = NSSUTIL_ArgGetParamValue("slotParams",nssc); mod->slotInfo = NSSUTIL_ArgParseSlotInfo(mod->arena,slotParams, diff -up nss/lib/pk11wrap/pk11util.c.fips nss/lib/pk11wrap/pk11util.c --- nss/lib/pk11wrap/pk11util.c.fips 2013-05-28 14:43:24.000000000 -0700 +++ nss/lib/pk11wrap/pk11util.c 2013-07-10 18:54:16.734465927 -0700 @@ -95,6 +95,25 @@ SECMOD_Shutdown() return SECSuccess; } +int SECMOD_GetSystemFIPSEnabled(void) { +#ifdef LINUX + FILE *f; + char d; + size_t size; + + f = fopen("/proc/sys/crypto/fips_enabled", "r"); + if (!f) + return 0; + + size = fread(&d, 1, 1, f); + fclose(f); + if (size != 1) + return 0; + if (d == '1') + return 1; +#endif + return 0; +} /* * retrieve the internal module @@ -417,7 +436,7 @@ SECMOD_DeleteInternalModule(const char * SECMODModuleList **mlpp; SECStatus rv = SECFailure; - if (pendingModule) { + if (SECMOD_GetSystemFIPSEnabled() || pendingModule) { PORT_SetError(SEC_ERROR_MODULE_STUCK); return rv; } @@ -888,7 +907,7 @@ SECMOD_DestroyModuleList(SECMODModuleLis PRBool SECMOD_CanDeleteInternalModule(void) { - return (PRBool) (pendingModule == NULL); + return (PRBool) ((pendingModule == NULL) && !SECMOD_GetSystemFIPSEnabled()); } /* diff -up nss/lib/pk11wrap/secmodi.h.fips nss/lib/pk11wrap/secmodi.h --- nss/lib/pk11wrap/secmodi.h.fips 2013-07-10 18:55:06.358298154 -0700 +++ nss/lib/pk11wrap/secmodi.h 2013-07-10 18:56:52.050069372 -0700 @@ -116,7 +116,12 @@ PK11SymKey *pk11_TokenKeyGenWithFlagsAnd CK_MECHANISM_TYPE pk11_GetPBECryptoMechanism(SECAlgorithmID *algid, SECItem **param, SECItem *pwd, PRBool faulty3DES); - +/* Get the state of the system FIPS mode */ +/* NSS uses this to force FIPS mode if the system bit is on. Applications which + * use the SECMOD_CanDeleteInteral() to check to see if they can switch to or + * from FIPS mode will automatically be told that they can't swith out of FIPS + * mode */ +int SECMOD_GetSystemFIPSEnabled(); extern void pk11sdr_Init(void); extern void pk11sdr_Shutdown(void);