* @brief Get the value of the Authorization header (AWS authorization) v4 * @return the Authorization header value */
| 722 | * @return the Authorization header value |
| 723 | */ |
| 724 | String |
| 725 | AwsAuthV4::getAuthorizationHeader() |
| 726 | { |
| 727 | String signedHeaders; |
| 728 | String canonicalReq = getCanonicalRequestSha256Hash(_api, _signPayload, _includedHeaders, _excludedHeaders, signedHeaders); |
| 729 | |
| 730 | int hostLen = 0; |
| 731 | const char *host = _api.getHost(&hostLen); |
| 732 | |
| 733 | String awsRegion = getRegion(_regionMap, host, hostLen); |
| 734 | |
| 735 | String stringToSign = getStringToSign(_dateTime, sizeof(_dateTime) - 1, awsRegion.c_str(), awsRegion.length(), _awsService, |
| 736 | _awsServiceLen, canonicalReq.c_str(), canonicalReq.length()); |
| 737 | #ifdef AWS_AUTH_V4_DETAILED_DEBUG_OUTPUT |
| 738 | std::cout << "<StringToSign>" << stringToSign << "</StringToSign>" << std::endl; |
| 739 | #endif |
| 740 | |
| 741 | char signature[EVP_MAX_MD_SIZE] = ""; |
| 742 | size_t signatureLen = |
| 743 | getSignature(_awsSecretAccessKey, _awsSecretAccessKeyLen, awsRegion.c_str(), awsRegion.length(), _awsService, _awsServiceLen, |
| 744 | _dateTime, 8, stringToSign.c_str(), stringToSign.length(), signature, EVP_MAX_MD_SIZE); |
| 745 | |
| 746 | String base16Signature = base16Encode(signature, signatureLen); |
| 747 | #ifdef AWS_AUTH_V4_DETAILED_DEBUG_OUTPUT |
| 748 | std::cout << "<SignatureProvided>" << base16Signature << "</SignatureProvided>" << std::endl; |
| 749 | #endif |
| 750 | |
| 751 | std::stringstream authorizationHeader; |
| 752 | authorizationHeader << "AWS4-HMAC-SHA256 "; |
| 753 | authorizationHeader << "Credential=" << String(_awsAccessKeyId, _awsAccessKeyIdLen) << "/" << String(_dateTime, 8) << "/" |
| 754 | << awsRegion << "/" << String(_awsService, _awsServiceLen) << "/" << "aws4_request" << ","; |
| 755 | authorizationHeader << "SignedHeaders=" << signedHeaders << ","; |
| 756 | authorizationHeader << "Signature=" << base16Signature; |
| 757 | |
| 758 | return authorizationHeader.str(); |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * @brief Authorization v4 constructor |