11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto) common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Test --trace-tls CLI flag.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst { fork } = require('child_process');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciif (process.argv[2] === 'test')
131cb0ef41Sopenharmony_ci  return test();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst binding = require('internal/test/binding').internalBinding;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciif (!binding('tls_wrap').HAVE_SSL_TRACE)
181cb0ef41Sopenharmony_ci  return common.skip('no SSL_trace() compiled into openssl');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciconst child = fork(__filename, ['test'], {
211cb0ef41Sopenharmony_ci  silent: true,
221cb0ef41Sopenharmony_ci  execArgv: ['--trace-tls']
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cilet stdout = '';
261cb0ef41Sopenharmony_cilet stderr = '';
271cb0ef41Sopenharmony_cichild.stdout.setEncoding('utf8');
281cb0ef41Sopenharmony_cichild.stderr.setEncoding('utf8');
291cb0ef41Sopenharmony_cichild.stdout.on('data', (data) => stdout += data);
301cb0ef41Sopenharmony_cichild.stderr.on('data', (data) => stderr += data);
311cb0ef41Sopenharmony_cichild.on('close', common.mustCall((code, signal) => {
321cb0ef41Sopenharmony_ci  // For debugging and observation of actual trace output.
331cb0ef41Sopenharmony_ci  console.log(stderr);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  assert.strictEqual(code, 0);
361cb0ef41Sopenharmony_ci  assert.strictEqual(signal, null);
371cb0ef41Sopenharmony_ci  assert.strictEqual(stdout.trim(), '');
381cb0ef41Sopenharmony_ci  assert.match(stderr, /Warning: Enabling --trace-tls can expose sensitive/);
391cb0ef41Sopenharmony_ci  assert.match(stderr, /Sent Record/);
401cb0ef41Sopenharmony_ci}));
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_cifunction test() {
431cb0ef41Sopenharmony_ci  const {
441cb0ef41Sopenharmony_ci    connect, keys
451cb0ef41Sopenharmony_ci  } = require(fixtures.path('tls-connect'));
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  connect({
481cb0ef41Sopenharmony_ci    client: {
491cb0ef41Sopenharmony_ci      checkServerIdentity: (servername, cert) => { },
501cb0ef41Sopenharmony_ci      ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
511cb0ef41Sopenharmony_ci    },
521cb0ef41Sopenharmony_ci    server: {
531cb0ef41Sopenharmony_ci      cert: keys.agent6.cert,
541cb0ef41Sopenharmony_ci      key: keys.agent6.key
551cb0ef41Sopenharmony_ci    },
561cb0ef41Sopenharmony_ci  }, common.mustCall((err, pair, cleanup) => {
571cb0ef41Sopenharmony_ci    if (pair.server.err) {
581cb0ef41Sopenharmony_ci      console.trace('server', pair.server.err);
591cb0ef41Sopenharmony_ci    }
601cb0ef41Sopenharmony_ci    if (pair.client.err) {
611cb0ef41Sopenharmony_ci      console.trace('client', pair.client.err);
621cb0ef41Sopenharmony_ci    }
631cb0ef41Sopenharmony_ci    assert.ifError(pair.server.err);
641cb0ef41Sopenharmony_ci    assert.ifError(pair.client.err);
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci    return cleanup();
671cb0ef41Sopenharmony_ci  }));
681cb0ef41Sopenharmony_ci}
69