@@ -23,13 +23,16 @@ const FIPS_ENABLE_ERROR_STRING = 'OpenSSL error when trying to enable FIPS:'; |
23 | 23 | const CNF_FIPS_ON = fixtures.path('openssl_fips_enabled.cnf'); |
24 | 24 | const CNF_FIPS_OFF = fixtures.path('openssl_fips_disabled.cnf'); |
25 | 25 |
|
| 26 | +const kNoFailure = 0; |
| 27 | +const kGenericUserError = 1; |
| 28 | + |
26 | 29 | let num_children_ok = 0; |
27 | 30 |
|
28 | 31 | function sharedOpenSSL() { |
29 | 32 | return process.config.variables.node_shared_openssl; |
30 | 33 | } |
31 | 34 |
|
32 | | -function testHelper(stream, args, expectedOutput, cmd, env) { |
| 35 | +function testHelper(stream, args, expectedStatus, expectedOutput, cmd, env) { |
33 | 36 | const fullArgs = args.concat(['-e', `console.log(${cmd})`]); |
34 | 37 | const child = spawnSync(process.execPath, fullArgs, { |
35 | 38 | cwd: path.dirname(process.execPath), |
@@ -56,6 +59,7 @@ function testHelper(stream, args, expectedOutput, cmd, env) { |
56 | 59 | // Normal path where we expect either FIPS enabled or disabled. |
57 | 60 | assert.strictEqual(getFipsValue, expectedOutput); |
58 | 61 | } |
| 62 | + assert.strictEqual(child.status, expectedStatus); |
59 | 63 | childOk(child); |
60 | 64 | } |
61 | 65 |
|
@@ -66,6 +70,7 @@ function testHelper(stream, args, expectedOutput, cmd, env) { |
66 | 70 | testHelper( |
67 | 71 | testFipsCrypto() ? 'stdout' : 'stderr', |
68 | 72 | ['--enable-fips'], |
| 73 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
69 | 74 | testFipsCrypto() ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING, |
70 | 75 | 'process.versions', |
71 | 76 | process.env); |
@@ -74,6 +79,7 @@ testHelper( |
74 | 79 | testHelper( |
75 | 80 | testFipsCrypto() ? 'stdout' : 'stderr', |
76 | 81 | ['--force-fips'], |
| 82 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
77 | 83 | testFipsCrypto() ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING, |
78 | 84 | 'process.versions', |
79 | 85 | process.env); |
@@ -85,6 +91,7 @@ if (!sharedOpenSSL()) { |
85 | 91 | testHelper( |
86 | 92 | 'stdout', |
87 | 93 | [], |
| 94 | + kNoFailure, |
88 | 95 | FIPS_DISABLED, |
89 | 96 | 'require("crypto").getFips()', |
90 | 97 | { ...process.env, 'OPENSSL_CONF': ' ' }); |
@@ -94,6 +101,7 @@ if (!sharedOpenSSL()) { |
94 | 101 | testHelper( |
95 | 102 | 'stderr', |
96 | 103 | [], |
| 104 | + kGenericUserError, |
97 | 105 | 'Calling crypto.setFips() is not supported in workers', |
98 | 106 | 'new worker_threads.Worker(\'require("crypto").setFips(true);\', { eval: true })', |
99 | 107 | process.env); |
@@ -120,6 +128,7 @@ if (!sharedOpenSSL() && !hasOpenSSL3) { |
120 | 128 | testHelper( |
121 | 129 | 'stdout', |
122 | 130 | [`--openssl-config=${CNF_FIPS_ON}`], |
| 131 | + kNoFailure, |
123 | 132 | testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED, |
124 | 133 | 'require("crypto").getFips()', |
125 | 134 | process.env); |
@@ -128,6 +137,7 @@ if (!sharedOpenSSL() && !hasOpenSSL3) { |
128 | 137 | testHelper( |
129 | 138 | 'stdout', |
130 | 139 | [], |
| 140 | + kNoFailure, |
131 | 141 | testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED, |
132 | 142 | 'require("crypto").getFips()', |
133 | 143 | Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON })); |
@@ -136,6 +146,7 @@ if (!sharedOpenSSL() && !hasOpenSSL3) { |
136 | 146 | testHelper( |
137 | 147 | 'stdout', |
138 | 148 | [`--openssl-config=${CNF_FIPS_ON}`], |
| 149 | + kNoFailure, |
139 | 150 | testFipsCrypto() ? FIPS_ENABLED : FIPS_DISABLED, |
140 | 151 | 'require("crypto").getFips()', |
141 | 152 | Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF })); |
@@ -149,6 +160,7 @@ if (!hasOpenSSL3) { |
149 | 160 | testHelper( |
150 | 161 | 'stdout', |
151 | 162 | [`--openssl-config=${CNF_FIPS_OFF}`], |
| 163 | + kNoFailure, |
152 | 164 | FIPS_DISABLED, |
153 | 165 | 'require("crypto").getFips()', |
154 | 166 | Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_ON })); |
@@ -157,20 +169,23 @@ if (!hasOpenSSL3) { |
157 | 169 | testHelper( |
158 | 170 | testFipsCrypto() ? 'stdout' : 'stderr', |
159 | 171 | ['--enable-fips', `--openssl-config=${CNF_FIPS_OFF}`], |
| 172 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
160 | 173 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
161 | 174 | 'require("crypto").getFips()', |
162 | 175 | process.env); |
163 | 176 | // --force-fips should take precedence over OpenSSL config file |
164 | 177 | testHelper( |
165 | 178 | testFipsCrypto() ? 'stdout' : 'stderr', |
166 | 179 | ['--force-fips', `--openssl-config=${CNF_FIPS_OFF}`], |
| 180 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
167 | 181 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
168 | 182 | 'require("crypto").getFips()', |
169 | 183 | process.env); |
170 | 184 | // --enable-fips should turn FIPS mode on |
171 | 185 | testHelper( |
172 | 186 | testFipsCrypto() ? 'stdout' : 'stderr', |
173 | 187 | ['--enable-fips'], |
| 188 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
174 | 189 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
175 | 190 | 'require("crypto").getFips()', |
176 | 191 | process.env); |
@@ -179,6 +194,7 @@ if (!hasOpenSSL3) { |
179 | 194 | testHelper( |
180 | 195 | testFipsCrypto() ? 'stdout' : 'stderr', |
181 | 196 | ['--force-fips'], |
| 197 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
182 | 198 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
183 | 199 | 'require("crypto").getFips()', |
184 | 200 | process.env); |
@@ -187,6 +203,7 @@ if (!hasOpenSSL3) { |
187 | 203 | testHelper( |
188 | 204 | testFipsCrypto() ? 'stdout' : 'stderr', |
189 | 205 | ['--enable-fips'], |
| 206 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
190 | 207 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
191 | 208 | 'require("crypto").getFips()', |
192 | 209 | Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF })); |
@@ -195,6 +212,7 @@ if (!hasOpenSSL3) { |
195 | 212 | testHelper( |
196 | 213 | testFipsCrypto() ? 'stdout' : 'stderr', |
197 | 214 | ['--force-fips'], |
| 215 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
198 | 216 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
199 | 217 | 'require("crypto").getFips()', |
200 | 218 | Object.assign({}, process.env, { 'OPENSSL_CONF': CNF_FIPS_OFF })); |
@@ -203,6 +221,7 @@ if (!hasOpenSSL3) { |
203 | 221 | testHelper( |
204 | 222 | testFipsCrypto() ? 'stdout' : 'stderr', |
205 | 223 | [], |
| 224 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
206 | 225 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
207 | 226 | '(require("crypto").setFips(true),' + |
208 | 227 | 'require("crypto").getFips())', |
@@ -212,6 +231,7 @@ if (!hasOpenSSL3) { |
212 | 231 | testHelper( |
213 | 232 | testFipsCrypto() ? 'stdout' : 'stderr', |
214 | 233 | [], |
| 234 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
215 | 235 | testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
216 | 236 | '(require("crypto").setFips(true),' + |
217 | 237 | 'require("crypto").setFips(false),' + |
@@ -222,6 +242,7 @@ if (!hasOpenSSL3) { |
222 | 242 | testHelper( |
223 | 243 | testFipsCrypto() ? 'stdout' : 'stderr', |
224 | 244 | [`--openssl-config=${CNF_FIPS_OFF}`], |
| 245 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
225 | 246 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
226 | 247 | '(require("crypto").setFips(true),' + |
227 | 248 | 'require("crypto").getFips())', |
@@ -231,6 +252,7 @@ if (!hasOpenSSL3) { |
231 | 252 | testHelper( |
232 | 253 | 'stdout', |
233 | 254 | [`--openssl-config=${CNF_FIPS_ON}`], |
| 255 | + kNoFailure, |
234 | 256 | FIPS_DISABLED, |
235 | 257 | '(require("crypto").setFips(false),' + |
236 | 258 | 'require("crypto").getFips())', |
@@ -240,6 +262,7 @@ if (!hasOpenSSL3) { |
240 | 262 | testHelper( |
241 | 263 | testFipsCrypto() ? 'stdout' : 'stderr', |
242 | 264 | ['--enable-fips'], |
| 265 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
243 | 266 | testFipsCrypto() ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
244 | 267 | '(require("crypto").setFips(false),' + |
245 | 268 | 'require("crypto").getFips())', |
@@ -249,6 +272,7 @@ if (!hasOpenSSL3) { |
249 | 272 | testHelper( |
250 | 273 | 'stderr', |
251 | 274 | ['--force-fips'], |
| 275 | + kGenericUserError, |
252 | 276 | testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING, |
253 | 277 | 'require("crypto").setFips(false)', |
254 | 278 | process.env); |
@@ -257,6 +281,7 @@ if (!hasOpenSSL3) { |
257 | 281 | testHelper( |
258 | 282 | testFipsCrypto() ? 'stdout' : 'stderr', |
259 | 283 | ['--force-fips'], |
| 284 | + testFipsCrypto() ? kNoFailure : kGenericUserError, |
260 | 285 | testFipsCrypto() ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING, |
261 | 286 | '(require("crypto").setFips(true),' + |
262 | 287 | 'require("crypto").getFips())', |
@@ -266,6 +291,7 @@ if (!hasOpenSSL3) { |
266 | 291 | testHelper( |
267 | 292 | 'stderr', |
268 | 293 | ['--force-fips', '--enable-fips'], |
| 294 | + kGenericUserError, |
269 | 295 | testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING, |
270 | 296 | 'require("crypto").setFips(false)', |
271 | 297 | process.env); |
@@ -274,6 +300,7 @@ if (!hasOpenSSL3) { |
274 | 300 | testHelper( |
275 | 301 | 'stderr', |
276 | 302 | ['--enable-fips', '--force-fips'], |
| 303 | + kGenericUserError, |
277 | 304 | testFipsCrypto() ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING, |
278 | 305 | 'require("crypto").setFips(false)', |
279 | 306 | process.env); |
|