From 907e240ff2de1ab7326932b9f622d1b770855243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Tue, 15 Jun 2021 14:05:56 +0200 Subject: [PATCH] #3269: Poco::Net::Context initialization with empty certificateFile --- NetSSL_OpenSSL/include/Poco/Net/Context.h | 1 + NetSSL_OpenSSL/src/Context.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NetSSL_OpenSSL/include/Poco/Net/Context.h b/NetSSL_OpenSSL/include/Poco/Net/Context.h index 754fcc945..9832b1a79 100644 --- a/NetSSL_OpenSSL/include/Poco/Net/Context.h +++ b/NetSSL_OpenSSL/include/Poco/Net/Context.h @@ -137,6 +137,7 @@ public: std::string certificateFile; /// Path to the certificate file (in PEM format). + /// /// If the private key and the certificate are stored in the same file, this /// can be empty if privateKeyFile is given. diff --git a/NetSSL_OpenSSL/src/Context.cpp b/NetSSL_OpenSSL/src/Context.cpp index 4be622027..1ecdca5be 100644 --- a/NetSSL_OpenSSL/src/Context.cpp +++ b/NetSSL_OpenSSL/src/Context.cpp @@ -155,13 +155,15 @@ void Context::init(const Params& params) } } - if (!params.certificateFile.empty()) + std::string certificateFile = params.certificateFile; + if (certificateFile.empty()) certificateFile = params.privateKeyFile; + if (!certificateFile.empty()) { - errCode = SSL_CTX_use_certificate_chain_file(_pSSLContext, Poco::Path::transcode(params.certificateFile).c_str()); + errCode = SSL_CTX_use_certificate_chain_file(_pSSLContext, Poco::Path::transcode(certificateFile).c_str()); if (errCode != 1) { std::string errMsg = Utility::getLastError(); - throw SSLContextException(std::string("Error loading certificate from file ") + params.certificateFile, errMsg); + throw SSLContextException(std::string("Error loading certificate from file ") + certificateFile, errMsg); } }