mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Renamed enable_server_host_verification to enable_server_hostname_verification and added Error::SSLServerHostnameVerification
This commit is contained in:
parent
f35aff84c2
commit
ea79494b29
1 changed files with 13 additions and 12 deletions
25
httplib.h
25
httplib.h
|
@ -1135,6 +1135,7 @@ enum class Error {
|
||||||
SSLConnection,
|
SSLConnection,
|
||||||
SSLLoadingCerts,
|
SSLLoadingCerts,
|
||||||
SSLServerVerification,
|
SSLServerVerification,
|
||||||
|
SSLServerHostnameVerification,
|
||||||
UnsupportedMultipartBoundaryChars,
|
UnsupportedMultipartBoundaryChars,
|
||||||
Compression,
|
Compression,
|
||||||
ConnectionTimeout,
|
ConnectionTimeout,
|
||||||
|
@ -1450,7 +1451,7 @@ public:
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void enable_server_certificate_verification(bool enabled);
|
void enable_server_certificate_verification(bool enabled);
|
||||||
void enable_server_host_verification(bool enabled);
|
void enable_server_hostname_verification(bool enabled);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set_logger(Logger logger);
|
void set_logger(Logger logger);
|
||||||
|
@ -1565,7 +1566,7 @@ protected:
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
bool server_certificate_verification_ = true;
|
bool server_certificate_verification_ = true;
|
||||||
bool server_host_verification_ = true;
|
bool server_hostname_verification_ = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Logger logger_;
|
Logger logger_;
|
||||||
|
@ -1871,7 +1872,7 @@ public:
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void enable_server_certificate_verification(bool enabled);
|
void enable_server_certificate_verification(bool enabled);
|
||||||
void enable_server_host_verification(bool enabled);
|
void enable_server_hostname_verification(bool enabled);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set_logger(Logger logger);
|
void set_logger(Logger logger);
|
||||||
|
@ -2163,6 +2164,8 @@ inline std::string to_string(const Error error) {
|
||||||
case Error::SSLConnection: return "SSL connection failed";
|
case Error::SSLConnection: return "SSL connection failed";
|
||||||
case Error::SSLLoadingCerts: return "SSL certificate loading failed";
|
case Error::SSLLoadingCerts: return "SSL certificate loading failed";
|
||||||
case Error::SSLServerVerification: return "SSL server verification failed";
|
case Error::SSLServerVerification: return "SSL server verification failed";
|
||||||
|
case Error::SSLServerHostnameVerification:
|
||||||
|
return "SSL server hostname verification failed";
|
||||||
case Error::UnsupportedMultipartBoundaryChars:
|
case Error::UnsupportedMultipartBoundaryChars:
|
||||||
return "Unsupported HTTP multipart boundary characters";
|
return "Unsupported HTTP multipart boundary characters";
|
||||||
case Error::Compression: return "Compression failed";
|
case Error::Compression: return "Compression failed";
|
||||||
|
@ -8726,8 +8729,8 @@ inline void ClientImpl::enable_server_certificate_verification(bool enabled) {
|
||||||
server_certificate_verification_ = enabled;
|
server_certificate_verification_ = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ClientImpl::enable_server_host_verification(bool enabled) {
|
inline void ClientImpl::enable_server_hostname_verification(bool enabled) {
|
||||||
server_host_verification_ = enabled;
|
server_hostname_verification_ = enabled;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -9319,21 +9322,19 @@ inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto server_cert = SSL_get1_peer_certificate(ssl2);
|
auto server_cert = SSL_get1_peer_certificate(ssl2);
|
||||||
|
auto se = detail::scope_exit([&] { X509_free(server_cert); });
|
||||||
|
|
||||||
if (server_cert == nullptr) {
|
if (server_cert == nullptr) {
|
||||||
error = Error::SSLServerVerification;
|
error = Error::SSLServerVerification;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_host_verification_) {
|
if (server_hostname_verification_) {
|
||||||
if (!verify_host(server_cert)) {
|
if (!verify_host(server_cert)) {
|
||||||
X509_free(server_cert);
|
error = Error::SSLServerHostnameVerification;
|
||||||
error = Error::SSLServerVerification;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
X509_free(server_cert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -10065,8 +10066,8 @@ inline void Client::enable_server_certificate_verification(bool enabled) {
|
||||||
cli_->enable_server_certificate_verification(enabled);
|
cli_->enable_server_certificate_verification(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Client::enable_server_host_verification(bool enabled) {
|
inline void Client::enable_server_hostname_verification(bool enabled) {
|
||||||
cli_->enable_server_host_verification(enabled);
|
cli_->enable_server_hostname_verification(enabled);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue