diff --git a/httplib.h b/httplib.h index 5e3b0f8..abe73a1 100644 --- a/httplib.h +++ b/httplib.h @@ -13095,7 +13095,7 @@ inline bool SSLClient::load_certs() { last_openssl_error_ = ERR_get_error(); ret = false; } - } else { + } else if (!ca_cert_store_) { auto loaded = false; #ifdef _WIN32 loaded = diff --git a/test/test.cc b/test/test.cc index b0f64da..5964096 100644 --- a/test/test.cc +++ b/test/test.cc @@ -9682,6 +9682,27 @@ TEST(SSLClientRedirectTest, CertFile) { ASSERT_EQ(StatusCode::OK_200, res->status); } +// Test that set_ca_cert_store() skips system certs (consistent with +// set_ca_cert_path behavior). When a custom cert store is set, only those certs +// should be trusted - system certs should NOT be loaded. +TEST(SSLClientTest, SetCaCertStoreSkipsSystemCerts_Online) { + // Load a specific cert that is NOT a system CA cert + std::string cert; + read_file(SERVER_CERT2_FILE, cert); + + SSLClient cli("google.com"); + cli.load_ca_cert_store(cert.c_str(), cert.size()); + cli.enable_server_certificate_verification(true); + + // This should FAIL because: + // 1. We loaded only SERVER_CERT2 (a test cert, not a CA for google.com) + // 2. System certs should NOT be loaded when custom store is set + // If system certs WERE loaded, this would succeed + auto res = cli.Get("/"); + ASSERT_FALSE(res); + EXPECT_EQ(Error::SSLServerVerification, res.error()); +} + TEST(MultipartFormDataTest, LargeData) { SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);