Keep an accepting verifier from overriding Mbed TLS verification

With built-in verification on, a server certificate verifier returning
true made Mbed TLS accept a certificate its own check had rejected,
such as a self-signed one, while OpenSSL and wolfSSL still failed with
SSLServerVerification. On a client, keep the flags of Mbed TLS's own
verification, so the verifier is an additional check as on the other
backends. With verification off, the verifier is still the only check.

A server still clears them: there all three backends let an accepting
callback admit a client certificate.
This commit is contained in:
yhirose committed 2026-10-18 12:41:23 -04:00
1 parent 3744227de2
commit 906a7bf04e
2 files changed
+46 -2

No files matched your search

+39
View File
@@ -17060,6 +17060,45 @@ TEST(VerifyCallbackTest, VerifyContextFields) {
EXPECT_TRUE(saw_leaf_cert);
}
// A verifier that accepts runs alongside the built-in verification, and is the
// only check once that is turned off.
TEST(VerifyCallbackTest, AcceptingVerifierDoesNotOverrideVerification) {
using namespace httplib::tls;
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
ASSERT_TRUE(svr.is_valid());
svr.Get("/test", [](const Request &, Response &res) {
res.set_content("ok", "text/plain");
});
auto port = svr.bind_to_any_port(HOST);
thread t([&]() { svr.listen_after_bind(); });
auto se = detail::scope_exit([&] {
svr.stop();
t.join();
});
svr.wait_until_ready();
SSLClient cli(HOST, port);
cli.enable_server_hostname_verification(false);
auto calls = 0;
cli.set_server_certificate_verifier([&](const VerifyContext &) {
calls++;
return true;
});
// cert.pem is not trusted
auto res = cli.Get("/test");
ASSERT_FALSE(res);
EXPECT_EQ(Error::SSLServerVerification, res.error());
EXPECT_GT(calls, 0);
cli.enable_server_certificate_verification(false);
res = cli.Get("/test");
ASSERT_TRUE(res) << "Error: " << to_string(res.error());
EXPECT_EQ("ok", res->body);
}
// A verifier belongs to the client that set it, not to the thread that set it.
TEST(VerifyCallbackTest, VerifierStaysWithItsClient) {
using namespace httplib::tls;