@@ -1124,6 +1124,7 @@ class ClientImpl {
11241124 void set_ca_cert_path (const std::string &ca_cert_file_path,
11251125 const std::string &ca_cert_dir_path = std::string());
11261126 void set_ca_cert_store (X509_STORE *ca_cert_store);
1127+ X509_STORE *create_ca_cert_store (const char *ca_cert, std::size_t size);
11271128#endif
11281129
11291130#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
@@ -1504,6 +1505,7 @@ class Client {
15041505 const std::string &ca_cert_dir_path = std::string());
15051506
15061507 void set_ca_cert_store (X509_STORE *ca_cert_store);
1508+ void load_ca_cert_store (const char *ca_cert, std::size_t size);
15071509
15081510 long get_openssl_verify_result () const ;
15091511
@@ -1563,6 +1565,7 @@ class SSLClient : public ClientImpl {
15631565 bool is_valid () const override ;
15641566
15651567 void set_ca_cert_store (X509_STORE *ca_cert_store);
1568+ void load_ca_cert_store (const char *ca_cert, std::size_t size);
15661569
15671570 long get_openssl_verify_result () const ;
15681571
@@ -7590,6 +7593,35 @@ inline void ClientImpl::set_ca_cert_store(X509_STORE *ca_cert_store) {
75907593 ca_cert_store_ = ca_cert_store;
75917594 }
75927595}
7596+
7597+ inline X509_STORE *ClientImpl::create_ca_cert_store (const char *ca_cert,
7598+ std::size_t size) {
7599+ auto mem = BIO_new_mem_buf (ca_cert, size);
7600+ if (!mem) return nullptr ;
7601+
7602+ auto inf = PEM_X509_INFO_read_bio (mem, nullptr , nullptr , nullptr );
7603+ if (!inf) {
7604+ BIO_free_all (mem);
7605+ return nullptr ;
7606+ }
7607+
7608+ auto cts = X509_STORE_new ();
7609+ if (cts) {
7610+ for (int first = 0 , last = sk_X509_INFO_num (inf); first < last; ++first) {
7611+ auto itmp = sk_X509_INFO_value (inf, first);
7612+ if (!itmp) continue ;
7613+
7614+ if (itmp->x509 ) X509_STORE_add_cert (cts, itmp->x509 );
7615+
7616+ if (itmp->crl ) X509_STORE_add_crl (cts, itmp->crl );
7617+ }
7618+ }
7619+
7620+ sk_X509_INFO_pop_free (inf, X509_INFO_free);
7621+ BIO_free_all (mem);
7622+
7623+ return cts;
7624+ }
75937625#endif
75947626
75957627#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
@@ -7990,6 +8022,11 @@ inline void SSLClient::set_ca_cert_store(X509_STORE *ca_cert_store) {
79908022 }
79918023}
79928024
8025+ inline void SSLClient::load_ca_cert_store (const char *ca_cert,
8026+ std::size_t size) {
8027+ set_ca_cert_store (ClientImpl::create_ca_cert_store (ca_cert, size));
8028+ }
8029+
79938030inline long SSLClient::get_openssl_verify_result () const {
79948031 return verify_result_;
79958032}
@@ -8773,6 +8810,10 @@ inline void Client::set_ca_cert_store(X509_STORE *ca_cert_store) {
87738810 }
87748811}
87758812
8813+ inline void Client::load_ca_cert_store (const char *ca_cert, std::size_t size) {
8814+ set_ca_cert_store (cli_->create_ca_cert_store (ca_cert, size));
8815+ }
8816+
87768817inline long Client::get_openssl_verify_result () const {
87778818 if (is_ssl_) {
87788819 return static_cast <SSLClient &>(*cli_).get_openssl_verify_result ();
0 commit comments