diff --git a/lib/inc/drogon/HttpClient.h b/lib/inc/drogon/HttpClient.h index 9ff6ee01..5835039e 100644 --- a/lib/inc/drogon/HttpClient.h +++ b/lib/inc/drogon/HttpClient.h @@ -258,6 +258,31 @@ class DROGON_EXPORT HttpClient : public trantor::NonCopyable return port() == 80; } + /** + * @brief Set the client certificate used by the HTTP connection + * + * @param cert Path to the certificate + * @param key Path to the certificate's private key + * @note this method has no effect if the HTTP client is communicating via + * unencrypted HTTP + */ + virtual void setCertPath(const std::string &cert, + const std::string &key) = 0; + + /** + * @brief Supplies command style options for `SSL_CONF_cmd` + * + * @param sslConfCmds options for SSL_CONF_cmd + * @note this method has no effect if the HTTP client is communicating via + * unencrypted HTTP + * @code + * addSSLConfigs({{"-dhparam", "/path/to/dhparam"}, {"-strict", ""}}); + * @endcode + */ + virtual void addSSLConfigs( + const std::vector> + &sslConfCmds) = 0; + /// Create a Http client using the hostString to connect to server /** * diff --git a/lib/src/HttpClientImpl.cc b/lib/src/HttpClientImpl.cc index b80dc31e..8788eccf 100644 --- a/lib/src/HttpClientImpl.cc +++ b/lib/src/HttpClientImpl.cc @@ -39,7 +39,12 @@ void HttpClientImpl::createTcpClient() { LOG_TRACE << "useOldTLS=" << useOldTLS_; LOG_TRACE << "domain=" << domain_; - tcpClientPtr_->enableSSL(useOldTLS_, validateCert_, domain_); + tcpClientPtr_->enableSSL(useOldTLS_, + validateCert_, + domain_, + sslConfCmds_, + clientCertPath_, + clientKeyPath_); } #endif auto thisPtr = shared_from_this(); @@ -645,3 +650,19 @@ void HttpClientImpl::handleCookies(const HttpResponseImplPtr &resp) } } } + +void HttpClientImpl::setCertPath(const std::string &cert, + const std::string &key) +{ + clientCertPath_ = cert; + clientKeyPath_ = key; +} + +void HttpClientImpl::addSSLConfigs( + const std::vector> &sslConfCmds) +{ + for (const auto &cmd : sslConfCmds) + { + sslConfCmds_.push_back(cmd); + } +} \ No newline at end of file diff --git a/lib/src/HttpClientImpl.h b/lib/src/HttpClientImpl.h index cc514c6f..a5690d14 100644 --- a/lib/src/HttpClientImpl.h +++ b/lib/src/HttpClientImpl.h @@ -101,6 +101,10 @@ class HttpClientImpl final : public HttpClient, return useSSL_; } + void setCertPath(const std::string &cert, const std::string &key) override; + void addSSLConfigs(const std::vector> + &sslConfCmds) override; + private: std::shared_ptr tcpClientPtr_; trantor::EventLoop *loop_; @@ -133,6 +137,9 @@ class HttpClientImpl final : public HttpClient, std::shared_ptr resolverPtr_; bool useOldTLS_{false}; std::string userAgent_{"DrogonClient"}; + std::vector> sslConfCmds_; + std::string clientCertPath_; + std::string clientKeyPath_; }; using HttpClientImplPtr = std::shared_ptr; } // namespace drogon diff --git a/trantor b/trantor index 586aacd0..63ff8d9b 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 586aacd084e088bbc041350a657b80b143820276 +Subproject commit 63ff8d9bad639c5fa3e6bd7072669813fae4c6af