| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ca3c309 commit 55298c4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,28 @@ const assert = require('assert'); | |||
| 7 | 7 | const crypto = require('crypto'); | |
| 8 | 8 | const { hasOpenSSL } = require('../common/crypto'); | |
| 9 | 9 | ||
| 10 | + // Error code for a key-type mismatch during (EC)DH. The underlying OpenSSL | ||
| 11 | + // error code varies by version, and in OpenSSL 4.0 by platform: some builds | ||
| 12 | + // report a generic internal error instead of a typed key-type mismatch. | ||
| 13 | + // https://github.com/openssl/openssl/issues/30895 | ||
| 14 | + // TODO(panva): Tighten this check once/if fixed. | ||
| 15 | + let keyTypeMismatchCode; | ||
| 16 | + if (hasOpenSSL(4, 0)) { | ||
| 17 | + keyTypeMismatchCode = | ||
| 18 | + /^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/; | ||
| 19 | + } else if (hasOpenSSL(3)) { | ||
| 20 | + keyTypeMismatchCode = 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE'; | ||
| 21 | + } else { | ||
| 22 | + keyTypeMismatchCode = 'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES'; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + function assertErrorCode(actual, expected) { | ||
| 26 | + if (expected instanceof RegExp) | ||
| 27 | + assert.match(actual, expected); | ||
| 28 | + else | ||
| 29 | + assert.strictEqual(actual, expected); | ||
| 30 | + } | ||
| 31 | + | ||
| 10 | 32 | assert.throws(() => crypto.diffieHellman(crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' }), null), { | |
| 11 | 33 | name: 'TypeError', | |
| 12 | 34 | code: 'ERR_INVALID_ARG_TYPE', | |
@@ -341,16 +363,16 @@ for (const { privateKey: alicePriv, publicKey: bobPub } of [ | |||
| 341 | 363 | privateKey: ec256.privateKey.export({ type: 'pkcs8', format: 'pem' }), | |
| 342 | 364 | publicKey: x25519.publicKey.export({ type: 'spki', format: 'pem' }), | |
| 343 | 365 | }, common.mustCall((err) => { | |
| 344 | - assert.strictEqual(err.code, | ||
| 345 | - hasOpenSSL(3) ? 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' : | ||
| 346 | - 'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES'); | ||
| 366 | + assertErrorCode(err.code, keyTypeMismatchCode); | ||
| 347 | 367 | })); | |
| 348 | 368 | ||
| 349 | 369 | // Unsupported key type (ed25519) | |
| 350 | 370 | crypto.diffieHellman({ | |
| 351 | 371 | privateKey: ed25519.privateKey.export({ type: 'pkcs8', format: 'pem' }), | |
| 352 | 372 | publicKey: ed25519.publicKey.export({ type: 'spki', format: 'pem' }), | |
| 353 | 373 | }, common.mustCall((err) => { | |
| 354 | - assert.strictEqual(err.code, 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE'); | ||
| 374 | + assertErrorCode(err.code, hasOpenSSL(4, 0) ? | ||
| 375 | + /^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/ : | ||
| 376 | + 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE'); | ||
| 355 | 377 | })); | |
| 356 | 378 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,21 @@ const assert = require('assert'); | |||
| 7 | 7 | const crypto = require('crypto'); | |
| 8 | 8 | const { hasOpenSSL } = require('../common/crypto'); | |
| 9 | 9 | ||
| 10 | + // Error code for a key-type mismatch during (EC)DH. The underlying OpenSSL | ||
| 11 | + // error code varies by version, and in OpenSSL 4.0 by platform: some builds | ||
| 12 | + // report a generic internal error instead of a typed key-type mismatch. | ||
| 13 | + // https://github.com/openssl/openssl/issues/30895 | ||
| 14 | + // TODO(panva): Tighten this check once/if fixed. | ||
| 15 | + let keyTypeMismatchCode; | ||
| 16 | + if (hasOpenSSL(4, 0)) { | ||
| 17 | + keyTypeMismatchCode = | ||
| 18 | + /^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/; | ||
| 19 | + } else if (hasOpenSSL(3)) { | ||
| 20 | + keyTypeMismatchCode = 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE'; | ||
| 21 | + } else { | ||
| 22 | + keyTypeMismatchCode = 'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES'; | ||
| 23 | + } | ||
| 24 | + | ||
| 10 | 25 | assert.throws(() => crypto.diffieHellman(), { | |
| 11 | 26 | name: 'TypeError', | |
| 12 | 27 | code: 'ERR_INVALID_ARG_TYPE', | |
@@ -459,12 +474,13 @@ for (const { privateKey: alicePriv, publicKey: bobPub } of [ | |||
| 459 | 474 | assert.throws(() => crypto.diffieHellman({ | |
| 460 | 475 | privateKey: ec256.privateKey.export({ type: 'pkcs8', format: 'pem' }), | |
| 461 | 476 | publicKey: x25519.publicKey.export({ type: 'spki', format: 'pem' }), | |
| 462 | - }), { code: hasOpenSSL(3) ? | ||
| 463 | - 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' : 'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES' }); | ||
| 477 | + }), { code: keyTypeMismatchCode }); | ||
| 464 | 478 | ||
| 465 | 479 | // Unsupported key type (ed25519) | |
| 466 | 480 | assert.throws(() => crypto.diffieHellman({ | |
| 467 | 481 | privateKey: ed25519.privateKey.export({ type: 'pkcs8', format: 'pem' }), | |
| 468 | 482 | publicKey: ed25519.publicKey.export({ type: 'spki', format: 'pem' }), | |
| 469 | - }), { code: 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' }); | ||
| 483 | + }), { code: hasOpenSSL(4, 0) ? | ||
| 484 | + /^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/ : | ||
| 485 | + 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' }); | ||
| 470 | 486 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments