11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst tls = require('tls');
91cb0ef41Sopenharmony_ciconst util = require('util');
101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst sent = 'hello world';
131cb0ef41Sopenharmony_ciconst serverOptions = {
141cb0ef41Sopenharmony_ci  isServer: true,
151cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
161cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
171cb0ef41Sopenharmony_ci};
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cilet ssl = null;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciprocess.on('exit', function() {
221cb0ef41Sopenharmony_ci  assert.ok(ssl !== null);
231cb0ef41Sopenharmony_ci  // If the internal pointer to stream_ isn't cleared properly then this
241cb0ef41Sopenharmony_ci  // will abort.
251cb0ef41Sopenharmony_ci  util.inspect(ssl);
261cb0ef41Sopenharmony_ci});
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciconst server = tls.createServer(serverOptions, function(s) {
291cb0ef41Sopenharmony_ci  s.on('data', function() { });
301cb0ef41Sopenharmony_ci  s.on('end', function() {
311cb0ef41Sopenharmony_ci    server.close();
321cb0ef41Sopenharmony_ci    s.destroy();
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci}).listen(0, function() {
351cb0ef41Sopenharmony_ci  const c = new tls.TLSSocket();
361cb0ef41Sopenharmony_ci  ssl = c.ssl;
371cb0ef41Sopenharmony_ci  c.connect(this.address().port, function() {
381cb0ef41Sopenharmony_ci    c.end(sent);
391cb0ef41Sopenharmony_ci  });
401cb0ef41Sopenharmony_ci});
41