Debian Codegraph @

crt/aws-c-auth/source/signing_config.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/auth/signing_config.h>
7
8 #include <aws/auth/credentials.h>
9
10 const struct aws_byte_cursor g_aws_signed_body_value_empty_sha256 =
11 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
12
13 const struct aws_byte_cursor g_aws_signed_body_value_unsigned_payload =
14 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("UNSIGNED-PAYLOAD");
15
16 const struct aws_byte_cursor g_aws_signed_body_value_streaming_unsigned_payload_trailer =
17 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-UNSIGNED-PAYLOAD-TRAILER");
18
19 const struct aws_byte_cursor g_aws_signed_body_value_streaming_aws4_hmac_sha256_payload =
20 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-AWS4-HMAC-SHA256-PAYLOAD");
21
22 const struct aws_byte_cursor g_aws_signed_body_value_streaming_aws4_hmac_sha256_payload_trailer =
23 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-AWS4-HMAC-SHA256-PAYLOAD-TRAILER");
24
25 const struct aws_byte_cursor g_aws_signed_body_value_streaming_aws4_ecdsa_p256_sha256_payload =
26 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-AWS4-ECDSA-P256-SHA256-PAYLOAD");
27
28 const struct aws_byte_cursor g_aws_signed_body_value_streaming_aws4_ecdsa_p256_sha256_payload_trailer =
29 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-AWS4-ECDSA-P256-SHA256-PAYLOAD-TRAILER");
30
31 const struct aws_byte_cursor g_aws_signed_body_value_streaming_aws4_hmac_sha256_events =
32 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("STREAMING-AWS4-HMAC-SHA256-EVENTS");
33
34 const char *aws_signing_algorithm_to_string(enum aws_signing_algorithm algorithm) {
35 switch (algorithm) {
36 case AWS_SIGNING_ALGORITHM_V4:
37 return "SigV4";
38
39 case AWS_SIGNING_ALGORITHM_V4_S3EXPRESS:
40 return "SigV4S3Express";
41
42 case AWS_SIGNING_ALGORITHM_V4_ASYMMETRIC:
43 return "SigV4Asymmetric";
44
45 default:
46 break;
47 }
48
49 return "Unknown";
50 }
51
52 int aws_validate_aws_signing_config_aws(const struct aws_signing_config_aws *config) {
53 if (config == NULL) {
54 AWS_LOGF_ERROR(AWS_LS_AUTH_SIGNING, "AWS signing config is null");
55 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
56 }
57
58 if (config->signature_type == AWS_ST_HTTP_REQUEST_EVENT && config->algorithm != AWS_SIGNING_ALGORITHM_V4) {
59 /*
60 * Not supported yet.
61 *
62 * Need to determine if the Transcribe service supports Sigv4a and how to test it.
63 * Transcribe's examples are insufficient.
64 */
65 AWS_LOGF_ERROR(AWS_LS_AUTH_SIGNING, "(id=%p) Event signing is only supported for Sigv4 yet", (void *)config);
66 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
67 }
68
69 if (config->signature_type != AWS_ST_HTTP_REQUEST_HEADERS &&
70 config->signature_type != AWS_ST_HTTP_REQUEST_QUERY_PARAMS) {
71 /*
72 * If we're not signing the full request then it's critical that the credentials we're using are the same
73 * credentials used on the original request. If we're using a provider to fetch credentials then that is
74 * not guaranteed. For now, force users to always pass in credentials when signing events or chunks.
75 *
76 * The correct long-term solution would be to add a way to pass the credentials used in the initial
77 * signing back to the user in the completion callback. Then the user could supply those credentials
78 * to all subsequent chunk/event signings. The fact that we don't do that yet doesn't invalidate this check.
79 */
80 if (config->credentials == NULL) {
81 AWS_LOGF_ERROR(
82 AWS_LS_AUTH_SIGNING,
83 "(id=%p) Chunk/event signing config must contain explicit credentials",
84 (void *)config);
85 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
86 }
87 }
88
89 if (config->region.len == 0) {
90 AWS_LOGF_ERROR(AWS_LS_AUTH_SIGNING, "(id=%p) Signing config is missing a region identifier", (void *)config);
91 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
92 }
93
94 if (config->service.len == 0) {
95 AWS_LOGF_ERROR(AWS_LS_AUTH_SIGNING, "(id=%p) Signing config is missing a service identifier", (void *)config);
96 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
97 }
98
99 switch (config->algorithm) {
100 case AWS_SIGNING_ALGORITHM_V4:
101 if (config->credentials == NULL && config->credentials_provider == NULL) {
102 AWS_LOGF_ERROR(
103 AWS_LS_AUTH_SIGNING,
104 "(id=%p) Sigv4 signing config is missing a credentials provider or credentials",
105 (void *)config);
106 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
107 }
108
109 if (config->credentials != NULL && !aws_credentials_is_anonymous(config->credentials)) {
110 if (aws_credentials_get_access_key_id(config->credentials).len == 0 ||
111 aws_credentials_get_secret_access_key(config->credentials).len == 0) {
112 AWS_LOGF_ERROR(
113 AWS_LS_AUTH_SIGNING,
114 "(id=%p) Sigv4 signing configured with invalid credentials",
115 (void *)config);
116 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CREDENTIALS);
117 }
118 }
119 break;
120 case AWS_SIGNING_ALGORITHM_V4_S3EXPRESS:
121 if (config->credentials == NULL && config->credentials_provider == NULL) {
122 AWS_LOGF_ERROR(
123 AWS_LS_AUTH_SIGNING,
124 "(id=%p) Sigv4 S3 Express signing config is missing a credentials provider or credentials",
125 (void *)config);
126 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
127 }
128
129 if (config->credentials != NULL) {
130 if (aws_credentials_is_anonymous(config->credentials) ||
131 aws_credentials_get_access_key_id(config->credentials).len == 0 ||
132 aws_credentials_get_secret_access_key(config->credentials).len == 0 ||
133 aws_credentials_get_session_token(config->credentials).len == 0) {
134 AWS_LOGF_ERROR(
135 AWS_LS_AUTH_SIGNING,
136 "(id=%p) Sigv4 S3 Express signing configured with invalid credentials",
137 (void *)config);
138 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CREDENTIALS);
139 }
140 }
141 break;
142
143 case AWS_SIGNING_ALGORITHM_V4_ASYMMETRIC:
144 if (config->credentials == NULL && config->credentials_provider == NULL) {
145 AWS_LOGF_ERROR(
146 AWS_LS_AUTH_SIGNING,
147 "(id=%p) Sigv4 asymmetric signing config is missing a credentials provider or credentials",
148 (void *)config);
149 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
150 }
151 break;
152
153 default:
154 return aws_raise_error(AWS_AUTH_SIGNING_INVALID_CONFIGURATION);
155 }
156
157 return AWS_OP_SUCCESS;
158 }