Skip to content

Commit 271126a

Browse files
Trottaddaleax
authored andcommitted
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 <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 190c063 commit 271126a

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

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

Lines changed: 21 additions & 36 deletions
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
constassert=require('assert');
31-
constspawn=require('child_process').spawn;
3231
consttls=require('tls');
3332
constfixtures=require('../common/fixtures');
3433

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

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

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

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

77-
child.stderr.on('data',function(data){
78-
if(seenError)return;
79-
handshakes+=((String(data)).match(/verifyreturn: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-
letclosed=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+
throwerr;
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
functionspam(){
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)