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); }
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); }
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); }