node/test/parallel/test-tls-write-error.js
Daniel Bevenius 640fe94354 src,test: support dynamically linking OpenSSL 3.0
This commit enables node to dynamically link against OpenSSL 3.0.

The motivation for opening this PR even though OpenSSL 3.0 has not been
released yet is to allow a nightly CI job to be created. This will
allow us stay on top of changes required for OpenSSL 3.0, and also to
make sure that changes to node crypto do not cause issues when linking
to OpenSSL 3.0.

PR-URL: https://github.com/nodejs/node/pull/37669
Refs: https://github.com/nodejs/node/issues/29817
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2021-03-16 05:59:25 +01:00

56 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const { TestTLSSocket, ccs } = require('../common/tls');
const fixtures = require('../common/fixtures');
const https = require('https');
// Regression test for an use-after-free bug in the TLS implementation that
// would occur when `SSL_write()` failed.
// Refs: https://github.com/nodejs-private/security/issues/189
const server_key = fixtures.readKey('agent1-key.pem');
const server_cert = fixtures.readKey('agent1-cert.pem');
const opts = {
key: server_key,
cert: server_cert,
ciphers: 'ALL@SECLEVEL=0'
};
const server = https.createServer(opts, (req, res) => {
res.write('hello');
}).listen(0, common.mustCall(() => {
const client = new TestTLSSocket(server_cert);
client.connect({
host: 'localhost',
port: server.address().port
}, common.mustCall(() => {
const ch = client.createClientHello();
client.write(ch);
}));
client.once('data', common.mustCall((buf) => {
let remaining = buf;
do {
remaining = client.parseTLSFrame(remaining);
} while (remaining.length > 0);
const cke = client.createClientKeyExchange();
const finished = client.createFinished();
const ill = client.createIllegalHandshake();
const frames = Buffer.concat([
cke,
ccs,
client.encrypt(finished),
client.encrypt(ill)
]);
client.write(frames, common.mustCall(() => {
client.end();
server.close();
}));
}));
}));