|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Verify that servername (SNI) is preserved on resumed TLS sessions. |
| 4 | +// Regression test for https://github.com/nodejs/node/issues/59202 |
| 5 | + |
| 6 | +const common = require('../common'); |
| 7 | +if (!common.hasCrypto) |
| 8 | + common.skip('missing crypto'); |
| 9 | + |
| 10 | +// The fix only applies to OpenSSL (not BoringSSL). |
| 11 | +if (process.features.openssl_is_boringssl) |
| 12 | + common.skip('BoringSSL does not support SSL_SESSION_set1_hostname'); |
| 13 | + |
| 14 | +const assert = require('assert'); |
| 15 | +const tls = require('tls'); |
| 16 | +const fixtures = require('../common/fixtures'); |
| 17 | + |
| 18 | +const SERVERNAME = 'agent1.example.com'; |
| 19 | + |
| 20 | +const serverOptions = { |
| 21 | + key: fixtures.readKey('agent1-key.pem'), |
| 22 | + cert: fixtures.readKey('agent1-cert.pem'), |
| 23 | +}; |
| 24 | + |
| 25 | +const server = tls.createServer(serverOptions, common.mustCall((socket) => { |
| 26 | + // servername must be the SNI value sent by the client on both the initial |
| 27 | + // and the resumed handshake. |
| 28 | + assert.strictEqual(socket.servername, SERVERNAME); |
| 29 | + socket.end(); |
| 30 | +}, 2)); |
| 31 | + |
| 32 | +server.listen(0, common.mustCall(function() { |
| 33 | + const port = server.address().port; |
| 34 | + |
| 35 | + // First connection: establish a session with an SNI servername. |
| 36 | + const client1 = tls.connect({ |
| 37 | + port, |
| 38 | + servername: SERVERNAME, |
| 39 | + rejectUnauthorized: false, |
| 40 | + }, common.mustCall()); |
| 41 | + |
| 42 | + client1.once('session', common.mustCall((session) => { |
| 43 | + // Second connection: resume the session and verify the servername is |
| 44 | + // preserved on the server side. |
| 45 | + const client2 = tls.connect({ |
| 46 | + port, |
| 47 | + servername: SERVERNAME, |
| 48 | + rejectUnauthorized: false, |
| 49 | + session, |
| 50 | + }, common.mustCall(() => { |
| 51 | + assert.strictEqual(client2.isSessionReused(), true, |
| 52 | + 'expected session to be reused'); |
| 53 | + client2.end(); |
| 54 | + })); |
| 55 | + |
| 56 | + client2.on('close', common.mustCall(() => server.close())); |
| 57 | + })); |
| 58 | + |
| 59 | + client1.resume(); |
| 60 | +})); |
0 commit comments