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 #27

Merged
merged 12 commits into from
Aug 10, 2021
Merged

Conversation

yourslab
Copy link
Contributor

@yourslab yourslab commented Aug 2, 2021

Contains all the functionality needed for SigV4_GenerateHTTPAuthorization. Although unit tests are not included as part of this PR to make reviews easier, they have already been started separately in another PR #29

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

typedef struct HmacContext
{
const SigV4CryptoInterface_t * pCryptoInterface;
char key[ SIGV4_HASH_MAX_BLOCK_LENGTH ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this a char when the crypto interface takes a uint8_t *?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I thought I had replaced the crypto interface to also be char *

muneebahmed10
muneebahmed10 previously approved these changes Aug 5, 2021
Copy link
Contributor

@muneebahmed10 muneebahmed10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it includes changes from #28, that should go in first and this can be rebased off of it

@yourslab yourslab force-pushed the generate-auth-header branch 4 times, most recently from 1c2a0ea to 72971e2 Compare August 6, 2021 15:01
amazon-auto and others added 7 commits August 9, 2021 18:30
Update auto-generated .md files

Add test and tool directories (aws#1)

Adding test and tools directories, with CMock submodule.

CI Actions (aws#2)

Add header files + default configurations (aws#3)

- Add files sigv4.h and sigv4_config_defaults.h
- Add public-facing API elements detailed in design doc

Format Date Header for ISO8601 Compliance (aws#4)

Add optional utility function to format date header returned from AWS IoT (ex. in temp tokens) for compliance with the ISO8601 format required for authentication

Add unit tests for SigV4_AwsIotDateToIso8601() (aws#8)

Setup proof infrastructure for CBMC (aws#7)

* Add Litani and templates for CBMC

* Add sample proof

* Implement CBMC proof for SigV4_AwsIotDateToIso8601

* Unwind all loops such that no unwinding errors occur

Change submodule to use https rather than ssh for aws-templates-for-cbmc-proofs (aws#12)

* CBMC fix test (do not merge)

* Change AWS templates to https instead of ssh

* Revert README

Update README.md and LICENSE files (aws#14)

Update README.md and LICENSE files before changing repo's visibility status (to public).

Add remaining doxygen + link verification checks (aws#15)

Add doxygen + link verifier checks (the library-specific doxygen content will be added in a separate PR for further review).

[SigV4] CBMC proof for Sigv4_awsIotdatetoISO8601 API (aws#19)

* Sigv4_AWSIOtDateToISO8601 CBMC PROOF

* Unit test coverage changes

Add release workflow (+ revert to previous license) (aws#18)

change permissions of run_cbmc_proofs.py (aws#21)

[Sigv4] Doxygen content updates (aws#22)

* doxygen doc update

* lexicon update

Update proof tools (+disable submodule cloning by default) (aws#20)

This commit advances Litani to release 1.10.0, and the starter kit to
the tip-of-tree. This brings the following improvements:

- Profiling
    - Litani measures the memory usage of the CBMC safety checking and
      coverage checking jobs
    - The dashboard includes box-and-whisker diagrams for memory use per
      proof
    - The dashboard includes a graph of how many parallel jobs are
      running over the whole run, making it easy to choose a CI machine
      with enough parallelism
    - It is now possible to designate particular proofs as "EXPENSIVE";
      Litani runs expensive proofs serially, ensuring that they do not
      over-consume resources like RAM.

- UI improvements
    - Each pipeline page includes a table of contents
    - Each pipeline page includes a dependency graph of the pipeline
    - Each job on the pipeline page has a hyperlink to that job
    - The terminal output is now less noisy

SigV4_GenerateHTTPAuthorization() API Functionality (aws#16)

* Squash of outdated aws#13 commits

* Hold for checks

* Add definitions for sorting structures

* Include parsing functions

* Fix old commit error

* Missing asserts

* (temporarily allow warnings)

* Spell check + include partial context

* More updates to lexicon+doxygen

* Add asserts for private func.

* Move access after asserts

* Clarify pointer increment

* Update postfix syntax for correct operator precedence

* Feedback changes only

* + remove accidental duplicate

Implement credential scope

Implement generate credential query

Validation of parameter count

Solution a bit overcomplicated

Squash bugs and canonical query parameters should also be sorted by value

Finish canonicalize query

Fix canonical URI encoding

Add hash helper function

Add hmac implementation

Add newline chars for canonical request

Finish writing of canonical request

Hex-encoded hash of canonical request matches

Write string to sign

Fix bug

Refactor writeStringToSign for complexity

Allow HMAC keys to be passed through separate function calls

Add code for generating signing key

Fix hmac bug

Generate the final signature correctly

Fix bug

Fix newline not being written

Merge Shivangi's code

Stylistic changes

Link OpenSSL to the test

Add unit tests attaining branch coverage of 71%

Integrate Shivangi's latest changes

Output authBufLen when complete

Update logic when headers are precanonicalized.

Add additional parameter checks for block/digest len

Add documentation

Fix test case

Get complexity <= 8 for private functions

Reduce complexity

Remove use of %zu

Revert changes to test as it was added to another PR

Uncrustify and add doxygen strings.

Add docs

Resolve doxygen errors and lexicon.txt

Document all private functions

Fix remaining doxygen errors

Update lexicon.txt

Remove duplicate declaration

Remove assertions on pQuery being NULL

Add log messages for insufficient memory errors

Uncrustify
@yourslab yourslab force-pushed the generate-auth-header branch from 8bbce6c to 962a2f7 Compare August 9, 2021 22:41
@aggarw13 aggarw13 force-pushed the generate-auth-header branch from 7ef4dc2 to 0a81e65 Compare August 9, 2021 23:23
if( returnStatus == SigV4Success )
{
encodedLen = canonicalContext.bufRemaining;
returnStatus = completeHashAndHexEncode( pParams->pHttpParameters->pPayload,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashing the payload again may not be required as Application is already hashing the payload and passing it as value of x-amz-content-sha56 header. We can directly use that value. I have discussed it with @aggarw13 already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a separate branch in my fork for logic updates of the optimization. I will create a separate PR for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gshvang @aggarw13 Should we add another option instead that allows the customer to choose whether to hash the payload or not?

char * pAuthBuf,
size_t * authBufLen,
char ** pSignature,
size_t * signatureLen )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion of input parameters is missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API function which has separate function for input validation.

@aggarw13 aggarw13 force-pushed the generate-auth-header branch from 1a78455 to e7174b5 Compare August 10, 2021 00:30
@aggarw13 aggarw13 force-pushed the generate-auth-header branch from e7174b5 to 613363d Compare August 10, 2021 00:33

/**
* @brief The maximum number of query parameters was exceeded while parsing
* the query string input parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be helpful to customer if we mention which config to update for changing the value for SigV4MaxQueryPairCountExceeded

gshvang
gshvang previously approved these changes Aug 10, 2021
@aggarw13 aggarw13 merged commit a71ec2a into aws:main Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants