Skip to content

Commit 92e7433

Browse files
committed
tls: fix 'hostless' tls connection verification
And fix last failing tests
1 parent 1ccdde9 commit 92e7433

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/tls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ exports.connect = function(/* [port, host], options, cb */) {
12381238
var sslcontext = crypto.createCredentials(options);
12391239

12401240
convertNPNProtocols(options.NPNProtocols, this);
1241-
var hostname = options.servername || options.host,
1241+
var hostname = options.servername || options.host || 'localhost',
12421242
pair = new SecurePair(sslcontext, false, true,
12431243
options.rejectUnauthorized === true ? true : false,
12441244
{

test/simple/test-tls-client-verify.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if (!process.versions.openssl) {
2525
}
2626

2727

28+
var hosterr = 'Hostname/IP doesn\'t match certificate\'s altnames';
2829
var testCases =
2930
[{ ca: ['ca1-cert'],
3031
key: 'agent2-key',
@@ -101,10 +102,12 @@ function testServers(index, servers, clientOptions, cb) {
101102

102103
console.error('connecting...');
103104
var client = tls.connect(clientOptions, function() {
105+
var authorized = client.authorized ||
106+
client.authorizationError === hosterr;
104107

105-
console.error('expected: ' + ok + ' authed: ' + client.authorized);
108+
console.error('expected: ' + ok + ' authed: ' + authorized);
106109

107-
assert.equal(ok, client.authorized);
110+
assert.equal(ok, authorized);
108111
server.close();
109112
});
110113

0 commit comments

Comments
 (0)