@@ -12,17 +12,13 @@ if (isBoringSSL)
1212const assert = require ( 'assert' ) ;
1313const spawnSync = require ( 'child_process' ) . spawnSync ;
1414const path = require ( 'path' ) ;
15+ const fixtures = require ( '../common/fixtures' ) ;
1516const { spawnSyncAndAssert } = require ( '../common/child_process' ) ;
1617const { internalBinding } = require ( 'internal/test/binding' ) ;
1718const { testFipsCrypto } = internalBinding ( 'crypto' ) ;
1819
1920const FIPS_ENABLED = 1 ;
2021const 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-
2622const kNoFailure = 0 ;
2723const 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