| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/auth/auth.h> |
| 6 |
|
| 7 |
#include <aws/auth/private/aws_signing.h> |
| 8 |
|
| 9 |
#include <aws/cal/cal.h> |
| 10 |
|
| 11 |
#include <aws/http/http.h> |
| 12 |
|
| 13 |
#include <aws/sdkutils/sdkutils.h> |
| 14 |
|
| 15 |
#include <aws/common/error.h> |
| 16 |
#include <aws/common/json.h> |
| 17 |
|
| 18 |
#define AWS_DEFINE_ERROR_INFO_AUTH(CODE, STR) AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-auth") |
| 19 |
|
| 20 |
|
| 21 |
static struct aws_error_info s_errors[] = { |
| 22 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 23 |
AWS_AUTH_SIGNING_UNSUPPORTED_ALGORITHM, |
| 24 |
"Attempt to sign an http request with an unsupported version of the AWS signing protocol"), |
| 25 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 26 |
AWS_AUTH_SIGNING_MISMATCHED_CONFIGURATION, |
| 27 |
"Attempt to sign an http request with a signing configuration unrecognized by the invoked signer"), |
| 28 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 29 |
AWS_AUTH_SIGNING_NO_CREDENTIALS, |
| 30 |
"Attempt to sign an http request without credentials"), |
| 31 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 32 |
AWS_AUTH_SIGNING_ILLEGAL_REQUEST_QUERY_PARAM, |
| 33 |
"Attempt to sign an http request that includes a query param that signing may add"), |
| 34 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 35 |
AWS_AUTH_SIGNING_ILLEGAL_REQUEST_HEADER, |
| 36 |
"Attempt to sign an http request that includes a header that signing may add"), |
| 37 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 38 |
AWS_AUTH_SIGNING_INVALID_CONFIGURATION, |
| 39 |
"Attempt to sign an http request with an invalid signing configuration"), |
| 40 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 41 |
AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_ENVIRONMENT, |
| 42 |
"Required environment variables could not be sourced from process environment"), |
| 43 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 44 |
AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_DELEGATE, |
| 45 |
"Valid credentials could not be sourced from the provided vtable"), |
| 46 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 47 |
AWS_AUTH_CREDENTIALS_PROVIDER_PROFILE_SOURCE_FAILURE, |
| 48 |
"Valid credentials could not be sourced by a profile provider"), |
| 49 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 50 |
AWS_AUTH_CREDENTIALS_PROVIDER_IMDS_SOURCE_FAILURE, |
| 51 |
"Valid credentials could not be sourced by the IMDS provider"), |
| 52 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 53 |
AWS_AUTH_CREDENTIALS_PROVIDER_STS_SOURCE_FAILURE, |
| 54 |
"Valid credentials could not be sourced by the STS provider"), |
| 55 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 56 |
AWS_AUTH_CREDENTIALS_PROVIDER_HTTP_STATUS_FAILURE, |
| 57 |
"Unsuccessful status code returned from credentials-fetching http request"), |
| 58 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 59 |
AWS_AUTH_PROVIDER_PARSER_UNEXPECTED_RESPONSE, |
| 60 |
"Invalid response document encountered while querying credentials via http"), |
| 61 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 62 |
AWS_AUTH_CREDENTIALS_PROVIDER_ECS_SOURCE_FAILURE, |
| 63 |
"Valid credentials could not be sourced by the ECS provider"), |
| 64 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 65 |
AWS_AUTH_CREDENTIALS_PROVIDER_X509_SOURCE_FAILURE, |
| 66 |
"Valid credentials could not be sourced by the X509 provider"), |
| 67 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 68 |
AWS_AUTH_CREDENTIALS_PROVIDER_PROCESS_SOURCE_FAILURE, |
| 69 |
"Valid credentials could not be sourced by the process provider"), |
| 70 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 71 |
AWS_AUTH_CREDENTIALS_PROVIDER_STS_WEB_IDENTITY_SOURCE_FAILURE, |
| 72 |
"Valid credentials could not be sourced by the sts web identity provider"), |
| 73 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 74 |
AWS_AUTH_SIGNING_UNSUPPORTED_SIGNATURE_TYPE, |
| 75 |
"Attempt to sign using an unusupported signature type"), |
| 76 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 77 |
AWS_AUTH_SIGNING_MISSING_PREVIOUS_SIGNATURE, |
| 78 |
"Attempt to sign a streaming item without supplying a previous signature"), |
| 79 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 80 |
AWS_AUTH_SIGNING_INVALID_CREDENTIALS, |
| 81 |
"Attempt to perform a signing operation with invalid credentials"), |
| 82 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 83 |
AWS_AUTH_CANONICAL_REQUEST_MISMATCH, |
| 84 |
"Expected canonical request did not match the computed canonical request"), |
| 85 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 86 |
AWS_AUTH_SIGV4A_SIGNATURE_VALIDATION_FAILURE, |
| 87 |
"The supplied sigv4a signature was not a valid signature for the hashed string to sign"), |
| 88 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 89 |
AWS_AUTH_CREDENTIALS_PROVIDER_COGNITO_SOURCE_FAILURE, |
| 90 |
"Valid credentials could not be sourced by the cognito provider"), |
| 91 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 92 |
AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE, |
| 93 |
"Valid credentials could not be sourced by the delegate provider"), |
| 94 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 95 |
AWS_AUTH_SSO_TOKEN_PROVIDER_SOURCE_FAILURE, |
| 96 |
"Valid token could not be sourced by the sso token provider"), |
| 97 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 98 |
AWS_AUTH_SSO_TOKEN_INVALID, |
| 99 |
"Token sourced by the sso token provider is invalid."), |
| 100 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 101 |
AWS_AUTH_SSO_TOKEN_EXPIRED, |
| 102 |
"Token sourced by the sso token provider is expired."), |
| 103 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 104 |
AWS_AUTH_CREDENTIALS_PROVIDER_SSO_SOURCE_FAILURE, |
| 105 |
"Valid credentials could not be sourced by the sso credentials provider"), |
| 106 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 107 |
AWS_AUTH_IMDS_CLIENT_SOURCE_FAILURE, |
| 108 |
"Failed to source the IMDS resource"), |
| 109 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 110 |
AWS_AUTH_PROFILE_STS_CREDENTIALS_PROVIDER_CYCLE_FAILURE, |
| 111 |
"Failed to resolve credentials because the profile contains a cycle in the assumeRole chain."), |
| 112 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 113 |
AWS_AUTH_CREDENTIALS_PROVIDER_ECS_INVALID_TOKEN_FILE_PATH, |
| 114 |
"Failed to read the ECS token file specified in the AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE environment variable."), |
| 115 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 116 |
AWS_AUTH_CREDENTIALS_PROVIDER_ECS_INVALID_HOST, |
| 117 |
"Failed to establish connection. The specified host is not allowed. It must be a loopback address, ECS/EKS container host, or use HTTPS."), |
| 118 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 119 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_SESSION_MISSING, |
| 120 |
"Credentials options are missing a required log in session"), |
| 121 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 122 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_REGION_MISSING, |
| 123 |
"Credentials options are missing a required region for log in call"), |
| 124 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 125 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_CREATE_TOKEN_PATH, |
| 126 |
"Login credentials providers was not able to calculate a path to the cached token on disk"), |
| 127 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 128 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_CREATE_TOKEN, |
| 129 |
"Failed to create a Login token from the cached token on disk"), |
| 130 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 131 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_TOKEN_EXPIRED, |
| 132 |
"The cached Login token is expired and we cannot complete a calll"), |
| 133 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 134 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_INVALID_PEM, |
| 135 |
"The PEM stored in the cached token file is not valid"), |
| 136 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 137 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_CREATE_REFRESH_TOKEN, |
| 138 |
"Failed to create a refresh token from the response returned for the AWS sign in service"), |
| 139 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 140 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_WRITE_TOKEN, |
| 141 |
"Failed to write back a updated Login token to disk"), |
| 142 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 143 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_CREATE_DPOP_HEADER, |
| 144 |
"Failed to create the needed dpop header for the AWS sign service in request"), |
| 145 |
AWS_DEFINE_ERROR_INFO_AUTH( |
| 146 |
AWS_AUTH_CREDENTIALS_PROVIDER_LOGIN_FAILED_TO_CREATE_REQUEST_BODY, |
| 147 |
"Failed to create the body for the AWS sign service in request") |
| 148 |
}; |
| 149 |
|
| 150 |
|
| 151 |
static struct aws_error_info_list s_error_list = { |
| 152 |
.error_list = s_errors, |
| 153 |
.count = sizeof(s_errors) / sizeof(struct aws_error_info), |
| 154 |
}; |
| 155 |
|
| 156 |
static struct aws_log_subject_info s_auth_log_subject_infos[] = { |
| 157 |
DEFINE_LOG_SUBJECT_INFO( |
| 158 |
AWS_LS_AUTH_GENERAL, |
| 159 |
"AuthGeneral", |
| 160 |
"Subject for aws-c-auth logging that defies categorization."), |
| 161 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_AUTH_PROFILE, "AuthProfile", "Subject for config profile related logging."), |
| 162 |
DEFINE_LOG_SUBJECT_INFO( |
| 163 |
AWS_LS_AUTH_CREDENTIALS_PROVIDER, |
| 164 |
"AuthCredentialsProvider", |
| 165 |
"Subject for credentials provider related logging."), |
| 166 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_AUTH_SIGNING, "AuthSigning", "Subject for AWS request signing logging."), |
| 167 |
}; |
| 168 |
|
| 169 |
static struct aws_log_subject_info_list s_auth_log_subject_list = { |
| 170 |
.subject_list = s_auth_log_subject_infos, |
| 171 |
.count = AWS_ARRAY_SIZE(s_auth_log_subject_infos), |
| 172 |
}; |
| 173 |
|
| 174 |
static bool s_library_initialized = false; |
| 175 |
static struct aws_allocator *s_library_allocator = NULL; |
| 176 |
|
| 177 |
void aws_auth_library_init(struct aws_allocator *allocator) { |
| 178 |
if (s_library_initialized) { |
| 179 |
return; |
| 180 |
} |
| 181 |
|
| 182 |
if (allocator) { |
| 183 |
s_library_allocator = allocator; |
| 184 |
} else { |
| 185 |
s_library_allocator = aws_default_allocator(); |
| 186 |
} |
| 187 |
|
| 188 |
aws_sdkutils_library_init(s_library_allocator); |
| 189 |
aws_cal_library_init(s_library_allocator); |
| 190 |
aws_http_library_init(s_library_allocator); |
| 191 |
|
| 192 |
aws_register_error_info(&s_error_list); |
| 193 |
aws_register_log_subject_info_list(&s_auth_log_subject_list); |
| 194 |
|
| 195 |
AWS_FATAL_ASSERT(aws_signing_init_signing_tables(allocator) == AWS_OP_SUCCESS); |
| 196 |
s_library_initialized = true; |
| 197 |
} |
| 198 |
|
| 199 |
void aws_auth_library_clean_up(void) { |
| 200 |
if (!s_library_initialized) { |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
s_library_initialized = false; |
| 205 |
|
| 206 |
aws_signing_clean_up_signing_tables(); |
| 207 |
aws_unregister_log_subject_info_list(&s_auth_log_subject_list); |
| 208 |
aws_unregister_error_info(&s_error_list); |
| 209 |
aws_http_library_clean_up(); |
| 210 |
aws_cal_library_clean_up(); |
| 211 |
aws_sdkutils_library_clean_up(); |
| 212 |
s_library_allocator = NULL; |
| 213 |
} |