Skip to content

Commit 357e285

Browse files
danbevrichardlau
authored andcommittedDec 23, 2020
test: add test-tls-use-after-free-regression
This commit adds the test provided in pull request nodejs-private/node-private#230. PR-URL: nodejs-private/node-private#238 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 7f17866 commit 357e285

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const https = require('https');
9+
const tls = require('tls');
10+
11+
const kMessage =
12+
'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: Keep-alive\r\n\r\n';
13+
14+
const key = `-----BEGIN EC PARAMETERS-----
15+
BggqhkjOPQMBBw==
16+
-----END EC PARAMETERS-----
17+
-----BEGIN EC PRIVATE KEY-----
18+
MHcCAQEEIDKfHHbiJMdu2STyHL11fWC7psMY19/gUNpsUpkwgGACoAoGCCqGSM49
19+
AwEHoUQDQgAEItqm+pYj3Ca8bi5mBs+H8xSMxuW2JNn4I+kw3aREsetLk8pn3o81
20+
PWBiTdSZrGBGQSy+UAlQvYeE6Z/QXQk8aw==
21+
-----END EC PRIVATE KEY-----`;
22+
23+
const cert = `-----BEGIN CERTIFICATE-----
24+
MIIBhjCCASsCFDJU1tCo88NYU//pE+DQKO9hUDsFMAoGCCqGSM49BAMCMEUxCzAJ
25+
BgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5l
26+
dCBXaWRnaXRzIFB0eSBMdGQwHhcNMjAwOTIyMDg1NDU5WhcNNDgwMjA3MDg1NDU5
27+
WjBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwY
28+
SW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD
29+
QgAEItqm+pYj3Ca8bi5mBs+H8xSMxuW2JNn4I+kw3aREsetLk8pn3o81PWBiTdSZ
30+
rGBGQSy+UAlQvYeE6Z/QXQk8azAKBggqhkjOPQQDAgNJADBGAiEA7Bdn4F87KqIe
31+
Y/ABy/XIXXpFUb2nyv3zV7POQi2lPcECIQC3UWLmfiedpiIKsf9YRIyO0uEood7+
32+
glj2R1NNr1X68w==
33+
-----END CERTIFICATE-----`;
34+
35+
const server = https.createServer(
36+
{ key, cert },
37+
common.mustCall((req, res) => {
38+
res.writeHead(200);
39+
res.end('boom goes the dynamite\n');
40+
}, 3));
41+
42+
server.listen(0, common.mustCall(() => {
43+
const socket =
44+
tls.connect(
45+
server.address().port,
46+
'localhost',
47+
{ rejectUnauthorized: false },
48+
common.mustCall(() => {
49+
socket.write(kMessage);
50+
socket.write(kMessage);
51+
socket.write(kMessage);
52+
}));
53+
54+
socket.on('data', common.mustCall(() => socket.destroy()));
55+
socket.on('close', () => {
56+
setImmediate(() => server.close());
57+
});
58+
}));

0 commit comments

Comments
 (0)