Skip to content

Commit 166c405

Browse files
committed
tls: fix lazy initialization of clienthello parser
`server.SNICallback` was initialized with `SNICallback.bind(this)`, and therefore check `this.SNICallback === SNICallback` was always false, and `_tls_wrap.js` always thought that it was a custom callback instead of default one. Which in turn was causing clienthello parser to be enabled regardless of presence of SNI contexts.
1 parent b26d346 commit 166c405

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

lib/_tls_wrap.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ function Server(/* [options], listener */) {
427427
requestCert: self.requestCert,
428428
rejectUnauthorized: self.rejectUnauthorized,
429429
NPNProtocols: self.NPNProtocols,
430-
SNICallback: self.SNICallback
430+
SNICallback: options.SNICallback || SNICallback
431431
});
432432

433433
function listener() {
@@ -517,11 +517,6 @@ Server.prototype.setOptions = function(options) {
517517
}
518518
if (secureOptions) this.secureOptions = secureOptions;
519519
if (options.NPNProtocols) tls.convertNPNProtocols(options.NPNProtocols, this);
520-
if (options.SNICallback) {
521-
this.SNICallback = options.SNICallback;
522-
} else {
523-
this.SNICallback = this.SNICallback.bind(this);
524-
}
525520
if (options.sessionIdContext) {
526521
this.sessionIdContext = options.sessionIdContext;
527522
} else if (this.requestCert) {
@@ -547,7 +542,7 @@ Server.prototype.addContext = function(servername, credentials) {
547542
function SNICallback(servername, callback) {
548543
var ctx;
549544

550-
this._contexts.some(function(elem) {
545+
this.server._contexts.some(function(elem) {
551546
if (!util.isNull(servername.match(elem[0]))) {
552547
ctx = elem[1];
553548
return true;
@@ -557,8 +552,6 @@ function SNICallback(servername, callback) {
557552
callback(null, ctx);
558553
}
559554

560-
Server.prototype.SNICallback = SNICallback;
561-
562555

563556
// Target API:
564557
//

0 commit comments

Comments
 (0)