Commit b4e1e7ae804 for nodejs

commit b4e1e7ae8044cd08a2f162a7b5b4d685b532b956
Author: James M Snell <jasnell@gmail.com>
Date:   Sat Dec 5 08:28:03 2026 -0800

    tls: add tls.getGroups()

    Return the names of the TLS groups that can be used in the ecdhCurve
    option. Requires OpenSSL 3.5 or later.

    Assisted-by: Claude Opus 5.5
    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67992
    Reviewed-By: Tim Perry <pimterry@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Filip Skokan <panva.ip@gmail.com>

diff --git a/doc/api/tls.md b/doc/api/tls.md
index 52f183f7894..ca2db64b60f 100644
--- a/doc/api/tls.md
+++ b/doc/api/tls.md
@@ -2541,6 +2541,25 @@ TLSv1.2 and below.
 console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...]
 ```

+## `tls.getGroups()`
+
+<!-- YAML
+added: REPLACEME
+-->
+
+* Returns: {string\[]}
+
+Returns an array with the names of the TLS groups that can be used in the
+`ecdhCurve` option of [`tls.createSecureContext()`][] and in
+[`tls.DEFAULT_ECDH_CURVE`][]. Not all supported groups are enabled by default.
+
+Requires OpenSSL 3.5 or later. Throws `ERR_CRYPTO_UNSUPPORTED_OPERATION`
+otherwise.
+
+```js
+console.log(tls.getGroups()); // ['MLKEM1024', 'MLKEM512', 'MLKEM768', ...]
+```
+
 ## `tls.getCertificateCompressionAlgorithms()`

 <!-- YAML
diff --git a/lib/tls.js b/lib/tls.js
index ee6c34daea7..eb185a30a42 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -47,6 +47,7 @@ const {
   resetRootCertStore,
   getUserRootCertificates,
   getSSLCiphers,
+  getSSLGroups,
   getCertificateCompressionAlgorithms,
   startLoadingCertificatesOffThread,
 } = internalBinding('crypto');
@@ -137,6 +138,10 @@ exports.getCiphers = internalUtil.cachedResult(
   () => internalUtil.filterDuplicateStrings(getSSLCiphers(), true),
 );

+exports.getGroups = internalUtil.cachedResult(
+  () => internalUtil.filterDuplicateStrings(getSSLGroups()),
+);
+
 exports.getCertificateCompressionAlgorithms = internalUtil.cachedResult(
   () => getCertificateCompressionAlgorithms(),
 );
diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc
index df3b890b35a..9e13d03217d 100644
--- a/src/crypto/crypto_cipher.cc
+++ b/src/crypto/crypto_cipher.cc
@@ -190,6 +190,40 @@ void CipherBase::GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
   args.GetReturnValue().Set(Array::New(env->isolate(), arr.data(), arr.size()));
 }

+void CipherBase::GetSSLGroups(const FunctionCallbackInfo<Value>& args) {
+  Environment* env = Environment::GetCurrent(args);
+#ifdef SSL_CTRL_GET0_IMPLEMENTED_GROUPS
+  ClearErrorOnReturn clear_error_on_return;
+
+  auto ctx = SSLCtxPointer::New();
+  if (!ctx) {
+    return ThrowCryptoError(
+        env, clear_error_on_return.peekError(), "SSL_CTX_new");
+  }
+
+  STACK_OF(OPENSSL_CSTRING)* names = sk_OPENSSL_CSTRING_new_null();
+  if (names == nullptr) return THROW_ERR_MEMORY_ALLOCATION_FAILED(env);
+  auto free_names = OnScopeLeave([&] { sk_OPENSSL_CSTRING_free(names); });
+
+  if (!SSL_CTX_get0_implemented_groups(ctx.get(), 0, names)) {
+    return ThrowCryptoError(env,
+                            clear_error_on_return.peekError(),
+                            "SSL_CTX_get0_implemented_groups");
+  }
+
+  LocalVector<Value> arr(env->isolate());
+  for (int i = 0; i < sk_OPENSSL_CSTRING_num(names); i++) {
+    arr.push_back(
+        OneByteString(env->isolate(), sk_OPENSSL_CSTRING_value(names, i)));
+  }
+
+  args.GetReturnValue().Set(Array::New(env->isolate(), arr.data(), arr.size()));
+#else
+  THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(
+      env, "Listing TLS groups requires OpenSSL 3.5 or later");
+#endif
+}
+
 void CipherBase::GetCiphers(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args);
   std::vector<std::string> cipher_names;
@@ -253,6 +287,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
   SetConstructorFunction(context, target, "CipherBase", t);

   SetMethodNoSideEffect(context, target, "getSSLCiphers", GetSSLCiphers);
+  SetMethodNoSideEffect(context, target, "getSSLGroups", GetSSLGroups);
   SetMethodNoSideEffect(context, target, "getCiphers", GetCiphers);

   SetMethod(context,
@@ -294,6 +329,7 @@ void CipherBase::RegisterExternalReferences(
   registry->Register(SetAAD);

   registry->Register(GetSSLCiphers);
+  registry->Register(GetSSLGroups);
   registry->Register(GetCiphers);

   registry->Register(PublicKeyCipher::Cipher<PublicKeyCipher::kPublic,
diff --git a/src/crypto/crypto_cipher.h b/src/crypto/crypto_cipher.h
index 8817171a2be..87a409c5467 100644
--- a/src/crypto/crypto_cipher.h
+++ b/src/crypto/crypto_cipher.h
@@ -18,6 +18,7 @@ namespace crypto {
 class CipherBase : public BaseObject {
  public:
   static void GetSSLCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);
+  static void GetSSLGroups(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void GetCiphers(const v8::FunctionCallbackInfo<v8::Value>& args);

   static void Initialize(Environment* env, v8::Local<v8::Object> target);
diff --git a/test/parallel/test-tls-get-groups.js b/test/parallel/test-tls-get-groups.js
new file mode 100644
index 00000000000..898395463a3
--- /dev/null
+++ b/test/parallel/test-tls-get-groups.js
@@ -0,0 +1,30 @@
+'use strict';
+const common = require('../common');
+if (!common.hasCrypto)
+  common.skip('missing crypto');
+
+const assert = require('assert');
+const { hasOpenSSL, isBoringSSL } = require('../common/crypto');
+const tls = require('tls');
+
+if (isBoringSSL || !hasOpenSSL(3, 5)) {
+  assert.throws(() => tls.getGroups(), {
+    code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION',
+  });
+  return;
+}
+
+const groups = tls.getGroups();
+assert(Array.isArray(groups));
+assert(groups.length > 0);
+assert(groups.includes('secp256r1'));
+assert(groups.includes('MLKEM768'));
+
+// Each group is accepted by the ecdhCurve option.
+for (const group of groups) {
+  tls.createSecureContext({ ecdhCurve: group });
+}
+
+// The returned array is a copy.
+groups.length = 0;
+assert.notStrictEqual(tls.getGroups().length, 0);