Commit 5ebc6299ba2 for nodejs

commit 5ebc6299ba2a09e19908caa7480f85182bb6ac99
Author: James M Snell <jasnell@gmail.com>
Date:   Fri Nov 27 23:01:24 2026 +0000

    net: offer only SHA-256 DTLS 1.3 suites with psk

    A server holding a certificate commits to a SHA-384 suite in its
    HelloRetryRequest, which a client's SHA-256 PSK cannot be used with.

    Assisted-by: Claude Opus 5.5
    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67837
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>

diff --git a/doc/api/dtls.md b/doc/api/dtls.md
index 5e92cce68cd..eaa5d271071 100644
--- a/doc/api/dtls.md
+++ b/doc/api/dtls.md
@@ -583,9 +583,15 @@ exception.

 The default DTLS 1.2 cipher list excludes PSK, so giving `psk` without `ciphers`
 enables the PSK suites. DTLS 1.3 needs no special suites for PSK, but a key
-supplied by a callback or a map can only be used with a SHA-256 suite, which the
-defaults include. Supplying `ciphers` disables that and uses exactly what was
-asked for.
+supplied by a callback or a map can only be used with a SHA-256 suite, so a
+client given `psk` without `ciphers` offers only `TLS_AES_128_GCM_SHA256` and
+`TLS_CHACHA20_POLY1305_SHA256`. Supplying `ciphers` disables both and uses
+exactly what was asked for.
+
+A server that also has a certificate takes the client's order of DTLS 1.3
+suites. A client from another implementation that prefers a SHA-384 suite is
+therefore offered one in the HelloRetryRequest, and fails, since its key cannot
+be used with it; such a client has to put the SHA-256 suites first.

 A server keeps the certificate suites as well, since it may serve both kinds
 of client on one port. A client does not: a client that configured a
diff --git a/lib/internal/dtls/dtls.js b/lib/internal/dtls/dtls.js
index 8f4db033b4b..efd7dd50d67 100644
--- a/lib/internal/dtls/dtls.js
+++ b/lib/internal/dtls/dtls.js
@@ -928,6 +928,7 @@ function createContext(options = kEmptyObject) {
     // recorded traffic. DEFAULT stays on the end so a context that also has a
     // certificate can still use it.
     context.setCiphers(isServer ? kPSKCiphersServer : kPSKCiphersClient);
+    if (!isServer) context.setCipherSuites(kPSKCipherSuitesClient);
   }

   // Applied after the ciphers, which may raise the floor.
@@ -1143,6 +1144,15 @@ function applyCiphers(context, ciphers, versions) {
 const kPSKCiphersServer = 'DEFAULT:kECDHEPSK:kDHEPSK:kPSK:!kRSAPSK';
 const kPSKCiphersClient = 'kECDHEPSK:kDHEPSK:kPSK:!kRSAPSK';

+// The DTLS 1.3 suites a PSK client offers when ciphers is not given. A key
+// from psk is bound to SHA-256, and a server holding a certificate does not
+// prefer SHA-256 suites on its own: offered the defaults, it commits to a
+// SHA-384 suite in the HelloRetryRequest, and the client can then only fail
+// with bad_psk. Offering only the suites the key can be used with leaves the
+// server nothing else to choose.
+const kPSKCipherSuitesClient =
+  'TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256';
+
 /**
  * Configure pre-shared keys on a context.
  * @param {object} context Native context.