SearchForChildByTag() public method

public SearchForChildByTag ( string tag ) : SecurityElement
tag string
return SecurityElement
Example #1
0
 private byte[] GetNamedParam(SecurityElement se, string param)
 {
     SecurityElement sep = se.SearchForChildByTag(param);
     if (sep == null)
         return null;
     return Convert.FromBase64String(sep.Text);
 }
Example #2
0
	/// LAMESPEC: ArgumentNullException is thrown (not CryptographicException)
	public SignatureDescription (SecurityElement el) 
	{
		if (el == null)
			throw new ArgumentNullException ("el");

		// thanksfully documented in VS.NET 2005
		SecurityElement child = el.SearchForChildByTag ("Deformatter");
		_DeformatterAlgorithm = ((child == null) ? null : child.Text);

		child = el.SearchForChildByTag ("Digest");
		_DigestAlgorithm = ((child == null) ? null : child.Text);

		child = el.SearchForChildByTag ("Formatter");
		_FormatterAlgorithm = ((child == null) ? null : child.Text);

		child = el.SearchForChildByTag ("Key");
		_KeyAlgorithm = ((child == null) ? null : child.Text);
	}
Example #3
0
        private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            Contract.EndContractBlock();

            PolicyLevel level = new PolicyLevel(type, path);

            Parser          parser = new Parser(str);
            SecurityElement elRoot = parser.GetTopElement();

            if (elRoot == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "configuration"));
            }

            SecurityElement elMscorlib = elRoot.SearchForChildByTag("mscorlib");

            if (elMscorlib == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "mscorlib"));
            }

            SecurityElement elSecurity = elMscorlib.SearchForChildByTag("security");

            if (elSecurity == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "security"));
            }

            SecurityElement elPolicy = elSecurity.SearchForChildByTag("policy");

            if (elPolicy == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "policy"));
            }

            SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag("PolicyLevel");

            if (elPolicyLevel != null)
            {
                level.FromXml(elPolicyLevel);
            }
            else
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "PolicyLevel"));
            }

            return(level);
        }
Example #4
0
        // Search for a child by tag path.
        internal SecurityElement SearchForChildByPath(params String[] tags)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            SecurityElement current = this;

            foreach (String tag in tags)
            {
                current = current.SearchForChildByTag(tag);
                if (current == null)
                {
                    break;
                }
            }
            return(current);
        }
Example #5
0
        private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            PolicyLevel     policyLevel = new PolicyLevel(type, path);
            SecurityElement topElement  = new Parser(str).GetTopElement();

            if (topElement == null)
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"configuration"));
            }
            string          tag1             = "mscorlib";
            SecurityElement securityElement1 = topElement.SearchForChildByTag(tag1);

            if (securityElement1 == null)
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"mscorlib"));
            }
            string          tag2             = "security";
            SecurityElement securityElement2 = securityElement1.SearchForChildByTag(tag2);

            if (securityElement2 == null)
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"security"));
            }
            string          tag3             = "policy";
            SecurityElement securityElement3 = securityElement2.SearchForChildByTag(tag3);

            if (securityElement3 == null)
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"policy"));
            }
            string          tag4 = "PolicyLevel";
            SecurityElement e    = securityElement3.SearchForChildByTag(tag4);

            if (e == null)
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"PolicyLevel"));
            }
            policyLevel.FromXml(e);
            return(policyLevel);
        }
Example #6
0
        // Get the value of an attribute by tag path.  The last string
        // in the path is the attribute name.
        internal String AttributeByPath(params String[] tags)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            SecurityElement current = this;
            int             posn    = 0;

            while (posn < (tags.Length - 1))
            {
                current = current.SearchForChildByTag(tags[posn]);
                if (current == null)
                {
                    return(null);
                }
                ++posn;
            }
            return(current.Attribute(tags[posn]));
        }
        // Token: 0x06001E18 RID: 7704 RVA: 0x0006907C File Offset: 0x0006727C
        private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            PolicyLevel     policyLevel = new PolicyLevel(type, path);
            Parser          parser      = new Parser(str);
            SecurityElement topElement  = parser.GetTopElement();

            if (topElement == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "configuration"));
            }
            SecurityElement securityElement = topElement.SearchForChildByTag("mscorlib");

            if (securityElement == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "mscorlib"));
            }
            SecurityElement securityElement2 = securityElement.SearchForChildByTag("security");

            if (securityElement2 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "security"));
            }
            SecurityElement securityElement3 = securityElement2.SearchForChildByTag("policy");

            if (securityElement3 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "policy"));
            }
            SecurityElement securityElement4 = securityElement3.SearchForChildByTag("PolicyLevel");

            if (securityElement4 != null)
            {
                policyLevel.FromXml(securityElement4);
                return(policyLevel);
            }
            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "PolicyLevel"));
        }
Example #8
0
        private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            PolicyLevel     level      = new PolicyLevel(type, path);
            SecurityElement topElement = new Parser(str).GetTopElement();

            if (topElement == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "configuration" }));
            }
            SecurityElement element2 = topElement.SearchForChildByTag("mscorlib");

            if (element2 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "mscorlib" }));
            }
            SecurityElement element3 = element2.SearchForChildByTag("security");

            if (element3 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "security" }));
            }
            SecurityElement element4 = element3.SearchForChildByTag("policy");

            if (element4 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "policy" }));
            }
            SecurityElement e = element4.SearchForChildByTag("PolicyLevel");

            if (e == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "PolicyLevel" }));
            }
            level.FromXml(e);
            return(level);
        }
Example #9
0
        /// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.FromXml"]/*' />
        /// <devdoc>
        /// </devdoc>
        public override void FromXml(SecurityElement securityElement) {
            if (securityElement == null) {

                //
                // null SecurityElement
                //

                throw new ArgumentNullException("securityElement");
            }
            if (!securityElement.Tag.Equals("IPermission")) {

                //
                // SecurityElement must be a permission element
                //

                throw new ArgumentException("securityElement");
            }

            string className = securityElement.Attribute("class");

            if (className == null) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException("securityElement");
            }
            if (className.IndexOf(this.GetType().FullName) < 0) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException("securityElement");
            }

            String str = securityElement.Attribute("Unrestricted");

            if (str != null) {
                m_noRestriction = (0 == string.Compare( str, "true", true, CultureInfo.InvariantCulture));
                if(m_noRestriction)
                    return;
            }

            m_noRestriction = false;
            m_connectList = new ArrayList();
            m_acceptList = new ArrayList();

            SecurityElement et = securityElement.SearchForChildByTag("ConnectAccess");
            string uriPattern;

            if (et != null) {

                foreach(SecurityElement uriElem in et.Children) {
                    //NOTE: Any stuff coming from XML is treated as URI PATTERN!
                    if (uriElem.Tag.Equals("URI")) {
                        try {
                            uriPattern = uriElem.Attributes["uri"] as string;
                        }
                        catch {
                            uriPattern = null;
                        }
                        if (uriPattern == null) {
                            throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val_in_element), "ConnectAccess");
                        }
                        AddAsPattern(NetworkAccess.Connect, uriPattern);
                    }
                    else {
                        // improper tag found, just ignore
                    }
                }
            }

            et = securityElement.SearchForChildByTag("AcceptAccess");
            if (et != null) {

                foreach(SecurityElement uriElem in et.Children) {
                    //NOTE: Any stuff coming from XML is treated as URI PATTERN!
                    if (uriElem.Tag.Equals("URI")) {
                        try {
                            uriPattern = uriElem.Attributes["uri"] as string;
                        }
                        catch {
                            uriPattern = null;
                        }
                        if (uriPattern == null) {
                            throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val_in_element), "AcceptAccess");
                        }
                        AddAsPattern(NetworkAccess.Accept, uriPattern);
                    }
                    else {
                        // improper tag found, just ignore
                    }
                }
            }
        }
        public override void FromXml(SecurityElement securityElement)
        {
            string str3;
            if (securityElement == null)
            {
                throw new ArgumentNullException("securityElement");
            }
            if (!securityElement.Tag.Equals("IPermission"))
            {
                throw new ArgumentException(SR.GetString("net_not_ipermission"), "securityElement");
            }
            string str = securityElement.Attribute("class");
            if (str == null)
            {
                throw new ArgumentException(SR.GetString("net_no_classname"), "securityElement");
            }
            if (str.IndexOf(base.GetType().FullName) < 0)
            {
                throw new ArgumentException(SR.GetString("net_no_typename"), "securityElement");
            }
            string strA = securityElement.Attribute("Unrestricted");
            this.m_connectList = new ArrayList();
            this.m_acceptList = new ArrayList();
            this.m_UnrestrictedAccept = this.m_UnrestrictedConnect = false;
            if ((strA != null) && (string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0))
            {
                this.m_noRestriction = true;
                return;
            }
            this.m_noRestriction = false;
            SecurityElement element = securityElement.SearchForChildByTag("ConnectAccess");
            if (element != null)
            {
                foreach (SecurityElement element2 in element.Children)
                {
                    if (element2.Tag.Equals("URI"))
                    {
                        try
                        {
                            str3 = element2.Attribute("uri");
                        }
                        catch
                        {
                            str3 = null;
                        }
                        switch (str3)
                        {
                            case null:
                                throw new ArgumentException(SR.GetString("net_perm_invalid_val_in_element"), "ConnectAccess");

                            case ".*":
                                this.m_UnrestrictedConnect = true;
                                this.m_connectList = new ArrayList();
                                goto Label_0196;
                        }
                        this.AddAsPattern(NetworkAccess.Connect, new DelayedRegex(str3));
                    }
                }
            }
        Label_0196:
            element = securityElement.SearchForChildByTag("AcceptAccess");
            if (element != null)
            {
                foreach (SecurityElement element3 in element.Children)
                {
                    if (element3.Tag.Equals("URI"))
                    {
                        try
                        {
                            str3 = element3.Attribute("uri");
                        }
                        catch
                        {
                            str3 = null;
                        }
                        switch (str3)
                        {
                            case null:
                                throw new ArgumentException(SR.GetString("net_perm_invalid_val_in_element"), "AcceptAccess");

                            case ".*":
                                this.m_UnrestrictedAccept = true;
                                this.m_acceptList = new ArrayList();
                                return;
                        }
                        this.AddAsPattern(NetworkAccess.Accept, new DelayedRegex(str3));
                    }
                }
            }
        }
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(S._("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				acceptList.Clear();
				connectList.Clear();
				if(state != PermissionState.Unrestricted)
				{
					SecurityElement child;
					String str;
					child = esd.SearchForChildByTag("ConnectAccess");
					if(child != null && child.Children != null)
					{
						foreach(SecurityElement uri1 in child.Children)
						{
							if(uri1.Tag != "URI")
							{
								continue;
							}
							str = uri1.Attribute("uri");
							if(!IsRegex(str))
							{
								connectList.Add(RegexUnescape(str));
							}
						#if !ECMA_COMPAT
							else
							{
								connectList.Add(new Regex(str));
							}
						#endif
						}
					}
					child = esd.SearchForChildByTag("AcceptAccess");
					if(child != null && child.Children != null)
					{
						foreach(SecurityElement uri1 in child.Children)
						{
							if(uri1.Tag != "URI")
							{
								continue;
							}
							str = uri1.Attribute("uri");
							if(!IsRegex(str))
							{
								acceptList.Add(RegexUnescape(str));
							}
						#if !ECMA_COMPAT
							else
							{
								acceptList.Add(new Regex(str));
							}
						#endif
						}
					}
				}
			}
 internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
 {
     if (et == null)
     {
         throw new ArgumentNullException("et");
     }
     if (!et.Tag.Equals("PolicyStatement"))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
     }
     this.m_attributes = PolicyStatementAttribute.Nothing;
     string str = et.Attribute("Attributes");
     if (str != null)
     {
         this.m_attributes = (PolicyStatementAttribute) Enum.Parse(typeof(PolicyStatementAttribute), str);
     }
     lock (this)
     {
         this.m_permSet = null;
         if (level != null)
         {
             string name = et.Attribute("PermissionSetName");
             if (name != null)
             {
                 this.m_permSet = level.GetNamedPermissionSetInternal(name);
                 if (this.m_permSet == null)
                 {
                     this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                 }
             }
         }
         if (this.m_permSet == null)
         {
             SecurityElement element = et.SearchForChildByTag("PermissionSet");
             if (element == null)
             {
                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
             }
             string str3 = element.Attribute("class");
             if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
             {
                 this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
             }
             else
             {
                 this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
             }
             try
             {
                 this.m_permSet.FromXml(element, allowInternalOnly, true);
             }
             catch
             {
             }
         }
         if (this.m_permSet == null)
         {
             this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
         }
     }
 }
Example #13
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void FromXml( SecurityElement et, PolicyLevel level, bool allowInternalOnly )
        {
            if (et == null)
                throw new ArgumentNullException( "et" );

            if (!et.Tag.Equals( "PolicyStatement" ))
                throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ),  "PolicyStatement", this.GetType().FullName ) );
            Contract.EndContractBlock();
        
            m_attributes = (PolicyStatementAttribute) 0;

            String strAttributes = et.Attribute( "Attributes" );

            if (strAttributes != null)
                m_attributes = (PolicyStatementAttribute)Enum.Parse( typeof( PolicyStatementAttribute ), strAttributes );

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = et.Attribute( "PermissionSetName" );
    
                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal( permSetName );

                        if (m_permSet == null)
                            m_permSet = new PermissionSet( PermissionState.None );
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.
        
                    SecurityElement e = et.SearchForChildByTag( "PermissionSet" );

                    if (e != null)
                    {
                        String className = e.Attribute( "class" );

                        if (className != null && (className.Equals( "NamedPermissionSet" ) ||
                                                  className.Equals( "System.Security.NamedPermissionSet" )))
                            m_permSet = new NamedPermissionSet( "DefaultName", PermissionState.None );
                        else
                            m_permSet = new PermissionSet( PermissionState.None );
                
                        try
                        {
                            m_permSet.FromXml( e, allowInternalOnly, true );
                        }
                        catch
                        {
                            // ignore any exceptions from the decode process.
                            // Note: we go ahead and use the permission set anyway.  This should be safe since
                            // the decode process should never give permission beyond what a proper decode would have
                            // given.
                        }
                    }
                    else
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXML" ) );
                    }
                }

                if (m_permSet == null) 
                    m_permSet = new PermissionSet( PermissionState.None );
            }    
        }
 public void FromXml(SecurityElement e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     lock (this)
     {
         Hashtable hashtable;
         ArrayList list = new ArrayList();
         SecurityElement element = e.SearchForChildByTag("SecurityClasses");
         if (element != null)
         {
             hashtable = new Hashtable();
             IEnumerator enumerator = element.Children.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 SecurityElement current = (SecurityElement) enumerator.Current;
                 if (current.Tag.Equals("SecurityClass"))
                 {
                     string key = current.Attribute("Name");
                     string str2 = current.Attribute("Description");
                     if ((key != null) && (str2 != null))
                     {
                         hashtable.Add(key, str2);
                     }
                 }
             }
         }
         else
         {
             hashtable = null;
         }
         SecurityElement element3 = e.SearchForChildByTag("FullTrustAssemblies");
         if ((element3 != null) && (element3.InternalChildren != null))
         {
             string assemblyQualifiedName = typeof(StrongNameMembershipCondition).AssemblyQualifiedName;
             IEnumerator enumerator2 = element3.Children.GetEnumerator();
             while (enumerator2.MoveNext())
             {
                 StrongNameMembershipCondition condition = new StrongNameMembershipCondition();
                 condition.FromXml((SecurityElement) enumerator2.Current);
                 list.Add(condition);
             }
         }
         this.m_fullTrustAssemblies = list;
         ArrayList list2 = new ArrayList();
         SecurityElement elem = e.SearchForChildByTag("NamedPermissionSets");
         SecurityElement element5 = null;
         if ((elem != null) && (elem.InternalChildren != null))
         {
             element5 = this.UnnormalizeClassDeep(elem, hashtable);
             foreach (string str3 in s_reservedNamedPermissionSets)
             {
                 this.FindElement(element5, str3);
             }
         }
         if (element5 == null)
         {
             element5 = new SecurityElement("NamedPermissionSets");
         }
         list2.Add(BuiltInPermissionSets.FullTrust);
         list2.Add(BuiltInPermissionSets.Everything);
         list2.Add(BuiltInPermissionSets.SkipVerification);
         list2.Add(BuiltInPermissionSets.Execution);
         list2.Add(BuiltInPermissionSets.Nothing);
         list2.Add(BuiltInPermissionSets.Internet);
         list2.Add(BuiltInPermissionSets.LocalIntranet);
         foreach (PermissionSet set in list2)
         {
             set.IgnoreTypeLoadFailures = true;
         }
         this.m_namedPermissionSets = list2;
         this.m_permSetElement = element5;
         SecurityElement element6 = e.SearchForChildByTag("CodeGroup");
         if (element6 == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", new object[] { "CodeGroup", base.GetType().FullName }));
         }
         CodeGroup group = XMLUtil.CreateCodeGroup(this.UnnormalizeClassDeep(element6, hashtable));
         if (group == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", new object[] { "CodeGroup", base.GetType().FullName }));
         }
         group.FromXml(element6, this);
         this.m_rootCodeGroup = group;
     }
 }
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(S._("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				permissions.Clear();
				if(state != PermissionState.Unrestricted)
				{
					SecurityElement child =
						esd.SearchForChildByTag("ConnectAccess");
					if(child != null)
					{
						AddFromXml(child, NetworkAccess.Connect);
					}
					child = esd.SearchForChildByTag("AcceptAccess");
					if(child != null)
					{
						AddFromXml(child, NetworkAccess.Accept);
					}
				}
			}
        /// <summary>
        /// Restores the internal state of the permission to reflect
        /// a previously captured permission described in the SecurityElement.
        /// </summary>
        /// <param name="elem">Security element containing an XML representation
        /// of the permission.</param>
        public override void FromXml(SecurityElement elem)
        {
            if (elem == null)
                throw new ArgumentNullException("elem");

            if (!elem.Tag.Equals("IPermission"))
            {
                throw new ArgumentException("Missing IPermission element", "elem");
            }
            string cls = elem.Attribute("class");
            if (cls == null)
            {
                throw new ArgumentException("Missing class element", "elem");
            }
            if (cls.IndexOf(base.GetType().FullName) < 0)
            {
                throw new ArgumentException("Missing type name element", "elem");
            }
            string unre = elem.Attribute("Unrestricted");
            this._keys = new List<string>();
            if ((unre != null) && (string.Compare(unre, "true", StringComparison.OrdinalIgnoreCase) == 0))
            {
                this._isUnrestricted = true;
            }
            else
            {
                string name;
                this._isUnrestricted = false;
                SecurityElement keys = elem.SearchForChildByTag("AccessKeys");
                if (keys != null)
                {
                    foreach (SecurityElement key in keys.Children)
                    {
                        if (!key.Tag.Equals("Key"))
                        {
                            continue;
                        }
                        else
                        {
                            try
                            {
                                name = key.Attribute("name");
                            }
                            catch
                            {
                                name = null;
                            }
                            if (name == null)
                                throw new ArgumentException("Invalid key name", "elem");
                            else
                                _keys.Add(name);
                        }
                    }
                }
            }
        }
 protected override void ParseXml(SecurityElement e, PolicyLevel level)
 {
     this.ResetConnectAccess();
     SecurityElement element = e.SearchForChildByTag("connectAccessRules");
     if ((element == null) || (element.Children == null))
     {
         this.SetDefaults();
     }
     else
     {
         foreach (SecurityElement element2 in element.Children)
         {
             if (element2.Tag.Equals("codeOrigin"))
             {
                 string originScheme = element2.Attribute("scheme");
                 bool flag = false;
                 if (element2.Children != null)
                 {
                     foreach (SecurityElement element3 in element2.Children)
                     {
                         if (element3.Tag.Equals("connectAccess"))
                         {
                             string allowScheme = element3.Attribute("scheme");
                             string allowPort = element3.Attribute("port");
                             this.AddConnectAccess(originScheme, new CodeConnectAccess(allowScheme, allowPort));
                             flag = true;
                         }
                     }
                 }
                 if (!flag)
                 {
                     this.AddConnectAccess(originScheme, null);
                 }
             }
         }
     }
 }
Example #18
0
        /// <devdoc>
        /// </devdoc>
        public override void FromXml(SecurityElement securityElement) {
            if (securityElement == null) {

                //
                // null SecurityElement
                //

                throw new ArgumentNullException("securityElement");
            }
            if (!securityElement.Tag.Equals("IPermission")) {

                //
                // SecurityElement must be a permission element
                //

                throw new ArgumentException(SR.GetString(SR.net_not_ipermission), "securityElement");
            }

            string className = securityElement.Attribute("class");

            if (className == null) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException(SR.GetString(SR.net_no_classname), "securityElement");
            }
            if (className.IndexOf(this.GetType().FullName) < 0) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException(SR.GetString(SR.net_no_typename), "securityElement");
            }

            String str = securityElement.Attribute("Unrestricted");

            m_connectList = new ArrayList();
            m_acceptList = new ArrayList();
            m_UnrestrictedAccept = m_UnrestrictedConnect = false;

            if (str != null && string.Compare(str, "true", StringComparison.OrdinalIgnoreCase ) == 0)
            {
                m_noRestriction = true;
                return;
            }

            m_noRestriction = false;

            SecurityElement et = securityElement.SearchForChildByTag("ConnectAccess");
            string uriPattern;

            if (et != null) {

                foreach(SecurityElement uriElem in et.Children) {
                    //NOTE: Any stuff coming from XML is treated as URI PATTERN!
                    if (uriElem.Tag.Equals("URI")) {
                        try {
                            uriPattern = uriElem.Attribute("uri");
                        }
                        catch {
                            uriPattern = null;
                        }
                        if (uriPattern == null) {
                            throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val_in_element), "ConnectAccess");
                        }
                        if (uriPattern == MatchAll)
                        {
                            m_UnrestrictedConnect = true;
                            m_connectList = new ArrayList();
                            break;
                        }
                        else
                        {
                            AddAsPattern(NetworkAccess.Connect, new DelayedRegex(uriPattern));
                        }
                    }
                    else {
                        // improper tag found, just ignore
                    }
                }
            }

            et = securityElement.SearchForChildByTag("AcceptAccess");
            if (et != null) {

                foreach(SecurityElement uriElem in et.Children) {
                    //NOTE: Any stuff coming from XML is treated as URI PATTERN!
                    if (uriElem.Tag.Equals("URI")) {
                        try {
                            uriPattern = uriElem.Attribute("uri");
                        }
                        catch {
                            uriPattern = null;
                        }
                        if (uriPattern == null) {
                            throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val_in_element), "AcceptAccess");
                        }
                        if (uriPattern == MatchAll)
                        {
                            m_UnrestrictedAccept = true;
                            m_acceptList = new ArrayList();
                            break;
                        }
                        else
                        {
                            AddAsPattern(NetworkAccess.Accept, new DelayedRegex(uriPattern));
                        }
                    }
                    else {
                        // improper tag found, just ignore
                    }
                }
            }
        }
        static public PolicyLevel LoadPolicyLevelFromString(String str, PolicyLevelType type)
        {
#if _DEBUG
            if (debug)
            {
                DEBUG_OUT("Input string =");
                DEBUG_OUT(str);
            }
#endif

            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            String name = Enum.GetName(typeof(PolicyLevelType), type);

            if (name == null)
            {
                return(null);
            }

            Parser parser = new Parser(str);

            PolicyLevel level = new PolicyLevel(name, ConfigId.None, type == PolicyLevelType.Machine);

            SecurityElement elRoot = parser.GetTopElement();

            if (elRoot == null)
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "configuration"));
            }

            SecurityElement elMscorlib = elRoot.SearchForChildByTag("mscorlib");

            if (elMscorlib == null)
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "mscorlib"));
            }

            SecurityElement elSecurity = elMscorlib.SearchForChildByTag("security");

            if (elSecurity == null)
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "security"));
            }

            SecurityElement elPolicy = elSecurity.SearchForChildByTag("policy");

            if (elPolicy == null)
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "policy"));
            }

            SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag("PolicyLevel");

            if (elPolicyLevel != null)
            {
                level.FromXml(elPolicyLevel);
            }
            else
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "PolicyLevel"));
            }

            level.Loaded = true;

            return(level);
        }
 public override void FromXml(SecurityElement securityElement)
 {
     if (securityElement == null)
     {
         throw new ArgumentNullException("securityElement");
     }
     if (!securityElement.Tag.Equals("IPermission"))
     {
         throw new ArgumentException(SR.GetString("net_not_ipermission"), "securityElement");
     }
     string str = securityElement.Attribute("class");
     if (str == null)
     {
         throw new ArgumentException(SR.GetString("net_no_classname"), "securityElement");
     }
     if (str.IndexOf(base.GetType().FullName) < 0)
     {
         throw new ArgumentException(SR.GetString("net_no_typename"), "securityElement");
     }
     this.initialize();
     string strA = securityElement.Attribute("Unrestricted");
     if (strA != null)
     {
         this.m_noRestriction = 0 == string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase);
         if (this.m_noRestriction)
         {
             return;
         }
     }
     this.m_noRestriction = false;
     this.m_connectList = new ArrayList();
     this.m_acceptList = new ArrayList();
     SecurityElement et = securityElement.SearchForChildByTag("ConnectAccess");
     if (et != null)
     {
         ParseAddXmlElement(et, this.m_connectList, "ConnectAccess, ");
     }
     et = securityElement.SearchForChildByTag("AcceptAccess");
     if (et != null)
     {
         ParseAddXmlElement(et, this.m_acceptList, "AcceptAccess, ");
     }
 }
 public void FromXml(SecurityElement element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
     }
     this.m_appTrustedToRun = false;
     string strA = element.Attribute("TrustedToRun");
     if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
     {
         this.m_appTrustedToRun = true;
     }
     this.m_persist = false;
     string str2 = element.Attribute("Persist");
     if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
     {
         this.m_persist = true;
     }
     this.m_appId = null;
     string applicationIdentityFullName = element.Attribute("FullName");
     if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
     {
         this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
     }
     this.m_psDefaultGrant = null;
     this.m_grantSetSpecialFlags = 0;
     SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");
     if (element2 != null)
     {
         SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
         if (et != null)
         {
             PolicyStatement statement = new PolicyStatement(null);
             statement.FromXml(et);
             this.m_psDefaultGrant = statement;
             this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
         }
     }
     List<StrongName> list = new List<StrongName>();
     SecurityElement element4 = element.SearchForChildByTag("FullTrustAssemblies");
     if ((element4 != null) && (element4.InternalChildren != null))
     {
         IEnumerator enumerator = element4.Children.GetEnumerator();
         while (enumerator.MoveNext())
         {
             StrongName item = new StrongName();
             item.FromXml(enumerator.Current as SecurityElement);
             list.Add(item);
         }
     }
     this.m_fullTrustAssemblies = list.AsReadOnly();
     this.m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
 }
        protected override void ParseXml( SecurityElement e, PolicyLevel level )
        {
            //Reset the exiting content
            ResetConnectAccess();

            SecurityElement et = e.SearchForChildByTag("connectAccessRules");

            if (et == null || et.Children == null)
            {
                SetDefaults();
                return;
            }

            foreach(SecurityElement codeOriginElem in et.Children)
            {
                if (codeOriginElem.Tag.Equals("codeOrigin"))
                {
                    string originScheme = codeOriginElem.Attribute("scheme");
                    bool oneAdded = false;

                    if (codeOriginElem.Children != null)
                    {
                        foreach(SecurityElement accessElem in codeOriginElem.Children)
                        {
                            if (accessElem.Tag.Equals("connectAccess"))
                            {
                                string connectScheme = accessElem.Attribute("scheme");
                                string connectPort   = accessElem.Attribute("port");
                                AddConnectAccess(originScheme, new CodeConnectAccess(connectScheme, connectPort));
                                oneAdded = true;
                            }
                            else {
                                // improper tag found, just ignore
                            }
                        }
                    }

                    if (!oneAdded)
                    {
                        //special case as to no talkback access for a given scheme
                        AddConnectAccess(originScheme, null);
                    }

                }
                else {
                    // improper tag found, just ignore
                }
            }
        }
        /// <devdoc>
        /// </devdoc>
        public override void FromXml(SecurityElement securityElement) {
            if (securityElement == null) {

                //
                // null SecurityElement
                //

                throw new ArgumentNullException("securityElement");
            }
            if (!securityElement.Tag.Equals("IPermission")) {

                //
                // SecurityElement must be a permission element
                //

                throw new ArgumentException(SR.GetString(SR.net_not_ipermission), "securityElement");
            }

            string className = securityElement.Attribute("class");

            if (className == null) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException(SR.GetString(SR.net_no_classname), "securityElement");
            }
            if (className.IndexOf(this.GetType().FullName) < 0) {

                //
                // SecurityElement must be a permission element for this type
                //

                throw new ArgumentException(SR.GetString(SR.net_no_typename), "securityElement");
            }

            //
            // Start recovering the state from XML encoding
            //

            initialize();


            String str = securityElement.Attribute("Unrestricted");

            if (str != null) {
                m_noRestriction = (0 == string.Compare( str, "true", StringComparison.OrdinalIgnoreCase ));
                if(m_noRestriction)
                    return;
            }

            m_noRestriction = false;
            m_connectList = new ArrayList();
            m_acceptList = new ArrayList();

            SecurityElement et = securityElement.SearchForChildByTag("ConnectAccess");
            if (et != null) {
                ParseAddXmlElement(et, m_connectList, "ConnectAccess, ");
            }
            et = securityElement.SearchForChildByTag("AcceptAccess");
            if (et != null) {
                ParseAddXmlElement(et, m_acceptList, "AcceptAccess, ");
            }
        }