From 767ca4ee01992ff7ed0fc1cde4c405a356110819 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Fri, 15 Mar 2024 10:39:36 -0700 Subject: [PATCH] Fixing workflo failures --- .../http/common/include/http_demo_s3_utils.h | 6 +- demos/http/common/src/http_demo_s3_utils.c | 8 +- .../http_demo_s3_download.c | 6 +- .../http_demo_s3_generate_presigned_url.c | 140 +++++++----------- demos/lexicon.txt | 1 + manifest.yml | 4 +- 6 files changed, 69 insertions(+), 96 deletions(-) diff --git a/demos/http/common/include/http_demo_s3_utils.h b/demos/http/common/include/http_demo_s3_utils.h index 47e3546f65..e705593d30 100644 --- a/demos/http/common/include/http_demo_s3_utils.h +++ b/demos/http/common/include/http_demo_s3_utils.h @@ -45,12 +45,12 @@ /** * @brief Length in bytes of hex encoded hash digest. */ -#define HEX_ENCODED_SHA256_HASH_DIGEST_LENGTH ( ( ( uint16_t ) 64 ) ) +#define HEX_ENCODED_SHA256_HASH_DIGEST_LENGTH ( ( ( uint16_t ) 64 ) ) /** * @brief Length in bytes of SHA256 hash digest. */ -#define SHA256_HASH_DIGEST_LENGTH ( HEX_ENCODED_SHA256_HASH_DIGEST_LENGTH / 2 ) +#define SHA256_HASH_DIGEST_LENGTH ( HEX_ENCODED_SHA256_HASH_DIGEST_LENGTH / 2 ) /** * @brief Maximum Length for AWS IOT Credential provider server host name. @@ -58,7 +58,7 @@ * @note length of the AWS IOT Credential provider server host name string * cannot exceed this value. */ -#define SERVER_HOST_NAME_MAX_LENGTH 65U +#define SERVER_HOST_NAME_MAX_LENGTH 65U /** * @brief The host address string extracted from the AWS IOT CREDENTIAL PROVIDER URL. diff --git a/demos/http/common/src/http_demo_s3_utils.c b/demos/http/common/src/http_demo_s3_utils.c index 01b446e2ea..f814c27e96 100644 --- a/demos/http/common/src/http_demo_s3_utils.c +++ b/demos/http/common/src/http_demo_s3_utils.c @@ -137,10 +137,10 @@ static JSONStatus_t parseCredentials( HTTPResponse_t * response, /*-----------------------------------------------------------*/ bool getTemporaryCredentials( TransportInterface_t * transportInterface, - char * pDateISO8601, - size_t pDateISO8601Len, - HTTPResponse_t * response, - SigV4Credentials_t * sigvCreds ) + char * pDateISO8601, + size_t pDateISO8601Len, + HTTPResponse_t * response, + SigV4Credentials_t * sigvCreds ) { bool returnStatus = true; HTTPRequestHeaders_t requestHeaders = { 0 }; diff --git a/demos/http/http_demo_s3_download/http_demo_s3_download.c b/demos/http/http_demo_s3_download/http_demo_s3_download.c index caee221937..baf7e10bdf 100644 --- a/demos/http/http_demo_s3_download/http_demo_s3_download.c +++ b/demos/http/http_demo_s3_download/http_demo_s3_download.c @@ -175,17 +175,17 @@ /** * @brief Field name of the HTTP Authorization header to add to the request headers. */ -#define SIGV4_AUTH_HEADER_FIELD_NAME "Authorization" +#define SIGV4_AUTH_HEADER_FIELD_NAME "Authorization" /** * @brief Length of AWS HTTP Authorization header value generated using SigV4 library. */ -#define AWS_HTTP_AUTH_HEADER_VALUE_LEN 2048U +#define AWS_HTTP_AUTH_HEADER_VALUE_LEN 2048U /** * @brief Represents empty payload for HTTP GET request sent to AWS S3. */ -#define S3_REQUEST_EMPTY_PAYLOAD "" +#define S3_REQUEST_EMPTY_PAYLOAD "" /** diff --git a/demos/http/http_demo_s3_generate_presigned_url/http_demo_s3_generate_presigned_url.c b/demos/http/http_demo_s3_generate_presigned_url/http_demo_s3_generate_presigned_url.c index 4d15cc73d6..375e57c9c6 100644 --- a/demos/http/http_demo_s3_generate_presigned_url/http_demo_s3_generate_presigned_url.c +++ b/demos/http/http_demo_s3_generate_presigned_url/http_demo_s3_generate_presigned_url.c @@ -106,7 +106,7 @@ /** * @brief The length of the HTTP GET method. */ -#define HTTP_METHOD_GET_LENGTH ( sizeof( HTTP_METHOD_GET ) - 1 ) +#define HTTP_METHOD_GET_LENGTH ( sizeof( HTTP_METHOD_GET ) - 1 ) /** * @brief The maximum number of times to run the loop in this demo. @@ -155,12 +155,12 @@ /** * @brief Length of AWS HTTP Authorization header value generated using SigV4 library. */ -#define AWS_HTTP_AUTH_HEADER_VALUE_LEN 2048U +#define AWS_HTTP_AUTH_HEADER_VALUE_LEN 2048U /** * @brief Represents empty payload for HTTP GET request sent to AWS S3. */ -#define S3_REQUEST_EMPTY_PAYLOAD "" +#define S3_REQUEST_EMPTY_PAYLOAD "" /** @@ -220,11 +220,6 @@ static uint8_t pAwsIotHttpBuffer[ CREDENTIAL_BUFFER_LENGTH ] = { 0 }; */ static char pDateISO8601[ SIGV4_ISO_STRING_LEN ] = { 0 }; -/** - * @brief Represents hash digest of payload. - */ -static char pPayloadHashDigest[ SHA256_HASH_DIGEST_LENGTH ]; - /** * @brief Represents Authorization header value generated using SigV4 library. */ @@ -248,21 +243,17 @@ struct NetworkContext /** * @brief Generate a pre-signed URL to an S3 object file and print it to stdout * - * @param[in] pTransportInterface The transport interface for making network - * calls. * @param[in] pPath The Request-URI to the objects of interest. This string * should be null-terminated. * * @return The status of the pre-signed URL generation: true on success, false on failure. */ -static bool generateS3ObjectFilePresignedURL( const TransportInterface_t * pTransportInterface, - const char * pPath ); +static bool generateS3ObjectFilePresignedURL( const char * pPath ); /** * @brief Generate and print a pre-signed URL to the S3 object file that is specified in pPath. * - * @param[in] pTransportInterface The transport interface for making network - * calls. + * @param[in] pHost The server host address. * @param[in] hostLen The length of the server host address. * @param[in] pPath The Request-URI to the objects of interest. This string @@ -270,8 +261,7 @@ static bool generateS3ObjectFilePresignedURL( const TransportInterface_t * pTran * * @return The status of the pre-signed URL generation: true on success, false on failure. */ -static bool printS3ObjectFilePresignedURL( const TransportInterface_t * pTransportInterface, - const char * pHost, +static bool printS3ObjectFilePresignedURL( const char * pHost, size_t hostLen, const char * pPath ); @@ -306,27 +296,9 @@ static SigV4Parameters_t sigv4Params = /*-----------------------------------------------------------*/ -static bool generateS3ObjectFilePresignedURL( const TransportInterface_t * pTransportInterface, - const char * pPath ) +static bool generateS3ObjectFilePresignedURL( const char * pPath ) { bool returnStatus = false; - - /* The number of bytes we want to request with in each range of the file - * bytes. */ - size_t numReqBytes = 0; - /* curByte indicates which starting byte we want to download next. */ - size_t curByte = 0; - - SigV4Status_t sigv4Status = SigV4Success; - SigV4HttpParameters_t sigv4HttpParams; - - char * pHeaders = NULL; - size_t headersLen = 0; - - /* Store Signature used in AWS HTTP requests generated using SigV4 library. */ - char * signature = NULL; - size_t signatureLen = 0; - assert( pPath != NULL ); /* Initialize all HTTP Client library API structs to 0. */ @@ -357,8 +329,7 @@ static bool generateS3ObjectFilePresignedURL( const TransportInterface_t * pTran response.bufferLen = USER_BUFFER_LENGTH; /* Generate and print the pre-signed URL. */ - returnStatus = printS3ObjectFilePresignedURL( pTransportInterface, - serverHost, + returnStatus = printS3ObjectFilePresignedURL( serverHost, serverHostLength, pPath ); return returnStatus; @@ -366,8 +337,7 @@ static bool generateS3ObjectFilePresignedURL( const TransportInterface_t * pTran /*-----------------------------------------------------------*/ -static bool printS3ObjectFilePresignedURL( const TransportInterface_t * pTransportInterface, - const char * pHost, +static bool printS3ObjectFilePresignedURL( const char * pHost, size_t hostLen, const char * pPath ) { @@ -433,27 +403,27 @@ static bool printS3ObjectFilePresignedURL( const TransportInterface_t * pTranspo * library and are not required by SigV4 library. */ getHeaderStartLocFromHttpRequest( requestHeaders, &pHeaders, &headersLen ); - // ////aws4_request - char x_amz_credentials[256] = ""; - strncat(x_amz_credentials, sigvCreds.pAccessKeyId, sigvCreds.accessKeyIdLen); - strcat(x_amz_credentials, "/"); - strncat(x_amz_credentials, pDateISO8601, 8); - strcat(x_amz_credentials, "/"); - strcat(x_amz_credentials, AWS_S3_BUCKET_REGION); - strcat(x_amz_credentials, "/s3/aws4_request"); - - // https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html - char canonical_queries[2048] = ""; - strcat(canonical_queries, "X-Amz-Algorithm="); - strcat(canonical_queries, SIGV4_AWS4_HMAC_SHA256); - strcat(canonical_queries, "&X-Amz-Credential="); - strcat(canonical_queries, x_amz_credentials); - strcat(canonical_queries, "&X-Amz-Date="); - strncat(canonical_queries, pDateISO8601, SIGV4_ISO_STRING_LEN); - strcat(canonical_queries, "&X-Amz-Expires=3600"); - strcat(canonical_queries, "&X-Amz-Security-Token="); - strncat(canonical_queries, pSecurityToken, securityTokenLen); - strcat(canonical_queries, "&X-Amz-SignedHeaders=host"); + /* ////aws4_request */ + char x_amz_credentials[ 256 ] = ""; + strncat( x_amz_credentials, sigvCreds.pAccessKeyId, sigvCreds.accessKeyIdLen ); + strcat( x_amz_credentials, "/" ); + strncat( x_amz_credentials, pDateISO8601, 8 ); + strcat( x_amz_credentials, "/" ); + strcat( x_amz_credentials, AWS_S3_BUCKET_REGION ); + strcat( x_amz_credentials, "/s3/aws4_request" ); + + /* https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html */ + char canonical_queries[ 2048 ] = ""; + strcat( canonical_queries, "X-Amz-Algorithm=" ); + strcat( canonical_queries, SIGV4_AWS4_HMAC_SHA256 ); + strcat( canonical_queries, "&X-Amz-Credential=" ); + strcat( canonical_queries, x_amz_credentials ); + strcat( canonical_queries, "&X-Amz-Date=" ); + strncat( canonical_queries, pDateISO8601, SIGV4_ISO_STRING_LEN ); + strcat( canonical_queries, "&X-Amz-Expires=3600" ); + strcat( canonical_queries, "&X-Amz-Security-Token=" ); + strncat( canonical_queries, pSecurityToken, securityTokenLen ); + strcat( canonical_queries, "&X-Amz-SignedHeaders=host" ); /* Setup the HTTP parameters. */ sigv4HttpParams.pHttpMethod = requestInfo.pMethod; @@ -463,7 +433,7 @@ static bool printS3ObjectFilePresignedURL( const TransportInterface_t * pTranspo sigv4HttpParams.pPath = requestInfo.pPath; sigv4HttpParams.pathLen = requestInfo.pathLen; sigv4HttpParams.pQuery = canonical_queries; - sigv4HttpParams.queryLen = strlen(canonical_queries); + sigv4HttpParams.queryLen = strlen( canonical_queries ); sigv4HttpParams.pHeaders = pHeaders; sigv4HttpParams.headersLen = headersLen; sigv4HttpParams.pPayload = S3_REQUEST_EMPTY_PAYLOAD; @@ -486,41 +456,45 @@ static bool printS3ObjectFilePresignedURL( const TransportInterface_t * pTranspo if( returnStatus == true ) { - char presigned_url[4096] = "https://" AWS_S3_ENDPOINT AWS_S3_URI_PATH "?"; - strcat(presigned_url, "X-Amz-Algorithm="); - strcat(presigned_url, SIGV4_AWS4_HMAC_SHA256); - strcat(presigned_url, "&X-Amz-Credential="); - size_t encodedLen = sizeof(presigned_url) - strlen(presigned_url); + char presigned_url[ 4096 ] = "https://" AWS_S3_ENDPOINT AWS_S3_URI_PATH "?"; + strcat( presigned_url, "X-Amz-Algorithm=" ); + strcat( presigned_url, SIGV4_AWS4_HMAC_SHA256 ); + strcat( presigned_url, "&X-Amz-Credential=" ); + size_t encodedLen = sizeof( presigned_url ) - strlen( presigned_url ); sigv4Status = SigV4_EncodeURI( x_amz_credentials, - strlen(x_amz_credentials), - presigned_url + strlen(presigned_url), + strlen( x_amz_credentials ), + presigned_url + strlen( presigned_url ), &encodedLen, - true/* encode slash */, - false/* do not double encode equal */ ); + true /* encode slash */, + false /* do not double encode equal */ ); + if( sigv4Status != SigV4Success ) { LogError( ( "Failed to run SigV4_EncodeURI on '%s'.", x_amz_credentials ) ); returnStatus = false; } - strcat(presigned_url, "&X-Amz-Date="); - strncat(presigned_url, pDateISO8601, SIGV4_ISO_STRING_LEN); - strcat(presigned_url, "&X-Amz-Expires=3600"); - strcat(presigned_url, "&X-Amz-SignedHeaders=host"); - strcat(presigned_url, "&X-Amz-Security-Token="); - encodedLen = sizeof(presigned_url) - strlen(presigned_url); + + strcat( presigned_url, "&X-Amz-Date=" ); + strncat( presigned_url, pDateISO8601, SIGV4_ISO_STRING_LEN ); + strcat( presigned_url, "&X-Amz-Expires=3600" ); + strcat( presigned_url, "&X-Amz-SignedHeaders=host" ); + strcat( presigned_url, "&X-Amz-Security-Token=" ); + encodedLen = sizeof( presigned_url ) - strlen( presigned_url ); sigv4Status = SigV4_EncodeURI( pSecurityToken, securityTokenLen, - presigned_url + strlen(presigned_url), + presigned_url + strlen( presigned_url ), &encodedLen, - true/* encode slash */, - false/* do not double encode equal */ ); + true /* encode slash */, + false /* do not double encode equal */ ); + if( sigv4Status != SigV4Success ) { LogError( ( "Failed to run SigV4_EncodeURI on '%s'.", pSecurityToken ) ); returnStatus = false; } - strcat(presigned_url, "&X-Amz-Signature="); - strncat(presigned_url, signature, signatureLen); + + strcat( presigned_url, "&X-Amz-Signature=" ); + strncat( presigned_url, signature, signatureLen ); LogInfo( ( "presigned_url=\n%s", presigned_url ) ); } @@ -542,7 +516,6 @@ int main( int argc, int32_t returnStatus = EXIT_SUCCESS; /* Return value of private functions. */ bool ret = false, credentialStatus = false; - int demoRunCount = 0; /* The transport layer interface used by the HTTP Client library. */ TransportInterface_t transportInterface = { NULL }; @@ -627,8 +600,7 @@ int main( int argc, if( returnStatus == EXIT_SUCCESS ) { - ret = generateS3ObjectFilePresignedURL( &transportInterface, - pPath ); + ret = generateS3ObjectFilePresignedURL( pPath ); returnStatus = ( ret == true ) ? EXIT_SUCCESS : EXIT_FAILURE; } } diff --git a/demos/lexicon.txt b/demos/lexicon.txt index 80367abd85..54b18faf50 100644 --- a/demos/lexicon.txt +++ b/demos/lexicon.txt @@ -742,6 +742,7 @@ statechanged std stderr stdlib +stdout strerror strlen struct diff --git a/manifest.yml b/manifest.yml index 0ed1da67e9..005ca373b6 100644 --- a/manifest.yml +++ b/manifest.yml @@ -26,7 +26,7 @@ dependencies: url: "https://github.com/aws/Device-Shadow-for-AWS-IoT-embedded-sdk" path: "libraries/aws/device-shadow-for-aws-iot-embedded-sdk" - name: "coreHTTP" - version: "48ccceb4bc048a36012ff33a0adbb49bc891045f" + version: "1749807ef26d17cc8e5a14ad1c57aba62ffb5b21" repository: type: "git" url: "https://github.com/FreeRTOS/coreHTTP" @@ -68,7 +68,7 @@ dependencies: url: "https://github.com/aws/Fleet-Provisioning-for-AWS-IoT-embedded-sdk" path: "libraries/aws/fleet-provisioning-for-aws-iot-embedded-sdk" - name: "sigv4-for-AWS-IoT-embedded-sdk" - version: "df863270afba4de9d013ae62063b2bfd0aa89039" + version: "e82835329069d804e0db883d69eb4e1124dd7f08" repository: type: "git" url: "https://github.com/aws/SigV4-for-AWS-IoT-embedded-sdk"