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

Support presigned URL signature "UNSIGNED-PAYLOAD" and expose EncodeURI #89

Merged
merged 14 commits into from
Feb 23, 2024

Conversation

giuspen
Copy link
Contributor

@giuspen giuspen commented Oct 5, 2023

As discussed in aws/aws-iot-device-sdk-embedded-C#1887 I have made changes to an existing demo http_demo_s3_download to generate a presigned URL instead of directly downloading the file.

I'm planning, if the changes to the submodules are accepted, to then generate a new demo called http_demo_s3_presigned_url or something like that.

You can see/test my work at https://github.com/giuspen/aws-iot-device-sdk-embedded-C/tree/GP_http_demo_s3_download_test_signature (only generate presigned URL) or https://github.com/giuspen/aws-iot-device-sdk-embedded-C/tree/GP_http_demo_s3_download_test_signature2 (download and also generate presigned URL)

Exact same requirements of original demo http_demo_s3_download

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@moninom1
Copy link
Member

moninom1 commented Oct 9, 2023

Hello @giuspen, Thank you for raising the PR! We will be looking further into this issue as soon as we can, thank you for your patience!

archigup
archigup previously approved these changes Oct 13, 2023
@giuspen
Copy link
Contributor Author

giuspen commented Oct 13, 2023

/bot run formatting

archigup
archigup previously approved these changes Oct 19, 2023
@giuspen
Copy link
Contributor Author

giuspen commented Nov 9, 2023

I see that there are unit tests errors but that doesn't seem to be related to my change.
Can anybody help me reviewing this?

@tony-josi-aws
Copy link
Member

@giuspen, Thanks for the PR. We will look into the unit test failures and update.

source/sigv4.c Outdated
pBufCur + 1U,
&valueBytesWritten,
true,
false );
Copy link
Member

Choose a reason for hiding this comment

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

The unit test test_SigV4_GenerateHTTPAuthorization_Happy_Paths is failing because of this change [line 2066]. Can you please update the tests to match the changes in your PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing and apologies for missing that.
I completely forgot about this change so I excluded that my changes could ever cause a unit test failure.
I will review this now, maybe I'll propose a way to pass false here only with the flag SIGV4_HTTP_PAYLOAD_IS_UNSIGNED as to not upset other use cases.

@giuspen
Copy link
Contributor Author

giuspen commented Nov 17, 2023

I wanted to run the unit tests myself and possibly add one unit test myself to not waste your time and patience but the instructions in https://github.com/aws/SigV4-for-AWS-IoT-embedded-sdk/blob/main/README.md#building-unit-tests don't work for me, I get instead

penoneg@cinnamon:~/git/SigV4-for-AWS-IoT-embedded-sdk/build$ ctest
Test project /home/penoneg/git/SigV4-for-AWS-IoT-embedded-sdk/build
    Start 1: sigv4_utest
1/1 Test #1: sigv4_utest ......................Child aborted***Exception:   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.01 sec

The following tests FAILED:
	  1 - sigv4_utest (Child aborted)
Errors while running CTest

@tony-josi-aws
Copy link
Member

@giuspen,

Can you try the following script to build and run the unit tests:

cmake -S test -B build/ -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_UNIT_TESTS=ON -DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG -DLOGGING_LEVEL_DEBUG=1'
make -C build/ all
cd build/ && ctest -E system --output-on-failure --verbose

@giuspen
Copy link
Contributor Author

giuspen commented Nov 20, 2023

Thanks @tony-josi-aws I could run the unit tests with your command, I did check that my implementation didn't fail existing unit tests and I also added a unit test to protect the presigned URL

@AniruddhaKanhere
Copy link
Member

AniruddhaKanhere commented Nov 22, 2023

@giuspen, it seems that your changes have increased the memory consumption of the library a bit. It is causing the memory-statistics check to fail. Would you mind updating the size_table.md like so:

  --- docs/doxygen/include/size_table.md	2023-11-22 20:54:32.891598188 +0000
  +++ size_table.html	2023-11-22 20:54:59.319864025 +0000
  @@ -10,5 +10,5 @@
       <tr>
           <td>sigv4.c</td>
  -        <td><center>5.2K</center></td>
  +        <td><center>5.3K</center></td>
           <td><center>4.4K</center></td>
       </tr>
  @@ -20,5 +20,5 @@
       <tr>
           <td><b>Total estimates</b></td>
  -        <td><b><center>5.6K</center></b></td>
  +        <td><b><center>5.7K</center></b></td>
           <td><b><center>4.7K</center></b></td>
       </tr>

I shall look at the failing memory safety proofs in the meanwhile.

thanks,
Aniruddha

@giuspen
Copy link
Contributor Author

giuspen commented Nov 22, 2023

sure thanks for reviewing @AniruddhaKanhere

@AniruddhaKanhere
Copy link
Member

@giuspen, thanks for updating the code.

I found the issue with memory safety proofs. We are using mocks to simplify and test implementation of functions. To that end, we have to define the stub of the function we intend to mock out.

The mock of generateCanonicalQuery here is missing the newly added const bool doubleEncodeEqualsInParmsValues, parameter. Can you add it please? You just need to add the parameter to that definition - it will not be used at all - and that is perfectly fine!

I think that should fix the failing check :)

Thanks again,
Aniruddha

@giuspen
Copy link
Contributor Author

giuspen commented Nov 22, 2023

Thanks @AniruddhaKanhere , I noticed that in the same file that you pointed out there is also the stub for encodeURI() but that was renamed in my PR as it is now no longer private but exposed to the API. I wonder if I should remove that stub as no longer needed or rename it

@AniruddhaKanhere
Copy link
Member

Thanks @AniruddhaKanhere , I noticed that in the same file that you pointed out there is also the stub for encodeURI() but that was renamed in my PR as it is now no longer private but exposed to the API. I wonder if I should remove that stub as no longer needed or rename it

Ah! Yes, I overlooked that. Thank you for catching it.
I think we should also rename the stub for encodeURI() to the new API that you have created.

@giuspen
Copy link
Contributor Author

giuspen commented Nov 24, 2023

I suspect the stubs are just for private stuff while for the public API there's no need. I have removed completely the encodeURI() for now, would it be possible to try and run the CI and see how it behaves?

@giuspen
Copy link
Contributor Author

giuspen commented Nov 24, 2023

If you are sure though I will restore and rename... let me know

@AniruddhaKanhere
Copy link
Member

Those stubs work in a different way. I think we should rename them.

Those stubs are there so that CBMC does not need to compute everything all at once. Because, if CBMC were to try and prove all the functions in the call graph to be memory safe, it would take exponentially long time and quite a bit more RAM. These stubs reduce the computation that the CBMC SAT solver has to do.

Will keep an eye on the result though :)

Thank you for making that change.

@giuspen
Copy link
Contributor Author

giuspen commented Nov 24, 2023

Thanks @AniruddhaKanhere I'm going to restore and rename the encodeURI() stub

@giuspen
Copy link
Contributor Author

giuspen commented Feb 8, 2024

Is there any chance that my work will be merged in?
This will allow me to proceed submitting a new demo for the generation of a presigned URL to download a file from an S3 bucket.

@tony-josi-aws
Copy link
Member

Hi @giuspen, could you help in fixing the failing CBMC proofs?

@giuspen
Copy link
Contributor Author

giuspen commented Feb 19, 2024

Hi Tony, 100%, only thing it is not clear that CI error but maybe I can restore the private function name that I suspect the check is looking for and have the public function just call the private one. I'll give that a try this evening Europe time and push so we'll see if that makes the CI happy

@giuspen
Copy link
Contributor Author

giuspen commented Feb 19, 2024

/bot run formatting

@giuspen
Copy link
Contributor Author

giuspen commented Feb 21, 2024

I'm puzzled but I will try to run the test locally and possibly extract more info, the log of the error is not helping :(

@tony-josi-aws
Copy link
Member

Hi @giuspen,

Thanks for updating the PR. Could you please apply this attached patch and update the PR again?
It should fix the failing CBMC proof.

0001-Fix-CBMC-proof-for-SigV4_GenerateHTTPAuthorization.patch

@giuspen
Copy link
Contributor Author

giuspen commented Feb 21, 2024

Hi @tony-josi-aws thanks for the help, I applied your patch

@tony-josi-aws tony-josi-aws merged commit e828353 into aws:main Feb 23, 2024
12 checks passed
@giuspen giuspen deleted the GP_SupportForPresignedURLs branch February 23, 2024 07:34
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