mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-23 13:09:11 +00:00
Wildcard support for verifying server certificate. fix #87
This commit is contained in:
parent
82193b9489
commit
3f42804a4f
5 changed files with 3548 additions and 90 deletions
3401
test/ca-bundle.crt
Normal file
3401
test/ca-bundle.crt
Normal file
File diff suppressed because it is too large
Load diff
29
test/test.cc
29
test/test.cc
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue