Debian Codegraph @

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

raw symbols SCIP
1 #ifndef AWS_AUTH_SIGNER_H
2 #define AWS_AUTH_SIGNER_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
11 #include <aws/auth/signing_config.h>
12
13 AWS_PUSH_SANE_WARNING_LEVEL
14
15 struct aws_ecc_key_pair;
16 struct aws_signable;
17 struct aws_signing_result;
18
19 /**
20 * Gets called by the signing function when the signing is complete.
21 *
22 * Note that result will be destroyed after this function returns, so either copy it,
23 * or do all necessary adjustments inside the callback.
24 *
25 * When performing event or chunk signing, you will need to copy out the signature value in order
26 * to correctly configure the signable that wraps the event or chunk you want signed next. The signature is
27 * found in the "signature" property on the signing result. This value must be added as the
28 * "previous-signature" property on the next signable.
29 */
30 typedef void(aws_signing_complete_fn)(struct aws_signing_result *result, int error_code, void *userdata);
31
32 AWS_EXTERN_C_BEGIN
33
34 /*
35 * Takes a signable object and a configuration struct and computes the changes to the signable necessary
36 * for compliance with the signer's signing algorithm.
37 *
38 * This signing function currently supports only the sigv4 algorithm.
39 *
40 * When using this signing function to sign AWS http requests:
41 *
42 * (1) Do not add the following headers to requests before signing:
43 * x-amz-content-sha256,
44 * X-Amz-Date,
45 * Authorization
46 *
47 * (2) Do not add the following query params to requests before signing:
48 * X-Amz-Signature,
49 * X-Amz-Date,
50 * X-Amz-Credential,
51 * X-Amz-Algorithm,
52 * X-Amz-SignedHeaders
53 *
54 * The signing result will tell exactly what header and/or query params to add to the request
55 * to become a fully-signed AWS http request.
56 *
57 *
58 * When using this signing function to sign chunks:
59 *
60 * (1) Use aws_signable_new_chunk() to create the signable object representing the chunk
61 *
62 * The signing result will include the chunk's signature as the "signature" property.
63 *
64 *
65 */
66
67 /**
68 * (Asynchronous) entry point to sign something (a request, a chunk, an event) with an AWS signing process.
69 * Depending on the configuration, the signing process may or may not complete synchronously.
70 *
71 * @param allocator memory allocator to use throughout the signing process
72 * @param signable the thing to be signed. See signable.h for common constructors for signables that
73 * wrap different types.
74 * @param base_config pointer to a signing configuration, currently this must be of type aws_signing_config_aws
75 * @param on_complete completion callback to be invoked when signing has finished
76 * @param user_data opaque user data that will be passed to the completion callback
77 *
78 * @return AWS_OP_SUCCESS if the signing attempt was *initiated* successfully, AWS_OP_ERR otherwise
79 */
80 AWS_AUTH_API
81 int aws_sign_request_aws(
82 struct aws_allocator *allocator,
83 const struct aws_signable *signable,
84 const struct aws_signing_config_base *base_config,
85 aws_signing_complete_fn *on_complete,
86 void *userdata);
87
88 /**
89 * Test-only API used for cross-library signing verification tests
90 *
91 * Verifies:
92 * (1) The canonical request generated during sigv4a signing of the request matches what is passed in
93 * (2) The signature passed in is a valid ECDSA signature of the hashed string-to-sign derived from the
94 * canonical request
95 *
96 * @param allocator memory allocator to use throughout the signing verification process
97 * @param signable the thing to be signed. See signable.h for common constructors for signables that
98 * wrap different types.
99 * @param base_config pointer to a signing configuration, currently this must be of type aws_signing_config_aws
100 * @param expected_canonical_request_cursor expected result when building the canonical request
101 * @param signature_cursor the actual signature computed from a previous signing of the signable
102 * @param ecc_key_pub_x the x coordinate of the public part of the ecc key to verify the signature
103 * @param ecc_key_pub_y the y coordinate of the public part of the ecc key to verify the signature
104 *
105 * @return AWS_OP_SUCCESS if the signing attempt was *initiated* successfully, AWS_OP_ERR otherwise
106 */
107 AWS_AUTH_API
108 int aws_verify_sigv4a_signing(
109 struct aws_allocator *allocator,
110 const struct aws_signable *signable,
111 const struct aws_signing_config_base *base_config,
112 struct aws_byte_cursor expected_canonical_request_cursor,
113 struct aws_byte_cursor signature_cursor,
114 struct aws_byte_cursor ecc_key_pub_x,
115 struct aws_byte_cursor ecc_key_pub_y);
116
117 /**
118 * Another helper function to check a computed sigv4a signature.
119 */
120 AWS_AUTH_API
121 int aws_validate_v4a_authorization_value(
122 struct aws_allocator *allocator,
123 struct aws_ecc_key_pair *ecc_key,
124 struct aws_byte_cursor string_to_sign_cursor,
125 struct aws_byte_cursor signature_value_cursor);
126
127 /**
128 * Removes any padding added to the end of a sigv4a signature. Signature must be hex-encoded.
129 * @param signature signature to remove padding from
130 * @return cursor that ranges over only the valid hex encoding of the sigv4a signature
131 */
132 AWS_AUTH_API
133 struct aws_byte_cursor aws_trim_padded_sigv4a_signature(struct aws_byte_cursor signature);
134
135 AWS_EXTERN_C_END
136 AWS_POP_SANE_WARNING_LEVEL
137
138 #endif /* AWS_AUTH_SIGNER_H */