예제 #1
0
        public override byte[] ComputeUrlDecodedUtf8EncodedStringToSign()
        {
            string item;
            string str                  = base.QueryParams["st"];
            string item1                = base.QueryParams["se"];
            string str1                 = base.QueryParams["sp"];
            string signedIdentifier     = base.SignedIdentifier ?? string.Empty;
            string item2                = base.QueryParams["sip"];
            string str2                 = base.QueryParams["spr"];
            string item3                = base.QueryParams["sv"];
            string tableName            = this.TableName ?? string.Empty;
            string startingPartitionKey = this.StartingPartitionKey ?? string.Empty;
            string startingRowKey       = this.StartingRowKey ?? string.Empty;
            string endingPartitionKey   = this.EndingPartitionKey ?? string.Empty;
            string endingRowKey         = this.EndingRowKey ?? string.Empty;

            if (base.SignedExtraPermission.HasValue)
            {
                item = base.QueryParams["sep"];
            }
            else
            {
                item = null;
            }
            return(TableSignedAccessHelper.ComputeUrlDecodedUtf8EncodedStringToSign(str, item1, str1, signedIdentifier, item2, str2, item3, tableName, startingPartitionKey, startingRowKey, endingPartitionKey, endingRowKey, item, base.UriComponents));
        }
예제 #2
0
        public static AuthDataEntry SignedKeyAuthenticate(string stringToSign, string requestSignature, AuthenticationInformation authInfo)
        {
            AuthDataEntry authDataEntry;

            NephosAssertionException.Assert(!string.IsNullOrEmpty(stringToSign));
            NephosAssertionException.Assert(!string.IsNullOrEmpty(requestSignature));
            NephosAssertionException.Assert(authInfo != null);
            RequestContext      requestContext  = authInfo.RequestContext;
            NephosUriComponents uriComponents   = authInfo.UriComponents;
            NameValueCollection queryParameters = requestContext.QueryParameters;
            string item  = queryParameters["st"];
            string str   = queryParameters["se"];
            string item1 = queryParameters["sp"];
            string str1  = queryParameters["si"];
            string item2 = queryParameters["sip"];
            string str2  = queryParameters["spr"];
            string item3 = queryParameters["sv"];
            string str3  = queryParameters["tn"];
            string item4 = queryParameters["spk"];
            string str4  = queryParameters["srk"];
            string item5 = queryParameters["epk"];
            string str5  = queryParameters["erk"];
            string item6 = queryParameters["sep"];

            byte[] sign = TableSignedAccessHelper.ComputeUrlDecodedUtf8EncodedStringToSign(item, str, item1, str1, item2, str2, item3, str3, item4, str4, item5, str5, item6, uriComponents);
            authInfo.AuthKeyName = AuthenticationManagerHelper.ExtractKeyNameFromParamsWithConversion(queryParameters);
            using (IEnumerator <AuthDataEntry> enumerator = SharedKeyAuthInfoHelper.GetSharedKeys(authInfo).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    AuthDataEntry current  = enumerator.Current;
                    byte[]        numArray = SASUtilities.ComputeSignedKey(sign, current.AuthValue);
                    if (!SASUtilities.ComputeSignatureAndCompare((new UTF8Encoding()).GetBytes(stringToSign), numArray, requestSignature))
                    {
                        continue;
                    }
                    authDataEntry = current;
                    return(authDataEntry);
                }
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                object[]    objArray         = new object[] { requestSignature, stringToSign };
                throw new AuthenticationFailureException(string.Format(invariantCulture, "The MAC signature found in the HTTP request '{0}' is not the same as any computed signature. Server used following string to sign: '{1}'.", objArray));
            }
            return(authDataEntry);
        }