From 938ae083cd4b525939f3d6de0d13f06f1a3d0284 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 15 Dec 2014 11:44:56 +0100 Subject: [PATCH] Cli: "node wizard" shouldn't crash when SaveCert fails fixes #7707 --- lib/cli/pkiutility.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/cli/pkiutility.cpp b/lib/cli/pkiutility.cpp index dca48a268..7f5944b53 100644 --- a/lib/cli/pkiutility.cpp +++ b/lib/cli/pkiutility.cpp @@ -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 sslContext = MakeSSLContext(certfile, keyfile); + boost::shared_ptr 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; }