Files
node/test/parallel/test-tls-clienthello-sync-write.js
T
Tim Perry 5b940dd124 tls: drop hand-rolled TLS client hello parser
This existed for 'resumeSession', which needed to do an async lookup
though SSL_CTX_sess_set_get_cb is sync-only. Nowadays both OpenSSL &
BoringSSL have an early ClientHello callback for suspend/resume to
handle this properly, so it was redundant, in addition to being
complicated and generally a bit fragile & scary.

This PR switches to use the modern OpenSSL/BoringSSL mechanisms for this
and drops the client hello parser & related infrastructure completely.

In addition, there's a new test here, covering a fixed bug: the hello
parser silently dropped fragmented hellos, which we now do handle
correctly.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64827
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-08-04 12:33:00 +00:00

54 lines
1.5 KiB
JavaScript

'use strict';
// Writing to a server TLSSocket synchronously from inside a 'resumeSession'
// handler, while the handshake is still waiting on the ClientHello, must not
// break the connection; the data must be delivered once the handshake ends.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { EventEmitter } = require('events');
const fixtures = require('../common/fixtures');
const net = require('net');
const tls = require('tls');
const secureContext = tls.createSecureContext({
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
});
const fakeServer = new EventEmitter();
fakeServer.getTicketKeys = () => null;
let serverSocket;
fakeServer.on('resumeSession', common.mustCall((id, callback) => {
serverSocket.write('from-mid-handshake');
callback(null, null);
}));
const server = net.createServer(common.mustCall((raw) => {
serverSocket = new tls.TLSSocket(raw, {
isServer: true,
secureContext,
server: fakeServer,
});
serverSocket.on('error', common.mustNotCall());
}));
server.listen(0, common.mustCall(() => {
const client = tls.connect({
port: server.address().port,
rejectUnauthorized: false,
}, common.mustCall(() => {
client.on('data', common.mustCall((data) => {
assert.strictEqual(data.toString(), 'from-mid-handshake');
client.end();
server.close();
}));
}));
client.on('error', common.mustNotCall());
}));