Пример #1
0
        public void Decode(string sasIdentifier)
        {
            ASCIIEncoding   aSCIIEncoding   = new ASCIIEncoding();
            UnicodeEncoding unicodeEncoding = new UnicodeEncoding();

            SASUtilities.ValidateACIIEncoding(sasIdentifier);
            NameValueCollection nameValueCollection = new NameValueCollection();

            MetadataEncoding.Decode(aSCIIEncoding.GetBytes(sasIdentifier), nameValueCollection);
            string item  = nameValueCollection[SASIdentifier.IdName];
            string str   = nameValueCollection[SASAccessPolicy.SignedStartName];
            string item1 = nameValueCollection[SASAccessPolicy.SignedExpiryName];
            string str1  = nameValueCollection[SASAccessPolicy.SignedPermissionName];

            if (!string.IsNullOrEmpty(item))
            {
                this.Id = unicodeEncoding.GetString(Convert.FromBase64String(item));
            }
            if (!string.IsNullOrEmpty(str))
            {
                this.AccessPolicy.SignedStart = new DateTime?(SASUtilities.ParseTime(str));
            }
            if (!string.IsNullOrEmpty(item1))
            {
                this.AccessPolicy.SignedExpiry = new DateTime?(SASUtilities.ParseTime(item1));
            }
            if (!string.IsNullOrEmpty(str1))
            {
                this.AccessPolicy.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(str1));
            }
        }
Пример #2
0
 public override void ParseAccessPolicyFields(bool isDoubleSigned)
 {
     try
     {
         if (isDoubleSigned)
         {
             string str = base.ExtractSignedAuthorization(base.RequestContext);
             base.ValidateMandatoryField(str, "SignedKey");
             base.ValidateSignedAuthorizationFormat(str);
         }
         else
         {
             string item = base.QueryParams["sig"];
             base.ValidateMandatoryField(item, "sig");
             base.ValidateSignatureFormat(item);
             base.Signature = item;
         }
         string item1 = base.QueryParams["si"];
         base.ValidateOptionalField(item1, "si");
         base.SignedIdentifier = item1;
         string str1 = base.QueryParams["sv"];
         base.ValidateMandatoryField(str1, "sv");
         this.ValidateSASVersion(str1);
         base.ParseAccessPolicyFields(isDoubleSigned);
         string item2 = base.QueryParams["sp"];
         if (!base.IsRevocableAccess)
         {
             base.ValidateMandatoryField(item2, "sp");
             SASUtilities.ValidatePermissionOrdering(item2, SASPermission.Queue);
             base.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(item2));
         }
         else
         {
             base.ValidateOptionalField(item2, "sp");
             if (item2 != null)
             {
                 SASUtilities.ValidatePermissionOrdering(item2, SASPermission.Queue);
                 base.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(item2));
             }
         }
         string str2 = AuthenticationManagerHelper.ExtractKeyNameFromParamsWithConversion(base.QueryParams);
         base.ValidateOptionalField(str2, "sk");
         if (str2 != null)
         {
             base.KeyName = str2.Trim();
             Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("Using secret key with KeyName '{0}' to authenticate SAS request.", new object[] { base.KeyName });
         }
     }
     catch (FormatException formatException)
     {
         throw new AuthenticationFailureException("Signature fields not well formed.", formatException);
     }
 }
Пример #3
0
 public SASAccessPolicy(string signedStart, string signedExpiry, string signedPermission)
 {
     if (!string.IsNullOrEmpty(signedStart))
     {
         this.SignedStart = new DateTime?(SASUtilities.ParseTime(signedStart));
     }
     if (!string.IsNullOrEmpty(signedExpiry))
     {
         this.SignedExpiry = new DateTime?(SASUtilities.ParseTime(signedExpiry));
     }
     if (!string.IsNullOrEmpty(signedPermission))
     {
         this.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(signedPermission));
     }
 }
Пример #4
0
 public override void ParseAccessPolicyFields(bool isDoubleSigned)
 {
     try
     {
         if (isDoubleSigned)
         {
             string str = base.ExtractSignedAuthorization(base.RequestContext);
             base.ValidateMandatoryField(str, "SignedKey");
             base.ValidateSignedAuthorizationFormat(str);
         }
         else
         {
             string item = base.QueryParams["sig"];
             base.ValidateMandatoryField(item, "sig");
             base.ValidateSignatureFormat(item);
             base.Signature = item;
         }
         string item1 = base.QueryParams["si"];
         base.ValidateOptionalField(item1, "si");
         base.SignedIdentifier = item1;
         string str1 = base.QueryParams["tn"];
         base.ValidateMandatoryField(str1, "tn");
         this.TableName = str1.ToLower();
         string item2 = base.QueryParams["spk"];
         this.StartingPartitionKey = item2;
         string str2 = base.QueryParams["srk"];
         if (item2 == null && str2 != null)
         {
             throw new AuthenticationFailureException(string.Format("{0} is required when {1} is provided.", "srk", "spk"));
         }
         this.StartingRowKey = str2;
         string item3 = base.QueryParams["epk"];
         this.EndingPartitionKey = item3;
         string str3 = base.QueryParams["erk"];
         if (item3 == null && str3 != null)
         {
             throw new AuthenticationFailureException(string.Format("{0} is required when {1} is provided.", "erk", "epk"));
         }
         this.EndingRowKey = str3;
         string item4 = base.QueryParams["sv"];
         base.ValidateMandatoryField(item4, "sv");
         this.ValidateSASVersion(item4);
         base.ParseAccessPolicyFields(isDoubleSigned);
         string str4 = base.QueryParams["sp"];
         if (!base.IsRevocableAccess)
         {
             base.ValidateMandatoryField(str4, "sp");
             SASUtilities.ValidatePermissionOrdering(str4, SASPermission.Table);
             base.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(str4));
         }
         else
         {
             base.ValidateOptionalField(str4, "sp");
             if (str4 != null)
             {
                 SASUtilities.ValidatePermissionOrdering(str4, SASPermission.Table);
                 base.SignedPermission = new SASPermission?(SASUtilities.ParseSASPermission(str4));
             }
         }
         string str5 = AuthenticationManagerHelper.ExtractKeyNameFromParamsWithConversion(base.QueryParams);
         base.ValidateOptionalField(str5, "sk");
         if (str5 != null)
         {
             base.KeyName = str5.Trim();
             Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("Using secret key with KeyName '{0}' to authenticate SAS request.", new object[] { base.KeyName });
         }
     }
     catch (FormatException formatException)
     {
         throw new AuthenticationFailureException("Signature fields not well formed.", formatException);
     }
 }