MCPcopy Create free account
hub / github.com/apache/trafficserver / getAuthorizationHeader

Method getAuthorizationHeader

plugins/origin_server_auth/aws_auth_v4.cc:724–759  ·  view source on GitHub ↗

* @brief Get the value of the Authorization header (AWS authorization) v4 * @return the Authorization header value */

Source from the content-addressed store, hash-verified

722 * @return the Authorization header value
723 */
724String
725AwsAuthV4::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

Callers 2

authorizeAwsV4Method · 0.80
ValidateBenchFunction · 0.80

Calls 10

getRegionFunction · 0.85
getStringToSignFunction · 0.85
getSignatureFunction · 0.85
base16EncodeFunction · 0.85
StringClass · 0.50
getHostMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45
strMethod · 0.45

Tested by 1

ValidateBenchFunction · 0.64