AddChild() private method

private AddChild ( ISecurityElementFactory child ) : void
child ISecurityElementFactory
return void
Exemplo n.º 1
0
    //removePath将要删除的路径
    static public string GetFileListXMLString(List <string> fileList, string removePath)
    {
        var root = new System.Security.SecurityElement("root");

        foreach (var item in fileList)
        {
            string fileName = Path.GetFileName(item);
            string ext      = Path.GetExtension(item);
            if (string.Compare(ext, ".meta", true) == 0)
            {
                continue;
            }

            string filePath = null;
            if (IsUseAssetBundle)
            {
                filePath = item.Replace(removePath, "");
                root.AddChild(new System.Security.SecurityElement("k", fileName.ToLower()));
                root.AddChild(new System.Security.SecurityElement("v", filePath.ToLower()));
            }
            else
            {
                filePath = item.Replace(removePath, "");
                root.AddChild(new System.Security.SecurityElement("k", fileName));
                root.AddChild(new System.Security.SecurityElement("v", filePath));
            }
        }

        return(root.ToString());
    }
 internal SecurityElement ToXml()
 {
     SecurityElement element2;
     SecurityElement element = new SecurityElement("System.Security.Policy.PermissionRequestEvidence");
     element.AddAttribute("version", "1");
     if (this.m_request != null)
     {
         element2 = new SecurityElement("Request");
         element2.AddChild(this.m_request.ToXml());
         element.AddChild(element2);
     }
     if (this.m_optional != null)
     {
         element2 = new SecurityElement("Optional");
         element2.AddChild(this.m_optional.ToXml());
         element.AddChild(element2);
     }
     if (this.m_denied != null)
     {
         element2 = new SecurityElement("Denied");
         element2.AddChild(this.m_denied.ToXml());
         element.AddChild(element2);
     }
     return element;
 }
Exemplo n.º 3
0
    //在生成资源包时使用
    static public string SerializeInEditor(List <ResInfo> listResInfo)
    {
        string      innerText        = MyFileUtil.ReadConfigDataInStreamingAssets(VersionManager.VersionInfoFilePath);
        VersionInfo innerVersionInfo = VersionInfo.ParseData(innerText);

        var root = new System.Security.SecurityElement("root");

        root.AddChild(new System.Security.SecurityElement("ProgramVersion", innerVersionInfo.ProgramVersion.ToString()));
        root.AddChild(new System.Security.SecurityElement("ApkUrl", innerVersionInfo.ApkUrl));
        root.AddChild(new System.Security.SecurityElement("ApkMd5"));
        root.AddChild(new System.Security.SecurityElement("IOSAppUrl", innerVersionInfo.IOSAppUrl));
        root.AddChild(new System.Security.SecurityElement("IOSAppStoreUrl", innerVersionInfo.IOSAppStoreUrl));
        root.AddChild(new System.Security.SecurityElement("IsAppleAppStore", innerVersionInfo.IsAppleAppStore.ToString()));
        root.AddChild(new System.Security.SecurityElement("IsOpenAutoUpdateInAppStore", innerVersionInfo.IsOpenAutoUpdateInAppStore.ToString()));
        root.AddChild(new System.Security.SecurityElement("IsForceToUpdate", innerVersionInfo.IsForceToUpdate.ToString()));
        var resInfoNode = new System.Security.SecurityElement("ResInfo");

        root.AddChild(resInfoNode);

        foreach (var item in listResInfo)
        {
            var recordNode = new System.Security.SecurityElement("Record");
            resInfoNode.AddChild(recordNode);

            recordNode.AddChild(new System.Security.SecurityElement("ResName", item.resName));
            recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.resMD5));
            recordNode.AddChild(new System.Security.SecurityElement("ResURL", item.resURL));
            recordNode.AddChild(new System.Security.SecurityElement("ResSize", item.resSize.ToString()));
            recordNode.AddChild(new System.Security.SecurityElement("ResRequire", "true"));
            recordNode.AddChild(new System.Security.SecurityElement("resRequireID", item.resRequireID.ToString()));
        }

        return(root.ToString());
    }
Exemplo n.º 4
0
    private void BuildPathFile()
    {
        var root = new System.Security.SecurityElement("root");

        foreach (var item in m_instance.m_filesDic)
        {
            root.AddChild(new System.Security.SecurityElement("k", item.Key));
            root.AddChild(new System.Security.SecurityElement("v", item.Value));
        }
        XMLParser.SaveText(m_instance.m_resourcePath + "resourceInfo.xml", root.ToString());
    }
	public void Constructor_SecurityElement_RSA ()
	{
		SecurityElement se = new SecurityElement ("RSASignature");
		se.AddChild (new SecurityElement ("Key", "System.Security.Cryptography.RSACryptoServiceProvider"));
		se.AddChild (new SecurityElement ("Digest", "System.Security.Cryptography.SHA1CryptoServiceProvider"));
		se.AddChild (new SecurityElement ("Formatter", "System.Security.Cryptography.RSAPKCS1SignatureFormatter"));
		se.AddChild (new SecurityElement ("Deformatter", "System.Security.Cryptography.RSAPKCS1SignatureDeformatter"));

		SignatureDescription sig = new SignatureDescription (se);
		Assert.AreEqual ("System.Security.Cryptography.RSACryptoServiceProvider", sig.KeyAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.SHA1CryptoServiceProvider", sig.DigestAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.RSAPKCS1SignatureFormatter", sig.FormatterAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.RSAPKCS1SignatureDeformatter", sig.DeformatterAlgorithm);
	}
Exemplo n.º 6
0
 private SecurityElement ToXml()
 {
     SecurityElement root = new SecurityElement("System.Xml.XmlSecureResolver");
     root.AddAttribute("version", "1");
     root.AddChild(new SecurityElement("UncDirectory", _uncDir));
     return root;
 }
Exemplo n.º 7
0
        internal static void EncodeLevel (PolicyLevel level)
        {
            Contract.Assert(level != null, "No policy level to encode.");

            // We cannot encode a policy level without a backing file  
            if (level.Path == null)
            {
                string errorMessage = Environment.GetResourceString("Policy_UnableToSave",
                                                    level.Label,
                                                    Environment.GetResourceString("Policy_SaveNotFileBased"));
                throw new PolicyException(errorMessage);
            }
                
            SecurityElement elConf = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                StringBuilder sb = new StringBuilder();
                Encoding encoding = Encoding.UTF8;

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                sb.Append(format.ToString());
                sb.Append(elConf.ToString());

                byte[] data = encoding.GetBytes(sb.ToString());

                // Write out the new config.
                int hrSave = Config.SaveDataByte(level.Path, data, data.Length);
                Exception extendedError = Marshal.GetExceptionForHR(hrSave);
                if (extendedError != null)
                {
                    string extendedInformation = extendedError != null ? extendedError.Message : String.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, extendedInformation), extendedError);
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, e.Message), e);
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
        }
Exemplo n.º 8
0
        public SecurityElement ToXml()
        {
            SecurityElement se = new SecurityElement(tagName);

            foreach (PermissionSet ps in _list)
            {
                se.AddChild(ps.ToXml());
            }
            return(se);
        }
 internal SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("System.Security.Policy.ApplicationDirectory");
     element.AddAttribute("version", "1");
     if (this.m_appDirectory != null)
     {
         element.AddChild(new SecurityElement("Directory", this.m_appDirectory.ToString()));
     }
     return element;
 }
Exemplo n.º 10
0
    //序列化为字符串
    static public string Serialize(VersionInfo versionInfo)
    {
        var root = new System.Security.SecurityElement("root");

        root.AddChild(new System.Security.SecurityElement("ProgramVersion", versionInfo.ProgramVersion.ToString()));
        var resInfoNode = new System.Security.SecurityElement("ResInfo");

        root.AddChild(resInfoNode);

        foreach (var item in versionInfo.dictRes)
        {
            var recordNode = new System.Security.SecurityElement("Record");
            resInfoNode.AddChild(recordNode);

            recordNode.AddChild(new System.Security.SecurityElement("ResName", item.Value.resName));
            recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.Value.resMD5));
        }

        return(root.ToString());
    }
Exemplo n.º 11
0
    private void SaveVersion(VersionManagerInfo version)
    {
        var props = typeof(VersionManagerInfo).GetProperties();
        var root  = new System.Security.SecurityElement("root");

        foreach (var item in props)
        {
            root.AddChild(new System.Security.SecurityElement(item.Name, item.GetGetMethod().Invoke(version, null) as String));
        }
        XMLParser.SaveText(SystemConfig.VersionPath, root.ToString());
    }
Exemplo n.º 12
0
        internal static void EncodeLevel(PolicyLevel level)
        {
            SecurityElement elConf     = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy   = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                StringBuilder sb       = new StringBuilder();
                Encoding      encoding = Encoding.UTF8;

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                sb.Append(format.ToString());
                sb.Append(elConf.ToString());

                byte[] data = encoding.GetBytes(sb.ToString());

                // Write out the new config.
                if (level.Path == null || !Config.SaveDataByte(level.Path, data, 0, data.Length))
                {
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                {
                    throw e;
                }
                else
                {
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label), e);
                }
            }
            catch
            {
                throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
            {
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
            }
        }
Exemplo n.º 13
0
        internal static void EncodeLevel(PolicyLevel level)
        {
            if (level.Path == null)
            {
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)Environment.GetResourceString("Policy_SaveNotFileBased")));
            }
            SecurityElement securityElement1 = new SecurityElement("configuration");
            SecurityElement child1           = new SecurityElement("mscorlib");
            SecurityElement child2           = new SecurityElement("security");
            SecurityElement child3           = new SecurityElement("policy");

            securityElement1.AddChild(child1);
            child1.AddChild(child2);
            child2.AddChild(child3);
            child3.AddChild(level.ToXml());
            try
            {
                StringBuilder   stringBuilder    = new StringBuilder();
                Encoding        utF8             = Encoding.UTF8;
                SecurityElement securityElement2 = new SecurityElement("xml");
                securityElement2.m_type = SecurityElementType.Format;
                securityElement2.AddAttribute("version", "1.0");
                securityElement2.AddAttribute("encoding", utF8.WebName);
                stringBuilder.Append(securityElement2.ToString());
                stringBuilder.Append(securityElement1.ToString());
                byte[]    bytes          = utF8.GetBytes(stringBuilder.ToString());
                string    path           = level.Path;
                byte[]    data           = bytes;
                int       length         = data.Length;
                Exception exceptionForHr = Marshal.GetExceptionForHR(Config.SaveDataByte(path, data, length));
                if (exceptionForHr != null)
                {
                    string str = exceptionForHr != null ? exceptionForHr.Message : string.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)str), exceptionForHr);
                }
            }
            catch (Exception ex)
            {
                if (ex is PolicyException)
                {
                    throw ex;
                }
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)ex.Message), ex);
            }
            Config.ResetCacheData(level.ConfigId);
            if (!PolicyManager.CanUseQuickCache(level.RootCodeGroup))
            {
                return;
            }
            Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level));
        }
Exemplo n.º 14
0
		private SecurityElement CreateElement ()
		{
			SecurityElement elem = new SecurityElement ("IPermission");
			elem.AddAttribute ("class", "System");
			elem.AddAttribute ("version", "1");
			
			SecurityElement child = new SecurityElement ("ConnectAccess");
			elem.AddChild (child);
			
			SecurityElement grandchild = new SecurityElement ("ENDPOINT", "some text");
			grandchild.AddAttribute ("transport", "All");
			grandchild.AddAttribute ("host", "localhost");
			grandchild.AddAttribute ("port", "8080");
			child.AddChild (grandchild);

			SecurityElement grandchild2 = new SecurityElement ("ENDPOINT");
			grandchild2.AddAttribute ("transport", "Tcp");
			grandchild2.AddAttribute ("host", "www.ximian.com");
			grandchild2.AddAttribute ("port", "All");
			child.AddChild (grandchild2);
			
			return elem;
		}
        internal static void EncodeLevel(PolicyLevel level)
        {
            if (level.Path == null)
            {
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") }));
            }
            SecurityElement element  = new SecurityElement("configuration");
            SecurityElement child    = new SecurityElement("mscorlib");
            SecurityElement element3 = new SecurityElement("security");
            SecurityElement element4 = new SecurityElement("policy");

            element.AddChild(child);
            child.AddChild(element3);
            element3.AddChild(element4);
            element4.AddChild(level.ToXml());
            try
            {
                StringBuilder   builder  = new StringBuilder();
                Encoding        encoding = Encoding.UTF8;
                SecurityElement element5 = new SecurityElement("xml")
                {
                    m_type = SecurityElementType.Format
                };
                element5.AddAttribute("version", "1.0");
                element5.AddAttribute("encoding", encoding.WebName);
                builder.Append(element5.ToString());
                builder.Append(element.ToString());
                byte[]    bytes          = encoding.GetBytes(builder.ToString());
                Exception exceptionForHR = Marshal.GetExceptionForHR(Config.SaveDataByte(level.Path, bytes, bytes.Length));
                if (exceptionForHR != null)
                {
                    string str2 = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, str2 }), exceptionForHR);
                }
            }
            catch (Exception exception2)
            {
                if (exception2 is PolicyException)
                {
                    throw exception2;
                }
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, exception2.Message }), exception2);
            }
            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
            {
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
            }
        }
Exemplo n.º 16
0
        // Convert this permission set into an XML security element.
        public virtual SecurityElement ToXml()
        {
            SecurityElement elem = new SecurityElement("PermissionSet");

            elem.AddAttribute
                ("class", typeof(PermissionSet).AssemblyQualifiedName);
            elem.AddAttribute("version", "1");
            if (IsUnrestricted())
            {
                elem.AddAttribute("Unrestricted", "true");
            }
            foreach (IPermission perm in permissions)
            {
                elem.AddChild(perm.ToXml());
            }
            return(elem);
        }
Exemplo n.º 17
0
        public virtual SecurityElement ToXml()
        {
            SecurityElement se = new SecurityElement(tagName);

            se.AddAttribute("class", GetType().FullName);
            se.AddAttribute("version", version.ToString());
            if (state == PermissionState.Unrestricted)
            {
                se.AddAttribute("Unrestricted", "true");
            }

            // required for permissions that do not implement IUnrestrictedPermission
            foreach (IPermission p in list)
            {
                se.AddChild(p.ToXml());
            }
            return(se);
        }
 public override SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("IPermission");
     element.AddAttribute("class", base.GetType().FullName + ", " + base.GetType().Module.Assembly.FullName.Replace('"', '\''));
     element.AddAttribute("version", "1");
     if (!this.IsUnrestricted())
     {
         string str = null;
         if (this.m_UnrestrictedConnect || (this.m_connectList.Count > 0))
         {
             SecurityElement child = new SecurityElement("ConnectAccess");
             if (this.m_UnrestrictedConnect)
             {
                 SecurityElement element3 = new SecurityElement("URI");
                 element3.AddAttribute("uri", SecurityElement.Escape(".*"));
                 child.AddChild(element3);
             }
             else
             {
                 foreach (object obj2 in this.m_connectList)
                 {
                     Uri uri = obj2 as Uri;
                     if (uri != null)
                     {
                         str = Regex.Escape(uri.GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped));
                     }
                     else
                     {
                         str = obj2.ToString();
                     }
                     if (obj2 is string)
                     {
                         str = Regex.Escape(str);
                     }
                     SecurityElement element4 = new SecurityElement("URI");
                     element4.AddAttribute("uri", SecurityElement.Escape(str));
                     child.AddChild(element4);
                 }
             }
             element.AddChild(child);
         }
         if (this.m_UnrestrictedAccept || (this.m_acceptList.Count > 0))
         {
             SecurityElement element5 = new SecurityElement("AcceptAccess");
             if (this.m_UnrestrictedAccept)
             {
                 SecurityElement element6 = new SecurityElement("URI");
                 element6.AddAttribute("uri", SecurityElement.Escape(".*"));
                 element5.AddChild(element6);
             }
             else
             {
                 foreach (object obj3 in this.m_acceptList)
                 {
                     Uri uri2 = obj3 as Uri;
                     if (uri2 != null)
                     {
                         str = Regex.Escape(uri2.GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped));
                     }
                     else
                     {
                         str = obj3.ToString();
                     }
                     if (obj3 is string)
                     {
                         str = Regex.Escape(str);
                     }
                     SecurityElement element7 = new SecurityElement("URI");
                     element7.AddAttribute("uri", SecurityElement.Escape(str));
                     element5.AddChild(element7);
                 }
             }
             element.AddChild(element5);
         }
         return element;
     }
     element.AddAttribute("Unrestricted", "true");
     return element;
 }
Exemplo n.º 19
0
        // Parse an element tag.
        private SecurityElement ParseElement()
        {
            // Create the new element.
            SecurityElement element;

            element = new SecurityElement(value);

            // Parse and add the attribute arguments.
            int    temp = 0;
            int    start;
            String name;
            String avalue;

            for (;;)
            {
                while (temp < args.Length && Char.IsWhiteSpace(args[temp]))
                {
                    ++temp;
                }
                if (temp >= args.Length)
                {
                    break;
                }
                start = temp;
                while (temp < args.Length && args[temp] != '=')
                {
                    ++temp;
                }
                name = args.Substring(start, temp - start);
                if (temp < args.Length)
                {
                    ++temp;
                }
                if (temp < args.Length && args[temp] == '"')
                {
                    ++temp;
                    start = temp;
                    while (temp < args.Length && args[temp] != '"')
                    {
                        ++temp;
                    }
                    avalue = args.Substring(start, temp - start);
                    if (temp < args.Length)
                    {
                        ++temp;
                    }
                }
                else if (temp < args.Length && args[temp] == '\'')
                {
                    ++temp;
                    start = temp;
                    while (temp < args.Length && args[temp] != '\'')
                    {
                        ++temp;
                    }
                    avalue = args.Substring(start, temp - start);
                    if (temp < args.Length)
                    {
                        ++temp;
                    }
                }
                else
                {
                    avalue = String.Empty;
                }
                element.AddAttribute(name, avalue);
            }

            // Parse the children of this element.
            if (token == Token.SingletonTag)
            {
                NextToken();
            }
            else
            {
                NextToken();
                while (token != Token.EOF && token != Token.EndTag)
                {
                    if (token == Token.StartTag ||
                        token == Token.SingletonTag)
                    {
                        SecurityElement child;
                        child = ParseElement();
                        element.AddChild(child);
                    }
                    else if (token == Token.Text)
                    {
                        String prevText = element.Text;
                        if (prevText != null)
                        {
                            element.Text = prevText + value;
                        }
                        else
                        {
                            element.Text = value;
                        }
                    }
                    NextToken();
                }
            }

            // Return the final element to the caller.
            return(element);
        }
Exemplo n.º 20
0
        private void WriteChildren(SecurityElement currentElement, object currentContent, int tagIndex) {
            IDictionaryEnumerator contentEnumerator = ((Hashtable)currentContent).GetEnumerator();
            while(contentEnumerator.MoveNext()) {
                SecurityElement contentElement = new SecurityElement(this.TagNames[tagIndex]);
                currentElement.AddChild(contentElement);
                contentElement.AddAttribute("name", (string)contentEnumerator.Key);

                if (tagIndex < (this.TagNames.Length -1))
                    WriteChildren(contentElement, contentEnumerator.Value, tagIndex + 1);
                else {
                    String accessString = null;
                    int currentAccess = (int)contentEnumerator.Value;
                    if (this.PermissionAccessType != null && currentAccess != 0) {
                        accessString = Enum.Format(PermissionAccessType, currentAccess, "g");
                        contentElement.AddAttribute("access", accessString);
                    }
                }
            }
        }
Exemplo n.º 21
0
		static SecurityElement AddSecurityXml (SecurityDeclarationCollection declarations)
		{
			ArrayList list = new ArrayList ();
			foreach (SecurityDeclaration declsec in declarations) {
				SecurityElement child = new SecurityElement ("Action");
				AddAttribute (child, "Name", declsec.Action.ToString ());
				child.AddChild (declsec.PermissionSet.ToXml ());
				list.Add (child);
			}
			// sort actions
			list.Sort (Comparer);

			SecurityElement se = new SecurityElement ("Actions");
			foreach (SecurityElement child in list) {
				se.AddChild (child);
			}
			return se;
		}
Exemplo n.º 22
0
		void Save ()
		{
			if (IsMarkedForDeletion)
				return;

			if (!File.Exists (file) && values.Count == 0)
				return;

			SecurityElement se = new SecurityElement ("values");
			
			// With SecurityElement.Text = value, and SecurityElement.AddAttribute(key, value)
			// the values must be escaped prior to being assigned. 
			foreach (DictionaryEntry de in values){
				object val = de.Value;
				SecurityElement value = new SecurityElement ("value");
				value.AddAttribute ("name", SecurityElement.Escape ((string) de.Key));
				
				if (val is string){
					value.AddAttribute ("type", "string");
					value.Text = SecurityElement.Escape ((string) val);
				} else if (val is int){
					value.AddAttribute ("type", "int");
					value.Text = val.ToString ();
				} else if (val is long) {
					value.AddAttribute ("type", "qword");
					value.Text = val.ToString ();
				} else if (val is byte []){
					value.AddAttribute ("type", "bytearray");
					value.Text = Convert.ToBase64String ((byte[]) val);
				} else if (val is ExpandString){
					value.AddAttribute ("type", "expand");
					value.Text = SecurityElement.Escape (val.ToString ());
				} else if (val is string []){
					value.AddAttribute ("type", "string-array");

					foreach (string ss in (string[]) val){
						SecurityElement str = new SecurityElement ("string");
						str.Text = SecurityElement.Escape (ss); 
						value.AddChild (str);
					}
				}
				se.AddChild (value);
			}

			using (FileStream fs = File.Create (file)){
				StreamWriter sw = new StreamWriter (fs);

				sw.Write (se.ToString ());
				sw.Flush ();
			}
		}
		public void FromXml () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			AssertNotNull ("ToXml()", se);

			PrincipalPermission p2 = (PrincipalPermission) p.Copy ();
			p2.FromXml (se);
			AssertEquals ("FromXml-Copy", p.ToString (), p2.ToString ());

			string className = (string) se.Attributes ["class"];
			string version = (string) se.Attributes ["version"];

			SecurityElement se2 = new SecurityElement (se.Tag);
			se2.AddAttribute ("class", className);
			se2.AddAttribute ("version", version);
			p2.FromXml (se2);

			SecurityElement sec = new SecurityElement ("Identity");
			sec.AddAttribute ("Authenticated", "true");
			se2.AddChild (sec);
			p2.FromXml (se2);
			Assert ("FromXml-Unrestricted", p2.IsUnrestricted ());
		}
 internal SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("System.Security.Policy.Zone");
     element.AddAttribute("version", "1");
     if (this.SecurityZone != System.Security.SecurityZone.NoZone)
     {
         element.AddChild(new SecurityElement("Zone", s_names[(int) this.SecurityZone]));
         return element;
     }
     element.AddChild(new SecurityElement("Zone", s_names[s_names.Length - 1]));
     return element;
 }
Exemplo n.º 25
0
        internal static void EncodeLevel(PolicyLevel level)
        {
            SecurityElement elConf     = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy   = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                MemoryStream stream = new MemoryStream(24576);

                StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false));

                Encoding encoding = level.Encoding;

                if (encoding == null)
                {
                    encoding = writer.Encoding;
                }

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                writer.Write(format.ToString());
                writer.Flush();
                writer = new StreamWriter(stream, encoding);

                writer.Write(elConf.ToString());

                writer.Flush();

                // Write out the new config.

                if (!Config.SaveData(level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length))
                {
                    throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label));
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                {
                    throw e;
                }
                else
                {
                    throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label), e);
                }
            }

            Config.ResetCacheData(level.ConfigId);

            try
            {
                if (CanUseQuickCache(level.RootCodeGroup))
                {
                    Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
                }
            }
            catch (Exception)
            {
            }
        }
 /// <summary>
 /// Creates an XML encoding of the security object and its current state.
 /// </summary>
 /// <returns>
 /// An XML encoding of the security object, including any state information.
 /// </returns>
 public SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("IPermission");
     Type type = base.GetType();
     StringBuilder builder = new StringBuilder(type.Assembly.ToString());
     builder.Replace('"', '\'');
     element.AddAttribute("class", type.FullName + ", " + builder);
     element.AddAttribute("version", "1");
     foreach (ResourceAction action in this._resourceActions)
     {
         SecurityElement child = new SecurityElement("ResourceAction");
         child.AddAttribute("resource", action.Resource);
         child.AddAttribute("action", action.Action);
         element.AddChild(child);
     }
     return element;
 }
Exemplo n.º 27
0
 private static SecurityElement XmlElementToSecurityElement(XmlElement xe)
 {
     SecurityElement se = new SecurityElement(xe.Name);
     foreach (XmlAttribute xa in xe.Attributes)
         se.AddAttribute(xa.Name, xa.Value);
     foreach (XmlNode xn in xe.ChildNodes)
         if (xn.NodeType == XmlNodeType.Element)
             se.AddChild(XmlElementToSecurityElement((XmlElement)xn));
     return se;
 }
Exemplo n.º 28
0
		public void FromXml_PermissionWithoutNamespace ()
		{
			SecurityElement child = new SecurityElement ("IPermission");
			child.AddAttribute ("class", "EnvironmentPermission");
			child.AddAttribute ("version", "1");
			child.AddAttribute ("Read", "USERNAME");

			SecurityElement se = new SecurityElement ("PermissionSet");
			se.AddAttribute ("class", "PermissionSet");
			se.AddAttribute ("version", "1");
			se.AddChild (child);

			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.FromXml (se);
		}
        public override SecurityElement ToXml() {

            SecurityElement securityElement = new SecurityElement( "IPermission" );

            securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace( '\"', '\'' ));
            securityElement.AddAttribute("version", "1");

            if(unrestricted){
                securityElement.AddAttribute("Unrestricted", "true");
                return securityElement;
            }

            if ((access & NetworkInformationAccess.Read) > 0) {
                SecurityElement child = new SecurityElement("NetworkInformationAccess");
                child.AddAttribute( "Access", "Read");
                securityElement.AddChild(child);
            }
            if ((access & NetworkInformationAccess.Ping) > 0) {
                SecurityElement child = new SecurityElement("NetworkInformationAccess");
                child.AddAttribute( "Access", "Ping");
                securityElement.AddChild(child);
            }
            return securityElement;
        }
Exemplo n.º 30
0
		public void FromXml_WithPermissionWithoutClass ()
		{
			SecurityElement child = new SecurityElement ("IPermission");
			child.AddAttribute ("version", "1");

			SecurityElement se = new SecurityElement ("PermissionSet");
			se.AddAttribute ("class", "PermissionSet");
			se.AddAttribute ("version", "1");
			se.AddChild (child);

			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.FromXml (se);
		}
 public override SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("IPermission");
     element.AddAttribute("class", base.GetType().FullName + ", " + base.GetType().Module.Assembly.FullName.Replace('"', '\''));
     element.AddAttribute("version", "1");
     if (this.unrestricted)
     {
         element.AddAttribute("Unrestricted", "true");
         return element;
     }
     if ((this.access & NetworkInformationAccess.Read) > NetworkInformationAccess.None)
     {
         SecurityElement child = new SecurityElement("NetworkInformationAccess");
         child.AddAttribute("Access", "Read");
         element.AddChild(child);
     }
     if ((this.access & NetworkInformationAccess.Ping) > NetworkInformationAccess.None)
     {
         SecurityElement element3 = new SecurityElement("NetworkInformationAccess");
         element3.AddAttribute("Access", "Ping");
         element.AddChild(element3);
     }
     return element;
 }
Exemplo n.º 32
0
        internal PolicyStatement CalculatePolicy( String host, String scheme, String port )
        {
            SecurityElement webPerm = CreateWebPermission( host, scheme, port );

            SecurityElement root = new SecurityElement( "PolicyStatement" );
            SecurityElement permSet = new SecurityElement( "PermissionSet" );
            permSet.AddAttribute( "class", "System.Security.PermissionSet" );
            permSet.AddAttribute( "version", "1" );

            if (webPerm != null)
                permSet.AddChild( webPerm );

            root.AddChild( permSet );

            PolicyStatement policy = new PolicyStatement();
            policy.FromXml( root );
            return policy;
        }
 internal SecurityElement ToXml()
 {
     SecurityElement element = new SecurityElement("System.Security.Policy.Site");
     element.AddAttribute("version", "1");
     if (this.m_name != null)
     {
         element.AddChild(new SecurityElement("Name", this.m_name.ToString()));
     }
     return element;
 }
		public void FromXml_InvalidVersion ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", "2");
			foreach (SecurityElement child in se.Children)
				w.AddChild (child);

			at.FromXml (w);
		}
Exemplo n.º 35
0
		static bool ProcessAssemblyXml (TextWriter tw, AssemblyDefinition ad)
		{
			SecurityElement se = new SecurityElement ("Assembly");
			se.AddAttribute ("Name", ad.Name.FullName);

			if (ad.SecurityDeclarations.Count > 0) {
				se.AddChild (AddSecurityXml (ad.SecurityDeclarations));
			}

			ArrayList tlist = new ArrayList ();
			ArrayList mlist = new ArrayList ();

			foreach (ModuleDefinition module in ad.Modules) {

				foreach (TypeDefinition type in module.Types) {

					SecurityElement klass = new SecurityElement ("Class");
					SecurityElement methods = new SecurityElement ("Methods");

					SecurityElement typelem = null;
					if (type.SecurityDeclarations.Count > 0) {
						typelem = AddSecurityXml (type.SecurityDeclarations);
					}

					if (mlist.Count > 0)
						mlist.Clear ();

					foreach (MethodDefinition method in type.Methods) {
						if (method.SecurityDeclarations.Count > 0) {
							SecurityElement meth = new SecurityElement ("Method");
							AddAttribute (meth, "Name", method.ToString ());
							meth.AddChild (AddSecurityXml (method.SecurityDeclarations));
							mlist.Add (meth);
						}
					}

					// sort methods
					mlist.Sort (Comparer);
					foreach (SecurityElement method in mlist) {
						methods.AddChild (method);
					}

					if ((typelem != null) || ((methods.Children != null) && (methods.Children.Count > 0))) {
						AddAttribute (klass, "Name", type.ToString ());
						if (typelem != null)
							klass.AddChild (typelem);
						if ((methods.Children != null) && (methods.Children.Count > 0))
							klass.AddChild (methods);
						tlist.Add (klass);
					}
				}

				// sort types
				tlist.Sort (Comparer);
				foreach (SecurityElement type in tlist) {
					se.AddChild (type);
				}
			}

			tw.WriteLine (se.ToString ());
			return true;
		}
Exemplo n.º 36
0
    public static string GetXMLListContent <T>(string path, List <T> data, string attrName = "record")
    {
        try
        {
            var root  = new System.Security.SecurityElement("root");
            var props = typeof(T).GetProperties();
            foreach (var item in data)
            {
                if (item == null)
                {
                    LoggerHelper.Error("null item: " + path);
                    continue;
                }
                var xml = new System.Security.SecurityElement(attrName);
                foreach (var prop in props)
                {
                    var    type   = prop.PropertyType;
                    String result = String.Empty;
                    object obj    = prop.GetGetMethod().Invoke(item, null);
                    if (obj == null)
                    {
                        LoggerHelper.Error("null obj: " + prop.Name);
                        continue;
                    }
                    //var obj = prop.GetValue(item, null);
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                    {
                        var o = typeof(Utils).GetMethod("PackMap")
                                .MakeGenericMethod(type.GetGenericArguments())
                                .Invoke(null, new object[] { obj, ':', ',' });
                        if (o != null)
                        {
                            result = o.ToString();
                        }
                        else
                        {
                            LoggerHelper.Error("null obj: " + prop.Name);
                        }
                    }
                    else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                    {
                        var o = typeof(Utils).GetMethod("PackList")
                                .MakeGenericMethod(type.GetGenericArguments())
                                .Invoke(null, new object[] { obj, ',' });

                        if (o != null)
                        {
                            result = o.ToString();
                        }
                        else
                        {
                            LoggerHelper.Error("null obj: " + prop.Name);
                        }
                    }
                    else
                    {
                        result = obj.ToString();
                    }
                    xml.AddChild(new System.Security.SecurityElement(prop.Name, result));
                }
                root.AddChild(xml);
            }
            return(root.ToString());
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
            return("");
        }
    }
Exemplo n.º 37
0
        // <IPermission class="...Permission" version="1" AllowBlankPassword=false>
        //     <add ConnectionString="provider=x;data source=y;"/>
        //     <add ConnectionString="provider=x;data source=y;" KeyRestrictions="user id=;password=;" KeyRestrictionBehavior=AllowOnly/>
        //     <add ConnectionString="provider=x;data source=y;" KeyRestrictions="address=;server=" KeyRestrictionBehavior=PreventUsage/>
        // </IPermission>
        override public SecurityElement ToXml() {
            Type type = this.GetType();
            SecurityElement root = new SecurityElement(XmlStr._IPermission);
            root.AddAttribute(XmlStr._class, type.AssemblyQualifiedName.Replace('\"', '\''));
            root.AddAttribute(XmlStr._Version, XmlStr._VersionNumber);

            if (IsUnrestricted()) {
                root.AddAttribute(XmlStr._Unrestricted, XmlStr._true);
            }
            else {
                root.AddAttribute(XmlStr._AllowBlankPassword, _allowBlankPassword.ToString(CultureInfo.InvariantCulture));

                if (null != _keyvalues) {
                    foreach(DBConnectionString value in _keyvalues) {
                        SecurityElement valueElement = new SecurityElement(XmlStr._add);
                        string tmp;

                        tmp = value.ConnectionString; // WebData 97375
                        tmp = EncodeXmlValue(tmp);
                        if (!ADP.IsEmpty(tmp)) {
                            valueElement.AddAttribute(XmlStr._ConnectionString, tmp);
                        }
                        tmp = value.Restrictions;
                        tmp = EncodeXmlValue(tmp);
                        if (null == tmp) { tmp = ADP.StrEmpty; }
                        valueElement.AddAttribute(XmlStr._KeyRestrictions, tmp);

                        tmp = value.Behavior.ToString();
                        valueElement.AddAttribute(XmlStr._KeyRestrictionBehavior, tmp);

                        root.AddChild(valueElement);
                    }
                }
            }
            return root;
        }
        internal static void EncodeLevel(PolicyLevel level)
        {
            if (level.Path == null)
            {
                string resourceString = Environment.GetResourceString("Policy_UnableToSave", new object[]
                {
                    level.Label,
                    Environment.GetResourceString("Policy_SaveNotFileBased")
                });
                throw new PolicyException(resourceString);
            }
            SecurityElement securityElement  = new SecurityElement("configuration");
            SecurityElement securityElement2 = new SecurityElement("mscorlib");
            SecurityElement securityElement3 = new SecurityElement("security");
            SecurityElement securityElement4 = new SecurityElement("policy");

            securityElement.AddChild(securityElement2);
            securityElement2.AddChild(securityElement3);
            securityElement3.AddChild(securityElement4);
            securityElement4.AddChild(level.ToXml());
            try
            {
                StringBuilder   stringBuilder    = new StringBuilder();
                Encoding        utf              = Encoding.UTF8;
                SecurityElement securityElement5 = new SecurityElement("xml");
                securityElement5.m_type = SecurityElementType.Format;
                securityElement5.AddAttribute("version", "1.0");
                securityElement5.AddAttribute("encoding", utf.WebName);
                stringBuilder.Append(securityElement5.ToString());
                stringBuilder.Append(securityElement.ToString());
                byte[]    bytes          = utf.GetBytes(stringBuilder.ToString());
                int       errorCode      = Config.SaveDataByte(level.Path, bytes, bytes.Length);
                Exception exceptionForHR = Marshal.GetExceptionForHR(errorCode);
                if (exceptionForHR != null)
                {
                    string text = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[]
                    {
                        level.Label,
                        text
                    }), exceptionForHR);
                }
            }
            catch (Exception ex)
            {
                if (ex is PolicyException)
                {
                    throw ex;
                }
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[]
                {
                    level.Label,
                    ex.Message
                }), ex);
            }
            Config.ResetCacheData(level.ConfigId);
            if (PolicyManager.CanUseQuickCache(level.RootCodeGroup))
            {
                Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level));
            }
        }
Exemplo n.º 39
0
		public void FromXml_PermissionOutsideCorlib ()
		{
			SecurityElement child = new SecurityElement ("IPermission");
			child.AddAttribute ("class", "PrintingPermission");	// System.Drawing
			child.AddAttribute ("version", "1");
			child.AddAttribute ("Level", "DefaultPrinting");

			SecurityElement se = new SecurityElement ("PermissionSet");
			se.AddAttribute ("class", "PermissionSet");
			se.AddAttribute ("version", "1");
			se.AddChild (child);

			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.FromXml (se);
		}
Exemplo n.º 40
0
        // internal helper which takes in the hardcoded permission name to avoid lookup at runtime
        // can be called from classes that derive from PermissionSet
        internal SecurityElement ToXml(String permName)
        {
            SecurityElement elTrunk = new SecurityElement("PermissionSet");
            elTrunk.AddAttribute( "class", permName );

            elTrunk.AddAttribute( "version", "1" );
        
            PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(this);
    
            if (m_Unrestricted)
            {
                elTrunk.AddAttribute(s_str_Unrestricted, "true" );
            }
   
            while (enumerator.MoveNext())
            {
                IPermission perm = (IPermission)enumerator.Current;

                if (!m_Unrestricted)
                    elTrunk.AddChild( perm.ToXml() );
            }
            return elTrunk;
        }
Exemplo n.º 41
0
        private SecurityElement CreateWebPermission(String host, String scheme, String port )
        {
            if (scheme == null)
                scheme = string.Empty;

            // If there is no OriginScheme host string, no talk back access is possible
            if (host == null || host.Length == 0)
                return null;

            host = host.ToLower(CultureInfo.InvariantCulture);
            scheme = scheme.ToLower(CultureInfo.InvariantCulture);

            int intPort = CodeConnectAccess.NoPort;
            if (port != null && port.Length != 0)
                intPort = Int32.Parse(port, CultureInfo.InvariantCulture );
            else
                port = string.Empty;

            CodeConnectAccess[] access = FindAccessRulesForScheme(scheme);
            if (access == null || access.Length == 0)
                return null;

            SecurityElement root = new SecurityElement( "IPermission" );

            root.AddAttribute( "class", "System.Net.WebPermission, System, Version=" + ThisAssembly.Version + ", Culture=neutral, PublicKeyToken=" + AssemblyRef.EcmaPublicKeyToken);
            root.AddAttribute( "version", "1" );

            SecurityElement connectAccess = new SecurityElement( "ConnectAccess" );

            host = EscapeStringForRegex(host);
            scheme = EscapeStringForRegex(scheme);
            string uriStr = TryPermissionAsOneString(access, scheme, host, intPort);

            if (uriStr != null)
            {
                SecurityElement uri = new SecurityElement( "URI" );
                uri.AddAttribute( "uri", uriStr );
                connectAccess.AddChild( uri );
            }
            else
            {
                if (port.Length != 0)
                    port = ":" + port;

                for (int i = 0; i < access.Length; ++i)
                {
                    uriStr = GetPermissionAccessElementString(access[i], scheme, host, port);
                    SecurityElement uri = new SecurityElement( "URI" );
                    uri.AddAttribute( "uri", uriStr );
                    connectAccess.AddChild( uri );
                }
            }

            root.AddChild( connectAccess );
            return root;
        }
Exemplo n.º 42
0
        internal SecurityElement InternalToXml()
        {
            SecurityElement elTrunk = new SecurityElement("PermissionSet");
            elTrunk.AddAttribute( "class", this.GetType().FullName);
            elTrunk.AddAttribute( "version", "1" );
        
            if (m_Unrestricted)
            {
                elTrunk.AddAttribute(s_str_Unrestricted, "true" );
            }
    
            if (this.m_permSet != null)
            {
                int maxIndex = this.m_permSet.GetMaxUsedIndex();

                for (int i = m_permSet.GetStartingIndex(); i <= maxIndex; ++i)
                {
                    Object obj = this.m_permSet.GetItem( i );
                    if (obj != null)
                    {
                        if (obj is IPermission)
                        {
                            if (!m_Unrestricted)
                                elTrunk.AddChild( ((IPermission)obj).ToXml() );
                        }
                        else
                        {
                            elTrunk.AddChild( (SecurityElement)obj );
                        }
                    }

                }
            }
            return elTrunk ;
        }
Exemplo n.º 43
0
        //
        protected override void CreateXml( SecurityElement element, PolicyLevel level )
        {
            DictionaryEntry[] rules = GetConnectAccessRules();
            if (rules == null)
                return;

            SecurityElement rulesElement = new SecurityElement("connectAccessRules");

            foreach (DictionaryEntry rule in rules)
            {
                SecurityElement codeOriginElement = new SecurityElement("codeOrigin");
                codeOriginElement.AddAttribute("scheme", (string) rule.Key);
                foreach (CodeConnectAccess access in (CodeConnectAccess[])rule.Value)
                {
                    SecurityElement accessElem = new SecurityElement("connectAccess");
                    accessElem.AddAttribute("scheme", access.Scheme);
                    accessElem.AddAttribute("port", access.StrPort);
                    codeOriginElement.AddChild(accessElem);
                }
                rulesElement.AddChild(codeOriginElement);
            }
            element.AddChild(rulesElement);
        }
Exemplo n.º 44
0
 static internal void SafeChildAdd( SecurityElement parent, ISecurityElementFactory child, bool copy )
 {
     if (child == parent)
         return;
     if (child.GetTag().Equals( "IPermission" ) || child.GetTag().Equals( "Permission" ))
     {
         parent.AddChild( child );
     }
     else if (parent.Tag.Equals( child.GetTag() ))
     {
         Contract.Assert( child is SecurityElement, "SecurityElement expected" );
         SecurityElement elChild = (SecurityElement)child;
         Contract.Assert( elChild.InternalChildren != null,
             "Non-permission elements should have children" );
             
         for (int i = 0; i < elChild.InternalChildren.Count; ++i)
         {
             ISecurityElementFactory current = (ISecurityElementFactory)elChild.InternalChildren[i];
             Contract.Assert( !current.GetTag().Equals( parent.Tag ),
                 "Illegal to insert a like-typed element" );
             parent.AddChildNoDuplicates( current );
         }
     }
     else
     {
         parent.AddChild( (ISecurityElementFactory)(copy ? child.Copy() : child) );
     }
 }
		public void FromXml_NoVersion ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			foreach (SecurityElement child in se.Children)
				w.AddChild (child);

			at.FromXml (w);
		}
Exemplo n.º 46
0
		public virtual SecurityElement ToXml ()
		{
			SecurityElement se = new SecurityElement (tagName);
			se.AddAttribute ("class", GetType ().FullName);
			se.AddAttribute ("version", version.ToString ());
			if (state == PermissionState.Unrestricted)
				se.AddAttribute ("Unrestricted", "true");

			// required for permissions that do not implement IUnrestrictedPermission
			foreach (IPermission p in list) {
				se.AddChild (p.ToXml ());
			}
			return se;
		}