File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -1171,7 +1171,6 @@ class SSLClient : public ClientImpl {
1171
1171
1172
1172
std::string ca_cert_file_path_;
1173
1173
std::string ca_cert_dir_path_;
1174
- X509_STORE *ca_cert_store_ = nullptr ;
1175
1174
long verify_result_ = 0 ;
1176
1175
1177
1176
friend class ClientImpl ;
@@ -5844,7 +5843,16 @@ inline void SSLClient::set_ca_cert_path(const char *ca_cert_file_path,
5844
5843
}
5845
5844
5846
5845
inline void SSLClient::set_ca_cert_store (X509_STORE *ca_cert_store) {
5847
- if (ca_cert_store) { ca_cert_store_ = ca_cert_store; }
5846
+ if (ca_cert_store) {
5847
+ if (ctx_) {
5848
+ if (SSL_CTX_get_cert_store (ctx_) != ca_cert_store) {
5849
+ // Free memory allocated for old cert and use new store `ca_cert_store`
5850
+ SSL_CTX_set_cert_store (ctx_, ca_cert_store);
5851
+ }
5852
+ } else {
5853
+ X509_STORE_free (ca_cert_store);
5854
+ }
5855
+ }
5848
5856
}
5849
5857
5850
5858
inline long SSLClient::get_openssl_verify_result () const {
@@ -5922,10 +5930,6 @@ inline bool SSLClient::load_certs() {
5922
5930
ca_cert_dir_path_.c_str ())) {
5923
5931
ret = false ;
5924
5932
}
5925
- } else if (ca_cert_store_ != nullptr ) {
5926
- if (SSL_CTX_get_cert_store (ctx_) != ca_cert_store_) {
5927
- SSL_CTX_set_cert_store (ctx_, ca_cert_store_);
5928
- }
5929
5933
} else {
5930
5934
#ifdef _WIN32
5931
5935
detail::load_system_certs_on_windows (SSL_CTX_get_cert_store (ctx_));
Original file line number Diff line number Diff line change 1
1
2
2
# CXX = clang++
3
- CXXFLAGS = -ggdb -O0 -std=c++11 -DGTEST_USE_OWN_TR1_TUPLE -I.. -I. -Wall -Wextra -Wtype-limits -Wconversion
3
+ CXXFLAGS = -ggdb -O0 -std=c++11 -DGTEST_USE_OWN_TR1_TUPLE -I.. -I. -Wall -Wextra -Wtype-limits -Wconversion -fsanitize=address
4
4
5
5
OPENSSL_DIR = /usr/local/opt/openssl@1.1
6
6
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR ) /include -L$(OPENSSL_DIR ) /lib -lssl -lcrypto
Original file line number Diff line number Diff line change @@ -3125,6 +3125,19 @@ TEST_F(PayloadMaxLengthTest, ExceedLimit) {
3125
3125
}
3126
3126
3127
3127
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3128
+ TEST (SSLClientTest, UpdateCAStore) {
3129
+ httplib::SSLClient httplib_client (" www.google.com" );
3130
+ auto ca_store_1 = X509_STORE_new ();
3131
+ X509_STORE_load_locations (ca_store_1, " /etc/ssl/certs/ca-certificates.crt" ,
3132
+ nullptr );
3133
+ httplib_client.set_ca_cert_store (ca_store_1);
3134
+
3135
+ auto ca_store_2 = X509_STORE_new ();
3136
+ X509_STORE_load_locations (ca_store_2, " /etc/ssl/certs/ca-certificates.crt" ,
3137
+ nullptr );
3138
+ httplib_client.set_ca_cert_store (ca_store_2);
3139
+ }
3140
+
3128
3141
TEST (SSLClientTest, ServerNameIndication) {
3129
3142
SSLClient cli (" httpbin.org" , 443 );
3130
3143
auto res = cli.Get (" /get" );
You can’t perform that action at this time.
0 commit comments