11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst tls = require('tls');
81cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
91cb0ef41Sopenharmony_ciconst { X509Certificate } = require('crypto');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst options = {
121cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent6-key.pem'),
131cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent6-cert.pem')
141cb0ef41Sopenharmony_ci};
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst server = tls.createServer(options, function(cleartext) {
171cb0ef41Sopenharmony_ci  cleartext.end('World');
181cb0ef41Sopenharmony_ci});
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciserver.once('secureConnection', common.mustCall(function(socket) {
211cb0ef41Sopenharmony_ci  const cert = socket.getX509Certificate();
221cb0ef41Sopenharmony_ci  assert(cert instanceof X509Certificate);
231cb0ef41Sopenharmony_ci  assert.strictEqual(
241cb0ef41Sopenharmony_ci    cert.serialNumber,
251cb0ef41Sopenharmony_ci    '5B75D77EDC7FB5B7FA9F1424DA4C64FB815DCBDE');
261cb0ef41Sopenharmony_ci}));
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() {
291cb0ef41Sopenharmony_ci  const socket = tls.connect({
301cb0ef41Sopenharmony_ci    port: this.address().port,
311cb0ef41Sopenharmony_ci    rejectUnauthorized: false
321cb0ef41Sopenharmony_ci  }, common.mustCall(function() {
331cb0ef41Sopenharmony_ci    const peerCert = socket.getPeerX509Certificate();
341cb0ef41Sopenharmony_ci    assert(peerCert.issuerCertificate instanceof X509Certificate);
351cb0ef41Sopenharmony_ci    assert.strictEqual(peerCert.issuerCertificate.issuerCertificate, undefined);
361cb0ef41Sopenharmony_ci    assert.strictEqual(
371cb0ef41Sopenharmony_ci      peerCert.issuerCertificate.serialNumber,
381cb0ef41Sopenharmony_ci      '147D36C1C2F74206DE9FAB5F2226D78ADB00A425'
391cb0ef41Sopenharmony_ci    );
401cb0ef41Sopenharmony_ci    server.close();
411cb0ef41Sopenharmony_ci  }));
421cb0ef41Sopenharmony_ci  socket.end('Hello');
431cb0ef41Sopenharmony_ci}));
44