Skip to content

Commit 6b8a454

Browse files
panvanodejs-github-bot
authored andcommitted
crypto: fix disabling FIPS mode
OpenSSL reports FIPS mode as disabled after a successful EVP_default_properties_enable_fips(..., 0) call. Do not treat that disabled state as a failure. Add OpenSSL 3 regression coverage that verifies the state is enabled before disabling it again. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64982 Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 3f2fc8a commit 6b8a454

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

deps/ncrypto/ncrypto.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,7 @@ bool setFipsEnabled(bool enable, CryptoErrorList* errors) {
539539
if (isFipsEnabled() == enable) return true;
540540
ClearErrorOnReturn clearErrorOnReturn(errors);
541541
#if OPENSSL_VERSION_MAJOR >= 3
542-
return EVP_default_properties_enable_fips(nullptr, enable ? 1 : 0) == 1 &&
543-
EVP_default_properties_is_fips_enabled(nullptr);
542+
return EVP_default_properties_enable_fips(nullptr, enable ? 1 : 0) == 1;
544543
#else
545544
return FIPS_mode_set(enable ? 1 : 0) == 1;
546545
#endif

test/parallel/test-crypto-fips.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ if (!sharedOpenSSL()) {
105105
FIPS_DISABLED,
106106
'require("crypto").getFips()',
107107
{ ...process.env, 'OPENSSL_CONF': ' ' });
108+
109+
if (hasOpenSSL3) {
110+
// Disabling FIPS mode should not throw after OpenSSL updates the default
111+
// property query.
112+
testHelper(
113+
'stdout',
114+
[],
115+
kNoFailure,
116+
FIPS_DISABLED,
117+
'(() => {' +
118+
'const crypto = require("crypto");' +
119+
'crypto.setFips(true);' +
120+
'require("assert").strictEqual(crypto.getFips(), 1);' +
121+
'crypto.setFips(false);' +
122+
'return crypto.getFips();' +
123+
'})()',
124+
{ ...process.env, 'OPENSSL_CONF': ' ' });
125+
}
108126
}
109127

110128
// Toggling fips with setFips should not be allowed from a worker thread

0 commit comments

Comments
 (0)