11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst tls = require('tls'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst options = { 101cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci // NOTE: Certificate Common Name is 'agent1' 131cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem'), 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci // NOTE: TLS 1.3 creates new session ticket **after** handshake so 161cb0ef41Sopenharmony_ci // `getSession()` output will be different even if the session was reused 171cb0ef41Sopenharmony_ci // during the handshake. 181cb0ef41Sopenharmony_ci secureProtocol: 'TLSv1_2_method' 191cb0ef41Sopenharmony_ci}; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst server = tls.createServer(options, common.mustCall((socket) => { 221cb0ef41Sopenharmony_ci socket.end(); 231cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(() => { 241cb0ef41Sopenharmony_ci let connected = false; 251cb0ef41Sopenharmony_ci let session = null; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const client = tls.connect({ 281cb0ef41Sopenharmony_ci rejectUnauthorized: false, 291cb0ef41Sopenharmony_ci port: server.address().port, 301cb0ef41Sopenharmony_ci }, common.mustCall(() => { 311cb0ef41Sopenharmony_ci assert(!connected); 321cb0ef41Sopenharmony_ci assert(!session); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci connected = true; 351cb0ef41Sopenharmony_ci })); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci client.on('session', common.mustCall((newSession) => { 381cb0ef41Sopenharmony_ci assert(connected); 391cb0ef41Sopenharmony_ci assert(!session); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci session = newSession; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci client.end(); 441cb0ef41Sopenharmony_ci server.close(); 451cb0ef41Sopenharmony_ci })); 461cb0ef41Sopenharmony_ci})); 47