@@ -9,27 +9,20 @@ const spawnSync = require('child_process').spawnSync;
9
9
const path = require ( 'path' ) ;
10
10
const fixtures = require ( '../common/fixtures' ) ;
11
11
const { internalBinding } = require ( 'internal/test/binding' ) ;
12
- const { fipsMode } = internalBinding ( 'config ' ) ;
12
+ const { testFipsCrypto } = internalBinding ( 'crypto ' ) ;
13
13
14
14
const FIPS_ENABLED = 1 ;
15
15
const FIPS_DISABLED = 0 ;
16
- const FIPS_ERROR_STRING =
17
- 'Error [ERR_CRYPTO_FIPS_UNAVAILABLE]: Cannot set FIPS mode in a ' +
18
- 'non-FIPS build.' ;
19
16
const FIPS_ERROR_STRING2 =
20
17
'Error [ERR_CRYPTO_FIPS_FORCED]: Cannot set FIPS mode, it was forced with ' +
21
18
'--force-fips at startup.' ;
22
- const OPTION_ERROR_STRING = 'bad option ' ;
19
+ const FIPS_UNSUPPORTED_ERROR_STRING = 'fips mode not supported ' ;
23
20
24
21
const CNF_FIPS_ON = fixtures . path ( 'openssl_fips_enabled.cnf' ) ;
25
22
const CNF_FIPS_OFF = fixtures . path ( 'openssl_fips_disabled.cnf' ) ;
26
23
27
24
let num_children_ok = 0 ;
28
25
29
- function compiledWithFips ( ) {
30
- return fipsMode ? true : false ;
31
- }
32
-
33
26
function sharedOpenSSL ( ) {
34
27
return process . config . variables . node_shared_openssl ;
35
28
}
@@ -75,17 +68,17 @@ testHelper(
75
68
76
69
// --enable-fips should turn FIPS mode on
77
70
testHelper (
78
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
71
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
79
72
[ '--enable-fips' ] ,
80
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
73
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
81
74
'require("crypto").getFips()' ,
82
75
process . env ) ;
83
76
84
77
// --force-fips should turn FIPS mode on
85
78
testHelper (
86
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
79
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
87
80
[ '--force-fips' ] ,
88
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
81
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
89
82
'require("crypto").getFips()' ,
90
83
process . env ) ;
91
84
@@ -106,23 +99,23 @@ if (!sharedOpenSSL()) {
106
99
testHelper (
107
100
'stdout' ,
108
101
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
109
- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
102
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
110
103
'require("crypto").getFips()' ,
111
104
process . env ) ;
112
105
113
106
// OPENSSL_CONF should be able to turn on FIPS mode
114
107
testHelper (
115
108
'stdout' ,
116
109
[ ] ,
117
- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
110
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
118
111
'require("crypto").getFips()' ,
119
112
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_ON } ) ) ;
120
113
121
114
// --openssl-config option should override OPENSSL_CONF
122
115
testHelper (
123
116
'stdout' ,
124
117
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
125
- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
118
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
126
119
'require("crypto").getFips()' ,
127
120
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
128
121
}
@@ -136,78 +129,78 @@ testHelper(
136
129
137
130
// --enable-fips should take precedence over OpenSSL config file
138
131
testHelper (
139
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
132
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
140
133
[ '--enable-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
141
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
134
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
142
135
'require("crypto").getFips()' ,
143
136
process . env ) ;
144
137
145
138
// OPENSSL_CONF should _not_ make a difference to --enable-fips
146
139
testHelper (
147
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
140
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
148
141
[ '--enable-fips' ] ,
149
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
142
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
150
143
'require("crypto").getFips()' ,
151
144
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
152
145
153
146
// --force-fips should take precedence over OpenSSL config file
154
147
testHelper (
155
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
148
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
156
149
[ '--force-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
157
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
150
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
158
151
'require("crypto").getFips()' ,
159
152
process . env ) ;
160
153
161
154
// Using OPENSSL_CONF should not make a difference to --force-fips
162
155
testHelper (
163
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
156
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
164
157
[ '--force-fips' ] ,
165
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
158
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
166
159
'require("crypto").getFips()' ,
167
160
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
168
161
169
162
// setFipsCrypto should be able to turn FIPS mode on
170
163
testHelper (
171
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
164
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
172
165
[ ] ,
173
- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_ERROR_STRING ,
166
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
174
167
'(require("crypto").setFips(true),' +
175
168
'require("crypto").getFips())' ,
176
169
process . env ) ;
177
170
178
171
// setFipsCrypto should be able to turn FIPS mode on and off
179
172
testHelper (
180
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
173
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
181
174
[ ] ,
182
- compiledWithFips ( ) ? FIPS_DISABLED : FIPS_ERROR_STRING ,
175
+ testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
183
176
'(require("crypto").setFips(true),' +
184
177
'require("crypto").setFips(false),' +
185
178
'require("crypto").getFips())' ,
186
179
process . env ) ;
187
180
188
181
// setFipsCrypto takes precedence over OpenSSL config file, FIPS on
189
182
testHelper (
190
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
183
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
191
184
[ `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
192
- compiledWithFips ( ) ? FIPS_ENABLED : FIPS_ERROR_STRING ,
185
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
193
186
'(require("crypto").setFips(true),' +
194
187
'require("crypto").getFips())' ,
195
188
process . env ) ;
196
189
197
190
// setFipsCrypto takes precedence over OpenSSL config file, FIPS off
198
191
testHelper (
199
- compiledWithFips ( ) ? 'stdout' : 'stderr ',
192
+ 'stdout' ,
200
193
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
201
- compiledWithFips ( ) ? FIPS_DISABLED : FIPS_ERROR_STRING ,
194
+ FIPS_DISABLED ,
202
195
'(require("crypto").setFips(false),' +
203
196
'require("crypto").getFips())' ,
204
197
process . env ) ;
205
198
206
199
// --enable-fips does not prevent use of setFipsCrypto API
207
200
testHelper (
208
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
201
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
209
202
[ '--enable-fips' ] ,
210
- compiledWithFips ( ) ? FIPS_DISABLED : OPTION_ERROR_STRING ,
203
+ testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
211
204
'(require("crypto").setFips(false),' +
212
205
'require("crypto").getFips())' ,
213
206
process . env ) ;
@@ -216,15 +209,15 @@ testHelper(
216
209
testHelper (
217
210
'stderr' ,
218
211
[ '--force-fips' ] ,
219
- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
212
+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
220
213
'require("crypto").setFips(false)' ,
221
214
process . env ) ;
222
215
223
216
// --force-fips makes setFipsCrypto enable a no-op (FIPS stays on)
224
217
testHelper (
225
- compiledWithFips ( ) ? 'stdout' : 'stderr' ,
218
+ testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
226
219
[ '--force-fips' ] ,
227
- compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
220
+ testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
228
221
'(require("crypto").setFips(true),' +
229
222
'require("crypto").getFips())' ,
230
223
process . env ) ;
@@ -233,14 +226,14 @@ testHelper(
233
226
testHelper (
234
227
'stderr' ,
235
228
[ '--force-fips' , '--enable-fips' ] ,
236
- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
229
+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
237
230
'require("crypto").setFips(false)' ,
238
231
process . env ) ;
239
232
240
233
// --enable-fips and --force-fips order does not matter
241
234
testHelper (
242
235
'stderr' ,
243
236
[ '--enable-fips' , '--force-fips' ] ,
244
- compiledWithFips ( ) ? FIPS_ERROR_STRING2 : OPTION_ERROR_STRING ,
237
+ testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
245
238
'require("crypto").setFips(false)' ,
246
239
process . env ) ;
0 commit comments