Skip to content

Commit 7569711

Browse files
committed
tls: do not hang without newSession handler
When listening for client hello parser events (like OCSP requests), do not hang if `newSession` event handler is not present. Fix: nodejs/node-v0.x-archive#8660Fix: nodejs/node-v0.x-archive#25735 Reviewed-By: Fedor Indutny <[email protected]> PR-URL: nodejs/node-v0.x-archive#25739
1 parent 39e0563 commit 7569711

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

‎lib/_tls_legacy.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,17 @@ function onnewsession(key, session){
662662
varself=this;
663663
varonce=false;
664664

665-
self.server.emit('newSession',key,session,function(){
665+
if(!self.server.emit('newSession',key,session,done))
666+
done();
667+
668+
functiondone(){
666669
if(once)
667670
return;
668671
once=true;
669672

670673
if(self.ssl)
671674
self.ssl.newSessionDone();
672-
});
675+
};
673676
}
674677

675678

‎lib/_tls_wrap.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ function onnewsession(key, session){
201201
varonce=false;
202202

203203
this._newSessionPending=true;
204-
this.server.emit('newSession',key,session,function(){
204+
if(!this.server.emit('newSession',key,session,done))
205+
done();
206+
207+
functiondone(){
205208
if(once)
206209
return;
207210
once=true;
@@ -212,7 +215,7 @@ function onnewsession(key, session){
212215
if(self._securePending)
213216
self._finishInit();
214217
self._securePending=false;
215-
});
218+
}
216219
}
217220

218221

‎test/simple/test-tls-ocsp-callback.js‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ if (!common.opensslCli){
3131
process.exit(0);
3232
}
3333

34+
varassert=require('assert');
35+
vartls=require('tls');
36+
varconstants=require('constants');
37+
varfs=require('fs');
38+
varjoin=require('path').join;
39+
3440
test({response: false},function(){
35-
test({response: 'hello world'});
41+
test({response: 'hello world'},function(){
42+
test({ocsp: false});
43+
});
3644
});
3745

3846
functiontest(testOptions,cb){
39-
varassert=require('assert');
40-
vartls=require('tls');
41-
varfs=require('fs');
42-
varjoin=require('path').join;
43-
varspawn=require('child_process').spawn;
4447

4548
varkeyFile=join(common.fixturesDir,'keys','agent1-key.pem');
4649
varcertFile=join(common.fixturesDir,'keys','agent1-cert.pem');
@@ -54,6 +57,7 @@ function test(testOptions, cb){
5457
ca: [ca]
5558
};
5659
varrequestCount=0;
60+
varclientSecure=0;
5761
varocspCount=0;
5862
varocspResponse;
5963
varsession;
@@ -83,9 +87,12 @@ function test(testOptions, cb){
8387
server.listen(common.PORT,function(){
8488
varclient=tls.connect({
8589
port: common.PORT,
86-
requestOCSP: true,
90+
requestOCSP: testOptions.ocsp!==false,
91+
secureOptions: testOptions.ocsp===false ?
92+
constants.SSL_OP_NO_TICKET : 0,
8793
rejectUnauthorized: false
8894
},function(){
95+
clientSecure++;
8996
});
9097
client.on('OCSPResponse',function(resp){
9198
ocspResponse=resp;
@@ -98,12 +105,19 @@ function test(testOptions, cb){
98105
});
99106

100107
process.on('exit',function(){
108+
if(testOptions.ocsp===false){
109+
assert.equal(requestCount,clientSecure);
110+
assert.equal(requestCount,1);
111+
return;
112+
}
113+
101114
if(testOptions.response){
102115
assert.equal(ocspResponse.toString(),testOptions.response);
103116
}else{
104117
assert.ok(ocspResponse===null);
105118
}
106119
assert.equal(requestCount,testOptions.response ? 0 : 1);
120+
assert.equal(clientSecure,requestCount);
107121
assert.equal(ocspCount,1);
108122
});
109123
}

0 commit comments

Comments
(0)