@@ -28,7 +28,6 @@ if (!common.opensslCli)
2828 common . skip ( 'node compiled without OpenSSL CLI.' ) ;
2929
3030const assert = require ( 'assert' ) ;
31- const spawn = require ( 'child_process' ) . spawn ;
3231const tls = require ( 'tls' ) ;
3332const https = require ( 'https' ) ;
3433const fixtures = require ( '../common/fixtures' ) ;
@@ -63,50 +62,47 @@ function test(next) {
6362 } ) ;
6463
6564 server . listen ( 0 , function ( ) {
66- const cmd = `s_client -connect 127.0.0.1:${ server . address ( ) . port } ` ;
67- const args = cmd . split ( ' ' ) ;
68- const child = spawn ( common . opensslCli , args ) ;
69-
70- child . stdout . resume ( ) ;
71- child . stderr . resume ( ) ;
65+ const agent = https . Agent ( {
66+ keepAlive : true ,
67+ } ) ;
7268
73- // Count handshakes, start the attack after the initial handshake is done
74- let handshakes = 0 ;
69+ let client ;
7570 let renegs = 0 ;
7671
77- child . stderr . on ( 'data' , function ( data ) {
78- handshakes += ( ( String ( data ) ) . match ( / v e r i f y r e t u r n : 1 / g) || [ ] ) . length ;
79- if ( handshakes === 2 ) spam ( ) ;
80- renegs += ( ( String ( data ) ) . match ( / R E N E G O T I A T I N G / g) || [ ] ) . length ;
81- } ) ;
72+ const options = {
73+ rejectUnauthorized : false ,
74+ agent
75+ } ;
8276
83- child . on ( 'exit' , function ( ) {
84- assert . strictEqual ( renegs , tls . CLIENT_RENEG_LIMIT + 1 ) ;
85- server . close ( ) ;
86- process . nextTick ( next ) ;
87- } ) ;
77+ const { port } = server . address ( ) ;
78+
79+ https . get ( `https://localhost:${ port } /` , options , ( res ) => {
80+ client = res . socket ;
8881
89- let closed = false ;
90- child . stdin . on ( 'error' , function ( err ) {
91- switch ( err . code ) {
92- case 'ECONNRESET' :
93- case 'EPIPE' :
94- break ;
95- default :
96- assert . strictEqual ( err . code , 'ECONNRESET' ) ;
97- break ;
82+ client . on ( 'close' , function ( hadErr ) {
83+ assert . strictEqual ( hadErr , false ) ;
84+ assert . strictEqual ( renegs , tls . CLIENT_RENEG_LIMIT + 1 ) ;
85+ server . close ( ) ;
86+ process . nextTick ( next ) ;
87+ } ) ;
88+
89+ client . on ( 'error' , function ( err ) {
90+ console . log ( 'CLIENT ERR' , err ) ;
91+ throw err ;
92+ } ) ;
93+
94+ spam ( ) ;
95+
96+ // simulate renegotiation attack
97+ function spam ( ) {
98+ client . renegotiate ( { } , ( err ) => {
99+ assert . ifError ( err ) ;
100+ assert . ok ( renegs <= tls . CLIENT_RENEG_LIMIT ) ;
101+ setImmediate ( spam ) ;
102+ } ) ;
103+ renegs ++ ;
98104 }
99- closed = true ;
100- } ) ;
101- child . stdin . on ( 'close' , function ( ) {
102- closed = true ;
103105 } ) ;
104106
105- // simulate renegotiation attack
106- function spam ( ) {
107- if ( closed ) return ;
108- child . stdin . write ( 'R\n' ) ;
109- setTimeout ( spam , 50 ) ;
110- }
111107 } ) ;
112108}
0 commit comments