Debian Codegraph @

crt/aws-c-auth/include/aws/auth/private/aws_signing.h

raw symbols SCIP
1 #ifndef AWS_AUTH_SIGNING_SIGV4_H
2 #define AWS_AUTH_SIGNING_SIGV4_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/auth/auth.h>
10 #include <aws/auth/signing.h>
11 #include <aws/auth/signing_result.h>
12
13 #include <aws/common/byte_buf.h>
14 #include <aws/common/hash_table.h>
15
16 struct aws_ecc_key_pair;
17 struct aws_signable;
18 struct aws_signing_config_aws;
19 struct aws_signing_result;
20
21 /*
22 * Private signing API
23 *
24 * Technically this could be folded directly into signing.c but it's useful to be able
25 * to call the individual stages of the signing process for testing.
26 */
27
28 /*
29 * A structure that contains all the state related to signing a request for AWS. We pass
30 * this around rather than a million parameters.
31 */
32 struct aws_signing_state_aws {
33 struct aws_allocator *allocator;
34
35 const struct aws_signable *signable;
36 aws_signing_complete_fn *on_complete;
37 void *userdata;
38
39 struct aws_signing_config_aws config;
40 struct aws_byte_buf config_string_buffer;
41
42 struct aws_signing_result result;
43 int error_code;
44
45 /* persistent, constructed values that are either/or
46 * (1) consumed by later stages of the signing process,
47 * (2) used in multiple places
48 */
49 struct aws_byte_buf canonical_request;
50 struct aws_byte_buf string_to_sign;
51 struct aws_byte_buf signed_headers;
52 struct aws_byte_buf canonical_header_block;
53 struct aws_byte_buf payload_hash;
54 struct aws_byte_buf credential_scope;
55 struct aws_byte_buf access_credential_scope;
56 struct aws_byte_buf date;
57 struct aws_byte_buf signature;
58 /* The "payload" to be used in the string-to-sign.
59 * For a normal HTTP request, this is the hashed canonical-request.
60 * But for other types of signing (i.e chunk, event) it's something else. */
61 struct aws_byte_buf string_to_sign_payload;
62
63 /* temp buf for writing out strings */
64 struct aws_byte_buf scratch_buf;
65
66 char expiration_array[32]; /* serialization of the pre-signing expiration duration value */
67 };
68
69 AWS_EXTERN_C_BEGIN
70
71 AWS_AUTH_API
72 struct aws_signing_state_aws *aws_signing_state_new(
73 struct aws_allocator *allocator,
74 const struct aws_signing_config_aws *config,
75 const struct aws_signable *signable,
76 aws_signing_complete_fn *on_complete,
77 void *userdata);
78
79 AWS_AUTH_API
80 void aws_signing_state_destroy(struct aws_signing_state_aws *state);
81
82 /*
83 * A set of functions that together performs the AWS signing process based
84 * on the algorithm and signature type requested in the shared config.
85 *
86 * These must be called (presumably by the signer) in sequential order:
87 *
88 * (1) aws_signing_build_canonical_request
89 * (2) aws_signing_build_string_to_sign
90 * (3) aws_signing_build_authorization_value
91 */
92
93 AWS_AUTH_API
94 int aws_signing_build_canonical_request(struct aws_signing_state_aws *state);
95
96 AWS_AUTH_API
97 int aws_signing_build_string_to_sign(struct aws_signing_state_aws *state);
98
99 AWS_AUTH_API
100 int aws_signing_build_authorization_value(struct aws_signing_state_aws *state);
101
102 /*
103 * Named constants particular to the sigv4 signing algorithm. Can be moved to a public header
104 * as needed.
105 */
106 AWS_AUTH_API extern const struct aws_string *g_aws_signing_content_header_name;
107 AWS_AUTH_API extern const struct aws_string *g_aws_signing_algorithm_query_param_name;
108 AWS_AUTH_API extern const struct aws_string *g_aws_signing_credential_query_param_name;
109 AWS_AUTH_API extern const struct aws_string *g_aws_signing_date_name;
110 AWS_AUTH_API extern const struct aws_string *g_aws_signing_signed_headers_query_param_name;
111 AWS_AUTH_API extern const struct aws_string *g_aws_signing_security_token_name;
112 AWS_AUTH_API extern const struct aws_string *g_aws_signing_s3session_token_name;
113 AWS_AUTH_API extern const struct aws_string *g_signature_type_sigv4a_http_request;
114
115 /**
116 * Initializes the internal table of headers that should not be signed
117 */
118 AWS_AUTH_API
119 int aws_signing_init_signing_tables(struct aws_allocator *allocator);
120
121 /**
122 * Cleans up the internal table of headers that should not be signed
123 */
124 AWS_AUTH_API
125 void aws_signing_clean_up_signing_tables(void);
126
127 AWS_EXTERN_C_END
128
129 #endif /* AWS_AUTH_SIGNING_SIGV4_H */