@@ -223,8 +223,6 @@ function test_rsa(padding, encryptOaepHash, decryptOaepHash) { |
223 | 223 |
|
224 | 224 |
|
225 | 225 | if (padding === constants.RSA_PKCS1_PADDING) { |
226 | | - // TODO(richardlau): see if it's possible to determine implicit rejection |
227 | | - // support when dynamically linked against OpenSSL. |
228 | 226 | if (!process.config.variables.node_shared_openssl) { |
229 | 227 | assert.throws(() => { |
230 | 228 | crypto.privateDecrypt({ |
@@ -240,6 +238,55 @@ function test_rsa(padding, encryptOaepHash, decryptOaepHash) { |
240 | 238 | oaepHash: decryptOaepHash |
241 | 239 | }, encryptedBuffer); |
242 | 240 | }, { code: 'ERR_INVALID_ARG_VALUE' }); |
| 241 | + } else { |
| 242 | + // The version of a linked against OpenSSL. May |
| 243 | + // or may not support implicit rejection. Figuring |
| 244 | + // this out in the test is not feasible but we |
| 245 | + // require that it pass based on one of the two |
| 246 | + // cases of supporting it or not. |
| 247 | + try { |
| 248 | + // The expected exceptions should be thrown if implicit rejection |
| 249 | + // is not supported |
| 250 | + assert.throws(() => { |
| 251 | + crypto.privateDecrypt({ |
| 252 | + key: rsaKeyPem, |
| 253 | + padding: padding, |
| 254 | + oaepHash: decryptOaepHash |
| 255 | + }, encryptedBuffer); |
| 256 | + }, { code: 'ERR_INVALID_ARG_VALUE' }); |
| 257 | + assert.throws(() => { |
| 258 | + crypto.privateDecrypt({ |
| 259 | + key: rsaPkcs8KeyPem, |
| 260 | + padding: padding, |
| 261 | + oaepHash: decryptOaepHash |
| 262 | + }, encryptedBuffer); |
| 263 | + }, { code: 'ERR_INVALID_ARG_VALUE' }); |
| 264 | + } catch (e) { |
| 265 | + if (e.toString() === |
| 266 | + 'AssertionError [ERR_ASSERTION]: Missing expected exception.') { |
| 267 | + // Implicit rejection must be supported since |
| 268 | + // we did not get the exceptions that are thrown |
| 269 | + // when it is not, we should be able to decrypt |
| 270 | + let decryptedBuffer = crypto.privateDecrypt({ |
| 271 | + key: rsaKeyPem, |
| 272 | + padding: padding, |
| 273 | + oaepHash: decryptOaepHash |
| 274 | + }, encryptedBuffer); |
| 275 | + assert.deepStrictEqual(decryptedBuffer, input); |
| 276 | + |
| 277 | + decryptedBuffer = crypto.privateDecrypt({ |
| 278 | + key: rsaPkcs8KeyPem, |
| 279 | + padding: padding, |
| 280 | + oaepHash: decryptOaepHash |
| 281 | + }, encryptedBuffer); |
| 282 | + assert.deepStrictEqual(decryptedBuffer, input); |
| 283 | + } else { |
| 284 | + // There was an exception but it is not the one we expect if implicit |
| 285 | + // rejection is not supported so there was some other failure, |
| 286 | + // re-throw it so the test fails |
| 287 | + throw e; |
| 288 | + } |
| 289 | + } |
243 | 290 | } |
244 | 291 | } else { |
245 | 292 | let decryptedBuffer = crypto.privateDecrypt({ |
|