예제 #1
0
        internal string CreateCanonicalRequest(Guid requestId, string objectKey, HttpMethod method, IReadOnlyDictionary <string, string> headers, IReadOnlyDictionary <string, string> query, string contentHash)
        {
            _logger.LogTrace("Creating canonical request for {RequestId}", requestId);

            //Consists of:
            // HTTP Verb + \n
            // Canonical URI + \n
            // Canonical Query String + \n
            // Canonical Headers + \n
            // Signed Headers + \n
            // Sha256 Content Hash

            StringBuilder sb = StringBuilderPool.Shared.Rent(300);

            sb.Append(method.ToString()).Append(SigningConstants.Newline);
            sb.Append(CanonicalizeUri(objectKey)).Append(SigningConstants.Newline);
            sb.Append(CanonicalizeQueryParameters(query)).Append(SigningConstants.Newline);

            //Headers needs to be ordered by key
            OrderedDictionary <string, string> orderedHeaders = new OrderedDictionary <string, string>(headers.Count);

            foreach (KeyValuePair <string, string> item in headers.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase))
            {
                string loweredKey = item.Key.ToLowerInvariant();

                if (SigningConstants.ShouldSignHeader(loweredKey))
                {
                    orderedHeaders.Add(loweredKey, item.Value);
                }
            }

            sb.Append(CanonicalizeHeaders(orderedHeaders)).Append(SigningConstants.Newline);
            sb.Append(CanonicalizeHeaderNames(orderedHeaders)).Append(SigningConstants.Newline);
            sb.Append(contentHash);

            string canonicalRequest = sb.ToString();

            StringBuilderPool.Shared.Return(sb);

            _logger.LogDebug("CanonicalRequest: {CanonicalRequest}", canonicalRequest);
            return(canonicalRequest);
        }
예제 #2
0
        internal string CreateCanonicalRequest(Guid requestId, string url, HttpMethod method, IReadOnlyDictionary <string, string> headers, IReadOnlyDictionary <string, string> query, string contentHash)
        {
            _logger.LogTrace("Creating canonical request for {RequestId}", requestId);

            //Consists of:
            // HTTP Verb + \n
            // Canonical URI + \n
            // Canonical Query String + \n
            // Canonical Headers + \n
            // Signed Headers + \n
            // Sha256 Content Hash

            StringBuilder sb = StringBuilderPool.Shared.Rent(300);

            sb.Append(method.ToString()).Append(SigningConstants.Newline);
            sb.Append(url).Append(SigningConstants.Newline);
            sb.Append(CanonicalizeQueryParameters(query)).Append(SigningConstants.Newline);

            //Headers needs to be ordered by key
            OrderedDictionary <string, string> orderedHeaders = new OrderedDictionary <string, string>(SigningConstants.FilterHeaders(headers));

            sb.Append(CanonicalizeHeaders(orderedHeaders)).Append(SigningConstants.Newline);
            sb.Append(CanonicalizeHeaderNames(orderedHeaders)).Append(SigningConstants.Newline);
            sb.Append(contentHash);

            string canonicalRequest = sb.ToString();

            StringBuilderPool.Shared.Return(sb);

            _logger.LogDebug("CanonicalRequest: {CanonicalRequest}", canonicalRequest);
            return(canonicalRequest);
        }