11cb0ef41Sopenharmony_ci// Certs in NODE_EXTRA_CA_CERTS are used for TLS peer validation
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci'use strict';
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (!common.hasCrypto)
71cb0ef41Sopenharmony_ci  common.skip('missing crypto');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst tls = require('tls');
111cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst { fork } = require('child_process');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciif (process.env.CHILD) {
161cb0ef41Sopenharmony_ci  const copts = {
171cb0ef41Sopenharmony_ci    port: process.env.PORT,
181cb0ef41Sopenharmony_ci    checkServerIdentity: common.mustCall(),
191cb0ef41Sopenharmony_ci  };
201cb0ef41Sopenharmony_ci  const client = tls.connect(copts, common.mustCall(function() {
211cb0ef41Sopenharmony_ci    client.end('hi');
221cb0ef41Sopenharmony_ci  }));
231cb0ef41Sopenharmony_ci  return;
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst options = {
271cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
281cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem'),
291cb0ef41Sopenharmony_ci};
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciconst server = tls.createServer(options, common.mustCall(function(s) {
321cb0ef41Sopenharmony_ci  s.end('bye');
331cb0ef41Sopenharmony_ci  server.close();
341cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(function() {
351cb0ef41Sopenharmony_ci  const env = {
361cb0ef41Sopenharmony_ci    ...process.env,
371cb0ef41Sopenharmony_ci    CHILD: 'yes',
381cb0ef41Sopenharmony_ci    PORT: this.address().port,
391cb0ef41Sopenharmony_ci    NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem')
401cb0ef41Sopenharmony_ci  };
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  fork(__filename, { env }).on('exit', common.mustCall(function(status) {
431cb0ef41Sopenharmony_ci    // Client did not succeed in connecting
441cb0ef41Sopenharmony_ci    assert.strictEqual(status, 0);
451cb0ef41Sopenharmony_ci  }));
461cb0ef41Sopenharmony_ci}));
47