From ba1ce9c8537b04af463436ec0b590fc829729e9c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 25 Jul 2019 16:45:39 +0200 Subject: [PATCH] Replace std::shared_ptr with Shared::Ptr --- lib/base/tlsutility.cpp | 12 ++++++------ lib/base/tlsutility.hpp | 9 +++++---- lib/cli/consolecommand.cpp | 2 +- lib/perfdata/elasticsearchwriter.cpp | 2 +- lib/perfdata/gelfwriter.cpp | 2 +- lib/perfdata/influxdbwriter.cpp | 2 +- lib/remote/apilistener.cpp | 4 ++-- lib/remote/apilistener.hpp | 4 ++-- lib/remote/pkiutility.cpp | 4 ++-- plugins/check_nscp_api.cpp | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index 3c6751002..7b8a6967f 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -58,7 +58,7 @@ void InitializeOpenSSL() l_SSLInitialized = true; } -static void SetupSslContext(const std::shared_ptr& context, const String& pubkey, const String& privkey, const String& cakey) +static void SetupSslContext(const Shared::Ptr& context, const String& pubkey, const String& privkey, const String& cakey) { char errbuf[256]; @@ -156,13 +156,13 @@ static void SetupSslContext(const std::shared_ptr& co * @param cakey CA certificate chain file. * @returns An SSL context. */ -std::shared_ptr MakeAsioSslContext(const String& pubkey, const String& privkey, const String& cakey) +Shared::Ptr MakeAsioSslContext(const String& pubkey, const String& privkey, const String& cakey) { namespace ssl = boost::asio::ssl; InitializeOpenSSL(); - auto context (std::make_shared(ssl::context::tlsv12)); + auto context (Shared::Make(ssl::context::tlsv12)); SetupSslContext(context, pubkey, privkey, cakey); @@ -174,7 +174,7 @@ std::shared_ptr MakeAsioSslContext(const String& pubk * @param context The ssl context. * @param cipherList The ciper list. **/ -void SetCipherListToSSLContext(const std::shared_ptr& context, const String& cipherList) +void SetCipherListToSSLContext(const Shared::Ptr& context, const String& cipherList) { char errbuf[256]; @@ -215,7 +215,7 @@ void SetCipherListToSSLContext(const std::shared_ptr& * @param context The ssl context. * @param tlsProtocolmin The minimum TLS protocol version. */ -void SetTlsProtocolminToSSLContext(const std::shared_ptr& context, const String& tlsProtocolmin) +void SetTlsProtocolminToSSLContext(const Shared::Ptr& context, const String& tlsProtocolmin) { // tlsProtocolmin has no effect since we enforce TLS 1.2 since 2.11. /* @@ -235,7 +235,7 @@ void SetTlsProtocolminToSSLContext(const std::shared_ptr& context, const String& crlPath) +void AddCRLToSSLContext(const Shared::Ptr& context, const String& crlPath) { char errbuf[256]; X509_STORE *x509_store = SSL_CTX_get_cert_store(context->native_handle()); diff --git a/lib/base/tlsutility.hpp b/lib/base/tlsutility.hpp index de7033311..0f120aaf9 100644 --- a/lib/base/tlsutility.hpp +++ b/lib/base/tlsutility.hpp @@ -5,6 +5,7 @@ #include "base/i2-base.hpp" #include "base/object.hpp" +#include "base/shared.hpp" #include "base/string.hpp" #include #include @@ -22,10 +23,10 @@ namespace icinga void InitializeOpenSSL(); -std::shared_ptr MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String()); -void AddCRLToSSLContext(const std::shared_ptr& context, const String& crlPath); -void SetCipherListToSSLContext(const std::shared_ptr& context, const String& cipherList); -void SetTlsProtocolminToSSLContext(const std::shared_ptr& context, const String& tlsProtocolmin); +Shared::Ptr MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String()); +void AddCRLToSSLContext(const Shared::Ptr& context, const String& crlPath); +void SetCipherListToSSLContext(const Shared::Ptr& context, const String& cipherList); +void SetTlsProtocolminToSSLContext(const Shared::Ptr& context, const String& tlsProtocolmin); String GetCertificateCN(const std::shared_ptr& certificate); std::shared_ptr GetX509Certificate(const String& pemfile); diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 41dcdf99a..41b6590e4 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -524,7 +524,7 @@ incomplete: */ Shared::Ptr ConsoleCommand::Connect() { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 9e9a91978..c7d33a6c5 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -588,7 +588,7 @@ OptionalTlsStream ElasticsearchWriter::Connect() bool tls = GetEnableTls(); if (tls) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath()); diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index ed3b678c3..9ea470107 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -163,7 +163,7 @@ void GelfWriter::ReconnectInternal() bool ssl = GetEnableTls(); if (ssl) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath()); diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 9036a79dc..9ea2a95dd 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -177,7 +177,7 @@ OptionalTlsStream InfluxdbWriter::Connect() bool ssl = GetSslEnable(); if (ssl) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(GetSslCert(), GetSslKey(), GetSslCaCert()); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 1d49c63d2..7e54d06de 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -178,7 +178,7 @@ void ApiListener::UpdateSSLContext() { namespace ssl = boost::asio::ssl; - std::shared_ptr context; + Shared::Ptr context; try { context = MakeAsioSslContext(GetDefaultCertPath(), GetDefaultKeyPath(), GetDefaultCaPath()); @@ -423,7 +423,7 @@ bool ApiListener::AddListener(const String& node, const String& service) return true; } -void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Shared::Ptr& server, const std::shared_ptr& sslContext) +void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Shared::Ptr& server, const Shared::Ptr& sslContext) { namespace asio = boost::asio; diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 49116ca80..ca33e4d30 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -125,7 +125,7 @@ protected: void ValidateTlsHandshakeTimeout(const Lazy& lvalue, const ValidationUtils& utils) override; private: - std::shared_ptr m_SSLContext; + Shared::Ptr m_SSLContext; mutable boost::mutex m_AnonymousClientsLock; mutable boost::mutex m_HttpClientsLock; @@ -153,7 +153,7 @@ private: void NewClientHandler(boost::asio::yield_context yc, const Shared::Ptr& client, const String& hostname, ConnectionRole role); void NewClientHandlerInternal(boost::asio::yield_context yc, const Shared::Ptr& client, const String& hostname, ConnectionRole role); - void ListenerCoroutineProc(boost::asio::yield_context yc, const Shared::Ptr& server, const std::shared_ptr& sslContext); + void ListenerCoroutineProc(boost::asio::yield_context yc, const Shared::Ptr& server, const Shared::Ptr& sslContext); WorkQueue m_RelayQueue; WorkQueue m_SyncQueue{0, 4}; diff --git a/lib/remote/pkiutility.cpp b/lib/remote/pkiutility.cpp index a9200d739..9b96ca0ea 100644 --- a/lib/remote/pkiutility.cpp +++ b/lib/remote/pkiutility.cpp @@ -81,7 +81,7 @@ int PkiUtility::SignCsr(const String& csrfile, const String& certfile) std::shared_ptr PkiUtility::FetchCert(const String& host, const String& port) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(); @@ -149,7 +149,7 @@ int PkiUtility::GenTicket(const String& cn, const String& salt, std::ostream& ti int PkiUtility::RequestCertificate(const String& host, const String& port, const String& keyfile, const String& certfile, const String& cafile, const std::shared_ptr& trustedCert, const String& ticket) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(certfile, keyfile); diff --git a/plugins/check_nscp_api.cpp b/plugins/check_nscp_api.cpp index 3113478a4..3f6843ec2 100644 --- a/plugins/check_nscp_api.cpp +++ b/plugins/check_nscp_api.cpp @@ -176,7 +176,7 @@ static int FormatOutput(const Dictionary::Ptr& result) */ static Shared::Ptr Connect(const String& host, const String& port) { - std::shared_ptr sslContext; + Shared::Ptr sslContext; try { sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters