mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-20 19:51:54 +00:00
Verify WebSocketClient certificates with CryptoAPI on Windows
SSLClient verifies the server certificate chain with CryptoAPI on Windows by default, while WebSocketClient always left it to the TLS backend, whose snapshot of the Windows store lacks the roots Windows fetches on demand. A wss:// connection could fail against a host that SSLClient connects to. WebSocketClient now makes the same decision through a shared helper, and gets enable_windows_certificate_verification() to turn it off. Fix #2685
This commit is contained in:
1 parent
9458c27c7c
commit
a6ab971a3f
4 files changed
+79
-10
No files matched your search
@@ -16829,6 +16829,39 @@ TEST(SSLClientTest, WindowsCertificateVerification_RejectsUntrustedRoot) {
|
||||
EXPECT_EQ(Error::SSLServerVerification, res.error());
|
||||
EXPECT_EQ(static_cast<DWORD>(CERT_E_UNTRUSTEDROOT), res.ssl_backend_error());
|
||||
}
|
||||
|
||||
TEST(WebSocketSSLVerifyTest, WindowsCertificateVerification) {
|
||||
SSLServer svr(SERVER_CERT2_FILE, SERVER_PRIVATE_KEY_FILE);
|
||||
ASSERT_TRUE(svr.is_valid());
|
||||
|
||||
thread t = thread([&]() { ASSERT_TRUE(svr.listen("127.0.0.1", PORT)); });
|
||||
auto se = detail::scope_exit([&] {
|
||||
svr.stop();
|
||||
t.join();
|
||||
ASSERT_FALSE(svr.is_running());
|
||||
});
|
||||
|
||||
svr.wait_until_ready();
|
||||
|
||||
auto url = "wss://127.0.0.1:" + std::to_string(PORT) + "/";
|
||||
{
|
||||
ws::WebSocketClient client(url);
|
||||
auto res = client.connect();
|
||||
ASSERT_FALSE(res);
|
||||
EXPECT_EQ(Error::SSLServerVerification, res.error());
|
||||
EXPECT_EQ(static_cast<DWORD>(CERT_E_UNTRUSTEDROOT),
|
||||
res.ssl_backend_error());
|
||||
}
|
||||
{
|
||||
ws::WebSocketClient client(url);
|
||||
client.enable_windows_certificate_verification(false);
|
||||
auto res = client.connect();
|
||||
ASSERT_FALSE(res);
|
||||
EXPECT_EQ(Error::SSLServerVerification, res.error());
|
||||
EXPECT_NE(static_cast<DWORD>(CERT_E_UNTRUSTEDROOT),
|
||||
res.ssl_backend_error());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(SSLClientTest, ServerCertificateVerification1_Online) {
|
||||
|
||||
Reference in new issue
Block a user