| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/auth/credentials.h> |
| 6 |
#include <aws/auth/private/credentials_utils.h> |
| 7 |
#include <aws/auth/signable.h> |
| 8 |
#include <aws/auth/signing.h> |
| 9 |
#include <aws/auth/signing_config.h> |
| 10 |
#include <aws/auth/signing_result.h> |
| 11 |
#include <aws/common/clock.h> |
| 12 |
#include <aws/common/environment.h> |
| 13 |
#include <aws/common/string.h> |
| 14 |
#include <aws/common/xml_parser.h> |
| 15 |
#include <aws/sdkutils/aws_profile.h> |
| 16 |
|
| 17 |
#include <aws/http/connection.h> |
| 18 |
#include <aws/http/connection_manager.h> |
| 19 |
#include <aws/http/request_response.h> |
| 20 |
#include <aws/http/status_code.h> |
| 21 |
|
| 22 |
#include <aws/io/channel_bootstrap.h> |
| 23 |
#include <aws/io/retry_strategy.h> |
| 24 |
#include <aws/io/socket.h> |
| 25 |
#include <aws/io/stream.h> |
| 26 |
#include <aws/io/tls_channel_handler.h> |
| 27 |
#include <aws/io/uri.h> |
| 28 |
|
| 29 |
#include <inttypes.h> |
| 30 |
|
| 31 |
#ifdef _MSC_VER |
| 32 |
|
| 33 |
# pragma warning(disable : 4204) |
| 34 |
|
| 35 |
# pragma warning(disable : 4221) |
| 36 |
|
| 37 |
# pragma warning(disable : 4232) |
| 38 |
#endif |
| 39 |
|
| 40 |
static int s_sts_xml_on_AssumeRoleResponse_child(struct aws_xml_node *, void *); |
| 41 |
static int s_sts_xml_on_AssumeRoleResult_child(struct aws_xml_node *, void *); |
| 42 |
static int s_sts_xml_on_Credentials_child(struct aws_xml_node *, void *); |
| 43 |
static int s_sts_xml_on_AssumedRoleUser_child(struct aws_xml_node *, void *); |
| 44 |
|
| 45 |
static struct aws_http_header s_content_type_header = { |
| 46 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("content-type"), |
| 47 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("application/x-www-form-urlencoded"), |
| 48 |
}; |
| 49 |
|
| 50 |
static struct aws_byte_cursor s_content_length = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("content-length"); |
| 51 |
static struct aws_byte_cursor s_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/"); |
| 52 |
AWS_STATIC_STRING_FROM_LITERAL(s_sts_service_name, "sts"); |
| 53 |
AWS_STATIC_STRING_FROM_LITERAL(s_sts_service_env_name, "STS"); |
| 54 |
|
| 55 |
static const int s_max_retries = 3; |
| 56 |
|
| 57 |
const uint16_t aws_sts_assume_role_default_duration_secs = 900; |
| 58 |
|
| 59 |
struct aws_credentials_provider_sts_impl { |
| 60 |
struct aws_http_connection_manager *connection_manager; |
| 61 |
struct aws_string *assume_role_profile; |
| 62 |
struct aws_string *role_session_name; |
| 63 |
struct aws_string *external_id; |
| 64 |
struct aws_string *endpoint; |
| 65 |
struct aws_string *region; |
| 66 |
uint16_t duration_seconds; |
| 67 |
struct aws_credentials_provider *provider; |
| 68 |
struct aws_credentials_provider_shutdown_options source_shutdown_options; |
| 69 |
const struct aws_auth_http_system_vtable *function_table; |
| 70 |
struct aws_retry_strategy *retry_strategy; |
| 71 |
aws_io_clock_fn *system_clock_fn; |
| 72 |
}; |
| 73 |
|
| 74 |
struct sts_creds_provider_user_data { |
| 75 |
struct aws_allocator *allocator; |
| 76 |
struct aws_credentials_provider *provider; |
| 77 |
struct aws_credentials *credentials; |
| 78 |
struct aws_string *access_key_id; |
| 79 |
struct aws_string *secret_access_key; |
| 80 |
struct aws_string *session_token; |
| 81 |
struct aws_string *account_id; |
| 82 |
aws_on_get_credentials_callback_fn *callback; |
| 83 |
struct aws_http_connection *connection; |
| 84 |
struct aws_byte_buf payload_body; |
| 85 |
struct aws_input_stream *input_stream; |
| 86 |
struct aws_signable *signable; |
| 87 |
struct aws_signing_config_aws signing_config; |
| 88 |
struct aws_http_message *message; |
| 89 |
struct aws_byte_buf output_buf; |
| 90 |
|
| 91 |
struct aws_retry_token *retry_token; |
| 92 |
int error_code; |
| 93 |
void *user_data; |
| 94 |
}; |
| 95 |
|
| 96 |
static void s_reset_request_specific_data(struct sts_creds_provider_user_data *user_data) { |
| 97 |
if (user_data->connection) { |
| 98 |
struct aws_credentials_provider_sts_impl *provider_impl = user_data->provider->impl; |
| 99 |
provider_impl->function_table->aws_http_connection_manager_release_connection( |
| 100 |
provider_impl->connection_manager, user_data->connection); |
| 101 |
user_data->connection = NULL; |
| 102 |
} |
| 103 |
|
| 104 |
if (user_data->signable) { |
| 105 |
aws_signable_destroy(user_data->signable); |
| 106 |
user_data->signable = NULL; |
| 107 |
} |
| 108 |
|
| 109 |
if (user_data->input_stream) { |
| 110 |
aws_input_stream_destroy(user_data->input_stream); |
| 111 |
user_data->input_stream = NULL; |
| 112 |
} |
| 113 |
|
| 114 |
aws_byte_buf_clean_up(&user_data->payload_body); |
| 115 |
|
| 116 |
if (user_data->message) { |
| 117 |
aws_http_message_destroy(user_data->message); |
| 118 |
user_data->message = NULL; |
| 119 |
} |
| 120 |
|
| 121 |
aws_byte_buf_clean_up(&user_data->output_buf); |
| 122 |
|
| 123 |
aws_string_destroy(user_data->access_key_id); |
| 124 |
user_data->access_key_id = NULL; |
| 125 |
|
| 126 |
aws_string_destroy_secure(user_data->secret_access_key); |
| 127 |
user_data->secret_access_key = NULL; |
| 128 |
|
| 129 |
aws_string_destroy(user_data->session_token); |
| 130 |
user_data->session_token = NULL; |
| 131 |
|
| 132 |
aws_string_destroy(user_data->account_id); |
| 133 |
user_data->account_id = NULL; |
| 134 |
} |
| 135 |
static void s_clean_up_user_data(struct sts_creds_provider_user_data *user_data) { |
| 136 |
user_data->callback(user_data->credentials, user_data->error_code, user_data->user_data); |
| 137 |
|
| 138 |
aws_credentials_release(user_data->credentials); |
| 139 |
|
| 140 |
s_reset_request_specific_data(user_data); |
| 141 |
aws_credentials_provider_release(user_data->provider); |
| 142 |
|
| 143 |
aws_retry_token_release(user_data->retry_token); |
| 144 |
aws_mem_release(user_data->allocator, user_data); |
| 145 |
} |
| 146 |
|
| 147 |
static int s_write_body_to_buffer(struct aws_credentials_provider *provider, struct aws_byte_buf *body) { |
| 148 |
struct aws_credentials_provider_sts_impl *provider_impl = provider->impl; |
| 149 |
|
| 150 |
struct aws_byte_cursor working_cur = aws_byte_cursor_from_c_str("Version=2011-06-15&Action=AssumeRole&RoleArn="); |
| 151 |
if (aws_byte_buf_append_dynamic(body, &working_cur)) { |
| 152 |
return AWS_OP_ERR; |
| 153 |
} |
| 154 |
struct aws_byte_cursor role_cur = aws_byte_cursor_from_string(provider_impl->assume_role_profile); |
| 155 |
if (aws_byte_buf_append_encoding_uri_param(body, &role_cur)) { |
| 156 |
return AWS_OP_ERR; |
| 157 |
} |
| 158 |
working_cur = aws_byte_cursor_from_c_str("&RoleSessionName="); |
| 159 |
if (aws_byte_buf_append_dynamic(body, &working_cur)) { |
| 160 |
return AWS_OP_ERR; |
| 161 |
} |
| 162 |
|
| 163 |
struct aws_byte_cursor session_cur = aws_byte_cursor_from_string(provider_impl->role_session_name); |
| 164 |
if (aws_byte_buf_append_encoding_uri_param(body, &session_cur)) { |
| 165 |
return AWS_OP_ERR; |
| 166 |
} |
| 167 |
|
| 168 |
if (provider_impl->external_id != NULL) { |
| 169 |
working_cur = aws_byte_cursor_from_c_str("&ExternalId="); |
| 170 |
if (aws_byte_buf_append_dynamic(body, &working_cur)) { |
| 171 |
return AWS_OP_ERR; |
| 172 |
} |
| 173 |
|
| 174 |
struct aws_byte_cursor external_id_cur = aws_byte_cursor_from_string(provider_impl->external_id); |
| 175 |
if (aws_byte_buf_append_encoding_uri_param(body, &external_id_cur)) { |
| 176 |
return AWS_OP_ERR; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
working_cur = aws_byte_cursor_from_c_str("&DurationSeconds="); |
| 181 |
if (aws_byte_buf_append_dynamic(body, &working_cur)) { |
| 182 |
return AWS_OP_ERR; |
| 183 |
} |
| 184 |
|
| 185 |
char duration_seconds[6]; |
| 186 |
AWS_ZERO_ARRAY(duration_seconds); |
| 187 |
snprintf(duration_seconds, sizeof(duration_seconds), "%" PRIu16, provider_impl->duration_seconds); |
| 188 |
working_cur = aws_byte_cursor_from_c_str(duration_seconds); |
| 189 |
if (aws_byte_buf_append_dynamic(body, &working_cur)) { |
| 190 |
return AWS_OP_ERR; |
| 191 |
} |
| 192 |
|
| 193 |
return AWS_OP_SUCCESS; |
| 194 |
} |
| 195 |
|
| 196 |
static int s_on_incoming_body_fn(struct aws_http_stream *stream, const struct aws_byte_cursor *data, void *user_data) { |
| 197 |
(void)stream; |
| 198 |
|
| 199 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 200 |
return aws_byte_buf_append_dynamic(&provider_user_data->output_buf, data); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
static int s_sts_xml_on_root(struct aws_xml_node *node, void *user_data) { |
| 219 |
struct aws_byte_cursor node_name = aws_xml_node_get_name(node); |
| 220 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "AssumeRoleResponse")) { |
| 221 |
return aws_xml_node_traverse(node, s_sts_xml_on_AssumeRoleResponse_child, user_data); |
| 222 |
} |
| 223 |
return AWS_OP_SUCCESS; |
| 224 |
} |
| 225 |
|
| 226 |
static int s_sts_xml_on_AssumeRoleResponse_child(struct aws_xml_node *node, void *user_data) { |
| 227 |
struct aws_byte_cursor node_name = aws_xml_node_get_name(node); |
| 228 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "AssumeRoleResult")) { |
| 229 |
return aws_xml_node_traverse(node, s_sts_xml_on_AssumeRoleResult_child, user_data); |
| 230 |
} |
| 231 |
return AWS_OP_SUCCESS; |
| 232 |
} |
| 233 |
|
| 234 |
static int s_sts_xml_on_AssumeRoleResult_child(struct aws_xml_node *node, void *user_data) { |
| 235 |
struct aws_byte_cursor node_name = aws_xml_node_get_name(node); |
| 236 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "Credentials")) { |
| 237 |
return aws_xml_node_traverse(node, s_sts_xml_on_Credentials_child, user_data); |
| 238 |
} |
| 239 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "AssumedRoleUser")) { |
| 240 |
return aws_xml_node_traverse(node, s_sts_xml_on_AssumedRoleUser_child, user_data); |
| 241 |
} |
| 242 |
|
| 243 |
return AWS_OP_SUCCESS; |
| 244 |
} |
| 245 |
|
| 246 |
static int s_sts_xml_on_AssumedRoleUser_child(struct aws_xml_node *node, void *user_data) { |
| 247 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 248 |
struct aws_byte_cursor node_name = aws_xml_node_get_name(node); |
| 249 |
struct aws_byte_cursor arn_cursor; |
| 250 |
AWS_ZERO_STRUCT(arn_cursor); |
| 251 |
|
| 252 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "Arn")) { |
| 253 |
if (aws_xml_node_as_body(node, &arn_cursor)) { |
| 254 |
return AWS_OP_ERR; |
| 255 |
} |
| 256 |
struct aws_byte_cursor account_id = aws_parse_account_id_from_arn(arn_cursor); |
| 257 |
provider_user_data->account_id = aws_string_new_from_cursor(provider_user_data->allocator, &account_id); |
| 258 |
} |
| 259 |
|
| 260 |
return AWS_OP_SUCCESS; |
| 261 |
} |
| 262 |
|
| 263 |
static int s_sts_xml_on_Credentials_child(struct aws_xml_node *node, void *user_data) { |
| 264 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 265 |
struct aws_byte_cursor node_name = aws_xml_node_get_name(node); |
| 266 |
struct aws_byte_cursor credential_data; |
| 267 |
AWS_ZERO_STRUCT(credential_data); |
| 268 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "AccessKeyId")) { |
| 269 |
if (aws_xml_node_as_body(node, &credential_data)) { |
| 270 |
return AWS_OP_ERR; |
| 271 |
} |
| 272 |
provider_user_data->access_key_id = aws_string_new_from_cursor(provider_user_data->allocator, &credential_data); |
| 273 |
AWS_LOGF_DEBUG( |
| 274 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 275 |
"(id=%p): Read AccessKeyId %s", |
| 276 |
(void *)provider_user_data->provider, |
| 277 |
aws_string_c_str(provider_user_data->access_key_id)); |
| 278 |
} |
| 279 |
|
| 280 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "SecretAccessKey")) { |
| 281 |
if (aws_xml_node_as_body(node, &credential_data)) { |
| 282 |
return AWS_OP_ERR; |
| 283 |
} |
| 284 |
provider_user_data->secret_access_key = |
| 285 |
aws_string_new_from_cursor(provider_user_data->allocator, &credential_data); |
| 286 |
} |
| 287 |
|
| 288 |
if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "SessionToken")) { |
| 289 |
if (aws_xml_node_as_body(node, &credential_data)) { |
| 290 |
return AWS_OP_ERR; |
| 291 |
} |
| 292 |
provider_user_data->session_token = aws_string_new_from_cursor(provider_user_data->allocator, &credential_data); |
| 293 |
} |
| 294 |
|
| 295 |
return AWS_OP_SUCCESS; |
| 296 |
} |
| 297 |
|
| 298 |
static void s_start_make_request( |
| 299 |
struct aws_credentials_provider *provider, |
| 300 |
struct sts_creds_provider_user_data *provider_user_data); |
| 301 |
|
| 302 |
static void s_on_retry_ready(struct aws_retry_token *token, int error_code, void *user_data) { |
| 303 |
(void)token; |
| 304 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 305 |
|
| 306 |
if (!error_code) { |
| 307 |
s_start_make_request(provider_user_data->provider, provider_user_data); |
| 308 |
} else { |
| 309 |
AWS_LOGF_ERROR( |
| 310 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 311 |
"(id=%p): retry task failed: %s", |
| 312 |
(void *)provider_user_data->provider, |
| 313 |
aws_error_str(aws_last_error())); |
| 314 |
s_clean_up_user_data(provider_user_data); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
static void s_on_stream_complete_fn(struct aws_http_stream *stream, int error_code, void *user_data) { |
| 320 |
int http_response_code = 0; |
| 321 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 322 |
struct aws_credentials_provider_sts_impl *provider_impl = provider_user_data->provider->impl; |
| 323 |
|
| 324 |
provider_user_data->error_code = error_code; |
| 325 |
|
| 326 |
if (provider_impl->function_table->aws_http_stream_get_incoming_response_status(stream, &http_response_code)) { |
| 327 |
goto finish; |
| 328 |
} |
| 329 |
|
| 330 |
if (http_response_code != 200) { |
| 331 |
provider_user_data->error_code = AWS_AUTH_CREDENTIALS_PROVIDER_HTTP_STATUS_FAILURE; |
| 332 |
} |
| 333 |
|
| 334 |
provider_impl->function_table->aws_http_stream_release(stream); |
| 335 |
|
| 336 |
AWS_LOGF_DEBUG( |
| 337 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 338 |
"(id=%p): AssumeRole call completed with http status %d", |
| 339 |
(void *)provider_user_data->provider, |
| 340 |
http_response_code); |
| 341 |
|
| 342 |
if (error_code || http_response_code != AWS_HTTP_STATUS_CODE_200_OK) { |
| 343 |
|
| 344 |
provider_impl->function_table->aws_http_connection_close(provider_user_data->connection); |
| 345 |
|
| 346 |
enum aws_retry_error_type error_type = |
| 347 |
aws_credentials_provider_compute_retry_error_type(http_response_code, error_code); |
| 348 |
|
| 349 |
s_reset_request_specific_data(provider_user_data); |
| 350 |
|
| 351 |
|
| 352 |
if (error_type != AWS_RETRY_ERROR_TYPE_CLIENT_ERROR) { |
| 353 |
if (aws_retry_strategy_schedule_retry( |
| 354 |
provider_user_data->retry_token, error_type, s_on_retry_ready, provider_user_data)) { |
| 355 |
AWS_LOGF_ERROR( |
| 356 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 357 |
"(id=%p): failed to schedule retry: %s", |
| 358 |
(void *)provider_user_data->provider, |
| 359 |
aws_error_str(aws_last_error())); |
| 360 |
goto finish; |
| 361 |
} |
| 362 |
return; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
if (!error_code && http_response_code == AWS_HTTP_STATUS_CODE_200_OK) { |
| 367 |
|
| 368 |
|
| 369 |
if (aws_retry_token_record_success(provider_user_data->retry_token)) { |
| 370 |
AWS_LOGF_ERROR( |
| 371 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 372 |
"(id=%p): failed to register operation success: %s", |
| 373 |
(void *)provider_user_data->provider, |
| 374 |
aws_error_str(aws_last_error())); |
| 375 |
goto finish; |
| 376 |
} |
| 377 |
|
| 378 |
uint64_t now = UINT64_MAX; |
| 379 |
if (provider_impl->system_clock_fn(&now) != AWS_OP_SUCCESS) { |
| 380 |
goto finish; |
| 381 |
} |
| 382 |
|
| 383 |
uint64_t now_seconds = aws_timestamp_convert(now, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, NULL); |
| 384 |
|
| 385 |
struct aws_xml_parser_options options = { |
| 386 |
.doc = aws_byte_cursor_from_buf(&provider_user_data->output_buf), |
| 387 |
.on_root_encountered = s_sts_xml_on_root, |
| 388 |
.user_data = provider_user_data, |
| 389 |
}; |
| 390 |
if (aws_xml_parse(provider_user_data->provider->allocator, &options)) { |
| 391 |
provider_user_data->error_code = aws_last_error(); |
| 392 |
AWS_LOGF_ERROR( |
| 393 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 394 |
"(id=%p): credentials parsing failed with error %s", |
| 395 |
(void *)provider_user_data->credentials, |
| 396 |
aws_error_debug_str(provider_user_data->error_code)); |
| 397 |
|
| 398 |
provider_user_data->error_code = AWS_AUTH_CREDENTIALS_PROVIDER_STS_SOURCE_FAILURE; |
| 399 |
goto finish; |
| 400 |
} |
| 401 |
|
| 402 |
if (provider_user_data->access_key_id && provider_user_data->secret_access_key && |
| 403 |
provider_user_data->session_token) { |
| 404 |
struct aws_credentials_options creds_option = { |
| 405 |
.access_key_id_cursor = aws_byte_cursor_from_string(provider_user_data->access_key_id), |
| 406 |
.secret_access_key_cursor = aws_byte_cursor_from_string(provider_user_data->secret_access_key), |
| 407 |
.session_token_cursor = aws_byte_cursor_from_string(provider_user_data->session_token), |
| 408 |
.account_id_cursor = aws_byte_cursor_from_string(provider_user_data->account_id), |
| 409 |
.expiration_timepoint_seconds = now_seconds + provider_impl->duration_seconds, |
| 410 |
}; |
| 411 |
provider_user_data->credentials = |
| 412 |
aws_credentials_new_with_options(provider_user_data->allocator, &creds_option); |
| 413 |
} |
| 414 |
|
| 415 |
if (provider_user_data->credentials == NULL) { |
| 416 |
provider_user_data->error_code = AWS_AUTH_CREDENTIALS_PROVIDER_STS_SOURCE_FAILURE; |
| 417 |
AWS_LOGF_ERROR( |
| 418 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 419 |
"(id=%p): credentials document was corrupted, treating as an error.", |
| 420 |
(void *)provider_user_data->provider); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
finish: |
| 425 |
|
| 426 |
s_clean_up_user_data(provider_user_data); |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
static void s_on_connection_setup_fn(struct aws_http_connection *connection, int error_code, void *user_data) { |
| 431 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 432 |
struct aws_credentials_provider_sts_impl *provider_impl = provider_user_data->provider->impl; |
| 433 |
struct aws_http_stream *stream = NULL; |
| 434 |
|
| 435 |
AWS_LOGF_DEBUG( |
| 436 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 437 |
"(id=%p): connection returned with error code %d", |
| 438 |
(void *)provider_user_data->provider, |
| 439 |
error_code); |
| 440 |
|
| 441 |
if (error_code) { |
| 442 |
aws_raise_error(error_code); |
| 443 |
goto error; |
| 444 |
} |
| 445 |
provider_user_data->connection = connection; |
| 446 |
|
| 447 |
if (aws_byte_buf_init(&provider_user_data->output_buf, provider_impl->provider->allocator, 2048)) { |
| 448 |
goto error; |
| 449 |
} |
| 450 |
|
| 451 |
struct aws_http_make_request_options options = { |
| 452 |
.user_data = user_data, |
| 453 |
.request = provider_user_data->message, |
| 454 |
.self_size = sizeof(struct aws_http_make_request_options), |
| 455 |
.on_response_headers = NULL, |
| 456 |
.on_response_header_block_done = NULL, |
| 457 |
.on_response_body = s_on_incoming_body_fn, |
| 458 |
.on_complete = s_on_stream_complete_fn, |
| 459 |
}; |
| 460 |
|
| 461 |
stream = provider_impl->function_table->aws_http_connection_make_request(connection, &options); |
| 462 |
|
| 463 |
if (!stream) { |
| 464 |
goto error; |
| 465 |
} |
| 466 |
|
| 467 |
if (provider_impl->function_table->aws_http_stream_activate(stream)) { |
| 468 |
goto error; |
| 469 |
} |
| 470 |
|
| 471 |
return; |
| 472 |
error: |
| 473 |
provider_impl->function_table->aws_http_stream_release(stream); |
| 474 |
s_clean_up_user_data(provider_user_data); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
void s_on_signing_complete(struct aws_signing_result *result, int error_code, void *userdata) { |
| 479 |
struct sts_creds_provider_user_data *provider_user_data = userdata; |
| 480 |
struct aws_credentials_provider_sts_impl *sts_impl = provider_user_data->provider->impl; |
| 481 |
|
| 482 |
AWS_LOGF_DEBUG( |
| 483 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 484 |
"(id=%p): signing completed with error code %d", |
| 485 |
(void *)provider_user_data->provider, |
| 486 |
error_code); |
| 487 |
|
| 488 |
if (error_code) { |
| 489 |
provider_user_data->error_code = error_code; |
| 490 |
aws_raise_error(error_code); |
| 491 |
goto error; |
| 492 |
} |
| 493 |
|
| 494 |
if (aws_apply_signing_result_to_http_request( |
| 495 |
provider_user_data->message, provider_user_data->provider->allocator, result)) { |
| 496 |
goto error; |
| 497 |
} |
| 498 |
|
| 499 |
sts_impl->function_table->aws_http_connection_manager_acquire_connection( |
| 500 |
sts_impl->connection_manager, s_on_connection_setup_fn, provider_user_data); |
| 501 |
return; |
| 502 |
|
| 503 |
error: |
| 504 |
s_clean_up_user_data(provider_user_data); |
| 505 |
} |
| 506 |
|
| 507 |
static void s_start_make_request( |
| 508 |
struct aws_credentials_provider *provider, |
| 509 |
struct sts_creds_provider_user_data *provider_user_data) { |
| 510 |
provider_user_data->message = aws_http_message_new_request(provider->allocator); |
| 511 |
struct aws_credentials_provider_sts_impl *impl = provider->impl; |
| 512 |
|
| 513 |
if (!provider_user_data->message) { |
| 514 |
goto error; |
| 515 |
} |
| 516 |
struct aws_http_header host_header = { |
| 517 |
.name = aws_byte_cursor_from_c_str("Host"), |
| 518 |
.value = aws_byte_cursor_from_string(impl->endpoint), |
| 519 |
}; |
| 520 |
|
| 521 |
if (aws_http_message_add_header(provider_user_data->message, host_header)) { |
| 522 |
goto error; |
| 523 |
} |
| 524 |
|
| 525 |
if (aws_http_message_add_header(provider_user_data->message, s_content_type_header)) { |
| 526 |
goto error; |
| 527 |
} |
| 528 |
|
| 529 |
if (aws_byte_buf_init(&provider_user_data->payload_body, provider->allocator, 256)) { |
| 530 |
goto error; |
| 531 |
} |
| 532 |
|
| 533 |
if (s_write_body_to_buffer(provider, &provider_user_data->payload_body)) { |
| 534 |
goto error; |
| 535 |
} |
| 536 |
|
| 537 |
char content_length[21]; |
| 538 |
AWS_ZERO_ARRAY(content_length); |
| 539 |
snprintf(content_length, sizeof(content_length), "%" PRIu64, (uint64_t)provider_user_data->payload_body.len); |
| 540 |
|
| 541 |
struct aws_http_header content_len_header = { |
| 542 |
.name = s_content_length, |
| 543 |
.value = aws_byte_cursor_from_c_str(content_length), |
| 544 |
}; |
| 545 |
|
| 546 |
if (aws_http_message_add_header(provider_user_data->message, content_len_header)) { |
| 547 |
goto error; |
| 548 |
} |
| 549 |
|
| 550 |
struct aws_byte_cursor payload_cur = aws_byte_cursor_from_buf(&provider_user_data->payload_body); |
| 551 |
provider_user_data->input_stream = |
| 552 |
aws_input_stream_new_from_cursor(provider_user_data->provider->allocator, &payload_cur); |
| 553 |
|
| 554 |
if (!provider_user_data->input_stream) { |
| 555 |
goto error; |
| 556 |
} |
| 557 |
|
| 558 |
aws_http_message_set_body_stream(provider_user_data->message, provider_user_data->input_stream); |
| 559 |
|
| 560 |
if (aws_http_message_set_request_method(provider_user_data->message, aws_http_method_post)) { |
| 561 |
goto error; |
| 562 |
} |
| 563 |
|
| 564 |
if (aws_http_message_set_request_path(provider_user_data->message, s_path)) { |
| 565 |
goto error; |
| 566 |
} |
| 567 |
|
| 568 |
provider_user_data->signable = aws_signable_new_http_request(provider->allocator, provider_user_data->message); |
| 569 |
|
| 570 |
if (!provider_user_data->signable) { |
| 571 |
goto error; |
| 572 |
} |
| 573 |
|
| 574 |
provider_user_data->signing_config.algorithm = AWS_SIGNING_ALGORITHM_V4; |
| 575 |
provider_user_data->signing_config.signature_type = AWS_ST_HTTP_REQUEST_HEADERS; |
| 576 |
provider_user_data->signing_config.signed_body_header = AWS_SBHT_NONE; |
| 577 |
provider_user_data->signing_config.config_type = AWS_SIGNING_CONFIG_AWS; |
| 578 |
provider_user_data->signing_config.credentials_provider = impl->provider; |
| 579 |
uint64_t now = UINT64_MAX; |
| 580 |
if (impl->system_clock_fn(&now) != AWS_OP_SUCCESS) { |
| 581 |
goto error; |
| 582 |
} |
| 583 |
uint64_t now_millis = aws_timestamp_convert(now, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_MILLIS, NULL); |
| 584 |
aws_date_time_init_epoch_millis(&provider_user_data->signing_config.date, now_millis); |
| 585 |
provider_user_data->signing_config.region = aws_byte_cursor_from_string(impl->region); |
| 586 |
provider_user_data->signing_config.service = aws_byte_cursor_from_string(s_sts_service_name); |
| 587 |
provider_user_data->signing_config.flags.use_double_uri_encode = false; |
| 588 |
|
| 589 |
if (aws_sign_request_aws( |
| 590 |
provider->allocator, |
| 591 |
provider_user_data->signable, |
| 592 |
(struct aws_signing_config_base *)&provider_user_data->signing_config, |
| 593 |
s_on_signing_complete, |
| 594 |
provider_user_data)) { |
| 595 |
goto error; |
| 596 |
} |
| 597 |
|
| 598 |
return; |
| 599 |
|
| 600 |
error: |
| 601 |
AWS_LOGF_ERROR( |
| 602 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 603 |
"(id=%p): error occurred while creating an http request for signing: %s", |
| 604 |
(void *)provider_user_data->provider, |
| 605 |
aws_error_debug_str(aws_last_error())); |
| 606 |
if (provider_user_data) { |
| 607 |
s_clean_up_user_data(provider_user_data); |
| 608 |
} else { |
| 609 |
provider_user_data->callback(NULL, provider_user_data->error_code, provider_user_data->user_data); |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
static void s_on_retry_token_acquired( |
| 614 |
struct aws_retry_strategy *strategy, |
| 615 |
int error_code, |
| 616 |
struct aws_retry_token *token, |
| 617 |
void *user_data) { |
| 618 |
(void)strategy; |
| 619 |
struct sts_creds_provider_user_data *provider_user_data = user_data; |
| 620 |
|
| 621 |
if (!error_code) { |
| 622 |
provider_user_data->retry_token = token; |
| 623 |
s_start_make_request(provider_user_data->provider, provider_user_data); |
| 624 |
} else { |
| 625 |
AWS_LOGF_ERROR( |
| 626 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 627 |
"(id=%p): failed to acquire retry token: %s", |
| 628 |
(void *)provider_user_data->provider, |
| 629 |
aws_error_debug_str(error_code)); |
| 630 |
s_clean_up_user_data(provider_user_data); |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
static int s_sts_get_creds( |
| 635 |
struct aws_credentials_provider *provider, |
| 636 |
aws_on_get_credentials_callback_fn callback, |
| 637 |
void *user_data) { |
| 638 |
|
| 639 |
struct aws_credentials_provider_sts_impl *impl = provider->impl; |
| 640 |
|
| 641 |
AWS_LOGF_DEBUG(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "(id=%p): fetching credentials", (void *)provider); |
| 642 |
|
| 643 |
struct sts_creds_provider_user_data *provider_user_data = |
| 644 |
aws_mem_calloc(provider->allocator, 1, sizeof(struct sts_creds_provider_user_data)); |
| 645 |
|
| 646 |
if (!provider_user_data) { |
| 647 |
AWS_LOGF_ERROR( |
| 648 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 649 |
"(id=%p): error occurred while allocating memory: %s", |
| 650 |
(void *)provider, |
| 651 |
aws_error_debug_str(aws_last_error())); |
| 652 |
callback(NULL, aws_last_error(), user_data); |
| 653 |
return AWS_OP_ERR; |
| 654 |
} |
| 655 |
|
| 656 |
provider_user_data->allocator = provider->allocator; |
| 657 |
provider_user_data->provider = provider; |
| 658 |
aws_credentials_provider_acquire(provider); |
| 659 |
provider_user_data->callback = callback; |
| 660 |
provider_user_data->user_data = user_data; |
| 661 |
|
| 662 |
if (aws_retry_strategy_acquire_retry_token( |
| 663 |
impl->retry_strategy, NULL, s_on_retry_token_acquired, provider_user_data, 100)) { |
| 664 |
AWS_LOGF_ERROR( |
| 665 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 666 |
"(id=%p): failed to acquire retry token: %s", |
| 667 |
(void *)provider_user_data->provider, |
| 668 |
aws_error_debug_str(aws_last_error())); |
| 669 |
callback(NULL, aws_last_error(), user_data); |
| 670 |
s_clean_up_user_data(user_data); |
| 671 |
return AWS_OP_ERR; |
| 672 |
} |
| 673 |
|
| 674 |
return AWS_OP_SUCCESS; |
| 675 |
} |
| 676 |
|
| 677 |
static void s_on_credentials_provider_shutdown(void *user_data) { |
| 678 |
struct aws_credentials_provider *provider = user_data; |
| 679 |
if (provider == NULL) { |
| 680 |
return; |
| 681 |
} |
| 682 |
|
| 683 |
struct aws_credentials_provider_sts_impl *impl = provider->impl; |
| 684 |
if (impl == NULL) { |
| 685 |
return; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
if (impl->source_shutdown_options.shutdown_callback != NULL) { |
| 690 |
impl->source_shutdown_options.shutdown_callback(impl->source_shutdown_options.shutdown_user_data); |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
aws_credentials_provider_invoke_shutdown_callback(provider); |
| 695 |
|
| 696 |
aws_string_destroy(impl->role_session_name); |
| 697 |
aws_string_destroy(impl->assume_role_profile); |
| 698 |
aws_string_destroy(impl->external_id); |
| 699 |
aws_string_destroy(impl->endpoint); |
| 700 |
aws_string_destroy(impl->region); |
| 701 |
aws_mem_release(provider->allocator, provider); |
| 702 |
} |
| 703 |
|
| 704 |
void s_destroy(struct aws_credentials_provider *provider) { |
| 705 |
AWS_LOGF_TRACE(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "(id=%p): cleaning up credentials provider", (void *)provider); |
| 706 |
|
| 707 |
struct aws_credentials_provider_sts_impl *sts_impl = provider->impl; |
| 708 |
|
| 709 |
if (sts_impl->connection_manager) { |
| 710 |
sts_impl->function_table->aws_http_connection_manager_release(sts_impl->connection_manager); |
| 711 |
} |
| 712 |
|
| 713 |
aws_retry_strategy_release(sts_impl->retry_strategy); |
| 714 |
aws_credentials_provider_release(sts_impl->provider); |
| 715 |
} |
| 716 |
|
| 717 |
static struct aws_credentials_provider_vtable s_aws_credentials_provider_sts_vtable = { |
| 718 |
.get_credentials = s_sts_get_creds, |
| 719 |
.destroy = s_destroy, |
| 720 |
}; |
| 721 |
|
| 722 |
AWS_STATIC_STRING_FROM_LITERAL(s_region_config, "region"); |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
static struct aws_string *s_resolve_region(struct aws_allocator *allocator, const struct aws_profile *profile) { |
| 731 |
|
| 732 |
struct aws_string *region = aws_credentials_provider_resolve_region_from_env(allocator); |
| 733 |
if (region != NULL) { |
| 734 |
return region; |
| 735 |
} |
| 736 |
|
| 737 |
if (profile) { |
| 738 |
const struct aws_profile_property *property = aws_profile_get_property(profile, s_region_config); |
| 739 |
if (property) { |
| 740 |
region = aws_string_new_from_string(allocator, aws_profile_property_get_value(property)); |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
return region; |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
void s_resolve_endpoint( |
| 751 |
struct aws_allocator *allocator, |
| 752 |
const struct aws_credentials_provider_sts_options *options, |
| 753 |
struct aws_string **out_endpoint, |
| 754 |
struct aws_string **out_region) { |
| 755 |
|
| 756 |
struct aws_profile_collection *profile_collection = NULL; |
| 757 |
struct aws_string *profile_name = NULL; |
| 758 |
const struct aws_profile *profile = NULL; |
| 759 |
|
| 760 |
if (options->profile_collection_cached) { |
| 761 |
profile_collection = aws_profile_collection_acquire(options->profile_collection_cached); |
| 762 |
} else { |
| 763 |
profile_collection = |
| 764 |
aws_load_profile_collection_from_config_file(allocator, options->config_file_name_override); |
| 765 |
} |
| 766 |
if (profile_collection) { |
| 767 |
profile_name = aws_get_profile_name(allocator, &options->profile_name_override); |
| 768 |
if (profile_name) { |
| 769 |
profile = aws_profile_collection_get_profile(profile_collection, profile_name); |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
*out_region = s_resolve_region(allocator, profile); |
| 774 |
|
| 775 |
if (aws_credentials_provider_construct_endpoint( |
| 776 |
allocator, |
| 777 |
out_endpoint, |
| 778 |
*out_region, |
| 779 |
s_sts_service_name, |
| 780 |
s_sts_service_env_name, |
| 781 |
s_sts_service_name, |
| 782 |
profile_collection, |
| 783 |
profile, |
| 784 |
NULL, |
| 785 |
false)) { |
| 786 |
goto cleanup; |
| 787 |
} |
| 788 |
|
| 789 |
cleanup: |
| 790 |
aws_string_destroy(profile_name); |
| 791 |
aws_profile_collection_release(profile_collection); |
| 792 |
} |
| 793 |
|
| 794 |
struct aws_credentials_provider *aws_credentials_provider_new_sts( |
| 795 |
struct aws_allocator *allocator, |
| 796 |
const struct aws_credentials_provider_sts_options *options) { |
| 797 |
|
| 798 |
if (!options->bootstrap) { |
| 799 |
AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "a client bootstrap is necessary for querying STS"); |
| 800 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 801 |
return NULL; |
| 802 |
} |
| 803 |
|
| 804 |
if (!options->tls_ctx) { |
| 805 |
AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "a TLS context is necessary for querying STS"); |
| 806 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 807 |
return NULL; |
| 808 |
} |
| 809 |
|
| 810 |
if (options->role_arn.len == 0) { |
| 811 |
AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "role_arn is necessary for querying STS"); |
| 812 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 813 |
return NULL; |
| 814 |
} |
| 815 |
|
| 816 |
if (options->session_name.len == 0) { |
| 817 |
AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "role_session_name is necessary for querying STS"); |
| 818 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 819 |
return NULL; |
| 820 |
} |
| 821 |
|
| 822 |
struct aws_credentials_provider *provider = NULL; |
| 823 |
struct aws_credentials_provider_sts_impl *impl = NULL; |
| 824 |
int result = AWS_OP_ERR; |
| 825 |
struct aws_string *region = NULL; |
| 826 |
|
| 827 |
aws_mem_acquire_many( |
| 828 |
allocator, |
| 829 |
2, |
| 830 |
&provider, |
| 831 |
sizeof(struct aws_credentials_provider), |
| 832 |
&impl, |
| 833 |
sizeof(struct aws_credentials_provider_sts_impl)); |
| 834 |
|
| 835 |
AWS_LOGF_DEBUG(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "static: creating STS credentials provider"); |
| 836 |
if (!provider) { |
| 837 |
return NULL; |
| 838 |
} |
| 839 |
|
| 840 |
AWS_ZERO_STRUCT(*provider); |
| 841 |
AWS_ZERO_STRUCT(*impl); |
| 842 |
|
| 843 |
aws_credentials_provider_init_base(provider, allocator, &s_aws_credentials_provider_sts_vtable, impl); |
| 844 |
|
| 845 |
impl->function_table = g_aws_credentials_provider_http_function_table; |
| 846 |
|
| 847 |
if (options->function_table) { |
| 848 |
impl->function_table = options->function_table; |
| 849 |
} |
| 850 |
|
| 851 |
struct aws_tls_connection_options tls_connection_options; |
| 852 |
AWS_ZERO_STRUCT(tls_connection_options); |
| 853 |
|
| 854 |
if (!options->creds_provider) { |
| 855 |
AWS_LOGF_ERROR( |
| 856 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, "(id=%p): A credentials provider must be specified", (void *)provider); |
| 857 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 858 |
goto on_done; |
| 859 |
} |
| 860 |
|
| 861 |
impl->role_session_name = |
| 862 |
aws_string_new_from_array(allocator, options->session_name.ptr, options->session_name.len); |
| 863 |
AWS_LOGF_DEBUG( |
| 864 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 865 |
"(id=%p): using role_session_name '%s'", |
| 866 |
(void *)provider, |
| 867 |
aws_string_c_str(impl->role_session_name)); |
| 868 |
|
| 869 |
impl->assume_role_profile = aws_string_new_from_array(allocator, options->role_arn.ptr, options->role_arn.len); |
| 870 |
AWS_LOGF_DEBUG( |
| 871 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 872 |
"(id=%p): using role_arn '%s'", |
| 873 |
(void *)provider, |
| 874 |
aws_string_c_str(impl->assume_role_profile)); |
| 875 |
|
| 876 |
if (options->external_id.len > 0) { |
| 877 |
impl->external_id = aws_string_new_from_cursor(allocator, &options->external_id); |
| 878 |
AWS_LOGF_DEBUG( |
| 879 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 880 |
"(id=%p): using external_id '%s'", |
| 881 |
(void *)provider, |
| 882 |
aws_string_c_str(impl->external_id)); |
| 883 |
} |
| 884 |
|
| 885 |
impl->duration_seconds = options->duration_seconds; |
| 886 |
|
| 887 |
if (options->system_clock_fn != NULL) { |
| 888 |
impl->system_clock_fn = options->system_clock_fn; |
| 889 |
} else { |
| 890 |
impl->system_clock_fn = aws_sys_clock_get_ticks; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
if (impl->duration_seconds < aws_sts_assume_role_default_duration_secs) { |
| 895 |
impl->duration_seconds = aws_sts_assume_role_default_duration_secs; |
| 896 |
} |
| 897 |
|
| 898 |
AWS_LOGF_DEBUG( |
| 899 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 900 |
"(id=%p): using credentials duration %" PRIu16, |
| 901 |
(void *)provider, |
| 902 |
impl->duration_seconds); |
| 903 |
|
| 904 |
impl->provider = options->creds_provider; |
| 905 |
aws_credentials_provider_acquire(impl->provider); |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
s_resolve_endpoint(allocator, options, &impl->endpoint, &impl->region); |
| 912 |
if (!impl->endpoint) { |
| 913 |
|
| 914 |
if (impl->region) { |
| 915 |
aws_string_destroy(impl->region); |
| 916 |
} |
| 917 |
impl->endpoint = aws_string_new_from_c_str(allocator, "sts.amazonaws.com"); |
| 918 |
impl->region = aws_string_new_from_c_str(allocator, "us-east-1"); |
| 919 |
} else if (!impl->region) { |
| 920 |
AWS_LOGF_ERROR( |
| 921 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 922 |
"(id=%p): Region must be configured if the endpoint_override is configured. Please configure the region " |
| 923 |
"using the AWS_REGION environment variable or region property in the configuration file. %s", |
| 924 |
(void *)provider, |
| 925 |
aws_error_debug_str(aws_last_error())); |
| 926 |
goto on_done; |
| 927 |
} |
| 928 |
|
| 929 |
struct aws_byte_cursor endpoint_cursor = aws_byte_cursor_from_string(impl->endpoint); |
| 930 |
|
| 931 |
aws_tls_connection_options_init_from_ctx(&tls_connection_options, options->tls_ctx); |
| 932 |
|
| 933 |
if (aws_tls_connection_options_set_server_name(&tls_connection_options, allocator, &endpoint_cursor)) { |
| 934 |
AWS_LOGF_ERROR( |
| 935 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 936 |
"(id=%p): failed to create a tls connection options with error %s", |
| 937 |
(void *)provider, |
| 938 |
aws_error_debug_str(aws_last_error())); |
| 939 |
goto on_done; |
| 940 |
} |
| 941 |
|
| 942 |
struct aws_socket_options socket_options = { |
| 943 |
.type = AWS_SOCKET_STREAM, |
| 944 |
.domain = AWS_SOCKET_IPV6, |
| 945 |
.connect_timeout_ms = 3000, |
| 946 |
}; |
| 947 |
|
| 948 |
struct aws_http_connection_manager_options connection_manager_options = { |
| 949 |
.bootstrap = options->bootstrap, |
| 950 |
.host = endpoint_cursor, |
| 951 |
.initial_window_size = SIZE_MAX, |
| 952 |
.max_connections = 2, |
| 953 |
.port = 443, |
| 954 |
.socket_options = &socket_options, |
| 955 |
.tls_connection_options = &tls_connection_options, |
| 956 |
.proxy_options = options->http_proxy_options, |
| 957 |
.proxy_ev_settings = options->proxy_ev_settings, |
| 958 |
}; |
| 959 |
|
| 960 |
impl->connection_manager = |
| 961 |
impl->function_table->aws_http_connection_manager_new(allocator, &connection_manager_options); |
| 962 |
|
| 963 |
if (!impl->connection_manager) { |
| 964 |
AWS_LOGF_ERROR( |
| 965 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 966 |
"(id=%p): failed to create a connection manager with error %s", |
| 967 |
(void *)provider, |
| 968 |
aws_error_debug_str(aws_last_error())); |
| 969 |
goto on_done; |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
impl->source_shutdown_options = impl->provider->shutdown_options; |
| 976 |
impl->provider->shutdown_options.shutdown_callback = s_on_credentials_provider_shutdown; |
| 977 |
impl->provider->shutdown_options.shutdown_user_data = provider; |
| 978 |
|
| 979 |
provider->shutdown_options = options->shutdown_options; |
| 980 |
|
| 981 |
struct aws_standard_retry_options retry_options = { |
| 982 |
.backoff_retry_options = |
| 983 |
{ |
| 984 |
.el_group = options->bootstrap->event_loop_group, |
| 985 |
.max_retries = s_max_retries, |
| 986 |
}, |
| 987 |
}; |
| 988 |
|
| 989 |
impl->retry_strategy = aws_retry_strategy_new_standard(allocator, &retry_options); |
| 990 |
|
| 991 |
if (!impl->retry_strategy) { |
| 992 |
AWS_LOGF_ERROR( |
| 993 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 994 |
"(id=%p): failed to create a retry strategy with error %s", |
| 995 |
(void *)provider, |
| 996 |
aws_error_debug_str(aws_last_error())); |
| 997 |
goto on_done; |
| 998 |
} |
| 999 |
result = AWS_OP_SUCCESS; |
| 1000 |
|
| 1001 |
on_done: |
| 1002 |
aws_tls_connection_options_clean_up(&tls_connection_options); |
| 1003 |
aws_string_destroy(region); |
| 1004 |
if (result != AWS_OP_SUCCESS) { |
| 1005 |
provider = aws_credentials_provider_release(provider); |
| 1006 |
} |
| 1007 |
return provider; |
| 1008 |
} |