From f3c7e88c0c1b3fe63a02d653a41c3fbfc169a91e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 13 Nov 2026 12:54:00 +0100 Subject: [PATCH] test: deflake test-tls-resume-servername The PSK server returned the secret for any identity. The client also offers its resumption ticket as a PSK identity, and OpenSSL passes it to pskCallback when its leading bytes read as a string, for example when the random ticket key name starts with a NUL byte. The server then used the ticket as an external PSK with the wrong key and failed the binder check with decrypt_error, in about 0.7% of runs. Only return the secret for the identity the client uses. Refs: https://github.com/nodejs/node/actions/runs/43411330264/job/131838200960 Signed-off-by: Matteo Collina --- test/parallel/test-tls-resume-servername.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-tls-resume-servername.js b/test/parallel/test-tls-resume-servername.js index 927ee597891c..c98f9ae7bdb4 100644 --- a/test/parallel/test-tls-resume-servername.js +++ b/test/parallel/test-tls-resume-servername.js @@ -82,11 +82,18 @@ server.listen(0, common.mustCall(async () => { // TLS1.3 PSK works by pretending to be resumption (but it's not). const secret = Buffer.alloc(32, 1); const ciphers = 'TLS_AES_128_GCM_SHA256'; - const psk = tls.createServer({ ciphers, pskCallback: () => secret }, - common.mustCall((socket) => { - assert.strictEqual(socket.servername, 'psk.example'); - socket.end(); - }, 2)); + // The resumption ticket is offered as a PSK identity too, and OpenSSL + // passes it to pskCallback when its leading bytes read as a string (e.g. + // '' when the random ticket key name starts with a NUL byte). Only answer + // for the identity the client uses, or the ticket is taken as an external + // PSK with the wrong key and the handshake fails with decrypt_error. + const psk = tls.createServer({ + ciphers, + pskCallback: (socket, identity) => (identity === 'client' ? secret : null), + }, common.mustCall((socket) => { + assert.strictEqual(socket.servername, 'psk.example'); + socket.end(); + }, 2)); await new Promise((resolve) => psk.listen(0, resolve)); const pskOptions = { port: psk.address().port,