11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// Check cert chain is received by client, and is completed with the ca cert 61cb0ef41Sopenharmony_ci// known to the client. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst { 91cb0ef41Sopenharmony_ci assert, connect, debug, keys 101cb0ef41Sopenharmony_ci} = require(fixtures.path('tls-connect')); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// agent6-cert.pem includes cert for agent6 and ca3, split it apart and 141cb0ef41Sopenharmony_ci// provide ca3 in the .ca property. 151cb0ef41Sopenharmony_ciconst agent6Chain = keys.agent6.cert.split(/(?=-----BEGIN CERTIFICATE-----)/); 161cb0ef41Sopenharmony_ciconst agent6End = agent6Chain[0]; 171cb0ef41Sopenharmony_ciconst agent6Middle = agent6Chain[1]; 181cb0ef41Sopenharmony_ciconnect({ 191cb0ef41Sopenharmony_ci client: { 201cb0ef41Sopenharmony_ci checkServerIdentity: (servername, cert) => { }, 211cb0ef41Sopenharmony_ci ca: keys.agent6.ca, 221cb0ef41Sopenharmony_ci }, 231cb0ef41Sopenharmony_ci server: { 241cb0ef41Sopenharmony_ci cert: agent6End, 251cb0ef41Sopenharmony_ci key: keys.agent6.key, 261cb0ef41Sopenharmony_ci ca: agent6Middle, 271cb0ef41Sopenharmony_ci }, 281cb0ef41Sopenharmony_ci}, function(err, pair, cleanup) { 291cb0ef41Sopenharmony_ci assert.ifError(err); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci const peer = pair.client.conn.getPeerCertificate(); 321cb0ef41Sopenharmony_ci debug('peer:\n', peer); 331cb0ef41Sopenharmony_ci assert.match(peer.serialNumber, /5B75D77EDC7FB5B7FA9F1424DA4C64FB815DCBDE/i); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci const next = pair.client.conn.getPeerCertificate(true).issuerCertificate; 361cb0ef41Sopenharmony_ci const root = next.issuerCertificate; 371cb0ef41Sopenharmony_ci delete next.issuerCertificate; 381cb0ef41Sopenharmony_ci debug('next:\n', next); 391cb0ef41Sopenharmony_ci assert.match(next.serialNumber, /147D36C1C2F74206DE9FAB5F2226D78ADB00A425/i); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci debug('root:\n', root); 421cb0ef41Sopenharmony_ci assert.match(root.serialNumber, /4AB16C8DFD6A7D0D2DFCABDF9C4B0E92C6AD0229/i); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci return cleanup(); 451cb0ef41Sopenharmony_ci}); 46