From db35fee1e1ca909f0f33940c0d9501a72baf2375 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 8 Nov 2018 13:40:46 -0800 Subject: [PATCH] tls: get the local certificate after tls handshake Add an API to get the local certificate chosen during TLS handshake from the SSL context. Fix: https://github.com/nodejs/node/issues/24095 PR-URL: https://github.com/nodejs/node/pull/24261 Fixes: https://github.com/nodejs/node/issues/24095 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Daniel Bevenius --- doc/api/tls.md | 17 ++++++++++++++ lib/_tls_common.js | 3 +++ lib/_tls_wrap.js | 12 +++++++++- src/node_crypto.cc | 23 +++++++++++++++++-- src/node_crypto.h | 1 + .../test-tls-peer-certificate-multi-keys.js | 12 ++++++++-- test/parallel/test-tls-peer-certificate.js | 2 ++ .../test-tls-pfx-authorizationerror.js | 4 ++++ 8 files changed, 69 insertions(+), 5 deletions(-) diff --git a/doc/api/tls.md b/doc/api/tls.md index 1d0d8bfad27739..5bda2f26c0af33 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -566,6 +566,22 @@ added: v0.11.4 Always returns `true`. This may be used to distinguish TLS sockets from regular `net.Socket` instances. +### tlsSocket.getCertificate() + + +* Returns: {Object} + +Returns an object representing the local certificate. The returned object has +some properties corresponding to the fields of the certificate. + +See [`tls.TLSSocket.getPeerCertificate()`][] for an example of the certificate +structure. + +If there is no local certificate, an empty object will be returned. If the +socket has been destroyed, `null` will be returned. + ### tlsSocket.getCipher()