#3269: Poco::Net::Context initialization with empty certificateFile

This commit is contained in:
Günter Obiltschnig
2021-06-15 14:05:56 +02:00
parent e01fede825
commit 907e240ff2
2 changed files with 6 additions and 3 deletions

View File

@@ -137,6 +137,7 @@ public:
std::string certificateFile; std::string certificateFile;
/// Path to the certificate file (in PEM format). /// Path to the certificate file (in PEM format).
///
/// If the private key and the certificate are stored in the same file, this /// If the private key and the certificate are stored in the same file, this
/// can be empty if privateKeyFile is given. /// can be empty if privateKeyFile is given.

View File

@@ -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) if (errCode != 1)
{ {
std::string errMsg = Utility::getLastError(); 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);
} }
} }