Skip to content

Commit 3b09e1e

Browse files
committed
Refactor: add typedef boost::asio::ssl::context SslContext;
1 parent 6c03598 commit 3b09e1e

12 files changed

+33
-31
lines changed

lib/base/tlsstream.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SeenStream : public ARS
5959
struct UnbufferedAsioTlsStreamParams
6060
{
6161
boost::asio::io_context& IoContext;
62-
boost::asio::ssl::context& SslContext;
62+
SslContext& SslContext;
6363
const String& Hostname;
6464
};
6565

@@ -108,7 +108,7 @@ class AsioTlsStream : public boost::asio::buffered_stream<UnbufferedAsioTlsStrea
108108
{
109109
public:
110110
inline
111-
AsioTlsStream(boost::asio::io_context& ioContext, boost::asio::ssl::context& sslContext, const String& hostname = String())
111+
AsioTlsStream(boost::asio::io_context& ioContext, SslContext& sslContext, const String& hostname = String())
112112
: AsioTlsStream(UnbufferedAsioTlsStreamParams{ioContext, sslContext, hostname})
113113
{
114114
}

lib/base/tlsutility.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ void InitializeOpenSSL()
7272
l_SSLInitialized = true;
7373
}
7474

75-
static void InitSslContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& pubkey, const String& privkey, const String& cakey)
75+
static void InitSslContext(const Shared<SslContext>::Ptr& context, const String& pubkey, const String& privkey, const String& cakey)
7676
{
7777
char errbuf[256];
7878

7979
// Enforce TLS v1.2 as minimum
8080
context->set_options(
81-
boost::asio::ssl::context::default_workarounds |
82-
boost::asio::ssl::context::no_compression |
83-
boost::asio::ssl::context::no_sslv2 |
84-
boost::asio::ssl::context::no_sslv3 |
85-
boost::asio::ssl::context::no_tlsv1 |
86-
boost::asio::ssl::context::no_tlsv1_1
81+
SslContext::default_workarounds |
82+
SslContext::no_compression |
83+
SslContext::no_sslv2 |
84+
SslContext::no_sslv3 |
85+
SslContext::no_tlsv1 |
86+
SslContext::no_tlsv1_1
8787
);
8888

8989
// Custom TLS flags
@@ -202,13 +202,13 @@ static void InitSslContext(const Shared<boost::asio::ssl::context>::Ptr& context
202202
* @param cakey CA certificate chain file.
203203
* @returns An SSL context.
204204
*/
205-
Shared<boost::asio::ssl::context>::Ptr MakeAsioSslContext(const String& pubkey, const String& privkey, const String& cakey)
205+
Shared<SslContext>::Ptr MakeAsioSslContext(const String& pubkey, const String& privkey, const String& cakey)
206206
{
207207
namespace ssl = boost::asio::ssl;
208208

209209
InitializeOpenSSL();
210210

211-
auto context (Shared<ssl::context>::Make(ssl::context::tls));
211+
auto context (Shared<SslContext>::Make(SslContext::tls));
212212

213213
InitSslContext(context, pubkey, privkey, cakey);
214214

@@ -220,7 +220,7 @@ Shared<boost::asio::ssl::context>::Ptr MakeAsioSslContext(const String& pubkey,
220220
* @param context The ssl context.
221221
* @param cipherList The ciper list.
222222
**/
223-
void SetCipherListToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& cipherList)
223+
void SetCipherListToSSLContext(const Shared<SslContext>::Ptr& context, const String& cipherList)
224224
{
225225
char errbuf[256];
226226

@@ -278,12 +278,12 @@ int ResolveTlsProtocolVersion(const std::string& version) {
278278
}
279279
}
280280

281-
Shared<boost::asio::ssl::context>::Ptr SetupSslContext(String certPath, String keyPath,
281+
Shared<SslContext>::Ptr SetupSslContext(String certPath, String keyPath,
282282
String caPath, String crlPath, String cipherList, String protocolmin, DebugInfo di)
283283
{
284284
namespace ssl = boost::asio::ssl;
285285

286-
Shared<ssl::context>::Ptr context;
286+
Shared<SslContext>::Ptr context;
287287

288288
try {
289289
context = MakeAsioSslContext(certPath, keyPath, caPath);
@@ -327,7 +327,7 @@ Shared<boost::asio::ssl::context>::Ptr SetupSslContext(String certPath, String k
327327
* @param context The ssl context.
328328
* @param tlsProtocolmin The minimum TLS protocol version.
329329
*/
330-
void SetTlsProtocolminToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& tlsProtocolmin)
330+
void SetTlsProtocolminToSSLContext(const Shared<SslContext>::Ptr& context, const String& tlsProtocolmin)
331331
{
332332
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
333333
int ret = SSL_CTX_set_min_proto_version(context->native_handle(), ResolveTlsProtocolVersion(tlsProtocolmin));
@@ -355,7 +355,7 @@ void SetTlsProtocolminToSSLContext(const Shared<boost::asio::ssl::context>::Ptr&
355355
* @param context The SSL context.
356356
* @param crlPath The path to the CRL file.
357357
*/
358-
void AddCRLToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& crlPath)
358+
void AddCRLToSSLContext(const Shared<SslContext>::Ptr& context, const String& crlPath)
359359
{
360360
X509_STORE *x509_store = SSL_CTX_get_cert_store(context->native_handle());
361361
AddCRLToSSLContext(x509_store, crlPath);

lib/base/tlsutility.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ const auto LEAF_VALID_FOR = 60 * 60 * 24 * 397;
3838
const auto RENEW_THRESHOLD = 60 * 60 * 24 * 30;
3939
const auto RENEW_INTERVAL = 60 * 60 * 24;
4040

41+
typedef boost::asio::ssl::context SslContext;
42+
4143
void InitializeOpenSSL();
4244

4345
String GetOpenSSLVersion();
4446

45-
Shared<boost::asio::ssl::context>::Ptr MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
46-
void AddCRLToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& crlPath);
47+
Shared<SslContext>::Ptr MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
48+
void AddCRLToSSLContext(const Shared<SslContext>::Ptr& context, const String& crlPath);
4749
void AddCRLToSSLContext(X509_STORE *x509_store, const String& crlPath);
48-
void SetCipherListToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& cipherList);
49-
void SetTlsProtocolminToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& tlsProtocolmin);
50+
void SetCipherListToSSLContext(const Shared<SslContext>::Ptr& context, const String& cipherList);
51+
void SetTlsProtocolminToSSLContext(const Shared<SslContext>::Ptr& context, const String& tlsProtocolmin);
5052
int ResolveTlsProtocolVersion(const std::string& version);
5153

52-
Shared<boost::asio::ssl::context>::Ptr SetupSslContext(String certPath, String keyPath,
54+
Shared<SslContext>::Ptr SetupSslContext(String certPath, String keyPath,
5355
String caPath, String crlPath, String cipherList, String protocolmin, DebugInfo di);
5456

5557
String GetCertificateCN(const std::shared_ptr<X509>& certificate);

lib/cli/consolecommand.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& con
524524
*/
525525
Shared<AsioTlsStream>::Ptr ConsoleCommand::Connect()
526526
{
527-
Shared<boost::asio::ssl::context>::Ptr sslContext;
527+
Shared<SslContext>::Ptr sslContext;
528528

529529
try {
530530
sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters

lib/icingadb/redisconnection.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace icinga
183183
typedef boost::asio::buffered_stream<Tcp::socket> TcpConn;
184184
typedef boost::asio::buffered_stream<Unix::socket> UnixConn;
185185

186-
Shared<boost::asio::ssl::context>::Ptr m_TLSContext;
186+
Shared<SslContext>::Ptr m_TLSContext;
187187

188188
template<class AsyncReadStream>
189189
static Value ReadRESP(AsyncReadStream& stream, boost::asio::yield_context& yc);

lib/methods/ifwapichecktask.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void IfwApiCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
497497

498498
auto& io (IoEngine::Get().GetIoContext());
499499
auto strand (Shared<asio::io_context::strand>::Make(io));
500-
Shared<asio::ssl::context>::Ptr ctx;
500+
Shared<SslContext>::Ptr ctx;
501501
double start = Utility::GetTime();
502502

503503
try {

lib/perfdata/elasticsearchwriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ OptionalTlsStream ElasticsearchWriter::Connect()
602602
bool tls = GetEnableTls();
603603

604604
if (tls) {
605-
Shared<boost::asio::ssl::context>::Ptr sslContext;
605+
Shared<SslContext>::Ptr sslContext;
606606

607607
try {
608608
sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath());

lib/perfdata/gelfwriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void GelfWriter::ReconnectInternal()
174174
bool ssl = GetEnableTls();
175175

176176
if (ssl) {
177-
Shared<boost::asio::ssl::context>::Ptr sslContext;
177+
Shared<SslContext>::Ptr sslContext;
178178

179179
try {
180180
sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath());

lib/perfdata/influxdbcommonwriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ OptionalTlsStream InfluxdbCommonWriter::Connect()
149149
bool ssl = GetSslEnable();
150150

151151
if (ssl) {
152-
Shared<boost::asio::ssl::context>::Ptr sslContext;
152+
Shared<SslContext>::Ptr sslContext;
153153

154154
try {
155155
sslContext = MakeAsioSslContext(GetSslCert(), GetSslKey(), GetSslCaCert());

lib/remote/apilistener.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
161161
void ValidateTlsHandshakeTimeout(const Lazy<double>& lvalue, const ValidationUtils& utils) override;
162162

163163
private:
164-
Shared<boost::asio::ssl::context>::Ptr m_SSLContext;
164+
Shared<SslContext>::Ptr m_SSLContext;
165165
boost::shared_mutex m_SSLContextMutex;
166166

167167
mutable std::mutex m_AnonymousClientsLock;

lib/remote/pkiutility.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int PkiUtility::SignCsr(const String& csrfile, const String& certfile)
8383

8484
std::shared_ptr<X509> PkiUtility::FetchCert(const String& host, const String& port)
8585
{
86-
Shared<boost::asio::ssl::context>::Ptr sslContext;
86+
Shared<SslContext>::Ptr sslContext;
8787

8888
try {
8989
sslContext = MakeAsioSslContext();
@@ -151,7 +151,7 @@ int PkiUtility::GenTicket(const String& cn, const String& salt, std::ostream& ti
151151
int PkiUtility::RequestCertificate(const String& host, const String& port, const String& keyfile,
152152
const String& certfile, const String& cafile, const std::shared_ptr<X509>& trustedCert, const String& ticket)
153153
{
154-
Shared<boost::asio::ssl::context>::Ptr sslContext;
154+
Shared<SslContext>::Ptr sslContext;
155155

156156
try {
157157
sslContext = MakeAsioSslContext(certfile, keyfile);

plugins/check_nscp_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int FormatOutput(const Dictionary::Ptr& result)
176176
*/
177177
static Shared<AsioTlsStream>::Ptr Connect(const String& host, const String& port)
178178
{
179-
Shared<boost::asio::ssl::context>::Ptr sslContext;
179+
Shared<SslContext>::Ptr sslContext;
180180

181181
try {
182182
sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters

0 commit comments

Comments
 (0)