Skip to content

Commit e5db93e

Browse files
committed
test: accept OpenSSL 4 generic internal error for DH key-type mismatches
Signed-off-by: Filip Skokan <[email protected]>
1 parent 71b5603 commit e5db93e

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

test/parallel/test-crypto-dh-stateless.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ const assert = require('assert');
77
const crypto = require('crypto');
88
const { hasOpenSSL } = require('../common/crypto');
99

10+
// Error code for a key-type mismatch during ECDH/EdDH derivation. The
11+
// underlying OpenSSL error code varies by version (and in OpenSSL 4.0, by
12+
// platform: some builds report a generic internal error instead
13+
// of a typed key-type mismatch).
14+
// TODO(panva): report the OpenSSL 4.0 generic internal error behavior
15+
// upstream and tighten this check once fixed.
16+
let keyTypeMismatchCode;
17+
if (hasOpenSSL(4, 0)) {
18+
keyTypeMismatchCode =
19+
/^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/;
20+
} else if (hasOpenSSL(3)) {
21+
keyTypeMismatchCode = 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE';
22+
} else {
23+
keyTypeMismatchCode = 'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES';
24+
}
25+
1026
assert.throws(() => crypto.diffieHellman(), {
1127
name: 'TypeError',
1228
code: 'ERR_INVALID_ARG_TYPE',
@@ -397,9 +413,7 @@ test(crypto.generateKeyPairSync('x25519'),
397413
privateKey: crypto.generateKeyPairSync('x448').privateKey,
398414
publicKey: crypto.generateKeyPairSync('x25519').publicKey,
399415
};
400-
testDHError(options, { code: hasOpenSSL(3) ?
401-
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' :
402-
'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES' });
416+
testDHError(options, { code: keyTypeMismatchCode });
403417
}
404418

405419
// Test all key encoding formats
@@ -541,23 +555,21 @@ for (const { privateKey: alicePriv, publicKey: bobPub } of [
541555
testDHError({
542556
privateKey: privKey(ec256.privateKey),
543557
publicKey: pubKey(x25519.publicKey),
544-
}, { code: hasOpenSSL(3) ?
545-
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' :
546-
'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES' });
558+
}, { code: keyTypeMismatchCode });
547559

548560
// Unsupported key type (ed25519)
549561
testDHError({
550562
privateKey: privKey(ed25519.privateKey),
551563
publicKey: pubKey(ed25519.publicKey),
552-
}, { code: 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' });
564+
}, { code: hasOpenSSL(4, 0) ?
565+
/^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/ :
566+
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' });
553567

554568
// Incompatible key types (x448 + x25519)
555569
testDHError({
556570
privateKey: privKey(x448.privateKey),
557571
publicKey: pubKey(x25519.publicKey),
558-
}, { code: hasOpenSSL(3) ?
559-
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' :
560-
'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES' });
572+
}, { code: keyTypeMismatchCode });
561573

562574
// Zero x25519 public key
563575
testDHError({

0 commit comments

Comments
 (0)