• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7// Verify that multiple CA certificates can be provided, and that for
8// convenience that can also be in newline-separated strings.
9
10const tls = require('tls');
11const fixtures = require('../common/fixtures');
12
13const ca1 = fixtures.readKey('ca1-cert.pem', 'utf8');
14const ca2 = fixtures.readKey('ca2-cert.pem', 'utf8');
15const cert = fixtures.readKey('agent3-cert.pem', 'utf8');
16const key = fixtures.readKey('agent3-key.pem', 'utf8');
17
18function test(ca) {
19  const server = tls.createServer({ ca, cert, key });
20
21  server.addContext('agent3', { ca, cert, key });
22
23  const host = common.localhostIPv4;
24  server.listen(0, host, common.mustCall(() => {
25    const socket = tls.connect({
26      servername: 'agent3',
27      host,
28      port: server.address().port,
29      ca
30    }, common.mustCall(() => {
31      socket.end();
32    }));
33
34    socket.on('close', () => {
35      server.close();
36    });
37  }));
38}
39
40// `ca1` is not actually necessary for the certificate validation -- maybe
41// the fixtures should be written in a way that requires it?
42test([ca1, ca2]);
43test(`${ca1}\n${ca2}`);
44