Debian Codegraph @

crt/aws-c-auth/include/aws/auth/signable.h

raw symbols SCIP
1 #ifndef AWS_AUTH_SIGNABLE_H
2 #define AWS_AUTH_SIGNABLE_H
3
4 #include <aws/auth/auth.h>
5
6 AWS_PUSH_SANE_WARNING_LEVEL
7
8 struct aws_http_message;
9 struct aws_http_headers;
10 struct aws_input_stream;
11 struct aws_signable;
12 struct aws_string;
13
14 /*
15 * While not referenced directly in this file, this is the structure expected to be in the property lists
16 */
17 struct aws_signable_property_list_pair {
18 struct aws_byte_cursor name;
19 struct aws_byte_cursor value;
20 };
21
22 typedef int(aws_signable_get_property_fn)(
23 const struct aws_signable *signable,
24 const struct aws_string *name,
25 struct aws_byte_cursor *out_value);
26
27 typedef int(aws_signable_get_property_list_fn)(
28 const struct aws_signable *signable,
29 const struct aws_string *name,
30 struct aws_array_list **out_list);
31
32 typedef int(aws_signable_get_payload_stream_fn)(
33 const struct aws_signable *signable,
34 struct aws_input_stream **out_input_stream);
35
36 typedef void(aws_signable_destroy_fn)(struct aws_signable *signable);
37
38 struct aws_signable_vtable {
39 aws_signable_get_property_fn *get_property;
40 aws_signable_get_property_list_fn *get_property_list;
41 aws_signable_get_payload_stream_fn *get_payload_stream;
42 aws_signable_destroy_fn *destroy;
43 };
44
45 /**
46 * Signable is a generic interface for any kind of object that can be cryptographically signed.
47 *
48 * Like signing_result, the signable interface presents
49 *
50 * (1) Properties - A set of key-value pairs
51 * (2) Property Lists - A set of named key-value pair lists
52 *
53 * as well as
54 *
55 * (3) A message payload modeled as a stream
56 *
57 * When creating a signable "subclass" the query interface should map to retrieving
58 * the properties of the underlying object needed by signing algorithms that can operate on it.
59 *
60 * As an example, if a signable implementation wrapped an http request, you would query
61 * request elements like method and uri from the property interface, headers would be queried
62 * via the property list interface, and the request body would map to the payload stream.
63 *
64 * String constants that map to agreed on keys for particular signable types
65 * ("METHOD", "URI", "HEADERS", etc...) are exposed in appropriate header files.
66 */
67 struct aws_signable {
68 struct aws_allocator *allocator;
69 void *impl;
70 struct aws_signable_vtable *vtable;
71 };
72
73 AWS_EXTERN_C_BEGIN
74
75 /**
76 * Cleans up and frees all resources associated with a signable instance
77 *
78 * @param signable signable object to destroy
79 */
80 AWS_AUTH_API
81 void aws_signable_destroy(struct aws_signable *signable);
82
83 /**
84 * Retrieves a property (key-value pair) from a signable. Global property name constants are
85 * included below.
86 *
87 * @param signable signable object to retrieve a property from
88 * @param name name of the property to query
89 * @param out_value output parameter for the property's value
90 *
91 * @return AWS_OP_SUCCESS if the property was successfully fetched, AWS_OP_ERR otherwise
92 */
93 AWS_AUTH_API
94 int aws_signable_get_property(
95 const struct aws_signable *signable,
96 const struct aws_string *name,
97 struct aws_byte_cursor *out_value);
98
99 /**
100 * Retrieves a named property list (list of key-value pairs) from a signable. Global property list name
101 * constants are included below.
102 *
103 * @param signable signable object to retrieve a property list from
104 * @param name name of the property list to fetch
105 * @param out_property_list output parameter for the fetched property list
106 *
107 * @return AWS_OP_SUCCESS if the property list was successfully fetched, AWS_OP_ERR otherwise
108 */
109 AWS_AUTH_API
110 int aws_signable_get_property_list(
111 const struct aws_signable *signable,
112 const struct aws_string *name,
113 struct aws_array_list **out_property_list);
114
115 /**
116 * Retrieves the signable's message payload as a stream.
117 *
118 * @param signable signable to get the payload of
119 * @param out_input_stream output parameter for the payload stream
120 *
121 * @return AWS_OP_SUCCESS if successful, AWS_OP_ERR otherwise
122 */
123 AWS_AUTH_API
124 int aws_signable_get_payload_stream(const struct aws_signable *signable, struct aws_input_stream **out_input_stream);
125
126 /*
127 * Some global property and property-list name constants
128 */
129
130 /**
131 * Name of the property list that wraps the headers of an http request
132 */
133 AWS_AUTH_API extern const struct aws_string *g_aws_http_headers_property_list_name;
134
135 /**
136 * Name of the property list that wraps the query params of an http request. Only used by signing_result.
137 * For input to a http signing algorithm, query params are assumed to be part of the uri.
138 */
139 AWS_AUTH_API extern const struct aws_string *g_aws_http_query_params_property_list_name;
140
141 /**
142 * Name of the property that holds the method of an http request
143 */
144 AWS_AUTH_API extern const struct aws_string *g_aws_http_method_property_name;
145
146 /**
147 * Name of the property that holds the URI of an http request
148 */
149 AWS_AUTH_API extern const struct aws_string *g_aws_http_uri_property_name;
150
151 /**
152 * Name of the property that holds the signature value. This is always added to signing results.
153 * Depending on the requested signature type, the signature may be padded or encoded differently:
154 * (1) Header - hex encoding of the binary signature value
155 * (2) QueryParam - hex encoding of the binary signature value
156 * (3) Chunk/Sigv4 - hex encoding of the binary signature value
157 * (4) Chunk/Sigv4a - fixed-size-rhs-padded (with AWS_SIGV4A_SIGNATURE_PADDING_BYTE) hex encoding of the
158 * binary signature value
159 * (5) Event - binary signature value (NYI)
160 */
161 AWS_AUTH_API extern const struct aws_string *g_aws_signature_property_name;
162
163 /**
164 * Name of the property that holds the (hex-encoded) signature value of the signing event that preceded this one.
165 * This property must appear on signables that represent chunks or events.
166 */
167 AWS_AUTH_API extern const struct aws_string *g_aws_previous_signature_property_name;
168
169 /**
170 * Name of the property that holds the canonical request associated with this signable.
171 * This property must appear on signables that represent an http request's canonical request.
172 */
173 AWS_AUTH_API extern const struct aws_string *g_aws_canonical_request_property_name;
174
175 /*
176 * Common signable constructors
177 */
178
179 /**
180 * Creates a signable wrapper around an http request.
181 *
182 * @param allocator memory allocator to use to create the signable
183 * @param request http request to create a signable for
184 *
185 * @return the new signable object, or NULL if failure
186 */
187 AWS_AUTH_API
188 struct aws_signable *aws_signable_new_http_request(struct aws_allocator *allocator, struct aws_http_message *request);
189
190 /**
191 * Creates a signable that represents a unit of chunked encoding within an http request.
192 * This can also be used for Transcribe event signing with encoded payload as chunk_data.
193 *
194 * @param allocator memory allocator use to create the signable
195 * @param chunk_data stream representing the data in the chunk; it should be in its final, encoded form
196 * @param previous_signature the signature computed in the most recent signing that preceded this one. It can be
197 * found by copying the "signature" property from the signing_result of that most recent signing.
198 *
199 * @return the new signable object, or NULL if failure
200 */
201 AWS_AUTH_API
202 struct aws_signable *aws_signable_new_chunk(
203 struct aws_allocator *allocator,
204 struct aws_input_stream *chunk_data,
205 struct aws_byte_cursor previous_signature);
206
207 /**
208 * Creates a signable wrapper around a set of headers.
209 *
210 * @param allocator memory allocator use to create the signable
211 * @param trailing_headers http headers to create a signable for
212 * @param previous_signature the signature computed in the most recent signing that preceded this one. It can be
213 * found by copying the "signature" property from the signing_result of that most recent signing.
214 *
215 * @return the new signable object, or NULL if failure
216 */
217 AWS_AUTH_API
218 struct aws_signable *aws_signable_new_trailing_headers(
219 struct aws_allocator *allocator,
220 struct aws_http_headers *trailing_headers,
221 struct aws_byte_cursor previous_signature);
222
223 /**
224 * Creates a signable that represents a pre-computed canonical request from an http request
225 * @param allocator memory allocator use to create the signable
226 * @param canonical_request text of the canonical request
227 * @return the new signable object, or NULL if failure
228 */
229 AWS_AUTH_API
230 struct aws_signable *aws_signable_new_canonical_request(
231 struct aws_allocator *allocator,
232 struct aws_byte_cursor canonical_request);
233
234 AWS_EXTERN_C_END
235 AWS_POP_SANE_WARNING_LEVEL
236
237 #endif /* AWS_AUTH_SIGNABLE_H */