mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-22 11:46:13 +00:00
Require client certificates once update_certs_pem() loads a client CA
SSLServer::update_certs_pem() loaded the client CA it was given but left client certificate verification as it was, so on a server built without a client CA it returned true while clients without a certificate still got in. Turn verification on, as the constructors do when they are given a client CA. A client CA passed to update_certs_pem() now always makes client certificates required.
This commit is contained in:
1 parent
7a9cee0e05
commit
98647e059d
2 files changed
+17
-6
No files matched your search
@@ -18955,7 +18955,9 @@ inline bool SSLServer::update_certs_pem(const char *cert_pem,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (client_ca_pem) {
|
if (client_ca_pem) {
|
||||||
return tls::update_server_client_ca(ctx_, client_ca_pem);
|
if (!tls::update_server_client_ca(ctx_, client_ca_pem)) { return false; }
|
||||||
|
// As in the constructors, a client CA makes client certificates required
|
||||||
|
tls::set_verify_client(ctx_, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-5
@@ -16221,15 +16221,24 @@ TEST(SSLClientServerTest, ClientCertStillRequiredAfterVerifyCallbackCleared) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SSLClientServerTest, ClientCertStillRequiredAfterUpdateCertsPem) {
|
void UpdateCertsPemWithClientCA(SSLServer &svr) {
|
||||||
ClientCertStillRequired([](SSLServer &svr) {
|
|
||||||
std::string cert_pem, key_pem, ca_pem;
|
std::string cert_pem, key_pem, ca_pem;
|
||||||
read_file(SERVER_CERT_FILE, cert_pem);
|
read_file(SERVER_CERT_FILE, cert_pem);
|
||||||
read_file(SERVER_PRIVATE_KEY_FILE, key_pem);
|
read_file(SERVER_PRIVATE_KEY_FILE, key_pem);
|
||||||
read_file(CLIENT_CA_CERT_FILE, ca_pem);
|
read_file(CLIENT_CA_CERT_FILE, ca_pem);
|
||||||
ASSERT_TRUE(svr.update_certs_pem(cert_pem.c_str(), key_pem.c_str(),
|
ASSERT_TRUE(
|
||||||
ca_pem.c_str()));
|
svr.update_certs_pem(cert_pem.c_str(), key_pem.c_str(), ca_pem.c_str()));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
TEST(SSLClientServerTest, UpdateCertsPemWithClientCARequiresClientCert) {
|
||||||
|
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
|
||||||
|
ASSERT_TRUE(svr.is_valid());
|
||||||
|
UpdateCertsPemWithClientCA(svr);
|
||||||
|
RejectsClientWithoutCert(svr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SSLClientServerTest, ClientCertStillRequiredAfterUpdateCertsPem) {
|
||||||
|
ClientCertStillRequired(UpdateCertsPemWithClientCA);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A TLS error from one request must not show up in a later request's Result
|
// A TLS error from one request must not show up in a later request's Result
|
||||||
|
|||||||
Reference in new issue
Block a user