1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const { TestTLSSocket, ccs } = require('../common/tls'); 7const fixtures = require('../common/fixtures'); 8const https = require('https'); 9 10// Regression test for an use-after-free bug in the TLS implementation that 11// would occur when `SSL_write()` failed. 12// Refs: https://github.com/nodejs-private/security/issues/189 13 14const server_key = fixtures.readKey('agent1-key.pem'); 15const server_cert = fixtures.readKey('agent1-cert.pem'); 16 17const opts = { 18 key: server_key, 19 cert: server_cert 20}; 21 22const server = https.createServer(opts, (req, res) => { 23 res.write('hello'); 24}).listen(0, common.mustCall(() => { 25 const client = new TestTLSSocket(server_cert); 26 27 client.connect({ 28 host: 'localhost', 29 port: server.address().port 30 }, common.mustCall(() => { 31 const ch = client.createClientHello(); 32 client.write(ch); 33 })); 34 35 client.once('data', common.mustCall((buf) => { 36 let remaining = buf; 37 do { 38 remaining = client.parseTLSFrame(remaining); 39 } while (remaining.length > 0); 40 41 const cke = client.createClientKeyExchange(); 42 const finished = client.createFinished(); 43 const ill = client.createIllegalHandshake(); 44 const frames = Buffer.concat([ 45 cke, 46 ccs, 47 client.encrypt(finished), 48 client.encrypt(ill), 49 ]); 50 client.write(frames, common.mustCall(() => { 51 client.end(); 52 server.close(); 53 })); 54 })); 55})); 56