SigV4 v1.0.0
SigV4 Library for AWS Authentication
sigv4_internal.h File Reference

Internal definitions for the SigV4 Client Utility Library. More...

#include "sigv4_config.h"
#include "sigv4_config_defaults.h"

Go to the source code of this file.

Data Structures

struct  SigV4DateTime_t
 An aggregator representing the individually parsed elements of the user-provided date parameter. This is used to verify the complete date representation, and construct the final ISO 8601 string. More...
 
struct  SigV4String_t
 A library structure holding the string and length values of parameters to be sorted and standardized. This allows for a layer of abstraction during the canonicalization step of the V4 signing process. More...
 
struct  SigV4ConstString_t
 A library structure holding the string and length values of parameters to be sorted and standardized. This allows for a layer of abstraction during the canonicalization step of the V4 signing process. More...
 
struct  SigV4KeyValuePair_t
 A key-value pair data structure that allows for sorting of SigV4 string values using internal comparison functions, and provides additional stability to quickSort(), to comply with Misra rule 21.9. More...
 
struct  CanonicalContext_t
 An aggregator to maintain the internal state of canonicalization during intermediate calculations. More...
 
struct  HmacContext_t
 An aggregator to maintain the internal state of HMAC calculations. More...
 

Macros

#define YEAR_MIN   1900L
 
#define MONTH_ASCII_LEN   3U
 
#define MONTH_NAMES   { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
 Month name abbreviations for RFC 5322 date parsing.
 
#define MONTH_DAYS   { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 Number of days in each respective month.
 
#define FORMAT_RFC_3339   "%4Y-%2M-%2DT%2h:%2m:%2sZ"
 
#define FORMAT_RFC_3339_LEN   sizeof( FORMAT_RFC_3339 ) - 1U
 
#define FORMAT_RFC_5322   "%3*, %2D %3M %4Y %2h:%2m:%2s GMT"
 
#define FORMAT_RFC_5322_LEN   sizeof( FORMAT_RFC_5322 ) - 1U
 
#define ISO_YEAR_LEN   4U
 
#define ISO_NON_YEAR_LEN   2U
 
#define ISO_DATE_SCOPE_LEN   8U
 
#define CREDENTIAL_SCOPE_SEPARATOR   '/'
 The separator between each component of the credential scope.
 
#define CREDENTIAL_SCOPE_SEPARATOR_LEN   1U
 
#define CREDENTIAL_SCOPE_TERMINATOR   "aws4_request"
 The last component that terminates the credential scope.
 
#define CREDENTIAL_SCOPE_TERMINATOR_LEN   ( sizeof( CREDENTIAL_SCOPE_TERMINATOR ) - 1U )
 
#define HTTP_EMPTY_PATH   "/"
 Default value when HttpParameters_t.pPath == NULL.
 
#define HTTP_EMPTY_PATH_LEN   ( sizeof( HTTP_EMPTY_PATH ) - 1U )
 
#define URI_ENCODED_SPECIAL_CHAR_SIZE   3U
 
#define URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE   5U
 
#define LINEFEED_CHAR   '\n'
 
#define LINEFEED_CHAR_LEN   1U
 
#define HTTP_REQUEST_LINE_ENDING   "\r\n"
 
#define HTTP_REQUEST_LINE_ENDING_LEN   ( sizeof( HTTP_REQUEST_LINE_ENDING ) - 1U )
 
#define SPACE_CHAR   ' '
 
#define SPACE_CHAR_LEN   1U
 
#define S3_SERVICE_NAME   "s3"
 
#define S3_SERVICE_NAME_LEN   ( sizeof( S3_SERVICE_NAME ) - 1U )
 
#define SIGV4_HMAC_SIGNING_KEY_PREFIX   "AWS4"
 
#define SIGV4_HMAC_SIGNING_KEY_PREFIX_LEN   ( sizeof( SIGV4_HMAC_SIGNING_KEY_PREFIX ) - 1U )
 
#define AUTH_CREDENTIAL_PREFIX   "Credential="
 
#define AUTH_CREDENTIAL_PREFIX_LEN   ( sizeof( AUTH_CREDENTIAL_PREFIX ) - 1U )
 
#define AUTH_SEPARATOR   ", "
 
#define AUTH_SEPARATOR_LEN   ( sizeof( AUTH_SEPARATOR ) - 1U )
 
#define AUTH_SIGNED_HEADERS_PREFIX   "SignedHeaders="
 
#define AUTH_SIGNED_HEADERS_PREFIX_LEN   ( sizeof( AUTH_SIGNED_HEADERS_PREFIX ) - 1U )
 
#define AUTH_SIGNATURE_PREFIX   "Signature="
 
#define AUTH_SIGNATURE_PREFIX_LEN   ( sizeof( AUTH_SIGNATURE_PREFIX ) - 1U )
 
#define HMAC_INNER_PAD_BYTE   ( 0x36U )
 
#define HMAC_OUTER_PAD_BYTE   ( 0x5CU )
 
#define LOG_INSUFFICIENT_MEMORY_ERROR(purposeOfWrite, bytesExceeded)
 A helper macro to print insufficient memory errors. More...
 
#define FLAG_IS_SET(bits, flag)   ( ( ( bits ) & ( flag ) ) == ( flag ) )
 A helper macro to test if a flag is set.
 
#define isWhitespace(c)   ( ( ( c ) == ' ' ) || ( ( c ) == '\t' ) )
 A helper macro to determine if a character is whitespace. More...
 

Detailed Description

Internal definitions for the SigV4 Client Utility Library.

Macro Definition Documentation

◆ YEAR_MIN

#define YEAR_MIN   1900L

Earliest year accepted.

◆ MONTH_ASCII_LEN

#define MONTH_ASCII_LEN   3U

Length of month abbreviations.

◆ FORMAT_RFC_3339

#define FORMAT_RFC_3339   "%4Y-%2M-%2DT%2h:%2m:%2sZ"

Format string to parse RFC 3339 date.

◆ FORMAT_RFC_3339_LEN

#define FORMAT_RFC_3339_LEN   sizeof( FORMAT_RFC_3339 ) - 1U

Length of the RFC 3339 format string.

◆ FORMAT_RFC_5322

#define FORMAT_RFC_5322   "%3*, %2D %3M %4Y %2h:%2m:%2s GMT"

Format string to parse RFC 5322 date.

◆ FORMAT_RFC_5322_LEN

#define FORMAT_RFC_5322_LEN   sizeof( FORMAT_RFC_5322 ) - 1U

Length of the RFC 3339 format string.

◆ ISO_YEAR_LEN

#define ISO_YEAR_LEN   4U

Length of year value in ISO 8601 date.

◆ ISO_NON_YEAR_LEN

#define ISO_NON_YEAR_LEN   2U

Length of non-year values in ISO 8601 date.

◆ ISO_DATE_SCOPE_LEN

#define ISO_DATE_SCOPE_LEN   8U

Length of date substring used in credential scope.

◆ CREDENTIAL_SCOPE_SEPARATOR_LEN

#define CREDENTIAL_SCOPE_SEPARATOR_LEN   1U

◆ CREDENTIAL_SCOPE_TERMINATOR_LEN

#define CREDENTIAL_SCOPE_TERMINATOR_LEN   ( sizeof( CREDENTIAL_SCOPE_TERMINATOR ) - 1U )

◆ HTTP_EMPTY_PATH_LEN

#define HTTP_EMPTY_PATH_LEN   ( sizeof( HTTP_EMPTY_PATH ) - 1U )

The length of HTTP_EMPTY_PATH.

◆ URI_ENCODED_SPECIAL_CHAR_SIZE

#define URI_ENCODED_SPECIAL_CHAR_SIZE   3U

The size of an encoded URI special character.

◆ URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE

#define URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE   5U

The size of the double-encoded "=" character.

◆ LINEFEED_CHAR

#define LINEFEED_CHAR   '\n'

A linefeed character used to build the canonical request.

◆ LINEFEED_CHAR_LEN

#define LINEFEED_CHAR_LEN   1U

The length of LINEFEED_CHAR.

◆ HTTP_REQUEST_LINE_ENDING

#define HTTP_REQUEST_LINE_ENDING   "\r\n"

The string used in non-canonicalized HTTP headers to separate header entries in HTTP request.

◆ HTTP_REQUEST_LINE_ENDING_LEN

#define HTTP_REQUEST_LINE_ENDING_LEN   ( sizeof( HTTP_REQUEST_LINE_ENDING ) - 1U )

The length of HTTP_REQUEST_LINE_ENDING.

◆ SPACE_CHAR

#define SPACE_CHAR   ' '

A linefeed character used to build the Authorization header value.

◆ SPACE_CHAR_LEN

#define SPACE_CHAR_LEN   1U

The length of SPACE_CHAR.

◆ S3_SERVICE_NAME

#define S3_SERVICE_NAME   "s3"

S3 is the only service where the URI must only be encoded once.

◆ S3_SERVICE_NAME_LEN

#define S3_SERVICE_NAME_LEN   ( sizeof( S3_SERVICE_NAME ) - 1U )

The length of S3_SERVICE_NAME.

◆ SIGV4_HMAC_SIGNING_KEY_PREFIX

#define SIGV4_HMAC_SIGNING_KEY_PREFIX   "AWS4"

HMAC signing key prefix.

◆ SIGV4_HMAC_SIGNING_KEY_PREFIX_LEN

#define SIGV4_HMAC_SIGNING_KEY_PREFIX_LEN   ( sizeof( SIGV4_HMAC_SIGNING_KEY_PREFIX ) - 1U )

◆ AUTH_CREDENTIAL_PREFIX

#define AUTH_CREDENTIAL_PREFIX   "Credential="

The prefix that goes before the credential value in the Authorization header value.

◆ AUTH_CREDENTIAL_PREFIX_LEN

#define AUTH_CREDENTIAL_PREFIX_LEN   ( sizeof( AUTH_CREDENTIAL_PREFIX ) - 1U )

The length of AUTH_CREDENTIAL_PREFIX.

◆ AUTH_SEPARATOR

#define AUTH_SEPARATOR   ", "

The separator between each component in the Authorization header value.

◆ AUTH_SEPARATOR_LEN

#define AUTH_SEPARATOR_LEN   ( sizeof( AUTH_SEPARATOR ) - 1U )

The length of AUTH_SEPARATOR.

◆ AUTH_SIGNED_HEADERS_PREFIX

#define AUTH_SIGNED_HEADERS_PREFIX   "SignedHeaders="

The prefix that goes before the signed headers in the Authorization header value.

◆ AUTH_SIGNED_HEADERS_PREFIX_LEN

#define AUTH_SIGNED_HEADERS_PREFIX_LEN   ( sizeof( AUTH_SIGNED_HEADERS_PREFIX ) - 1U )

◆ AUTH_SIGNATURE_PREFIX

#define AUTH_SIGNATURE_PREFIX   "Signature="

The prefix that goes before the signature in the Authorization header value.

◆ AUTH_SIGNATURE_PREFIX_LEN

#define AUTH_SIGNATURE_PREFIX_LEN   ( sizeof( AUTH_SIGNATURE_PREFIX ) - 1U )

The length of AUTH_SIGNATURE_PREFIX.

◆ HMAC_INNER_PAD_BYTE

#define HMAC_INNER_PAD_BYTE   ( 0x36U )

The "ipad" byte used for generating the inner key in the HMAC calculation process.

◆ HMAC_OUTER_PAD_BYTE

#define HMAC_OUTER_PAD_BYTE   ( 0x5CU )

The "opad" byte used for generating the outer key in the HMAC calculation process.

◆ LOG_INSUFFICIENT_MEMORY_ERROR

#define LOG_INSUFFICIENT_MEMORY_ERROR (   purposeOfWrite,
  bytesExceeded 
)
Value:
{ \
LogError( ( "Unable to " purposeOfWrite ": Insufficient memory configured in \"SIGV4_PROCESSING_BUFFER_LENGTH\" macro. BytesExceeded=%lu", \
( unsigned long ) ( bytesExceeded ) ) ); \
}

A helper macro to print insufficient memory errors.

◆ isWhitespace

#define isWhitespace (   c)    ( ( ( c ) == ' ' ) || ( ( c ) == '\t' ) )

A helper macro to determine if a character is whitespace.

Note
The ctype function isspace() returns true for the following characters: , \t, \n, \v, \f, \r. However, according to RFC5234: https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1 the only whitespace characters in an HTTP header are spaces and horizontal tabs.