Skip to content

Commit 6177ced

Browse files
committed
fix verify ssl on windows, add option for anonymous auth
1 parent 50f3795 commit 6177ced

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/aws-cpp-sdk-core/include/aws/core/client/ClientConfiguration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ namespace Aws
453453
* Provide TelemetryProvider here or via a factory method.
454454
*/
455455
std::shared_ptr<smithy::components::tracing::TelemetryProvider> telemetryProvider;
456+
457+
/**
458+
* Configuration that is specifically used for the windows http client
459+
*/
460+
struct WinHTTPOptions {
461+
/**
462+
* Sets the windows http client to use WINHTTP_NO_CLIENT_CERT_CONTEXT when connecting
463+
* to a service, specifically only useful when disabling ssl verification and using
464+
* a different type of authentication.
465+
*/
466+
bool useAnonymousAuth = false;
467+
} winHTTPOptions;
456468
};
457469

458470
/**

src/aws-cpp-sdk-core/include/aws/core/http/windows/WinHttpSyncHttpClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace Aws
5959

6060
bool m_usingProxy = false;
6161
bool m_verifySSL = true;
62+
bool m_useAnonymousAuth = false;
6263
Aws::Http::Version m_version = Aws::Http::Version::HTTP_VERSION_2TLS;
6364
Aws::WString m_proxyUserName;
6465
Aws::WString m_proxyPassword;

src/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ WinHttpSyncHttpClient::WinHttpSyncHttpClient(const ClientConfiguration& config)
402402
Base(),
403403
m_usingProxy(!config.proxyHost.empty()),
404404
m_verifySSL(config.verifySSL),
405-
m_version(config.version)
405+
m_version(config.version),
406+
m_useAnonymousAuth(config.winHTTPOptions.useAnonymousAuth)
406407
{
407408
m_enableHttpClientTrace = config.enableHttpClientTrace;
408409

@@ -533,7 +534,10 @@ void* WinHttpSyncHttpClient::OpenRequest(const std::shared_ptr<HttpRequest>& req
533534
{
534535
LPCWSTR accept[2] = { nullptr, nullptr };
535536

536-
DWORD requestFlags = request->GetUri().GetScheme() == Scheme::HTTPS && m_verifySSL ? WINHTTP_FLAG_SECURE : 0;
537+
DWORD requestFlags{0};
538+
if (request->GetUri().GetScheme() == Scheme::HTTPS) {
539+
requestFlags |= WINHTTP_FLAG_SECURE;
540+
}
537541
if (m_usingProxy) {
538542
// Avoid force adding "Cache-Control: no-cache" header.
539543
requestFlags |= WINHTTP_FLAG_REFRESH;
@@ -569,11 +573,22 @@ void* WinHttpSyncHttpClient::OpenRequest(const std::shared_ptr<HttpRequest>& req
569573

570574
if (!m_verifySSL) // Turning ssl unknown ca verification off
571575
{
572-
DWORD flags = SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
576+
DWORD flags = SECURITY_FLAG_IGNORE_UNKNOWN_CA |
577+
SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
578+
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
579+
SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
573580
if (!AzCallWinHttp("WinHttpSetOption", WinHttpSetOption, hHttpRequest, WINHTTP_OPTION_SECURITY_FLAGS, &flags, (DWORD) sizeof(flags)))
574581
{
575582
AWS_LOGSTREAM_FATAL(GetLogTag(), "Failed to turn ssl cert ca verification off.");
576583
}
584+
585+
if (m_useAnonymousAuth)
586+
{
587+
if (!WinHttpSetOption(hHttpRequest, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, WINHTTP_NO_CLIENT_CERT_CONTEXT, 0))
588+
{
589+
AWS_LOGSTREAM_FATAL(GetLogTag(), "Failed to set anonymous auth on.");
590+
}
591+
}
577592
}
578593

579594
if (!GetConnectionPoolManager()->GetEnableTcpKeepAlive())

0 commit comments

Comments
 (0)