Пример #1
0
		public void AddConnectAccess (string originScheme, CodeConnectAccess connectAccess)
		{
			if (originScheme == null)
				throw new ArgumentException ("originScheme");

			// TODO (2.0) - invalid characters in originScheme
			if ((originScheme == AbsentOriginScheme) && (connectAccess.Scheme == CodeConnectAccess.OriginScheme)) {
				throw new ArgumentOutOfRangeException ("connectAccess", Locale.GetText (
					"Schema == CodeConnectAccess.OriginScheme"));
			}

			if (_rules.ContainsKey (originScheme)) {
				// NULL has no effect
				if (connectAccess != null) {
					CodeConnectAccess[] existing = (CodeConnectAccess[]) _rules [originScheme];
					CodeConnectAccess[] array = new CodeConnectAccess [existing.Length + 1];
					Array.Copy (existing, 0, array, 0, existing.Length);
					array [existing.Length] = connectAccess;
					_rules [originScheme] = array;
				}
			}
			else {
				CodeConnectAccess[] array = new CodeConnectAccess [1];
				array [0] = connectAccess;
				_rules.Add (originScheme, array);
				// add null to prevent access
			}
		}
Пример #2
0
 public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
 {
     if (originScheme == null)
     {
         throw new ArgumentException("originScheme");
     }
     if (originScheme == NetCodeGroup.AbsentOriginScheme && connectAccess.Scheme == CodeConnectAccess.OriginScheme)
     {
         throw new ArgumentOutOfRangeException("connectAccess", Locale.GetText("Schema == CodeConnectAccess.OriginScheme"));
     }
     if (this._rules.ContainsKey(originScheme))
     {
         if (connectAccess != null)
         {
             CodeConnectAccess[] array  = (CodeConnectAccess[])this._rules[originScheme];
             CodeConnectAccess[] array2 = new CodeConnectAccess[array.Length + 1];
             Array.Copy(array, 0, array2, 0, array.Length);
             array2[array.Length]      = connectAccess;
             this._rules[originScheme] = array2;
         }
     }
     else
     {
         CodeConnectAccess[] value = new CodeConnectAccess[]
         {
             connectAccess
         };
         this._rules.Add(originScheme, value);
     }
 }
Пример #3
0
        //
        // Added public stuff for programmatic support of the talkback access
        // The connectAccess can be null means an empty access (no access) is added
        //
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
            {
                throw new ArgumentNullException("originScheme");
            }

            if (originScheme != AbsentOriginScheme && originScheme != AnyOtherOriginScheme && !CodeConnectAccess.IsValidScheme(originScheme))
            {
                throw new ArgumentOutOfRangeException("originScheme");
            }

            if (originScheme == AbsentOriginScheme && connectAccess.IsOriginScheme)
            {
                throw new ArgumentOutOfRangeException("connectAccess");
            }

            if (m_schemesList == null)
            {
                m_schemesList = new ArrayList();
                m_accessList  = new ArrayList();
            }

            originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);

            for (int i = 0; i < m_schemesList.Count; ++i)
            {
                if ((string)m_schemesList[i] == originScheme)
                {
                    // originScheme entry is found and we may want to add nothing to it.
                    if (connectAccess == null)
                    {
                        return;
                    }

                    ArrayList list = (ArrayList)m_accessList[i];
                    for (i = 0; i < list.Count; ++i)
                    {
                        if (((CodeConnectAccess)list[i]).Equals(connectAccess))
                        {
                            return;
                        }
                    }
                    list.Add(connectAccess);
                    return;
                }
            }

            // originScheme entry is not found, create a new one.
            m_schemesList.Add(originScheme);
            ArrayList newOriginSchemeList = new ArrayList();

            m_accessList.Add(newOriginSchemeList);

            // we may want to keep it empty.
            if (connectAccess != null)
            {
                newOriginSchemeList.Add(connectAccess);
            }
        }
Пример #4
0
        //
        // This tries to return a single element to be added into resulting WebPermission
        // Returns Null if there is nothing to add.
        //
        private string GetPermissionAccessElementString(CodeConnectAccess access, string escapedScheme, string escapedHost, string strPort)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(c_AnyScheme.Length * 2 + c_IgnoreUserInfo.Length + escapedHost.Length);

            if (access.IsAnyScheme)
            {
                sb.Append(c_AnyScheme);
            }
            else if (access.IsOriginScheme)
            {
                sb.Append(escapedScheme).Append("://");
            }
            else
            {
                sb.Append(EscapeStringForRegex(access.Scheme)).Append("://");
            }

            sb.Append(c_IgnoreUserInfo).Append(escapedHost);

            if (access.IsDefaultPort)
            {
                ;
            }
            else if (access.IsOriginPort)
            {
                sb.Append(strPort);
            }
            else
            {
                sb.Append(':').Append(access.StrPort);
            }

            sb.Append("/.*");
            return(sb.ToString());
        }
Пример #5
0
        //
        public static CodeConnectAccess CreateOriginSchemeAccess(int allowPort)
        {
            CodeConnectAccess access = new CodeConnectAccess();

            access.SetCodeConnectAccess(OriginScheme, allowPort);
            return(access);
        }
Пример #6
0
        /// <summary>Returns a <see cref="T:System.Security.Policy.CodeConnectAccess" /> instance that represents access to the specified port using any scheme.</summary>
        /// <param name="allowPort">The port represented by the returned instance.</param>
        /// <returns>A <see cref="T:System.Security.Policy.CodeConnectAccess" /> instance for the specified port.</returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="allowPort" /> is less than 0.-or-
        ///         <paramref name="allowPort" /> is greater than 65,535.</exception>
        // Token: 0x0600296A RID: 10602 RVA: 0x00098804 File Offset: 0x00096A04
        public static CodeConnectAccess CreateAnySchemeAccess(int allowPort)
        {
            CodeConnectAccess codeConnectAccess = new CodeConnectAccess();

            codeConnectAccess.SetCodeConnectAccess(CodeConnectAccess.AnyScheme, allowPort);
            return(codeConnectAccess);
        }
Пример #7
0
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
            {
                throw new ArgumentException("originScheme");
            }

            // TODO (2.0) - invalid characters in originScheme
            if ((originScheme == AbsentOriginScheme) && (connectAccess.Scheme == CodeConnectAccess.OriginScheme))
            {
                throw new ArgumentOutOfRangeException("connectAccess", Locale.GetText(
                                                          "Schema == CodeConnectAccess.OriginScheme"));
            }

            if (_rules.ContainsKey(originScheme))
            {
                // NULL has no effect
                if (connectAccess != null)
                {
                    CodeConnectAccess[] existing = (CodeConnectAccess[])_rules [originScheme];
                    CodeConnectAccess[] array    = new CodeConnectAccess [existing.Length + 1];
                    Array.Copy(existing, 0, array, 0, existing.Length);
                    array [existing.Length] = connectAccess;
                    _rules [originScheme]   = array;
                }
            }
            else
            {
                CodeConnectAccess[] array = new CodeConnectAccess [1];
                array [0] = connectAccess;
                _rules.Add(originScheme, array);
                // add null to prevent access
            }
        }
        // Token: 0x06002989 RID: 10633 RVA: 0x000992CC File Offset: 0x000974CC
        private string GetPermissionAccessElementString(CodeConnectAccess access, string escapedScheme, string escapedHost, string strPort)
        {
            StringBuilder stringBuilder = new StringBuilder("([0-9a-z+\\-\\.]+)://".Length * 2 + "".Length + escapedHost.Length);

            if (access.IsAnyScheme)
            {
                stringBuilder.Append("([0-9a-z+\\-\\.]+)://");
            }
            else if (access.IsOriginScheme)
            {
                stringBuilder.Append(escapedScheme).Append("://");
            }
            else
            {
                stringBuilder.Append(this.EscapeStringForRegex(access.Scheme)).Append("://");
            }
            stringBuilder.Append("").Append(escapedHost);
            if (!access.IsDefaultPort)
            {
                if (access.IsOriginPort)
                {
                    stringBuilder.Append(strPort);
                }
                else
                {
                    stringBuilder.Append(':').Append(access.StrPort);
                }
            }
            stringBuilder.Append("/.*");
            return(stringBuilder.ToString());
        }
Пример #9
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.CodeConnectAccess" /> class. </summary>
 /// <param name="allowScheme">The URI scheme represented by the current instance.</param>
 /// <param name="allowPort">The port represented by the current instance.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///         <paramref name="allowScheme" /> is <see langword="null" />.-or-
 ///         <paramref name="allowScheme" /> is an empty string ("").-or-
 ///         <paramref name="allowScheme" /> contains characters that are not permitted in schemes.-or-
 ///         <paramref name="allowPort" /> is less than 0.-or-
 ///         <paramref name="allowPort" /> is greater than 65,535.</exception>
 // Token: 0x06002968 RID: 10600 RVA: 0x000987B5 File Offset: 0x000969B5
 public CodeConnectAccess(string allowScheme, int allowPort)
 {
     if (!CodeConnectAccess.IsValidScheme(allowScheme))
     {
         throw new ArgumentOutOfRangeException("allowScheme");
     }
     this.SetCodeConnectAccess(allowScheme.ToLower(CultureInfo.InvariantCulture), allowPort);
 }
 // Token: 0x06002996 RID: 10646 RVA: 0x0009994C File Offset: 0x00097B4C
 private void SetDefaults()
 {
     this.AddConnectAccess("file", null);
     this.AddConnectAccess("http", new CodeConnectAccess("http", CodeConnectAccess.OriginPort));
     this.AddConnectAccess("http", new CodeConnectAccess("https", CodeConnectAccess.OriginPort));
     this.AddConnectAccess("https", new CodeConnectAccess("https", CodeConnectAccess.OriginPort));
     this.AddConnectAccess(NetCodeGroup.AbsentOriginScheme, CodeConnectAccess.CreateAnySchemeAccess(CodeConnectAccess.OriginPort));
     this.AddConnectAccess(NetCodeGroup.AnyOtherOriginScheme, CodeConnectAccess.CreateOriginSchemeAccess(CodeConnectAccess.OriginPort));
 }
Пример #11
0
        /// <summary>返回一个 <see cref="T:System.Security.Policy.CodeConnectAccess" /> 实例,该实例表示使用任何方案对指定端口的访问权限。</summary>
        /// <returns>指定端口的 <see cref="T:System.Security.Policy.CodeConnectAccess" /> 实例。</returns>
        /// <param name="allowPort">返回的实例表示的端口。</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="allowPort" /> 小于 0。- 或 -<paramref name="allowPort" /> 大于 65,535。</exception>
        public static CodeConnectAccess CreateAnySchemeAccess(int allowPort)
        {
            CodeConnectAccess codeConnectAccess = new CodeConnectAccess();
            string            lowerCaseScheme   = CodeConnectAccess.AnyScheme;
            int allowPort1 = allowPort;

            codeConnectAccess.SetCodeConnectAccess(lowerCaseScheme, allowPort1);
            return(codeConnectAccess);
        }
Пример #12
0
        public override bool Equals(object o)
        {
            CodeConnectAccess cca = (o as CodeConnectAccess);

            if (cca == null)
            {
                return(false);
            }
            return((_scheme == cca._scheme) && (_port == cca._port));
        }
Пример #13
0
        /// <summary>Returns a value indicating whether two <see cref="T:System.Security.Policy.CodeConnectAccess" /> objects represent the same scheme and port.</summary>
        /// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.CodeConnectAccess" /> object.</param>
        /// <returns>
        ///     <see langword="true" /> if the two objects represent the same scheme and port; otherwise, <see langword="false" />.</returns>
        // Token: 0x0600296F RID: 10607 RVA: 0x000988AC File Offset: 0x00096AAC
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            CodeConnectAccess codeConnectAccess = o as CodeConnectAccess;

            return(codeConnectAccess != null && this.Scheme == codeConnectAccess.Scheme && this.Port == codeConnectAccess.Port);
        }
        /// <summary>Adds the specified connection access to the current code group.</summary>
        /// <param name="originScheme">A <see cref="T:System.String" /> containing the scheme to match against the code's scheme.</param>
        /// <param name="connectAccess">A <see cref="T:System.Security.Policy.CodeConnectAccess" /> that specifies the scheme and port code can use to connect back to its origin server.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="originScheme" /> is <see langword="null" />.</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="originScheme" /> contains characters that are not permitted in schemes.-or-
        ///         <paramref name="originScheme" /> = <see cref="F:System.Security.Policy.NetCodeGroup.AbsentOriginScheme" /> and <paramref name="connectAccess" /> specifies <see cref="F:System.Security.Policy.CodeConnectAccess.OriginScheme" /> as its scheme.</exception>
        // Token: 0x06002980 RID: 10624 RVA: 0x00098BA4 File Offset: 0x00096DA4
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
            {
                throw new ArgumentNullException("originScheme");
            }
            if (originScheme != NetCodeGroup.AbsentOriginScheme && originScheme != NetCodeGroup.AnyOtherOriginScheme && !CodeConnectAccess.IsValidScheme(originScheme))
            {
                throw new ArgumentOutOfRangeException("originScheme");
            }
            if (originScheme == NetCodeGroup.AbsentOriginScheme && connectAccess.IsOriginScheme)
            {
                throw new ArgumentOutOfRangeException("connectAccess");
            }
            if (this.m_schemesList == null)
            {
                this.m_schemesList = new ArrayList();
                this.m_accessList  = new ArrayList();
            }
            originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);
            int i = 0;

            while (i < this.m_schemesList.Count)
            {
                if ((string)this.m_schemesList[i] == originScheme)
                {
                    if (connectAccess == null)
                    {
                        return;
                    }
                    ArrayList arrayList = (ArrayList)this.m_accessList[i];
                    for (i = 0; i < arrayList.Count; i++)
                    {
                        if (((CodeConnectAccess)arrayList[i]).Equals(connectAccess))
                        {
                            return;
                        }
                    }
                    arrayList.Add(connectAccess);
                    return;
                }
                else
                {
                    i++;
                }
            }
            this.m_schemesList.Add(originScheme);
            ArrayList arrayList2 = new ArrayList();

            this.m_accessList.Add(arrayList2);
            if (connectAccess != null)
            {
                arrayList2.Add(connectAccess);
            }
        }
Пример #15
0
 private static bool IsAsciiLetterOrDigit(char character)
 {
     if (CodeConnectAccess.IsAsciiLetter(character))
     {
         return(true);
     }
     if ((int)character >= 48)
     {
         return((int)character <= 57);
     }
     return(false);
 }
Пример #16
0
 public static void CodeConnectAccessCallMethods()
 {
     CodeConnectAccess cca = new CodeConnectAccess("test", 0);
     string teststring = CodeConnectAccess.AnyScheme;
     int testint = CodeConnectAccess.DefaultPort;
     testint = CodeConnectAccess.OriginPort;
     teststring = CodeConnectAccess.OriginScheme;
     cca = CodeConnectAccess.CreateAnySchemeAccess(0);
     cca = CodeConnectAccess.CreateOriginSchemeAccess(0);
     cca = new CodeConnectAccess("test", 0);
     bool testbool = cca.Equals(new object());
     testint = cca.GetHashCode();
 }
Пример #17
0
        /// <summary>将指定的连接访问权限添加到当前代码组。</summary>
        /// <param name="originScheme">一个 <see cref="T:System.String" />,包含要与代码的方案进行匹配的方案。</param>
        /// <param name="connectAccess">一个 <see cref="T:System.Security.Policy.CodeConnectAccess" />,指定代码可用来连接回其原始服务器的方案和端口。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="originScheme" /> 为 null。</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">一个 <paramref name="originScheme" />,包含方案中不允许的字符。- 或 -<paramref name="originScheme" /> = <see cref="F:System.Security.Policy.NetCodeGroup.AbsentOriginScheme" /> 和 <paramref name="connectAccess" /> 指定 <see cref="F:System.Security.Policy.CodeConnectAccess.OriginScheme" /> 作为其方案。</exception>
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
            {
                throw new ArgumentNullException("originScheme");
            }
            if (originScheme != NetCodeGroup.AbsentOriginScheme && originScheme != NetCodeGroup.AnyOtherOriginScheme && !CodeConnectAccess.IsValidScheme(originScheme))
            {
                throw new ArgumentOutOfRangeException("originScheme");
            }
            if (originScheme == NetCodeGroup.AbsentOriginScheme && connectAccess.IsOriginScheme)
            {
                throw new ArgumentOutOfRangeException("connectAccess");
            }
            if (this.m_schemesList == null)
            {
                this.m_schemesList = new ArrayList();
                this.m_accessList  = new ArrayList();
            }
            originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);
            for (int index1 = 0; index1 < this.m_schemesList.Count; ++index1)
            {
                if ((string)this.m_schemesList[index1] == originScheme)
                {
                    if (connectAccess == null)
                    {
                        return;
                    }
                    ArrayList arrayList = (ArrayList)this.m_accessList[index1];
                    for (int index2 = 0; index2 < arrayList.Count; ++index2)
                    {
                        if (((CodeConnectAccess)arrayList[index2]).Equals((object)connectAccess))
                        {
                            return;
                        }
                    }
                    arrayList.Add((object)connectAccess);
                    return;
                }
            }
            this.m_schemesList.Add((object)originScheme);
            ArrayList arrayList1 = new ArrayList();

            this.m_accessList.Add((object)arrayList1);
            if (connectAccess == null)
            {
                return;
            }
            arrayList1.Add((object)connectAccess);
        }
Пример #18
0
        /// <summary>返回一个值,指示两个 <see cref="T:System.Security.Policy.CodeConnectAccess" /> 对象是否表示相同的方案和端口。</summary>
        /// <returns>如果两个对象表示相同的方案和端口,则为 true;否则为 false。</returns>
        /// <param name="o">要与当前 <see cref="T:System.Security.Policy.CodeConnectAccess" /> 对象进行比较的对象。</param>
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            CodeConnectAccess codeConnectAccess = o as CodeConnectAccess;

            if (codeConnectAccess == null || !(this.Scheme == codeConnectAccess.Scheme))
            {
                return(false);
            }
            return(this.Port == codeConnectAccess.Port);
        }
Пример #19
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            CodeConnectAccess access = o as CodeConnectAccess;

            if (access == null)
            {
                return(false);
            }
            return((this.Scheme == access.Scheme) && (this.Port == access.Port));
        }
Пример #20
0
 // Token: 0x06002977 RID: 10615 RVA: 0x00098A98 File Offset: 0x00096C98
 internal static bool IsValidScheme(string scheme)
 {
     if (scheme == null || scheme.Length == 0 || !CodeConnectAccess.IsAsciiLetter(scheme[0]))
     {
         return(false);
     }
     for (int i = scheme.Length - 1; i > 0; i--)
     {
         if (!CodeConnectAccess.IsAsciiLetterOrDigit(scheme[i]) && scheme[i] != '+' && scheme[i] != '-' && scheme[i] != '.')
         {
             return(false);
         }
     }
     return(true);
 }
Пример #21
0
 internal static bool IsValidScheme(string scheme)
 {
     if (scheme == null || scheme.Length == 0 || !CodeConnectAccess.IsAsciiLetter(scheme[0]))
     {
         return(false);
     }
     for (int index = scheme.Length - 1; index > 0; --index)
     {
         if (!CodeConnectAccess.IsAsciiLetterOrDigit(scheme[index]) && (int)scheme[index] != 43 && ((int)scheme[index] != 45 && (int)scheme[index] != 46))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #22
0
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
            {
                throw new ArgumentNullException("originScheme");
            }
            if (((originScheme != AbsentOriginScheme) && (originScheme != AnyOtherOriginScheme)) && !CodeConnectAccess.IsValidScheme(originScheme))
            {
                throw new ArgumentOutOfRangeException("originScheme");
            }
            if ((originScheme == AbsentOriginScheme) && connectAccess.IsOriginScheme)
            {
                throw new ArgumentOutOfRangeException("connectAccess");
            }
            if (this.m_schemesList == null)
            {
                this.m_schemesList = new ArrayList();
                this.m_accessList  = new ArrayList();
            }
            originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);
            for (int i = 0; i < this.m_schemesList.Count; i++)
            {
                if (((string)this.m_schemesList[i]) == originScheme)
                {
                    if (connectAccess != null)
                    {
                        ArrayList list = (ArrayList)this.m_accessList[i];
                        for (i = 0; i < list.Count; i++)
                        {
                            if (((CodeConnectAccess)list[i]).Equals(connectAccess))
                            {
                                return;
                            }
                        }
                        list.Add(connectAccess);
                    }
                    return;
                }
            }
            this.m_schemesList.Add(originScheme);
            ArrayList list2 = new ArrayList();

            this.m_accessList.Add(list2);
            if (connectAccess != null)
            {
                list2.Add(connectAccess);
            }
        }
Пример #23
0
        //
        public override bool Equals(object o)
        {
            if ((object)this == (object)o)
            {
                return(true);
            }

            CodeConnectAccess that = (o as CodeConnectAccess);

            if (that == null)
            {
                return(false);
            }

            return(this.Scheme == that.Scheme && this.Port == that.Port);
        }
 public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
 {
     if (originScheme == null)
     {
         throw new ArgumentNullException("originScheme");
     }
     if (((originScheme != AbsentOriginScheme) && (originScheme != AnyOtherOriginScheme)) && !CodeConnectAccess.IsValidScheme(originScheme))
     {
         throw new ArgumentOutOfRangeException("originScheme");
     }
     if ((originScheme == AbsentOriginScheme) && connectAccess.IsOriginScheme)
     {
         throw new ArgumentOutOfRangeException("connectAccess");
     }
     if (this.m_schemesList == null)
     {
         this.m_schemesList = new ArrayList();
         this.m_accessList = new ArrayList();
     }
     originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);
     for (int i = 0; i < this.m_schemesList.Count; i++)
     {
         if (((string) this.m_schemesList[i]) == originScheme)
         {
             if (connectAccess != null)
             {
                 ArrayList list = (ArrayList) this.m_accessList[i];
                 for (i = 0; i < list.Count; i++)
                 {
                     if (((CodeConnectAccess) list[i]).Equals(connectAccess))
                     {
                         return;
                     }
                 }
                 list.Add(connectAccess);
             }
             return;
         }
     }
     this.m_schemesList.Add(originScheme);
     ArrayList list2 = new ArrayList();
     this.m_accessList.Add(list2);
     if (connectAccess != null)
     {
         list2.Add(connectAccess);
     }
 }
Пример #25
0
 internal CodeConnectAccess(string allowScheme, string allowPort)
 {
     if (allowScheme == null || allowScheme.Length == 0)
     {
         throw new ArgumentNullException("allowScheme");
     }
     if (allowPort == null || allowPort.Length == 0)
     {
         throw new ArgumentNullException("allowPort");
     }
     this._LowerCaseScheme = allowScheme.ToLower(CultureInfo.InvariantCulture);
     if (this._LowerCaseScheme == CodeConnectAccess.OriginScheme)
     {
         this._LowerCaseScheme = CodeConnectAccess.OriginScheme;
     }
     else if (this._LowerCaseScheme == CodeConnectAccess.AnyScheme)
     {
         this._LowerCaseScheme = CodeConnectAccess.AnyScheme;
     }
     else if (!CodeConnectAccess.IsValidScheme(this._LowerCaseScheme))
     {
         throw new ArgumentOutOfRangeException("allowScheme");
     }
     this._LowerCasePort = allowPort.ToLower(CultureInfo.InvariantCulture);
     if (this._LowerCasePort == "$default")
     {
         this._IntPort = CodeConnectAccess.DefaultPort;
     }
     else if (this._LowerCasePort == "$origin")
     {
         this._IntPort = CodeConnectAccess.OriginPort;
     }
     else
     {
         this._IntPort = int.Parse(allowPort, (IFormatProvider)CultureInfo.InvariantCulture);
         if (this._IntPort < 0 || this._IntPort > (int)ushort.MaxValue)
         {
             throw new ArgumentOutOfRangeException("allowPort");
         }
         this._LowerCasePort = this._IntPort.ToString((IFormatProvider)CultureInfo.InvariantCulture);
     }
 }
Пример #26
0
        //
        // This method is called at the ctor time to populate default accesses (V1.1 compat)
        //
        private void SetDefaults()
        {
            // No access for file://
            AddConnectAccess("file", null);

            // access fot http://
            AddConnectAccess("http", new CodeConnectAccess("http", CodeConnectAccess.OriginPort));
            AddConnectAccess("http", new CodeConnectAccess("https", CodeConnectAccess.OriginPort));

            /* CONSIDER
             * AddConnectAccess("http", new CodeConnectAccess("https", CodeConnectAccess.DefaultPort));
             * AddConnectAccess("http", new CodeConnectAccess("ftp", CodeConnectAccess.DefaultPort));
             * AddConnectAccess("http", new CodeConnectAccess("soap.tcp", CodeConnectAccess.DefaultPort));
             */

            // access fot https://
            AddConnectAccess("https", new CodeConnectAccess("https", CodeConnectAccess.OriginPort));

            /* CONSIDER
             * AddConnectAccess("https", new CodeConnectAccess("soap.tcp", CodeConnectAccess.DefaultPort));
             */


            // access fot ftp://

            /* CONSIDER
             * AddConnectAccess("ftp", new CodeConnectAccess("ftp", CodeConnectAccess.OriginPort));
             * AddConnectAccess("ftp", new CodeConnectAccess("http", CodeConnectAccess.DefaultPort));
             * AddConnectAccess("ftp", new CodeConnectAccess("https", CodeConnectAccess.DefaultPort));
             * AddConnectAccess("ftp", new CodeConnectAccess("soap.tcp", CodeConnectAccess.DefaultPort));
             */

            // access for no scheme and for any other scheme
            AddConnectAccess(NetCodeGroup.AbsentOriginScheme, CodeConnectAccess.CreateAnySchemeAccess(CodeConnectAccess.OriginPort));
            AddConnectAccess(NetCodeGroup.AnyOtherOriginScheme, CodeConnectAccess.CreateOriginSchemeAccess(CodeConnectAccess.OriginPort));
        }
        /// <summary>Returns a value indicating whether two <see cref="T:System.Security.Policy.CodeConnectAccess" /> objects represent the same scheme and port.</summary>
        /// <returns>true if the two objects represent the same scheme and port; otherwise, false.</returns>
        /// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.CodeConnectAccess" /> object.</param>
        public override bool Equals(object o)
        {
            CodeConnectAccess codeConnectAccess = o as CodeConnectAccess;

            return(codeConnectAccess != null && this._scheme == codeConnectAccess._scheme && this._port == codeConnectAccess._port);
        }
Пример #28
0
 public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
 {
 }
Пример #29
0
 // Token: 0x06002978 RID: 10616 RVA: 0x00098B05 File Offset: 0x00096D05
 private static bool IsAsciiLetterOrDigit(char character)
 {
     return(CodeConnectAccess.IsAsciiLetter(character) || (character >= '0' && character <= '9'));
 }
Пример #30
0
        //
        // This tries to return a single element to be added into resulting WebPermission
        // Returns Null if there is nothing to add.
        //
        private string GetPermissionAccessElementString(CodeConnectAccess access, string escapedScheme, string escapedHost, string strPort)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(c_AnyScheme.Length*2 + c_IgnoreUserInfo.Length + escapedHost.Length);

            if (access.IsAnyScheme)
                sb.Append(c_AnyScheme);
            else if (access.IsOriginScheme)
                sb.Append(escapedScheme).Append("://");
            else
                sb.Append(EscapeStringForRegex(access.Scheme)).Append("://");

            sb.Append(c_IgnoreUserInfo).Append(escapedHost);

            if (access.IsDefaultPort) {;}
            else if (access.IsOriginPort)
                 sb.Append(strPort);
            else sb.Append(':').Append(access.StrPort);

            sb.Append("/.*");
            return sb.ToString();
        }
Пример #31
0
 /// <summary>Adds the specified connection access to the current code group.</summary><param name="originScheme">A <see cref="T:System.String" /> containing the scheme to match against the code's scheme.</param><param name="connectAccess">A <see cref="T:System.Security.Policy.CodeConnectAccess" /> that specifies the scheme and port code can use to connect back to its origin server.</param><exception cref="T:System.ArgumentNullException"><paramref name="originScheme" /> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="originScheme" /> contains characters that are not permitted in schemes.-or-<paramref name="originScheme" /> = <see cref="F:System.Security.Policy.NetCodeGroup.AbsentOriginScheme" /> and <paramref name="connectAccess" /> specifies <see cref="F:System.Security.Policy.CodeConnectAccess.OriginScheme" /> as its scheme.</exception>
 public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
 {
     throw new NotImplementedException();
 }
 private string GetPermissionAccessElementString(CodeConnectAccess access, string escapedScheme, string escapedHost, string strPort)
 {
     StringBuilder builder = new StringBuilder(((@"([0-9a-z+\-\.]+)://".Length * 2) + "".Length) + escapedHost.Length);
     if (access.IsAnyScheme)
     {
         builder.Append(@"([0-9a-z+\-\.]+)://");
     }
     else if (access.IsOriginScheme)
     {
         builder.Append(escapedScheme).Append("://");
     }
     else
     {
         builder.Append(this.EscapeStringForRegex(access.Scheme)).Append("://");
     }
     builder.Append("").Append(escapedHost);
     if (!access.IsDefaultPort)
     {
         if (access.IsOriginPort)
         {
             builder.Append(strPort);
         }
         else
         {
             builder.Append(':').Append(access.StrPort);
         }
     }
     builder.Append("/.*");
     return builder.ToString();
 }
 private string TryPermissionAsOneString(CodeConnectAccess[] access, string escapedScheme, string escapedHost, int intPort)
 {
     bool flag = true;
     bool flag2 = true;
     bool flag3 = false;
     int port = -2;
     for (int i = 0; i < access.Length; i++)
     {
         flag &= access[i].IsDefaultPort || (access[i].IsOriginPort && (intPort == -1));
         flag2 &= access[i].IsOriginPort || (access[i].Port == intPort);
         if (access[i].Port >= 0)
         {
             if (port == -2)
             {
                 port = access[i].Port;
             }
             else if (access[i].Port != port)
             {
                 port = -1;
             }
         }
         else
         {
             port = -1;
         }
         if (access[i].IsAnyScheme)
         {
             flag3 = true;
         }
     }
     if ((!flag && !flag2) && (port == -1))
     {
         return null;
     }
     StringBuilder builder = new StringBuilder(((@"([0-9a-z+\-\.]+)://".Length * access.Length) + ("".Length * 2)) + escapedHost.Length);
     if (flag3)
     {
         builder.Append(@"([0-9a-z+\-\.]+)://");
     }
     else
     {
         builder.Append('(');
         for (int j = 0; j < access.Length; j++)
         {
             int index = 0;
             while (index < j)
             {
                 if (access[j].Scheme == access[index].Scheme)
                 {
                     break;
                 }
                 index++;
             }
             if (index == j)
             {
                 if (j != 0)
                 {
                     builder.Append('|');
                 }
                 builder.Append(access[j].IsOriginScheme ? escapedScheme : this.EscapeStringForRegex(access[j].Scheme));
             }
         }
         builder.Append(")://");
     }
     builder.Append("").Append(escapedHost);
     if (!flag)
     {
         if (flag2)
         {
             builder.Append(':').Append(intPort);
         }
         else
         {
             builder.Append(':').Append(port);
         }
     }
     builder.Append("/.*");
     return builder.ToString();
 }
Пример #34
0
        //
        // Added public stuff for programmatic support of the talkback access
        // The connectAccess can be null means an empty access (no access) is added
        //
        public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
        {
            if (originScheme == null)
                throw new ArgumentNullException("originScheme");

            if (originScheme != AbsentOriginScheme && originScheme != AnyOtherOriginScheme && !CodeConnectAccess.IsValidScheme(originScheme))
                throw new ArgumentOutOfRangeException("originScheme");

            if (originScheme == AbsentOriginScheme && connectAccess.IsOriginScheme)
                throw new ArgumentOutOfRangeException("connectAccess");

            if (m_schemesList == null)
            {
                m_schemesList = new ArrayList();
                m_accessList = new ArrayList();
            }

            originScheme = originScheme.ToLower(CultureInfo.InvariantCulture);

            for (int i=0; i < m_schemesList.Count; ++i)
            {
                if ((string)m_schemesList[i] == originScheme)
                {
                    // originScheme entry is found and we may want to add nothing to it.
                    if (connectAccess == null)
                        return;

                    ArrayList list = (ArrayList)m_accessList[i];
                    for (i = 0; i < list.Count; ++i)
                    {
                        if (((CodeConnectAccess)list[i]).Equals(connectAccess))
                            return;
                    }
                    list.Add(connectAccess);
                    return;
                }
            }

            // originScheme entry is not found, create a new one.
            m_schemesList.Add(originScheme);
            ArrayList newOriginSchemeList = new ArrayList();
            m_accessList.Add(newOriginSchemeList);

            // we may want to keep it empty.
            if (connectAccess != null)
                newOriginSchemeList.Add(connectAccess);

        }
Пример #35
0
        //
        // This is an attempt to optimize resulting regex if the rules can be combined into one expression string
        //
        private string TryPermissionAsOneString(CodeConnectAccess[] access, string escapedScheme, string escapedHost, int intPort)
        {
            bool noPort = true;
            bool originPort = true;
            bool anyScheme = false;
            int  sameCustomPort = CodeConnectAccess.AnyPort;

            //
            // We can compact rules in one regex if the destination port is the same for all granted accesses.
            // We may have three cases (order is significant)
            // - No port (empty) in the resulting rule
            // - Origin server port that is intPort parameter
            // - Some custom port that is the same for all accesses
            //
            for (int i = 0; i < access.Length; ++i)
            {
                noPort    &= (access[i].IsDefaultPort || (access[i].IsOriginPort && intPort == CodeConnectAccess.NoPort));
                originPort&= (access[i].IsOriginPort  || access[i].Port == intPort);

                if (access[i].Port >= 0)
                {

                    if (sameCustomPort == CodeConnectAccess.AnyPort)
                    {
                        sameCustomPort = access[i].Port;
                    }
                    else if (access[i].Port != sameCustomPort)
                    {
                        // found conflicting ports
                        sameCustomPort = CodeConnectAccess.NoPort;
                    }
                }
                else
                {
                    // Cannot compress Regex if saw at least one "default port" access rule and another one with exact port.
                    sameCustomPort = CodeConnectAccess.NoPort;
                }

                if (access[i].IsAnyScheme)
                    anyScheme = true;
            }

            if (!noPort && !originPort && sameCustomPort == CodeConnectAccess.NoPort)
                return null;

            // We can produce the resulting expression as one string
            System.Text.StringBuilder sb = new System.Text.StringBuilder(c_AnyScheme.Length * access.Length + c_IgnoreUserInfo.Length*2 + escapedHost.Length);
            if (anyScheme)
                sb.Append(c_AnyScheme);
            else
            {
                sb.Append('(');
                int i = 0;
                for (; i < access.Length; ++i)
                {
                    // This is  to avoid output like (http|http|http)
                    int k = 0;
                    for (; k < i; ++k)
                    {
                        if (access[i].Scheme == access[k].Scheme)
                            break;
                    }
                    if (k == i)
                    {
                        if (i != 0)
                            sb.Append('|');
                        sb.Append(access[i].IsOriginScheme? escapedScheme: EscapeStringForRegex(access[i].Scheme));
                    }
                }
                sb.Append(")://");;
            }

            sb.Append(c_IgnoreUserInfo).Append(escapedHost);

            if (noPort) {;}
            else if (originPort) sb.Append(':').Append(intPort);
            else sb.Append(':').Append(sameCustomPort);

            sb.Append("/.*");
            return sb.ToString();
        }
 public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
 {
 }
Пример #37
0
 //
 public static CodeConnectAccess CreateAnySchemeAccess(int allowPort)
 {
     CodeConnectAccess access = new CodeConnectAccess();
     access.SetCodeConnectAccess(AnyScheme, allowPort);
     return access;
 }
Пример #38
0
		private bool Equals (CodeConnectAccess[] rules1, CodeConnectAccess[] rules2)
		{
			for (int i=0; i < rules1.Length; i++) {
				bool found = false;
				for (int j=0; j < rules2.Length; j++) {
					if (rules1 [i].Equals (rules2 [j])) {
						found = true;
						break;
					}
				}
				if (!found)
					return false;
			}
			return true;
		}