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

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