Debian Codegraph @

crt/aws-c-http/include/aws/http/private/proxy_impl.h

raw symbols SCIP
1 #ifndef AWS_HTTP_PROXY_IMPL_H
2 #define AWS_HTTP_PROXY_IMPL_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/http/http.h>
10
11 #include <aws/common/hash_table.h>
12 #include <aws/http/connection.h>
13 #include <aws/http/proxy.h>
14 #include <aws/http/status_code.h>
15 #include <aws/io/channel_bootstrap.h>
16 #include <aws/io/socket.h>
17
18 struct aws_http_connection_manager_options;
19 struct aws_http_message;
20 struct aws_channel_slot;
21 struct aws_string;
22 struct aws_tls_connection_options;
23 struct aws_http_proxy_negotiator;
24 struct aws_http_proxy_strategy;
25 struct aws_http_proxy_strategy_tunneling_sequence_options;
26 struct aws_http_proxy_strategy_tunneling_kerberos_options;
27 struct aws_http_proxy_strategy_tunneling_ntlm_options;
28
29 /*
30 * (Successful) State transitions for proxy connections
31 *
32 * Http : None -> Socket Connect -> Success
33 * Https: None -> Socket Connect -> Http Connect -> Tls Negotiation -> Success
34 */
35 enum aws_proxy_bootstrap_state {
36 AWS_PBS_NONE = 0,
37 AWS_PBS_SOCKET_CONNECT,
38 AWS_PBS_HTTP_CONNECT,
39 AWS_PBS_TLS_NEGOTIATION,
40 AWS_PBS_SUCCESS,
41 AWS_PBS_FAILURE,
42 };
43
44 /**
45 * A persistent copy of the aws_http_proxy_options struct. Clones everything appropriate.
46 */
47 struct aws_http_proxy_config {
48
49 struct aws_allocator *allocator;
50
51 enum aws_http_proxy_connection_type connection_type;
52
53 struct aws_byte_buf host;
54
55 uint32_t port;
56
57 struct aws_tls_connection_options *tls_options;
58
59 struct aws_http_proxy_strategy *proxy_strategy;
60
61 struct aws_byte_buf no_proxy_hosts;
62 };
63
64 /*
65 * When a proxy connection is made, we wrap the user-supplied user data with this
66 * proxy user data. Callbacks are passed properly to the user. By having this data
67 * available, the proxy request transform that was attached to the connection can extract
68 * the proxy settings it needs in order to properly transform the requests.
69 *
70 * Another possibility would be to fold this data into the connection itself.
71 */
72 struct aws_http_proxy_user_data {
73 struct aws_allocator *allocator;
74
75 /*
76 * dynamic proxy connection resolution state
77 */
78 enum aws_proxy_bootstrap_state state;
79 int error_code;
80 enum aws_http_status_code connect_status_code;
81
82 /*
83 * The initial http connection object between the client and the proxy.
84 */
85 struct aws_http_connection *proxy_connection;
86
87 /*
88 * The http connection object that gets surfaced to callers if http is the final protocol of proxy
89 * negotiation.
90 *
91 * In the case of a forwarding proxy, proxy_connection and final_connection are the same.
92 */
93 struct aws_http_connection *final_connection;
94 struct aws_http_message *connect_request;
95 struct aws_http_stream *connect_stream;
96 struct aws_http_proxy_negotiator *proxy_negotiator;
97
98 /*
99 * Cached original connect options
100 */
101 struct aws_string *original_host;
102 uint32_t original_port;
103 void *original_user_data;
104 struct aws_tls_connection_options *original_tls_options;
105 struct aws_client_bootstrap *original_bootstrap;
106 struct aws_socket_options original_socket_options;
107 bool original_manual_window_management;
108 size_t original_initial_window_size;
109 bool prior_knowledge_http2;
110 struct aws_http1_connection_options original_http1_options;
111 struct aws_http2_connection_options
112 original_http2_options; /* the resource within options are allocated with userdata */
113 struct aws_hash_table alpn_string_map;
114 /*
115 * setup/shutdown callbacks. We enforce via fatal assert that either the http callbacks are supplied or
116 * the channel callbacks are supplied but never both.
117 *
118 * When using a proxy to ultimately establish an http connection, use the http callbacks.
119 * When using a proxy to establish any other protocol connection, use the raw channel callbacks.
120 *
121 * In the future, we might consider a further refactor which only use raw channel callbacks.
122 */
123 aws_http_on_client_connection_setup_fn *original_http_on_setup;
124 aws_http_on_client_connection_shutdown_fn *original_http_on_shutdown;
125 aws_client_bootstrap_on_channel_event_fn *original_channel_on_setup;
126 aws_client_bootstrap_on_channel_event_fn *original_channel_on_shutdown;
127
128 struct aws_http_proxy_config *proxy_config;
129
130 struct aws_event_loop *requested_event_loop;
131
132 const struct aws_host_resolution_config *host_resolution_config;
133 };
134
135 /* vtable of functions that proxy uses to interact with external systems.
136 * tests override the vtable to mock those systems */
137 struct aws_http_proxy_system_vtable {
138 int (*aws_channel_setup_client_tls)(
139 struct aws_channel_slot *right_of_slot,
140 struct aws_tls_connection_options *tls_options);
141 };
142
143 AWS_EXTERN_C_BEGIN
144
145 AWS_HTTP_API
146 struct aws_http_proxy_user_data *aws_http_proxy_user_data_new(
147 struct aws_allocator *allocator,
148 const struct aws_http_client_connection_options *options,
149 aws_client_bootstrap_on_channel_event_fn *on_channel_setup,
150 aws_client_bootstrap_on_channel_event_fn *on_channel_shutdown);
151
152 AWS_HTTP_API
153 void aws_http_proxy_user_data_destroy(struct aws_http_proxy_user_data *user_data);
154
155 AWS_HTTP_API
156 int aws_http_client_connect_via_proxy(const struct aws_http_client_connection_options *options);
157
158 AWS_HTTP_API
159 int aws_http_rewrite_uri_for_proxy_request(
160 struct aws_http_message *request,
161 struct aws_http_proxy_user_data *proxy_user_data);
162
163 AWS_HTTP_API
164 void aws_http_proxy_system_set_vtable(struct aws_http_proxy_system_vtable *vtable);
165
166 /**
167 * Checks if tunneling proxy negotiation should continue to try and connect
168 * @param proxy_negotiator negotiator to query
169 * @return true if another connect request should be attempted, false otherwise
170 */
171 AWS_HTTP_API
172 enum aws_http_proxy_negotiation_retry_directive aws_http_proxy_negotiator_get_retry_directive(
173 struct aws_http_proxy_negotiator *proxy_negotiator);
174
175 /**
176 * Constructor for a tunnel-only proxy strategy that applies no changes to outbound CONNECT requests. Intended to be
177 * the first link in an adaptive sequence for a tunneling proxy: first try a basic CONNECT, then based on the response,
178 * later links are allowed to make attempts.
179 *
180 * @param allocator memory allocator to use
181 * @return a new proxy strategy if successfully constructed, otherwise NULL
182 */
183 AWS_HTTP_API
184 struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_tunneling_one_time_identity(
185 struct aws_allocator *allocator);
186
187 /**
188 * Constructor for a forwarding-only proxy strategy that does nothing. Exists so that all proxy logic uses a
189 * strategy.
190 *
191 * @param allocator memory allocator to use
192 * @return a new proxy strategy if successfully constructed, otherwise NULL
193 */
194 AWS_HTTP_API
195 struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_forwarding_identity(struct aws_allocator *allocator);
196
197 /**
198 * Constructor for a tunneling proxy strategy that contains a set of sub-strategies which are tried
199 * sequentially in order. Each strategy has the choice to either proceed on a fresh connection or
200 * reuse the current one.
201 *
202 * @param allocator memory allocator to use
203 * @param config sequence configuration options
204 * @return a new proxy strategy if successfully constructed, otherwise NULL
205 */
206 AWS_HTTP_API
207 struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_tunneling_sequence(
208 struct aws_allocator *allocator,
209 struct aws_http_proxy_strategy_tunneling_sequence_options *config);
210
211 /**
212 * A constructor for a proxy strategy that performs kerberos authentication by adding the appropriate
213 * header and header value to CONNECT requests.
214 *
215 * Currently only supports synchronous fetch of kerberos token values.
216 *
217 * @param allocator memory allocator to use
218 * @param config kerberos authentication configuration info
219 * @return a new proxy strategy if successfully constructed, otherwise NULL
220 */
221 AWS_HTTP_API
222 struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_tunneling_kerberos(
223 struct aws_allocator *allocator,
224 struct aws_http_proxy_strategy_tunneling_kerberos_options *config);
225
226 /**
227 * Constructor for an NTLM proxy strategy. Because ntlm is a challenge-response authentication protocol, this
228 * strategy will only succeed in a chain in a non-leading position. The strategy extracts the challenge from the
229 * proxy's response to a previous CONNECT request in the chain.
230 *
231 * Currently only supports synchronous fetch of token values.
232 *
233 * @param allocator memory allocator to use
234 * @param config configuration options for the strategy
235 * @return a new proxy strategy if successfully constructed, otherwise NULL
236 */
237 AWS_HTTP_API
238 struct aws_http_proxy_strategy *aws_http_proxy_strategy_new_tunneling_ntlm(
239 struct aws_allocator *allocator,
240 struct aws_http_proxy_strategy_tunneling_ntlm_options *config);
241
242 AWS_EXTERN_C_END
243
244 #endif /* AWS_HTTP_PROXY_IMPL_H */