Skip to content

Commit f392ac0

Browse files
voxikmhdawson
authored andcommittedFeb 25, 2021
crypto: make FIPS related options always awailable
There is no reason to hide FIPS functionality behind build flags. OpenSSL always provide the information about FIPS availability via `FIPS_mode()` function. This makes the user experience more consistent, because the OpenSSL library is always queried and the `crypto.getFips()` always returns OpenSSL settings. Fixes #34903 PR-URL: #36341 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent 148bc33 commit f392ac0

15 files changed

+76
-107
lines changed
 

‎doc/api/cli.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ code from strings throw an exception instead. This does not affect the Node.js
186186
added: v6.0.0
187187
-->
188188

189-
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with
190-
`./configure --openssl-fips`.)
189+
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built
190+
against FIPS-compatible OpenSSL.)
191191

192192
### `--enable-source-maps`
193193
<!-- YAML
@@ -613,8 +613,8 @@ added: v6.9.0
613613
-->
614614

615615
Load an OpenSSL configuration file on startup. Among other uses, this can be
616-
used to enable FIPS-compliant crypto if Node.js is built with
617-
`./configure --openssl-fips`.
616+
used to enable FIPS-compliant crypto if Node.js is built
617+
against FIPS-enabled OpenSSL.
618618

619619
### `--pending-deprecation`
620620
<!-- YAML

‎lib/crypto.js

+4-18
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ assertCrypto();
3737

3838
const {
3939
ERR_CRYPTO_FIPS_FORCED,
40-
ERR_CRYPTO_FIPS_UNAVAILABLE
4140
} = require('internal/errors').codes;
4241
const constants = internalBinding('constants').crypto;
4342
const { getOptionValue } = require('internal/options');
4443
const pendingDeprecation = getOptionValue('--pending-deprecation');
45-
const { fipsMode } = internalBinding('config');
4644
const fipsForced = getOptionValue('--force-fips');
4745
const {
4846
getFipsCrypto,
@@ -218,10 +216,8 @@ module.exports = {
218216
sign: signOneShot,
219217
setEngine,
220218
timingSafeEqual,
221-
getFips: !fipsMode ? getFipsDisabled :
222-
fipsForced ? getFipsForced : getFipsCrypto,
223-
setFips: !fipsMode ? setFipsDisabled :
224-
fipsForced ? setFipsForced : setFipsCrypto,
219+
getFips: fipsForced ? getFipsForced : getFipsCrypto,
220+
setFips: fipsForced ? setFipsForced : setFipsCrypto,
225221
verify: verifyOneShot,
226222

227223
// Classes
@@ -242,19 +238,11 @@ module.exports = {
242238
secureHeapUsed,
243239
};
244240

245-
function setFipsDisabled() {
246-
throw new ERR_CRYPTO_FIPS_UNAVAILABLE();
247-
}
248-
249241
function setFipsForced(val) {
250242
if (val) return;
251243
throw new ERR_CRYPTO_FIPS_FORCED();
252244
}
253245

254-
function getFipsDisabled() {
255-
return 0;
256-
}
257-
258246
function getFipsForced() {
259247
return 1;
260248
}
@@ -276,10 +264,8 @@ ObjectDefineProperties(module.exports, {
276264
},
277265
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
278266
fips: {
279-
get: !fipsMode ? getFipsDisabled :
280-
fipsForced ? getFipsForced : getFipsCrypto,
281-
set: !fipsMode ? setFipsDisabled :
282-
fipsForced ? setFipsForced : setFipsCrypto
267+
get: fipsForced ? getFipsForced : getFipsCrypto,
268+
set: fipsForced ? setFipsForced : setFipsCrypto
283269
},
284270
DEFAULT_ENCODING: {
285271
enumerable: false,

‎node.gypi

-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@
319319
[ 'node_use_openssl=="true"', {
320320
'defines': [ 'HAVE_OPENSSL=1' ],
321321
'conditions': [
322-
['openssl_fips != "" or openssl_is_fips=="true"', {
323-
'defines': [ 'NODE_FIPS_MODE' ],
324-
}],
325322
[ 'node_shared_openssl=="false"', {
326323
'dependencies': [
327324
'./deps/openssl/openssl.gyp:openssl',

‎src/crypto/crypto_cipher.cc

-4
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,10 @@ void CipherBase::Init(const char* cipher_type,
343343
HandleScope scope(env()->isolate());
344344
MarkPopErrorOnReturn mark_pop_error_on_return;
345345

346-
#ifdef NODE_FIPS_MODE
347346
if (FIPS_mode()) {
348347
return THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env(),
349348
"crypto.createCipher() is not supported in FIPS mode.");
350349
}
351-
#endif // NODE_FIPS_MODE
352350

353351
const EVP_CIPHER* const cipher = EVP_get_cipherbyname(cipher_type);
354352
if (cipher == nullptr)
@@ -528,14 +526,12 @@ bool CipherBase::InitAuthenticated(
528526
return false;
529527
}
530528

531-
#ifdef NODE_FIPS_MODE
532529
// TODO(tniessen) Support CCM decryption in FIPS mode
533530
if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode()) {
534531
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env(),
535532
"CCM encryption not supported in FIPS mode");
536533
return false;
537534
}
538-
#endif
539535

540536
// Tell OpenSSL about the desired length.
541537
if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,

‎src/crypto/crypto_sig.cc

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ using v8::Value;
2727
namespace crypto {
2828
namespace {
2929
bool ValidateDSAParameters(EVP_PKEY* key) {
30-
#ifdef NODE_FIPS_MODE
3130
/* Validate DSA2 parameters from FIPS 186-4 */
3231
if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) {
3332
DSA* dsa = EVP_PKEY_get0_DSA(key);
@@ -43,7 +42,6 @@ bool ValidateDSAParameters(EVP_PKEY* key) {
4342
(L == 2048 && N == 256) ||
4443
(L == 3072 && N == 256);
4544
}
46-
#endif // NODE_FIPS_MODE
4745

4846
return true;
4947
}

‎src/crypto/crypto_util.cc

+14-10
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ void InitCryptoOnce() {
133133
}
134134
#endif
135135

136-
#ifdef NODE_FIPS_MODE
137136
/* Override FIPS settings in cnf file, if needed. */
138137
unsigned long err = 0; // NOLINT(runtime/int)
139138
if (per_process::cli_options->enable_fips_crypto ||
@@ -143,12 +142,10 @@ void InitCryptoOnce() {
143142
}
144143
}
145144
if (0 != err) {
146-
fprintf(stderr,
147-
"openssl fips failed: %s\n",
148-
ERR_error_string(err, nullptr));
149-
UNREACHABLE();
145+
auto* isolate = Isolate::GetCurrent();
146+
auto* env = Environment::GetCurrent(isolate);
147+
return ThrowCryptoError(env, err);
150148
}
151-
#endif // NODE_FIPS_MODE
152149

153150
// Turn off compression. Saves memory and protects against CRIME attacks.
154151
// No-op with OPENSSL_NO_COMP builds of OpenSSL.
@@ -162,7 +159,6 @@ void InitCryptoOnce() {
162159
NodeBIO::GetMethod();
163160
}
164161

165-
#ifdef NODE_FIPS_MODE
166162
void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
167163
args.GetReturnValue().Set(FIPS_mode() ? 1 : 0);
168164
}
@@ -180,7 +176,16 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
180176
return ThrowCryptoError(env, err);
181177
}
182178
}
183-
#endif /* NODE_FIPS_MODE */
179+
180+
void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args) {
181+
#ifdef OPENSSL_FIPS
182+
const auto enabled = FIPS_selftest() ? 1 : 0;
183+
#else // OPENSSL_FIPS
184+
const auto enabled = 0;
185+
#endif // OPENSSL_FIPS
186+
187+
args.GetReturnValue().Set(enabled);
188+
}
184189

185190
void CryptoErrorVector::Capture() {
186191
clear();
@@ -652,10 +657,9 @@ void Initialize(Environment* env, Local<Object> target) {
652657
env->SetMethod(target, "setEngine", SetEngine);
653658
#endif // !OPENSSL_NO_ENGINE
654659

655-
#ifdef NODE_FIPS_MODE
656660
env->SetMethodNoSideEffect(target, "getFipsCrypto", GetFipsCrypto);
657661
env->SetMethod(target, "setFipsCrypto", SetFipsCrypto);
658-
#endif
662+
env->SetMethodNoSideEffect(target, "testFipsCrypto", TestFipsCrypto);
659663

660664
NODE_DEFINE_CONSTANT(target, kCryptoJobAsync);
661665
NODE_DEFINE_CONSTANT(target, kCryptoJobSync);

‎src/crypto/crypto_util.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#ifndef OPENSSL_NO_ENGINE
2323
# include <openssl/engine.h>
2424
#endif // !OPENSSL_NO_ENGINE
25+
// The FIPS-related functions are only available
26+
// when the OpenSSL itself was compiled with FIPS support.
27+
#ifdef OPENSSL_FIPS
28+
# include <openssl/fips.h>
29+
#endif // OPENSSL_FIPS
2530

2631
#include <algorithm>
2732
#include <memory>
@@ -510,11 +515,11 @@ bool SetEngine(
510515
void SetEngine(const v8::FunctionCallbackInfo<v8::Value>& args);
511516
#endif // !OPENSSL_NO_ENGINE
512517

513-
#ifdef NODE_FIPS_MODE
514518
void GetFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
515519

516520
void SetFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
517-
#endif /* NODE_FIPS_MODE */
521+
522+
void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
518523

519524
class CipherPushContext {
520525
public:

‎src/node.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,11 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
10131013
if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs))
10141014
crypto::UseExtraCaCerts(extra_ca_certs);
10151015
}
1016-
#ifdef NODE_FIPS_MODE
10171016
// In the case of FIPS builds we should make sure
10181017
// the random source is properly initialized first.
1019-
OPENSSL_init();
1020-
#endif // NODE_FIPS_MODE
1018+
if (FIPS_mode()) {
1019+
OPENSSL_init();
1020+
}
10211021
// V8 on Windows doesn't have a good source of entropy. Seed it from
10221022
// OpenSSL's pool.
10231023
V8::SetEntropySource(crypto::EntropySource);

‎src/node_config.cc

-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ static void Initialize(Local<Object> target,
4242
READONLY_FALSE_PROPERTY(target, "hasOpenSSL");
4343
#endif // HAVE_OPENSSL
4444

45-
#ifdef NODE_FIPS_MODE
4645
READONLY_TRUE_PROPERTY(target, "fipsMode");
47-
#endif
4846

4947
#ifdef NODE_HAVE_I18N_SUPPORT
5048

‎src/node_crypto.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace node {
3131
using v8::Context;
3232
using v8::Local;
3333
using v8::Object;
34+
using v8::TryCatch;
3435
using v8::Value;
3536

3637
namespace crypto {
@@ -39,10 +40,15 @@ void Initialize(Local<Object> target,
3940
Local<Value> unused,
4041
Local<Context> context,
4142
void* priv) {
43+
Environment* env = Environment::GetCurrent(context);
44+
4245
static uv_once_t init_once = UV_ONCE_INIT;
46+
TryCatch try_catch{env->isolate()};
4347
uv_once(&init_once, InitCryptoOnce);
44-
45-
Environment* env = Environment::GetCurrent(context);
48+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
49+
try_catch.ReThrow();
50+
return;
51+
}
4652

4753
AES::Initialize(env, target);
4854
CipherBase::Initialize(env, target);

‎src/node_options.cc

-2
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
766766
&PerProcessOptions::ssl_openssl_cert_store);
767767
Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
768768
ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]");
769-
#if NODE_FIPS_MODE
770769
AddOption("--enable-fips",
771770
"enable FIPS crypto at startup",
772771
&PerProcessOptions::enable_fips_crypto,
@@ -775,7 +774,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
775774
"force FIPS crypto (cannot be disabled)",
776775
&PerProcessOptions::force_fips_crypto,
777776
kAllowedInEnvironment);
778-
#endif
779777
AddOption("--secure-heap",
780778
"total size of the OpenSSL secure heap",
781779
&PerProcessOptions::secure_heap,

‎src/node_options.h

-2
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,8 @@ class PerProcessOptions : public Options {
245245
#endif
246246
bool use_openssl_ca = false;
247247
bool use_bundled_ca = false;
248-
#if NODE_FIPS_MODE
249248
bool enable_fips_crypto = false;
250249
bool force_fips_crypto = false;
251-
#endif
252250
#endif
253251

254252
// Per-process because reports can be triggered outside a known V8 context.

‎test/parallel/test-cli-node-print-help.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const common = require('../common');
88

99
const assert = require('assert');
1010
const { exec } = require('child_process');
11-
const { internalBinding } = require('internal/test/binding');
12-
const { fipsMode } = internalBinding('config');
1311
let stdOut;
1412

1513

@@ -28,9 +26,8 @@ function validateNodePrintHelp() {
2826
const cliHelpOptions = [
2927
{ compileConstant: HAVE_OPENSSL,
3028
flags: [ '--openssl-config=...', '--tls-cipher-list=...',
31-
'--use-bundled-ca', '--use-openssl-ca' ] },
32-
{ compileConstant: fipsMode,
33-
flags: [ '--enable-fips', '--force-fips' ] },
29+
'--use-bundled-ca', '--use-openssl-ca',
30+
'--enable-fips', '--force-fips' ] },
3431
{ compileConstant: NODE_HAVE_I18N_SUPPORT,
3532
flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
3633
{ compileConstant: HAVE_INSPECTOR,

‎test/parallel/test-crypto-fips.js

+32-39
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,20 @@ const spawnSync = require('child_process').spawnSync;
99
const path = require('path');
1010
const fixtures = require('../common/fixtures');
1111
const { internalBinding } = require('internal/test/binding');
12-
const { fipsMode } = internalBinding('config');
12+
const { testFipsCrypto } = internalBinding('crypto');
1313

1414
const FIPS_ENABLED = 1;
1515
const FIPS_DISABLED = 0;
16-
const FIPS_ERROR_STRING =
17-
'Error [ERR_CRYPTO_FIPS_UNAVAILABLE]: Cannot set FIPS mode in a ' +
18-
'non-FIPS build.';
1916
const FIPS_ERROR_STRING2 =
2017
'Error [ERR_CRYPTO_FIPS_FORCED]: Cannot set FIPS mode, it was forced with ' +
2118
'--force-fips at startup.';
22-
const OPTION_ERROR_STRING = 'bad option';
19+
const FIPS_UNSUPPORTED_ERROR_STRING = 'fips mode not supported';
2320

2421
const CNF_FIPS_ON = fixtures.path('openssl_fips_enabled.cnf');
2522
const CNF_FIPS_OFF = fixtures.path('openssl_fips_disabled.cnf');
2623

2724
let num_children_ok = 0;
2825

29-
function compiledWithFips() {
30-
return fipsMode ? true : false;
31-
}
32-
3326
function sharedOpenSSL() {
3427
return process.config.variables.node_shared_openssl;
3528
}
@@ -75,17 +68,17 @@ testHelper(
7568

7669
// --enable-fips should turn FIPS mode on
7770
testHelper(
78-
compiledWithFips() ? 'stdout' : 'stderr',
71+
testFipsCrypto() ? 'stdout' : 'stderr',
7972
['--enable-fips'],
80-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
73+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
8174
'require("crypto").getFips()',
8275
process.env);
8376

8477
// --force-fips should turn FIPS mode on
8578
testHelper(
86-
compiledWithFips() ? 'stdout' : 'stderr',
79+
testFipsCrypto() ? 'stdout' : 'stderr',
8780
['--force-fips'],
88-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
81+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
8982
'require("crypto").getFips()',
9083
process.env);
9184

@@ -106,23 +99,23 @@ if (!sharedOpenSSL()) {
10699
testHelper(
107100
'stdout',
108101
[`--openssl-config=${CNF_FIPS_ON}`],
109-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
102+
testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
110103
'require("crypto").getFips()',
111104
process.env);
112105

113106
// OPENSSL_CONF should be able to turn on FIPS mode
114107
testHelper(
115108
'stdout',
116109
[],
117-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
110+
testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
118111
'require("crypto").getFips()',
119112
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON }));
120113

121114
// --openssl-config option should override OPENSSL_CONF
122115
testHelper(
123116
'stdout',
124117
[`--openssl-config=${CNF_FIPS_ON}`],
125-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
118+
testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED,
126119
'require("crypto").getFips()',
127120
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
128121
}
@@ -136,78 +129,78 @@ testHelper(
136129

137130
// --enable-fips should take precedence over OpenSSL config file
138131
testHelper(
139-
compiledWithFips() ? 'stdout' : 'stderr',
132+
testFipsCrypto() ? 'stdout' : 'stderr',
140133
['--enable-fips', `--openssl-config=${CNF_FIPS_OFF}`],
141-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
134+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
142135
'require("crypto").getFips()',
143136
process.env);
144137

145138
// OPENSSL_CONF should _not_ make a difference to --enable-fips
146139
testHelper(
147-
compiledWithFips() ? 'stdout' : 'stderr',
140+
testFipsCrypto() ? 'stdout' : 'stderr',
148141
['--enable-fips'],
149-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
142+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
150143
'require("crypto").getFips()',
151144
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
152145

153146
// --force-fips should take precedence over OpenSSL config file
154147
testHelper(
155-
compiledWithFips() ? 'stdout' : 'stderr',
148+
testFipsCrypto() ? 'stdout' : 'stderr',
156149
['--force-fips', `--openssl-config=${CNF_FIPS_OFF}`],
157-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
150+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
158151
'require("crypto").getFips()',
159152
process.env);
160153

161154
// Using OPENSSL_CONF should not make a difference to --force-fips
162155
testHelper(
163-
compiledWithFips() ? 'stdout' : 'stderr',
156+
testFipsCrypto() ? 'stdout' : 'stderr',
164157
['--force-fips'],
165-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
158+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
166159
'require("crypto").getFips()',
167160
Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF }));
168161

169162
// setFipsCrypto should be able to turn FIPS mode on
170163
testHelper(
171-
compiledWithFips() ? 'stdout' : 'stderr',
164+
testFipsCrypto() ? 'stdout' : 'stderr',
172165
[],
173-
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
166+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
174167
'(require("crypto").setFips(true),' +
175168
'require("crypto").getFips())',
176169
process.env);
177170

178171
// setFipsCrypto should be able to turn FIPS mode on and off
179172
testHelper(
180-
compiledWithFips() ? 'stdout' : 'stderr',
173+
testFipsCrypto() ? 'stdout' : 'stderr',
181174
[],
182-
compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
175+
testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING,
183176
'(require("crypto").setFips(true),' +
184177
'require("crypto").setFips(false),' +
185178
'require("crypto").getFips())',
186179
process.env);
187180

188181
// setFipsCrypto takes precedence over OpenSSL config file, FIPS on
189182
testHelper(
190-
compiledWithFips() ? 'stdout' : 'stderr',
183+
testFipsCrypto() ? 'stdout' : 'stderr',
191184
[`--openssl-config=${CNF_FIPS_OFF}`],
192-
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
185+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
193186
'(require("crypto").setFips(true),' +
194187
'require("crypto").getFips())',
195188
process.env);
196189

197190
// setFipsCrypto takes precedence over OpenSSL config file, FIPS off
198191
testHelper(
199-
compiledWithFips() ? 'stdout' : 'stderr',
192+
'stdout',
200193
[`--openssl-config=${CNF_FIPS_ON}`],
201-
compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
194+
FIPS_DISABLED,
202195
'(require("crypto").setFips(false),' +
203196
'require("crypto").getFips())',
204197
process.env);
205198

206199
// --enable-fips does not prevent use of setFipsCrypto API
207200
testHelper(
208-
compiledWithFips() ? 'stdout' : 'stderr',
201+
testFipsCrypto() ? 'stdout' : 'stderr',
209202
['--enable-fips'],
210-
compiledWithFips() ? FIPS_DISABLED : OPTION_ERROR_STRING,
203+
testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING,
211204
'(require("crypto").setFips(false),' +
212205
'require("crypto").getFips())',
213206
process.env);
@@ -216,15 +209,15 @@ testHelper(
216209
testHelper(
217210
'stderr',
218211
['--force-fips'],
219-
compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
212+
testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
220213
'require("crypto").setFips(false)',
221214
process.env);
222215

223216
// --force-fips makes setFipsCrypto enable a no-op (FIPS stays on)
224217
testHelper(
225-
compiledWithFips() ? 'stdout' : 'stderr',
218+
testFipsCrypto() ? 'stdout' : 'stderr',
226219
['--force-fips'],
227-
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
220+
testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING,
228221
'(require("crypto").setFips(true),' +
229222
'require("crypto").getFips())',
230223
process.env);
@@ -233,14 +226,14 @@ testHelper(
233226
testHelper(
234227
'stderr',
235228
['--force-fips', '--enable-fips'],
236-
compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
229+
testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
237230
'require("crypto").setFips(false)',
238231
process.env);
239232

240233
// --enable-fips and --force-fips order does not matter
241234
testHelper(
242235
'stderr',
243236
['--enable-fips', '--force-fips'],
244-
compiledWithFips() ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING,
237+
testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING,
245238
'require("crypto").setFips(false)',
246239
process.env);

‎test/parallel/test-process-env-allowed-flags-are-documented.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,10 @@ const conditionalOpts = [
5151
'--use-openssl-ca',
5252
'--secure-heap',
5353
'--secure-heap-min',
54+
'--enable-fips',
55+
'--force-fips',
5456
].includes(opt);
5557
}
56-
}, {
57-
// We are using openssl_is_fips from the configuration because it could be
58-
// the case that OpenSSL is FIPS compatible but fips has not been enabled
59-
// (starting node with --enable-fips). If we use common.hasFipsCrypto
60-
// that would only tells us if fips has been enabled, but in this case we
61-
// want to check options which will be available regardless of whether fips
62-
// is enabled at runtime or not.
63-
include: process.config.variables.openssl_is_fips,
64-
filter: (opt) => opt.includes('-fips')
6558
}, {
6659
include: common.hasIntl,
6760
filter: (opt) => opt === '--icu-data-dir'

0 commit comments

Comments
 (0)
Please sign in to comment.