• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4if (!common.hasCrypto) common.skip('missing crypto');
5const fixtures = require('../common/fixtures');
6
7// Test enableTrace: option for TLS.
8
9const assert = require('assert');
10const { fork } = require('child_process');
11
12if (process.argv[2] === 'test')
13  return test();
14
15const binding = require('internal/test/binding').internalBinding;
16
17if (!binding('tls_wrap').HAVE_SSL_TRACE)
18  return common.skip('no SSL_trace() compiled into openssl');
19
20const child = fork(__filename, ['test'], { silent: true });
21
22let stderr = '';
23child.stderr.setEncoding('utf8');
24child.stderr.on('data', (data) => stderr += data);
25child.on('close', common.mustCall(() => {
26  assert(/Received Record/.test(stderr));
27  assert(/ClientHello/.test(stderr));
28}));
29
30// For debugging and observation of actual trace output.
31child.stderr.pipe(process.stderr);
32child.stdout.pipe(process.stdout);
33
34child.on('exit', common.mustCall((code) => {
35  assert.strictEqual(code, 0);
36}));
37
38function test() {
39  const {
40    connect, keys
41  } = require(fixtures.path('tls-connect'));
42
43  connect({
44    client: {
45      checkServerIdentity: (servername, cert) => { },
46      ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
47    },
48    server: {
49      cert: keys.agent6.cert,
50      key: keys.agent6.key,
51      enableTrace: true,
52    },
53  }, common.mustCall((err, pair, cleanup) => {
54    pair.client.conn.enableTrace();
55
56    return cleanup();
57  }));
58}
59