-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls_wrap: use localhost if options.host is empty
tls.connect(options) with no options.host should accept a certificate with CN: 'localhost'. Fix Error: Hostname/IP doesn't match certificate's altnames: "Host: undefined. is not cert's CN: localhost" 'localhost' is not added directly to defaults because that is not always desired (for example, when using options.socket) PR-URL: #1493 Fixes: #1489 Reviewed-By: Brendan Ashworth <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
- Loading branch information
1 parent
22aafa5
commit a7d7463
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
process.exit(); | ||
} | ||
var tls = require('tls'); | ||
|
||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); | ||
var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); | ||
|
||
// https://github.com/iojs/io.js/issues/1489 | ||
// tls.connect(options) with no options.host should accept a cert with | ||
// CN:'localhost' | ||
tls.createServer({ | ||
key: key, | ||
cert: cert | ||
}).listen(common.PORT); | ||
|
||
var socket = tls.connect({ | ||
port: common.PORT, | ||
ca: cert, | ||
// No host set here. 'localhost' is the default, | ||
// but tls.checkServerIdentity() breaks before the fix with: | ||
// Error: Hostname/IP doesn't match certificate's altnames: | ||
// "Host: undefined. is not cert's CN: localhost" | ||
}, function() { | ||
assert(socket.authorized); | ||
process.exit(); | ||
}); |