@@ -28,7 +28,6 @@ if (!common.opensslCli)
28
28
common . skip ( 'node compiled without OpenSSL CLI.' ) ;
29
29
30
30
const assert = require ( 'assert' ) ;
31
- const spawn = require ( 'child_process' ) . spawn ;
32
31
const tls = require ( 'tls' ) ;
33
32
const https = require ( 'https' ) ;
34
33
const fixtures = require ( '../common/fixtures' ) ;
@@ -63,50 +62,47 @@ function test(next) {
63
62
} ) ;
64
63
65
64
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
+ } ) ;
72
68
73
- // Count handshakes, start the attack after the initial handshake is done
74
- let handshakes = 0 ;
69
+ let client ;
75
70
let renegs = 0 ;
76
71
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
+ } ;
82
76
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 ;
88
81
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 ++ ;
98
104
}
99
- closed = true ;
100
- } ) ;
101
- child . stdin . on ( 'close' , function ( ) {
102
- closed = true ;
103
105
} ) ;
104
106
105
- // simulate renegotiation attack
106
- function spam ( ) {
107
- if ( closed ) return ;
108
- child . stdin . write ( 'R\n' ) ;
109
- setTimeout ( spam , 50 ) ;
110
- }
111
107
} ) ;
112
108
}
0 commit comments