@@ -9,27 +9,20 @@ const spawnSync = require('child_process').spawnSync;
99const path = require ( 'path' ) ;
1010const fixtures = require ( '../common/fixtures' ) ;
1111const { internalBinding } = require ( 'internal/test/binding' ) ;
12- const { fipsMode } = internalBinding ( 'config ' ) ;
12+ const { testFipsCrypto } = internalBinding ( 'crypto ' ) ;
1313
1414const FIPS_ENABLED = 1 ;
1515const FIPS_DISABLED = 0 ;
16- const FIPS_ERROR_STRING =
17- 'Error [ERR_CRYPTO_FIPS_UNAVAILABLE]: Cannot set FIPS mode in a ' +
18- 'non-FIPS build.' ;
1916const FIPS_ERROR_STRING2 =
2017 'Error [ERR_CRYPTO_FIPS_FORCED]: Cannot set FIPS mode, it was forced with ' +
2118 '--force-fips at startup.' ;
22- const OPTION_ERROR_STRING = 'bad option ' ;
19+ const FIPS_UNSUPPORTED_ERROR_STRING = 'fips mode not supported ' ;
2320
2421const CNF_FIPS_ON = fixtures . path ( 'openssl_fips_enabled.cnf' ) ;
2522const CNF_FIPS_OFF = fixtures . path ( 'openssl_fips_disabled.cnf' ) ;
2623
2724let num_children_ok = 0 ;
2825
29- function compiledWithFips ( ) {
30- return fipsMode ? true : false ;
31- }
32-
3326function sharedOpenSSL ( ) {
3427 return process . config . variables . node_shared_openssl ;
3528}
@@ -75,17 +68,17 @@ testHelper(
7568
7669// --enable-fips should turn FIPS mode on
7770testHelper (
78- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
71+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
7972 [ '--enable-fips' ] ,
80- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
73+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
8174 'require("crypto").getFips()' ,
8275 process . env ) ;
8376
8477// --force-fips should turn FIPS mode on
8578testHelper (
86- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
79+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
8780 [ '--force-fips' ] ,
88- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
81+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
8982 'require("crypto").getFips()' ,
9083 process . env ) ;
9184
@@ -106,23 +99,23 @@ if (!sharedOpenSSL()) {
10699 testHelper (
107100 'stdout' ,
108101 [ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
109- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
102+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
110103 'require("crypto").getFips()' ,
111104 process . env ) ;
112105
113106 // OPENSSL_CONF should be able to turn on FIPS mode
114107 testHelper (
115108 'stdout' ,
116109 [ ] ,
117- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
110+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
118111 'require("crypto").getFips()' ,
119112 Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_ON } ) ) ;
120113
121114 // --openssl-config option should override OPENSSL_CONF
122115 testHelper (
123116 'stdout' ,
124117 [ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
125- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
118+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
126119 'require("crypto").getFips()' ,
127120 Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
128121}
@@ -136,78 +129,78 @@ testHelper(
136129
137130// --enable-fips should take precedence over OpenSSL config file
138131testHelper (
139- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
132+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
140133 [ '--enable-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
141- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
134+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
142135 'require("crypto").getFips()' ,
143136 process . env ) ;
144137
145138// OPENSSL_CONF should _not_ make a difference to --enable-fips
146139testHelper (
147- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
140+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
148141 [ '--enable-fips' ] ,
149- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
142+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
150143 'require("crypto").getFips()' ,
151144 Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
152145
153146// --force-fips should take precedence over OpenSSL config file
154147testHelper (
155- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
148+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
156149 [ '--force-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
157- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
150+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
158151 'require("crypto").getFips()' ,
159152 process . env ) ;
160153
161154// Using OPENSSL_CONF should not make a difference to --force-fips
162155testHelper (
163- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
156+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
164157 [ '--force-fips' ] ,
165- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
158+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
166159 'require("crypto").getFips()' ,
167160 Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
168161
169162// setFipsCrypto should be able to turn FIPS mode on
170163testHelper (
171- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
164+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
172165 [ ] ,
173- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_ERROR_STRING ,
166+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
174167 '(require("crypto").setFips(true),' +
175168 'require("crypto").getFips())' ,
176169 process . env ) ;
177170
178171// setFipsCrypto should be able to turn FIPS mode on and off
179172testHelper (
180- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
173+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
181174 [ ] ,
182- compiledWithFips ( ) ? FIPS_DISABLED : FIPS_ERROR_STRING ,
175+ testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
183176 '(require("crypto").setFips(true),' +
184177 'require("crypto").setFips(false),' +
185178 'require("crypto").getFips())' ,
186179 process . env ) ;
187180
188181// setFipsCrypto takes precedence over OpenSSL config file, FIPS on
189182testHelper (
190- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
183+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
191184 [ `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
192- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_ERROR_STRING ,
185+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
193186 '(require("crypto").setFips(true),' +
194187 'require("crypto").getFips())' ,
195188 process . env ) ;
196189
197190// setFipsCrypto takes precedence over OpenSSL config file, FIPS off
198191testHelper (
199- compiledWithFips ( ) ? 'stdout' : 'stderr ',
192+ 'stdout' ,
200193 [ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
201- compiledWithFips ( ) ? FIPS_DISABLED : FIPS_ERROR_STRING ,
194+ FIPS_DISABLED ,
202195 '(require("crypto").setFips(false),' +
203196 'require("crypto").getFips())' ,
204197 process . env ) ;
205198
206199// --enable-fips does not prevent use of setFipsCrypto API
207200testHelper (
208- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
201+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
209202 [ '--enable-fips' ] ,
210- compiledWithFips ( ) ? FIPS_DISABLED : OPTION_ERROR_STRING ,
203+ testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
211204 '(require("crypto").setFips(false),' +
212205 'require("crypto").getFips())' ,
213206 process . env ) ;
@@ -216,15 +209,15 @@ testHelper(
216209testHelper (
217210 'stderr' ,
218211 [ '--force-fips' ] ,
219- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
212+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
220213 'require("crypto").setFips(false)' ,
221214 process . env ) ;
222215
223216// --force-fips makes setFipsCrypto enable a no-op (FIPS stays on)
224217testHelper (
225- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
218+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
226219 [ '--force-fips' ] ,
227- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
220+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
228221 '(require("crypto").setFips(true),' +
229222 'require("crypto").getFips())' ,
230223 process . env ) ;
@@ -233,14 +226,14 @@ testHelper(
233226testHelper (
234227 'stderr' ,
235228 [ '--force-fips' , '--enable-fips' ] ,
236- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
229+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
237230 'require("crypto").setFips(false)' ,
238231 process . env ) ;
239232
240233// --enable-fips and --force-fips order does not matter
241234testHelper (
242235 'stderr' ,
243236 [ '--enable-fips' , '--force-fips' ] ,
244- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
237+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
245238 'require("crypto").setFips(false)' ,
246239 process . env ) ;
0 commit comments