2004-08-08 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Sun, 8 Aug 2004 14:41:52 +0000 (14:41 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Sun, 8 Aug 2004 14:41:52 +0000 (14:41 -0000)
* Evidence.cs: Added new static internal method to create default
host evidences for an assembly.
* FileCodeGroup.cs: Added incomplete (no children) policy resolution
in order to load more complex policies.
* Hash.cs: Added ISerialization support (required for cross-domain
evidence support, like nunit).
* NetCodeGroup.cs: Added incomplete (no children) policy resolution in
order to load more complex policies.

svn path=/trunk/mcs/; revision=32040

mcs/class/corlib/System.Security.Policy/ChangeLog
mcs/class/corlib/System.Security.Policy/Evidence.cs
mcs/class/corlib/System.Security.Policy/FileCodeGroup.cs
mcs/class/corlib/System.Security.Policy/Hash.cs
mcs/class/corlib/System.Security.Policy/NetCodeGroup.cs

index 35b73aea3971d65e6cc87d365f7bab9e16c41769..b3041528ff48f87dbf059d527378415728a9a039 100644 (file)
@@ -1,3 +1,14 @@
+2004-08-08  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Evidence.cs: Added new static internal method to create default
+       host evidences for an assembly.
+       * FileCodeGroup.cs: Added incomplete (no children) policy resolution 
+       in order to load more complex policies.
+       * Hash.cs: Added ISerialization support (required for cross-domain 
+       evidence support, like nunit).
+       * NetCodeGroup.cs: Added incomplete (no children) policy resolution in
+       order to load more complex policies.
+
 2004-08-04  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Gac.cs: New. Implemented Gac evidence for NET_2_0.
index 87ab55bde93a6e2b441d2b363e694c55b6c0848f..278b6b4d207b2161900a22effe131d9aea1b1824 100644 (file)
@@ -33,7 +33,9 @@
 
 using System;
 using System.Collections;
+using System.Reflection;
 using System.Security.Permissions;
+using System.Security.Cryptography.X509Certificates;
 
 namespace System.Security.Policy {
 
@@ -236,6 +238,60 @@ namespace System.Security.Policy {
                        }
                }
 #endif
+
+               // this avoid us to build all evidences from the runtime
+               // (i.e. multiple unmanaged->managed calls) and also allows
+               // to delay their creation until (if) needed
+               static internal Evidence GetDefaultHostEvidence (Assembly a) 
+               {
+                       Evidence e = new Evidence ();
+                       string aname = a.CodeBase;
+
+                       // by default all assembly have the Zone, Url and Hash evidences
+                       e.AddHost (Zone.CreateFromUrl (aname));
+                       e.AddHost (new Url (aname));
+                       e.AddHost (new Hash (a));
+
+                       // non local files (e.g. http://) also get a Site evidence
+                       if (!aname.ToUpper ().StartsWith ("FILE://")) {
+                               e.AddHost (Site.CreateFromUrl (aname));
+                       }
+
+                       // strongnamed assemblies gets a StrongName evidence
+                       AssemblyName an = a.GetName ();
+                       byte[] pk = an.GetPublicKey ();
+                       if (pk != null) {
+                               StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (pk);
+                               e.AddHost (new StrongName (blob, an.Name, an.Version));
+                       }
+
+                       // Authenticode(r) signed assemblies get a Publisher evidence
+                       try {
+                               X509Certificate x509 = X509Certificate.CreateFromSignedFile (a.Location);
+                               if (x509.GetHashCode () != 0) {
+                                       e.AddHost (new Publisher (x509));
+                               }
+                       }
+                       catch (ArgumentException) {
+                               // URI are not supported
+                       }
+#if NET_2_0
+                       // assemblies loaded from the GAC also get a Gac evidence (new in Fx 2.0)
+                       if (a.GlobalAssemblyCache) {
+                               e.AddHost (new Gac ());
+                       }
+/*
+                       // the current HostSecurityManager may add/remove some evidence
+                       AppDomainManager dommgr = AppDomain.CurrentDomain.DomainManager;
+                       if (dommgr != null) {
+                               if ((dommgr.HostSecurityManager.Flags & HostSecurityManagerFlags.HostAssemblyEvidence) ==
+                                       HostSecurityManagerFlags.HostAssemblyEvidence) {
+                                       e = dommgr.HostSecurityManager.ProvideAssemblyEvidence (a, e);
+                               }
+                       }*/
+#endif
+                       return e;
+               }
        
                private class EvidenceEnumerator : IEnumerator {
                        
index 17a93fcbcafbac99f3995380986e2f12aba0d762..241d5eb0e719adc190e8b68d8cebbb0444a69663 100644 (file)
@@ -69,7 +69,7 @@ namespace System.Security.Policy {
                        get { return "Union";}
                }
 
-               [MonoTODO]
+                [MonoTODO ("no children processing")]
                public override PolicyStatement Resolve (Evidence evidence)
                {
                        if (null == evidence)
@@ -81,13 +81,16 @@ namespace System.Security.Policy {
                        if (!MembershipCondition.Check(evidence))
                                return null;
 
-                       IEnumerator hostEnumerator = evidence.GetHostEnumerator();
-                       while (hostEnumerator.MoveNext())
-                       {
-                               // FIXME: not sure what to do here
-                               //  How do we check the URL and make a PolicyStatement?
+                       PolicyStatement pst = this.PolicyStatement.Copy ();
+                       if (this.Children.Count > 0) {
+                               foreach (CodeGroup cg in this.Children) {
+                                       PolicyStatement child = cg.Resolve (evidence);
+                                       if (child != null) {
+                                               // TODO union
+                                       }
+                               }
                        }
-                       throw new NotImplementedException();
+                       return pst;
                }
 
                public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
@@ -95,7 +98,7 @@ namespace System.Security.Policy {
                        if (null == evidence)
                                throw new ArgumentNullException("evidence");
 
-                       if (!MembershipCondition.Check(evidence))
+                       if (!MembershipCondition.Check (evidence))
                                return null;
 
                        FileCodeGroup matchRoot = new FileCodeGroup(MembershipCondition, m_access);
index d534366c6ccb85ffb8057a9759d951b734eda904..6cf3ab9f31f55042046f3f1cd9f201e28d0f4f02 100644 (file)
@@ -55,11 +55,14 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                this.assembly = assembly;
        }
 
-#if NET_2_0
        internal Hash () 
        {
        }
-#endif
+
+       internal Hash (SerializationInfo info, StreamingContext context)
+       {
+               data = (byte[]) info.GetValue ("RawData", typeof (byte[]));
+       }
 
        //
        // Public Properties
@@ -98,12 +101,11 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                return hashAlg.ComputeHash (GetData ());
        }
 
-       [MonoTODO]
        public void GetObjectData (SerializationInfo info, StreamingContext context) 
        {
                if (info == null)
                        throw new ArgumentNullException ("info");
-               throw new NotImplementedException ();
+               info.AddValue ("RawData", GetData ());
        }
 
        [MonoTODO("The Raw data seems to be different than the raw data I have")]
@@ -143,10 +145,9 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
 
        // interface IBuiltInEvidence
 
-       [MonoTODO]
        int IBuiltInEvidence.GetRequiredSize (bool verbose) 
        {
-               return 0;
+               return (verbose ? 5 : 0);       // as documented
        }
 
        [MonoTODO]
index 70877859f2222ce429b9483b7870765bd5701838..933117b2d3ae71c0eca3d4e85c7631d5c9c1c349 100644 (file)
@@ -193,13 +193,25 @@ namespace System.Security.Policy {
                }
 #endif
 
-               [MonoTODO]
+                [MonoTODO ("no children processing")]
                public override PolicyStatement Resolve (Evidence evidence)
                {
                        if (evidence == null) 
                                throw new ArgumentNullException ("evidence");
 
-                       throw new NotImplementedException ();
+                       if (!MembershipCondition.Check (evidence))
+                               return null;
+
+                       PolicyStatement pst = this.PolicyStatement.Copy ();
+                       if (this.Children.Count > 0) {
+                               foreach (CodeGroup cg in this.Children) {
+                                       PolicyStatement child = cg.Resolve (evidence);
+                                       if (child != null) {
+                                               // TODO union
+                                       }
+                               }
+                       }
+                       return pst;
                }
 
 #if NET_2_0
@@ -212,7 +224,7 @@ namespace System.Security.Policy {
                public override CodeGroup ResolveMatchingCodeGroups (Evidence evidence) 
                {
                        if (evidence == null)
-                               throw new ArgumentNullException ();
+                               throw new ArgumentNullException ("evidence");
                        
                        CodeGroup return_group = null;
                        if (MembershipCondition.Check (evidence)) {