// snippet moved from FileIOPermission (nickd) to be reused in all derived classes internal static SecurityElement Element (Type type, int version) { SecurityElement se = new SecurityElement ("IPermission"); se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\'')); se.AddAttribute ("version", version.ToString ()); return se; }
} //Union() public override SecurityElement ToXml() { SecurityElement s = new SecurityElement("IPermission"); s.AddAttribute("class","myperm, myperm, Version=1.0.1.0, Culture=neutral, PublicKeyToken=0e8dcc8628396732"); s.AddAttribute("version", "1"); s.AddAttribute("Unrestricted", "true"); return s; } //ToXml()
public void FromXmlWrongVersion() { PrincipalPermission p = new PrincipalPermission(PermissionState.None); SecurityElement se = p.ToXml(); // can't modify - so we create our own SecurityElement se2 = new SecurityElement(se.Tag, se.Text); se2.AddAttribute("class", se.Attribute("class")); se2.AddAttribute("version", "2"); Assert.Throws<ArgumentException>(() => p.FromXml(se2)); }
public SecurityElement ToXml( PolicyLevel level ) { SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), this.GetType().FullName ); root.AddAttribute( "version", "1" ); return root; }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence"); SecurityElement child; element.AddAttribute("version", "1"); if(request != null) { child = new SecurityElement("Request"); child.AddChild(request.ToXml()); element.AddChild(child); } if(optional != null) { child = new SecurityElement("Optional"); child.AddChild(optional.ToXml()); element.AddChild(child); } if(denied != null) { child = new SecurityElement("Denied"); child.AddChild(denied.ToXml()); element.AddChild(child); } return element.ToString(); }
internal SecurityElement ToXml() { SecurityElement root = new SecurityElement("Identity"); if (Authenticated) { root.AddAttribute("Authenticated", "true"); } if (ID != null) { root.AddAttribute("ID", SecurityElement.Escape(ID)); } if (Role != null) { root.AddAttribute("Role", SecurityElement.Escape(Role)); } return root; }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.Publisher"); se.AddAttribute ("version", "1"); SecurityElement cert = new SecurityElement ("X509v3Certificate"); string data = m_cert.GetRawCertDataString (); if (data != null) cert.Text = data; se.AddChild (cert); return se.ToString (); }
internal SecurityElement ToXml() { SecurityElement root = new SecurityElement( "System.Security.Policy.ApplicationDirectory" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.ApplicationDirectory" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_appDirectory != null) root.AddChild( new SecurityElement( "Directory", m_appDirectory.ToString() ) ); return root; }
public void FromXml() { PrincipalPermission p = new PrincipalPermission(PermissionState.None); SecurityElement se = p.ToXml(); Assert.NotNull(se); PrincipalPermission p2 = (PrincipalPermission)p.Copy(); p2.FromXml(se); Assert.Equal(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.True(p2.IsUnrestricted()); }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence"); se.AddAttribute ("version", "1"); if (requested != null) { SecurityElement requestElement = new SecurityElement ("Request"); requestElement.AddChild (requested.ToXml ()); se.AddChild (requestElement); } if (optional != null) { SecurityElement optionalElement = new SecurityElement ("Optional"); optionalElement.AddChild (optional.ToXml ()); se.AddChild (optionalElement); } if (denied != null) { SecurityElement deniedElement = new SecurityElement ("Denied"); deniedElement.AddChild (denied.ToXml ()); se.AddChild (deniedElement); } return se.ToString (); }
public void OnStartElement(string name, MiniParser.IAttrList attrs) { SecurityElement newel = new SecurityElement(name); if (root == null) { root = newel; current = newel; } else { SecurityElement parent = (SecurityElement)stack.Peek(); parent.AddChild(newel); } stack.Push(newel); current = newel; // attributes int n = attrs.Length; for (int i = 0; i < n; i++) { current.AddAttribute(attrs.GetName(i), SecurityElement.Escape(attrs.GetValue(i))); } }
/// <summary>Creates an XML encoding of the permission and its current state.</summary> /// <returns>An XML encoding of the permission, including any state information.</returns> // Token: 0x06002685 RID: 9861 RVA: 0x0008BA38 File Offset: 0x00089C38 public override SecurityElement ToXml() { SecurityElement securityElement = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.ZoneIdentityPermission"); if (this.SecurityZone != SecurityZone.NoZone) { securityElement.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), this.SecurityZone)); } else { int num = 0; for (uint num2 = 1U; num2 < 31U; num2 <<= 1) { if ((this.m_zones & num2) != 0U) { SecurityElement securityElement2 = new SecurityElement("Zone"); securityElement2.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), (SecurityZone)num)); securityElement.AddChild(securityElement2); } num++; } } return(securityElement); }
[Test] // bug #333699 (ugh, mostly a dup) public void TestToString() { SecurityElement values = new SecurityElement("values"); SecurityElement infoValue = new SecurityElement("value"); infoValue.AddAttribute("name", "string"); infoValue.Text = SecurityElement.Escape("<'Suds' & \"Soda\">!"); values.AddChild(infoValue); Assert.AreEqual("<value name=\"string\"><'Suds' & "Soda">!</value>" + Environment.NewLine, infoValue.ToString(), "#1"); Assert.AreEqual("<'Suds' & \"Soda\">!", infoValue.Text, "#2"); Assert.IsNull(values.Text, "#3"); #if NET_2_0 Assert.AreEqual(String.Format("<values>{0}<value name=\"string\"><'Suds' & "Soda">!</value>{0}</values>{0}", Environment.NewLine), values.ToString(), "#4"); #else Assert.AreEqual(String.Format("<values>{0} <value name=\"string\"><'Suds' & "Soda">!</value>{0}</values>{0}", Environment.NewLine), values.ToString(), "#4"); #endif #if NET_2_0 SecurityElement sec = SecurityElement.FromString(values.ToString()); Assert.AreEqual(1, sec.Children.Count, "#5"); Assert.AreEqual("<'Suds' & \"Soda\">!", ((SecurityElement)sec.Children [0]).Text, "#6"); #endif }
/// <summary>创建权限及其当前状态的 XML 编码。</summary> /// <returns>权限的 XML 编码,包括任何状态信息。</returns> public override SecurityElement ToXml() { SecurityElement permissionElement = CodeAccessPermission.CreatePermissionElement((IPermission)this, "System.Security.Permissions.FileIOPermission"); if (!this.IsUnrestricted()) { if (this.m_read != null && !this.m_read.IsEmpty()) { permissionElement.AddAttribute("Read", SecurityElement.Escape(this.m_read.ToString())); } if (this.m_write != null && !this.m_write.IsEmpty()) { permissionElement.AddAttribute("Write", SecurityElement.Escape(this.m_write.ToString())); } if (this.m_append != null && !this.m_append.IsEmpty()) { permissionElement.AddAttribute("Append", SecurityElement.Escape(this.m_append.ToString())); } if (this.m_pathDiscovery != null && !this.m_pathDiscovery.IsEmpty()) { permissionElement.AddAttribute("PathDiscovery", SecurityElement.Escape(this.m_pathDiscovery.ToString())); } if (this.m_viewAcl != null && !this.m_viewAcl.IsEmpty()) { permissionElement.AddAttribute("ViewAcl", SecurityElement.Escape(this.m_viewAcl.ToString())); } if (this.m_changeAcl != null && !this.m_changeAcl.IsEmpty()) { permissionElement.AddAttribute("ChangeAcl", SecurityElement.Escape(this.m_changeAcl.ToString())); } } else { permissionElement.AddAttribute("Unrestricted", "true"); } return(permissionElement); }
///<summary> /// Return an XML instantiation of this permisson. ///</summary> public override SecurityElement ToXml() { SecurityElement securityElement = new SecurityElement("IPermission"); securityElement.AddAttribute("class", this.GetType().AssemblyQualifiedName); securityElement.AddAttribute("version", "1"); if (IsUnrestricted()) { securityElement.AddAttribute("Unrestricted", Boolean.TrueString); } else { securityElement.AddAttribute("Audio", _mediaPermissionAudio.ToString()); securityElement.AddAttribute("Video", _mediaPermissionVideo.ToString()); securityElement.AddAttribute("Image", _mediaPermissionImage.ToString()); } return(securityElement); }
// Convert this permissions object into an XML value. public override SecurityElement ToXml() { SecurityElement element; element = new SecurityElement("IPermission"); element.AddAttribute ("class", SecurityElement.Escape(typeof(RegistryPermission). AssemblyQualifiedName)); element.AddAttribute("version", "1"); if (state == PermissionState.Unrestricted) { element.AddAttribute("Unrestricted", "true"); } else { // Always use ";" as the separator so that we can // guarantee a fixed external form, regardless of // whatever PathSeparator is set to. if (readList != null) { element.AddAttribute ("Read", SecurityElement.Escape (String.Join(";", readList))); } if (writeList != null) { element.AddAttribute ("Write", SecurityElement.Escape (String.Join(";", writeList))); } if (createList != null) { element.AddAttribute ("Create", SecurityElement.Escape (String.Join(";", createList))); } } return(element); }
public override SecurityElement ToXml () { SecurityElement securityElement = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.KeyContainerPermission"); if (!IsUnrestricted()) { securityElement.AddAttribute("Flags", m_flags.ToString()); if (AccessEntries.Count > 0) { SecurityElement al = new SecurityElement("AccessList"); foreach (KeyContainerPermissionAccessEntry accessEntry in AccessEntries) { SecurityElement entryElem = new SecurityElement("AccessEntry"); entryElem.AddAttribute("KeyStore", accessEntry.KeyStore); entryElem.AddAttribute("ProviderName", accessEntry.ProviderName); entryElem.AddAttribute("ProviderType", accessEntry.ProviderType.ToString(null, null)); entryElem.AddAttribute("KeyContainerName", accessEntry.KeyContainerName); entryElem.AddAttribute("KeySpec", accessEntry.KeySpec.ToString(null, null)); entryElem.AddAttribute("Flags", accessEntry.Flags.ToString()); al.AddChild(entryElem); } securityElement.AddChild(al); } } else securityElement.AddAttribute("Unrestricted", "true"); return securityElement; }
internal SecurityElement ToXml() { SecurityElement root = new SecurityElement( "StrongName" ); root.AddAttribute( "version", "1" ); if (m_publicKeyBlob != null) root.AddAttribute( "Key", System.Security.Util.Hex.EncodeHexString( m_publicKeyBlob.PublicKey ) ); if (m_name != null) root.AddAttribute( "Name", m_name ); if (m_version != null) root.AddAttribute( "Version", m_version.ToString() ); return root; }
// Token: 0x06002986 RID: 10630 RVA: 0x00098F1C File Offset: 0x0009711C internal SecurityElement CreateWebPermission(string host, string scheme, string port, string assemblyOverride) { if (scheme == null) { scheme = string.Empty; } if (host == null || host.Length == 0) { return(null); } host = host.ToLower(CultureInfo.InvariantCulture); scheme = scheme.ToLower(CultureInfo.InvariantCulture); int intPort = -1; if (port != null && port.Length != 0) { intPort = int.Parse(port, CultureInfo.InvariantCulture); } else { port = string.Empty; } CodeConnectAccess[] array = this.FindAccessRulesForScheme(scheme); if (array == null || array.Length == 0) { return(null); } SecurityElement securityElement = new SecurityElement("IPermission"); string str = (assemblyOverride == null) ? "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" : assemblyOverride; securityElement.AddAttribute("class", "System.Net.WebPermission, " + str); securityElement.AddAttribute("version", "1"); SecurityElement securityElement2 = new SecurityElement("ConnectAccess"); host = this.EscapeStringForRegex(host); scheme = this.EscapeStringForRegex(scheme); string text = this.TryPermissionAsOneString(array, scheme, host, intPort); if (text != null) { SecurityElement securityElement3 = new SecurityElement("URI"); securityElement3.AddAttribute("uri", text); securityElement2.AddChild(securityElement3); } else { if (port.Length != 0) { port = ":" + port; } for (int i = 0; i < array.Length; i++) { text = this.GetPermissionAccessElementString(array[i], scheme, host, port); SecurityElement securityElement4 = new SecurityElement("URI"); securityElement4.AddAttribute("uri", text); securityElement2.AddChild(securityElement4); } } securityElement.AddChild(securityElement2); return(securityElement); }
private static SecurityElement ObjectToXml (string tag, Object obj) { BCLDebug.Assert(obj != null, "You need to pass in an object"); ISecurityEncodable encodableObj = obj as ISecurityEncodable; SecurityElement elObject; if (encodableObj != null) { elObject = encodableObj.ToXml(); if (!elObject.Tag.Equals(tag)) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); } MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, obj); byte[] array = stream.ToArray(); elObject = new SecurityElement(tag); elObject.AddAttribute("Data", Hex.EncodeHexString(array)); return elObject; }
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); }
public override string ToString () { // MS "by design" behaviour (see FDBK14362) ThrowOnInvalid (Directory); SecurityElement element = new SecurityElement ("System.Security.Policy.ApplicationDirectory"); element.AddAttribute ("version", "1"); element.AddChild (new SecurityElement ("Directory", directory)); return element.ToString (); }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.ToXml"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> 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 (!IsUnrestricted()) { String tempStr = null; if (m_connectList != null && m_connectList.Count > 0) { SecurityElement connectElement = new SecurityElement("ConnectAccess"); //NOTE All strings going to XML will become URI PATTERNS i.e. escaped to Regex foreach (object Uri in m_connectList) { String uriString = Uri as String; if (uriString != null) { tempStr = Regex.Escape(uriString); } else { tempStr = Uri.ToString(); } SecurityElement uripattern = new SecurityElement("URI"); uripattern.AddAttribute("uri", tempStr); connectElement.AddChild(uripattern); } securityElement.AddChild(connectElement); } if (m_acceptList != null && m_acceptList.Count > 0) { SecurityElement acceptElement = new SecurityElement("AcceptAccess"); //NOTE All strings going to XML will become URI PATTERNS i.e. escaped to Regex foreach (object Uri in m_acceptList) { String uriString = Uri as String; if (uriString != null) { tempStr = Regex.Escape(uriString); } else { tempStr = Uri.ToString(); } SecurityElement uripattern = new SecurityElement("URI"); uripattern.AddAttribute("uri", tempStr); acceptElement.AddChild(uripattern); } securityElement.AddChild(acceptElement); } } else { securityElement.AddAttribute("Unrestricted", "true"); } return(securityElement); }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element; element = new SecurityElement("IMembershipCondition"); element.AddAttribute ("class", SecurityElement.Escape(typeof(SiteMembershipCondition). AssemblyQualifiedName)); element.AddAttribute("version", "1"); element.AddAttribute("Site", SecurityElement.Escape(site)); return element; }
public SecurityElement ToXml( PolicyLevel level ) { if (m_site == null && m_element != null) ParseSite(); SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.SiteMembershipCondition" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.SiteMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_site != null) root.AddAttribute( "Site", m_site.ToString() ); return root; }
[System.Security.SecuritySafeCritical] // auto-generated public SecurityElement ToXml() { // Make sure we have loaded everything and that all the // permission sets are loaded. CheckLoaded(); LoadAllPermissionSets(); IEnumerator enumerator; SecurityElement e = new SecurityElement("PolicyLevel"); e.AddAttribute("version", "1"); Hashtable classes = new Hashtable(); lock (this) { SecurityElement elPermSets = new SecurityElement("NamedPermissionSets"); enumerator = m_namedPermissionSets.GetEnumerator(); while (enumerator.MoveNext()) { elPermSets.AddChild(NormalizeClassDeep(((NamedPermissionSet)enumerator.Current).ToXml(), classes)); } SecurityElement elCodeGroup = NormalizeClassDeep(m_rootCodeGroup.ToXml(this), classes); SecurityElement elFullTrust = new SecurityElement("FullTrustAssemblies"); enumerator = m_fullTrustAssemblies.GetEnumerator(); while (enumerator.MoveNext()) { elFullTrust.AddChild(NormalizeClassDeep(((StrongNameMembershipCondition)enumerator.Current).ToXml(), classes)); } SecurityElement elClasses = new SecurityElement("SecurityClasses"); IDictionaryEnumerator dicEnumerator = classes.GetEnumerator(); while (dicEnumerator.MoveNext()) { SecurityElement elClass = new SecurityElement("SecurityClass"); elClass.AddAttribute("Name", (string)dicEnumerator.Value); elClass.AddAttribute("Description", (string)dicEnumerator.Key); elClasses.AddChild(elClass); } e.AddChild(elClasses); e.AddChild(elPermSets); e.AddChild(elCodeGroup); e.AddChild(elFullTrust); } return e; }
private static SecurityElement CreateCodeGroupElement(string codeGroupType, string permissionSetName, SecurityElement mshipElement) { SecurityElement root = new SecurityElement("CodeGroup"); root.AddAttribute("class", "System.Security." + codeGroupType + ", mscorlib, Version={VERSION}, Culture=neutral, PublicKeyToken=" + AssemblyRef.EcmaPublicKeyToken + ""); root.AddAttribute("version", "1"); root.AddAttribute("PermissionSetName", permissionSetName); root.AddChild(mshipElement); return root; }
protected override void CreateXml (SecurityElement element, PolicyLevel level) { element.AddAttribute ("Access", m_access.ToString ()); }
public override SecurityElement ToXml () { SecurityElement se = PermissionHelper.Element (this.GetType (), version); if (IsUnrestricted ()) { se.AddAttribute ("Unrestricted", "true"); } else { foreach (ResourcePermissionBaseEntry entry in _list) { SecurityElement container = se; string access = null; if (PermissionAccessType != null) access = Enum.Format (PermissionAccessType, entry.PermissionAccess, "g"); for (int i=0; i < _tags.Length; i++) { SecurityElement child = new SecurityElement (_tags [i]); child.AddAttribute ("name", entry.PermissionAccessPath [i]); if (access != null) child.AddAttribute ("access", access); container.AddChild (child); child = container; } } } return se; }
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); }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.Zone"); se.AddAttribute ("version", "1"); se.AddChild (new SecurityElement ("Zone", zone.ToString ())); return se.ToString (); }
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); }
// Set a value under this registry key. public void SetValue(String name, Object value) { lock (this) { // Find or create a tag for this name. SecurityElement e = FindValue(name); if (e == null) { e = new SecurityElement("value"); e.AddAttribute("name", SecurityElement.Escape(name)); values.AddChild(e); } // Modify the value associated with the tag. e.Children = null; if (value is String) { e.SetAttribute("type", "string"); e.Text = SecurityElement.Escape((String)value); } else if (value is int) { e.SetAttribute("type", "int"); e.Text = ((int)value).ToString(); } else if (value is uint) { e.SetAttribute("type", "uint"); e.Text = ((uint)value).ToString(); } else if (value is long) { e.SetAttribute("type", "long"); e.Text = ((long)value).ToString(); } else if (value is ulong) { e.SetAttribute("type", "ulong"); e.Text = ((ulong)value).ToString(); } else if (value is byte[]) { e.SetAttribute("type", "binary"); e.Text = Convert.ToBase64String((byte[])value); } else if (value is String[]) { e.SetAttribute("type", "strings"); String[] list = (String[])value; SecurityElement child; for (int i = 0; i < list.Length; i++) { child = new SecurityElement("string"); String str = list[i]; if (str == null) { str = String.Empty; } child.Text = SecurityElement.Escape(str); e.AddChild(child); } } else { // Treat everything else as a string. e.SetAttribute("type", "string"); e.Text = SecurityElement.Escape(value.ToString()); } // The value has been modified. modified = true; } }
private void ParsePolicy() { // There is a potential deadlock situation here // since the PolicyStatement.FromXml method calls // into PolicyLevel and we are holding this CodeGroup's lock. // We solve this by releasing the lock for the duration of // the FromXml call, but this leads us into some race conditions // with other threads trying to alter the state of this object. // The trickiest of these is the case from FromXml gets called on // this object, in which case we will loop and try the decode again. while (true) { PolicyStatement policy = new PolicyStatement(); bool needToParse = false; SecurityElement elPolicy = new SecurityElement("PolicyStatement"); elPolicy.AddAttribute("version", "1"); SecurityElement localRef = m_element; lock (this) { // We create an xml representation of a policy statement from the // xml for a code group. We do this to hide the policy statement from // users in the config file. if (m_element != null) { String permSetName = m_element.Attribute("PermissionSetName"); if (permSetName != null) { elPolicy.AddAttribute("PermissionSetName", permSetName); needToParse = true; } else { SecurityElement elPermSet = m_element.SearchForChildByTag("PermissionSet"); if (elPermSet != null) { elPolicy.AddChild(elPermSet); needToParse = true; } else { elPolicy.AddChild(new PermissionSet(false).ToXml()); needToParse = true; } } String attributes = m_element.Attribute("Attributes"); if (attributes != null) { elPolicy.AddAttribute("Attributes", attributes); needToParse = true; } } } if (needToParse) { policy.FromXml(elPolicy, m_parentLevel); } else { policy.PermissionSet = null; } lock (this) { if (localRef == m_element && m_policy == null) { m_policy = policy; break; } else if (m_policy != null) { break; } } } if (m_policy != null && m_children != null && m_membershipCondition != null) { //m_element = null; //m_parentLevel = null; } }
private Dictionary <string, string> SplitLang(string content) { m_parser.LoadXml(content); Dictionary <string, bool> used_standalone_attrs = GetUsedStandaloneAttr(); Dictionary <string, string> base_kv = GetBaseKV(); /*--------------- Result ----------------*/ Dictionary <string, string> langs = new Dictionary <string, string>(); Dictionary <string, SecurityElement> out_items = new Dictionary <string, SecurityElement>(); SecurityElement e_root = m_parser.ToXml(); SecurityElement e_type = e_root.SearchForChildByTag(TAG_TYPE); SecurityElement e_data = e_root.SearchForChildByTag(TAG_DATA); /*--------------- Type Line ---------------*/ SecurityElement e_type_item = e_type.SearchForChildByTag(TAG_ITEM); var type_item_itr = e_type_item.Attributes.GetEnumerator(); while (type_item_itr.MoveNext()) { string attr = type_item_itr.Key.ToString(); if (IsExistStandaloneAttr(used_standalone_attrs, attr)) { continue; } SecurityElement table = new SecurityElement(TAG_TABLE); SecurityElement type = new SecurityElement(TAG_TYPE); SecurityElement item = new SecurityElement(TAG_ITEM); SecurityElement data = new SecurityElement(TAG_DATA); foreach (KeyValuePair <string, bool> except_attr in used_standalone_attrs) { if (except_attr.Value) { string k = except_attr.Key; string v = e_type_item.Attributes[k].ToString(); item.AddAttribute(k, v); } } item.AddAttribute(TAG_TEXT, e_type_item.Attributes[attr].ToString()); type.AddChild(item); table.AddChild(type); table.AddChild(data); out_items.Add(attr, table); out_items.Add(attr + UPDATE_SUFFIX, SecurityElement.FromString(table.ToString())); } /*------------- Data Set ---------------*/ int curIndex = 0; int languageVersion = 0; foreach (SecurityElement e_data_item in e_data.Children) { ++curIndex; var curVersion = 0; int.TryParse(e_data_item.Attributes[TAG_VERSION].ToString(), out curVersion); if (curIndex == 1) { languageVersion = curVersion; Console.WriteLine("Language Version : {0}", languageVersion); continue; } var data_item_itr = e_data_item.Attributes.GetEnumerator(); while (data_item_itr.MoveNext()) { string attr = data_item_itr.Key.ToString(); if (IsExistStandaloneAttr(used_standalone_attrs, attr)) { continue; } SecurityElement table = (curVersion <= languageVersion ? out_items[attr] : out_items[attr + UPDATE_SUFFIX]); SecurityElement data = table.SearchForChildByTag(TAG_DATA); SecurityElement item = new SecurityElement(TAG_ITEM); foreach (KeyValuePair <string, bool> except_attr in used_standalone_attrs) { if (except_attr.Value) { string k = except_attr.Key; string v = e_data_item.Attributes[k].ToString(); item.AddAttribute(k, v); } } string key = e_data_item.Attributes[TAG_ID].ToString(); string text = e_data_item.Attributes[attr].ToString(); text = AddOrderNum4PlaceHolder(base_kv[key], text); item.AddAttribute(TAG_TEXT, text); data.AddChild(item); } } /*---------------- To Langs ----------------*/ foreach (var d in out_items) { string text = FormatXml(d.Value); text = AddHeader(text); langs.Add(d.Key, text); } return(langs); }
private void ParsePolicy() { System.Security.Policy.PolicyStatement statement; Label_0000: statement = new System.Security.Policy.PolicyStatement(); bool flag = false; SecurityElement et = new SecurityElement("PolicyStatement"); et.AddAttribute("version", "1"); SecurityElement element = this.m_element; lock (this) { if (this.m_element != null) { string str = this.m_element.Attribute("PermissionSetName"); if (str != null) { et.AddAttribute("PermissionSetName", str); flag = true; } else { SecurityElement child = this.m_element.SearchForChildByTag("PermissionSet"); if (child != null) { et.AddChild(child); flag = true; } else { et.AddChild(new PermissionSet(false).ToXml()); flag = true; } } string str2 = this.m_element.Attribute("Attributes"); if (str2 != null) { et.AddAttribute("Attributes", str2); flag = true; } } } if (flag) { statement.FromXml(et, this.m_parentLevel); } else { statement.PermissionSet = null; } lock (this) { if ((element == this.m_element) && (this.m_policy == null)) { this.m_policy = statement; } else if (this.m_policy == null) { goto Label_0000; } } if ((this.m_policy != null) && (this.m_children != null)) { IMembershipCondition membershipCondition = this.m_membershipCondition; } }
[System.Security.SecurityCritical] // auto-generated internal SecurityElement ToXml(PolicyLevel level, String policyClassName) { if (m_membershipCondition == null && m_element != null) { ParseMembershipCondition(); } if (m_children == null) { ParseChildren(); } if (m_policy == null && m_element != null) { ParsePolicy(); } SecurityElement e = new SecurityElement("CodeGroup"); System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType(), policyClassName); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert(this.GetType().FullName.Equals(policyClassName), "Incorrect class name passed in! Was: " + policyClassName + " Should be " + this.GetType().FullName); e.AddAttribute("version", "1"); e.AddChild(m_membershipCondition.ToXml(level)); // Grab the inerts of the policy statement's xml and just stick it // into the code group xml directly. We do this to hide the policy statement from // users in the config file. if (m_policy != null) { PermissionSet permSet = m_policy.GetPermissionSetNoCopy(); NamedPermissionSet namedPermSet = permSet as NamedPermissionSet; if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null) { e.AddAttribute("PermissionSetName", namedPermSet.Name); } else { if (!permSet.IsEmpty()) { e.AddChild(permSet.ToXml()); } } if (m_policy.Attributes != PolicyStatementAttribute.Nothing) { e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes)); } } if (m_children.Count > 0) { lock (this) { IEnumerator enumerator = m_children.GetEnumerator(); while (enumerator.MoveNext()) { e.AddChild(((CodeGroup)enumerator.Current).ToXml(level)); } } } if (m_name != null) { e.AddAttribute("Name", SecurityElement.Escape(m_name)); } if (m_description != null) { e.AddAttribute("Description", SecurityElement.Escape(m_description)); } CreateXml(e, level); return(e); }
private static SecurityElement EventLogPermission (string name, string access) { SecurityElement se = new SecurityElement ("IPermission"); se.AddAttribute ("class", EventLogPermissionClass); se.AddAttribute ("version", "1"); SecurityElement child = new SecurityElement ("Machine"); child.AddAttribute ("name", name); child.AddAttribute ("access", access); se.AddChild (child); return se; }
public SecurityElement ToXml () { SecurityElement elRoot = new SecurityElement("ApplicationTrust"); elRoot.AddAttribute("version", "1"); #if FEATURE_CLICKONCE if (m_appId != null) { elRoot.AddAttribute("FullName", SecurityElement.Escape(m_appId.FullName)); } if (m_appTrustedToRun) { elRoot.AddAttribute("TrustedToRun", "true"); } if (m_persist) { elRoot.AddAttribute("Persist", "true"); } #endif // FEATURE_CLICKONCE if (m_psDefaultGrant != null) { SecurityElement elDefaultGrant = new SecurityElement("DefaultGrant"); elDefaultGrant.AddChild(m_psDefaultGrant.ToXml()); elRoot.AddChild(elDefaultGrant); } if (m_fullTrustAssemblies.Count > 0) { SecurityElement elFullTrustAssemblies = new SecurityElement("FullTrustAssemblies"); foreach (StrongName fullTrustAssembly in m_fullTrustAssemblies) { elFullTrustAssemblies.AddChild(fullTrustAssembly.ToXml()); } elRoot.AddChild(elFullTrustAssemblies); } #if FEATURE_CLICKONCE if (ExtraInfo != null) { elRoot.AddChild(ObjectToXml("ExtraInfo", ExtraInfo)); } #endif // FEATURE_CLICKONCE return elRoot; }
/// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.ToXml"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override SecurityElement ToXml() { SecurityElement root = new SecurityElement("IPermission"); Type type = this.GetType(); root.AddAttribute("class", type.FullName + ", " + type.Module.Assembly.FullName.Replace('\"', '\'')); root.AddAttribute("version", "1"); if (this.isUnrestricted) { root.AddAttribute("Unrestricted", "true"); return(root); } IEnumerator enumerator = this.PermissionEntries.GetEnumerator(); while (enumerator.MoveNext()) { SecurityElement currentElement = null; MessageQueuePermissionEntry entry = (MessageQueuePermissionEntry)enumerator.Current; if (entry.Path != null) { currentElement = new SecurityElement("Path"); currentElement.AddAttribute("value", entry.Path); } else { currentElement = new SecurityElement("Criteria"); if (entry.MachineName != null) { currentElement.AddAttribute("machine", entry.MachineName); } if (entry.Category != null) { currentElement.AddAttribute("category", entry.Category); } if (entry.Label != null) { currentElement.AddAttribute("label", entry.Label); } } int currentAccess = (int)entry.PermissionAccess; if (currentAccess != 0) { StringBuilder accessStringBuilder = null; int[] enumValues = (int[])Enum.GetValues(typeof(MessageQueuePermissionAccess)); Array.Sort(enumValues); for (int index = (enumValues.Length - 1); index >= 0; --index) { if (enumValues[index] != 0 && ((currentAccess & enumValues[index]) == enumValues[index])) { if (accessStringBuilder == null) { accessStringBuilder = new StringBuilder(); } else { accessStringBuilder.Append("|"); } accessStringBuilder.Append(Enum.GetName(typeof(MessageQueuePermissionAccess), enumValues[index])); currentAccess = currentAccess & (enumValues[index] ^ enumValues[index]); } } currentElement.AddAttribute("access", accessStringBuilder.ToString()); } root.AddChild(currentElement); } return(root); }
internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( "System.Security.Policy.Zone" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.Zone" ), "Class name changed!" ); elem.AddAttribute( "version", "1" ); if (SecurityZone != SecurityZone.NoZone) elem.AddChild( new SecurityElement( "Zone", s_names[(int)SecurityZone] ) ); else elem.AddChild( new SecurityElement( "Zone", s_names[s_names.Length-1] ) ); return elem; }
internal SecurityElement CreateWebPermission(string host, string scheme, string port, string assemblyOverride) { 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"); // If we were given a specific assembly to find the WebPermission type in use that, otherwise use // the current version of System.dll. This enables us to build WebPermissions targeting older // runtimes for ClickOnce trust decisions that need to target the older runtime. string permissionAssembly = assemblyOverride == null ? "System, Version=" + ThisAssembly.Version + ", Culture=neutral, PublicKeyToken=" + AssemblyRef.EcmaPublicKeyToken : assemblyOverride; root.AddAttribute("class", "System.Net.WebPermission, " + permissionAssembly); 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); }
/// <summary> /// Gets the medium trust permission set. /// </summary> /// <param name="pathToConfigFile">The path to the config file.</param> /// <returns></returns> public static NamedPermissionSet GetMediumTrustPermissionSet(string pathToConfigFile) { // Load the config file trusting that it exists. var xDocument = XDocument.Load(pathToConfigFile); // Get all of the SecurityClass elements which we'll use later to look // up a type strongname given a key var securityClasses = xDocument.Descendants("SecurityClass").Select( x => new { Name = (string)x.Attribute("Name"), Type = (string)x.Attribute("Description") }); // Get the first PermissionSet element where the Name attribute is "ASP.Net" var namedSet = xDocument.Descendants("PermissionSet").Where(x => (string)x.Attribute("Name") == "ASP.Net").FirstOrDefault(); // If we didn't find it, that's a fail Assert.NotNull(namedSet); // Create a new SecurityElement class to mimic what is represented in Xml var secElement = new SecurityElement("PermissionSet"); secElement.AddAttribute("Name", "ASP.Net"); secElement.AddAttribute("class", "NamedPermissionSet"); secElement.AddAttribute("version", "1"); // For each child of the ASP.Net PermissionSet, create a child SecurityElement representing the IPermission foreach (var xElement in namedSet.Elements()) { var child = new SecurityElement("IPermission"); // Check if we need to do any string replacement on the Xml values first ProcessIPermissionAttributeValue(xElement); // Get the attributes of the IPermission from Xml and put them onto our child SecurityElement foreach (var xAttribute in xElement.Attributes()) { var attribName = xAttribute.Name.LocalName; var value = xAttribute.Value; try { if (attribName == "class") { // This is the type key. Get the full type name from the SecurityClasses list we grabbed earlier value = securityClasses.Where(x => x.Name == value).Select(x => x.Type).Single(); } } catch (Exception ex) { throw new XmlException("Could not find the fully-qualified type name for " + value, ex); } child.AddAttribute(attribName, value); } secElement.AddChild(child); } // Create a new NamedPermissionSet, pass in the SecurityElement class representing the Xml var permissionSet = new NamedPermissionSet("ASP.Net"); permissionSet.FromXml(secElement); return(permissionSet); }
protected override void CreateXml(SecurityElement element, PolicyLevel level) { element.AddAttribute("Access", XMLUtil.BitFieldEnumToString(typeof(FileIOPermissionAccess), m_access)); }
public void AddAttribute() { SecurityElement elem = CreateElement(); elem.AddAttribute("valid", "valid\'"); }
static void AddAttribute(SecurityElement se, string attr, string value) { value = value.Replace("&", "&"); se.AddAttribute(attr, value); }
/// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.ToXml1"]/*' /> public SecurityElement ToXml(PolicyLevel level) { if (m_membershipCondition == null && m_element != null) { ParseMembershipCondition(); } if (m_children == null) { ParseChildren(); } if (m_policy == null && m_element != null) { ParsePolicy(); } SecurityElement e = new SecurityElement("CodeGroup"); System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType()); e.AddAttribute("version", "1"); e.AddChild(m_membershipCondition.ToXml(level)); // Grab the inerts of the policy statement's xml and just stick it // into the code group xml directly. We do this to hide the policy statement from // users in the config file. if (m_policy != null) { PermissionSet permSet = m_policy.GetPermissionSetNoCopy(); NamedPermissionSet namedPermSet = permSet as NamedPermissionSet; if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null) { e.AddAttribute("PermissionSetName", namedPermSet.Name); } else { if (!permSet.IsEmpty()) { e.AddChild(permSet.ToXml()); } } if (m_policy.Attributes != PolicyStatementAttribute.Nothing) { e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes)); } } if (m_children.Count > 0) { lock (this) { IEnumerator enumerator = m_children.GetEnumerator(); while (enumerator.MoveNext()) { e.AddChild(((CodeGroup)enumerator.Current).ToXml(level)); } } } if (m_name != null) { e.AddAttribute("Name", SecurityElement.Escape(m_name)); } if (m_description != null) { e.AddAttribute("Description", SecurityElement.Escape(m_description)); } CreateXml(e, level); return(e); }
public override SecurityElement ToXml() { SecurityElement element = new SecurityElement("IPermission"); Type type = base.GetType(); element.AddAttribute("class", type.FullName + ", " + type.Module.Assembly.FullName.Replace('"', '\'')); element.AddAttribute("version", "1"); if (this.isUnrestricted) { element.AddAttribute("Unrestricted", "true"); return(element); } IEnumerator enumerator = this.PermissionEntries.GetEnumerator(); while (enumerator.MoveNext()) { SecurityElement child = null; MessageQueuePermissionEntry current = (MessageQueuePermissionEntry)enumerator.Current; if (current.Path != null) { child = new SecurityElement("Path"); child.AddAttribute("value", current.Path); } else { child = new SecurityElement("Criteria"); if (current.MachineName != null) { child.AddAttribute("machine", current.MachineName); } if (current.Category != null) { child.AddAttribute("category", current.Category); } if (current.Label != null) { child.AddAttribute("label", current.Label); } } int permissionAccess = (int)current.PermissionAccess; if (permissionAccess != 0) { StringBuilder builder = null; int[] values = (int[])Enum.GetValues(typeof(MessageQueuePermissionAccess)); Array.Sort(values, System.InvariantComparer.Default); for (int i = values.Length - 1; i >= 0; i--) { if ((values[i] != 0) && ((permissionAccess & values[i]) == values[i])) { if (builder == null) { builder = new StringBuilder(); } else { builder.Append("|"); } builder.Append(Enum.GetName(typeof(MessageQueuePermissionAccess), values[i])); permissionAccess &= values[i] ^ values[i]; } } child.AddAttribute("access", builder.ToString()); } element.AddChild(child); } return(element); }
public SecurityElement ToXml() { SecurityElement root = new SecurityElement("IPermission"); string typename = "System.Security.Permissions.PrincipalPermission"; root.AddAttribute("class", typename + ", " + GetType().Module.Assembly.FullName.Replace('\"', '\'')); root.AddAttribute("version", "1"); if (_idArray != null) { foreach (IDRole idRole in _idArray) { root.AddChild(idRole.ToXml()); } } return root; }
private static SecurityElement CreateDefaultApplicationTrustManagerElement() { SecurityElement elTrustManager = new SecurityElement("IApplicationTrustManager"); elTrustManager.AddAttribute("class", "System.Security.Policy.TrustManager, System.Windows.Forms, Version=" + System.Reflection.Assembly.GetExecutingAssembly().GetVersion() + ", Culture=neutral, PublicKeyToken=" + AssemblyRef.EcmaPublicKeyToken); elTrustManager.AddAttribute("version", "1"); return elTrustManager; }
private static SecurityElement PrintingPermission (string level) { SecurityElement se = new SecurityElement ("IPermission"); se.AddAttribute ("class", PrintingPermissionClass); se.AddAttribute ("version", "1"); se.AddAttribute ("Level", level); return se; }
void Save() { if (IsMarkedForDeletion) { return; } SecurityElement se = new SecurityElement("values"); lock (values){ if (!File.Exists(file) && values.Count == 0) { return; } // 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(); } }
internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( this.GetType().FullName ); elem.AddAttribute( "version", "1" ); return elem; }
public void AddAttribute_Value_Invalid() { SecurityElement elem = CreateElement(); AssertExtensions.Throws <ArgumentException>(null, () => elem.AddAttribute("valid", "invalid\"")); }
internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( "System.Security.Policy.Site" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.Site" ), "Class name changed!" ); elem.AddAttribute( "version", "1" ); if(m_name != null) elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) ); return elem; }
public void AddAttribute_InvalidValue3() { SecurityElement elem = CreateElement(); Assert.Throws <ArgumentException>(() => elem.AddAttribute("valid", "<invalid>")); }
public override string ToString () { SecurityElement se = new SecurityElement (GetType ().FullName); se.AddAttribute ("version", "1"); StringBuilder sb = new StringBuilder (); byte[] raw = GetData (); for (int i=0; i < raw.Length; i++) sb.Append (raw [i].ToString ("X2")); se.AddChild (new SecurityElement ("RawData", sb.ToString ())); return se.ToString (); }
private void ToSecurityElement (SecurityElement se, SNIP snip) { if (snip.PublicKey != null) se.AddAttribute ("PublicKeyBlob", snip.PublicKey.ToString ()); if (snip.Name != null) se.AddAttribute ("Name", snip.Name); if (snip.AssemblyVersion != null) se.AddAttribute ("AssemblyVersion", snip.AssemblyVersion.ToString ()); }
protected override void CreateXml(SecurityElement element, PolicyLevel level) { element.AddAttribute("Access", m_access.ToString()); }