Skip to content

Allow disabling SSL certificate revocation checks #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Release/include/cpprest/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class http_client_config
, m_chunksize(0)
, m_request_compressed(false)
#if !defined(__cplusplus_winrt)
, m_validate_certificates(true)
, m_validate_certificates(true),
, m_check_ssl_certificate_revocation(true)
#endif
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
, m_tlsext_sni_enabled(true)
Expand Down Expand Up @@ -262,6 +263,19 @@ class http_client_config
/// otherwise.</param> <remarks>Note ignoring certificate errors can be dangerous and should be done with
/// caution.</remarks>
void set_validate_certificates(bool validate_certs) { m_validate_certificates = validate_certs; }

/// <summary>
/// Gets the enable SSL revocation property.
/// </summary>
/// <returns>True if certificates revocation is to be checked, false otherwise.</returns>
bool check_ssl_certificate_revocation() const { return m_check_ssl_certificate_revocation; }

/// <summary>
/// Sets the enable SSL revocation property.
/// </summary>
/// <param name="check_ssl_certificate_revocation">True to check certificate validation, false to skip these checks.</param>
/// <remarks>Note ignoring certificate revocation can be dangerous and should be done with caution.</remarks>
void set_check_ssl_certificate_revocation(bool check_ssl_certificate_revocation) { m_check_ssl_certificate_revocation = check_ssl_certificate_revocation; }
#endif

#if (defined(_WIN32) && !defined(__cplusplus_winrt)) || defined(CPPREST_FORCE_HTTP_CLIENT_WINHTTPPAL)
Expand Down Expand Up @@ -414,6 +428,7 @@ class http_client_config
#if !defined(__cplusplus_winrt)
// IXmlHttpRequest2 doesn't allow configuration of certificate verification.
bool m_validate_certificates;
bool m_check_ssl_certificate_revocation;
#endif

std::function<void(native_handle)> m_set_user_nativehandle_options;
Expand Down
23 changes: 13 additions & 10 deletions Release/src/http/client/http_client_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,16 +1091,19 @@ class winhttp_client final : public _http_client_communicator
DWORD ignoredCertificateValidationSteps = 0;
if (client_config().validate_certificates())
{
// if we are validating certificates, also turn on revocation checking
DWORD dwEnableSSLRevocationOpt = WINHTTP_ENABLE_SSL_REVOCATION;
if (!WinHttpSetOption(winhttp_context->m_request_handle,
WINHTTP_OPTION_ENABLE_FEATURE,
&dwEnableSSLRevocationOpt,
sizeof(dwEnableSSLRevocationOpt)))
{
auto errorCode = GetLastError();
request->report_error(errorCode, build_error_msg(errorCode, "Error enabling SSL revocation check"));
return;
// Check to see if we are checking certificate revocation as well
if (client_config().check_ssl_certificate_revocation())
{
DWORD dwEnableSSLRevocationOpt = WINHTTP_ENABLE_SSL_REVOCATION;
if (!WinHttpSetOption(winhttp_context->m_request_handle,
WINHTTP_OPTION_ENABLE_FEATURE,
&dwEnableSSLRevocationOpt,
sizeof(dwEnableSSLRevocationOpt)))
{
auto errorCode = GetLastError();
request->report_error(errorCode, build_error_msg(errorCode, "Error enabling SSL revocation check"));
return;
}
}

// check if the user has overridden the desired Common Name with the host header
Expand Down