@@ -1036,6 +1036,12 @@ class ClientImpl {
10361036 void set_proxy_digest_auth (const char *username, const char *password);
10371037#endif
10381038
1039+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1040+ void set_ca_cert_path (const char *ca_cert_file_path,
1041+ const char *ca_cert_dir_path = nullptr );
1042+ void set_ca_cert_store (X509_STORE *ca_cert_store);
1043+ #endif
1044+
10391045#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
10401046 void enable_server_certificate_verification (bool enabled);
10411047#endif
@@ -1137,6 +1143,13 @@ class ClientImpl {
11371143 std::string proxy_digest_auth_password_;
11381144#endif
11391145
1146+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1147+ std::string ca_cert_file_path_;
1148+ std::string ca_cert_dir_path_;
1149+
1150+ X509_STORE *ca_cert_store_ = nullptr ;
1151+ #endif
1152+
11401153#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
11411154 bool server_certificate_verification_ = true ;
11421155#endif
@@ -1415,9 +1428,6 @@ class SSLClient : public ClientImpl {
14151428
14161429 bool is_valid () const override ;
14171430
1418- void set_ca_cert_path (const char *ca_cert_file_path,
1419- const char *ca_cert_dir_path = nullptr );
1420-
14211431 void set_ca_cert_store (X509_STORE *ca_cert_store);
14221432
14231433 long get_openssl_verify_result () const ;
@@ -1450,8 +1460,6 @@ class SSLClient : public ClientImpl {
14501460
14511461 std::vector<std::string> host_components_;
14521462
1453- std::string ca_cert_file_path_;
1454- std::string ca_cert_dir_path_;
14551463 long verify_result_ = 0 ;
14561464
14571465 friend class ClientImpl ;
@@ -5309,6 +5317,11 @@ inline void ClientImpl::copy_settings(const ClientImpl &rhs) {
53095317 proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_ ;
53105318 proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_ ;
53115319#endif
5320+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
5321+ ca_cert_file_path_ = rhs.ca_cert_file_path_ ;
5322+ ca_cert_dir_path_ = rhs.ca_cert_dir_path_ ;
5323+ ca_cert_store_ = rhs.ca_cert_store_ ;
5324+ #endif
53125325#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
53135326 server_certificate_verification_ = rhs.server_certificate_verification_ ;
53145327#endif
@@ -5604,6 +5617,9 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
56045617#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
56055618 SSLClient cli (next_host.c_str (), next_port);
56065619 cli.copy_settings (*this );
5620+ if (ca_cert_store_) {
5621+ cli.set_ca_cert_store (ca_cert_store_);
5622+ }
56075623 return detail::redirect (cli, req, res, next_path, location, error);
56085624#else
56095625 return false ;
@@ -6511,6 +6527,20 @@ inline void ClientImpl::set_proxy_digest_auth(const char *username,
65116527}
65126528#endif
65136529
6530+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6531+ inline void ClientImpl::set_ca_cert_path (const char *ca_cert_file_path,
6532+ const char *ca_cert_dir_path) {
6533+ if (ca_cert_file_path) { ca_cert_file_path_ = ca_cert_file_path; }
6534+ if (ca_cert_dir_path) { ca_cert_dir_path_ = ca_cert_dir_path; }
6535+ }
6536+
6537+ inline void ClientImpl::set_ca_cert_store (X509_STORE *ca_cert_store) {
6538+ if (ca_cert_store && ca_cert_store != ca_cert_store_) {
6539+ ca_cert_store_ = ca_cert_store;
6540+ }
6541+ }
6542+ #endif
6543+
65146544#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
65156545inline void ClientImpl::enable_server_certificate_verification (bool enabled) {
65166546 server_certificate_verification_ = enabled;
@@ -6901,12 +6931,6 @@ inline SSLClient::~SSLClient() {
69016931
69026932inline bool SSLClient::is_valid () const { return ctx_; }
69036933
6904- inline void SSLClient::set_ca_cert_path (const char *ca_cert_file_path,
6905- const char *ca_cert_dir_path) {
6906- if (ca_cert_file_path) { ca_cert_file_path_ = ca_cert_file_path; }
6907- if (ca_cert_dir_path) { ca_cert_dir_path_ = ca_cert_dir_path; }
6908- }
6909-
69106934inline void SSLClient::set_ca_cert_store (X509_STORE *ca_cert_store) {
69116935 if (ca_cert_store) {
69126936 if (ctx_) {
@@ -7649,15 +7673,14 @@ inline void Client::set_logger(Logger logger) { cli_->set_logger(logger); }
76497673#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
76507674inline void Client::set_ca_cert_path (const char *ca_cert_file_path,
76517675 const char *ca_cert_dir_path) {
7652- if (is_ssl_) {
7653- static_cast <SSLClient &>(*cli_).set_ca_cert_path (ca_cert_file_path,
7654- ca_cert_dir_path);
7655- }
7676+ cli_->set_ca_cert_path (ca_cert_file_path, ca_cert_dir_path);
76567677}
76577678
76587679inline void Client::set_ca_cert_store (X509_STORE *ca_cert_store) {
76597680 if (is_ssl_) {
76607681 static_cast <SSLClient &>(*cli_).set_ca_cert_store (ca_cert_store);
7682+ } else {
7683+ cli_->set_ca_cert_store (ca_cert_store);
76617684 }
76627685}
76637686
0 commit comments