Cli: "node wizard" shouldn't crash when SaveCert fails

fixes #7707
This commit is contained in:
Michael Friedrich 2014-12-15 11:44:56 +01:00
parent 252f3205cb
commit 938ae083cd
1 changed files with 22 additions and 2 deletions

View File

@ -132,9 +132,27 @@ int PkiUtility::SaveCert(const String& host, const String& port, const String& k
{
TcpSocket::Ptr client = new TcpSocket();
client->Connect(host, port);
try {
client->Connect(host, port);
} catch (const std::exception& ex) {
Log(LogCritical, "cli")
<< "Cannot connect to host '" << host << "' on port '" << port << "'";
Log(LogDebug, "cli")
<< "Cannot connect to host '" << host << "' on port '" << port << "':\n" << DiagnosticInformation(ex);
return 1;
}
boost::shared_ptr<SSL_CTX> sslContext = MakeSSLContext(certfile, keyfile);
boost::shared_ptr<SSL_CTX> sslContext;
try {
sslContext = MakeSSLContext(certfile, keyfile);
} catch (const std::exception& ex) {
Log(LogCritical, "cli")
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "'.";
Log(LogDebug, "cli")
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "':\n" << DiagnosticInformation(ex);
return 1;
}
TlsStream::Ptr stream = new TlsStream(client, RoleClient, sslContext);
@ -192,6 +210,8 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const
} catch (const std::exception& ex) {
Log(LogCritical, "cli")
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "' ca path: '" << cafile << "'.";
Log(LogDebug, "cli")
<< "Cannot make SSL context for cert path: '" << certfile << "' key path: '" << keyfile << "' ca path: '" << cafile << "':\n" << DiagnosticInformation(ex);
return 1;
}