help
help copied to clipboard
[tls.Server] connection event and setSecureContext()
Details
Just a quick question: it seems that setting a new secure context inside a connection event listener will not impact this connection but only the ones after.
However in the documentation I read that This event is emitted when a new TCP stream is established, before the TLS handshake begins.
Is it a bug?
Node.js version
Tested in Node 16.16.0 and 18.7.0.
Example code
const { genSelfSignedCert } = require('@xen-orchestra/self-signed')
genSelfSignedCert().then(({ cert, key }) => {
new require('tls').Server({ cert, key }).listen(47911).on('connection', function () {
genSelfSignedCert().then(
({ cert, key }) => {
console.log(String(cert))
this.setSecureContext({ cert, key })
}
)
})
})
Then, using openssl s_client -connect 127.0.0.1:47911 show that the previous certificate is always used in stead of the new one.
Operating system
Fedora 36 with Linux 5.18.13-200.fc36.x86_64
Scope
urntime
Module and version
Not applicable.
I checked it and it didn't happen. I would suggest you add this after setSecureContext.
console.log(this._sharedCreds.context.getCertificate().toString('base64'))
The console.log indeed displays the freshly set secure context, but nevertheless, the (openssl) client does receive the previous one.
There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.
Closing after no activity on this issue for 12 months.