Skip to content

Commit 6f65e87

Browse files
authored
Implement host override of CN checking in the WinHTTP backend (#824)
* Implement CN overrides via the Host: header in the WinHTTP backend. * Repair lack of fallback CN verification on Windows. * Set security settings even for non-HTTPS URIs in WinHTTP, in case we get upgraded to SSL/TLS later. * Add test to make sure this doesn't explode. * Repair CPPREST_EXCLUDE_WEBSOCKETS support. * Move x509_cert_utilities.h out of public headers.
1 parent f884d91 commit 6f65e87

File tree

6 files changed

+374
-132
lines changed

6 files changed

+374
-132
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#include "cpprest/base_uri.h"
4141
#include "cpprest/details/http_helpers.h"
42-
#include "cpprest/details/x509_cert_utilities.h"
42+
#include "../common/x509_cert_utilities.h"
4343
#include "http_client_impl.h"
4444
#include "pplx/threadpool.h"
4545
#include <memory>
@@ -468,7 +468,7 @@ class asio_context final : public request_context, public std::enable_shared_fro
468468
, m_needChunked(false)
469469
, m_timer(client->client_config().timeout<std::chrono::microseconds>())
470470
, m_connection(connection)
471-
#if defined(__APPLE__) || (defined(ANDROID) || defined(__ANDROID__))
471+
#ifdef CPPREST_PLATFORM_ASIO_CERT_VERIFICATION_AVAILABLE
472472
, m_openssl_failed(false)
473473
#endif
474474
{
@@ -1032,11 +1032,11 @@ class asio_context final : public request_context, public std::enable_shared_fro
10321032
// finally by the root CA self signed certificate.
10331033

10341034
const auto& host = utility::conversions::to_utf8string(m_http_client->base_uri().host());
1035-
#if defined(__APPLE__) || (defined(ANDROID) || defined(__ANDROID__))
1036-
// On OS X, iOS, and Android, OpenSSL doesn't have access to where the OS
1037-
// stores keychains. If OpenSSL fails we will doing verification at the
1038-
// end using the whole certificate chain so wait until the 'leaf' cert.
1039-
// For now return true so OpenSSL continues down the certificate chain.
1035+
#ifdef CPPREST_PLATFORM_ASIO_CERT_VERIFICATION_AVAILABLE
1036+
// Attempt to use platform certificate validation when it is available:
1037+
// If OpenSSL fails we will doing verification at the end using the whole certificate chain,
1038+
// so wait until the 'leaf' cert. For now return true so OpenSSL continues down the certificate
1039+
// chain.
10401040
if (!preverified)
10411041
{
10421042
m_openssl_failed = true;
@@ -1757,7 +1757,7 @@ class asio_context final : public request_context, public std::enable_shared_fro
17571757
boost::asio::streambuf m_body_buf;
17581758
std::shared_ptr<asio_connection> m_connection;
17591759

1760-
#if defined(__APPLE__) || (defined(ANDROID) || defined(__ANDROID__))
1760+
#ifdef CPPREST_PLATFORM_ASIO_CERT_VERIFICATION_AVAILABLE
17611761
bool m_openssl_failed;
17621762
#endif
17631763
};

0 commit comments

Comments
 (0)