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