char key_service[SHA256_DIGEST_LENGTH];
char* aws4_secret_access_key = switch_mprintf("AWS4%s", aws_s3_profile->access_key_secret);
- hmac256(key_date, SHA256_DIGEST_LENGTH, aws4_secret_access_key, strlen(aws4_secret_access_key), aws_s3_profile->date_stamp);
- hmac256(key_region, SHA256_DIGEST_LENGTH, key_date, SHA256_DIGEST_LENGTH, aws_s3_profile->region);
- hmac256(key_service, SHA256_DIGEST_LENGTH, key_region, SHA256_DIGEST_LENGTH, "s3");
- hmac256(key_signing, SHA256_DIGEST_LENGTH, key_service, SHA256_DIGEST_LENGTH, "aws4_request");
+ if (!hmac256(key_date, SHA256_DIGEST_LENGTH, aws4_secret_access_key, (unsigned int)strlen(aws4_secret_access_key), aws_s3_profile->date_stamp)
+ || !hmac256(key_region, SHA256_DIGEST_LENGTH, key_date, SHA256_DIGEST_LENGTH, aws_s3_profile->region)
+ || !hmac256(key_service, SHA256_DIGEST_LENGTH, key_region, SHA256_DIGEST_LENGTH, "s3")
+ || !hmac256(key_signing, SHA256_DIGEST_LENGTH, key_service, SHA256_DIGEST_LENGTH, "aws4_request")) {
+ key_signing = NULL;
+ }
switch_safe_free(aws4_secret_access_key);
char* standardized_query_string;
credential = switch_mprintf("%s%%2F%s%%2F%s%%2Fs3%%2Faws4_request", aws_s3_profile->access_key_id, aws_s3_profile->date_stamp, aws_s3_profile->region);
- switch_snprintf(expires, 9, "%ld", aws_s3_profile->expires);
+ switch_snprintf(expires, 9, "%" SWITCH_TIME_T_FMT, aws_s3_profile->expires);
standardized_query_string = switch_mprintf(
"X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%s&X-Amz-Date=%s&X-Amz-Expires=%s&X-Amz-SignedHeaders=host",
string_to_sign = aws_s3_string_to_sign(standardized_request, aws_s3_profile);
// Get signature_key
- aws_s3_signature_key(signature_key, aws_s3_profile);
-
- // Get signature
- hmac256_hex(signature, signature_key, SHA256_DIGEST_LENGTH, string_to_sign);
-
- // Build final query string
- query_param = switch_mprintf("%s&X-Amz-Signature=%s", standardized_query_string, signature);
+ if (!aws_s3_signature_key(signature_key, aws_s3_profile)
+ // Get signature
+ || !hmac256_hex(signature, signature_key, SHA256_DIGEST_LENGTH, string_to_sign)) {
+ query_param = NULL;
+ } else {
+ // Build final query string
+ query_param = switch_mprintf("%s&X-Amz-Signature=%s", standardized_query_string, signature);
+ }
switch_safe_free(string_to_sign);
switch_safe_free(standardized_query_string);