Skip to content

Commit c421619

Browse files
committed
test: remove s_client from test-tls-ci-reneg-attack
Rewrite test-tls-ci-reneg-attack to use tls.renegotiate() instead of external (and potentially unpredictable/quirky/buggy) s_client. Refs: #25676 (comment) PR-URL: #25700 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 6d937c0 commit c421619

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

test/pummel/test-tls-ci-reneg-attack.js

+21-36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ if (!common.opensslCli)
2828
common.skip('node compiled without OpenSSL CLI.');
2929

3030
const assert = require('assert');
31-
const spawn = require('child_process').spawn;
3231
const tls = require('tls');
3332
const fixtures = require('../common/fixtures');
3433

@@ -51,63 +50,49 @@ function test(next) {
5150
key: fixtures.readSync('test_key.pem')
5251
};
5352

54-
let seenError = false;
55-
5653
const server = tls.createServer(options, function(conn) {
5754
conn.on('error', function(err) {
5855
console.error(`Caught exception: ${err}`);
5956
assert(/TLS session renegotiation attack/.test(err));
6057
conn.destroy();
61-
seenError = true;
6258
});
6359
conn.pipe(conn);
6460
});
6561

66-
server.listen(common.PORT, function() {
67-
const args = (`s_client -connect 127.0.0.1:${common.PORT}`).split(' ');
68-
const child = spawn(common.opensslCli, args);
69-
70-
child.stdout.resume();
71-
child.stderr.resume();
62+
server.listen(0, function() {
63+
const options = {
64+
host: server.address().host,
65+
port: server.address().port,
66+
rejectUnauthorized: false
67+
};
68+
const client = tls.connect(options, spam);
7269

73-
// Count handshakes, start the attack after the initial handshake is done
74-
let handshakes = 0;
7570
let renegs = 0;
7671

77-
child.stderr.on('data', function(data) {
78-
if (seenError) return;
79-
handshakes += ((String(data)).match(/verify return:1/g) || []).length;
80-
if (handshakes === 2) spam();
81-
renegs += ((String(data)).match(/RENEGOTIATING/g) || []).length;
82-
});
83-
84-
child.on('exit', function() {
72+
client.on('close', function() {
8573
assert.strictEqual(renegs, tls.CLIENT_RENEG_LIMIT + 1);
8674
server.close();
8775
process.nextTick(next);
8876
});
8977

90-
let closed = false;
91-
child.stdin.on('error', function(err) {
92-
switch (err.code) {
93-
case 'ECONNRESET':
94-
case 'EPIPE':
95-
break;
96-
default:
97-
assert.strictEqual(err.code, 'ECONNRESET');
98-
break;
99-
}
100-
closed = true;
78+
client.on('error', function(err) {
79+
console.log('CLIENT ERR', err);
80+
throw err;
10181
});
102-
child.stdin.on('close', function() {
103-
closed = true;
82+
83+
client.on('close', function(hadErr) {
84+
assert.strictEqual(hadErr, false);
10485
});
10586

10687
// simulate renegotiation attack
10788
function spam() {
108-
if (closed) return;
109-
child.stdin.write('R\n');
110-
setTimeout(spam, 50);
89+
client.write('');
90+
client.renegotiate({}, (err) => {
91+
assert.ifError(err);
92+
assert.ok(renegs <= tls.CLIENT_RENEG_LIMIT);
93+
spam();
94+
});
95+
renegs++;
11196
}
11297
});
11398
}

0 commit comments

Comments
 (0)