aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.96k stars 1.05k forks source link

fix disable ssl in windows http client #2864

Closed sbiscigl closed 7 months ago

sbiscigl commented 7 months ago

Issue #, if available:

issues/1445

Description of changes:

Fixes a issue where when verify ssl is disabled on windows we still set WINHTTP_FLAG_SECURE

according to msft documentation

Uses secure transaction semantics. This translates to using Secure Sockets Layer (SSL)/Transport Layer Security (TLS).

This checks to not set it when verify ssl has been turned off.

Tested using the code provided in the above issues using a opensearch distro

#include <aws/core/Aws.h>
#include <aws/core/http/HttpClient.h>
#include <aws/core/utils/HashingUtils.h>

using namespace Aws;

auto main() -> int {
    SDKOptions options;
    options.loggingOptions.logLevel = Utils::Logging::LogLevel::Trace;
    InitAPI(options); {
        // Set client configuration
        Client::ClientConfiguration config;
        config.scheme = Aws::Http::Scheme::HTTPS;
        config.verifySSL = false;

        const auto client = Aws::Http::CreateHttpClient(config);

        // Generate http request
        const auto request = CreateHttpRequest(
          String("https://localhost:9200/_cat/plugins?format=json"),
          Http::HttpMethod::HTTP_GET,
          Utils::Stream::DefaultResponseStreamFactoryMethod);

        // Set Authentication
        std::string authString = "admin:admin";
        Utils::Array<unsigned char> userpw_arr(reinterpret_cast<const unsigned char *>(authString.c_str()),authString.length());
        const auto basicAuth = Utils::HashingUtils::Base64Encode(userpw_arr);
        request->SetAuthorization("Basic " + basicAuth);

        // Issue request
        const auto response = client->MakeRequest(request);
        //assert(response->GetResponseCode() == Http::HttpResponseCode::OK);
        std::stringstream ss;
        ss << response->GetResponseBody().rdbuf();
        std::cout << ss.str() << "\n";
    }
    ShutdownAPI(options);
    return 0;
}

Check all that applies:

Check which platforms you have built SDK on to verify the correctness of this PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.