Blame SOURCES/always-available-fips-options.patch

2509f6
From 7bc4111b770ada25cdd6e1b938ca7a914617ea53 Mon Sep 17 00:00:00 2001
2509f6
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
2509f6
Date: Tue, 25 Aug 2020 14:04:54 +0200
2509f6
Subject: [PATCH] crypto: make FIPS related options always awailable
2509f6
MIME-Version: 1.0
2509f6
Content-Type: text/plain; charset=UTF-8
2509f6
Content-Transfer-Encoding: 8bit
2509f6
2509f6
There is no reason to hide FIPS functionality behind build flags.
2509f6
OpenSSL always provide the information about FIPS availability via
2509f6
`FIPS_mode()` function.
2509f6
2509f6
This makes the user experience more consistent, because the OpenSSL
2509f6
library is always queried and the `crypto.getFips()` always returns
2509f6
OpenSSL settings.
2509f6
2509f6
Fixes #34903
2509f6
2509f6
PR-URL: https://github.com/nodejs/node/pull/36341
2509f6
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2509f6
Reviewed-By: Michael Dawson <midawson@redhat.com>
2509f6
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2509f6
Signed-off-by: Jan Staněk <jstanek@redhat.com>
2509f6
---
2509f6
 doc/api/cli.md                                |  8 +--
2509f6
 lib/crypto.js                                 | 22 ++----
2509f6
 node.gypi                                     |  3 -
2509f6
 src/node.cc                                   |  6 +-
2509f6
 src/node_config.cc                            |  2 -
2509f6
 src/node_crypto.cc                            | 45 +++++++-----
2509f6
 src/node_options.cc                           |  2 -
2509f6
 src/node_options.h                            |  2 -
2509f6
 test/parallel/test-cli-node-print-help.js     |  7 +-
2509f6
 test/parallel/test-crypto-fips.js             | 71 +++++++++----------
2509f6
 ...rocess-env-allowed-flags-are-documented.js | 11 +--
2509f6
 11 files changed, 74 insertions(+), 105 deletions(-)
2509f6
2509f6
diff --git a/doc/api/cli.md b/doc/api/cli.md
2509f6
index 86635f267b..6f14fa6810 100644
2509f6
--- a/doc/api/cli.md
2509f6
+++ b/doc/api/cli.md
2509f6
@@ -183,8 +183,8 @@ code from strings throw an exception instead. This does not affect the Node.js
2509f6
 added: v6.0.0
2509f6
 -->
2509f6
 
2509f6
-Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with
2509f6
-`./configure --openssl-fips`.)
2509f6
+Enable FIPS-compliant crypto at startup. (Requires Node.js to be built
2509f6
+against FIPS-compatible OpenSSL.)
2509f6
 
2509f6
 ### `--enable-source-maps`
2509f6
 
2509f6
@@ -550,8 +550,8 @@ added: v6.9.0
2509f6
 -->
2509f6
 
2509f6
 Load an OpenSSL configuration file on startup. Among other uses, this can be
2509f6
-used to enable FIPS-compliant crypto if Node.js is built with
2509f6
-`./configure --openssl-fips`.
2509f6
+used to enable FIPS-compliant crypto if Node.js is built
2509f6
+against FIPS-enabled OpenSSL.
2509f6
 
2509f6
 ### `--pending-deprecation`
2509f6
 
2509f6
diff --git a/lib/crypto.js b/lib/crypto.js
2509f6
index b2bcc4d0a4..93d5e21fa0 100644
2509f6
--- a/lib/crypto.js
2509f6
+++ b/lib/crypto.js
2509f6
@@ -37,12 +37,10 @@ assertCrypto();
2509f6
 
2509f6
 const {
2509f6
   ERR_CRYPTO_FIPS_FORCED,
2509f6
-  ERR_CRYPTO_FIPS_UNAVAILABLE
2509f6
 } = require('internal/errors').codes;
2509f6
 const constants = internalBinding('constants').crypto;
2509f6
 const { getOptionValue } = require('internal/options');
2509f6
 const pendingDeprecation = getOptionValue('--pending-deprecation');
2509f6
-const { fipsMode } = internalBinding('config');
2509f6
 const fipsForced = getOptionValue('--force-fips');
2509f6
 const {
2509f6
   getFipsCrypto,
2509f6
@@ -191,10 +189,8 @@ module.exports = {
2509f6
   sign: signOneShot,
2509f6
   setEngine,
2509f6
   timingSafeEqual,
2509f6
-  getFips: !fipsMode ? getFipsDisabled :
2509f6
-    fipsForced ? getFipsForced : getFipsCrypto,
2509f6
-  setFips: !fipsMode ? setFipsDisabled :
2509f6
-    fipsForced ? setFipsForced : setFipsCrypto,
2509f6
+  getFips: fipsForced ? getFipsForced : getFipsCrypto,
2509f6
+  setFips: fipsForced ? setFipsForced : setFipsCrypto,
2509f6
   verify: verifyOneShot,
2509f6
 
2509f6
   // Classes
2509f6
@@ -213,19 +209,11 @@ module.exports = {
2509f6
   Verify
2509f6
 };
2509f6
 
2509f6
-function setFipsDisabled() {
2509f6
-  throw new ERR_CRYPTO_FIPS_UNAVAILABLE();
2509f6
-}
2509f6
-
2509f6
 function setFipsForced(val) {
2509f6
   if (val) return;
2509f6
   throw new ERR_CRYPTO_FIPS_FORCED();
2509f6
 }
2509f6
 
2509f6
-function getFipsDisabled() {
2509f6
-  return 0;
2509f6
-}
2509f6
-
2509f6
 function getFipsForced() {
2509f6
   return 1;
2509f6
 }
2509f6
@@ -247,10 +235,8 @@ ObjectDefineProperties(module.exports, {
2509f6
   },
2509f6
   // crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
2509f6
   fips: {
2509f6
-    get: !fipsMode ? getFipsDisabled :
2509f6
-      fipsForced ? getFipsForced : getFipsCrypto,
2509f6
-    set: !fipsMode ? setFipsDisabled :
2509f6
-      fipsForced ? setFipsForced : setFipsCrypto
2509f6
+    get: fipsForced ? getFipsForced : getFipsCrypto,
2509f6
+    set: fipsForced ? setFipsForced : setFipsCrypto
2509f6
   },
2509f6
   DEFAULT_ENCODING: {
2509f6
     enumerable: false,
2509f6
diff --git a/node.gypi b/node.gypi
2509f6
index 116c1c7149..34f385f652 100644
2509f6
--- a/node.gypi
2509f6
+++ b/node.gypi
2509f6
@@ -320,9 +320,6 @@
2509f6
     [ 'node_use_openssl=="true"', {
2509f6
       'defines': [ 'HAVE_OPENSSL=1' ],
2509f6
       'conditions': [
2509f6
-        ['openssl_fips != "" or openssl_is_fips=="true"', {
2509f6
-          'defines': [ 'NODE_FIPS_MODE' ],
2509f6
-        }],
2509f6
         [ 'node_shared_openssl=="false"', {
2509f6
           'dependencies': [
2509f6
             './deps/openssl/openssl.gyp:openssl',
2509f6
diff --git a/src/node.cc b/src/node.cc
2509f6
index 46e8f74cc2..0a5c3ee8ee 100644
2509f6
--- a/src/node.cc
2509f6
+++ b/src/node.cc
2509f6
@@ -964,11 +964,11 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
2509f6
     if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs))
2509f6
       crypto::UseExtraCaCerts(extra_ca_certs);
2509f6
   }
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   // In the case of FIPS builds we should make sure
2509f6
   // the random source is properly initialized first.
2509f6
-  OPENSSL_init();
2509f6
-#endif  // NODE_FIPS_MODE
2509f6
+  if (FIPS_mode()) {
2509f6
+    OPENSSL_init();
2509f6
+  }
2509f6
   // V8 on Windows doesn't have a good source of entropy. Seed it from
2509f6
   // OpenSSL's pool.
2509f6
   V8::SetEntropySource(crypto::EntropySource);
2509f6
diff --git a/src/node_config.cc b/src/node_config.cc
2509f6
index 6ee3164a13..e229eee765 100644
2509f6
--- a/src/node_config.cc
2509f6
+++ b/src/node_config.cc
2509f6
@@ -42,9 +42,7 @@ static void Initialize(Local<Object> target,
2509f6
   READONLY_FALSE_PROPERTY(target, "hasOpenSSL");
2509f6
 #endif  // HAVE_OPENSSL
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   READONLY_TRUE_PROPERTY(target, "fipsMode");
2509f6
-#endif
2509f6
 
2509f6
 #ifdef NODE_HAVE_I18N_SUPPORT
2509f6
 
2509f6
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
2509f6
index 764dcb8720..f142e625ef 100644
2509f6
--- a/src/node_crypto.cc
2509f6
+++ b/src/node_crypto.cc
2509f6
@@ -50,6 +50,11 @@
2509f6
 #include <openssl/hmac.h>
2509f6
 #include <openssl/rand.h>
2509f6
 #include <openssl/pkcs12.h>
2509f6
+// The FIPS-related functions are only available
2509f6
+// when the OpenSSL itself was compiled with FIPS support.
2509f6
+#ifdef OPENSSL_FIPS
2509f6
+#include <openssl/fips.h>
2509f6
+#endif // OPENSSL_FIPS
2509f6
 
2509f6
 #include <cerrno>
2509f6
 #include <climits>  // INT_MAX
2509f6
@@ -97,6 +102,7 @@ using v8::Signature;
2509f6
 using v8::String;
2509f6
 using v8::Uint32;
2509f6
 using v8::Undefined;
2509f6
+using v8::TryCatch;
2509f6
 using v8::Value;
2509f6
 
2509f6
 #ifdef OPENSSL_NO_OCB
2509f6
@@ -3595,12 +3601,10 @@ void CipherBase::Init(const char* cipher_type,
2509f6
   HandleScope scope(env()->isolate());
2509f6
   MarkPopErrorOnReturn mark_pop_error_on_return;
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   if (FIPS_mode()) {
2509f6
     return env()->ThrowError(
2509f6
         "crypto.createCipher() is not supported in FIPS mode.");
2509f6
   }
2509f6
-#endif  // NODE_FIPS_MODE
2509f6
 
2509f6
   const EVP_CIPHER* const cipher = EVP_get_cipherbyname(cipher_type);
2509f6
   if (cipher == nullptr)
2509f6
@@ -3786,13 +3790,11 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
2509f6
       return false;
2509f6
     }
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
     // TODO(tniessen) Support CCM decryption in FIPS mode
2509f6
     if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode()) {
2509f6
       env()->ThrowError("CCM decryption not supported in FIPS mode");
2509f6
       return false;
2509f6
     }
2509f6
-#endif
2509f6
 
2509f6
     // Tell OpenSSL about the desired length.
2509f6
     if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
2509f6
@@ -4712,7 +4714,6 @@ static AllocatedBuffer Node_SignFinal(Environment* env,
2509f6
 }
2509f6
 
2509f6
 static inline bool ValidateDSAParameters(EVP_PKEY* key) {
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   /* Validate DSA2 parameters from FIPS 186-4 */
2509f6
   if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) {
2509f6
     DSA* dsa = EVP_PKEY_get0_DSA(key);
2509f6
@@ -4728,7 +4729,6 @@ static inline bool ValidateDSAParameters(EVP_PKEY* key) {
2509f6
            (L == 2048 && N == 256) ||
2509f6
            (L == 3072 && N == 256);
2509f6
   }
2509f6
-#endif  // NODE_FIPS_MODE
2509f6
 
2509f6
   return true;
2509f6
 }
2509f6
@@ -6889,7 +6889,6 @@ void InitCryptoOnce() {
2509f6
   settings = nullptr;
2509f6
 #endif
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   /* Override FIPS settings in cnf file, if needed. */
2509f6
   unsigned long err = 0;  // NOLINT(runtime/int)
2509f6
   if (per_process::cli_options->enable_fips_crypto ||
2509f6
@@ -6899,12 +6898,10 @@ void InitCryptoOnce() {
2509f6
     }
2509f6
   }
2509f6
   if (0 != err) {
2509f6
-    fprintf(stderr,
2509f6
-            "openssl fips failed: %s\n",
2509f6
-            ERR_error_string(err, nullptr));
2509f6
-    UNREACHABLE();
2509f6
+      auto* isolate = Isolate::GetCurrent();
2509f6
+      auto* env = Environment::GetCurrent(isolate);
2509f6
+      return ThrowCryptoError(env, err);
2509f6
   }
2509f6
-#endif  // NODE_FIPS_MODE
2509f6
 
2509f6
 
2509f6
   // Turn off compression. Saves memory and protects against CRIME attacks.
2509f6
@@ -6950,7 +6947,6 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
2509f6
 }
2509f6
 #endif  // !OPENSSL_NO_ENGINE
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
 void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
2509f6
   args.GetReturnValue().Set(FIPS_mode() ? 1 : 0);
2509f6
 }
2509f6
@@ -6968,17 +6964,33 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
2509f6
     return ThrowCryptoError(env, err);
2509f6
   }
2509f6
 }
2509f6
-#endif /* NODE_FIPS_MODE */
2509f6
+
2509f6
+void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) {
2509f6
+#ifdef OPENSSL_FIPS
2509f6
+  const auto enabled = FIPS_selftest() ? 1 : 0;
2509f6
+#else  // OPENSSL_FIPS
2509f6
+  const auto enabled = 0;
2509f6
+#endif  // OPENSSL_FIPS
2509f6
+
2509f6
+  args.GetReturnValue().Set(enabled);
2509f6
+}
2509f6
 
2509f6
 
2509f6
 void Initialize(Local<Object> target,
2509f6
                 Local<Value> unused,
2509f6
                 Local<Context> context,
2509f6
                 void* priv) {
2509f6
+  Environment* env = Environment::GetCurrent(context);
2509f6
+
2509f6
   static uv_once_t init_once = UV_ONCE_INIT;
2509f6
+  TryCatch try_catch{env->isolate()};
2509f6
   uv_once(&init_once, InitCryptoOnce);
2509f6
 
2509f6
-  Environment* env = Environment::GetCurrent(context);
2509f6
+  if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
2509f6
+    try_catch.ReThrow();
2509f6
+    return;
2509f6
+  }
2509f6
+
2509f6
   SecureContext::Initialize(env, target);
2509f6
   target->Set(env->context(),
2509f6
             FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"),
2509f6
@@ -7007,10 +7019,9 @@ void Initialize(Local<Object> target,
2509f6
   env->SetMethod(target, "setEngine", SetEngine);
2509f6
 #endif  // !OPENSSL_NO_ENGINE
2509f6
 
2509f6
-#ifdef NODE_FIPS_MODE
2509f6
   env->SetMethodNoSideEffect(target, "getFipsCrypto", GetFipsCrypto);
2509f6
   env->SetMethod(target, "setFipsCrypto", SetFipsCrypto);
2509f6
-#endif
2509f6
+  env->SetMethodNoSideEffect(target, "testFipsCrypto", TestFipsCrypto);
2509f6
 
2509f6
   env->SetMethod(target, "pbkdf2", PBKDF2);
2509f6
   env->SetMethod(target, "generateKeyPairRSA", GenerateKeyPairRSA);
2509f6
diff --git a/src/node_options.cc b/src/node_options.cc
2509f6
index 0240b2ef58..d1230da1ad 100644
2509f6
--- a/src/node_options.cc
2509f6
+++ b/src/node_options.cc
2509f6
@@ -729,7 +729,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
2509f6
             &PerProcessOptions::ssl_openssl_cert_store);
2509f6
   Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
2509f6
   ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]");
2509f6
-#if NODE_FIPS_MODE
2509f6
   AddOption("--enable-fips",
2509f6
             "enable FIPS crypto at startup",
2509f6
             &PerProcessOptions::enable_fips_crypto,
2509f6
@@ -738,7 +737,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
2509f6
             "force FIPS crypto (cannot be disabled)",
2509f6
             &PerProcessOptions::force_fips_crypto,
2509f6
             kAllowedInEnvironment);
2509f6
-#endif
2509f6
 #endif
2509f6
   AddOption("--use-largepages",
2509f6
             "Map the Node.js static code to large pages. Options are "
2509f6
diff --git a/src/node_options.h b/src/node_options.h
2509f6
index aa138c6970..f5e1e7da57 100644
2509f6
--- a/src/node_options.h
2509f6
+++ b/src/node_options.h
2509f6
@@ -236,10 +236,8 @@ class PerProcessOptions : public Options {
2509f6
 #endif
2509f6
   bool use_openssl_ca = false;
2509f6
   bool use_bundled_ca = false;
2509f6
-#if NODE_FIPS_MODE
2509f6
   bool enable_fips_crypto = false;
2509f6
   bool force_fips_crypto = false;
2509f6
-#endif
2509f6
 #endif
2509f6
 
2509f6
   // Per-process because reports can be triggered outside a known V8 context.
2509f6
diff --git a/test/parallel/test-cli-node-print-help.js b/test/parallel/test-cli-node-print-help.js
2509f6
index e115124b04..ed58bf085c 100644
2509f6
--- a/test/parallel/test-cli-node-print-help.js
2509f6
+++ b/test/parallel/test-cli-node-print-help.js
2509f6
@@ -8,8 +8,6 @@ const common = require('../common');
2509f6
 
2509f6
 const assert = require('assert');
2509f6
 const { exec } = require('child_process');
2509f6
-const { internalBinding } = require('internal/test/binding');
2509f6
-const { fipsMode } = internalBinding('config');
2509f6
 let stdOut;
2509f6
 
2509f6
 
2509f6
@@ -29,9 +27,8 @@ function validateNodePrintHelp() {
2509f6
   const cliHelpOptions = [
2509f6
     { compileConstant: HAVE_OPENSSL,
2509f6
       flags: [ '--openssl-config=...', '--tls-cipher-list=...',
2509f6
-               '--use-bundled-ca', '--use-openssl-ca' ] },
2509f6
-    { compileConstant: fipsMode,
2509f6
-      flags: [ '--enable-fips', '--force-fips' ] },
2509f6
+               '--use-bundled-ca', '--use-openssl-ca',
2509f6
+               '--enable-fips', '--force-fips' ] },
2509f6
     { compileConstant: NODE_HAVE_I18N_SUPPORT,
2509f6
       flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
2509f6
     { compileConstant: HAVE_INSPECTOR,
2509f6
diff --git a/test/parallel/test-crypto-fips.js b/test/parallel/test-crypto-fips.js
2509f6
index eae3134402..a1ed645184 100644
2509f6
--- a/test/parallel/test-crypto-fips.js
2509f6
+++ b/test/parallel/test-crypto-fips.js
2509f6
@@ -9,27 +9,20 @@ const spawnSync = require('child_process').spawnSync;
2509f6
 const path = require('path');
2509f6
 const fixtures = require('../common/fixtures');
2509f6
 const { internalBinding } = require('internal/test/binding');
2509f6
-const { fipsMode } = internalBinding('config');
2509f6
+const { testFipsCrypto } = internalBinding('crypto');
2509f6
 
2509f6
 const FIPS_ENABLED = 1;
2509f6
 const FIPS_DISABLED = 0;
2509f6
-const FIPS_ERROR_STRING =
2509f6
-  'Error [ERR_CRYPTO_FIPS_UNAVAILABLE]: Cannot set FIPS mode in a ' +
2509f6
-  'non-FIPS build.';
2509f6
 const FIPS_ERROR_STRING2 =
2509f6
   'Error [ERR_CRYPTO_FIPS_FORCED]: Cannot set FIPS mode, it was forced with ' +
2509f6
   '--force-fips at startup.';
2509f6
-const OPTION_ERROR_STRING = 'bad option';
2509f6
+const FIPS_UNSUPPORTED_ERROR_STRING = 'fips mode not supported';
2509f6
 
2509f6
 const CNF_FIPS_ON = fixtures.path('openssl_fips_enabled.cnf');
2509f6
 const CNF_FIPS_OFF = fixtures.path('openssl_fips_disabled.cnf');
2509f6
 
2509f6
 let num_children_ok = 0;
2509f6
 
2509f6
-function compiledWithFips() {
2509f6
-  return fipsMode ? true : false;
2509f6
-}
2509f6
-
2509f6
 function sharedOpenSSL() {
2509f6
   return process.config.variables.node_shared_openssl;
2509f6
 }
2509f6
@@ -75,17 +68,17 @@ testHelper(
2509f6
 
2509f6
 // --enable-fips should turn FIPS mode on
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--enable-fips'],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   process.env);
2509f6
 
2509f6
 // --force-fips should turn FIPS mode on
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--force-fips'],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   process.env);
2509f6
 
2509f6
@@ -106,7 +99,7 @@ if (!sharedOpenSSL()) {
2509f6
   testHelper(
2509f6
     'stdout',
2509f6
     [`--openssl-config=${CNF_FIPS_ON}`],
2509f6
-    compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
+    testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
     'require("crypto").getFips()',
2509f6
     process.env);
2509f6
 
2509f6
@@ -114,7 +107,7 @@ if (!sharedOpenSSL()) {
2509f6
   testHelper(
2509f6
     'stdout',
2509f6
     [],
2509f6
-    compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
+    testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
     'require("crypto").getFips()',
2509f6
     Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
2509f6
 
2509f6
@@ -122,7 +115,7 @@ if (!sharedOpenSSL()) {
2509f6
   testHelper(
2509f6
     'stdout',
2509f6
     [`--openssl-config=${CNF_FIPS_ON}`],
2509f6
-    compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
+    testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
2509f6
     'require("crypto").getFips()',
2509f6
     Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
2509f6
 }
2509f6
@@ -136,50 +129,50 @@ testHelper(
2509f6
 
2509f6
 // --enable-fips should take precedence over OpenSSL config file
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--enable-fips', `--openssl-config=${CNF_FIPS_OFF}`],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   process.env);
2509f6
 
2509f6
 // OPENSSL_CONF should _not_ make a difference to --enable-fips
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--enable-fips'],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
2509f6
 
2509f6
 // --force-fips should take precedence over OpenSSL config file
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--force-fips', `--openssl-config=${CNF_FIPS_OFF}`],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   process.env);
2509f6
 
2509f6
 // Using OPENSSL_CONF should not make a difference to --force-fips
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--force-fips'],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").getFips()',
2509f6
   Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
2509f6
 
2509f6
 // setFipsCrypto should be able to turn FIPS mode on
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   [],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   '(require("crypto").setFips(true),' +
2509f6
   'require("crypto").getFips())',
2509f6
   process.env);
2509f6
 
2509f6
 // setFipsCrypto should be able to turn FIPS mode on and off
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   [],
2509f6
-  compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   '(require("crypto").setFips(true),' +
2509f6
   'require("crypto").setFips(false),' +
2509f6
   'require("crypto").getFips())',
2509f6
@@ -187,27 +180,27 @@ testHelper(
2509f6
 
2509f6
 // setFipsCrypto takes precedence over OpenSSL config file, FIPS on
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   [`--openssl-config=${CNF_FIPS_OFF}`],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   '(require("crypto").setFips(true),' +
2509f6
   'require("crypto").getFips())',
2509f6
   process.env);
2509f6
 
2509f6
 // setFipsCrypto takes precedence over OpenSSL config file, FIPS off
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  'stdout',
2509f6
   [`--openssl-config=${CNF_FIPS_ON}`],
2509f6
-  compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
2509f6
+  FIPS_DISABLED,
2509f6
   '(require("crypto").setFips(false),' +
2509f6
   'require("crypto").getFips())',
2509f6
   process.env);
2509f6
 
2509f6
 // --enable-fips does not prevent use of setFipsCrypto API
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--enable-fips'],
2509f6
-  compiledWithFips() ? FIPS_DISABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   '(require("crypto").setFips(false),' +
2509f6
   'require("crypto").getFips())',
2509f6
   process.env);
2509f6
@@ -216,15 +209,15 @@ testHelper(
2509f6
 testHelper(
2509f6
   'stderr',
2509f6
   ['--force-fips'],
2509f6
-  compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").setFips(false)',
2509f6
   process.env);
2509f6
 
2509f6
 // --force-fips makes setFipsCrypto enable a no-op (FIPS stays on)
2509f6
 testHelper(
2509f6
-  compiledWithFips() ? 'stdout' : 'stderr',
2509f6
+  testFipsCrypto() ? 'stdout' : 'stderr',
2509f6
   ['--force-fips'],
2509f6
-  compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   '(require("crypto").setFips(true),' +
2509f6
   'require("crypto").getFips())',
2509f6
   process.env);
2509f6
@@ -233,7 +226,7 @@ testHelper(
2509f6
 testHelper(
2509f6
   'stderr',
2509f6
   ['--force-fips', '--enable-fips'],
2509f6
-  compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").setFips(false)',
2509f6
   process.env);
2509f6
 
2509f6
@@ -241,6 +234,6 @@ testHelper(
2509f6
 testHelper(
2509f6
   'stderr',
2509f6
   ['--enable-fips', '--force-fips'],
2509f6
-  compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
2509f6
+  testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
2509f6
   'require("crypto").setFips(false)',
2509f6
   process.env);
2509f6
diff --git a/test/parallel/test-process-env-allowed-flags-are-documented.js b/test/parallel/test-process-env-allowed-flags-are-documented.js
2509f6
index 0e0af9471c..af10809634 100644
2509f6
--- a/test/parallel/test-process-env-allowed-flags-are-documented.js
2509f6
+++ b/test/parallel/test-process-env-allowed-flags-are-documented.js
2509f6
@@ -44,17 +44,8 @@ const conditionalOpts = [
2509f6
   { include: common.hasCrypto,
2509f6
     filter: (opt) => {
2509f6
       return ['--openssl-config', '--tls-cipher-list', '--use-bundled-ca',
2509f6
-              '--use-openssl-ca' ].includes(opt);
2509f6
+              '--use-openssl-ca', '--enable-fips', '--force-fips' ].includes(opt);
2509f6
     } },
2509f6
-  {
2509f6
-    // We are using openssl_is_fips from the configuration because it could be
2509f6
-    // the case that OpenSSL is FIPS compatible but fips has not been enabled
2509f6
-    // (starting node with --enable-fips). If we use common.hasFipsCrypto
2509f6
-    // that would only tells us if fips has been enabled, but in this case we
2509f6
-    // want to check options which will be available regardless of whether fips
2509f6
-    // is enabled at runtime or not.
2509f6
-    include: process.config.variables.openssl_is_fips,
2509f6
-    filter: (opt) => opt.includes('-fips') },
2509f6
   { include: common.hasIntl,
2509f6
     filter: (opt) => opt === '--icu-data-dir' },
2509f6
   { include: process.features.inspector,
2509f6
-- 
2509f6
2.31.1
2509f6