Skip to content

Commit 7475c61

Browse files
sbSteveKgraebm
andauthored
Add HttpClientConnectionProxyOptions to SecureTunnel (#339)
* Added HttpClientConnectionProxyOptions to SecureTunnel constructor * Added aws_http_proxy_options and aws_http_proxy_options_storage implementation to SecureTunnel * expose private header for test build on linux Co-authored-by: Michael Graeb <graebm@amazon.com>
1 parent 74e0b28 commit 7475c61

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

secure_tunneling/include/aws/iotsecuretunneling/SecureTunnel.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0.
55
*/
66

7+
#include <aws/crt/http/HttpConnection.h>
78
#include <aws/crt/io/Bootstrap.h>
89
#include <aws/crt/io/SocketOptions.h>
910
#include <aws/iotdevice/secure_tunneling.h>
@@ -25,6 +26,26 @@ namespace Aws
2526
class AWS_IOTSECURETUNNELING_API SecureTunnel final
2627
{
2728
public:
29+
SecureTunnel(
30+
// Parameters map to aws_secure_tunneling_connection_config
31+
Crt::Allocator *allocator, // Should out live this object
32+
Aws::Crt::Io::ClientBootstrap *clientBootstrap, // Should out live this object
33+
const Aws::Crt::Io::SocketOptions &socketOptions, // Make a copy and save in this object
34+
Aws::Crt::Http::HttpClientConnectionProxyOptions
35+
*httpClientConnectionProxyOptions, // Make a copy and save in this object
36+
37+
const std::string &accessToken, // Make a copy and save in this object
38+
aws_secure_tunneling_local_proxy_mode localProxyMode,
39+
const std::string &endpointHost, // Make a copy and save in this object
40+
const std::string &rootCa, // Make a copy and save in this object
41+
42+
OnConnectionComplete onConnectionComplete,
43+
OnConnectionShutdown onConnectionShutdown,
44+
OnSendDataComplete onSendDataComplete,
45+
OnDataReceive onDataReceive,
46+
OnStreamStart onStreamStart,
47+
OnStreamReset onStreamReset,
48+
OnSessionReset onSessionReset);
2849
SecureTunnel(
2950
// Parameters map to aws_secure_tunneling_connection_config
3051
Crt::Allocator *allocator, // Should out live this object

secure_tunneling/source/SecureTunnel.cpp

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Aws
1313
Crt::Allocator *allocator,
1414
Aws::Crt::Io::ClientBootstrap *clientBootstrap,
1515
const Aws::Crt::Io::SocketOptions &socketOptions,
16+
Aws::Crt::Http::HttpClientConnectionProxyOptions *httpClientConnectionProxyOptions,
1617

1718
const std::string &accessToken,
1819
aws_secure_tunneling_local_proxy_mode localProxyMode,
@@ -41,8 +42,8 @@ namespace Aws
4142
m_endpointHost = endpointHost;
4243
m_rootCa = rootCa;
4344

44-
// Initialize aws_secure_tunneling_connection_config
45-
aws_secure_tunneling_connection_config config;
45+
// Initialize aws_secure_tunnel_options
46+
aws_secure_tunnel_options config;
4647
AWS_ZERO_STRUCT(config);
4748

4849
config.allocator = allocator;
@@ -52,7 +53,11 @@ namespace Aws
5253
config.access_token = aws_byte_cursor_from_c_str(m_accessToken.c_str());
5354
config.local_proxy_mode = localProxyMode;
5455
config.endpoint_host = aws_byte_cursor_from_c_str(m_endpointHost.c_str());
55-
config.root_ca = m_rootCa.c_str();
56+
57+
if (m_rootCa.length() > 0)
58+
{
59+
config.root_ca = m_rootCa.c_str();
60+
}
5661

5762
config.on_connection_complete = s_OnConnectionComplete;
5863
config.on_connection_shutdown = s_OnConnectionShutdown;
@@ -64,10 +69,54 @@ namespace Aws
6469

6570
config.user_data = this;
6671

72+
aws_http_proxy_options temp;
73+
AWS_ZERO_STRUCT(temp);
74+
if (httpClientConnectionProxyOptions != NULL)
75+
{
76+
httpClientConnectionProxyOptions->InitializeRawProxyOptions(temp);
77+
config.http_proxy_options = &temp;
78+
}
79+
6780
// Create the secure tunnel
6881
m_secure_tunnel = aws_secure_tunnel_new(&config);
6982
}
7083

84+
SecureTunnel::SecureTunnel(
85+
Crt::Allocator *allocator,
86+
Aws::Crt::Io::ClientBootstrap *clientBootstrap,
87+
const Aws::Crt::Io::SocketOptions &socketOptions,
88+
89+
const std::string &accessToken,
90+
aws_secure_tunneling_local_proxy_mode localProxyMode,
91+
const std::string &endpointHost,
92+
const std::string &rootCa,
93+
94+
OnConnectionComplete onConnectionComplete,
95+
OnConnectionShutdown onConnectionShutdown,
96+
OnSendDataComplete onSendDataComplete,
97+
OnDataReceive onDataReceive,
98+
OnStreamStart onStreamStart,
99+
OnStreamReset onStreamReset,
100+
OnSessionReset onSessionReset)
101+
: SecureTunnel(
102+
allocator,
103+
clientBootstrap,
104+
socketOptions,
105+
nullptr,
106+
accessToken,
107+
localProxyMode,
108+
endpointHost,
109+
rootCa,
110+
onConnectionComplete,
111+
onConnectionShutdown,
112+
onSendDataComplete,
113+
onDataReceive,
114+
onStreamStart,
115+
onStreamReset,
116+
onSessionReset)
117+
{
118+
}
119+
71120
SecureTunnel::SecureTunnel(SecureTunnel &&other) noexcept
72121
{
73122
m_OnConnectionComplete = other.m_OnConnectionComplete;

secure_tunneling/tests/SecureTunnelTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <aws/common/byte_buf.h>
77
#include <aws/crt/io/SocketOptions.h>
88
#include <aws/http/http.h>
9+
#include <aws/iotdevice/private/secure_tunneling_impl.h>
910
#include <aws/iotdevice/private/serializer.h>
1011
#include <aws/iotdevicecommon/IotDevice.h>
1112
#include <aws/iotsecuretunneling/SecureTunnel.h>

0 commit comments

Comments
 (0)