Skip to content

Instantly share code, notes, and snippets.

@indutny

indutny/1.patch Secret

Created July 20, 2012 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indutny/6ddfd4cdcdad13d8d394 to your computer and use it in GitHub Desktop.
Save indutny/6ddfd4cdcdad13d8d394 to your computer and use it in GitHub Desktop.
commit 50122fed8ae29c982fa4c806136c4b24dd2de382
Author: Fedor Indutny <fedor.indutny@gmail.com>
Date: Fri Jul 20 21:43:12 2012 +0400
tls: fix 'hostless' tls connection verification
And fix last failing tests
diff --git a/lib/tls.js b/lib/tls.js
index 584ee0a..089ad9b 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -1208,7 +1208,7 @@ exports.connect = function(/* [port, host], options, cb */) {
var sslcontext = crypto.createCredentials(options);
convertNPNProtocols(options.NPNProtocols, this);
- var hostname = options.servername || options.host,
+ var hostname = options.servername || options.host || 'localhost',
pair = new SecurePair(sslcontext, false, true,
options.rejectUnauthorized === true ? true : false,
{
diff --git a/test/simple/test-tls-client-verify.js b/test/simple/test-tls-client-verify.js
index 4e5c4ab..9b1083f 100644
--- a/test/simple/test-tls-client-verify.js
+++ b/test/simple/test-tls-client-verify.js
@@ -25,6 +25,7 @@ if (!process.versions.openssl) {
}
+var hosterr = 'Hostname/IP doesn\'t match certificate\'s altnames';
var testCases =
[{ ca: ['ca1-cert'],
key: 'agent2-key',
@@ -101,10 +102,12 @@ function testServers(index, servers, clientOptions, cb) {
console.error('connecting...');
var client = tls.connect(clientOptions, function() {
+ var authorized = client.authorized ||
+ client.authorizationError === hosterr;
- console.error('expected: ' + ok + ' authed: ' + client.authorized);
+ console.error('expected: ' + ok + ' authed: ' + authorized);
- assert.equal(ok, client.authorized);
+ assert.equal(ok, authorized);
server.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment