Wildcard support for verifying server certificate. fix

This commit is contained in:
yhirose 2019-05-07 21:39:03 -04:00
parent 82193b9489
commit 3f42804a4f
5 changed files with 3548 additions and 90 deletions

3401
test/ca-bundle.crt Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@
#define SERVER_CERT_FILE "./cert.pem"
#define SERVER_PRIVATE_KEY_FILE "./key.pem"
#define CA_CERT_FILE "./ca-bundle.crt"
#ifdef _WIN32
#include <process.h>
@ -1345,6 +1346,34 @@ TEST(SSLClientTest, ServerNameIndication) {
ASSERT_TRUE(res != nullptr);
ASSERT_EQ(200, res->status);
}
TEST(SSLClientTest, ServerCertificateVerification) {
SSLClient cli("google.com");
auto res = cli.Get("/");
ASSERT_TRUE(res != nullptr);
ASSERT_EQ(301, res->status);
cli.enable_server_certificate_verification(true);
res = cli.Get("/");
ASSERT_TRUE(res == nullptr);
cli.set_ca_cert_path(CA_CERT_FILE);
res = cli.Get("/");
ASSERT_TRUE(res != nullptr);
ASSERT_EQ(301, res->status);
}
TEST(SSLClientTest, WildcardHostNameMatch) {
SSLClient cli("www.youtube.com");
cli.set_ca_cert_path(CA_CERT_FILE);
cli.enable_server_certificate_verification(true);
auto res = cli.Get("/");
ASSERT_TRUE(res != nullptr);
ASSERT_EQ(200, res->status);
}
#endif
#ifdef _WIN32