SigV4 v1.2.0
SigV4 Library for AWS Authentication
sigv4_internal.h
Go to the documentation of this file.
1/*
2 * SigV4 Library v1.2.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
30#ifndef SIGV4_INTERNAL_H_
31#define SIGV4_INTERNAL_H_
32
33/* *INDENT-OFF* */
34#ifdef __cplusplus
35 extern "C" {
36#endif
37/* *INDENT-ON* */
38
39/* SIGV4_DO_NOT_USE_CUSTOM_CONFIG allows building of the SigV4 library without a
40 * config file. If a config file is provided, the SIGV4_DO_NOT_USE_CUSTOM_CONFIG
41 * macro must not be defined.
42 */
43#ifndef SIGV4_DO_NOT_USE_CUSTOM_CONFIG
44 #include "sigv4_config.h"
45#endif
46
47/* Include config defaults header to get default values of configurations not
48 * defined in sigv4_config.h file. */
50
51/* Constants for date verification. */
52#define YEAR_MIN 1900L
53#define MONTH_ASCII_LEN 3U
58#define MONTH_NAMES { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
59
63#define MONTH_DAYS { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
64
65#define FORMAT_RFC_3339 "%4Y-%2M-%2DT%2h:%2m:%2sZ"
66#define FORMAT_RFC_3339_LEN sizeof( FORMAT_RFC_3339 ) - 1U
68#define FORMAT_RFC_5322 "%3*, %2D %3M %4Y %2h:%2m:%2s GMT"
69#define FORMAT_RFC_5322_LEN sizeof( FORMAT_RFC_5322 ) - 1U
71#define ISO_YEAR_LEN 4U
72#define ISO_NON_YEAR_LEN 2U
74#define ISO_DATE_SCOPE_LEN 8U
76/* SigV4 related string literals and lengths. */
77
81#define CREDENTIAL_SCOPE_SEPARATOR '/'
82#define CREDENTIAL_SCOPE_SEPARATOR_LEN 1U
87#define CREDENTIAL_SCOPE_TERMINATOR "aws4_request"
88#define CREDENTIAL_SCOPE_TERMINATOR_LEN ( sizeof( CREDENTIAL_SCOPE_TERMINATOR ) - 1U )
93#define HTTP_EMPTY_PATH "/"
94#define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U )
96#define URI_ENCODED_SPECIAL_CHAR_SIZE 3U
97#define URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE 5U
99#define LINEFEED_CHAR '\n'
100#define LINEFEED_CHAR_LEN 1U
102#define HTTP_REQUEST_LINE_ENDING "\r\n"
103#define HTTP_REQUEST_LINE_ENDING_LEN ( sizeof( HTTP_REQUEST_LINE_ENDING ) - 1U )
105#define SPACE_CHAR ' '
106#define SPACE_CHAR_LEN 1U
108#define S3_SERVICE_NAME "s3"
109#define S3_SERVICE_NAME_LEN ( sizeof( S3_SERVICE_NAME ) - 1U )
111#define SIGV4_HMAC_SIGNING_KEY_PREFIX "AWS4"
112#define SIGV4_HMAC_SIGNING_KEY_PREFIX_LEN ( sizeof( SIGV4_HMAC_SIGNING_KEY_PREFIX ) - 1U )
114#define AUTH_CREDENTIAL_PREFIX "Credential="
115#define AUTH_CREDENTIAL_PREFIX_LEN ( sizeof( AUTH_CREDENTIAL_PREFIX ) - 1U )
116#define AUTH_SEPARATOR ", "
117#define AUTH_SEPARATOR_LEN ( sizeof( AUTH_SEPARATOR ) - 1U )
118#define AUTH_SIGNED_HEADERS_PREFIX "SignedHeaders="
119#define AUTH_SIGNED_HEADERS_PREFIX_LEN ( sizeof( AUTH_SIGNED_HEADERS_PREFIX ) - 1U )
120#define AUTH_SIGNATURE_PREFIX "Signature="
121#define AUTH_SIGNATURE_PREFIX_LEN ( sizeof( AUTH_SIGNATURE_PREFIX ) - 1U )
123#define HMAC_INNER_PAD_BYTE ( 0x36U )
124#define HMAC_OUTER_PAD_BYTE ( 0x5CU )
125#define HMAX_IPAD_XOR_OPAD_BYTE ( 0x6AU )
130#define LOG_INSUFFICIENT_MEMORY_ERROR( purposeOfWrite, bytesExceeded ) \
131 { \
132 LogError( ( "Unable to " purposeOfWrite ": Insufficient memory configured in SIGV4_PROCESSING_BUFFER_LENGTH macro. BytesExceeded=%lu", \
133 ( unsigned long ) ( bytesExceeded ) ) ); \
134 }
135
139#define FLAG_IS_SET( bits, flag ) ( ( ( bits ) & ( flag ) ) == ( flag ) )
140
149#define isWhitespace( c ) ( ( ( c ) == ' ' ) || ( ( c ) == '\t' ) )
150
156typedef struct SigV4DateTime
157{
158 int32_t tm_year;
159 int32_t tm_mon;
160 int32_t tm_mday;
161 int32_t tm_hour;
162 int32_t tm_min;
163 int32_t tm_sec;
165
171typedef struct SigV4String
172{
173 char * pData;
174 size_t dataLen;
176
182typedef struct SigV4ConstString
183{
184 const char * pData;
185 size_t dataLen;
187
193typedef struct SigV4KeyValuePair
194{
198
203typedef struct CanonicalContext
204{
208 uint8_t pBufProcessing[ SIGV4_PROCESSING_BUFFER_LENGTH ];
209 char * pBufCur;
211 const char * pHashPayloadLoc;
214
219typedef struct HmacContext
220{
225
230
234 size_t keyLen;
236
237/* *INDENT-OFF* */
238#ifdef __cplusplus
239 }
240#endif
241/* *INDENT-ON* */
242
243#endif /* ifndef SIGV4_INTERNAL_H_ */
The default values for configuration macros used by the SigV4 Library.
#define SIGV4_MAX_QUERY_PAIR_COUNT
Macro defining the maximum number of query key/value pairs, used to assist the library in sorting que...
Definition: sigv4_config_defaults.h:105
#define SIGV4_PROCESSING_BUFFER_LENGTH
Macro defining the size of the internal buffer used for incremental canonicalization and hashing.
Definition: sigv4_config_defaults.h:77
#define SIGV4_MAX_HTTP_HEADER_COUNT
Macro defining the maximum number of headers in the request, used to assist the library in sorting he...
Definition: sigv4_config_defaults.h:91
#define SIGV4_HASH_MAX_BLOCK_LENGTH
Macro indicating the largest block size of any hashing algorithm used for SigV4 authentication i....
Definition: sigv4_config_defaults.h:131
An aggregator to maintain the internal state of canonicalization during intermediate calculations.
Definition: sigv4_internal.h:204
char * pBufCur
Definition: sigv4_internal.h:209
size_t bufRemaining
Definition: sigv4_internal.h:210
const char * pHashPayloadLoc
Definition: sigv4_internal.h:211
size_t hashPayloadLen
Definition: sigv4_internal.h:212
An aggregator to maintain the internal state of HMAC calculations.
Definition: sigv4_internal.h:220
size_t keyLen
The length of the accumulated key data.
Definition: sigv4_internal.h:234
const SigV4CryptoInterface_t * pCryptoInterface
The cryptography interface.
Definition: sigv4_internal.h:224
A library structure holding the string and length values of parameters to be sorted and standardized....
Definition: sigv4_internal.h:183
const char * pData
Definition: sigv4_internal.h:184
size_t dataLen
Definition: sigv4_internal.h:185
The cryptography interface used to supply the user-defined hash implementation.
Definition: sigv4.h:226
An aggregator representing the individually parsed elements of the user-provided date parameter....
Definition: sigv4_internal.h:157
int32_t tm_mon
Definition: sigv4_internal.h:159
int32_t tm_mday
Definition: sigv4_internal.h:160
int32_t tm_min
Definition: sigv4_internal.h:162
int32_t tm_hour
Definition: sigv4_internal.h:161
int32_t tm_year
Definition: sigv4_internal.h:158
int32_t tm_sec
Definition: sigv4_internal.h:163
A key-value pair data structure that allows for sorting of SigV4 string values using internal compari...
Definition: sigv4_internal.h:194
SigV4ConstString_t value
Definition: sigv4_internal.h:196
SigV4ConstString_t key
Definition: sigv4_internal.h:195
A library structure holding the string and length values of parameters to be sorted and standardized....
Definition: sigv4_internal.h:172
char * pData
Definition: sigv4_internal.h:173
size_t dataLen
Definition: sigv4_internal.h:174