Skip to content

Commit f37ab79

Browse files
indutnyaddaleax
authored andcommitted
tls: do not crash on STARTTLS when OCSP requested
`TLSSocket` should not have a hard dependency on `tls.Server`, since it may be running without it in cases like `STARTTLS`. Fix: #10704 PR-URL: #10706 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent d301367 commit f37ab79

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

‎lib/_tls_wrap.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ function requestOCSP(self, hello, ctx, cb){
110110

111111
if(!ctx)
112112
ctx=self.server._sharedCreds;
113+
114+
// TLS socket is using a `net.Server` instead of a tls.TLSServer.
115+
// Some TLS properties like `server._sharedCreds` will not be present
116+
if(!ctx)
117+
returncb(null);
118+
119+
// TODO(indutny): eventually disallow raw `SecureContext`
113120
if(ctx.context)
114121
ctx=ctx.context;
115122

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
// Test asynchronous SNI+OCSP on TLSSocket created with `server` set to
4+
// `net.Server` instead of `tls.Server`
5+
6+
constcommon=require('../common');
7+
8+
if(!common.hasCrypto){
9+
common.skip('missing crypto');
10+
return;
11+
}
12+
13+
constassert=require('assert');
14+
constfs=require('fs');
15+
constnet=require('net');
16+
consttls=require('tls');
17+
18+
constkey=fs.readFileSync(common.fixturesDir+'/keys/agent1-key.pem');
19+
constcert=fs.readFileSync(common.fixturesDir+'/keys/agent1-cert.pem');
20+
21+
constserver=net.createServer(common.mustCall((s)=>{
22+
consttlsSocket=newtls.TLSSocket(s,{
23+
isServer: true,
24+
server: server,
25+
26+
secureContext: tls.createSecureContext({
27+
key: key,
28+
cert: cert
29+
}),
30+
31+
SNICallback: common.mustCall((hostname,callback)=>{
32+
assert.strictEqual(hostname,'test.test');
33+
34+
callback(null,null);
35+
})
36+
});
37+
38+
tlsSocket.on('secure',common.mustCall(()=>{
39+
tlsSocket.end();
40+
server.close();
41+
}));
42+
})).listen(0,()=>{
43+
constopts={
44+
servername: 'test.test',
45+
port: server.address().port,
46+
rejectUnauthorized: false,
47+
requestOCSP: true
48+
};
49+
50+
tls.connect(opts,function(){
51+
this.end();
52+
});
53+
});

0 commit comments

Comments
(0)