mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Both events (backed by oncertcb) could potentially write to the socket synchronously, re-entering SSL mid-handshake and breaking the connection, so we defer them just like the new 'resumeSession' behaviour. Also fixes a small bug in the error path of EmitClientHello, which now bails out more aggressively instead of resuming handshakes in a V8 teardown scenario. Co-authored-by: Filip Skokan <panva.ip@gmail.com> 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>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Writing to a server TLSSocket synchronously from inside an SNICallback,
|
|
// while the handshake is still waiting on the certificate callback, 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 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'),
|
|
});
|
|
|
|
let serverSocket;
|
|
const server = net.createServer(common.mustCall((raw) => {
|
|
serverSocket = new tls.TLSSocket(raw, {
|
|
isServer: true,
|
|
secureContext,
|
|
SNICallback: common.mustCall((servername, callback) => {
|
|
assert.strictEqual(servername, 'localhost');
|
|
serverSocket.write('from-mid-handshake');
|
|
callback(null, null);
|
|
}),
|
|
});
|
|
serverSocket.on('error', common.mustNotCall());
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = tls.connect({
|
|
port: server.address().port,
|
|
servername: 'localhost',
|
|
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());
|
|
}));
|