From 9922c67ef206d8bb29078ed46f98f5a9792e90df Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 3 Dec 2026 16:03:36 +0000 Subject: [PATCH] tls: add tlsSocket.getNegotiatedGroup() Return the TLS group negotiated for key agreement. Unlike getEphemeralKeyInfo(), it also works on server sockets. Assisted-by: Claude Opus 5.5 Signed-off-by: James M Snell --- doc/api/tls.md | 24 +++++++- lib/internal/tls/wrap.js | 1 + src/crypto/crypto_tls.cc | 30 ++++++++++ src/crypto/crypto_tls.h | 2 + .../parallel/test-tls-get-negotiated-group.js | 57 +++++++++++++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-tls-get-negotiated-group.js diff --git a/doc/api/tls.md b/doc/api/tls.md index 942733df8cc7..644c09759025 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1271,8 +1271,9 @@ added: v5.0.0 Returns an object describing ephemeral key agreement in [perfect forward secrecy][] on a client connection. It returns an empty object when the key agreement is not ephemeral. As this is only supported on a client socket; -`null` is returned if called on a server socket. The supported types are `'DH'`, -`'ECDH'`, and `'TLSGroup'`. For `'DH'` and `'ECDH'`, the object describes peer +`null` is returned if called on a server socket. Use +[`tlsSocket.getNegotiatedGroup()`][] to get the negotiated group on a server +socket. The supported types are `'DH'`, `'ECDH'`, and `'TLSGroup'`. For `'DH'` and `'ECDH'`, the object describes peer temporary key parameters. For `'TLSGroup'`, the object identifies the negotiated TLS Supported Group used for key agreement when a peer temporary key object is not available. @@ -1302,6 +1303,23 @@ provided by SSL/TLS is not desired or is not enough. Corresponds to the `SSL_get_finished` routine in OpenSSL and may be used to implement the `tls-unique` channel binding from [RFC 5929][]. +### `tlsSocket.getNegotiatedGroup()` + + + +* Returns: {string|undefined} The name of the TLS group used for key + agreement, or `undefined` if no group was negotiated. + +Returns the TLS Supported Group negotiated for key agreement, for example +`'X25519MLKEM768'`, `'x25519'`, or `'secp256r1'`. Unlike +[`tlsSocket.getEphemeralKeyInfo()`][], this method works on both client and +server sockets. `undefined` is returned when the key agreement does not use a +group, such as with TLSv1.2 RSA key exchange, or before the handshake has +completed. With TLSv1.2 DHE key exchange, only the server socket reports the +group. + ### `tlsSocket.getPeerCertificate([detailed])`