From c3dd21b7a0032a20b1cd3d8a587b519ed1e5ade9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 25 Jan 2021 16:38:51 -0800 Subject: [PATCH] tls: add ability to get cert/peer cert as X509Certificate object Signed-off-by: James M Snell --- doc/api/crypto.md | 10 ++++ doc/api/tls.md | 24 ++++++++ lib/_tls_wrap.js | 13 ++++ lib/internal/crypto/x509.js | 29 ++++++--- src/crypto/crypto_tls.cc | 26 ++++++++ src/crypto/crypto_tls.h | 4 ++ src/crypto/crypto_x509.cc | 60 +++++++++++-------- src/crypto/crypto_x509.h | 13 ++-- test/parallel/test-tls-getcertificate-x509.js | 43 +++++++++++++ 9 files changed, 183 insertions(+), 39 deletions(-) create mode 100644 test/parallel/test-tls-getcertificate-x509.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 4afb6d27d38706..03f34a29a12cc4 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1804,6 +1804,16 @@ added: v15.6.0 The issuer identification included in this certificate. +### `x509.issuerCertificate` + + +* Type: {X509Certificate} + +The issuer certificate (if known). Will be `undefined` if the issuer +certificate is not available. + ### `x509.keyUsage` + +* Returns: {X509Certificate} + +Returns the peer certificate as an {X509Certificate} object. + +If there is no peer certificate, or the socket has been destroyed, +`undefined` will be returned. + +### `tlsSocket.getX509Certificate()` + + +* Returns: {X509Certificate} + +Returns the local certificate as an {X509Certificate} object. + +If there is no local certificate, or the socket has been destroyed, +`undefined` will be returned. + ### `tlsSocket.isSessionReused()`