What would you like to discuss?

Is there a way to retrieve TLS certificate after response?

in Node you can do:

res.connection.getPeerCertificate()

right now I'm setting a variable from checkServerIdentity, but it doesn't always work as expected

https: {
  checkServerIdentity (hostname, certificate) {
    sslCertificate = certificate
   }
}

Checklist

  • [X] I have read the documentation.
0

checkServerIdentity has a different purpose. https://nodejs.org/api/tls.html#tlscheckserveridentityhostname-cert

You could try response.socket.getPeerCertificate() but I'm not sure if this will work as the socket may be closed already.

0

Alternatively you could try the response event

0

@szmarczak thanks for taking time to answer!

I'm using TypeScript and getting "Property 'getPeerCertificate' does not exist on type 'Socket'." But, when I use (response.socket as TLSSocket).getPeerCertificate() in my response event listener, it works regardless!

Maybe the types need some improvement?

0

Maybe the types need some improvement?

No, that's correct. socket can be either net.Socket or tls.TLSSocket which extends net.Socket.

0
© 2022 pullanswer.com - All rights reserved.