Skip to content

Commit 6120a0d

Browse files
danbevaddaleax
authored andcommitted
test: skip fips tests using OpenSSL config file
The motivation for this commit is that we are building Node with --shared-openssl and in our case the system OpenSSL version supports FIPS. The tests in test-crypto-fips that toggle fips mode on/off using the config file option might succeed and return 1 instead of an error being thrown from OpenSSL (which is what happens for a default build but the error is not processed/displayed in any way at the moment): openssl config failed: error:060B10A7:digital envelope routines:ALG_MODULE_INIT:fips mode not supported Note that this only concerns the test that use the configuration file option which is different from when calling the fips setter as the handling of the configuration file is handled by OpenSSL, so it is not possible for us to try to call the fips setter as that would throw an error ("Error: Cannot set FIPS mode in a non-FIPS build."). The suggestion is to skips these tests when --shared-openssl is used. PR-URL: #13786 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5579bc8 commit 6120a0d

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

test/parallel/test-crypto-fips.js

+41-23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function compiledWithFips() {
2121
return process.config.variables.openssl_fips ? true : false;
2222
}
2323

24+
function sharedOpenSSL() {
25+
return process.config.variables.node_shared_openssl;
26+
}
27+
2428
function addToEnv(newVar, value) {
2529
const envCopy = {};
2630
for (const e in process.env) {
@@ -85,29 +89,43 @@ testHelper(
8589
'require("crypto").fips',
8690
process.env);
8791

88-
// OpenSSL config file should be able to turn on FIPS mode
89-
testHelper(
90-
'stdout',
91-
[`--openssl-config=${CNF_FIPS_ON}`],
92-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
93-
'require("crypto").fips',
94-
process.env);
95-
96-
// OPENSSL_CONF should be able to turn on FIPS mode
97-
testHelper(
98-
'stdout',
99-
[],
100-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
101-
'require("crypto").fips',
102-
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
103-
104-
// --openssl-config option should override OPENSSL_CONF
105-
testHelper(
106-
'stdout',
107-
[`--openssl-config=${CNF_FIPS_ON}`],
108-
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
109-
'require("crypto").fips',
110-
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
92+
// If Node was configured using --shared-openssl fips support might be
93+
// available depending on how OpenSSL was built. If fips support is
94+
// available the tests that toggle the fips_mode on/off using the config
95+
// file option will succeed and return 1 instead of 0.
96+
//
97+
// Note that this case is different from when calling the fips setter as the
98+
// configuration file is handled by OpenSSL, so it is not possible for us
99+
// to try to call the fips setter, to try to detect this situation, as
100+
// that would throw an error:
101+
// ("Error: Cannot set FIPS mode in a non-FIPS build.").
102+
// Due to this uncertanty the following tests are skipped when configured
103+
// with --shared-openssl.
104+
if (!sharedOpenSSL()) {
105+
// OpenSSL config file should be able to turn on FIPS mode
106+
testHelper(
107+
'stdout',
108+
[`--openssl-config=${CNF_FIPS_ON}`],
109+
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
110+
'require("crypto").fips',
111+
process.env);
112+
113+
// OPENSSL_CONF should be able to turn on FIPS mode
114+
testHelper(
115+
'stdout',
116+
[],
117+
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
118+
'require("crypto").fips',
119+
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
120+
121+
// --openssl-config option should override OPENSSL_CONF
122+
testHelper(
123+
'stdout',
124+
[`--openssl-config=${CNF_FIPS_ON}`],
125+
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
126+
'require("crypto").fips',
127+
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
128+
}
111129

112130
testHelper(
113131
'stdout',

0 commit comments

Comments
 (0)