From: Francis Dupont Date: Fri, 12 Mar 2021 11:13:17 +0000 (+0100) Subject: [#1661] Fixed rebase X-Git-Tag: Kea-1.9.6~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6860c9c4a4900fa98fb2e7123300fd401b57cfc9;p=thirdparty%2Fkea.git [#1661] Fixed rebase --- diff --git a/src/lib/asiolink/openssl_tls.h b/src/lib/asiolink/openssl_tls.h index 69692758d3..9c224afcfa 100644 --- a/src/lib/asiolink/openssl_tls.h +++ b/src/lib/asiolink/openssl_tls.h @@ -230,138 +230,6 @@ const int STREAM_TRUNCATED = boost::asio::ssl::error::stream_truncated; const int STREAM_TRUNCATED = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ); #endif -/// @brief The type of underlying TLS streams. -typedef boost::asio::ssl::stream TlsStreamImpl; - -/// @brief The type of X509 certificates. -typedef ::X509 TlsCertificate; - -/// @brief TlsStreamBase constructor. -/// -/// @param Callback The type of callbacks. -/// @param TlsStreamImpl The type of underlying TLS streams. -/// @param TlsCertificate The type of X509 certificates. -template -TlsStreamBase:: -TlsStreamBase(IOService& service, TlsContextPtr context) - : TlsStreamImpl(service.get_io_service(), context->getContext()), - role_(context->getRole()) { -} - -/// @brief OpenSSL TLS stream. -/// -/// @param callback The callback. -template -class TlsStream : public TlsStreamBase { -public: - - /// @brief Type of the base. - typedef TlsStreamBase Base; - - /// @brief Constructor. - /// - /// @param service I/O Service object used to manage the stream. - /// @param context Pointer to the TLS context. - /// @note The caller must not provide a null pointer to the TLS context. - TlsStream(IOService& service, TlsContextPtr context) - : TlsStreamImpl(service.get_io_service(), context->getContext()), - role_(context->role_) { - } - - /// @brief Destructor. - virtual ~TlsStream() { } - - /// @brief TLS Handshake. - /// - /// @param callback Callback object. - virtual void handshake(Callback& callback) { - Base::async_handshake(roleToImpl(Base::getRole()), callback); - } - - /// @brief TLS shutdown. - /// - /// @param callback Callback object. - virtual void shutdown(Callback& callback) { - Base::async_shutdown(callback); - } - - /// @brief Clear the SSL object. - virtual void clear() { - static_cast(::SSL_clear(this->native_handle())); - } - - /// @brief Return the peer certificate. - /// - /// @note The native_handle() method is used so it can't be made const. - /// @note Do not forget to free it when no longer used. - virtual TlsCertificate* getPeerCert() { - return (::SSL_get_peer_certificate(this->native_handle())); - } - - /// @break Return the commonName part of the subjectName of - /// the peer certificate. - /// - /// First commonName when there are more than one, in UTF-8. - /// - /// @return The commonName part of the subjectName or the empty string. - virtual std::string getSubject() { - TlsCertificate* cert = getPeerCert(); - if (!cert) { - return (""); - } - ::X509_NAME *name = ::X509_get_subject_name(cert); - int loc = ::X509_NAME_get_index_by_NID(name, NID_commonName, -1); - ::X509_NAME_ENTRY* ne = ::X509_NAME_get_entry(name, loc); - if (!ne) { - ::X509_free(cert); - return (""); - } - unsigned char* buf = 0; - int len = ::ASN1_STRING_to_UTF8(&buf, ::X509_NAME_ENTRY_get_data(ne)); - if (len < 0) { - ::X509_free(cert); - return (""); - } - std::string ret(reinterpret_cast(buf), static_cast(len)); - ::OPENSSL_free(buf); - ::X509_free(cert); - return (ret); - } - - /// @break Return the commonName part of the issuerName of - /// the peer certificate. - /// - /// First commonName when there are more than one, in UTF-8. - /// - /// @return The commonName part of the issuerName or the empty string. - virtual std::string getIssuer() { - TlsCertificate* cert = getPeerCert(); - if (!cert) { - return (""); - } - ::X509_NAME *name = ::X509_get_issuer_name(cert); - int loc = ::X509_NAME_get_index_by_NID(name, NID_commonName, -1); - ::X509_NAME_ENTRY* ne = ::X509_NAME_get_entry(name, loc); - if (!ne) { - ::X509_free(cert); - return (""); - } - unsigned char* buf = 0; - int len = ::ASN1_STRING_to_UTF8(&buf, ::X509_NAME_ENTRY_get_data(ne)); - if (len < 0) { - ::X509_free(cert); - return (""); - } - std::string ret(reinterpret_cast(buf), static_cast(len)); - ::OPENSSL_free(buf); - ::X509_free(cert); - return (ret); - } -}; - -// Stream truncated error code. -const int STREAM_TRUNCATED = boost::asio::ssl::error::stream_truncated; - } // namespace asiolink } // namespace isc