GeezerVison is showing github.com — tls_wrap: use localhost if options.host is empty · Fishrock123/node@a7d7463
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -858,7 +858,8 @@ exports.connect = function(/* [port, host], options, cb */) { |
858 | 858 |
|
859 | 859 | var hostname = options.servername || |
860 | 860 | options.host || |
861 | | - options.socket && options.socket._host, |
| 861 | + (options.socket && options.socket._host) || |
| 862 | + 'localhost', |
862 | 863 | NPN = {}, |
863 | 864 | context = tls.createSecureContext(options); |
864 | 865 | tls.convertNPNProtocols(options.NPNProtocols, NPN); |
|
Collapse file
Copy file name to clipboard +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +var common = require('../common'); |
| 2 | + |
| 3 | +if (!common.hasCrypto) { |
| 4 | + console.log('1..0 # Skipped: missing crypto'); |
| 5 | + process.exit(); |
| 6 | +} |
| 7 | +var tls = require('tls'); |
| 8 | + |
| 9 | +var assert = require('assert'); |
| 10 | +var fs = require('fs'); |
| 11 | +var path = require('path'); |
| 12 | + |
| 13 | +var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); |
| 14 | +var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); |
| 15 | + |
| 16 | +// https://github.com/iojs/io.js/issues/1489 |
| 17 | +// tls.connect(options) with no options.host should accept a cert with |
| 18 | +// CN:'localhost' |
| 19 | +tls.createServer({ |
| 20 | + key: key, |
| 21 | + cert: cert |
| 22 | +}).listen(common.PORT); |
| 23 | + |
| 24 | +var socket = tls.connect({ |
| 25 | + port: common.PORT, |
| 26 | + ca: cert, |
| 27 | + // No host set here. 'localhost' is the default, |
| 28 | + // but tls.checkServerIdentity() breaks before the fix with: |
| 29 | + // Error: Hostname/IP doesn't match certificate's altnames: |
| 30 | + // "Host: undefined. is not cert's CN: localhost" |
| 31 | +}, function() { |
| 32 | + assert(socket.authorized); |
| 33 | + process.exit(); |
| 34 | +}); |