11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciif (!common.hasIPv6)
81cb0ef41Sopenharmony_ci  common.skip('IPv6 support required');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst initHooks = require('./init-hooks');
111cb0ef41Sopenharmony_ciconst verifyGraph = require('./verify-graph');
121cb0ef41Sopenharmony_ciconst tls = require('tls');
131cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst hooks = initHooks();
161cb0ef41Sopenharmony_cihooks.enable();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci//
191cb0ef41Sopenharmony_ci// Creating server and listening on port
201cb0ef41Sopenharmony_ci//
211cb0ef41Sopenharmony_ciconst server = tls
221cb0ef41Sopenharmony_ci  .createServer({
231cb0ef41Sopenharmony_ci    cert: fixtures.readKey('rsa_cert.crt'),
241cb0ef41Sopenharmony_ci    key: fixtures.readKey('rsa_private.pem'),
251cb0ef41Sopenharmony_ci  })
261cb0ef41Sopenharmony_ci  .on('listening', common.mustCall(onlistening))
271cb0ef41Sopenharmony_ci  .on('secureConnection', common.mustCall(onsecureConnection))
281cb0ef41Sopenharmony_ci  .listen(0);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cifunction onlistening() {
311cb0ef41Sopenharmony_ci  //
321cb0ef41Sopenharmony_ci  // Creating client and connecting it to server
331cb0ef41Sopenharmony_ci  //
341cb0ef41Sopenharmony_ci  tls
351cb0ef41Sopenharmony_ci    .connect(server.address().port, { rejectUnauthorized: false })
361cb0ef41Sopenharmony_ci    .on('secureConnect', common.mustCall(onsecureConnect));
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cifunction onsecureConnection() {}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_cifunction onsecureConnect() {
421cb0ef41Sopenharmony_ci  // end() client socket, which causes slightly different hook events than
431cb0ef41Sopenharmony_ci  // destroy(), but with TLS1.3 destroy() rips the connection down before the
441cb0ef41Sopenharmony_ci  // server completes the handshake.
451cb0ef41Sopenharmony_ci  this.end();
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  // Closing server
481cb0ef41Sopenharmony_ci  server.close(common.mustCall(onserverClosed));
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cifunction onserverClosed() {}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciprocess.on('exit', onexit);
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cifunction onexit() {
561cb0ef41Sopenharmony_ci  hooks.disable();
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  verifyGraph(
591cb0ef41Sopenharmony_ci    hooks,
601cb0ef41Sopenharmony_ci    [ { type: 'TCPSERVERWRAP', id: 'tcpserver:1', triggerAsyncId: null },
611cb0ef41Sopenharmony_ci      { type: 'TCPWRAP', id: 'tcp:1', triggerAsyncId: 'tcpserver:1' },
621cb0ef41Sopenharmony_ci      { type: 'TLSWRAP', id: 'tls:1', triggerAsyncId: 'tcpserver:1' },
631cb0ef41Sopenharmony_ci      { type: 'GETADDRINFOREQWRAP',
641cb0ef41Sopenharmony_ci        id: 'getaddrinforeq:1', triggerAsyncId: 'tls:1' },
651cb0ef41Sopenharmony_ci      { type: 'TCPCONNECTWRAP',
661cb0ef41Sopenharmony_ci        id: 'tcpconnect:1', triggerAsyncId: 'tcp:1' },
671cb0ef41Sopenharmony_ci      { type: 'TCPWRAP', id: 'tcp:2', triggerAsyncId: 'tcpserver:1' },
681cb0ef41Sopenharmony_ci      { type: 'TLSWRAP', id: 'tls:2', triggerAsyncId: 'tcpserver:1' },
691cb0ef41Sopenharmony_ci    ],
701cb0ef41Sopenharmony_ci  );
711cb0ef41Sopenharmony_ci}
72