1'use strict'; 2 3const common = require('../common'); 4const fixtures = require('../common/fixtures'); 5 6if (!common.hasCrypto) 7 common.skip('missing crypto'); 8 9// This test ensures that tlsSocket.getFinished() and 10// tlsSocket.getPeerFinished() return undefined before 11// secure connection is established, and return non-empty 12// Buffer objects with Finished messages afterwards, also 13// verifying alice.getFinished() == bob.getPeerFinished() 14// and alice.getPeerFinished() == bob.getFinished(). 15 16const assert = require('assert'); 17const tls = require('tls'); 18 19const msg = {}; 20const pem = (n) => fixtures.readKey(`${n}.pem`); 21const server = tls.createServer({ 22 key: pem('agent1-key'), 23 cert: pem('agent1-cert') 24}, common.mustCall((alice) => { 25 msg.server = { 26 alice: alice.getFinished(), 27 bob: alice.getPeerFinished() 28 }; 29 server.close(); 30})); 31 32server.listen(0, common.mustCall(() => { 33 const bob = tls.connect({ 34 port: server.address().port, 35 rejectUnauthorized: false 36 }, common.mustCall(() => { 37 msg.client = { 38 alice: bob.getPeerFinished(), 39 bob: bob.getFinished() 40 }; 41 bob.end(); 42 })); 43 44 msg.before = { 45 alice: bob.getPeerFinished(), 46 bob: bob.getFinished() 47 }; 48})); 49 50process.on('exit', () => { 51 assert.strictEqual(undefined, msg.before.alice); 52 assert.strictEqual(undefined, msg.before.bob); 53 54 assert(Buffer.isBuffer(msg.server.alice)); 55 assert(Buffer.isBuffer(msg.server.bob)); 56 assert(Buffer.isBuffer(msg.client.alice)); 57 assert(Buffer.isBuffer(msg.client.bob)); 58 59 assert(msg.server.alice.length > 0); 60 assert(msg.server.bob.length > 0); 61 assert(msg.client.alice.length > 0); 62 assert(msg.client.bob.length > 0); 63 64 assert(msg.server.alice.equals(msg.client.alice)); 65 assert(msg.server.bob.equals(msg.client.bob)); 66}); 67