Наследование: IConstantMembershipCondition, IReportMatchMembershipCondition, IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
Пример #1
0
        public void RemoveFullTrustAssembly(StrongName sn)
        {
            if (sn == null)
            {
                throw new ArgumentNullException("sn");
            }
            StrongNameMembershipCondition snMC = new StrongNameMembershipCondition(sn.PublicKey, sn.Name, sn.Version);

            this.RemoveFullTrustAssembly(snMC);
        }
Пример #2
0
        /// <summary>Creates an XML encoding of the security object and its current state.</summary>
        /// <returns>An XML encoding of the security object, including any state information.</returns>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
        /// </PermissionSet>
        public SecurityElement ToXml()
        {
            Hashtable hashtable = new Hashtable();

            if (this.full_trust_assemblies.Count > 0 && !hashtable.Contains("StrongNameMembershipCondition"))
            {
                hashtable.Add("StrongNameMembershipCondition", typeof(StrongNameMembershipCondition).FullName);
            }
            SecurityElement securityElement = new SecurityElement("NamedPermissionSets");

            foreach (object obj in this.named_permission_sets)
            {
                NamedPermissionSet namedPermissionSet = (NamedPermissionSet)obj;
                SecurityElement    securityElement2   = namedPermissionSet.ToXml();
                object             key = securityElement2.Attributes["class"];
                if (!hashtable.Contains(key))
                {
                    hashtable.Add(key, namedPermissionSet.GetType().FullName);
                }
                securityElement.AddChild(securityElement2);
            }
            SecurityElement securityElement3 = new SecurityElement("FullTrustAssemblies");

            foreach (object obj2 in this.full_trust_assemblies)
            {
                StrongNameMembershipCondition strongNameMembershipCondition = (StrongNameMembershipCondition)obj2;
                securityElement3.AddChild(strongNameMembershipCondition.ToXml(this));
            }
            SecurityElement securityElement4 = new SecurityElement("SecurityClasses");

            if (hashtable.Count > 0)
            {
                foreach (object obj3 in hashtable)
                {
                    DictionaryEntry dictionaryEntry  = (DictionaryEntry)obj3;
                    SecurityElement securityElement5 = new SecurityElement("SecurityClass");
                    securityElement5.AddAttribute("Name", (string)dictionaryEntry.Key);
                    securityElement5.AddAttribute("Description", (string)dictionaryEntry.Value);
                    securityElement4.AddChild(securityElement5);
                }
            }
            SecurityElement securityElement6 = new SecurityElement(typeof(PolicyLevel).Name);

            securityElement6.AddAttribute("version", "1");
            securityElement6.AddChild(securityElement4);
            securityElement6.AddChild(securityElement);
            if (this.root_code_group != null)
            {
                securityElement6.AddChild(this.root_code_group.ToXml(this));
            }
            securityElement6.AddChild(securityElement3);
            return(securityElement6);
        }
Пример #3
0
 public void AddFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     if (snMC == null)
     {
         throw new ArgumentNullException("snMC");
     }
     if (fullTrustAssemblies.Contains(snMC))
     {
         throw new ArgumentException
                   (_("Security_FullTrustPresent"));
     }
     fullTrustAssemblies.Add(snMC);
 }
		public void AddFullTrustAssembly () 
		{
			PolicyLevel pl = Load (minimal, PolicyLevelType.Machine);
			int n = pl.FullTrustAssemblies.Count;

			StrongName sn = new StrongName (new StrongNamePublicKeyBlob (snPublicKey), "First", new Version (1, 2, 3, 4)); 
			pl.AddFullTrustAssembly (sn);
			Assert.AreEqual (n + 1, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count+1");

			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (new StrongNamePublicKeyBlob (snPublicKey), "Second", new Version ("0.1.2.3"));
			pl.AddFullTrustAssembly (snmc);
			Assert.AreEqual (n + 2, pl.FullTrustAssemblies.Count, "FullTrustAssemblies.Count+2");
		}
Пример #5
0
 public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     if (snMC == null)
     {
         throw new ArgumentNullException("snMC");
     }
     if (((IList)this.full_trust_assemblies).Contains(snMC))
     {
         ((IList)this.full_trust_assemblies).Remove(snMC);
         return;
     }
     throw new ArgumentException(Locale.GetText("sn does not have full trust."));
 }
        internal bool IsFullTrustAssembly(Assembly a)
        {
            AssemblyName                  an    = a.UnprotectedGetName();
            StrongNamePublicKeyBlob       snpkb = new StrongNamePublicKeyBlob(an.GetPublicKey());
            StrongNameMembershipCondition snMC  = new StrongNameMembershipCondition(snpkb, an.Name, an.Version);

            foreach (StrongNameMembershipCondition sn in full_trust_assemblies)
            {
                if (sn.Equals(snMC))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
 public void AddFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     if (snMC == null)
     {
         throw new ArgumentNullException("snMC");
     }
     foreach (object obj in this.full_trust_assemblies)
     {
         StrongNameMembershipCondition strongNameMembershipCondition = (StrongNameMembershipCondition)obj;
         if (strongNameMembershipCondition.Equals(snMC))
         {
             throw new ArgumentException(Locale.GetText("sn already has full trust."));
         }
     }
     this.full_trust_assemblies.Add(snMC);
 }
Пример #8
0
        internal bool IsFullTrustAssembly(Assembly a)
        {
            AssemblyName                  assemblyName = a.UnprotectedGetName();
            StrongNamePublicKeyBlob       blob         = new StrongNamePublicKeyBlob(assemblyName.GetPublicKey());
            StrongNameMembershipCondition o            = new StrongNameMembershipCondition(blob, assemblyName.Name, assemblyName.Version);

            foreach (object obj in this.full_trust_assemblies)
            {
                StrongNameMembershipCondition strongNameMembershipCondition = (StrongNameMembershipCondition)obj;
                if (strongNameMembershipCondition.Equals(o))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #9
0
        /// <include file='doc\StrongNameMembershipCondition.uex' path='docs/doc[@for="StrongNameMembershipCondition.Equals"]/*' />
        public override bool Equals(Object o)
        {
            StrongNameMembershipCondition that = (o as StrongNameMembershipCondition);

            if (that != null)
            {
                if (this.m_publicKeyBlob == null && this.m_element != null)
                {
                    this.ParseKeyBlob();
                }
                if (that.m_publicKeyBlob == null && that.m_element != null)
                {
                    that.ParseKeyBlob();
                }

                if (Equals(this.m_publicKeyBlob, that.m_publicKeyBlob))
                {
                    if (this.m_name == null && this.m_element != null)
                    {
                        this.ParseName();
                    }
                    if (that.m_name == null && that.m_element != null)
                    {
                        that.ParseName();
                    }

                    if (Equals(this.m_name, that.m_name))
                    {
                        if (this.m_version == null && this.m_element != null)
                        {
                            this.ParseVersion();
                        }
                        if (that.m_version == null && that.m_element != null)
                        {
                            that.ParseVersion();
                        }

                        if (Equals(this.m_version, that.m_version))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public override bool Equals(object o)
        {
            StrongNameMembershipCondition condition = o as StrongNameMembershipCondition;

            if (condition != null)
            {
                if ((this.m_publicKeyBlob == null) && (this.m_element != null))
                {
                    this.ParseKeyBlob();
                }
                if ((condition.m_publicKeyBlob == null) && (condition.m_element != null))
                {
                    condition.ParseKeyBlob();
                }
                if (object.Equals(this.m_publicKeyBlob, condition.m_publicKeyBlob))
                {
                    if ((this.m_name == null) && (this.m_element != null))
                    {
                        this.ParseName();
                    }
                    if ((condition.m_name == null) && (condition.m_element != null))
                    {
                        condition.ParseName();
                    }
                    if (object.Equals(this.m_name, condition.m_name))
                    {
                        if ((this.m_version == null) && (this.m_element != null))
                        {
                            this.ParseVersion();
                        }
                        if ((condition.m_version == null) && (condition.m_element != null))
                        {
                            condition.ParseVersion();
                        }
                        if (object.Equals(this.m_version, condition.m_version))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>确定指定对象中的 <see cref="T:System.Security.Policy.StrongName" /> 是否等效于包含在当前 <see cref="T:System.Security.Policy.StrongNameMembershipCondition" /> 中的 <see cref="T:System.Security.Policy.StrongName" />。</summary>
        /// <returns>如果指定对象中的 <see cref="T:System.Security.Policy.StrongName" /> 等效于包含在当前 <see cref="T:System.Security.Policy.StrongNameMembershipCondition" /> 中的 <see cref="T:System.Security.Policy.StrongName" />,则为 true;否则为 false。</returns>
        /// <param name="o">与当前的 <see cref="T:System.Security.Policy.StrongNameMembershipCondition" /> 比较的对象。</param>
        /// <exception cref="T:System.ArgumentException">当前对象或指定对象的 <see cref="P:System.Security.Policy.StrongNameMembershipCondition.PublicKey" /> 属性是 null。</exception>
        public override bool Equals(object o)
        {
            StrongNameMembershipCondition membershipCondition = o as StrongNameMembershipCondition;

            if (membershipCondition != null)
            {
                if (this.m_publicKeyBlob == null && this.m_element != null)
                {
                    this.ParseKeyBlob();
                }
                if (membershipCondition.m_publicKeyBlob == null && membershipCondition.m_element != null)
                {
                    membershipCondition.ParseKeyBlob();
                }
                if (object.Equals((object)this.m_publicKeyBlob, (object)membershipCondition.m_publicKeyBlob))
                {
                    if (this.m_name == null && this.m_element != null)
                    {
                        this.ParseName();
                    }
                    if (membershipCondition.m_name == null && membershipCondition.m_element != null)
                    {
                        membershipCondition.ParseName();
                    }
                    if (object.Equals((object)this.m_name, (object)membershipCondition.m_name))
                    {
                        if (this.m_version == (Version)null && this.m_element != null)
                        {
                            this.ParseVersion();
                        }
                        if (membershipCondition.m_version == (Version)null && membershipCondition.m_element != null)
                        {
                            membershipCondition.ParseVersion();
                        }
                        if (object.Equals((object)this.m_version, (object)membershipCondition.m_version))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
 public void AddFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     if (snMC == null)
     {
         throw new ArgumentNullException("snMC");
     }
     this.CheckLoaded();
     IEnumerator enumerator = this.m_fullTrustAssemblies.GetEnumerator();
     while (enumerator.MoveNext())
     {
         if (((StrongNameMembershipCondition) enumerator.Current).Equals(snMC))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_AssemblyAlreadyFullTrust"));
         }
     }
     lock (this.m_fullTrustAssemblies)
     {
         this.m_fullTrustAssemblies.Add(snMC);
     }
 }
Пример #13
0
        public override bool Equals(object o)
        {
            StrongNameMembershipCondition snmc = (o as StrongNameMembershipCondition);

            if (snmc == null)
            {
                return(false);
            }
            if (!snmc.PublicKey.Equals(PublicKey))
            {
                return(false);
            }
            if (name != snmc.Name)
            {
                return(false);
            }
            if (assemblyVersion != null)
            {
                return(assemblyVersion.Equals(snmc.Version));
            }
            return(snmc.Version == null);
        }
        /// <summary>Determines whether the <see cref="T:System.Security.Policy.StrongName" /> from the specified object is equivalent to the <see cref="T:System.Security.Policy.StrongName" /> contained in the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</summary>
        /// <returns>true if the <see cref="T:System.Security.Policy.StrongName" /> from the specified object is equivalent to the <see cref="T:System.Security.Policy.StrongName" /> contained in the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />; otherwise, false.</returns>
        /// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />. </param>
        /// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.StrongNameMembershipCondition.PublicKey" /> property of the current object or the specified object is null. </exception>
        public override bool Equals(object o)
        {
            StrongNameMembershipCondition strongNameMembershipCondition = o as StrongNameMembershipCondition;

            if (strongNameMembershipCondition == null)
            {
                return(false);
            }
            if (!strongNameMembershipCondition.PublicKey.Equals(this.PublicKey))
            {
                return(false);
            }
            if (this.name != strongNameMembershipCondition.Name)
            {
                return(false);
            }
            if (this.assemblyVersion != null)
            {
                return(this.assemblyVersion.Equals(strongNameMembershipCondition.Version));
            }
            return(strongNameMembershipCondition.Version == null);
        }
Пример #15
0
                public void RemoveFullTrustAssembly (StrongNameMembershipCondition snMC)
                {
                        if (snMC == null)
                                throw new ArgumentNullException ("snMC");

                        if (((IList) full_trust_assemblies).Contains (snMC))
                                ((IList) full_trust_assemblies).Remove (snMC);

                        else
                                throw new ArgumentException (
                                        Locale.GetText ("sn does not have full trust."));
                }
Пример #16
0
 public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     throw new NotImplementedException();
 }
		public void RemoveFullTrustAssembly_UnknownStrongNameMembershipCondition () 
		{
			PolicyLevel pl = Load (minimal, PolicyLevelType.Machine);
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (new StrongNamePublicKeyBlob (snPublicKey), "Second", new Version ("0.1.2.3"));
			pl.RemoveFullTrustAssembly (snmc);
		}
Пример #18
0
 public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
 }
		public void ToXml_Null ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			// no ArgumentNullException here
			SecurityElement se = snmc.ToXml (null);
			Assert.IsNotNull (se, "ToXml(null)");
		}
		public void FromXml_NoClass ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			SecurityElement se = snmc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			snmc.FromXml (w);
			// doesn't even care of the class attribute presence
		}
		public void StrongNameMembershipCondition_NullBlob ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (null, name, version);
		}
Пример #22
0
        public void FromXml(SecurityElement e) {
            if (e == null)
                throw new ArgumentNullException("e");
            Contract.EndContractBlock();

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

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

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

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

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

                m_fullTrustAssemblies = fullTrustAssemblies;

                ArrayList namedPermissionSets = new ArrayList();

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

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

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

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

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

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

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

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

                m_namedPermissionSets = namedPermissionSets;
                m_permSetElement = permSetElement;

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

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

                rootCodeGroup.FromXml(elCodeGroup, this);
                m_rootCodeGroup = rootCodeGroup;
            }
        }
Пример #23
0
        public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC) {
            if (snMC == null)
                throw new ArgumentNullException("snMC");
            Contract.EndContractBlock();

            CheckLoaded();

            Object toRemove = null;
            IEnumerator enumerator = m_fullTrustAssemblies.GetEnumerator();

            while (enumerator.MoveNext()) {
                if (((StrongNameMembershipCondition)enumerator.Current).Equals(snMC)) {
                    toRemove = enumerator.Current;
                    break;
                }
            }

            if (toRemove == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_AssemblyNotFullTrust"));

            lock (m_fullTrustAssemblies) {
                m_fullTrustAssemblies.Remove(toRemove);
            }
        }
Пример #24
0
        private void SetDefaultFullTrustAssemblies() {
            m_fullTrustAssemblies = new ArrayList();

            StrongNamePublicKeyBlob ecmaBlob = new StrongNamePublicKeyBlob(AssemblyRef.EcmaPublicKeyFull);
            for (int index=0; index < EcmaFullTrustAssemblies.Length; index++) {
                StrongNameMembershipCondition sn = new StrongNameMembershipCondition(ecmaBlob,
                                                                                     EcmaFullTrustAssemblies[index],
                                                                                     new Version(ThisAssembly.Version));
                m_fullTrustAssemblies.Add(sn);
            }

            StrongNamePublicKeyBlob microsoftBlob = new StrongNamePublicKeyBlob(AssemblyRef.MicrosoftPublicKeyFull);
            for (int index=0; index < MicrosoftFullTrustAssemblies.Length; index++) {
                StrongNameMembershipCondition sn = new StrongNameMembershipCondition(microsoftBlob,
                                                                                     MicrosoftFullTrustAssemblies[index],
                                                                                     new Version(ThisAssembly.Version));
                m_fullTrustAssemblies.Add(sn);
            }
        }
        public void AddFullTrustAssembly (StrongNameMembershipCondition snMC) {
            Contract.Requires(snMC != null);

        }
Пример #26
0
	public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
			{
				if(snMC == null)
				{
					throw new ArgumentNullException("snMC");
				}
				if(fullTrustAssemblies.Contains(snMC))
				{
					fullTrustAssemblies.Remove(snMC);
				}
				else
				{
					throw new ArgumentException
						(_("Security_FullTrustNotPresent"));
				}
			}
Пример #27
0
        internal PermissionSet GetHomogenousGrantSet(Evidence evidence)
        {
            Contract.Assert(evidence != null);
            Contract.Assert(IsHomogenous);
            Contract.Assert(evidence.GetHostEvidence<GacInstalled>() == null);

            if (_IsFastFullTrustDomain)
            {
                return new PermissionSet(PermissionState.Unrestricted);
            }

            // If the ApplicationTrust's full trust list calls out the assembly, then it is fully trusted
            if (evidence.GetDelayEvaluatedHostEvidence<StrongName>() != null)
            {
                foreach (StrongName fullTrustAssembly in ApplicationTrust.FullTrustAssemblies)
                {
                    StrongNameMembershipCondition sn = new StrongNameMembershipCondition(fullTrustAssembly.PublicKey,
                                                                                         fullTrustAssembly.Name,
                                                                                         fullTrustAssembly.Version);

                    object usedEvidence = null;
                    if ((sn as IReportMatchMembershipCondition).Check(evidence, out usedEvidence))
                    {
                        IDelayEvaluatedEvidence delayEvidence = usedEvidence as IDelayEvaluatedEvidence;
                        if (usedEvidence != null)
                        {
                            delayEvidence.MarkUsed();
                        }

                        return new PermissionSet(PermissionState.Unrestricted);
                    }
                }
            }

            // Otherwise, the grant set is just the default grant set
            return ApplicationTrust.DefaultGrantSet.PermissionSet.Copy();
        }
 public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
 }
		private void Common (StrongNameMembershipCondition snmc)
		{
			Assert.IsFalse (snmc.Check (allEmpty), "Check(allEmpty)");
			Assert.IsFalse (snmc.Check (hostOther), "Check(hostOther)");
			Assert.IsFalse (snmc.Check (assemblyEcmaCorlibVersion), "Check(assemblyEcmaCorlibVersion)");
			Assert.IsFalse (snmc.Check (assemblyEcmaVersion), "Check(assemblyEcmaVersion)");
			Assert.IsFalse (snmc.Check (assemblyMsSystemSecurityVersion), "Check(assemblyMsSystemSecurityVersion)");
			Assert.IsFalse (snmc.Check (assemblyMsVersion), "Check(assemblyMsVersion)");
			Assert.IsFalse (snmc.Check (assemblyOther), "Check(assemblyOther)");

			StrongNameMembershipCondition copy = (StrongNameMembershipCondition)snmc.Copy ();
			Assert.IsTrue (copy.Equals (snmc), "copy.Equals (snmc)");
			Assert.IsTrue (snmc.Equals (copy), "snmc.Equals (copy)");
			copy.Name = null;
			copy.Version = null;
			bool original = ((snmc.Name == null) && (snmc.Version == null));
			Assert.AreEqual (original, copy.Equals (snmc), "bad.Equals (snmc)");
			Assert.AreEqual (original, snmc.Equals (copy), "snmc.Equals (bad)");

			SecurityElement se = snmc.ToXml ();
			copy.FromXml (se);
			Assert.AreEqual (snmc.PublicKey, copy.PublicKey, "PublicKey");
			Assert.AreEqual (snmc.Name, copy.Name, "Name");
			Assert.AreEqual (snmc.Version, copy.Version, "Version");
			Assert.AreEqual (snmc.GetHashCode (), copy.GetHashCode (), "GetHashCode ()");
			Assert.AreEqual (snmc.ToString (), copy.ToString (), "ToString ()");
			Assert.IsTrue (copy.Equals (snmc), "xml.Equals (snmc)");
			Assert.IsTrue (snmc.Equals (copy), "snmc.Equals (xml)");
		}
		public void FromXml_NoVersion ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			SecurityElement se = snmc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			snmc.FromXml (w);
		}
		public void StrongNameMembershipCondition_NullNameVersion ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, null, null);
			Assert.AreEqual (blob, snmc.PublicKey, "PublicKey");
			Assert.IsNull (snmc.Name, "Name");
			Assert.IsNull (snmc.Version, "Version");
			Assert.AreEqual (blob.GetHashCode (), snmc.GetHashCode (), "GetHashCode ()");
			Assert.AreEqual ("StrongName - 00000000000000000400000000000000", snmc.ToString (), "ToString ()");

			Assert.IsTrue (snmc.Check (hostEcmaCorlibVersion), "Check(hostEcmaCorlibVersion)");
			Assert.IsTrue (snmc.Check (hostEcmaVersion), "Check(hostEcmaVersion)");
			Assert.IsFalse (snmc.Check (hostMsSystemSecurityVersion), "Check(hostMsSystemSecurityVersion)");
			Assert.IsFalse (snmc.Check (hostMsVersion), "Check(hostMsVersion)");
			Common (snmc);
		}
		public void ToXml_PolicyLevel ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			SecurityElement se = snmc.ToXml ();
			string s = snmc.ToXml ().ToString ();
			// is it accepted for all policy levels ?
			IEnumerator e = SecurityManager.PolicyHierarchy ();
			while (e.MoveNext ()) {
				PolicyLevel pl = e.Current as PolicyLevel;
				StrongNameMembershipCondition spl = new StrongNameMembershipCondition (blob, name, version);
				spl.FromXml (se, pl);
				Assert.AreEqual (s, spl.ToXml (pl).ToString (), "ToXml(PolicyLevel='" + pl.Label + "')");
			}
			// yes!
		}
 public void FromXml(SecurityElement e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     lock (this)
     {
         Hashtable hashtable;
         ArrayList list = new ArrayList();
         SecurityElement element = e.SearchForChildByTag("SecurityClasses");
         if (element != null)
         {
             hashtable = new Hashtable();
             IEnumerator enumerator = element.Children.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 SecurityElement current = (SecurityElement) enumerator.Current;
                 if (current.Tag.Equals("SecurityClass"))
                 {
                     string key = current.Attribute("Name");
                     string str2 = current.Attribute("Description");
                     if ((key != null) && (str2 != null))
                     {
                         hashtable.Add(key, str2);
                     }
                 }
             }
         }
         else
         {
             hashtable = null;
         }
         SecurityElement element3 = e.SearchForChildByTag("FullTrustAssemblies");
         if ((element3 != null) && (element3.InternalChildren != null))
         {
             string assemblyQualifiedName = typeof(StrongNameMembershipCondition).AssemblyQualifiedName;
             IEnumerator enumerator2 = element3.Children.GetEnumerator();
             while (enumerator2.MoveNext())
             {
                 StrongNameMembershipCondition condition = new StrongNameMembershipCondition();
                 condition.FromXml((SecurityElement) enumerator2.Current);
                 list.Add(condition);
             }
         }
         this.m_fullTrustAssemblies = list;
         ArrayList list2 = new ArrayList();
         SecurityElement elem = e.SearchForChildByTag("NamedPermissionSets");
         SecurityElement element5 = null;
         if ((elem != null) && (elem.InternalChildren != null))
         {
             element5 = this.UnnormalizeClassDeep(elem, hashtable);
             foreach (string str3 in s_reservedNamedPermissionSets)
             {
                 this.FindElement(element5, str3);
             }
         }
         if (element5 == null)
         {
             element5 = new SecurityElement("NamedPermissionSets");
         }
         list2.Add(BuiltInPermissionSets.FullTrust);
         list2.Add(BuiltInPermissionSets.Everything);
         list2.Add(BuiltInPermissionSets.SkipVerification);
         list2.Add(BuiltInPermissionSets.Execution);
         list2.Add(BuiltInPermissionSets.Nothing);
         list2.Add(BuiltInPermissionSets.Internet);
         list2.Add(BuiltInPermissionSets.LocalIntranet);
         foreach (PermissionSet set in list2)
         {
             set.IgnoreTypeLoadFailures = true;
         }
         this.m_namedPermissionSets = list2;
         this.m_permSetElement = element5;
         SecurityElement element6 = e.SearchForChildByTag("CodeGroup");
         if (element6 == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", new object[] { "CodeGroup", base.GetType().FullName }));
         }
         CodeGroup group = XMLUtil.CreateCodeGroup(this.UnnormalizeClassDeep(element6, hashtable));
         if (group == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", new object[] { "CodeGroup", base.GetType().FullName }));
         }
         group.FromXml(element6, this);
         this.m_rootCodeGroup = group;
     }
 }
		public void StrongNameMembershipCondition_MsKey ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (ms, null, null);
			Assert.AreEqual (ms, snmc.PublicKey, "PublicKey");
			Assert.IsNull (snmc.Name, "Name");
			Assert.IsNull (snmc.Version, "Version");
			Assert.AreEqual (ms.GetHashCode (), snmc.GetHashCode (), "GetHashCode ()");

			Assert.IsFalse (snmc.Check (hostEcmaCorlibVersion), "Check(hostEcmaCorlibVersion)");
			Assert.IsFalse (snmc.Check (hostEcmaVersion), "Check(hostEcmaVersion)");
			Assert.IsTrue (snmc.Check (hostMsSystemSecurityVersion), "Check(hostMsSystemSecurityVersion)");
			Assert.IsTrue (snmc.Check (hostMsVersion), "Check(hostMsVersion)");
			Common (snmc);
		}
		public void PublicKey_Null ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			snmc.PublicKey = null;
		}
 private void SetDefaultFullTrustAssemblies()
 {
     this.m_fullTrustAssemblies = new ArrayList();
     StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob("00000000000000000400000000000000");
     for (int i = 0; i < EcmaFullTrustAssemblies.Length; i++)
     {
         StrongNameMembershipCondition condition = new StrongNameMembershipCondition(blob, EcmaFullTrustAssemblies[i], new Version("4.0.0.0"));
         this.m_fullTrustAssemblies.Add(condition);
     }
     StrongNamePublicKeyBlob blob2 = new StrongNamePublicKeyBlob("002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293");
     for (int j = 0; j < MicrosoftFullTrustAssemblies.Length; j++)
     {
         StrongNameMembershipCondition condition2 = new StrongNameMembershipCondition(blob2, MicrosoftFullTrustAssemblies[j], new Version("4.0.0.0"));
         this.m_fullTrustAssemblies.Add(condition2);
     }
 }
		public void Version_Null ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			snmc.Version = null;
		}
Пример #38
0
		internal bool IsFullTrustAssembly (Assembly a)
		{
			AssemblyName an = a.UnprotectedGetName ();
			StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob (an.GetPublicKey ());
			StrongNameMembershipCondition snMC = new StrongNameMembershipCondition (snpkb, an.Name, an.Version);
			foreach (StrongNameMembershipCondition sn in full_trust_assemblies) {
				if (sn.Equals (snMC)) {
					return true;
				}
			}
			return false;
		}
		public void FromXml_Null ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			snmc.FromXml (null);
		}
Пример #40
0
                public void RemoveFullTrustAssembly (StrongName sn)
                {
			if (sn == null)
				throw new ArgumentNullException ("sn");

			StrongNameMembershipCondition s = new StrongNameMembershipCondition (sn.PublicKey, sn.Name, sn.Version);
                        RemoveFullTrustAssembly (s);
                }
		public void FromXml_InvalidTag ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			SecurityElement se = snmc.ToXml ();
			se.Tag = "IMonoship";
			snmc.FromXml (se);
		}
 public void AddFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     Contract.Requires(snMC != null);
 }
		public void FromXml_InvalidClass ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			SecurityElement se = snmc.ToXml ();
			se.Attributes ["class"] = "Hello world";
			snmc.FromXml (se);
		}
		public void StrongNameMembershipCondition_Mscorlib ()
		{
			StrongNameMembershipCondition snmc = new StrongNameMembershipCondition (blob, name, version);
			Assert.AreEqual (blob, snmc.PublicKey, "PublicKey");
			Assert.AreEqual ("mscorlib", snmc.Name, "Name");
			Assert.AreEqual (version, snmc.Version, "Version");
			Assert.AreEqual (blob.GetHashCode (), snmc.GetHashCode (), "GetHashCode ()");
			Assert.IsTrue (snmc.ToString ().StartsWith ("StrongName - 00000000000000000400000000000000 name = mscorlib version = "), "ToString ()");

			Assert.IsTrue (snmc.Check (hostEcmaCorlibVersion), "Check(hostEcmaCorlibVersion)");
			Assert.IsFalse (snmc.Check (hostEcmaVersion), "Check(hostEcmaVersion)");
			Assert.IsFalse (snmc.Check (hostMsSystemSecurityVersion), "Check(hostMsSystemSecurityVersion)");
			Assert.IsFalse (snmc.Check (hostMsVersion), "Check(hostMsVersion)");
			Common (snmc);
		}
 public void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
 {
     if (snMC == null)
     {
         throw new ArgumentNullException("snMC");
     }
     this.CheckLoaded();
     object current = null;
     IEnumerator enumerator = this.m_fullTrustAssemblies.GetEnumerator();
     while (enumerator.MoveNext())
     {
         if (((StrongNameMembershipCondition) enumerator.Current).Equals(snMC))
         {
             current = enumerator.Current;
             break;
         }
     }
     if (current == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_AssemblyNotFullTrust"));
     }
     lock (this.m_fullTrustAssemblies)
     {
         this.m_fullTrustAssemblies.Remove(current);
     }
 }