You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SNICallback doesn't appear to work with tls.createSecurePair() #4878
Docs say that there should be two arguments passed to SNICallback, the servername and the callback to call with the secure context. The second argument doesn't appear to be passed through when the TLS connection is created as a stream with tls.createSecurePair().
I get the error:
TypeError: cb is not a function
at Object.tls.createSecurePair.SNICallback [as onselect]
I note that when removing the callback argument I get an OpenSSL error in my terminal:
#!/usr/bin/env node
varfs=require('fs');varnet=require('net');vartls=require('tls');varsecureContext=tls.createSecureContext({cert: fs.readFileSync('test_cert.pem'),key: fs.readFileSync('test_key.pem')})varserver=net.Server(function(raw){varpair=tls.createSecurePair(null,true,false,false,{SNICallback: function(servername,cb){console.log('servername',servername);cb(null,secureContext);}});raw.pipe(pair.encrypted).pipe(raw);});server.listen(4443,function(){varaddr=server.address();console.log('Server listening on %s %s:%d',addr.family,addr.address,addr.port);});
Here, tls.createSecurePair() calls into lib/_tls_legacy.js. That version of SNICallback never had a callback argument, IIRC. It's implemented in terms of SSL_CTX_set_tlsext_servername_callback(), its callback needs to accept or reject immediately. The non-legacy SNICallback is implemented through SSL_set_cert_cb(), which is asynchronous and can defer the action until a later time.
I think it should be possible to move the legacy implementation over to SSL_set_cert_cb(). It's a bit of work but it would reduce the line count. Alternatively, we could just document it.
'I think it should be possible to move the legacy implementation over to SSL_set_cert_cb()'
Do you mean moving the whole createSecurePair() from _tls_legacy?
Sounds interesting and I would really like to work on that, but might require a bit of mentoring.
@jhamhader let me know if you need any help on this. I would be more than happy to supply any amount of hints, or pick it over from you (if you are busy with other things).
Activity
evanlucas commentedon Jan 26, 2016
Yea, confirmed...looks like https://github.com/nodejs/node/blob/master/src/node_crypto.cc#L2691 could be where the issue lies? /cc @indutny
bnoordhuis commentedon Jan 26, 2016
Reproducing the test case here for posterity:
Here,
tls.createSecurePair()calls intolib/_tls_legacy.js. That version ofSNICallbacknever had a callback argument, IIRC. It's implemented in terms ofSSL_CTX_set_tlsext_servername_callback(), its callback needs to accept or reject immediately. The non-legacySNICallbackis implemented throughSSL_set_cert_cb(), which is asynchronous and can defer the action until a later time.I think it should be possible to move the legacy implementation over to
SSL_set_cert_cb(). It's a bit of work but it would reduce the line count. Alternatively, we could just document it.jhamhader commentedon Feb 16, 2016
@bnoordhuis by saying
Do you mean moving the whole
createSecurePair()from_tls_legacy?Sounds interesting and I would really like to work on that, but might require a bit of mentoring.
jhamhader commentedon Feb 17, 2016
I'm on it.
bnoordhuis commentedon Feb 24, 2016
@webertlima Looks to be the same issue, yes.
dcposch commentedon Mar 7, 2016
@jhamhader how goes?
indutny commentedon Mar 9, 2016
@jhamhader let me know if you need any help on this. I would be more than happy to supply any amount of hints, or pick it over from you (if you are busy with other things).
jhamhader commentedon Mar 9, 2016
I would like that and will contact you over IRC/mail.
webertrlz commentedon Jun 17, 2016
Any progress on this?
jhamhader commentedon Jun 17, 2016
tls.createSecurePair()has been deprecated (#6063)indutny commentedon Sep 16, 2016
Looks like the issue is resolved in some sense.