Beispiel #1
0
        // note: more than one configuration file can be loaded at the
        // same time (e.g. user specific and machine specific config).
        static public void LoadConfig(string filename)
        {
            if (File.Exists(filename))
            {
                SecurityParser sp = new SecurityParser();
                using (StreamReader sr = new StreamReader(filename)) {
                    string xml = sr.ReadToEnd();
                    sp.LoadXml(xml);
                }
                SecurityElement root = sp.ToXml();
                if ((root != null) && (root.Tag == "configuration"))
                {
                    SecurityElement strongnames = root.SearchForChildByTag("strongNames");
                    if ((strongnames != null) && (strongnames.Children.Count > 0))
                    {
                        SecurityElement mapping = strongnames.SearchForChildByTag("pubTokenMapping");
                        if ((mapping != null) && (mapping.Children.Count > 0))
                        {
                            LoadMapping(mapping);
                        }

                        SecurityElement settings = strongnames.SearchForChildByTag("verificationSettings");
                        if ((settings != null) && (settings.Children.Count > 0))
                        {
                            LoadVerificationSettings(settings);
                        }
                    }
                }
            }
        }
        /// <summary>Reconstructs an <see cref="T:System.Security.Policy.ApplicationTrust" /> object with a given state from an XML encoding.</summary>
        /// <param name="element">The XML encoding to use to reconstruct the <see cref="T:System.Security.Policy.ApplicationTrust" /> object. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="element" /> is null. </exception>
        /// <exception cref="T:System.ArgumentException">The XML encoding used for <paramref name="element" /> is invalid.</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
        /// </PermissionSet>
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (element.Tag != "ApplicationTrust")
            {
                throw new ArgumentException("element");
            }
            string text = element.Attribute("FullName");

            if (text != null)
            {
                this._appid = new ApplicationIdentity(text);
            }
            else
            {
                this._appid = null;
            }
            this._defaultPolicy = null;
            SecurityElement securityElement = element.SearchForChildByTag("DefaultGrant");

            if (securityElement != null)
            {
                for (int i = 0; i < securityElement.Children.Count; i++)
                {
                    SecurityElement securityElement2 = securityElement.Children[i] as SecurityElement;
                    if (securityElement2.Tag == "PolicyStatement")
                    {
                        this.DefaultGrantSet.FromXml(securityElement2, null);
                        break;
                    }
                }
            }
            if (!bool.TryParse(element.Attribute("TrustedToRun"), out this._trustrun))
            {
                this._trustrun = false;
            }
            if (!bool.TryParse(element.Attribute("Persist"), out this._persist))
            {
                this._persist = false;
            }
            this._xtranfo = null;
            SecurityElement securityElement3 = element.SearchForChildByTag("ExtraInfo");

            if (securityElement3 != null)
            {
                text = securityElement3.Attribute("Data");
                if (text != null)
                {
                    byte[] buffer = CryptoConvert.FromHex(text);
                    using (MemoryStream memoryStream = new MemoryStream(buffer))
                    {
                        BinaryFormatter binaryFormatter = new BinaryFormatter();
                        this._xtranfo = binaryFormatter.Deserialize(memoryStream);
                    }
                }
            }
        }
 public static void LoadConfig(string filename)
 {
     if (File.Exists(filename))
     {
         SecurityParser securityParser = new SecurityParser();
         using (StreamReader streamReader = new StreamReader(filename))
         {
             string xml = streamReader.ReadToEnd();
             securityParser.LoadXml(xml);
         }
         SecurityElement securityElement = securityParser.ToXml();
         if (securityElement != null && securityElement.Tag == "configuration")
         {
             SecurityElement securityElement2 = securityElement.SearchForChildByTag("strongNames");
             if (securityElement2 != null && securityElement2.Children.Count > 0)
             {
                 SecurityElement securityElement3 = securityElement2.SearchForChildByTag("pubTokenMapping");
                 if (securityElement3 != null && securityElement3.Children.Count > 0)
                 {
                     StrongNameManager.LoadMapping(securityElement3);
                 }
                 SecurityElement securityElement4 = securityElement2.SearchForChildByTag("verificationSettings");
                 if (securityElement4 != null && securityElement4.Children.Count > 0)
                 {
                     StrongNameManager.LoadVerificationSettings(securityElement4);
                 }
             }
         }
     }
 }
        private bool ParseMembershipCondition(bool safeLoad)
        {
            lock (this)
            {
                IMembershipCondition membershipCondition   = null;
                SecurityElement      elMembershipCondition = m_element.SearchForChildByTag("IMembershipCondition");
                if (elMembershipCondition != null)
                {
                    try
                    {
                        membershipCondition = System.Security.Util.XMLUtil.CreateMembershipCondition(elMembershipCondition, safeLoad);

                        if (membershipCondition == null)
                        {
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), ex);
                    }
                    membershipCondition.FromXml(elMembershipCondition, m_parentLevel);
                }
                else
                {
                    throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_InvalidXMLElement"), "IMembershipCondition", this.GetType().FullName));
                }

                m_membershipCondition = membershipCondition;
                return(true);
            }
        }
Beispiel #5
0
        /// <summary>Reconstructs a security object with a given state from an XML encoding.</summary>
        /// <param name="e">The XML encoding to use to reconstruct the security object. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentException">The <see cref="T:System.Security.SecurityElement" /> specified by the <paramref name="e" /> parameter is invalid. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
        /// </PermissionSet>
        public void FromXml(SecurityElement e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            SecurityElement securityElement = e.SearchForChildByTag("SecurityClasses");

            if (securityElement != null && securityElement.Children != null && securityElement.Children.Count > 0)
            {
                this.fullNames = new Hashtable(securityElement.Children.Count);
                foreach (object obj in securityElement.Children)
                {
                    SecurityElement securityElement2 = (SecurityElement)obj;
                    this.fullNames.Add(securityElement2.Attributes["Name"], securityElement2.Attributes["Description"]);
                }
            }
            SecurityElement securityElement3 = e.SearchForChildByTag("FullTrustAssemblies");

            if (securityElement3 != null && securityElement3.Children != null && securityElement3.Children.Count > 0)
            {
                this.full_trust_assemblies.Clear();
                foreach (object obj2 in securityElement3.Children)
                {
                    SecurityElement securityElement4 = (SecurityElement)obj2;
                    if (securityElement4.Tag != "IMembershipCondition")
                    {
                        throw new ArgumentException(Locale.GetText("Invalid XML"));
                    }
                    string text = securityElement4.Attribute("class");
                    if (text.IndexOf("StrongNameMembershipCondition") < 0)
                    {
                        throw new ArgumentException(Locale.GetText("Invalid XML - must be StrongNameMembershipCondition"));
                    }
                    this.full_trust_assemblies.Add(new StrongNameMembershipCondition(securityElement4));
                }
            }
            SecurityElement securityElement5 = e.SearchForChildByTag("CodeGroup");

            if (securityElement5 != null && securityElement5.Children != null && securityElement5.Children.Count > 0)
            {
                this.root_code_group = CodeGroup.CreateFromXml(securityElement5, this);
                SecurityElement securityElement6 = e.SearchForChildByTag("NamedPermissionSets");
                if (securityElement6 != null && securityElement6.Children != null && securityElement6.Children.Count > 0)
                {
                    this.named_permission_sets.Clear();
                    foreach (object obj3 in securityElement6.Children)
                    {
                        SecurityElement    et = (SecurityElement)obj3;
                        NamedPermissionSet namedPermissionSet = new NamedPermissionSet();
                        namedPermissionSet.Resolver = this;
                        namedPermissionSet.FromXml(et);
                        this.named_permission_sets.Add(namedPermissionSet);
                    }
                }
                return;
            }
            throw new ArgumentException(Locale.GetText("Missing Root CodeGroup"));
        }
Beispiel #6
0
        /// <summary>Reconstructs a security object with a given state and policy level from an XML encoding.</summary>
        /// <param name="e">The XML encoding to use to reconstruct the security object. </param>
        /// <param name="level">The policy level within which the code group exists. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
        public void FromXml(SecurityElement e, PolicyLevel level)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            string        text = e.Attribute("PermissionSetName");
            PermissionSet permissionSet;

            if (text != null && level != null)
            {
                permissionSet = level.GetNamedPermissionSet(text);
            }
            else
            {
                SecurityElement securityElement = e.SearchForChildByTag("PermissionSet");
                if (securityElement != null)
                {
                    Type type = Type.GetType(securityElement.Attribute("class"));
                    permissionSet = (PermissionSet)Activator.CreateInstance(type, true);
                    permissionSet.FromXml(securityElement);
                }
                else
                {
                    permissionSet = new PermissionSet(new PermissionSet(PermissionState.None));
                }
            }
            this.m_policy = new PolicyStatement(permissionSet);
            this.m_children.Clear();
            if (e.Children != null && e.Children.Count > 0)
            {
                foreach (object obj in e.Children)
                {
                    SecurityElement securityElement2 = (SecurityElement)obj;
                    if (securityElement2.Tag == "CodeGroup")
                    {
                        this.AddChild(CodeGroup.CreateFromXml(securityElement2, level));
                    }
                }
            }
            this.m_membershipCondition = null;
            SecurityElement securityElement3 = e.SearchForChildByTag("IMembershipCondition");

            if (securityElement3 != null)
            {
                string text2 = securityElement3.Attribute("class");
                Type   type2 = Type.GetType(text2);
                if (type2 == null)
                {
                    type2 = Type.GetType("System.Security.Policy." + text2);
                }
                this.m_membershipCondition = (IMembershipCondition)Activator.CreateInstance(type2, true);
                this.m_membershipCondition.FromXml(securityElement3, level);
            }
            this.m_name        = e.Attribute("Name");
            this.m_description = e.Attribute("Description");
            this.ParseXml(e, level);
        }
    // Delete the specified security element if the current time is past
    // the time stored in the destroytime tag.
    private static SecurityElement DestroyTree(SecurityElement xmlElement)
    {
        SecurityElement localXmlElement = xmlElement;
        SecurityElement destroyElement  =
            localXmlElement.SearchForChildByTag("destroytime");

        // Verify that a destroytime tag exists.
        //<Snippet17>
        if (localXmlElement.SearchForChildByTag("destroytime") != null)
        //</Snippet17>
        {
            // Retrieve the destroytime text to get the time
            // the tree can be destroyed.
            //<Snippet18>
            string storedDestroyTime =
                localXmlElement.SearchForTextOfTag("destroytime");
            //</Snippet18>

            DateTime destroyTime = DateTime.Parse(storedDestroyTime);
            if (DateTime.Now > destroyTime)
            {
                localXmlElement = null;
                Console.WriteLine("The XML security tree has been deleted.");
            }
        }

        // Verify that xmlElement is of type SecurityElement.
        //<Snippet21>
        if (xmlElement.GetType().Equals(
                typeof(System.Security.SecurityElement)))
        //</Snippet21>
        {
            // Determine whether the localXmlElement object
            // differs from xmlElement.
            //<Snippet20>
            if (xmlElement.Equals(localXmlElement))
            //</Snippet20>
            {
                // Verify that the tags, attributes and children of the
                // two security elements are identical.
                //<Snippet22>
                if (xmlElement.Equal(localXmlElement))
                //</Snippet22>
                {
                    // Return the original security element.
                    return(xmlElement);
                }
            }
        }

        // Return the modified security element.
        return(localXmlElement);
    }
 public void SearchForChildByTag_Null()
 {
     try {
         elem.SearchForChildByTag(null);
         Assert.Fail("#1");
     } catch (ArgumentNullException ex) {
         Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2");
         Assert.IsNull(ex.InnerException, "#3");
         Assert.IsNotNull(ex.Message, "#4");
         Assert.IsNotNull(ex.ParamName, "#5");
         Assert.AreEqual("tag", ex.ParamName, "#6");
     }
 }
Beispiel #9
0
        public void SearchForChildByTag()
        {
            SecurityElement elem  = CreateElement();
            SecurityElement child = elem.SearchForChildByTag("doesnotexist");

            Assert.Null(child);

            child = elem.SearchForChildByTag("ENDPOINT");
            Assert.Null(child);

            child = (SecurityElement)elem.Children[0];
            child = child.SearchForChildByTag("ENDPOINT");
            Assert.Equal("All", child.Attribute("transport"));
        }
Beispiel #10
0
 private static IApplicationTrustManager DecodeAppTrustManager()
 {
     if (File.InternalExists(ApplicationSecurityManager.s_machineConfigFile))
     {
         string end;
         using (FileStream fileStream = new FileStream(ApplicationSecurityManager.s_machineConfigFile, FileMode.Open, FileAccess.Read))
             end = new StreamReader((Stream)fileStream).ReadToEnd();
         SecurityElement securityElement1 = SecurityElement.FromString(end).SearchForChildByTag("mscorlib");
         if (securityElement1 != null)
         {
             SecurityElement securityElement2 = securityElement1.SearchForChildByTag("security");
             if (securityElement2 != null)
             {
                 SecurityElement securityElement3 = securityElement2.SearchForChildByTag("policy");
                 if (securityElement3 != null)
                 {
                     SecurityElement securityElement4 = securityElement3.SearchForChildByTag("ApplicationSecurityManager");
                     if (securityElement4 != null)
                     {
                         SecurityElement elTrustManager = securityElement4.SearchForChildByTag("IApplicationTrustManager");
                         if (elTrustManager != null)
                         {
                             IApplicationTrustManager applicationTrustManager = ApplicationSecurityManager.DecodeAppTrustManagerFromElement(elTrustManager);
                             if (applicationTrustManager != null)
                             {
                                 return(applicationTrustManager);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(ApplicationSecurityManager.DecodeAppTrustManagerFromElement(ApplicationSecurityManager.CreateDefaultApplicationTrustManagerElement()));
 }
        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, ");
            }
        }
        private static IApplicationTrustManager DecodeAppTrustManager()
        {
            if (!File.InternalExists(s_machineConfigFile))
            {
                goto defaultTrustManager;
            }

            // A config file exists. Decode the trust manager from its Xml.
            String configFileStr;

            using (FileStream contents = new FileStream(s_machineConfigFile, FileMode.Open, FileAccess.Read))
            {
                configFileStr = new StreamReader(contents).ReadToEnd();
            }

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

            if (elMscorlib == null)
            {
                goto defaultTrustManager;
            }
            SecurityElement elSecurity = elMscorlib.SearchForChildByTag("security");

            if (elSecurity == null)
            {
                goto defaultTrustManager;
            }
            SecurityElement elPolicy = elSecurity.SearchForChildByTag("policy");

            if (elPolicy == null)
            {
                goto defaultTrustManager;
            }
            SecurityElement elSecurityManager = elPolicy.SearchForChildByTag("ApplicationSecurityManager");

            if (elSecurityManager == null)
            {
                goto defaultTrustManager;
            }
            SecurityElement elTrustManager = elSecurityManager.SearchForChildByTag("IApplicationTrustManager");

            if (elTrustManager == null)
            {
                goto defaultTrustManager;
            }
            IApplicationTrustManager appTrustManager = DecodeAppTrustManagerFromElement(elTrustManager);

            if (appTrustManager == null)
            {
                goto defaultTrustManager;
            }
            return(appTrustManager);

defaultTrustManager:
            return(DecodeAppTrustManagerFromElement(CreateDefaultApplicationTrustManagerElement()));
        }
Beispiel #13
0
        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((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), (object)"PolicyStatement", (object)this.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 = (PermissionSet)null;
                if (level != null)
                {
                    string local_3 = et.Attribute("PermissionSetName");
                    if (local_3 != null)
                    {
                        this.m_permSet = (PermissionSet)level.GetNamedPermissionSetInternal(local_3);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    SecurityElement local_4 = et.SearchForChildByTag("PermissionSet");
                    if (local_4 == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                    string local_5 = local_4.Attribute("class");
                    this.m_permSet = local_5 == null || !local_5.Equals("NamedPermissionSet") && !local_5.Equals("System.Security.NamedPermissionSet") ? new PermissionSet(PermissionState.None) : (PermissionSet) new NamedPermissionSet("DefaultName", PermissionState.None);
                    try
                    {
                        this.m_permSet.FromXml(local_4, allowInternalOnly, true);
                    }
                    catch
                    {
                    }
                }
                if (this.m_permSet != null)
                {
                    return;
                }
                this.m_permSet = new PermissionSet(PermissionState.None);
            }
        }
Beispiel #14
0
 private AssembleSetting.Assemble LoadSuiteAssembleFromXml(SecurityElement element)
 {
     return(new AssembleSetting.Assemble {
         RequiredCount = StrParser.ParseDecInt(element.Attribute("RequiredCount"), 0),
         AssembleEffectDesc = StrParser.ParseStr(element.Attribute("AssembleEffectDesc"), string.Empty, true),
         ModifierSet = PropertyModifierSet.LoadFromXml(element.SearchForChildByTag("ModifierSet")),
         AssemblePower = StrParser.ParseDecInt(element.Attribute("AssemblePower"), 0),
         AssemblePowerPercent = StrParser.ParseFloat(element.Attribute("AssemblePowerPercent"), 0f)
     });
 }
Beispiel #15
0
        private byte[] GetNamedParam(SecurityElement se, string param)
        {
            SecurityElement securityElement = se.SearchForChildByTag(param);

            if (securityElement == null)
            {
                return(null);
            }
            return(Convert.FromBase64String(securityElement.Text));
        }
Beispiel #16
0
        /// <summary>
        /// 获取当前版本
        /// </summary>
        /// <returns>The version.</returns>
        private string getVersion()
        {
            SecurityParser sp = new SecurityParser();

            UnityEngine.Debug.Log(FConst.F_INTERNAL_VERSION_LIST_PATH);
            sp.LoadXml(Util.readTextFromInternal(FConst.F_INTERNAL_VERSION_LIST_PATH));
            SecurityElement root = sp.ToXml();
            SecurityElement ele  = root.SearchForChildByTag("CurrentVersion");

            return(ele.Text);
        }
    // Add a child element to the specified security element.
    private static SecurityElement AddChildElement(
        SecurityElement parentElement,
        string tagName,
        string tagText)
    {
        if (parentElement != null)
        {
            // Ensure that the tag text is in valid XML format.
            //<Snippet9>
            if (!SecurityElement.IsValidText(tagText))
            //</Snippet9>
            {
                // Replace invalid text with valid XML text
                // to enforce proper XML formatting.
                //<Snippet19>
                tagText = SecurityElement.Escape(tagText);
                //</Snippet19>
            }

            // Determine whether the tag is in valid XML format.
            //<Snippet10>
            if (SecurityElement.IsValidTag(tagName))
            //</Snippet10>
            {
                //<Snippet24>
                SecurityElement childElement;
                childElement = parentElement.SearchForChildByTag(tagName);
                //</Snippet24>

                if (childElement != null)
                {
                    //<Snippet25>
                    String elementText;
                    elementText = parentElement.SearchForTextOfTag(tagName);
                    //</Snippet25>

                    if (!elementText.Equals(tagText))
                    {
                        // Add child element to the parent security element.
                        parentElement.AddChild(
                            new SecurityElement(tagName, tagText));
                    }
                }
                else
                {
                    // Add child element to the parent security element.
                    parentElement.AddChild(
                        new SecurityElement(tagName, tagText));
                }
            }
        }
        return(parentElement);
    }
        /// 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);
        }
        public void SearchForChildByTag()
        {
            SecurityElement child = elem.SearchForChildByTag("doesnotexist");

            Assert.IsNull(child, "#1");

            child = elem.SearchForChildByTag("ENDPOINT");
            Assert.IsNull(child, "#2");

            child = (SecurityElement)elem.Children [0];
            child = child.SearchForChildByTag("ENDPOINT");
            Assert.AreEqual("All", child.Attribute("transport"), "#3");
        }
        protected override void ParseXml(SecurityElement e, PolicyLevel level)
        {
            //Reset the exiting content
            ResetConnectAccess();

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

            if (et == null || et.Children == null)
            {
                // Everett behavior, same as calling a default ctor.
                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
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// 需要先 Load Xml
        /// </summary>
        /// <param name="xmlContent"></param>
        /// <returns></returns>
        private Dictionary <string, string> GetBaseKV()
        {
            Dictionary <string, string> base_kv = new Dictionary <string, string>();
            SecurityElement             e_root  = m_parser.ToXml();
            SecurityElement             e_data  = e_root.SearchForChildByTag(TAG_DATA);

            foreach (SecurityElement e_data_item in e_data.Children)
            {
                string key   = e_data_item.Attributes[TAG_ID].ToString();
                string value = e_data_item.Attributes[BASE_KV_TITLE].ToString();
                base_kv.Add(key, value);
            }
            return(base_kv);
        }
Beispiel #22
0
        // 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);
                }
            }
        }
Beispiel #23
0
    private string parse(SecurityElement dom, string domPath)
    {
        if (dom == null || string.IsNullOrEmpty(domPath))
        {
            return(string.Empty);
        }
        SecurityElement node     = dom;
        var             subpaths = domPath.Split('/');

        for (int i = 1; node != null && i < subpaths.Length; ++i)
        {
            var tag = subpaths[i];
            node = node.SearchForChildByTag(tag);
        }
        return(node != null ? node.Text : string.Empty);
    }
        private void FromXml(string xml)
        {
            SecurityParser securityParser = new SecurityParser();

            securityParser.LoadXml(xml);
            SecurityElement securityElement = securityParser.ToXml();

            if (securityElement.Tag == "KeyPair")
            {
                SecurityElement securityElement2 = securityElement.SearchForChildByTag("KeyValue");
                if (securityElement2.Children.Count > 0)
                {
                    this._keyvalue = securityElement2.Children[0].ToString();
                }
            }
        }
        public void SearchForChildByTag_Null()
        {
            SecurityElement elem = CreateElement();

            try
            {
                elem.SearchForChildByTag(null);
                Assert.False(true);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal(typeof(ArgumentNullException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
                Assert.NotNull(ex.ParamName);
                Assert.Equal("tag", ex.ParamName);
            }
        }
        private void FromXml(string xml)
        {
            SecurityParser securityParser = new SecurityParser();

            securityParser.LoadXml(xml);
            SecurityElement xml1 = securityParser.ToXml();

            if (!(xml1.Tag == "KeyPair"))
            {
                return;
            }
            SecurityElement securityElement = xml1.SearchForChildByTag("KeyValue");

            if (securityElement.Children.Count <= 0)
            {
                return;
            }
            this._keyvalue = securityElement.Children[0].ToString();
        }
Beispiel #27
0
        /// <summary>
        ///     Not Implement right now
        /// </summary>
        /// <param name="e"></param>
        public void FromXml(SecurityElement e)
        {
            var rolesContainer = e.SearchForChildByTag(Roles);

            AllManditory = e.Attribute(nameof(AllManditory)) == "1";
            if (rolesContainer == null)
            {
                return;
            }

            foreach (var entry in rolesContainer.Attributes.Keys.OfType <string>())
            {
                var attributeValue = e.Attribute(entry);
                if (attributeValue == "1" || attributeValue == "true")
                {
                    _roles.Add(entry);
                }
            }
        }
        private void FromXml(string xml)
        {
            SecurityParser sp = new SecurityParser();

            sp.LoadXml(xml);

            SecurityElement root = sp.ToXml();

            if (root.Tag == "KeyPair")
            {
                //SecurityElement prop = root.SearchForChildByTag ("Properties");
                SecurityElement keyv = root.SearchForChildByTag("KeyValue");
                if (keyv.Children.Count > 0)
                {
                    _keyvalue = keyv.Children [0].ToString();
                }
                // Note: we do not read other stuff because
                // it can't be changed after key creation
            }
        }
        /// <summary>Reconstructs a security object with a given state from an XML encoding.</summary>
        /// <param name="et">The XML encoding to use to reconstruct the security object. </param>
        /// <param name="level">The <see cref="T:System.Security.Policy.PolicyLevel" /> context for lookup of <see cref="T:System.Security.NamedPermissionSet" /> values. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="et" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentException">The <paramref name="et" /> parameter is not a valid <see cref="T:System.Security.Policy.PolicyStatement" /> encoding. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
        /// </PermissionSet>
        public void FromXml(SecurityElement et, PolicyLevel level)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (et.Tag != "PolicyStatement")
            {
                throw new ArgumentException(Locale.GetText("Invalid tag."));
            }
            string text = et.Attribute("Attributes");

            if (text != null)
            {
                this.attrs = (PolicyStatementAttribute)((int)Enum.Parse(typeof(PolicyStatementAttribute), text));
            }
            SecurityElement et2 = et.SearchForChildByTag("PermissionSet");

            this.PermissionSet.FromXml(et2);
        }
Beispiel #30
0
        public void SearchForChildByTag_Null()
        {
            SecurityElement elem = CreateElement();

            try
            {
                elem.SearchForChildByTag(null);
                Assert.False(true);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal(typeof(ArgumentNullException), ex.GetType());
                Assert.Null(ex.InnerException);
                if (!PlatformDetection.IsNetNative)  // .Net Native toolchain optimizes away exception messages and paramnames.
                {
                    Assert.NotNull(ex.Message);
                    Assert.NotNull(ex.ParamName);
                    Assert.Equal("tag", ex.ParamName);
                }
            }
        }
		public void FromXml (SecurityElement et, PolicyLevel level)
		{
			if (et == null)
				throw new ArgumentNullException ("et");
			if (et.Tag != "PolicyStatement")
				throw new ArgumentException (Locale.GetText ("Invalid tag."));


			string attributes = et.Attribute ("Attributes");
			if (attributes != null) {
				attrs = (PolicyStatementAttribute) Enum.Parse (
					typeof (PolicyStatementAttribute), attributes);
			}

			SecurityElement permissions = et.SearchForChildByTag ("PermissionSet");
			PermissionSet.FromXml (permissions);
		}
	// Implement the ISecurityPolicyEncodable interface.
	public void FromXml(SecurityElement et, PolicyLevel level)
			{
				if(et == null)
				{
					throw new ArgumentNullException("et");
				}
				if(et.Tag != "PolicyStatement")
				{
					throw new ArgumentException
						(_("Security_PolicyName"));
				}
				if(et.Attribute("version") != "1")
				{
					throw new ArgumentException
						(_("Security_PolicyVersion"));
				}
				String value = et.Attribute("Attributes");
				if(value != null)
				{
					attributes = (PolicyStatementAttribute)
						Enum.Parse(typeof(PolicyStatementAttribute), value);
				}
				else
				{
					attributes = PolicyStatementAttribute.Nothing;
				}
				permSet = null;
				if(level != null)
				{
					String name = et.Attribute("PermissionSetName");
					if(name != null)
					{
						permSet = level.GetNamedPermissionSet(value);
						if(permSet == null)
						{
							permSet = new PermissionSet(PermissionState.None);
						}
					}
				}
				if(permSet == null)
				{
					SecurityElement child;
					child = et.SearchForChildByTag("PermissionSet");
					if(child != null)
					{
						String permClass;
						permClass = child.Attribute("class");
						if(permClass != null &&
						   permClass.IndexOf("NamedPermissionSet") != -1)
						{
							permSet = new NamedPermissionSet
								("DefaultName", PermissionState.None);
						}
						else
						{
							permSet = new PermissionSet(PermissionState.None);
						}
						try
						{
							permSet.FromXml(child);
						}
						catch(Exception)
						{
							// Ignore errors during set loading.
						}
					}
				}
				if(permSet == null)
				{
					permSet = new PermissionSet(PermissionState.None);
				}
			}
Beispiel #33
0
        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")); 
 
#if FEATURE_CLICKONCE
            m_appTrustedToRun = false; 
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
                m_appTrustedToRun = true;
            } 

            m_persist = false; 
            string persist = element.Attribute("Persist"); 
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
                m_persist = true; 
            }

            m_appId = null;
            string fullName = element.Attribute("FullName"); 
            if (fullName != null && fullName.Length > 0) {
                m_appId = new ApplicationIdentity(fullName); 
            } 
#endif // FEATURE_CLICKONCE
 
            m_psDefaultGrant = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) { 
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) { 
                    PolicyStatement ps = new PolicyStatement(null); 
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps; 
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }
 
            List<StrongName> fullTrustAssemblies = new List<StrongName>();
            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies"); 
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) { 
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext()) { 
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                } 
            }
 
            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly(); 

#if FEATURE_CLICKONCE 
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }
Beispiel #34
0
		private byte[] GetNamedParam(SecurityElement se, string param) {
			SecurityElement sep = se.SearchForChildByTag(param);
			if (sep == null)
				return null;
			return Convert.FromBase64String(sep.Text);
		}
Beispiel #35
0
		public void FromXml (SecurityElement element) 
		{
			if (element == null)
				throw new ArgumentNullException ("element");

			if (element.Tag != "ApplicationTrust")
				throw new ArgumentException ("element");

			string s = element.Attribute ("FullName");
			if (s != null)
				_appid = new ApplicationIdentity (s);
			else
				_appid = null;

			_defaultPolicy = null;
			SecurityElement defaultGrant = element.SearchForChildByTag ("DefaultGrant");
			if (defaultGrant != null) {
				for (int i=0; i < defaultGrant.Children.Count; i++) {
					SecurityElement se = (defaultGrant.Children [i] as SecurityElement);
					if (se.Tag == "PolicyStatement") {
						DefaultGrantSet.FromXml (se, null);
						break;
					}
				}
			}

			if (!Boolean.TryParse (element.Attribute ("TrustedToRun"), out _trustrun))
				_trustrun = false;

			if (!Boolean.TryParse (element.Attribute ("Persist"), out _persist))
				_persist = false;

			_xtranfo = null;
			SecurityElement xtra = element.SearchForChildByTag ("ExtraInfo");
			if (xtra != null) {
				s = xtra.Attribute ("Data");
				if (s != null) {
					byte[] data = CryptoConvert.FromHex (s);
					using (MemoryStream ms = new MemoryStream (data)) {
						BinaryFormatter bf = new BinaryFormatter ();
						_xtranfo = bf.Deserialize (ms);
					}
				}
			}
		}
		public void FromXml (SecurityElement e)
		{
			if (e == null)
				throw new ArgumentNullException ("e");
// MS doesn't throw an exception for this case
//			if (e.Tag != "PolicyLevel")
//				throw new ArgumentException (Locale.GetText ("Invalid XML"));

			SecurityElement sc = e.SearchForChildByTag ("SecurityClasses");
			if ((sc != null) && (sc.Children != null) && (sc.Children.Count > 0)) {
				fullNames = new Hashtable (sc.Children.Count);
				foreach (SecurityElement se in sc.Children) {
					fullNames.Add (se.Attributes ["Name"], se.Attributes ["Description"]);
				}
			}

			SecurityElement fta = e.SearchForChildByTag ("FullTrustAssemblies");
			if ((fta != null) && (fta.Children != null) && (fta.Children.Count > 0)) {
				full_trust_assemblies.Clear ();
				foreach (SecurityElement se in fta.Children) {
					if (se.Tag != "IMembershipCondition")
						throw new ArgumentException (Locale.GetText ("Invalid XML"));
					string className = se.Attribute ("class");
					if (className.IndexOf ("StrongNameMembershipCondition") < 0)
						throw new ArgumentException (Locale.GetText ("Invalid XML - must be StrongNameMembershipCondition"));
					// we directly use StrongNameMembershipCondition
					full_trust_assemblies.Add (new StrongNameMembershipCondition (se));
				}
			}

			SecurityElement cg = e.SearchForChildByTag ("CodeGroup");
			if ((cg != null) && (cg.Children != null) && (cg.Children.Count > 0)) {
				root_code_group = CodeGroup.CreateFromXml (cg, this);
			} else {
				throw new ArgumentException (Locale.GetText ("Missing Root CodeGroup"));
			}

			SecurityElement nps = e.SearchForChildByTag ("NamedPermissionSets");
			if ((nps != null) && (nps.Children != null) && (nps.Children.Count > 0)) {
				named_permission_sets.Clear ();
				foreach (SecurityElement se in nps.Children) {
					NamedPermissionSet n = new NamedPermissionSet ();
					n.Resolver = this;
					n.FromXml (se);
					named_permission_sets.Add (n);
				}
			}
		}
        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"));

            m_psDefaultGrant = null;
            m_fullTrustAssemblies = null;
            m_appTrustedToRun = false;

            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
                m_appTrustedToRun = true;
            string persist = element.Attribute("Persist");
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
                m_persist = true;

            string fullName = element.Attribute("FullName");
            if (fullName != null && fullName.Length > 0)
                m_appId = new ApplicationIdentity(fullName);

            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps;
                }
            }

            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
                m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count];
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                int index = 0;
                while (enumerator.MoveNext()) {
                    m_fullTrustAssemblies[index] = new StrongName();
                    m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement);
                    index++;
                }
            }

            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
        }
	public void FromXml(SecurityElement et, PolicyLevel level)
			{
				SecurityElement child;
				String className;
				Type type;
				ArrayList list;
				CodeGroup group;

				if(et == null)
				{
					throw new ArgumentNullException("et");
				}
				if(et.Tag != "CodeGroup")
				{
					throw new ArgumentException
						(_("Security_CodeGroupName"));
				}
				if(et.Attribute("version") != "1")
				{
					throw new ArgumentException
						(_("Security_PolicyVersion"));
				}
				name = et.Attribute("Name");
				description = et.Attribute("Description");

				// Load the membership condition information for the group.
				child = et.SearchForChildByTag("IMembershipCondition");
				if(child != null)
				{
					className = child.Attribute("class");
					if(className == null)
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					type = Type.GetType(className);
					if(type == null && className.IndexOf('.') == -1)
					{
						// May not have been fully-qualified.
						type = Type.GetType
							("System.Security.Policy." + className);
					}
					if(!typeof(IMembershipCondition).IsAssignableFrom(type))
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					membershipCondition =
						(Activator.CreateInstance(type)
								as IMembershipCondition);
					if(membershipCondition != null)
					{
						membershipCondition.FromXml(child, level);
					}
				}
				else
				{
					throw new ArgumentException
						(_("Arg_InvalidMembershipCondition"));
				}

				// Load the children within this code group.
				list = new ArrayList();
				foreach(SecurityElement elem in et.Children)
				{
					if(elem.Tag != "CodeGroup")
					{
						continue;
					}
					className = child.Attribute("class");
					if(className == null)
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					type = Type.GetType(className);
					if(type == null && className.IndexOf('.') == -1)
					{
						// May not have been fully-qualified.
						type = Type.GetType
							("System.Security.Policy." + className);
					}
					if(!typeof(CodeGroup).IsAssignableFrom(type))
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					group = (Activator.CreateInstance(type) as CodeGroup);
					if(group != null)
					{
						group.FromXml(elem, level);
						list.Add(group);
					}
				}
				children = list;

				// Parse subclass-specific data from the element.
				ParseXml(et, level);
			}
Beispiel #39
0
		public void FromXml (SecurityElement e, PolicyLevel level)
		{
			if (null == e)
				throw new ArgumentNullException("e");

			PermissionSet ps = null;
			string psetname = e.Attribute ("PermissionSetName");
			if ((psetname != null) && (level != null)) {
				ps = level.GetNamedPermissionSet (psetname);
			}
			else {
				SecurityElement pset = e.SearchForChildByTag ("PermissionSet");
				if (pset != null) {
					Type classType = Type.GetType (pset.Attribute ("class"));
					ps = (PermissionSet) Activator.CreateInstance (classType, true);
					ps.FromXml (pset);
				}
				else {
					ps = new PermissionSet (new PermissionSet (PermissionState.None));
				}
			}
			m_policy = new PolicyStatement (ps);

			m_children.Clear ();
			if ((e.Children != null) && (e.Children.Count > 0)) {
				foreach (SecurityElement se in e.Children) {
					if (se.Tag == "CodeGroup") {
						this.AddChild (CodeGroup.CreateFromXml (se, level));
					}
				}
			}
			
			m_membershipCondition = null;
			SecurityElement mc = e.SearchForChildByTag ("IMembershipCondition");
			if (mc != null) {
				string className = mc.Attribute ("class");
				Type classType = Type.GetType (className);
				if (classType == null)
					classType = Type.GetType ("System.Security.Policy." + className);
				m_membershipCondition = (IMembershipCondition) Activator.CreateInstance (classType, true);
				m_membershipCondition.FromXml (mc, level);
			}

			m_name = e.Attribute("Name");
			m_description = e.Attribute("Description");

			// seems like we might need this to Resolve() in subclasses
			//m_level = level;

			ParseXml (e, level);
		}
        public void FromXml(SecurityElement e) {
            if (e == null)
                throw new ArgumentNullException("e");
            Contract.EndContractBlock();

            Hashtable classes;
            lock (this) {
                ArrayList fullTrustAssemblies = new ArrayList();

                SecurityElement eClasses = e.SearchForChildByTag("SecurityClasses");
                if (eClasses != null) {
                    classes = new Hashtable();
                    IEnumerator enumerator = eClasses.Children.GetEnumerator();
                    while (enumerator.MoveNext()) {
                        SecurityElement current = (SecurityElement)enumerator.Current;
                        if (current.Tag.Equals("SecurityClass")) {
                            string name = current.Attribute("Name");
                            string description = current.Attribute("Description");

                            if (name != null && description != null)
                                classes.Add(name, description);
                        }
                    }
                }
                else {
                    classes = null;
                }

                SecurityElement elFullTrust = e.SearchForChildByTag("FullTrustAssemblies");
                if (elFullTrust != null && elFullTrust.InternalChildren != null) {
                    string className = typeof(System.Security.Policy.StrongNameMembershipCondition).AssemblyQualifiedName;

                    IEnumerator enumerator = elFullTrust.Children.GetEnumerator();
                    while (enumerator.MoveNext()) {
                        StrongNameMembershipCondition sn = new StrongNameMembershipCondition();
                        sn.FromXml((SecurityElement)enumerator.Current);
                        fullTrustAssemblies.Add(sn);
                    }
                }

                m_fullTrustAssemblies = fullTrustAssemblies;

                ArrayList namedPermissionSets = new ArrayList();

                SecurityElement elPermSets = e.SearchForChildByTag("NamedPermissionSets");
                SecurityElement permSetElement = null;

                // Here we just find the parent element for the named permission sets and
                // store it so that we can lazily load them later.

                if (elPermSets != null && elPermSets.InternalChildren != null) {
                    permSetElement = UnnormalizeClassDeep(elPermSets, classes);

                    // Call FindElement for each of the reserved sets (this removes their xml from
                    // permSetElement).
                    foreach (string builtInPermissionSet in s_reservedNamedPermissionSets) {
                        FindElement(permSetElement, builtInPermissionSet);
                    }
                }

                if (permSetElement == null)
                    permSetElement = new SecurityElement("NamedPermissionSets");

                // Then we add in the immutable permission sets (this prevents any alterations
                // to them in the XML file from impacting the runtime versions).

                namedPermissionSets.Add(BuiltInPermissionSets.FullTrust);
                namedPermissionSets.Add(BuiltInPermissionSets.Everything);
                namedPermissionSets.Add(BuiltInPermissionSets.SkipVerification);
                namedPermissionSets.Add(BuiltInPermissionSets.Execution);
                namedPermissionSets.Add(BuiltInPermissionSets.Nothing);
                namedPermissionSets.Add(BuiltInPermissionSets.Internet);
                namedPermissionSets.Add(BuiltInPermissionSets.LocalIntranet);

                foreach(PermissionSet ps in namedPermissionSets)
                    ps.IgnoreTypeLoadFailures = true;

                m_namedPermissionSets = namedPermissionSets;
                m_permSetElement = permSetElement;

                // Parse the root code group.
                SecurityElement elCodeGroup = e.SearchForChildByTag("CodeGroup");
                if (elCodeGroup == null)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement",  "CodeGroup", this.GetType().FullName));

                CodeGroup rootCodeGroup = System.Security.Util.XMLUtil.CreateCodeGroup(UnnormalizeClassDeep(elCodeGroup, classes));
                if (rootCodeGroup == null)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement",  "CodeGroup", this.GetType().FullName));

                rootCodeGroup.FromXml(elCodeGroup, this);
                m_rootCodeGroup = rootCodeGroup;
            }
        }