Skip to content

Commit c3dd52a

Browse files
panvanodejs-github-bot
authored andcommitted
test: accept OpenSSL 4 generic internal error for DH key-type mismatches
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #62805 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 12750e1 commit c3dd52a

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ 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 (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+
1025
assert.throws(() => crypto.diffieHellman(), {
1126
name: 'TypeError',
1227
code: 'ERR_INVALID_ARG_TYPE',
@@ -397,9 +412,7 @@ test(crypto.generateKeyPairSync('x25519'),
397412
privateKey: crypto.generateKeyPairSync('x448').privateKey,
398413
publicKey: crypto.generateKeyPairSync('x25519').publicKey,
399414
};
400-
testDHError(options, { code: hasOpenSSL(3) ?
401-
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' :
402-
'ERR_OSSL_EVP_DIFFERENT_KEY_TYPES' });
415+
testDHError(options, { code: keyTypeMismatchCode });
403416
}
404417

405418
// Test all key encoding formats
@@ -541,23 +554,21 @@ for (const { privateKey: alicePriv, publicKey: bobPub } of [
541554
testDHError({
542555
privateKey: privKey(ec256.privateKey),
543556
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' });
557+
}, { code: keyTypeMismatchCode });
547558

548559
// Unsupported key type (ed25519)
549560
testDHError({
550561
privateKey: privKey(ed25519.privateKey),
551562
publicKey: pubKey(ed25519.publicKey),
552-
}, { code: 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' });
563+
}, { code: hasOpenSSL(4, 0) ?
564+
/^ERR_OSSL_EVP_(OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE|INTERNAL_ERROR)$/ :
565+
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE' });
553566

554567
// Incompatible key types (x448 + x25519)
555568
testDHError({
556569
privateKey: privKey(x448.privateKey),
557570
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' });
571+
}, { code: keyTypeMismatchCode });
561572

562573
// Zero x25519 public key
563574
testDHError({

0 commit comments

Comments
 (0)