1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const assert = require('assert'); 7const tls = require('tls'); 8const fixtures = require('../common/fixtures'); 9const { X509Certificate } = require('crypto'); 10 11const options = { 12 key: fixtures.readKey('agent6-key.pem'), 13 cert: fixtures.readKey('agent6-cert.pem') 14}; 15 16const server = tls.createServer(options, function(cleartext) { 17 cleartext.end('World'); 18}); 19 20server.once('secureConnection', common.mustCall(function(socket) { 21 const cert = socket.getX509Certificate(); 22 assert(cert instanceof X509Certificate); 23 assert.strictEqual( 24 cert.serialNumber, 25 '5B75D77EDC7FB5B7FA9F1424DA4C64FB815DCBDE'); 26})); 27 28server.listen(0, common.mustCall(function() { 29 const socket = tls.connect({ 30 port: this.address().port, 31 rejectUnauthorized: false 32 }, common.mustCall(function() { 33 const peerCert = socket.getPeerX509Certificate(); 34 assert(peerCert.issuerCertificate instanceof X509Certificate); 35 assert.strictEqual(peerCert.issuerCertificate.issuerCertificate, undefined); 36 assert.strictEqual( 37 peerCert.issuerCertificate.serialNumber, 38 '147D36C1C2F74206DE9FAB5F2226D78ADB00A425' 39 ); 40 server.close(); 41 })); 42 socket.end('Hello'); 43})); 44