Skip to content

Commit fa08e90

Browse files
committed
Use SetupSslContext() instead of MakeAsioSslContext() everywhere
It does the same and already provides proper exception messages.
1 parent 7938d60 commit fa08e90

File tree

6 files changed

+17
-26
lines changed

6 files changed

+17
-26
lines changed

lib/cli/consolecommand.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,9 @@ Shared<AsioTlsStream>::Ptr ConsoleCommand::Connect()
527527
Shared<TlsContext>::Ptr sslContext;
528528

529529
try {
530-
sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters
530+
sslContext = SetupSslContext(); //TODO: Add support for cert, key, ca parameters
531531
} catch(const std::exception& ex) {
532-
Log(LogCritical, "DebugConsole")
533-
<< "Cannot make SSL context: " << ex.what();
532+
Log(LogCritical, "DebugConsole") << ex.what();
534533
throw;
535534
}
536535

lib/perfdata/elasticsearchwriter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,9 @@ OptionalTlsStream ElasticsearchWriter::Connect()
605605
Shared<TlsContext>::Ptr sslContext;
606606

607607
try {
608-
sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath());
609-
} catch (const std::exception&) {
610-
Log(LogWarning, "ElasticsearchWriter")
611-
<< "Unable to create SSL context.";
608+
sslContext = SetupSslContext(GetCertPath(), GetKeyPath(), GetCaPath());
609+
} catch (const std::exception& ex) {
610+
Log(LogWarning, "ElasticsearchWriter") << ex.what();
612611
throw;
613612
}
614613

lib/perfdata/gelfwriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ void GelfWriter::ReconnectInternal()
177177
Shared<TlsContext>::Ptr sslContext;
178178

179179
try {
180-
sslContext = MakeAsioSslContext(GetCertPath(), GetKeyPath(), GetCaPath());
180+
sslContext = SetupSslContext(GetCertPath(), GetKeyPath(), GetCaPath());
181181
} catch (const std::exception& ex) {
182-
Log(LogWarning, "GelfWriter")
183-
<< "Unable to create SSL context.";
182+
Log(LogWarning, "GelfWriter") << ex.what();
184183
throw;
185184
}
186185

lib/perfdata/influxdbcommonwriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ OptionalTlsStream InfluxdbCommonWriter::Connect()
152152
Shared<TlsContext>::Ptr sslContext;
153153

154154
try {
155-
sslContext = MakeAsioSslContext(GetSslCert(), GetSslKey(), GetSslCaCert());
155+
sslContext = SetupSslContext(GetSslCert(), GetSslKey(), GetSslCaCert());
156156
} catch (const std::exception& ex) {
157-
Log(LogWarning, GetReflectionType()->GetName())
158-
<< "Unable to create SSL context.";
157+
Log(LogWarning, GetReflectionType()->GetName()) << ex.what();
159158
throw;
160159
}
161160

lib/remote/pkiutility.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ std::shared_ptr<X509> PkiUtility::FetchCert(const String& host, const String& po
8686
Shared<TlsContext>::Ptr sslContext;
8787

8888
try {
89-
sslContext = MakeAsioSslContext();
89+
sslContext = SetupSslContext();
9090
} catch (const std::exception& ex) {
91-
Log(LogCritical, "pki")
92-
<< "Cannot make SSL context.";
93-
Log(LogDebug, "pki")
94-
<< "Cannot make SSL context:\n" << DiagnosticInformation(ex);
91+
Log(LogCritical, "pki") << ex.what();
92+
Log(LogDebug, "pki") << DiagnosticInformation(ex);
9593
return std::shared_ptr<X509>();
9694
}
9795

@@ -154,12 +152,10 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const
154152
Shared<TlsContext>::Ptr sslContext;
155153

156154
try {
157-
sslContext = MakeAsioSslContext(certfile, keyfile);
155+
sslContext = SetupSslContext(certfile, keyfile);
158156
} catch (const std::exception& ex) {
159-
Log(LogCritical, "cli")
160-
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "' ca path: '" << cafile << "'.";
161-
Log(LogDebug, "cli")
162-
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "' ca path: '" << cafile << "':\n" << DiagnosticInformation(ex);
157+
Log(LogCritical, "cli") << ex.what();
158+
Log(LogDebug, "cli") << DiagnosticInformation(ex);
163159
return 1;
164160
}
165161

plugins/check_nscp_api.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ static Shared<AsioTlsStream>::Ptr Connect(const String& host, const String& port
179179
Shared<TlsContext>::Ptr sslContext;
180180

181181
try {
182-
sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters
182+
sslContext = SetupSslContext(); //TODO: Add support for cert, key, ca parameters
183183
} catch(const std::exception& ex) {
184-
Log(LogCritical, "DebugConsole")
185-
<< "Cannot make SSL context: " << ex.what();
184+
Log(LogCritical, "DebugConsole") << ex.what();
186185
throw;
187186
}
188187

0 commit comments

Comments
 (0)