public static Boolean Test() { Boolean bRes = true; SecurityElement el = new SecurityElement("whatever"); // el.Text = "<Key>RSA</Key><Digest>SHA1</Digest><Formatter>System.Security.Cryptography.RSAPKCS1SignatureFormatter</Formatter><Deformatter>System.Security.Cryptography.RSAPKCS1SignatureFormatter</Deformatter>"; SecurityElement el_key = new SecurityElement("Key"); el_key.Text = "RSA"; SecurityElement el_digest = new SecurityElement("Digest"); el_digest.Text = "SHA1"; SecurityElement el_form = new SecurityElement("Formatter"); el_form.Text = "System.Security.Cryptography.RSAPKCS1SignatureFormatter"; SecurityElement el_deform = new SecurityElement("Deformatter"); el_deform.Text = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter"; el.AddChild(el_key); el.AddChild(el_digest); el.AddChild(el_form); el.AddChild(el_deform); SignatureDescription sd_empty = new SignatureDescription(); SignatureDescription sd = new SignatureDescription(el); Console.WriteLine(sd.CreateDigest()); Console.WriteLine(sd.CreateFormatter(RSA.Create())); Console.WriteLine(sd.CreateDeformatter(RSA.Create())); return bRes; }
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.Equal("System.Security.Cryptography.RSACryptoServiceProvider", sig.KeyAlgorithm); Assert.Equal("System.Security.Cryptography.SHA1CryptoServiceProvider", sig.DigestAlgorithm); Assert.Equal("System.Security.Cryptography.RSAPKCS1SignatureFormatter", sig.FormatterAlgorithm); Assert.Equal("System.Security.Cryptography.RSAPKCS1SignatureDeformatter", sig.DeformatterAlgorithm); }
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); }
// If a domain attribute is not found in the specified FileCodeGroup, // add a child XML element identifying a custom membership condition. private static void addXmlMember(ref FileCodeGroup fileCodeGroup) { //<Snippet10> SecurityElement xmlElement = fileCodeGroup.ToXml(); //</Snippet10> SecurityElement rootElement = new SecurityElement("CodeGroup"); if (xmlElement.Attribute("domain") == null) { //<Snippet11> SecurityElement newElement = new SecurityElement("CustomMembershipCondition"); newElement.AddAttribute("class", "CustomMembershipCondition"); newElement.AddAttribute("version", "1"); newElement.AddAttribute("domain", "contoso.com"); rootElement.AddChild(newElement); fileCodeGroup.FromXml(rootElement); //</Snippet11> } Console.WriteLine("Added a custom membership condition:"); Console.WriteLine(rootElement.ToString()); }
/// <summary>创建权限及其当前状态的 XML 编码。</summary> /// <returns>权限的 XML 编码,包括任何状态信息。</returns> public override SecurityElement ToXml() { SecurityElement permissionElement = CodeAccessPermission.CreatePermissionElement((IPermission)this, "System.Security.Permissions.UrlIdentityPermission"); if (this.m_unrestricted) { permissionElement.AddAttribute("Unrestricted", "true"); } else if (this.m_urls != null) { if (this.m_urls.Length == 1) { permissionElement.AddAttribute("Url", this.m_urls[0].ToString()); } else { for (int index = 0; index < this.m_urls.Length; ++index) { SecurityElement child = new SecurityElement("Url"); child.AddAttribute("Url", this.m_urls[index].ToString()); permissionElement.AddChild(child); } } } return(permissionElement); }
// Token: 0x06002AE6 RID: 10982 RVA: 0x0009F560 File Offset: 0x0009D760 internal SecurityElement ToXml() { SecurityElement securityElement = new SecurityElement("System.Security.Policy.Publisher"); securityElement.AddAttribute("version", "1"); securityElement.AddChild(new SecurityElement("X509v3Certificate", (this.m_cert != null) ? this.m_cert.GetRawCertDataString() : "")); return securityElement; }
/// <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> public SecurityElement ToXml() { SecurityElement securityElement = new SecurityElement("Permission"); Type type = base.GetType(); securityElement.AddAttribute("class", type.FullName + ", " + type.Assembly.ToString().Replace('"', '\'')); securityElement.AddAttribute("version", 1.ToString()); foreach (object obj in this.principals) { PrincipalPermission.PrincipalInfo principalInfo = (PrincipalPermission.PrincipalInfo)obj; SecurityElement securityElement2 = new SecurityElement("Identity"); if (principalInfo.Name != null) { securityElement2.AddAttribute("ID", principalInfo.Name); } if (principalInfo.Role != null) { securityElement2.AddAttribute("Role", principalInfo.Role); } if (principalInfo.IsAuthenticated) { securityElement2.AddAttribute("Authenticated", "true"); } securityElement.AddChild(securityElement2); } return(securityElement); }
public void AddChild_Null() { try { elem.AddChild(null); Assert.Fail("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.IsNotNull(ex.ParamName, "#5"); Assert.AreEqual("child", ex.ParamName, "#6"); } }
public void OnStartElement(string name, SmallXmlParser.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++) { string tmpStr = attrs.GetValue(i); if (attrs.GetName(i) == "Consume_Info") { tmpStr = tmpStr.Replace('"', '\''); } current.AddAttribute(attrs.GetName(i), tmpStr); } }
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); }
// 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); }
private SecurityElement CreateSocketPermission(String host, String scheme, int port) { // Note: this code currently does nothing with the port SecurityElement root = new SecurityElement("IPermission"); root.AddAttribute("class", "System.Net.SocketPermission, System, Version=" + Assembly.GetExecutingAssembly().GetVersion().ToString() + ", Culture=neutral, PublicKeyToken=b77a5c561934e089"); root.AddAttribute("version", "1"); SecurityElement connectAccess = new SecurityElement("ConnectAccess"); SecurityElement uri1 = new SecurityElement("ENDPOINT"); uri1.AddAttribute("host", host); uri1.AddAttribute("transport", "All"); uri1.AddAttribute("port", "All"); connectAccess.AddChild(uri1); SecurityElement acceptAccess = new SecurityElement("AcceptAccess"); SecurityElement uri2 = new SecurityElement("ENDPOINT"); uri2.AddAttribute("host", host); uri2.AddAttribute("transport", "All"); uri2.AddAttribute("port", "All"); acceptAccess.AddChild(uri2); root.AddChild(connectAccess); root.AddChild(acceptAccess); return(root); }
public override SecurityElement ToXml() { SecurityElement element = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.PublisherIdentityPermission"); if (this.m_unrestricted) { element.AddAttribute("Unrestricted", "true"); return(element); } if (this.m_certs != null) { if (this.m_certs.Length == 1) { element.AddAttribute("X509v3Certificate", this.m_certs[0].GetRawCertDataString()); return(element); } for (int i = 0; i < this.m_certs.Length; i++) { SecurityElement child = new SecurityElement("Cert"); child.AddAttribute("X509v3Certificate", this.m_certs[i].GetRawCertDataString()); element.AddChild(child); } } return(element); }
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[] access = this.FindAccessRulesForScheme(scheme); if ((access == null) || (access.Length == 0)) { return(null); } SecurityElement element = new SecurityElement("IPermission"); element.AddAttribute("class", "System.Net.WebPermission, " + ((assemblyOverride == null) ? "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" : assemblyOverride)); element.AddAttribute("version", "1"); SecurityElement child = new SecurityElement("ConnectAccess"); host = this.EscapeStringForRegex(host); scheme = this.EscapeStringForRegex(scheme); string str2 = this.TryPermissionAsOneString(access, scheme, host, intPort); if (str2 != null) { SecurityElement element3 = new SecurityElement("URI"); element3.AddAttribute("uri", str2); child.AddChild(element3); } else { if (port.Length != 0) { port = ":" + port; } for (int i = 0; i < access.Length; i++) { str2 = this.GetPermissionAccessElementString(access[i], scheme, host, port); SecurityElement element4 = new SecurityElement("URI"); element4.AddAttribute("uri", str2); child.AddChild(element4); } } element.AddChild(child); return(element); }
public static bool Add(SecurityElement se, string tag, string value) { SecurityElement item = new SecurityElement(tag, value); se.AddChild(item); return(true); }
private static SecurityElement LoadSecurityElementChecked(BinaryReader InReader, byte InType, SecurityElement InParent) { byte b = InReader.ReadByte(); if (b != InType) { return(null); } string text = InReader.ReadString(); string text2 = InReader.ReadString(); SecurityElement securityElement = new SecurityElement(text, text2); int num = InReader.ReadInt32(); DebugHelper.Assert(num < 512, "too many attributes."); for (int i = 0; i < num; i++) { string text3 = InReader.ReadString(); string text4 = InReader.ReadString(); securityElement.AddAttribute(text3, text4); } int num2 = InReader.ReadInt32(); DebugHelper.Assert(num2 < 515, "too many children"); for (int j = 0; j < num2; j++) { SecurityElement securityElement2 = SecurityTools.LoadSecurityElementChecked(InReader, 1, securityElement); DebugHelper.Assert(securityElement2 != null, "invalid child element"); } if (InParent != null) { InParent.AddChild(securityElement); } return(securityElement); }
SecurityElement MergeData(SecurityElement root) { SecurityElement out_root = new SecurityElement("table"); SecurityElement out_type = new SecurityElement("type"); SecurityElement out_data = new SecurityElement("data"); foreach (SecurityElement data in root.Children) { if (data.Children == null || data.Children.Count <= 0) { continue; } if (data.Tag == out_type.Tag) { if (out_type.Children == null || out_type.Children.Count <= 0) { out_type.AddChild(data.Children[0] as SecurityElement); } } else if (data.Tag == out_data.Tag) { foreach (SecurityElement item in data.Children) { out_data.AddChild(item); } } } out_root.AddChild(out_type); out_root.AddChild(out_data); return(out_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(); }
private static SecurityElement LoadSecurityElementChecked(BinaryReader InReader, byte InType, SecurityElement InParent) { if (InReader.ReadByte() != InType) { return(null); } string tag = InReader.ReadString(); string text = InReader.ReadString(); SecurityElement inParent = new SecurityElement(tag, text); int num2 = InReader.ReadInt32(); DebugHelper.Assert(num2 < 0x200, "too many attributes."); for (int i = 0; i < num2; i++) { string name = InReader.ReadString(); string str4 = InReader.ReadString(); inParent.AddAttribute(name, str4); } int num4 = InReader.ReadInt32(); DebugHelper.Assert(num4 < 0x203, "too many children"); for (int j = 0; j < num4; j++) { DebugHelper.Assert(LoadSecurityElementChecked(InReader, 1, inParent) != null, "invalid child element"); } if (InParent != null) { InParent.AddChild(inParent); } return(inParent); }
public void OnStartElement(string name, SmallXmlParser.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 if (attrs != null) { for (int i = 0; i < attrs.Length; i++) { current.AddAttribute(attrs.GetName(i), attrs.GetValue(i)); } } }
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 SecurityElement ToXml() { SecurityElement se = PermissionHelper.Element(this.GetType(), version); if (IsUnrestricted()) { se.AddAttribute("Unrestricted", "true"); } else { // attribute is present for both True and False se.AddAttribute("AllowBlankPassword", allowBlankPassword.ToString()); foreach (DictionaryEntry de in _connections) { SecurityElement child = new SecurityElement("add"); child.AddAttribute("ConnectionString", (string)de.Key); object[] restrictionsInfo = (object[])de.Value; child.AddAttribute("KeyRestrictions", (string)restrictionsInfo [0]); KeyRestrictionBehavior krb = (KeyRestrictionBehavior)restrictionsInfo [1]; child.AddAttribute("KeyRestrictionBehavior", krb.ToString()); se.AddChild(child); } } return(se); }
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); }
/// <include file='doc\PermissionRequestEvidence.uex' path='docs/doc[@for="PermissionRequestEvidence.ToXml"]/*' /> internal SecurityElement ToXml() { SecurityElement root = new SecurityElement(this.GetType().FullName); root.AddAttribute("version", "1"); SecurityElement elem; if (m_request != null) { elem = new SecurityElement("Request"); elem.AddChild(m_request.ToXml()); root.AddChild(elem); } if (m_optional != null) { elem = new SecurityElement("Optional"); elem.AddChild(m_optional.ToXml()); root.AddChild(elem); } if (m_denied != null) { elem = new SecurityElement("Denied"); elem.AddChild(m_denied.ToXml()); root.AddChild(elem); } return(root); }
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); } } } }
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 override SecurityElement ToXml() { SecurityElement element = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.UrlIdentityPermission"); if (this.m_unrestricted) { element.AddAttribute("Unrestricted", "true"); return(element); } if (this.m_urls != null) { if (this.m_urls.Length == 1) { element.AddAttribute("Url", this.m_urls[0].ToString()); return(element); } for (int i = 0; i < this.m_urls.Length; i++) { SecurityElement child = new SecurityElement("Url"); child.AddAttribute("Url", this.m_urls[i].ToString()); element.AddChild(child); } } return(element); }
private static 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); }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element; element = new SecurityElement("CodeGroup"); element.AddAttribute ("class", SecurityElement.Escape(GetType().AssemblyQualifiedName)); element.AddAttribute("version", "1"); element.AddChild(membershipCondition.ToXml(level)); if (policy != null) { PermissionSet permSet = policy.PermissionSetNoCopy; if (permSet is NamedPermissionSet && level != null && level.GetNamedPermissionSet (((NamedPermissionSet)permSet).Name) != null) { element.AddAttribute ("PermissionSetName", ((NamedPermissionSet)permSet).Name); } else if (!permSet.IsEmpty()) { element.AddChild(permSet.ToXml()); } if (policy.Attributes != PolicyStatementAttribute.Nothing) { element.AddAttribute ("Attributes", policy.Attributes.ToString()); } foreach (CodeGroup group in Children) { element.AddChild(group.ToXml(level)); } } if (name != null) { element.AddAttribute("Name", SecurityElement.Escape(name)); } if (description != null) { element.AddAttribute ("Description", SecurityElement.Escape(description)); } CreateXml(element, level); return(element); }
public SecurityElement ToXml() { Hashtable fullNames = new Hashtable(); // only StrongNameMembershipCondition so no need to loop if (full_trust_assemblies.Count > 0) { if (!fullNames.Contains("StrongNameMembershipCondition")) { fullNames.Add("StrongNameMembershipCondition", typeof(StrongNameMembershipCondition).FullName); } } SecurityElement namedPSs = new SecurityElement("NamedPermissionSets"); foreach (NamedPermissionSet nps in named_permission_sets) { SecurityElement se = nps.ToXml(); object objectClass = se.Attributes ["class"]; if (!fullNames.Contains(objectClass)) { fullNames.Add(objectClass, nps.GetType().FullName); } namedPSs.AddChild(se); } SecurityElement fta = new SecurityElement("FullTrustAssemblies"); foreach (StrongNameMembershipCondition snmc in full_trust_assemblies) { fta.AddChild(snmc.ToXml(this)); } SecurityElement security_classes = new SecurityElement("SecurityClasses"); if (fullNames.Count > 0) { foreach (DictionaryEntry de in fullNames) { SecurityElement sc = new SecurityElement("SecurityClass"); sc.AddAttribute("Name", (string)de.Key); sc.AddAttribute("Description", (string)de.Value); security_classes.AddChild(sc); } } SecurityElement element = new SecurityElement(typeof(System.Security.Policy.PolicyLevel).Name); element.AddAttribute("version", "1"); element.AddChild(security_classes); element.AddChild(namedPSs); if (root_code_group != null) { element.AddChild(root_code_group.ToXml(this)); } element.AddChild(fta); return(element); }
private SecurityElement ToXml() { SecurityElement element = new SecurityElement("System.Xml.XmlSecureResolver"); element.AddAttribute("version", "1"); element.AddChild(new SecurityElement("UncDirectory", this.uncDir)); return(element); }
public override string ToString() { SecurityElement element = new SecurityElement("System.Security.Policy.Site"); element.AddAttribute("version", "1"); element.AddChild(new SecurityElement("Name", origin_site)); return(element.ToString()); }
/// <summary>Returns a string representation of the current <see cref="T:System.Security.Policy.Zone" />.</summary> /// <returns>A representation of the current <see cref="T:System.Security.Policy.Zone" />.</returns> public override string ToString() { SecurityElement securityElement = new SecurityElement("System.Security.Policy.Zone"); securityElement.AddAttribute("version", "1"); securityElement.AddChild(new SecurityElement("Zone", this.zone.ToString())); return(securityElement.ToString()); }
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 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 () { // 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 (); }
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; }
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 (); }
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 override string ToString () { SecurityElement element = new SecurityElement ("System.Security.Policy.Site"); element.AddAttribute ("version", "1"); element.AddChild (new SecurityElement ("Name", origin_site)); return element.ToString (); }
internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( "System.Security.Policy.Publisher" ); // 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.Publisher" ), "Class name changed!" ); elem.AddAttribute( "version", "1" ); elem.AddChild( new SecurityElement( "X509v3Certificate", m_cert != null ? m_cert.GetRawCertDataString() : "" ) ); return elem; }
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; }
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; }
private Boolean SaveRecord() { SecurityElement xmlRoot = new SecurityElement("expansion_pack_record"); lock (m_lock) { foreach (var item in m_packRecordMap) { String packId = item.Key; ExpansionPackRecord record = item.Value; SecurityElement xmlItem = new SecurityElement("item"); xmlRoot.AddChild(xmlItem); xmlItem.AddAttribute("id", packId); xmlItem.AddAttribute("state", ((Int32)record.state).ToString()); } } try { CreateDirectoryForFile(GetRecordFilePath()); File.WriteAllText(GetRecordFilePath(), xmlRoot.ToString()); return true; } catch (IOException e) { Debug.LogException(e); return false; } }
// Convert this object into a string. public override String ToString() { SecurityElement element; element = new SecurityElement("System.Security.Policy.Hash"); element.AddAttribute("version", "1"); byte[] rawData = RawData; if(rawData != null && rawData.Length != 0) { element.AddChild(new SecurityElement ("RawData", StrongNamePublicKeyBlob.ToHex(rawData))); } return element.ToString(); }
private SecurityElement ToXml() { GenerateDefaultHashes(); SecurityElement root = new SecurityElement("System.Security.Policy.Hash"); // 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. BCLDebug.Assert(this.GetType().FullName.Equals("System.Security.Policy.Hash"), "Class name changed!"); root.AddAttribute("version", "2"); foreach (KeyValuePair<Type, byte[]> hashValue in m_hashes) { SecurityElement hashElement = new SecurityElement("hash"); hashElement.AddAttribute("algorithm", hashValue.Key.Name); hashElement.AddAttribute("value", Hex.EncodeHexString(hashValue.Value)); root.AddChild(hashElement); } return root; }
public SecurityElement ToXml () { Hashtable fullNames = new Hashtable (); // only StrongNameMembershipCondition so no need to loop if (full_trust_assemblies.Count > 0) { if (!fullNames.Contains ("StrongNameMembershipCondition")) { fullNames.Add ("StrongNameMembershipCondition", typeof (StrongNameMembershipCondition).FullName); } } SecurityElement namedPSs = new SecurityElement ("NamedPermissionSets"); foreach (NamedPermissionSet nps in named_permission_sets) { SecurityElement se = nps.ToXml (); object objectClass = se.Attributes ["class"]; if (!fullNames.Contains (objectClass)) { fullNames.Add (objectClass, nps.GetType ().FullName); } namedPSs.AddChild (se); } SecurityElement fta = new SecurityElement ("FullTrustAssemblies"); foreach (StrongNameMembershipCondition snmc in full_trust_assemblies) { fta.AddChild (snmc.ToXml (this)); } SecurityElement security_classes = new SecurityElement ("SecurityClasses"); if (fullNames.Count > 0) { foreach (DictionaryEntry de in fullNames) { SecurityElement sc = new SecurityElement ("SecurityClass"); sc.AddAttribute ("Name", (string)de.Key); sc.AddAttribute ("Description", (string)de.Value); security_classes.AddChild (sc); } } SecurityElement element = new SecurityElement (typeof (System.Security.Policy.PolicyLevel).Name); element.AddAttribute ("version", "1"); element.AddChild (security_classes); element.AddChild (namedPSs); if (root_code_group != null) { element.AddChild (root_code_group.ToXml (this)); } element.AddChild (fta); return element; }
public SecurityElement ToXml () { SecurityElement se = new SecurityElement ("ApplicationTrust"); se.AddAttribute ("version", "1"); if (_appid != null) { se.AddAttribute ("FullName", _appid.FullName); } if (_trustrun) { se.AddAttribute ("TrustedToRun", "true"); } if (_persist) { se.AddAttribute ("Persist", "true"); } SecurityElement defaultGrant = new SecurityElement ("DefaultGrant"); defaultGrant.AddChild (DefaultGrantSet.ToXml ()); se.AddChild (defaultGrant); if (_xtranfo != null) { byte[] data = null; using (MemoryStream ms = new MemoryStream ()) { BinaryFormatter bf = new BinaryFormatter (); bf.Serialize (ms, _xtranfo); data = ms.ToArray (); } SecurityElement xtra = new SecurityElement ("ExtraInfo"); xtra.AddAttribute ("Data", CryptoConvert.ToHex (data)); se.AddChild (xtra); } return se; }
public SecurityElement ToXml () { SecurityElement se = new SecurityElement ("Permission"); Type type = this.GetType (); se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\'')); se.AddAttribute ("version", version.ToString ()); foreach (PrincipalInfo pi in principals) { SecurityElement sec = new SecurityElement ("Identity"); if (pi.Name != null) sec.AddAttribute ("ID", pi.Name); if (pi.Role != null) sec.AddAttribute ("Role", pi.Role); if (pi.IsAuthenticated) sec.AddAttribute ("Authenticated", "true"); se.AddChild (sec); } return se; }
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; }
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; }
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 (); }
[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; }
internal SecurityElement ToXml() { SecurityElement root = new SecurityElement( "System.Security.Policy.PermissionRequestEvidence" ); // 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.PermissionRequestEvidence" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); SecurityElement elem; if (m_request != null) { elem = new SecurityElement( "Request" ); elem.AddChild( m_request.ToXml() ); root.AddChild( elem ); } if (m_optional != null) { elem = new SecurityElement( "Optional" ); elem.AddChild( m_optional.ToXml() ); root.AddChild( elem ); } if (m_denied != null) { elem = new SecurityElement( "Denied" ); elem.AddChild( m_denied.ToXml() ); root.AddChild( elem ); } return root; }
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; }
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; }
internal SecurityElement ToXml() { SecurityElement elem = new SecurityElement( this.GetType().FullName ); elem.AddAttribute( "version", "1" ); if(m_name != null) elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) ); return elem; }
private void SetFactoryPermissionSets() { lock (this) { m_namedPermissionSets = new ArrayList(); string[] repStrs = new string[s_FactoryPolicySearchStrings.Length]; repStrs[0] = ThisAssembly.Version; repStrs[1] = Environment.GetResourceString("Policy_PS_FullTrust"); repStrs[2] = Environment.GetResourceString("Policy_PS_Everything"); repStrs[3] = Environment.GetResourceString("Policy_PS_Nothing"); repStrs[4] = Environment.GetResourceString("Policy_PS_SkipVerification"); repStrs[5] = Environment.GetResourceString("Policy_PS_Execution"); m_permSetElement = new Parser(PolicyLevelData.s_defaultPermissionSets, s_FactoryPolicySearchStrings, repStrs).GetTopElement(); m_permSetElement.AddChild(GetInternetElement()); m_permSetElement.AddChild(GetLocalIntranetElement()); } }
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 void SetFactoryPermissionSets() { lock (this) { m_namedPermissionSets = new ArrayList(); String defaultPermissionSets = PolicyLevelData.s_defaultPermissionSets.Replace( "{VERSION}", s_mscorlibVersionString ); defaultPermissionSets = defaultPermissionSets.Replace( "{Policy_PS_FullTrust}", Environment.GetResourceString( "Policy_PS_FullTrust" ) ); defaultPermissionSets = defaultPermissionSets.Replace( "{Policy_PS_Everything}", Environment.GetResourceString( "Policy_PS_Everything" ) ); defaultPermissionSets = defaultPermissionSets.Replace( "{Policy_PS_Nothing}", Environment.GetResourceString( "Policy_PS_Nothing" ) ); defaultPermissionSets = defaultPermissionSets.Replace( "{Policy_PS_SkipVerification}", Environment.GetResourceString( "Policy_PS_SkipVerification" ) ); defaultPermissionSets = defaultPermissionSets.Replace( "{Policy_PS_Execution}", Environment.GetResourceString( "Policy_PS_Execution" ) ); m_permSetElement = new Parser( defaultPermissionSets ).GetTopElement(); m_permSetElement.AddChild( GetInternetElement() ); m_permSetElement.AddChild( GetLocalIntranetElement() ); } }