2018-07-12 13:45:03 +00:00
|
|
|
diff -up libgcrypt-1.8.3/src/global.c.fips-ctor libgcrypt-1.8.3/src/global.c
|
|
|
|
--- libgcrypt-1.8.3/src/global.c.fips-ctor 2017-11-23 19:25:58.000000000 +0100
|
2020-04-20 17:36:34 +00:00
|
|
|
+++ libgcrypt-1.8.3/src/global.c 2020-04-17 16:29:59.258218015 +0200
|
|
|
|
@@ -141,6 +141,34 @@ global_init (void)
|
2018-07-12 13:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+#ifndef FIPS_MODULE_PATH
|
|
|
|
+#define FIPS_MODULE_PATH "/etc/system-fips"
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+void __attribute__ ((constructor)) _gcry_global_constructor (void)
|
|
|
|
+{
|
|
|
|
+ int rv;
|
|
|
|
+
|
|
|
|
+ rv = access (FIPS_MODULE_PATH, F_OK);
|
|
|
|
+ if (rv < 0 && errno != ENOENT)
|
|
|
|
+ rv = 0;
|
|
|
|
+
|
|
|
|
+ if (!rv)
|
|
|
|
+ {
|
2020-04-20 17:36:34 +00:00
|
|
|
+ int no_secmem_save;
|
|
|
|
+
|
|
|
|
+ /* it should be always 0 at this point but let's keep on the safe side */
|
|
|
|
+ no_secmem_save = no_secure_memory;
|
|
|
|
+ no_secure_memory = 1;
|
|
|
|
+ /* force selftests */
|
|
|
|
+ global_init();
|
2018-07-12 13:45:03 +00:00
|
|
|
+ _gcry_fips_run_selftests (0);
|
2020-04-20 17:36:34 +00:00
|
|
|
+ if (!fips_mode())
|
|
|
|
+ _gcry_random_close_fds ();
|
|
|
|
+ no_secure_memory = no_secmem_save;
|
2018-07-12 13:45:03 +00:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
/* This function is called by the macro fips_is_operational and makes
|
|
|
|
sure that the minimal initialization has been done. This is far
|
|
|
|
from a perfect solution and hides problems with an improper
|
2020-04-20 17:36:34 +00:00
|
|
|
@@ -671,8 +699,7 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd,
|
2018-07-12 13:45:03 +00:00
|
|
|
|
|
|
|
case GCRYCTL_FIPS_MODE_P:
|
|
|
|
if (fips_mode ()
|
|
|
|
- && !_gcry_is_fips_mode_inactive ()
|
|
|
|
- && !no_secure_memory)
|
|
|
|
+ && !_gcry_is_fips_mode_inactive ())
|
|
|
|
rc = GPG_ERR_GENERAL; /* Used as TRUE value */
|
|
|
|
break;
|
|
|
|
|
2020-04-20 17:36:34 +00:00
|
|
|
@@ -749,9 +776,9 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd,
|
2018-07-12 13:45:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GCRYCTL_SET_ENFORCED_FIPS_FLAG:
|
2021-01-20 00:34:36 +00:00
|
|
|
- if (!_gcry_global_any_init_done)
|
2018-07-12 13:45:03 +00:00
|
|
|
+ if (fips_mode ())
|
|
|
|
{
|
2018-07-17 17:16:47 +00:00
|
|
|
- /* Not yet initialized at all. Set the enforced fips mode flag */
|
|
|
|
+ /* We are in FIPS mode, we can set the enforced fips mode flag. */
|
2018-07-12 13:45:03 +00:00
|
|
|
_gcry_set_preferred_rng_type (0);
|
2018-07-17 17:16:47 +00:00
|
|
|
_gcry_set_enforced_fips_mode ();
|
|
|
|
}
|