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