Skip to content

Commit dc6b820

Browse files
authored
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 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 2336a1f commit dc6b820

6 files changed

Lines changed: 66 additions & 66 deletions

File tree

‎doc/api/cli.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,9 @@ priority than `--dns-result-order`.
12321232
added: v6.0.0
12331233
-->
12341234

1235-
Enable [FIPS mode][] at startup. A configured provider named `fips` must be
1236-
available and initialize successfully.
1235+
Enable [FIPS mode][] at startup by adding `fips=yes` to OpenSSL's default
1236+
property query. This does not load or validate a FIPS provider or run its
1237+
self-tests. Configure OpenSSL to load the provider separately.
12371238

12381239
### `--enable-fips-indicator-events`
12391240

@@ -1799,7 +1800,8 @@ changes:
17991800
-->
18001801

18011802
Enable [FIPS mode][] at startup and prevent it from being disabled from script
1802-
code. The same OpenSSL requirements as [`--enable-fips`][] apply.
1803+
code. This changes the default property query as described for
1804+
[`--enable-fips`][].
18031805

18041806
An optional mode can be specified using `--force-fips=mode`:
18051807

‎doc/api/crypto.md‎

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

70897089
Throws an error if OpenSSL cannot change the state. FIPS mode cannot be
70907090
disabled when Node.js was started with `--force-fips`.
@@ -7731,10 +7731,9 @@ default section name.
77317731
The configuration above enables the `fips=yes` property query at startup. The
77327732
following controls are also available:
77337733

7734-
* [`--enable-fips`][] and [`--force-fips`][] enable the property query and
7735-
additionally require the configured provider named `fips` to initialize and
7736-
pass its self-test. Node.js exits if that check fails. `--force-fips` also
7737-
prevents FIPS mode from being disabled from script code. With
7734+
* [`--enable-fips`][] and [`--force-fips`][] enable the property query at startup.
7735+
They do not load or validate a provider or run its self-tests. `--force-fips`
7736+
also prevents FIPS mode from being disabled from script code. With
77387737
`--force-fips=strict`, Node.js also rejects non-approved operations reported
77397738
through the OpenSSL FIPS indicator callback.
77407739
* [`crypto.setFips()`][] changes the FIPS/property-query state. It does not

‎doc/node.1‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,9 @@ The default is \fBverbatim\fR and \fBdns.setDefaultResultOrder()\fR have higher
750750
priority than \fB--dns-result-order\fR.
751751
.
752752
.It Fl -enable-fips
753-
Enable FIPS mode at startup. A configured provider named \fBfips\fR must be
754-
available and initialize successfully.
753+
Enable FIPS mode at startup by adding \fBfips=yes\fR to OpenSSL's default
754+
property query. This does not load or validate a FIPS provider or run its
755+
self-tests. Configure OpenSSL to load the provider separately.
755756
.
756757
.It Fl -enable-fips-indicator-events
757758
Publish OpenSSL FIPS indicator results to the
@@ -962,7 +963,8 @@ Disable loading native addons that are not context-aware.
962963
.
963964
.It Fl -force-fips Ns = Ns Ar [mode]
964965
Enable FIPS mode at startup and prevent it from being disabled from script
965-
code. The same OpenSSL requirements as \fB--enable-fips\fR apply.
966+
code. This changes the default property query as described for
967+
\fB--enable-fips\fR.
966968
An optional mode can be specified using \fB--force-fips=mode\fR:
967969
.Bl -bullet
968970
.It

‎src/crypto/crypto_util.cc‎

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

451-
#ifndef OPENSSL_IS_BORINGSSL
452-
// Whether FIPS-approved implementations are reachable is decided by the
453-
// OpenSSL configuration, not by Node.js. Refuse to start rather than
454-
// restrict the default property query to a provider that is not there,
455-
// which would leave every operation failing as unsupported.
456-
if (!ncrypto::testFipsEnabled()) {
457-
const std::string option = force_fips ? "--force-fips" : "--enable-fips";
458-
return option + " requires an active OpenSSL provider named \"fips\". "
459-
"FIPS mode is configured through OpenSSL; see "
460-
"https://nodejs.org/api/crypto.html#fips-mode";
461-
}
462-
#endif
463-
464451
CryptoErrorList errors{CryptoErrorList::Option::NONE};
465452
if (!ncrypto::setFipsEnabled(true, &errors)) {
466453
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: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ if (isBoringSSL)
1212
const assert = require('assert');
1313
const spawnSync = require('child_process').spawnSync;
1414
const path = require('path');
15+
const fixtures = require('../common/fixtures');
1516
const { spawnSyncAndAssert } = require('../common/child_process');
1617
const { internalBinding } = require('internal/test/binding');
1718
const { testFipsCrypto } = internalBinding('crypto');
1819

1920
const FIPS_ENABLED = 1;
2021
const FIPS_DISABLED = 0;
21-
const FIPS_ENABLE_ERROR_STRING =
22-
'--enable-fips requires an active OpenSSL provider named "fips"';
23-
const FIPS_FORCE_ERROR_STRING =
24-
'--force-fips requires an active OpenSSL provider named "fips"';
25-
2622
const kNoFailure = 0;
2723
const kGenericUserError = 1;
2824

@@ -66,32 +62,37 @@ function testHelper(stream, args, expectedStatus, expectedOutput, cmd, env) {
6662
responseHandler(child[stream], expectedOutput);
6763
}
6864

69-
// --enable-fips should raise an error if OpenSSL is not FIPS enabled.
70-
testHelper(
71-
testFipsCrypto() ? 'stdout' : 'stderr',
72-
['--enable-fips'],
73-
testFipsCrypto() ? kNoFailure : kGenericUserError,
74-
testFipsCrypto() ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING,
75-
'require("crypto").getFips()',
76-
process.env);
77-
78-
// --force-fips should raise an error if OpenSSL is not FIPS enabled.
79-
testHelper(
80-
testFipsCrypto() ? 'stdout' : 'stderr',
81-
['--force-fips'],
82-
testFipsCrypto() ? kNoFailure : kGenericUserError,
83-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
84-
'require("crypto").getFips()',
85-
process.env);
86-
87-
// Explicit provider mode should preserve the behavior of bare --force-fips.
88-
testHelper(
89-
testFipsCrypto() ? 'stdout' : 'stderr',
90-
['--force-fips=provider'],
91-
testFipsCrypto() ? kNoFailure : kGenericUserError,
92-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
93-
'require("crypto").getFips()',
94-
process.env);
65+
const fipsFlags = ['--enable-fips', '--force-fips', '--force-fips=provider'];
66+
if (hasOpenSSL(3, 4))
67+
fipsFlags.push('--force-fips=strict');
68+
69+
// The flags change the default property query without requiring a provider
70+
// named "fips". This configuration supplies the RNG needed during startup,
71+
// but has no cryptographic implementations matching fips=yes.
72+
for (const flag of fipsFlags) {
73+
spawnSyncAndAssert(process.execPath, [
74+
flag,
75+
`--openssl-config=${fixtures.path('openssl3-conf', 'fips_no_provider.cnf')}`,
76+
'-e', `
77+
const assert = require('assert');
78+
const crypto = require('crypto');
79+
assert.strictEqual(crypto.getFips(), 1);
80+
assert.throws(() => crypto.createHash('sha256'), {
81+
code: 'ERR_OSSL_EVP_UNSUPPORTED',
82+
});
83+
if (${flag === '--enable-fips'}) {
84+
crypto.setFips(false);
85+
assert.strictEqual(crypto.getFips(), 0);
86+
crypto.createHash('sha256');
87+
} else {
88+
assert.throws(() => crypto.setFips(false), {
89+
code: 'ERR_CRYPTO_FIPS_FORCED',
90+
});
91+
assert.strictEqual(crypto.getFips(), 1);
92+
}
93+
`,
94+
], { stdout: '', stderr: '' });
95+
}
9596

9697
{
9798
spawnSyncAndAssert(
@@ -101,15 +102,7 @@ testHelper(
101102
});
102103
}
103104

104-
if (hasOpenSSL(3, 4)) {
105-
testHelper(
106-
testFipsCrypto() ? 'stdout' : 'stderr',
107-
['--force-fips=strict'],
108-
testFipsCrypto() ? kNoFailure : kGenericUserError,
109-
testFipsCrypto() ? FIPS_ENABLED : FIPS_FORCE_ERROR_STRING,
110-
'require("crypto").getFips()',
111-
process.env);
112-
} else {
105+
if (!hasOpenSSL(3, 4)) {
113106
spawnSyncAndAssert(
114107
process.execPath, ['--enable-fips-indicator-events', '-e', '0'], {
115108
status: 9,

0 commit comments

Comments
 (0)