Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SigV4_GenerateHTTPAuthorization unit tests #29

Merged
merged 50 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cc45898
Link OpenSSL to the test
yourslab Aug 3, 2021
5d60836
Add unit tests attaining branch coverage of 71%
yourslab Aug 4, 2021
9a688f5
Output authBufLen when complete
yourslab Aug 4, 2021
6174e8d
Fix test case
yourslab Aug 4, 2021
fa4a976
Revert changes to sigv4 sources
yourslab Aug 4, 2021
1e95193
SigV4_GenerateHTTPAuthorization Implementation
amazon-auto Feb 3, 2021
e1d370f
Merge doxygen
yourslab Aug 6, 2021
5140fa6
Create SigV4ConstString_t type
yourslab Aug 6, 2021
7cb9491
Fix checks
yourslab Aug 6, 2021
43258d6
Hygiene improvements in URI encoding logic
aggarw13 Aug 7, 2021
bcd8e72
Hygiene improvements in Authorization Header prefix value logic
aggarw13 Aug 7, 2021
962a2f7
Minor improvements
aggarw13 Aug 7, 2021
ab889d5
Resolve compiler warning
yourslab Aug 9, 2021
0a81e65
Fix checks
yourslab Aug 9, 2021
613363d
Address review comments
aggarw13 Aug 10, 2021
2380cab
More comment changes
aggarw13 Aug 10, 2021
dea0cc9
Merge branch 'generate-auth-header' into sigv4-unit-tests
aggarw13 Aug 10, 2021
098f715
Fix build errors
aggarw13 Aug 10, 2021
999a91d
Fix unit test run failures
aggarw13 Aug 10, 2021
080469e
Merge remote-tracking branch 'origin/main' into sigv4-unit-tests
aggarw13 Aug 10, 2021
aebaf44
Add test case for sorting corner cases
aggarw13 Aug 11, 2021
412c972
Minor coverage increment and hygiene of redundant length check in lib…
aggarw13 Aug 11, 2021
d8d5c9a
Prune API to remove unused members of struct, and add test coverage f…
aggarw13 Aug 11, 2021
90addaf
More code coverage on logic of trimmable spaces & header count > thre…
aggarw13 Aug 11, 2021
5a107b4
Hygiene improvements in build configuration
aggarw13 Aug 11, 2021
eb051de
Small refactor in implementation and complete testing coverage of enc…
aggarw13 Aug 12, 2021
74aa6d7
Fix bugs in encodeURI implementation when handling special characters…
aggarw13 Aug 12, 2021
49a150f
Fix some CI checks
aggarw13 Aug 12, 2021
160a31c
Disable asserts from unit test coverage
aggarw13 Aug 12, 2021
32d2bf5
Fix some doxygen failures
aggarw13 Aug 12, 2021
c27dfec
Merge branch 'main' into sigv4-unit-tests
muneebahmed10 Aug 12, 2021
ebdc1d4
Merge remote-tracking branch 'origin/main' into sigv4-unit-tests
aggarw13 Aug 12, 2021
532fbad
Address minor review comments
aggarw13 Aug 12, 2021
4e725e7
Merge branch 'sigv4-unit-tests' of github.com:yourslab/SigV4-for-AWS-…
aggarw13 Aug 12, 2021
ea007d9
Add error code for invalid HTTP headers and increment test coverage
aggarw13 Aug 13, 2021
d6909ac
Hygiene improvement in sigv4.c and test coverage increment
aggarw13 Aug 13, 2021
5ef01b9
Minor hygiene refactor in implementation and test coverage for canoni…
aggarw13 Aug 13, 2021
7c070fe
Complete test coverage for canonical functions
aggarw13 Aug 13, 2021
644d961
Merge remote-tracking branch 'origin/main' into sigv4-unit-tests
aggarw13 Aug 13, 2021
2bc887c
Fix some CI check failures
aggarw13 Aug 13, 2021
d43b903
Make more hygiene improvements and increase test coverage
aggarw13 Aug 13, 2021
0db41aa
Achieve 100% coverage
aggarw13 Aug 14, 2021
b2bc43f
Hygiene improvements
aggarw13 Aug 14, 2021
5a12d8c
Minor README.md update
aggarw13 Aug 14, 2021
3eaad85
Merge remote-tracking branch 'origin/main' into sigv4-unit-tests
aggarw13 Aug 14, 2021
f8d62ee
Address review comments
aggarw13 Aug 14, 2021
26b26bd
Quicksort: Remove unnecessary branches of invalid array or elements a…
aggarw13 Aug 14, 2021
6c04aba
100% coverage again
aggarw13 Aug 14, 2021
faafb73
Apply suggestions from code review
aggarw13 Aug 15, 2021
a87b4f3
Fix complexity and hygiene improvements
aggarw13 Aug 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:
workflow_dispatch:

jobs:
build-check-library:
runs-on: ubuntu-latest
steps:
- name: Clone This Repo
uses: actions/checkout@v2
- name: Build in Release Mode
run: |
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror'
make -C build/ all
unittest:
runs-on: ubuntu-latest
steps:
Expand All @@ -19,8 +31,8 @@ jobs:
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG'
-DBUILD_UNIT_TESTS=ON \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG -DLOGGING_LEVEL_DEBUG=1'
make -C build/ all
- name: Test
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ To use CMake, please refer to the [sigV4FilePaths.cmake](https://github.com/aws/

1. Go to the root directory of this repository.

1. Run the *cmake* command: `cmake -S test -B build -DBUILD_CLONE_SUBMODULES=ON`.
1. Run the *cmake* command: `cmake -S test -B build -DBUILD_UNIT_TESTS=ON`.

1. Run this command to build the library and unit tests: `make -C build all`.

Expand Down
4 changes: 2 additions & 2 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</tr>
<tr>
<td>sigv4.c</td>
<td><center>4.8K</center></td>
<td><center>4.9K</center></td>
<td><center>4.2K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>4.8K</center></b></td>
<td><b><center>4.9K</center></b></td>
<td><b><center>4.2K</center></b></td>
</tr>
</table>
31 changes: 28 additions & 3 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aws
br
bufferlen
bufremaining
bytesconsumed
canonicalrequest
canonicalurilen
cbmc
Expand All @@ -26,6 +27,7 @@ configpagestyle
const
constness
copydoc
crypto
css
ctype
currentparameter
Expand All @@ -35,62 +37,73 @@ datelen
dd
deconstructed
defgroup
doesn
doubleencodeequals
doxygen
encodeslash
encodetwice
endif
enums
expirationlen
failable
feb
formatchar
formatlen
gcc
generatecanonicaluri
github
gmt
gr
hashblocklen
hashdigestlen
hashfinal
hashinit
hashtofail
hashupdate
headercount
headerindex
headerlen
headersdatalen
headerslen
hexencoded
hexstring
hh
hhmmss
hmac
hmacaddkey
hmacdata
hmacfinal
hmacintermediate
hmackey
html
http
httpmethodlen
https
ietf
ifdef
ifndef
inc
ingroup
inputlen
iot
ipad
iskeyprefix
iso
itemsize
isspace
itemsize
jan
january
keylen
ksecret
leninput
lentoread
lf
linelen
logdebug
logerror
loginfo
logwarn
longregionlen
lv
maclen
mainpage
Expand All @@ -103,7 +116,9 @@ monthsperday
noninfringement
nullterminate
numitems
oom
opad
openssl
ored
org
outputlen
Expand Down Expand Up @@ -155,7 +170,11 @@ ppayload
pquery
pqueryloc
pre
precanonical
precanonicalized
pregion
pregion
printf
pseconditem
psecondval
psecretaccesskey
Expand All @@ -168,8 +187,8 @@ psigningkey
ptestformatfailure
puri
pvalue
quicksort
querylen
quicksort
rande
readloc
regionlen
Expand All @@ -178,6 +197,7 @@ sdk
sec
secretaccesskey
secretaccesskeylen
secretkey
securitytoken
securitytokenlen
sep
Expand All @@ -187,6 +207,7 @@ signaturelen
signedheaders
signedheaderslen
signingkey
sizeneededforcredentialscope
sizeof
snprintf
ss
Expand All @@ -202,6 +223,7 @@ subfolder
sublicense
thu
tm
todo
trimmable
trimmedlen
trimmedlength
Expand All @@ -215,7 +237,10 @@ url
utc
vallen
valuelen
writecanonicalqueryparameters
writelinetocanonicalrequest
xor
xoring
xy
yyyy
yyyymmdd
yyyymmdd
41 changes: 21 additions & 20 deletions source/include/sigv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ typedef enum SigV4Status
* Functions that may return this value:
* - #SigV4_GenerateHTTPAuthorization
*/
SigV4HashError
SigV4HashError,

/**
* @brief HTTP headers parsed to the library are invalid.
*
* Functions that may return this value:
* - #SigV4_GenerateHTTPAuthorization
*/
SigV4InvalidHttpHeaders
} SigV4Status_t;

/**
Expand Down Expand Up @@ -281,15 +289,21 @@ typedef struct SigV4HttpParameters
* question mark character ("?") that begins any query string parameters
* (e.g. "/path/to/item.txt"). If SIGV4_HTTP_PATH_IS_CANONICAL_FLAG is set,
* then this input must already be in canonical form.
*
* @note If there exists no path for the HTTP request, then this can be
* NULL.
*/
const char * pPath;
size_t pathLen; /**< @brief Length of pPath. */

/**
* @brief The HTTP request query from the URL. This contains all characters
* following the question mark character ("?") that denotes the start of the
* query. If SIGV4_HTTP_QUERY_IS_CANONICAL_FLAG is set, then this input
* @brief The HTTP request query from the URL, if it exists. This contains all
* characters following the question mark character ("?") that denotes the start
* of the query. If SIGV4_HTTP_QUERY_IS_CANONICAL_FLAG is set, then this input
* must already be in canonical form.
*
* @note If the HTTP request does not contain query string, this can
* be NULL.
*/
const char * pQuery;
size_t queryLen; /**< @brief Length of pQuery. */
Expand All @@ -299,6 +313,9 @@ typedef struct SigV4HttpParameters
* should be the raw headers in HTTP request format. If
* SIGV4_HTTP_HEADERS_IS_CANONICAL_FLAG is set, then this input must
* already be in canonical form.
*
* @note The headers data MUST NOT be empty. For HTTP/1.1 requests, it is
* required that the "host" header MUST be part of the SigV4 signature.
*/
const char * pHeaders;
size_t headersLen; /**< @brief Length of pHeaders. */
Expand Down Expand Up @@ -330,22 +347,6 @@ typedef struct SigV4Credentials
*/
const char * pSecretAccessKey;
size_t secretAccessKeyLen; /**< @brief Length of pSecretAccessKey. */

/**
* @brief The security token from AWS Security Token Service (AWS STS) is of
* varying length. This can be NULL if the access key id and secret access
* key were not retrieved from a temporary token service.
*/
const char * pSecurityToken;
size_t securityTokenLen; /**< @brief Length of pSecurityToken. */

/**
* @brief The expiration time for the pAccessKeyId, pSecretAccessKey, and
* pSecurityToken if the credentials were retrieved from a temporary token
* service. This is in ISO8601 date and time format.
*/
const char * pExpiration;
size_t expirationLen; /**< @brief Length of pExpiration. */
} SigV4Credentials_t;

/**
Expand Down
14 changes: 10 additions & 4 deletions source/include/sigv4_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
#define LINEFEED_CHAR '\n' /**< A linefeed character used to build the canonical request. */
#define LINEFEED_CHAR_LEN 1U /**< The length of #LINEFEED_CHAR. */

#define HTTP_REQUEST_LINE_ENDING "\r\n" /**< The string used in non-canonicalized HTTP headers to separate header entries in HTTP request. */
#define HTTP_REQUEST_LINE_ENDING_LEN ( sizeof( HTTP_REQUEST_LINE_ENDING ) - 1U ) /**< The length of #HTTP_REQUEST_LINE_ENDING. */

#define SPACE_CHAR ' ' /**< A linefeed character used to build the Authorization header value. */
#define SPACE_CHAR_LEN 1U /**< The length of #SPACE_CHAR. */

Expand All @@ -109,13 +112,16 @@
#define AUTH_SIGNATURE_PREFIX "Signature=" /**< The prefix that goes before the signature in the Authorization header value. */
#define AUTH_SIGNATURE_PREFIX_LEN ( sizeof( AUTH_SIGNATURE_PREFIX ) - 1U ) /**< The length of #AUTH_SIGNATURE_PREFIX. */

#define HMAC_INNER_PAD_BYTE ( 0x36U ) /**< The "ipad" byte used for generating the inner key in the HMAC calculation process. */
#define HMAC_OUTER_PAD_BYTE ( 0x5CU ) /**< The "opad" byte used for generating the outer key in the HMAC calculation process. */

/**
* @brief A helper macro to print insufficient memory errors.
*/
#define LOG_INSUFFICIENT_MEMORY_ERROR( purposeOfWrite, bytesExceeded ) \
{ \
LogError( ( "Insufficient memory provided to " purposeOfWrite ", bytesExceeded=%lu", \
( unsigned long ) ( bytesExceeded ) ) ); \
#define LOG_INSUFFICIENT_MEMORY_ERROR( purposeOfWrite, bytesExceeded ) \
{ \
LogError( ( "Unable to " purposeOfWrite ": Insufficient memory configured in \"SIGV4_PROCESSING_BUFFER_LENGTH\" macro. BytesExceeded=%lu", \
( unsigned long ) ( bytesExceeded ) ) ); \
}

/**
Expand Down
Loading