From 1c3863abfd40b2d95b7151a75427d9fd948e8e63 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 9 Sep 2013 18:18:05 +0400 Subject: [PATCH] tls: fix setting NPN protocols The NPN protocols was set on `require('tls')` or `global` object instead of being a local property. This fact lead to strange persistence of NPN protocols, and sometimes incorrect protocol selection (when no NPN protocols were passed in client options). fix #6168 --- lib/tls.js | 5 +++-- test/simple/test-tls-npn-server-client.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index ea3d2e4..976ff46 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -1321,12 +1321,13 @@ exports.connect = function(/* [port, host], options, cb */) { var sslcontext = crypto.createCredentials(options); - convertNPNProtocols(options.NPNProtocols, this); + var NPN = {}; + convertNPNProtocols(options.NPNProtocols, NPN); var hostname = options.servername || options.host || 'localhost', pair = new SecurePair(sslcontext, false, true, options.rejectUnauthorized === true ? true : false, { - NPNProtocols: this.NPNProtocols, + NPNProtocols: NPN.NPNProtocols, servername: hostname, cleartext: options.cleartext, encrypted: options.encrypted diff --git a/test/simple/test-tls-npn-server-client.js b/test/simple/test-tls-npn-server-client.js index 86e10be..d9e8f91 100644 --- a/test/simple/test-tls-npn-server-client.js +++ b/test/simple/test-tls-npn-server-client.js @@ -66,6 +66,12 @@ var clientsOptions = [{ key: serverOptions.key, cert: serverOptions.cert, crl: serverOptions.crl, + rejectUnauthorized: false +},{ + port: serverPort, + key: serverOptions.key, + cert: serverOptions.cert, + crl: serverOptions.crl, NPNProtocols: ['first-priority-unsupported', 'x', 'y'], rejectUnauthorized: false }]; @@ -91,7 +97,9 @@ function startTest() { connectClient(clientsOptions[0], function() { connectClient(clientsOptions[1], function() { connectClient(clientsOptions[2], function() { - server.close(); + connectClient(clientsOptions[3], function() { + server.close(); + }); }); }); }); @@ -100,6 +108,8 @@ function startTest() { process.on('exit', function() { assert.equal(serverResults[0], clientsResults[0]); assert.equal(serverResults[1], clientsResults[1]); - assert.equal(serverResults[2], 'first-priority-unsupported'); + assert.equal(serverResults[2], 'http/1.1'); assert.equal(clientsResults[2], false); + assert.equal(serverResults[3], 'first-priority-unsupported'); + assert.equal(clientsResults[3], false); }); -- 2.7.4