private static Uri ConstructHostStyleNephosUri(Uri hostSuffix, NephosUriComponents uriComponents) { if (uriComponents.AccountName == null) { return(hostSuffix); } string accountName = uriComponents.AccountName; if (uriComponents.IsSecondaryAccountAccess) { accountName = uriComponents.GetSecondaryAccountName(); } Uri uri = HttpRequestAccessorJuly09.ConstructHostStyleAccountUri(hostSuffix, accountName); StringBuilder stringBuilder = new StringBuilder(string.Empty); if (uriComponents.ContainerName != null) { stringBuilder.Append(uriComponents.ContainerName); } if (uriComponents.RemainingPart != null) { if (uriComponents.ContainerName != null) { stringBuilder.Append("/"); } stringBuilder.Append(uriComponents.RemainingPart); } return(HttpRequestAccessorJuly09.ConstructUriFromUriAndString(uri, stringBuilder.ToString())); }
public static NephosUriComponents GetNephosHostStyleUriComponents(Uri uri, string accountName) { string str; string str1; NephosUriComponents nephosUriComponent = new NephosUriComponents(accountName); string[] uriPathSubStrings = HttpRequestAccessorJuly09.GetUriPathSubStrings(uri, 2); NephosUriComponents nephosUriComponent1 = nephosUriComponent; if ((int)uriPathSubStrings.Length <= 0 || string.IsNullOrEmpty(uriPathSubStrings[0])) { str = null; } else { str = uriPathSubStrings[0]; } nephosUriComponent1.ContainerName = str; NephosUriComponents nephosUriComponent2 = nephosUriComponent; if ((int)uriPathSubStrings.Length <= 1 || string.IsNullOrEmpty(uriPathSubStrings[1])) { str1 = null; } else { str1 = uriPathSubStrings[1]; } nephosUriComponent2.RemainingPart = str1; nephosUriComponent.IsRemainingPartPresentButEmpty = ((int)uriPathSubStrings.Length <= 1 || uriPathSubStrings[1] == null ? false : uriPathSubStrings[1].Length == 0); return(nephosUriComponent); }
public static NephosUriComponents GetNephosHostStyleUriComponents(Uri uri, string accountName) { string str; string str1; NephosUriComponents nephosUriComponent = new NephosUriComponents(accountName); string[] uriPathSubStrings = HttpRequestAccessor.GetUriPathSubStrings(uri, 2); NephosUriComponents nephosUriComponent1 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 0) { str = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[0]); } else { str = null; } nephosUriComponent1.ContainerName = str; NephosUriComponents nephosUriComponent2 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 1) { str1 = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[1]); } else { str1 = null; } nephosUriComponent2.RemainingPart = str1; return(nephosUriComponent); }
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)); }
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)); }
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)); }
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); }
public static Uri ConstructNephosUri(Uri endpoint, NephosUriComponents uriComponents, bool pathStyleUri) { NephosAssertionException.Assert(endpoint != null); NephosAssertionException.Assert(uriComponents != null); if (!pathStyleUri) { return(HttpRequestAccessorJuly09.ConstructHostStyleNephosUri(endpoint, uriComponents)); } return(HttpRequestAccessorJuly09.ConstructPathStyleNephosUri(endpoint, uriComponents)); }
private static string GetUriWithoutSecondarySuffix(string rawUrl, NephosUriComponents uriComponents) { if (uriComponents.IsUriPathStyle && uriComponents.IsSecondaryAccountAccess && !string.IsNullOrEmpty(rawUrl)) { int length = rawUrl.IndexOf(uriComponents.GetSecondaryAccountName(), 0, StringComparison.OrdinalIgnoreCase); if (length == 1) { length += uriComponents.AccountName.Length; rawUrl = rawUrl.Remove(length, "-secondary".Length); Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("removing secondary suffix : {0}", new object[] { rawUrl }); } } return(rawUrl); }
public static string ComputeMac(RequestContext requestContext, NephosUriComponents uriComponents, byte[] key) { string str; HMAC hMAC = HMACCryptoCache.Instance.Acquire(key); try { str = MessageHashFunctions.ComputeMacWithSpecificAlgorithm(hMAC, requestContext, uriComponents); } finally { HMACCryptoCache.Instance.Release(hMAC); } return(str); }
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); }
public static NephosUriComponents GetNephosPathStyleUriComponents(Uri uri) { string str; string str1; string str2; NephosUriComponents nephosUriComponent = new NephosUriComponents() { IsUriPathStyle = true }; string[] uriPathSubStrings = HttpRequestAccessorJuly09.GetUriPathSubStrings(uri, 3); NephosUriComponents nephosUriComponent1 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 0) { str = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[0]); } else { str = null; } nephosUriComponent1.AccountName = str; NephosUriComponents nephosUriComponent2 = nephosUriComponent; if ((int)uriPathSubStrings.Length <= 1 || string.IsNullOrEmpty(uriPathSubStrings[1])) { str1 = null; } else { str1 = uriPathSubStrings[1]; } nephosUriComponent2.ContainerName = str1; NephosUriComponents nephosUriComponent3 = nephosUriComponent; if ((int)uriPathSubStrings.Length <= 2 || string.IsNullOrEmpty(uriPathSubStrings[2])) { str2 = null; } else { str2 = uriPathSubStrings[2]; } nephosUriComponent3.RemainingPart = str2; nephosUriComponent.IsRemainingPartPresentButEmpty = ((int)uriPathSubStrings.Length <= 2 || uriPathSubStrings[2] == null ? false : uriPathSubStrings[2].Length == 0); return(nephosUriComponent); }
public static NephosUriComponents GetNephosPathStyleUriComponents(Uri uri) { string str; string str1; string str2; NephosUriComponents nephosUriComponent = new NephosUriComponents() { IsUriPathStyle = true }; string[] uriPathSubStrings = HttpRequestAccessor.GetUriPathSubStrings(uri, 3); NephosUriComponents nephosUriComponent1 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 0) { str = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[0]); } else { str = null; } nephosUriComponent1.AccountName = str; NephosUriComponents nephosUriComponent2 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 1) { str1 = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[1]); } else { str1 = null; } nephosUriComponent2.ContainerName = str1; NephosUriComponents nephosUriComponent3 = nephosUriComponent; if ((int)uriPathSubStrings.Length > 2) { str2 = HttpRequestAccessorCommon.TrimEndSlash(uriPathSubStrings[2]); } else { str2 = null; } nephosUriComponent3.RemainingPart = str2; return(nephosUriComponent); }
public static NephosUriComponents GetNephosUriComponents(Uri uri, string[] hostSuffixes, bool allowPathStyleUri, out bool uriIsPathStyle) { NephosUriComponents nephosUriComponent = null; if (HttpRequestAccessorJuly09.TryGetNephosHostStyleUriComponents(uri, hostSuffixes, out nephosUriComponent)) { uriIsPathStyle = false; return(nephosUriComponent); } if (!allowPathStyleUri) { uriIsPathStyle = false; return(null); } uriIsPathStyle = true; return(HttpRequestAccessorJuly09.GetNephosPathStyleUriComponents(uri)); }
private static Uri ConstructStorageDomainStyleNephosUri(Uri storageDomain, NephosUriComponents uriComponents) { StringBuilder stringBuilder = new StringBuilder(string.Empty); if (uriComponents.ContainerName != null) { stringBuilder.Append(uriComponents.ContainerName); } if (uriComponents.RemainingPart != null) { if (uriComponents.ContainerName != null) { stringBuilder.Append("/"); } stringBuilder.Append(uriComponents.RemainingPart); } return(HttpRequestAccessorJuly09.ConstructUriFromUriAndString(storageDomain, stringBuilder.ToString())); }
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 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 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)); }
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()); }
private static Uri ConstructPathStyleNephosUri(Uri endpoint, NephosUriComponents uriComponents) { StringBuilder stringBuilder = new StringBuilder(string.Empty); if (uriComponents.AccountName != null) { stringBuilder.Append(uriComponents.AccountName); if (uriComponents.IsSecondaryAccountAccess) { stringBuilder.Append("-secondary"); } if (uriComponents.ContainerName != null) { stringBuilder.Append("/"); stringBuilder.Append(uriComponents.ContainerName); } if (uriComponents.RemainingPart != null) { stringBuilder.Append("/"); stringBuilder.Append(uriComponents.RemainingPart); } } return(HttpRequestAccessorJuly09.ConstructUriFromUriAndString(endpoint, stringBuilder.ToString())); }
private static bool TryGetNephosHostStyleUriComponents(Uri uri, string[] hostSuffixes, out NephosUriComponents uriComponents) { uriComponents = null; string host = uri.Host; string[] strArrays = hostSuffixes; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; if (host.EndsWith(str, StringComparison.OrdinalIgnoreCase)) { string str1 = host.Substring(0, host.Length - str.Length); if (str1.Length > 0 && str1[str1.Length - 1] == HttpRequestAccessorCommon.subDomainDelimiterChar && str1.Length > 1) { string str2 = str1.Substring(0, str1.Length - 1); uriComponents = HttpRequestAccessorJuly09.GetNephosHostStyleUriComponents(uri, str2); return(true); } } } return(false); }
public static Uri ConstructStorageDomainUri(Uri endpoint, NephosUriComponents uriComponents) { NephosAssertionException.Assert(endpoint != null); NephosAssertionException.Assert(uriComponents != null); return(HttpRequestAccessorJuly09.ConstructStorageDomainStyleNephosUri(endpoint, uriComponents)); }
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)); }
public static string ComputeMacWithSpecificAlgorithm(HMAC algorithm, RequestContext requestContext, NephosUriComponents uriComponents) { string str = MessageCanonicalizer.CanonicalizeHttpRequest(requestContext, uriComponents, false); return(MessageHashFunctions.ComputeMacWithSpecificAlgorithm(algorithm, str)); }
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)); }