help icon indicating copy to clipboard operation
help copied to clipboard

[tls.Server] connection event and setSecureContext()

Open julien-f opened this issue 3 years ago • 2 comments

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.

julien-f avatar Jul 29 '22 16:07 julien-f

I checked it and it didn't happen. I would suggest you add this after setSecureContext.

console.log(this._sharedCreds.context.getCertificate().toString('base64'))

Shonke avatar Jul 30 '22 04:07 Shonke

The console.log indeed displays the freshly set secure context, but nevertheless, the (openssl) client does receive the previous one.

julien-f avatar Aug 02 '22 15:08 julien-f

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.

github-actions[bot] avatar Dec 01 '23 01:12 github-actions[bot]

Closing after no activity on this issue for 12 months.

github-actions[bot] avatar Jan 01 '24 01:01 github-actions[bot]