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:
yhirose committed 2026-11-20 12:36:14 -05:00
1 parent 9458c27c7c
commit a6ab971a3f
4 files changed
+79 -10

No files matched your search

+33
View File
@@ -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) {