|
14 | 14 |
|
15 | 15 | #include "math.h" |
16 | 16 |
|
17 | | -#ifdef OPENSSL_FIPS |
18 | 17 | #if OPENSSL_VERSION_MAJOR >= 3 |
19 | 18 | #include "openssl/provider.h" |
20 | 19 | #endif |
21 | | -#endif |
22 | 20 |
|
23 | 21 | #include <openssl/rand.h> |
24 | 22 |
|
@@ -107,6 +105,25 @@ int NoPasswordCallback(char* buf, int size, int rwflag, void* u) { |
107 | 105 | return 0; |
108 | 106 | } |
109 | 107 |
|
| 108 | +bool ProcessFipsOptions() { |
| 109 | + /* Override FIPS settings in configuration file, if needed. */ |
| 110 | + if (per_process::cli_options->enable_fips_crypto || |
| 111 | + per_process::cli_options->force_fips_crypto) { |
| 112 | +#if OPENSSL_VERSION_MAJOR >= 3 |
| 113 | + OSSL_PROVIDER* fips_provider = OSSL_PROVIDER_load(nullptr, "fips"); |
| 114 | + if (fips_provider == nullptr) |
| 115 | + return false; |
| 116 | + OSSL_PROVIDER_unload(fips_provider); |
| 117 | + |
| 118 | + return EVP_default_properties_enable_fips(nullptr, 1) && |
| 119 | + EVP_default_properties_is_fips_enabled(nullptr); |
| 120 | +#else |
| 121 | + return FIPS_mode() == 0 && FIPS_mode_set(1); |
| 122 | +#endif |
| 123 | + } |
| 124 | + return true; |
| 125 | +} |
| 126 | + |
110 | 127 | void InitCryptoOnce() { |
111 | 128 | #ifndef OPENSSL_IS_BORINGSSL |
112 | 129 | OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new(); |
@@ -143,25 +160,6 @@ void InitCryptoOnce() { |
143 | 160 | } |
144 | 161 | #endif |
145 | 162 |
|
146 | | - /* Override FIPS settings in cnf file, if needed. */ |
147 | | - unsigned long err = 0; // NOLINT(runtime/int) |
148 | | - if (per_process::cli_options->enable_fips_crypto || |
149 | | - per_process::cli_options->force_fips_crypto) { |
150 | | -#if OPENSSL_VERSION_MAJOR >= 3 |
151 | | - if (0 == EVP_default_properties_is_fips_enabled(nullptr) && |
152 | | - !EVP_default_properties_enable_fips(nullptr, 1)) { |
153 | | -#else |
154 | | - if (0 == FIPS_mode() && !FIPS_mode_set(1)) { |
155 | | -#endif |
156 | | - err = ERR_get_error(); |
157 | | - } |
158 | | - } |
159 | | - if (0 != err) { |
160 | | - auto* isolate = Isolate::GetCurrent(); |
161 | | - auto* env = Environment::GetCurrent(isolate); |
162 | | - return ThrowCryptoError(env, err); |
163 | | - } |
164 | | - |
165 | 163 | // Turn off compression. Saves memory and protects against CRIME attacks. |
166 | 164 | // No-op with OPENSSL_NO_COMP builds of OpenSSL. |
167 | 165 | sk_SSL_COMP_zero(SSL_COMP_get_compression_methods()); |
|
0 commit comments