// 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; }
public SecurityElement ToXml () { SecurityElement se = new SecurityElement (tag); se.AddAttribute ("class", typeof (MonoTrustManager).AssemblyQualifiedName); se.AddAttribute ("version", "1"); return se; }
private static SecurityElement CreateDefaultApplicationTrustManagerElement() { SecurityElement element = new SecurityElement("IApplicationTrustManager"); element.AddAttribute("class", "System.Security.Policy.TrustManager, System.Windows.Forms, Version=" + ((RuntimeAssembly) Assembly.GetExecutingAssembly()).GetVersion() + ", Culture=neutral, PublicKeyToken=b77a5c561934e089"); element.AddAttribute("version", "1"); return element; }
public override SecurityElement ToXml() { SecurityElement esd = new SecurityElement("IPermission"); String name = typeof(VirtuosoCodeAccessPermission).AssemblyQualifiedName; esd.AddAttribute("class", name); esd.AddAttribute("version", "1.0"); return esd; }
// Convert this permissions object into an XML value. public override SecurityElement ToXml() { SecurityElement element; element = new SecurityElement("IPermission"); element.AddAttribute ("class", SecurityElement.Escape(typeof(ZoneIdentityPermission). AssemblyQualifiedName)); element.AddAttribute("version", "1"); element.AddAttribute("Zone", zone.ToString()); return element; }
// can be used to create an empty or an unrestricted permission from any valid type static public IPermission Create (string fullname, PermissionState state) { if (fullname == null) throw new ArgumentNullException ("fullname"); SecurityElement se = new SecurityElement ("IPermission"); se.AddAttribute ("class", fullname); se.AddAttribute ("version", "1"); if (state == PermissionState.Unrestricted) se.AddAttribute ("Unrestricted", "true"); return CreatePermission (fullname, se); }
internal SecurityElement ToXml() { SecurityElement element2; SecurityElement element = new SecurityElement("System.Security.Policy.PermissionRequestEvidence"); element.AddAttribute("version", "1"); if (this.m_request != null) { element2 = new SecurityElement("Request"); element2.AddChild(this.m_request.ToXml()); element.AddChild(element2); } if (this.m_optional != null) { element2 = new SecurityElement("Optional"); element2.AddChild(this.m_optional.ToXml()); element.AddChild(element2); } if (this.m_denied != null) { element2 = new SecurityElement("Denied"); element2.AddChild(this.m_denied.ToXml()); element.AddChild(element2); } return element; }
// Convert this permissions object into an XML value. public override SecurityElement ToXml() { SecurityElement element; element = new SecurityElement("IPermission"); element.AddAttribute ("class", SecurityElement.Escape(typeof(UrlIdentityPermission). AssemblyQualifiedName)); element.AddAttribute("version", "1"); if(url != null) { element.AddAttribute ("Url", SecurityElement.Escape(url)); } return element; }
internal static SecurityElement CreatePermissionElement(IPermission perm, string permname) { SecurityElement element = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(element, perm.GetType(), permname); element.AddAttribute("version", "1"); return element; }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element = new SecurityElement("IMembershipCondition"); XMLUtil.AddClassAttribute(element, base.GetType(), "System.Security.Policy.AllMembershipCondition"); element.AddAttribute("version", "1"); return element; }
private SecurityElement ToXml() { SecurityElement root = new SecurityElement("System.Xml.XmlSecureResolver"); root.AddAttribute("version", "1"); root.AddChild(new SecurityElement("UncDirectory", _uncDir)); return root; }
// Convert this principal information block into an XML blob. public SecurityElement ToXml() { SecurityElement elem = new SecurityElement("identity"); if(name != null) { elem.AddAttribute ("ID", SecurityElement.Escape(name)); } if(role != null) { elem.AddAttribute ("Role", SecurityElement.Escape(role)); } elem.AddAttribute ("Authenticated", isAuthenticated.ToString()); return elem; }
internal SecurityElement ToXml() { SecurityElement element = new SecurityElement("Identity"); if (this.m_authenticated) { element.AddAttribute("Authenticated", "true"); } if (this.m_id != null) { element.AddAttribute("ID", SecurityElement.Escape(this.m_id)); } if (this.m_role != null) { element.AddAttribute("Role", SecurityElement.Escape(this.m_role)); } return element; }
/// <include file='doc\AllMembershipCondition.uex' path='docs/doc[@for="AllMembershipCondition.ToXml1"]/*' /> public SecurityElement ToXml( PolicyLevel level ) { SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType() ); root.AddAttribute( "version", "1" ); return root; }
public static void AddClassAttribute(SecurityElement element, Type type, string typename) { if (typename == null) { typename = type.FullName; } element.AddAttribute("class", typename + ", " + type.Module.Assembly.FullName.Replace('"', '\'')); }
internal SecurityElement ToXml() { SecurityElement element = new SecurityElement("System.Security.Policy.Url"); element.AddAttribute("version", "1"); if (this.m_url != null) { element.AddChild(new SecurityElement("Url", this.m_url.ToString())); } return element; }
internal SecurityElement ToXml() { SecurityElement element = new SecurityElement("System.Security.Policy.ApplicationDirectory"); element.AddAttribute("version", "1"); if (this.m_appDirectory != null) { element.AddChild(new SecurityElement("Directory", this.m_appDirectory.ToString())); } return element; }
public SecurityElement ToXml( PolicyLevel level ) { SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.AllMembershipCondition" ); // 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.AllMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); return root; }
public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.EnvironmentPermission"); if (!IsUnrestricted()) { if (this.m_read != null && !this.m_read.IsEmpty()) { esd.AddAttribute("Read", SecurityElement.Escape(m_read.ToString())); } if (this.m_write != null && !this.m_write.IsEmpty()) { esd.AddAttribute("Write", SecurityElement.Escape(m_write.ToString())); } } else { esd.AddAttribute("Unrestricted", "true"); } return(esd); }
AddClassAttribute( SecurityElement element, Type type, String typename ) { // Replace any quotes with apostrophes so that we can include quoted materials // within classnames. Notably the assembly name member 'loc' uses a quoted string. // NOTE: this makes assumptions as to what reflection is expecting for a type string // it will need to be updated if reflection changes what it wants. if ( typename == null ) typename = type.FullName; Contract.Assert( type.FullName.Equals( typename ), "Incorrect class name passed! Was : " + typename + " Shoule be: " + type.FullName); element.AddAttribute( "class", typename + ", " + type.Module.Assembly.FullName.Replace( '\"', '\'' ) ); }
private SecurityElement CreateElement () { SecurityElement elem = new SecurityElement ("IPermission"); elem.AddAttribute ("class", "System"); elem.AddAttribute ("version", "1"); SecurityElement child = new SecurityElement ("ConnectAccess"); elem.AddChild (child); SecurityElement grandchild = new SecurityElement ("ENDPOINT", "some text"); grandchild.AddAttribute ("transport", "All"); grandchild.AddAttribute ("host", "localhost"); grandchild.AddAttribute ("port", "8080"); child.AddChild (grandchild); SecurityElement grandchild2 = new SecurityElement ("ENDPOINT"); grandchild2.AddAttribute ("transport", "Tcp"); grandchild2.AddAttribute ("host", "www.ximian.com"); grandchild2.AddAttribute ("port", "All"); child.AddChild (grandchild2); return elem; }
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), attrs.GetValue (i)); }
// Convert this permissions object into an XML value. public override SecurityElement ToXml() { SecurityElement element; element = new SecurityElement("IPermission"); element.AddAttribute ("class", SecurityElement.Escape (typeof(PublisherIdentityPermission). AssemblyQualifiedName)); element.AddAttribute("version", "1"); if(certificate != null) { element.AddAttribute ("X509v3Certificate", certificate.GetRawCertDataString()); } return element; }
public void FromXml_NoVersion () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", se.Attribute ("class")); uip.FromXml (w); }
public void FromXml_NoClass () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", se.Attribute ("version")); uip.FromXml (w); // doesn't even care of the class attribute presence }
public void FromXml_WrongClass () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", "Wrong" + se.Attribute ("class")); w.AddAttribute ("version", se.Attribute ("version")); uip.FromXml (w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void FromXml_NoChild () { ApplicationTrust at = new ApplicationTrust (); SecurityElement se = at.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", "1"); at.FromXml (w); Assert.IsNull (at.ApplicationIdentity, "ApplicationIdentity"); Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes"); Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString"); Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty"); Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted"); Assert.IsNull (at.ExtraInfo, "ExtraInfo"); Assert.IsFalse (at.IsApplicationTrustedToRun, "IsApplicationTrustedToRun"); Assert.IsFalse (at.Persist, "Persist"); }
// 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 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; }
internal PolicyStatement CalculatePolicy( String host, String scheme, String port ) { SecurityElement webPerm = CreateWebPermission( host, scheme, port ); SecurityElement root = new SecurityElement( "PolicyStatement" ); SecurityElement permSet = new SecurityElement( "PermissionSet" ); permSet.AddAttribute( "class", "System.Security.PermissionSet" ); permSet.AddAttribute( "version", "1" ); if (webPerm != null) permSet.AddChild( webPerm ); root.AddChild( permSet ); PolicyStatement policy = new PolicyStatement(); policy.FromXml( root ); return policy; }
internal static void EncodeLevel(PolicyLevel level) { Contract.Assert(level != null, "No policy level to encode."); // We cannot encode a policy level without a backing file if (level.Path == null) { string errorMessage = Environment.GetResourceString("Policy_UnableToSave", level.Label, Environment.GetResourceString("Policy_SaveNotFileBased")); throw new PolicyException(errorMessage); } SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { StringBuilder sb = new StringBuilder(); Encoding encoding = Encoding.UTF8; SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); sb.Append(format.ToString()); sb.Append(elConf.ToString()); byte[] data = encoding.GetBytes(sb.ToString()); // Write out the new config. int hrSave = Config.SaveDataByte(level.Path, data, data.Length); Exception extendedError = Marshal.GetExceptionForHR(hrSave); if (extendedError != null) { string extendedInformation = extendedError != null ? extendedError.Message : String.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, extendedInformation), extendedError); } } catch (Exception e) { if (e is PolicyException) { throw e; } else { throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, e.Message), e); } } Config.ResetCacheData(level.ConfigId); if (CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); } }
public void FromXml_InvalidVersion () { ApplicationTrust at = new ApplicationTrust (); SecurityElement se = at.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", "2"); foreach (SecurityElement child in se.Children) w.AddChild (child); at.FromXml (w); }
internal static void EncodeLevel(PolicyLevel level) { if (level.Path == null) { string resourceString = Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") }); throw new PolicyException(resourceString); } SecurityElement securityElement = new SecurityElement("configuration"); SecurityElement securityElement2 = new SecurityElement("mscorlib"); SecurityElement securityElement3 = new SecurityElement("security"); SecurityElement securityElement4 = new SecurityElement("policy"); securityElement.AddChild(securityElement2); securityElement2.AddChild(securityElement3); securityElement3.AddChild(securityElement4); securityElement4.AddChild(level.ToXml()); try { StringBuilder stringBuilder = new StringBuilder(); Encoding utf = Encoding.UTF8; SecurityElement securityElement5 = new SecurityElement("xml"); securityElement5.m_type = SecurityElementType.Format; securityElement5.AddAttribute("version", "1.0"); securityElement5.AddAttribute("encoding", utf.WebName); stringBuilder.Append(securityElement5.ToString()); stringBuilder.Append(securityElement.ToString()); byte[] bytes = utf.GetBytes(stringBuilder.ToString()); int errorCode = Config.SaveDataByte(level.Path, bytes, bytes.Length); Exception exceptionForHR = Marshal.GetExceptionForHR(errorCode); if (exceptionForHR != null) { string text = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, text }), exceptionForHR); } } catch (Exception ex) { if (ex is PolicyException) { throw ex; } throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, ex.Message }), ex); } Config.ResetCacheData(level.ConfigId); if (PolicyManager.CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level)); } }
internal static void EncodeLevel(PolicyLevel level) { SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { MemoryStream stream = new MemoryStream(24576); StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false)); Encoding encoding = level.Encoding; if (encoding == null) { encoding = writer.Encoding; } SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); writer.Write(format.ToString()); writer.Flush(); writer = new StreamWriter(stream, encoding); writer.Write(elConf.ToString()); writer.Flush(); // Write out the new config. if (!Config.SaveData(level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length)) { throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } } catch (Exception e) { if (e is PolicyException) { throw e; } else { throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label), e); } } Config.ResetCacheData(level.ConfigId); try { if (CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); } } catch (Exception) { } }
// Parse an element tag. private SecurityElement ParseElement() { // Create the new element. SecurityElement element; element = new SecurityElement(value); // Parse and add the attribute arguments. int temp = 0; int start; String name; String avalue; for (;;) { while (temp < args.Length && Char.IsWhiteSpace(args[temp])) { ++temp; } if (temp >= args.Length) { break; } start = temp; while (temp < args.Length && args[temp] != '=') { ++temp; } name = args.Substring(start, temp - start); if (temp < args.Length) { ++temp; } if (temp < args.Length && args[temp] == '"') { ++temp; start = temp; while (temp < args.Length && args[temp] != '"') { ++temp; } avalue = args.Substring(start, temp - start); if (temp < args.Length) { ++temp; } } else if (temp < args.Length && args[temp] == '\'') { ++temp; start = temp; while (temp < args.Length && args[temp] != '\'') { ++temp; } avalue = args.Substring(start, temp - start); if (temp < args.Length) { ++temp; } } else { avalue = String.Empty; } element.AddAttribute(name, avalue); } // Parse the children of this element. if (token == Token.SingletonTag) { NextToken(); } else { NextToken(); while (token != Token.EOF && token != Token.EndTag) { if (token == Token.StartTag || token == Token.SingletonTag) { SecurityElement child; child = ParseElement(); element.AddChild(child); } else if (token == Token.Text) { String prevText = element.Text; if (prevText != null) { element.Text = prevText + value; } else { element.Text = value; } } NextToken(); } } // Return the final element to the caller. return(element); }