コード例 #1
0
 private static string SanitizeRawUrl(string rawUrl)
 {
     if (rawUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
     {
         int num  = 0;
         int num1 = 0;
         int num2 = 0;
         while (num2 < rawUrl.Length)
         {
             if (rawUrl[num2] == '/')
             {
                 num1++;
             }
             if (num1 != 3)
             {
                 num2++;
             }
             else
             {
                 num = num2;
                 break;
             }
         }
         if (num == 0)
         {
             return("/");
         }
         rawUrl = rawUrl.Substring(num);
     }
     return(MessageCanonicalizer.DiscardQueryString(rawUrl));
 }
コード例 #2
0
 public static string CanonicalizeHttpRequest(RequestContext requestContext, NephosUriComponents uriComponents, bool isFileService = false)
 {
     if (!MessageCanonicalizer.IsVersionBeforeSep09(requestContext.RequestHeaders))
     {
         return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(uriComponents, requestContext, isFileService));
     }
     return(MessageCanonicalizer.CanonicalizeHttpRequestDefault(requestContext.RequestUrl, uriComponents, requestContext.HttpMethod, requestContext.RequestContentType, requestContext.RequestHeaders, isFileService, requestContext.RequestRawUrlString));
 }
コード例 #3
0
 public static string CanonicalizeHttpRequest(HttpWebRequest request, NephosUriComponents uriComponents)
 {
     if (!MessageCanonicalizer.IsVersionBeforeSep09(request.Headers))
     {
         return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(uriComponents, request));
     }
     return(MessageCanonicalizer.CanonicalizeHttpRequestDefault(request.Address, uriComponents, request.Method, request.ContentType, request.Headers, false, null));
 }
コード例 #4
0
 public static string CanonicalizeHttpRequest(Uri uri, NephosUriComponents uriComponents, string method, NameValueCollection headers, bool multipleConditionalHeadersEnabled = false)
 {
     if (!MessageCanonicalizer.IsVersionBeforeSep09(headers["x-ms-version"]))
     {
         return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(uri, uriComponents, method, headers, false, null, multipleConditionalHeadersEnabled));
     }
     return(MessageCanonicalizer.CanonicalizeHttpRequestDefault(uri, uriComponents, method, headers["Content-Type"], headers, false, null));
 }
コード例 #5
0
        public static string CanonicalizeHttpRequestVer1(Uri address, NephosUriComponents uriComponents, string method, string contentEncoding, string contentLanguage, string contentLength, string contentMD5, string contentType, string date, string ifModifiedSince, string ifMatch, string ifNoneMatch, string ifUnmodifiedSince, string range, NameValueCollection headers, bool isFileService = false, string rawUrl = null, bool multipleConditionalHeadersEnabled = false)
        {
            NephosAssertionException.Assert(address != null);
            NephosAssertionException.Assert(uriComponents != null);
            NephosAssertionException.Assert(!string.IsNullOrEmpty(method));
            NephosAssertionException.Assert(headers != null);
            MessageCanonicalizer.CanonicalizedString canonicalizedString = new MessageCanonicalizer.CanonicalizedString(method);
            canonicalizedString.AppendCanonicalizedElement(contentEncoding ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(contentLanguage ?? string.Empty);
            if (contentLength == null || !MessageCanonicalizer.IsVersionBeforeFeb15(headers) && contentLength.Equals("0"))
            {
                canonicalizedString.AppendCanonicalizedElement(string.Empty);
            }
            else
            {
                canonicalizedString.AppendCanonicalizedElement(contentLength);
            }
            canonicalizedString.AppendCanonicalizedElement(contentMD5 ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(contentType ?? string.Empty);
            if (headers["x-ms-date"] != null)
            {
                canonicalizedString.AppendCanonicalizedElement(string.Empty);
            }
            else
            {
                canonicalizedString.AppendCanonicalizedElement(date ?? string.Empty);
            }
            canonicalizedString.AppendCanonicalizedElement(ifModifiedSince ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(ifMatch ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(ifNoneMatch ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(ifUnmodifiedSince ?? string.Empty);
            canonicalizedString.AppendCanonicalizedElement(range ?? string.Empty);
            ArrayList arrayLists = new ArrayList();

            foreach (string key in headers.Keys)
            {
                if (key == null || !key.ToLowerInvariant().StartsWith("x-ms-", StringComparison.Ordinal))
                {
                    continue;
                }
                arrayLists.Add(key.ToLowerInvariant());
            }
            arrayLists.Sort();
            foreach (string arrayList in arrayLists)
            {
                string canonicalizedHeaderValueVer1 = MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, arrayList, multipleConditionalHeadersEnabled);
                if (string.IsNullOrEmpty(canonicalizedHeaderValueVer1) && !isFileService && MessageCanonicalizer.IsVersionBeforeFeb16(headers["x-ms-version"]))
                {
                    continue;
                }
                StringBuilder stringBuilder = new StringBuilder(arrayList);
                stringBuilder.Append(":");
                stringBuilder.Append(canonicalizedHeaderValueVer1);
                canonicalizedString.AppendCanonicalizedElement(stringBuilder.ToString());
            }
            canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetCanonicalizedResourceVer1(address, uriComponents, rawUrl));
            return(canonicalizedString.Value);
        }
コード例 #6
0
        private static string GetUriStringToSign(string absolutePath, string rawUrl)
        {
            string str = absolutePath;

            if (rawUrl == null)
            {
                return(str);
            }
            str = MessageCanonicalizer.SanitizeRawUrl(rawUrl);
            return(str);
        }
コード例 #7
0
        public static string ComputeMac(HttpWebRequest request, NephosUriComponents uriComponents, byte[] key)
        {
            string str;
            string str1 = MessageCanonicalizer.CanonicalizeHttpRequest(request, uriComponents);
            HMAC   hMAC = HMACCryptoCache.Instance.Acquire(key);

            try
            {
                str = MessageHashFunctions.ComputeMacWithSpecificAlgorithm(hMAC, str1);
            }
            finally
            {
                HMACCryptoCache.Instance.Release(hMAC);
            }
            return(str);
        }
コード例 #8
0
        public static string GetCanonicalizedResourceVer1(Uri uri, NephosUriComponents uriComponents, string rawUrl = null)
        {
            NephosAssertionException.Assert((uriComponents == null ? false : !string.IsNullOrEmpty(uriComponents.AccountName)), "Resource account name must be non-empty.");
            StringBuilder stringBuilder = new StringBuilder("/");

            stringBuilder.Append(uriComponents.AccountName);
            string uriStringToSign = MessageCanonicalizer.GetUriStringToSign(uri.AbsolutePath, rawUrl);

            stringBuilder.Append(MessageCanonicalizer.GetUriWithoutSecondarySuffix(uriStringToSign, uriComponents));
            MessageCanonicalizer.CanonicalizedString canonicalizedString = new MessageCanonicalizer.CanonicalizedString(stringBuilder.ToString());
            NameValueCollection nameValueCollection  = HttpUtility.ParseQueryString(uri.Query);
            NameValueCollection nameValueCollection1 = new NameValueCollection();

            foreach (string key in nameValueCollection.Keys)
            {
                object[] values = nameValueCollection.GetValues(key);
                Array.Sort <object>(values);
                StringBuilder stringBuilder1 = new StringBuilder();
                object[]      objArray       = values;
                for (int i = 0; i < (int)objArray.Length; i++)
                {
                    object obj = objArray[i];
                    if (stringBuilder1.Length > 0)
                    {
                        stringBuilder1.Append(",");
                    }
                    stringBuilder1.Append(obj.ToString());
                }
                nameValueCollection1.Add((key == null ? key : key.ToLowerInvariant()), stringBuilder1.ToString());
            }
            string[] allKeys = nameValueCollection1.AllKeys;
            Array.Sort <string>(allKeys);
            string[] strArrays = allKeys;
            for (int j = 0; j < (int)strArrays.Length; j++)
            {
                string        str            = strArrays[j];
                StringBuilder stringBuilder2 = new StringBuilder(string.Empty);
                stringBuilder2.Append(str);
                stringBuilder2.Append(":");
                stringBuilder2.Append(nameValueCollection1[str]);
                canonicalizedString.AppendCanonicalizedElement(stringBuilder2.ToString());
            }
            return(canonicalizedString.Value);
        }
コード例 #9
0
        public static string CanonicalizeHttpRequestDefault(Uri address, NephosUriComponents uriComponents, string method, string contentType, NameValueCollection headers, bool isFileService = false, string rawUrl = null)
        {
            MessageCanonicalizer.CanonicalizedString canonicalizedString = new MessageCanonicalizer.CanonicalizedString(method);
            canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetContentMD5(headers));
            canonicalizedString.AppendCanonicalizedElement(contentType);
            string str = null;

            if (HttpRequestAccessorCommon.GetHeaderValues(headers, "x-ms-date").Count <= 0)
            {
                string[] values = headers.GetValues("Date");
                str = (values == null || (int)values.Length == 0 ? string.Empty : values[0]);
            }
            else
            {
                str = null;
            }
            canonicalizedString.AppendCanonicalizedElement(str);
            ArrayList arrayLists = new ArrayList();

            foreach (string key in headers.Keys)
            {
                if (key == null || !key.ToLowerInvariant().StartsWith("x-ms-", StringComparison.Ordinal))
                {
                    continue;
                }
                arrayLists.Add(key.ToLowerInvariant());
            }
            arrayLists.Sort();
            foreach (string arrayList in arrayLists)
            {
                string canonicalizedHeaderValue = MessageCanonicalizer.GetCanonicalizedHeaderValue(headers, arrayList);
                if (string.IsNullOrEmpty(canonicalizedHeaderValue) && !isFileService && MessageCanonicalizer.IsVersionBeforeFeb16(headers["x-ms-version"]))
                {
                    continue;
                }
                StringBuilder stringBuilder = new StringBuilder(arrayList);
                stringBuilder.Append(":");
                stringBuilder.Append(canonicalizedHeaderValue);
                canonicalizedString.AppendCanonicalizedElement(stringBuilder.ToString());
            }
            canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetCanonicalizedResource(address, uriComponents, rawUrl));
            return(canonicalizedString.Value);
        }
コード例 #10
0
        public static string CanonicalizeHttpRequestVer1(NephosUriComponents uriComponents, HttpWebRequest request)
        {
            string canonicalizedHeaderValue;
            Uri    address = request.Address;
            NephosUriComponents nephosUriComponent = uriComponents;
            string method = request.Method;
            string str    = MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Content-Encoding");
            string canonicalizedHeaderValue1 = MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Content-Language");

            if (request.Headers["Content-Length"] != null)
            {
                canonicalizedHeaderValue = MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Content-Length");
            }
            else
            {
                canonicalizedHeaderValue = (request.ContentLength < (long)0 ? string.Empty : Convert.ToString(request.ContentLength));
            }
            return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(address, nephosUriComponent, method, str, canonicalizedHeaderValue1, canonicalizedHeaderValue, MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Content-MD5"), (request.Headers["Content-Type"] != null ? MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Content-Type") : request.ContentType), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Date"), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "If-Modified-Since"), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "If-Match"), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "If-None-Match"), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "If-Unmodified-Since"), MessageCanonicalizer.GetCanonicalizedHeaderValue(request.Headers, "Range"), request.Headers, false, null, false));
        }
コード例 #11
0
        public static string GetCanonicalizedResource(Uri address, NephosUriComponents uriComponents, string rawUrl = null)
        {
            NephosAssertionException.Assert(!string.IsNullOrEmpty(uriComponents.AccountName), "Resource account name must be non-empty.");
            StringBuilder stringBuilder = new StringBuilder("/");

            stringBuilder.Append(uriComponents.AccountName);
            string uriStringToSign = MessageCanonicalizer.GetUriStringToSign(address.AbsolutePath, rawUrl);

            stringBuilder.Append(MessageCanonicalizer.GetUriWithoutSecondarySuffix(uriStringToSign, uriComponents));
            string item = HttpUtility.ParseQueryString(address.Query)["comp"];

            if (item != null)
            {
                stringBuilder.Append("?");
                stringBuilder.Append("comp");
                stringBuilder.Append("=");
                stringBuilder.Append(item);
            }
            return(stringBuilder.ToString());
        }
コード例 #12
0
        public static string ComputeMacWithSpecificAlgorithm(HMAC algorithm, RequestContext requestContext, NephosUriComponents uriComponents)
        {
            string str = MessageCanonicalizer.CanonicalizeHttpRequest(requestContext, uriComponents, false);

            return(MessageHashFunctions.ComputeMacWithSpecificAlgorithm(algorithm, str));
        }
コード例 #13
0
 public static string CanonicalizeHttpRequestVer1(Uri uri, NephosUriComponents uriComponents, string method, NameValueCollection headers, bool isFileService = false, string rawUrl = null, bool multipleConditionalHeadersEnabled = false)
 {
     return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(uri, uriComponents, method, MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Encoding", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Language", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Length", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-MD5", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Type", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Date", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Modified-Since", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Match", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-None-Match", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Unmodified-Since", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Range", multipleConditionalHeadersEnabled), headers, isFileService, rawUrl, multipleConditionalHeadersEnabled));
 }
コード例 #14
0
 public static bool IsVersionBeforeSep09(NameValueCollection requestHeaders)
 {
     return(MessageCanonicalizer.IsVersionBeforeSep09(requestHeaders["x-ms-version"]));
 }
コード例 #15
0
        public static string GetNephosOrStandardDateString(NameValueCollection headers)
        {
            string str = null;

            str = (HttpRequestAccessorCommon.GetHeaderValues(headers, "x-ms-date").Count <= 0 ? headers.GetValues("Date")[0] : MessageCanonicalizer.GetCanonicalizedHeaderValue(headers, "x-ms-date"));
            return(str);
        }
コード例 #16
0
 public static string CanonicalizeHttpRequestVer1(NephosUriComponents uriComponents, RequestContext requestContext, bool isFileService = false)
 {
     return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(requestContext.RequestUrl, uriComponents, requestContext.HttpMethod, requestContext.RequestHeaders, isFileService, requestContext.RequestRawUrlString, requestContext.MultipleConditionalHeadersEnabled));
 }