Skip to content

Commit e7c0957

Browse files
panvaaduh95
authored andcommitted
crypto: remove the FIPS provider name check
FIPS-capable providers can use names other than fips. Remove the named-provider lookup and explicit self-test from the startup flags, leaving algorithm availability checks to each operation. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #67358 Backport-PR-URL: #67442 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 7265f62 commit e7c0957

6 files changed

Lines changed: 97 additions & 62 deletions

File tree

‎doc/api/cli.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,11 @@ priority than `--dns-result-order`.
11771177
added: v6.0.0
11781178
-->
11791179

1180-
Enable [FIPS mode][] at startup. With OpenSSL 3, a configured provider named
1181-
`fips` must be available and initialize successfully. With OpenSSL 1.1.1,
1182-
Node.js must be built against a FIPS-capable OpenSSL.
1180+
Enable [FIPS mode][] at startup. With OpenSSL 3, this adds `fips=yes` to
1181+
OpenSSL's default property query. This does not load or validate a FIPS
1182+
provider or run its self-tests. Configure OpenSSL to load the provider
1183+
separately. With OpenSSL 1.1.1, Node.js must be built against a FIPS-capable
1184+
OpenSSL.
11831185

11841186
### `--enable-fips-indicator-events`
11851187

@@ -1745,7 +1747,8 @@ changes:
17451747
-->
17461748

17471749
Enable [FIPS mode][] at startup and prevent it from being disabled from script
1748-
code. The same OpenSSL requirements as [`--enable-fips`][] apply.
1750+
code. With OpenSSL 3, this changes the default property query as described for
1751+
[`--enable-fips`][].
17491752

17501753
An optional mode can be specified using `--force-fips=mode`:
17511754

‎doc/api/crypto.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,9 +6794,9 @@ OpenSSL-backed APIs.
67946794
This method only affects subsequent algorithm fetches. Node.js initializes some
67956795
OpenSSL state before application code runs. When the property query must be
67966796
active from process startup, set `default_properties = fips=yes` in the OpenSSL
6797-
configuration or use [`--enable-fips`][] or [`--force-fips`][]. The command-line
6798-
flags additionally require a configured provider named `fips` to initialize and
6799-
pass its self-test; Node.js fails to start otherwise.
6797+
configuration or use [`--enable-fips`][] or [`--force-fips`][]. Like this method,
6798+
the command-line flags change the property query without loading or validating
6799+
a provider or running its self-tests.
68006800

68016801
Throws an error if OpenSSL cannot change the state. FIPS mode cannot be
68026802
disabled when Node.js was started with `--force-fips`. With OpenSSL 1.1.1,
@@ -7436,10 +7436,9 @@ default section name.
74367436
On OpenSSL 3, the configuration above enables the `fips=yes` property query at
74377437
startup. The following controls are also available:
74387438

7439-
* [`--enable-fips`][] and [`--force-fips`][] enable the property query and
7440-
additionally require the configured provider named `fips` to initialize and
7441-
pass its self-test. Node.js exits if that check fails. `--force-fips` also
7442-
prevents FIPS mode from being disabled from script code. With
7439+
* [`--enable-fips`][] and [`--force-fips`][] enable the property query at startup.
7440+
They do not load or validate a provider or run its self-tests. `--force-fips`
7441+
also prevents FIPS mode from being disabled from script code. With
74437442
`--force-fips=strict`, Node.js also rejects non-approved operations reported
74447443
through the OpenSSL FIPS indicator callback.
74457444
* [`crypto.setFips()`][] changes the FIPS/property-query state. On OpenSSL 3, it

‎doc/node.1‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,11 @@ The default is \fBverbatim\fR and \fBdns.setDefaultResultOrder()\fR have higher
710710
priority than \fB--dns-result-order\fR.
711711
.
712712
.It Fl -enable-fips
713-
Enable FIPS mode at startup. With OpenSSL 3, a configured provider named
714-
\fBfips\fR must be available and initialize successfully. With OpenSSL 1.1.1,
715-
Node.js must be built against a FIPS-capable OpenSSL.
713+
Enable FIPS mode at startup. With OpenSSL 3, this adds \fBfips=yes\fR to
714+
OpenSSL's default property query. This does not load or validate a FIPS
715+
provider or run its self-tests. Configure OpenSSL to load the provider
716+
separately. With OpenSSL 1.1.1, Node.js must be built against a FIPS-capable
717+
OpenSSL.
716718
.
717719
.It Fl -enable-fips-indicator-events
718720
Publish OpenSSL FIPS indicator results to the
@@ -929,7 +931,8 @@ Disable loading native addons that are not context-aware.
929931
.
930932
.It Fl -force-fips Ns = Ns Ar [mode]
931933
Enable FIPS mode at startup and prevent it from being disabled from script
932-
code. The same OpenSSL requirements as \fB--enable-fips\fR apply.
934+
code. With OpenSSL 3, this changes the default property query as described for
935+
\fB--enable-fips\fR.
933936
An optional mode can be specified using \fB--force-fips=mode\fR:
934937
.Bl -bullet
935938
.It

‎src/crypto/crypto_util.cc‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,6 @@ std::optional<std::string> ProcessFipsOptions() {
451451
const bool force_fips = per_process::cli_options->force_fips_crypto;
452452
if (!enable_fips && !force_fips) return std::nullopt;
453453

454-
#if OPENSSL_VERSION_MAJOR >= 3
455-
// Whether FIPS-approved implementations are reachable is decided by the
456-
// OpenSSL configuration, not by Node.js. Refuse to start rather than
457-
// restrict the default property query to a provider that is not there,
458-
// which would leave every operation failing as unsupported.
459-
if (!ncrypto::testFipsEnabled()) {
460-
const std::string option = force_fips ? "--force-fips" : "--enable-fips";
461-
return option + " requires an active OpenSSL provider named \"fips\". "
462-
"FIPS mode is configured through OpenSSL; see "
463-
"https://nodejs.org/api/crypto.html#fips-mode";
464-
}
465-
#endif
466-
467454
CryptoErrorList errors{CryptoErrorList::Option::NONE};
468455
if (!ncrypto::setFipsEnabled(true, &errors)) {
469456
std::string error = "OpenSSL error when trying to enable FIPS";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
nodejs_conf = nodejs_init
2+
openssl_conf = nodejs_init
3+
4+
[nodejs_init]
5+
providers = provider_sect
6+
random = random_sect
7+
8+
[provider_sect]
9+
default = default_sect
10+
11+
[default_sect]
12+
activate = 1
13+
14+
# Allow startup randomness while other operations use the default properties.
15+
[random_sect]
16+
properties = fips=no
17+
seed_properties = fips=no

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

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ if (isBoringSSL)
1212
const assert = require('assert');
1313
const spawnSync = require('child_process').spawnSync;
1414
const path = require('path');
15-
const { spawnSyncAndAssert } = require('../common/child_process');
1615
const fixtures = require('../common/fixtures');
16+
const { spawnSyncAndAssert } = require('../common/child_process');
1717
const { internalBinding } = require('internal/test/binding');
1818
const { testFipsCrypto } = internalBinding('crypto');
1919

@@ -78,32 +78,66 @@ function testHelper(stream, args, expectedStatus, expectedOutput, cmd, env) {
7878
responseHandler(child[stream], expectedOutput);
7979
}
8080

81-
// --enable-fips should raise an error if OpenSSL is not FIPS enabled.
82-
testHelper(
83-
testFipsCrypto() ? 'stdout' : 'stderr',
84-
['--enable-fips'],
85-
testFipsCrypto() ? kNoFailure : kGenericUserError,
86-
testFipsCrypto() ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING,
87-
'require("crypto").getFips()',
88-
process.env);
81+
if (hasOpenSSL(3)) {
82+
const fipsFlags = ['--enable-fips', '--force-fips', '--force-fips=provider'];
83+
if (hasOpenSSL(3, 4))
84+
fipsFlags.push('--force-fips=strict');
85+
86+
// The flags change the default property query without requiring a provider
87+
// named "fips". This configuration supplies the RNG needed during startup,
88+
// but has no cryptographic implementations matching fips=yes.
89+
for (const flag of fipsFlags) {
90+
spawnSyncAndAssert(process.execPath, [
91+
flag,
92+
`--openssl-config=${fixtures.path('openssl3-conf', 'fips_no_provider.cnf')}`,
93+
'-e', `
94+
const assert = require('assert');
95+
const crypto = require('crypto');
96+
assert.strictEqual(crypto.getFips(), 1);
97+
assert.throws(() => crypto.createHash('sha256'), {
98+
code: 'ERR_OSSL_EVP_UNSUPPORTED',
99+
});
100+
if (${flag === '--enable-fips'}) {
101+
crypto.setFips(false);
102+
assert.strictEqual(crypto.getFips(), 0);
103+
crypto.createHash('sha256');
104+
} else {
105+
assert.throws(() => crypto.setFips(false), {
106+
code: 'ERR_CRYPTO_FIPS_FORCED',
107+
});
108+
assert.strictEqual(crypto.getFips(), 1);
109+
}
110+
`,
111+
], { stdout: '', stderr: '' });
112+
}
113+
} else {
114+
// --enable-fips should raise an error if OpenSSL is not FIPS enabled.
115+
testHelper(
116+
testFipsCrypto() ? 'stdout' : 'stderr',
117+
['--enable-fips'],
118+
testFipsCrypto() ? kNoFailure : kGenericUserError,
119+
testFipsCrypto() ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING,
120+
'require("crypto").getFips()',
121+
process.env);
89122

90-
// --force-fips should raise an error if OpenSSL is not FIPS enabled.
91-
testHelper(
92-
testFipsCrypto() ? 'stdout' : 'stderr',
93-
['--force-fips'],
94-
testFipsCrypto() ? kNoFailure : kGenericUserError,
95-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
96-
'require("crypto").getFips()',
97-
process.env);
123+
// --force-fips should raise an error if OpenSSL is not FIPS enabled.
124+
testHelper(
125+
testFipsCrypto() ? 'stdout' : 'stderr',
126+
['--force-fips'],
127+
testFipsCrypto() ? kNoFailure : kGenericUserError,
128+
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
129+
'require("crypto").getFips()',
130+
process.env);
98131

99-
// Explicit provider mode should preserve the behavior of bare --force-fips.
100-
testHelper(
101-
testFipsCrypto() ? 'stdout' : 'stderr',
102-
['--force-fips=provider'],
103-
testFipsCrypto() ? kNoFailure : kGenericUserError,
104-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
105-
'require("crypto").getFips()',
106-
process.env);
132+
// Explicit provider mode should preserve the behavior of bare --force-fips.
133+
testHelper(
134+
testFipsCrypto() ? 'stdout' : 'stderr',
135+
['--force-fips=provider'],
136+
testFipsCrypto() ? kNoFailure : kGenericUserError,
137+
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
138+
'require("crypto").getFips()',
139+
process.env);
140+
}
107141

108142
{
109143
spawnSyncAndAssert(
@@ -113,15 +147,7 @@ testHelper(
113147
});
114148
}
115149

116-
if (hasOpenSSL(3, 4)) {
117-
testHelper(
118-
testFipsCrypto() ? 'stdout' : 'stderr',
119-
['--force-fips=strict'],
120-
testFipsCrypto() ? kNoFailure : kGenericUserError,
121-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
122-
'require("crypto").getFips()',
123-
process.env);
124-
} else {
150+
if (!hasOpenSSL(3, 4)) {
125151
spawnSyncAndAssert(
126152
process.execPath, ['--enable-fips-indicator-events', '-e', '0'], {
127153
status: 9,

0 commit comments

Comments
 (0)