11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciif (!common.hasCrypto) 71cb0ef41Sopenharmony_ci common.skip('missing crypto'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// This test ensures that tlsSocket.getFinished() and 101cb0ef41Sopenharmony_ci// tlsSocket.getPeerFinished() return undefined before 111cb0ef41Sopenharmony_ci// secure connection is established, and return non-empty 121cb0ef41Sopenharmony_ci// Buffer objects with Finished messages afterwards, also 131cb0ef41Sopenharmony_ci// verifying alice.getFinished() == bob.getPeerFinished() 141cb0ef41Sopenharmony_ci// and alice.getPeerFinished() == bob.getFinished(). 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst assert = require('assert'); 171cb0ef41Sopenharmony_ciconst tls = require('tls'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst msg = {}; 201cb0ef41Sopenharmony_ciconst pem = (n) => fixtures.readKey(`${n}.pem`); 211cb0ef41Sopenharmony_ciconst server = tls.createServer({ 221cb0ef41Sopenharmony_ci key: pem('agent1-key'), 231cb0ef41Sopenharmony_ci cert: pem('agent1-cert') 241cb0ef41Sopenharmony_ci}, common.mustCall((alice) => { 251cb0ef41Sopenharmony_ci msg.server = { 261cb0ef41Sopenharmony_ci alice: alice.getFinished(), 271cb0ef41Sopenharmony_ci bob: alice.getPeerFinished() 281cb0ef41Sopenharmony_ci }; 291cb0ef41Sopenharmony_ci server.close(); 301cb0ef41Sopenharmony_ci})); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 331cb0ef41Sopenharmony_ci const bob = tls.connect({ 341cb0ef41Sopenharmony_ci port: server.address().port, 351cb0ef41Sopenharmony_ci rejectUnauthorized: false 361cb0ef41Sopenharmony_ci }, common.mustCall(() => { 371cb0ef41Sopenharmony_ci msg.client = { 381cb0ef41Sopenharmony_ci alice: bob.getPeerFinished(), 391cb0ef41Sopenharmony_ci bob: bob.getFinished() 401cb0ef41Sopenharmony_ci }; 411cb0ef41Sopenharmony_ci bob.end(); 421cb0ef41Sopenharmony_ci })); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci msg.before = { 451cb0ef41Sopenharmony_ci alice: bob.getPeerFinished(), 461cb0ef41Sopenharmony_ci bob: bob.getFinished() 471cb0ef41Sopenharmony_ci }; 481cb0ef41Sopenharmony_ci})); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ciprocess.on('exit', () => { 511cb0ef41Sopenharmony_ci assert.strictEqual(undefined, msg.before.alice); 521cb0ef41Sopenharmony_ci assert.strictEqual(undefined, msg.before.bob); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci assert(Buffer.isBuffer(msg.server.alice)); 551cb0ef41Sopenharmony_ci assert(Buffer.isBuffer(msg.server.bob)); 561cb0ef41Sopenharmony_ci assert(Buffer.isBuffer(msg.client.alice)); 571cb0ef41Sopenharmony_ci assert(Buffer.isBuffer(msg.client.bob)); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci assert(msg.server.alice.length > 0); 601cb0ef41Sopenharmony_ci assert(msg.server.bob.length > 0); 611cb0ef41Sopenharmony_ci assert(msg.client.alice.length > 0); 621cb0ef41Sopenharmony_ci assert(msg.client.bob.length > 0); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci assert(msg.server.alice.equals(msg.client.alice)); 651cb0ef41Sopenharmony_ci assert(msg.server.bob.equals(msg.client.bob)); 661cb0ef41Sopenharmony_ci}); 67