• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const fixtures = require('../common/fixtures');
4
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7
8const tls = require('tls');
9const assert = require('assert');
10
11const cert = fixtures.readKey('rsa_cert.crt');
12const key = fixtures.readKey('rsa_private.pem');
13
14// https://github.com/nodejs/node/issues/1489
15// tls.connect(options) with no options.host should accept a cert with
16//   CN:'localhost'
17const server = tls.createServer({
18  key,
19  cert
20}).listen(0, common.mustCall(function() {
21  const socket = tls.connect({
22    port: this.address().port,
23    ca: cert,
24    // No host set here. 'localhost' is the default,
25    // but tls.checkServerIdentity() breaks before the fix with:
26    // Error: Hostname/IP doesn't match certificate's altnames:
27    //   "Host: undefined. is not cert's CN: localhost"
28  }, common.mustCall(function() {
29    assert(socket.authorized);
30    socket.destroy();
31    server.close();
32  }));
33}));
34