From 5617dcd7560e22ca31352ac3fe5af912a165bc04 Mon Sep 17 00:00:00 2001 From: Zac Turner Date: Mon, 7 Aug 2023 15:37:22 +0000 Subject: [PATCH 1/2] Pass proxy settings through to s3Crt --- .../aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp index b1fbd22ee84..740d0095c85 100644 --- a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp +++ b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp @@ -133,6 +133,7 @@ #include #include #include +#include using namespace Aws::Utils; @@ -364,6 +365,64 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config, s3CrtConfig.tls_connection_options = nullptr; } + Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions; + aws_http_proxy_options raw_proxy_options; + + if (!config.proxyHost.empty()) + { + if (!config.proxyUserName.empty() || !config.proxyPassword.empty()) + { + Aws::Crt::Http::HttpProxyStrategyBasicAuthConfig basicAuthConfig; + basicAuthConfig.ConnectionType = Aws::Crt::Http::AwsHttpProxyConnectionType::Tunneling; + basicAuthConfig.Username = config.proxyUserName.c_str(); + basicAuthConfig.Password = config.proxyPassword.c_str(); + proxyOptions.ProxyStrategy = Aws::Crt::Http::HttpProxyStrategy::CreateBasicHttpProxyStrategy(basicAuthConfig, Aws::get_aws_allocator()); + } + + proxyOptions.HostName = config.proxyHost.c_str(); + + if (config.proxyPort != 0) + { + proxyOptions.Port = static_cast(config.proxyPort); + } + else + { + proxyOptions.Port = config.proxyScheme == Scheme::HTTPS ? 443 : 80; + } + + if (config.proxyScheme == Scheme::HTTPS) + { + Crt::Io::TlsContextOptions contextOptions = Crt::Io::TlsContextOptions::InitDefaultClient(); + + if (config.proxySSLKeyPassword.empty() && !config.proxySSLCertPath.empty()) + { + const char* certPath = config.proxySSLCertPath.empty() ? nullptr : config.proxySSLCertPath.c_str(); + const char* certFile = config.proxySSLKeyPath.empty() ? nullptr : config.proxySSLKeyPath.c_str(); + contextOptions = Crt::Io::TlsContextOptions::InitClientWithMtls(certPath, certFile); + } + else if (!config.proxySSLKeyPassword.empty()) + { + const char* pkcs12CertFile = config.proxySSLKeyPath.empty() ? nullptr : config.proxySSLKeyPath.c_str(); + const char* pkcs12Pwd = config.proxySSLKeyPassword.c_str(); + contextOptions = Crt::Io::TlsContextOptions::InitClientWithMtlsPkcs12(pkcs12CertFile, pkcs12Pwd); + } + + if (!config.caFile.empty() || !config.caPath.empty()) + { + const char* caPath = config.caPath.empty() ? nullptr : config.caPath.c_str(); + const char* caFile = config.caFile.empty() ? nullptr : config.caFile.c_str(); + contextOptions.OverrideDefaultTrustStore(caPath, caFile); + } + + contextOptions.SetVerifyPeer(config.verifySSL); + Crt::Io::TlsContext context = Crt::Io::TlsContext(contextOptions, Crt::Io::TlsMode::CLIENT); + proxyOptions.TlsOptions = context.NewConnectionOptions(); + } + + proxyOptions.InitializeRawProxyOptions(raw_proxy_options); + s3CrtConfig.proxy_options = &raw_proxy_options; + } + s3CrtConfig.tls_mode = config.scheme == Aws::Http::Scheme::HTTPS ? AWS_MR_TLS_ENABLED : AWS_MR_TLS_DISABLED; s3CrtConfig.throughput_target_gbps = config.throughputTargetGbps; m_clientShutdownSem = Aws::MakeShared(ALLOCATION_TAG, 0, 1); From 8936e73d7c4a03a68aeed97d2d5d12d61e4adade Mon Sep 17 00:00:00 2001 From: sbiscigl Date: Mon, 4 Dec 2023 12:58:06 -0500 Subject: [PATCH 2/2] add codegen --- .../aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp | 2 +- .../cpp/ServiceClientSourceHeaders.vm | 1 + .../s3/s3-crt/S3CrtServiceClientSourceInit.vm | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp index 740d0095c85..98a9eef55f0 100644 --- a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp +++ b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp @@ -129,11 +129,11 @@ #include #include #include +#include #include #include #include #include -#include using namespace Aws::Utils; diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/ServiceClientSourceHeaders.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/ServiceClientSourceHeaders.vm index f031427f2ea..1b3c36ee2bd 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/ServiceClientSourceHeaders.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/ServiceClientSourceHeaders.vm @@ -48,6 +48,7 @@ \#include \#include \#include +\#include \#include \#include \#include diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtServiceClientSourceInit.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtServiceClientSourceInit.vm index 8a405975726..77609bab8c6 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtServiceClientSourceInit.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtServiceClientSourceInit.vm @@ -403,6 +403,64 @@ void ${className}::init(const ${clientConfigurationNamespace}::ClientConfigurati s3CrtConfig.tls_connection_options = nullptr; } + Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions; + aws_http_proxy_options raw_proxy_options; + + if (!config.proxyHost.empty()) + { + if (!config.proxyUserName.empty() || !config.proxyPassword.empty()) + { + Aws::Crt::Http::HttpProxyStrategyBasicAuthConfig basicAuthConfig; + basicAuthConfig.ConnectionType = Aws::Crt::Http::AwsHttpProxyConnectionType::Tunneling; + basicAuthConfig.Username = config.proxyUserName.c_str(); + basicAuthConfig.Password = config.proxyPassword.c_str(); + proxyOptions.ProxyStrategy = Aws::Crt::Http::HttpProxyStrategy::CreateBasicHttpProxyStrategy(basicAuthConfig, Aws::get_aws_allocator()); + } + + proxyOptions.HostName = config.proxyHost.c_str(); + + if (config.proxyPort != 0) + { + proxyOptions.Port = static_cast(config.proxyPort); + } + else + { + proxyOptions.Port = config.proxyScheme == Scheme::HTTPS ? 443 : 80; + } + + if (config.proxyScheme == Scheme::HTTPS) + { + Crt::Io::TlsContextOptions contextOptions = Crt::Io::TlsContextOptions::InitDefaultClient(); + + if (config.proxySSLKeyPassword.empty() && !config.proxySSLCertPath.empty()) + { + const char* certPath = config.proxySSLCertPath.empty() ? nullptr : config.proxySSLCertPath.c_str(); + const char* certFile = config.proxySSLKeyPath.empty() ? nullptr : config.proxySSLKeyPath.c_str(); + contextOptions = Crt::Io::TlsContextOptions::InitClientWithMtls(certPath, certFile); + } + else if (!config.proxySSLKeyPassword.empty()) + { + const char* pkcs12CertFile = config.proxySSLKeyPath.empty() ? nullptr : config.proxySSLKeyPath.c_str(); + const char* pkcs12Pwd = config.proxySSLKeyPassword.c_str(); + contextOptions = Crt::Io::TlsContextOptions::InitClientWithMtlsPkcs12(pkcs12CertFile, pkcs12Pwd); + } + + if (!config.caFile.empty() || !config.caPath.empty()) + { + const char* caPath = config.caPath.empty() ? nullptr : config.caPath.c_str(); + const char* caFile = config.caFile.empty() ? nullptr : config.caFile.c_str(); + contextOptions.OverrideDefaultTrustStore(caPath, caFile); + } + + contextOptions.SetVerifyPeer(config.verifySSL); + Crt::Io::TlsContext context = Crt::Io::TlsContext(contextOptions, Crt::Io::TlsMode::CLIENT); + proxyOptions.TlsOptions = context.NewConnectionOptions(); + } + + proxyOptions.InitializeRawProxyOptions(raw_proxy_options); + s3CrtConfig.proxy_options = &raw_proxy_options; + } + s3CrtConfig.tls_mode = config.scheme == Aws::Http::Scheme::HTTPS ? AWS_MR_TLS_ENABLED : AWS_MR_TLS_DISABLED; s3CrtConfig.throughput_target_gbps = config.throughputTargetGbps; m_clientShutdownSem = Aws::MakeShared(ALLOCATION_TAG, 0, 1);