Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2021-05-31 07:08:01 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2021-06-08 12:42:00 +0300
commit1997aa3b4073d1cfdf589c0656cfb286cbf8cea8 (patch)
treea483a71f2258ff7fc429a256e626e947b284e6b6 /src
parent911ff342553a78f162bc30f53237a5a80c757b8c (diff)
src,test: raise error for --enable-fips when no FIPS
This commit moves the check for FIPS from the crypto module initialization to process startup. The motivation for this is that when OpenSSL is not FIPS enabled and the command line options --enable-fips, or --force-fips are used, there will only be an error raised if the crypto module is used. This can be surprising and we have gotten feedback that users assumed that there would be an error if these options were specified and FIPS is not available. PR-URL: https://github.com/nodejs/node/pull/38859 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <rlau@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/crypto/crypto_util.cc40
-rw-r--r--src/crypto/crypto_util.h2
-rw-r--r--src/node.cc14
3 files changed, 32 insertions, 24 deletions
diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc
index bc4efe5f597..13c40dcb757 100644
--- a/src/crypto/crypto_util.cc
+++ b/src/crypto/crypto_util.cc
@@ -14,11 +14,9 @@
#include "math.h"
-#ifdef OPENSSL_FIPS
#if OPENSSL_VERSION_MAJOR >= 3
#include "openssl/provider.h"
#endif
-#endif
#include <openssl/rand.h>
@@ -107,6 +105,25 @@ int NoPasswordCallback(char* buf, int size, int rwflag, void* u) {
return 0;
}
+bool ProcessFipsOptions() {
+ /* Override FIPS settings in configuration file, if needed. */
+ if (per_process::cli_options->enable_fips_crypto ||
+ per_process::cli_options->force_fips_crypto) {
+#if OPENSSL_VERSION_MAJOR >= 3
+ OSSL_PROVIDER* fips_provider = OSSL_PROVIDER_load(nullptr, "fips");
+ if (fips_provider == nullptr)
+ return false;
+ OSSL_PROVIDER_unload(fips_provider);
+
+ return EVP_default_properties_enable_fips(nullptr, 1) &&
+ EVP_default_properties_is_fips_enabled(nullptr);
+#else
+ return FIPS_mode() == 0 && FIPS_mode_set(1);
+#endif
+ }
+ return true;
+}
+
void InitCryptoOnce() {
#ifndef OPENSSL_IS_BORINGSSL
OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new();
@@ -143,25 +160,6 @@ void InitCryptoOnce() {
}
#endif
- /* Override FIPS settings in cnf file, if needed. */
- unsigned long err = 0; // NOLINT(runtime/int)
- if (per_process::cli_options->enable_fips_crypto ||
- per_process::cli_options->force_fips_crypto) {
-#if OPENSSL_VERSION_MAJOR >= 3
- if (0 == EVP_default_properties_is_fips_enabled(nullptr) &&
- !EVP_default_properties_enable_fips(nullptr, 1)) {
-#else
- if (0 == FIPS_mode() && !FIPS_mode_set(1)) {
-#endif
- err = ERR_get_error();
- }
- }
- if (0 != err) {
- auto* isolate = Isolate::GetCurrent();
- auto* env = Environment::GetCurrent(isolate);
- return ThrowCryptoError(env, err);
- }
-
// Turn off compression. Saves memory and protects against CRIME attacks.
// No-op with OPENSSL_NO_COMP builds of OpenSSL.
sk_SSL_COMP_zero(SSL_COMP_get_compression_methods());
diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h
index 94bcb100cca..ac95612a0b1 100644
--- a/src/crypto/crypto_util.h
+++ b/src/crypto/crypto_util.h
@@ -86,6 +86,8 @@ using DsaSigPointer = DeleteFnPtr<DSA_SIG, DSA_SIG_free>;
// callback has been made.
extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx);
+bool ProcessFipsOptions();
+
void InitCryptoOnce();
void InitCrypto(v8::Local<v8::Object> target);
diff --git a/src/node.cc b/src/node.cc
index a9afbd2682f..3ca2a05d8b8 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1080,9 +1080,17 @@ InitializationResult InitializeOncePerProcess(
OPENSSL_init();
}
#endif
- // V8 on Windows doesn't have a good source of entropy. Seed it from
- // OpenSSL's pool.
- V8::SetEntropySource(crypto::EntropySource);
+ if (!crypto::ProcessFipsOptions()) {
+ result.exit_code = ERR_GET_REASON(ERR_peek_error());
+ result.early_return = true;
+ fprintf(stderr, "OpenSSL error when trying to enable FIPS:\n");
+ ERR_print_errors_fp(stderr);
+ return result;
+ }
+
+ // V8 on Windows doesn't have a good source of entropy. Seed it from
+ // OpenSSL's pool.
+ V8::SetEntropySource(crypto::EntropySource);
#endif // HAVE_OPENSSL
}
per_process::v8_platform.Initialize(