Skip to content

Commit e69ea78

Browse files
addaleaxMylesBorins
authored andcommitted
tls: fix SNICallback without .server option
`options.server` only needs to be set when its contents are actually being inspected. PR-URL: #17835 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a329cf6 commit e69ea78

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/_tls_wrap.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,8 @@ TLSSocket.prototype._init = function(socket, wrap) {
511511
if (process.features.tls_sni &&
512512
options.isServer &&
513513
options.SNICallback &&
514-
options.server &&
515514
(options.SNICallback !== SNICallback ||
516-
options.server._contexts.length)) {
515+
(options.server && options.server._contexts.length))) {
517516
assert(typeof options.SNICallback === 'function');
518517
this._SNICallback = options.SNICallback;
519518
ssl.enableCertCb();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
// This is based on test-tls-securepair-fiftharg.js
4+
// for the deprecated `tls.createSecurePair()` variant.
5+
6+
const common = require('../common');
7+
if (!common.hasCrypto)
8+
common.skip('missing crypto');
9+
10+
const assert = require('assert');
11+
const tls = require('tls');
12+
const fixtures = require('../common/fixtures');
13+
const makeDuplexPair = require('../common/duplexpair');
14+
15+
const { clientSide, serverSide } = makeDuplexPair();
16+
new tls.TLSSocket(serverSide, {
17+
isServer: true,
18+
SNICallback: common.mustCall((servername, cb) => {
19+
assert.strictEqual(servername, 'www.google.com');
20+
})
21+
});
22+
23+
// captured traffic from browser's request to https://www.google.com
24+
const sslHello = fixtures.readSync('google_ssl_hello.bin');
25+
26+
clientSide.write(sslHello);

0 commit comments

Comments
 (0)