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

Bug fixes in library and hygiene improvements in test cases #52

Merged
merged 9 commits into from
Aug 20, 2021

Conversation

aggarw13
Copy link
Contributor

@aggarw13 aggarw13 commented Aug 18, 2021

Hygiene Changes

Bugfixes

Fix 2 categories of bugs found from adding signature verification in tests:

  1. Fix parsing of query string for cases empty parameter values (with the format <param>=&<param2> OR <param>&<param2>)
  2. Fix URI encoding to not encode NULL character.

source/sigv4.c Outdated Show resolved Hide resolved
source/sigv4.c Outdated Show resolved Hide resolved
source/sigv4.c Outdated

/* Case when parameter has empty value even though the query parameter entry has the form
* "<param>=". */
else if( ( fieldHasValue ) && ( ( currQueryIndex - startOfFieldOrValue ) == 0U ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

So this will happen in the case of either <param>=<end of query> or <param>=&. Are either of these valid?

Copy link
Contributor Author

@aggarw13 aggarw13 Aug 19, 2021

Choose a reason for hiding this comment

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

The API Gateway Tutorial provides an example that supports providing query parameters with no value in both the formats.
The example REST API is: http://petstore-demo-endpoint.execute-api.com/petstore/pets?type=cat&page=2
It can be used successfully with the URI as http://petstore-demo-endpoint.execute-api.com/petstore/pets?type&page and http://petstore-demo-endpoint.execute-api.com/petstore/pets?type=&page=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moreover, the AWS SigV4 spec mentions about providing the query parameter name with = character but an empty string for empty values.

For each parameter, append the URI-encoded parameter name, followed by the equals sign character (=), followed by the URI-encoded parameter value. Use an empty string for parameters that have no value.

source/sigv4.c Outdated Show resolved Hide resolved

if( returnStatus == SigV4Success )
{
pBufLoc += encodedLen;
remainingLen -= encodedLen;

/* Encode parameter value if non-empty. Query parameters can have empty values. */
if( pCanonicalRequest->pQueryLoc[ paramsIndex ].value.dataLen > 0U )
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can this be assumed to be true now? Or does writeValueInCanonicalizedQueryString still work with a zero length parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or does writeValueInCanonicalizedQueryString still work with a zero length parameter?

Yes, this function adds the = character which is required for canonical query format even with empty values.

source/sigv4.c Outdated Show resolved Hide resolved
test/unit-test/sigv4_utest.c Outdated Show resolved Hide resolved
test/unit-test/sigv4_utest.c Show resolved Hide resolved
muneebahmed10
muneebahmed10 previously approved these changes Aug 19, 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.

Some spelling

test/unit-test/sigv4_utest.c Outdated Show resolved Hide resolved
source/sigv4.c Outdated Show resolved Hide resolved
@aggarw13 aggarw13 merged commit 10dab1d into aws:main Aug 20, 2021
@aggarw13 aggarw13 deleted the hygiene/unit-test-and-library branch August 20, 2021 20:53
markrtuttle pushed a commit to markrtuttle/SigV4-for-AWS-IoT-embedded-sdk that referenced this pull request Sep 2, 2021
* Adding OTA agent files

* Added tokens to lexicon.txt and spellings fix

* spell-check fix

* spell check and doxygen fix

* Added back OTA_JsonFileSignatureKey

* Support for coreJSON2.0

* Add fileType key support for multi file type support

* Fix filetype offset in job param table

* Update log strings in ota.c

* User buffer initial commit

* Remove unused code

* Alternative memory allocation support

* Implement request timer and self-test timers

* Cleanup on ota agent

* Update the ota config includes in ota.c and ota_private.h

* Fix issue with job parsing flag width

* Fix ota agent unit tests build errors

* Spell-check and formatting fix

* doxygen fix and added 2 error codes

* formatting and spell check fix

* Complexity reduction fix

* fixed commas for debug statements

* Remove void * from the json parsin table

* Add an error for failing to decode cbor

* Remove ota types header from library cmake paths

* Fix some compilation issues and warnings

* Fix PR feedfback in ota agent

* Fix CI checks

* Addressed PR feedback

* Fix pointer usage in job parsing (aws#76)

* Update lexicon and github workflow

* Sync fix from development

* Format files

Co-authored-by: pvyawaha <[email protected]>
Co-authored-by: Joshua Yan <[email protected]>
Co-authored-by: Tiangang Song <[email protected]>
pBufLoc += encodedLen;
remainingLen -= encodedLen;
}
assert( pCanonicalRequest->pQueryLoc[ paramsIndex ].value.pData != NULL );
Copy link

@digantaTheProgrammer digantaTheProgrammer Jun 2, 2024

Choose a reason for hiding this comment

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

@aggarw13 Since, as you mentioned above that, writeValueInCanonicalizedQueryString can work with empty values, why are we asserting this?

Doesn't it essentially force all query parameters to have non-empty value?

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.

4 participants