Skip to content
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

Crt proxy #2777

Merged
merged 2 commits into from
Dec 4, 2023
Merged
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
59 changes: 59 additions & 0 deletions generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#include <aws/crt/Types.h>
#include <aws/crt/auth/Credentials.h>
#include <aws/crt/http/HttpRequestResponse.h>
#include <aws/crt/http/HttpProxyStrategy.h>
#include <aws/crt/io/Stream.h>
#include <aws/crt/io/Uri.h>
#include <aws/http/request_response.h>
Expand Down Expand Up @@ -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<uint16_t>(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<Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
\#include <aws/crt/Types.h>
\#include <aws/crt/auth/Credentials.h>
\#include <aws/crt/http/HttpRequestResponse.h>
\#include <aws/crt/http/HttpProxyStrategy.h>
\#include <aws/crt/io/Stream.h>
\#include <aws/crt/io/Uri.h>
\#include <aws/http/request_response.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(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<Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
Expand Down
Loading