diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index 38913f28a..5f6fe33cf 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -465,6 +465,11 @@ String UnbufferedAsioTlsStream::GetVerifyError() const return m_VerifyError; } +std::shared_ptr UnbufferedAsioTlsStream::GetPeerCertificate() +{ + return std::shared_ptr(SSL_get_peer_certificate(native_handle()), X509_free); +} + void UnbufferedAsioTlsStream::BeforeHandshake(handshake_type type) { namespace ssl = boost::asio::ssl; diff --git a/lib/base/tlsstream.hpp b/lib/base/tlsstream.hpp index 6156a3d2f..3974d12b8 100644 --- a/lib/base/tlsstream.hpp +++ b/lib/base/tlsstream.hpp @@ -119,6 +119,7 @@ public: bool IsVerifyOK() const; String GetVerifyError() const; + std::shared_ptr GetPeerCertificate(); template inline diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index de6e754c0..c534c0969 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -523,7 +523,7 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const } }); - std::shared_ptr cert (SSL_get_peer_certificate(sslConn.native_handle()), X509_free); + std::shared_ptr cert (sslConn.GetPeerCertificate()); bool verify_ok = false; String identity; Endpoint::Ptr endpoint; diff --git a/lib/remote/jsonrpcconnection-pki.cpp b/lib/remote/jsonrpcconnection-pki.cpp index 66f88479b..2f66eb7b5 100644 --- a/lib/remote/jsonrpcconnection-pki.cpp +++ b/lib/remote/jsonrpcconnection-pki.cpp @@ -34,7 +34,7 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona /* Use the presented client certificate if not provided. */ if (certText.IsEmpty()) { auto stream (origin->FromClient->GetStream()); - cert = std::shared_ptr(SSL_get_peer_certificate(stream->next_layer().native_handle()), X509_free); + cert = stream->next_layer().GetPeerCertificate(); } else { cert = StringToCertificate(certText); }