Skip to content

Commit c51b7b2

Browse files
shigekiBridgeAR
authored andcommitted
tls: fix getEphemeralKeyInfo to support X25519
`EVP_PKEY_EC` only covers ANSI X9.62 curves not IETF ones(curve25519 and curve448). This fixes to add support of X25519 in `tlsSocket.getEphemeralKeyInfo()`. X448 should be added in the future upgrade to OpenSSL-1.1.1. PR-URL: #20273 Fixes: #20262 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent bdf0d9b commit c51b7b2

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/node_crypto.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,27 +2098,38 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
20982098
EVP_PKEY* key;
20992099

21002100
if (SSL_get_server_tmp_key(w->ssl_, &key)) {
2101-
switch (EVP_PKEY_id(key)) {
2101+
int kid = EVP_PKEY_id(key);
2102+
switch (kid) {
21022103
case EVP_PKEY_DH:
21032104
info->Set(context, env->type_string(),
21042105
FIXED_ONE_BYTE_STRING(env->isolate(), "DH")).FromJust();
21052106
info->Set(context, env->size_string(),
21062107
Integer::New(env->isolate(), EVP_PKEY_bits(key))).FromJust();
21072108
break;
21082109
case EVP_PKEY_EC:
2110+
// TODO(shigeki) Change this to EVP_PKEY_X25519 and add EVP_PKEY_X448
2111+
// after upgrading to 1.1.1.
2112+
case NID_X25519:
21092113
{
2110-
EC_KEY* ec = EVP_PKEY_get1_EC_KEY(key);
2111-
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2112-
EC_KEY_free(ec);
2114+
const char* curve_name;
2115+
if (kid == EVP_PKEY_EC) {
2116+
EC_KEY* ec = EVP_PKEY_get1_EC_KEY(key);
2117+
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2118+
curve_name = OBJ_nid2sn(nid);
2119+
EC_KEY_free(ec);
2120+
} else {
2121+
curve_name = OBJ_nid2sn(kid);
2122+
}
21132123
info->Set(context, env->type_string(),
21142124
FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH")).FromJust();
21152125
info->Set(context, env->name_string(),
21162126
OneByteString(args.GetIsolate(),
2117-
OBJ_nid2sn(nid))).FromJust();
2127+
curve_name)).FromJust();
21182128
info->Set(context, env->size_string(),
21192129
Integer::New(env->isolate(),
21202130
EVP_PKEY_bits(key))).FromJust();
21212131
}
2132+
break;
21222133
}
21232134
EVP_PKEY_free(key);
21242135
}

src/node_crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#endif // !OPENSSL_NO_ENGINE
4545
#include <openssl/err.h>
4646
#include <openssl/evp.h>
47+
// TODO(shigeki) Remove this after upgrading to 1.1.1
48+
#include <openssl/obj_mac.h>
4749
#include <openssl/pem.h>
4850
#include <openssl/x509.h>
4951
#include <openssl/x509v3.h>

test/parallel/test-tls-client-getephemeralkeyinfo.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ function testECDHE256() {
8282
}
8383

8484
function testECDHE512() {
85-
test(521, 'ECDH', 'secp521r1', null);
85+
test(521, 'ECDH', 'secp521r1', testX25519);
86+
ntests++;
87+
}
88+
89+
function testX25519() {
90+
test(253, 'ECDH', 'X25519', null);
8691
ntests++;
8792
}
8893

8994
testNOT_PFS();
9095

9196
process.on('exit', function() {
9297
assert.strictEqual(ntests, nsuccess);
93-
assert.strictEqual(ntests, 5);
98+
assert.strictEqual(ntests, 6);
9499
});

0 commit comments

Comments
 (0)