Example #1
0
        public static StrongNameMembershipCondition FullTrustMembership(string name, Key key)
        {
            StrongNamePublicKeyBlob snkb = null;

            switch (key)
            {
            case Key.Ecma:
                if (_ecma == null)
                {
                    _ecma = new StrongNamePublicKeyBlob(_ecmaKey);
                }
                snkb = _ecma;
                break;

            case Key.MsFinal:
                if (_msFinal == null)
                {
                    _msFinal = new StrongNamePublicKeyBlob(_msFinalKey);
                }
                snkb = _msFinal;
                break;
            }

            if (_fxVersion == null)
            {
                _fxVersion = new Version(Consts.FxVersion);
            }

            return(new StrongNameMembershipCondition(snkb, name, _fxVersion));
        }
Example #2
0
        public void FixtureSetUp()
        {
            wrongEvidence = new Site("test");
            allEmpty      = new Evidence();

            AssemblyName an = typeof(int).Assembly.GetName();

            name    = an.Name;
            version = an.Version;
            blob    = new StrongNamePublicKeyBlob(an.GetPublicKey());

            ms = new StrongNamePublicKeyBlob(_msFinalKey);

            hostEcmaCorlibVersion       = CreateHostEvidence(new StrongName(blob, name, version));
            hostEcmaVersion             = CreateHostEvidence(new StrongName(blob, " ", version));
            hostMsSystemSecurityVersion = CreateHostEvidence(new StrongName(ms, "System.Security", version));
            hostMsVersion = CreateHostEvidence(new StrongName(ms, " ", version));
            hostOther     = CreateHostEvidence(wrongEvidence);

            assemblyEcmaCorlibVersion       = CreateAssemblyEvidence(new StrongName(blob, name, version));
            assemblyEcmaVersion             = CreateAssemblyEvidence(new StrongName(blob, " ", version));
            assemblyMsSystemSecurityVersion = CreateAssemblyEvidence(new StrongName(ms, "System.Security", version));
            assemblyMsVersion = CreateAssemblyEvidence(new StrongName(ms, " ", version));
            assemblyOther     = CreateAssemblyEvidence(wrongEvidence);
        }
        /// <summary>
        /// Gets the name of the strong.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static System.Security.Policy.StrongName GetStrongName(Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            AssemblyName assemblyName = assembly.GetName();

            // get the public key blob
            byte[] publicKey = assemblyName.GetPublicKey();
            if (publicKey == null || publicKey.Length == 0)
            {
                throw new InvalidOperationException(
                          String.Format("{0} is not strongly named",
                                        assembly));
            }

            StrongNamePublicKeyBlob keyBlob =
                new StrongNamePublicKeyBlob(publicKey);

            // create the StrongName
            return(new System.Security.Policy.StrongName(
                       keyBlob, assemblyName.Name, assemblyName.Version));
        }
Example #4
0
 public static void StrongNamePublicKeyBlobTests()
 {
     StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(new byte[1]);
     bool   testbool   = snpkb.Equals(new object());
     int    hash       = snpkb.GetHashCode();
     string teststring = snpkb.ToString();
 }
Example #5
0
        public void Intersect()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            StrongNameIdentityPermission intersect = (StrongNameIdentityPermission)snip.Intersect(null);

            Assert.IsNull(intersect, "snip N null");

            StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None);

            intersect = (StrongNameIdentityPermission)snip.Intersect(empty);
#if NET_2_0
            Assert.IsNull(intersect, "snip N empty");
#else
            Compare(empty, intersect, "snip U empty");
#endif
            intersect = (StrongNameIdentityPermission)snip.Intersect(snip);
            Compare(snip, intersect, "snip U snip");

            StrongNameIdentityPermission samePk = new StrongNameIdentityPermission(blob, "novell", new Version(1, 2));
            intersect = (StrongNameIdentityPermission)snip.Intersect(samePk);
            Assert.IsNull(intersect, "(snip N samePk)");
            // strange, I would have expected a SNIP with the same public key...
        }
Example #6
0
        public void InvalidPublicKey()
        {
            StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(bad);

            // Proof that there's no validation on public key
            Assert.AreEqual("0BAD", snpkb.ToString(), "ToString(BAD)");
        }
Example #7
0
        public void PublicKey_Null()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            snip.PublicKey = null;
        }
Example #8
0
        public void PublicKey()
        {
            StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(pk);

            Assert.IsTrue(snpkb.Equals(snpkb), "Equals(Self)");
            Assert.IsFalse(snpkb.Equals(null), "Equals(null)");
            Assert.AreEqual("00240000048000009400000006020000002400005253413100040000010001003DBD7208C62B0EA8C1C058072B635F7C9ABDCB22DB20B2A9DADAEFE800642F5D8DEB7802F7A5367728D7558D1468DBEB2409D02B131B926E2E59544AAC18CFC909023F4FA83E94001FC2F11A27477D1084F514B861621A0C66ABD24C4B9FC90F3CD8920FF5FFCED76E5C6FB1F57DD356F96727A4A5485B079344004AF8FFA4CB", snpkb.ToString(), "ToString(pk)");

            StrongNamePublicKeyBlob snpkb2 = new StrongNamePublicKeyBlob(pk);

            Assert.IsTrue(snpkb.Equals(snpkb2), "Equals()-true");
            StrongNamePublicKeyBlob snpkb3 = new StrongNamePublicKeyBlob(bad);

            Assert.IsFalse(snpkb.Equals(snpkb3), "Equals()-false");

            // non standard get hash code - why ???
            Assert.AreEqual(snpkb2.GetHashCode(), snpkb.GetHashCode(), "GetHashCode-0");
#if NET_2_0
            // the first 4 bytes has code has been fixed in 2.0 beta 1
#elif NET_1_1
            // It seems to be the first four bytes of the public key data
            // which seems like non sense as all valid public key will have the same header ?
            Assert.AreEqual(2359296, snpkb.GetHashCode(), "GetHashCode-1");
            Assert.AreEqual(2359296, snpkb2.GetHashCode(), "GetHashCode-2");
            Assert.AreEqual(2989, snpkb3.GetHashCode(), "GetHashCode-3");
            byte[] header = { 0x00, 0x24, 0x00, 0x00 };
            StrongNamePublicKeyBlob snpkb4 = new StrongNamePublicKeyBlob(header);
            Assert.AreEqual(2359296, snpkb4.GetHashCode(), "GetHashCode-4");
#endif
        }
        internal void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (string.Compare(element.Tag, "StrongName", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            this.m_publicKeyBlob = null;
            this.m_version       = null;
            string hexString = element.Attribute("Key");

            if (hexString != null)
            {
                this.m_publicKeyBlob = new StrongNamePublicKeyBlob(Hex.DecodeHexString(hexString));
            }
            this.m_name = element.Attribute("Name");
            string version = element.Attribute("Version");

            if (version != null)
            {
                this.m_version = new System.Version(version);
            }
        }
        internal void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (String.Compare(element.Tag, "StrongName", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            Contract.EndContractBlock();

            m_publicKeyBlob = null;
            m_version       = null;

            string key = element.Attribute("Key");

            if (key != null)
            {
                m_publicKeyBlob = new StrongNamePublicKeyBlob(System.Security.Util.Hex.DecodeHexString(key));
            }

            m_name = element.Attribute("Name");

            string version = element.Attribute("Version");

            if (version != null)
            {
                m_version = new Version(version);
            }
        }
        // Implement the ISecurityPolicyEncodable interface.
        public void FromXml(SecurityElement et, PolicyLevel level)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (et.Tag != "IMembershipCondition")
            {
                throw new ArgumentException(_("Security_PolicyName"));
            }
            if (et.Attribute("version") != "1")
            {
                throw new ArgumentException(_("Security_PolicyVersion"));
            }
            String value = et.Attribute("PublicKey");

            if (value != null)
            {
                blob = new StrongNamePublicKeyBlob(value);
            }
            else
            {
                throw new ArgumentException(_("Arg_PublicKeyBlob"));
            }
            name  = et.Attribute("Name");
            value = et.Attribute("AssemblyVersion");
            if (value != null)
            {
                version = new Version(value);
            }
            else
            {
                version = null;
            }
        }
        internal StrongName(StrongNamePublicKeyBlob blob, string name, System.Version version, Assembly assembly)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
            }
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }
            RuntimeAssembly assembly2 = assembly as RuntimeAssembly;

            if ((assembly != null) && (assembly2 == null))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly");
            }
            this.m_publicKeyBlob = blob;
            this.m_name          = name;
            this.m_version       = version;
            this.m_assembly      = assembly2;
        }
Example #13
0
        /// <internalonly/>
        int IBuiltInEvidence.InitFromBuffer(char[] buffer, int position)
        {
            int length = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);

            position                 += 2;
            m_publicKeyBlob           = new StrongNamePublicKeyBlob();
            m_publicKeyBlob.PublicKey = new byte[length];

            int lengthInChars = ((length - 1) / 2) + 1;

            Buffer.InternalBlockCopy(buffer, position * 2, m_publicKeyBlob.PublicKey, 0, length);
            position += lengthInChars;

            int major    = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);
            int minor    = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position + 2);
            int build    = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position + 4);
            int revision = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position + 6);

            m_version = new Version(major, minor, build, revision);
            position += 8;

            length    = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);
            position += 2;

            m_name = new String(buffer, position, length);

            return(position + length);
        }
        public static StrongNameMembershipCondition FullTrustMembership(string name, DefaultPolicies.Key key)
        {
            StrongNamePublicKeyBlob blob = null;

            if (key != DefaultPolicies.Key.Ecma)
            {
                if (key == DefaultPolicies.Key.MsFinal)
                {
                    if (DefaultPolicies._msFinal == null)
                    {
                        DefaultPolicies._msFinal = new StrongNamePublicKeyBlob(DefaultPolicies._msFinalKey);
                    }
                    blob = DefaultPolicies._msFinal;
                }
            }
            else
            {
                if (DefaultPolicies._ecma == null)
                {
                    DefaultPolicies._ecma = new StrongNamePublicKeyBlob(DefaultPolicies._ecmaKey);
                }
                blob = DefaultPolicies._ecma;
            }
            if (DefaultPolicies._fxVersion == null)
            {
                DefaultPolicies._fxVersion = new Version("2.0.0.0");
            }
            return(new StrongNameMembershipCondition(blob, name, DefaultPolicies._fxVersion));
        }
Example #15
0
        internal static StrongName CreateStrongName(Assembly assembly)
        {
            System.Diagnostics.Contracts.Contract.Requires(assembly != null);

            // Since there is no managed API for finding the GAC path, I
            // assert path discovery for all local files.
            FileIOPermission permission = new FileIOPermission(PermissionState.None);

            permission.AllLocalFiles = FileIOPermissionAccess.PathDiscovery;
            permission.Assert();
            AssemblyName assemblyName = assembly.GetName();

            CodeAccessPermission.RevertAssert();

            // get the public key blob
            byte[] publicKey = assemblyName.GetPublicKey();
            if (publicKey == null || publicKey.Length == 0)
            {
                throw new InvalidOperationException(Res.NoStrongName);
            }

            StrongNamePublicKeyBlob keyBlob = new StrongNamePublicKeyBlob(publicKey);

            // and create the StrongName
            return(new StrongName(keyBlob, assemblyName.Name, assemblyName.Version));
        }
Example #16
0
        public StrongName(StrongNamePublicKeyBlob blob, String name, Version version)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Equals(""))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
            }

            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            m_publicKeyBlob = blob;
            m_name          = name;
            m_version       = version;
        }
Example #17
0
        public void Name_Empty()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            snip.Name = String.Empty;
        }
        internal StrongName(StrongNamePublicKeyBlob blob, String name, Version version, Assembly assembly)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
            }

            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            if (version == null)
            {
                throw new ArgumentNullException("version");
            }
            Contract.EndContractBlock();

            RuntimeAssembly rtAssembly = assembly as RuntimeAssembly;

            if (assembly != null && rtAssembly == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly");
            }

            m_publicKeyBlob = blob;
            m_name          = name;
            m_version       = version;
            m_assembly      = rtAssembly;
        }
Example #19
0
        public void Union()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            StrongNameIdentityPermission union = (StrongNameIdentityPermission)snip.Union(null);

            Compare(snip, union, "snip U null");

            StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None);

            union = (StrongNameIdentityPermission)snip.Union(empty);
            Compare(snip, union, "snip U empty");

            union = (StrongNameIdentityPermission)snip.Union(snip);
            Compare(snip, union, "snip U snip");

            // note: can't be tested with PermissionState.Unrestricted

            StrongNameIdentityPermission samePk = new StrongNameIdentityPermission(blob, null, null);

            union = (StrongNameIdentityPermission)snip.Union(samePk);
#if !NET_2_0
            // can't compare the properties with multiple entries
            Compare(snip, union, "snip U samePk");
#endif
            Assert.IsTrue(snip.IsSubsetOf(union), "snip.IsSubsetOf (union)");

            union = (StrongNameIdentityPermission)samePk.Union(snip);
#if !NET_2_0
            // can't compare the properties with multiple entries
            Compare(snip, union, "samePk U snip");
#endif
            Assert.IsTrue(samePk.IsSubsetOf(union), "snip.IsSubsetOf (union)");
        }
Example #20
0
        static internal Evidence GetDefaultHostEvidence(Assembly a)
        {
            Evidence e     = new Evidence();
            string   aname = a.EscapedCodeBase;

            // 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 (String.Compare("FILE://", 0, aname, 0, 7, true, CultureInfo.InvariantCulture) != 0)
            {
                e.AddHost(Site.CreateFromUrl(aname));
            }

            // strongnamed assemblies gets a StrongName evidence
            AssemblyName an = a.GetName();

            byte[] pk = an.GetPublicKey();
            if ((pk != null) && (pk.Length > 0))
            {
                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
                e.AddHost(new StrongName(blob, an.Name, an.Version));
            }

            // Authenticode(r) signed assemblies get a Publisher evidence
            if (IsAuthenticodePresent(a))
            {
                try {
                    X509Certificate x509 = X509Certificate.CreateFromSignedFile(a.Location);
                    e.AddHost(new Publisher(x509));
                }
                catch (CryptographicException) {
                }
            }

            // assemblies loaded from the GAC also get a Gac evidence (new in Fx 2.0)
            if (a.GlobalAssemblyCache)
            {
                e.AddHost(new GacInstalled());
            }

            // the current HostSecurityManager may add/remove some evidence
            AppDomainManager dommgr = AppDomain.CurrentDomain.DomainManager;

            if (dommgr != null)
            {
                if ((dommgr.HostSecurityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) ==
                    HostSecurityManagerOptions.HostAssemblyEvidence)
                {
                    e = dommgr.HostSecurityManager.ProvideAssemblyEvidence(a, e);
                }
            }

            return(e);
        }
        public static StrongName StrongnameFromType(Type type)
        {
            Assembly assembly = type.Assembly;
            string   name     = type.Name;
            Version  version  = assembly.GetName().Version;
            StrongNamePublicKeyBlob strongName = new StrongNamePublicKeyBlob(assembly.GetName().GetPublicKey());

            return(new StrongName(strongName, name, version));
        }
Example #22
0
        private StrongNameIdentityPermission GetUnion()
        {
            StrongNamePublicKeyBlob      blob   = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip   = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));
            StrongNamePublicKeyBlob      blob2  = new StrongNamePublicKeyBlob(new byte[16]);
            StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission(blob2, "mono", new Version(1, 2, 3, 4));

            return((StrongNameIdentityPermission)snip.Union(diffPk));
        }
Example #23
0
        /// <summary>
        /// Get the StrongName of the given assembly.
        /// </summary>
        /// <param name="ass"></param>
        /// <returns></returns>
        public static StrongName FromAssembly(Assembly ass)
        {
            var name = ass.GetName();

            byte[] pk   = name.GetPublicKey();
            var    blob = new StrongNamePublicKeyBlob(pk);

            return(new StrongName(blob, name.Name, name.Version));
        }
        public void StrongName_GetRequiredSize()
        {
            byte[] pk = { 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD, 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B, 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9, 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78, 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68, 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E, 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F, 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D, 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB, 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5, 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56, 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00, 0x4A, 0xF8, 0xFF, 0xA4, 0xCB };
            StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(pk);
            StrongName sn = new StrongName(snpkb, "mono", new Version());

            Assert.AreEqual(97, GetRequiredSize(sn, true), "GetRequiredSize-true");
            Assert.AreEqual(93, GetRequiredSize(sn, false), "GetRequiredSize-false");
        }
Example #25
0
        private StrongName GetStrongName(Type type)
        {
            AssemblyName aname = type.Assembly.GetName();

            byte[] pubkey = aname.GetPublicKey();
            var    blob   = new StrongNamePublicKeyBlob(pubkey);

            return(new StrongName(blob, aname.Name, aname.Version));
        }
Example #26
0
        public override String ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("Hash - ");
            builder.Append(hashAlg.GetType().AssemblyQualifiedName);
            builder.Append(" = ");
            builder.Append(StrongNamePublicKeyBlob.ToHex(value));
            return(builder.ToString());
        }
Example #27
0
        public void Name_Empty()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            snip.Name = String.Empty;
#if !NET_2_0
            Assert.AreEqual(String.Empty, snip.Name, "Name");
#endif
        }
Example #28
0
        public void Version()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            Assert.AreEqual("1.2.3.4", snip.Version.ToString(), "Version-1");
            snip.Version = null;
            Assert.IsNull(snip.Version, "Version-2");
            snip.Version = new Version(1, 2, 3);
            Assert.AreEqual("1.2.3", snip.Version.ToString(), "Version-3");
        }
Example #29
0
        public void IsSubsetOf()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            Assert.IsFalse(snip.IsSubsetOf(null), "snip.IsSubsetOf (null)");

            StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None);

            Assert.IsTrue(empty.IsSubsetOf(null), "empty.IsSubsetOf (null)");
        }
 public StrongNameMembershipCondition
     (StrongNamePublicKeyBlob blob, String name, Version version)
 {
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     this.blob    = blob;
     this.name    = name;
     this.version = version;
 }
 public StrongNameIdentityPermission(StrongNamePublicKeyBlob blob, string name, Version version)
 {
 }
Example #32
0
    // Create new code groups using the custom named permission sets previously created. 
    private static void CreateCodeGroups()
    {
        // Create instances of the named permission sets created earlier to establish the 
        // permissions for the new code groups.
        NamedPermissionSet companyCodeSet = new NamedPermissionSet("MyCompany",PermissionState.Unrestricted);
        NamedPermissionSet departmentCodeSet = new NamedPermissionSet("MyDepartment",PermissionState.Unrestricted);
        // Create new code groups using the named permission sets.
        PolicyStatement policyMyCompany = new PolicyStatement(companyCodeSet,PolicyStatementAttribute.LevelFinal);
        PolicyStatement policyMyDepartment = new PolicyStatement(departmentCodeSet,PolicyStatementAttribute.Exclusive);
        // Create new code groups using UnionCodeGroup.
        CodeGroup myCompanyZone = new UnionCodeGroup(new ZoneMembershipCondition(SecurityZone.Intranet), policyMyCompany);
        myCompanyZone.Name = "MyCompanyCodeGroup";

        byte[] b1 = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 230, 152, 218, 8, 206, 206, 170,84, 111, 145, 26, 208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180};
        StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);

        CodeGroup myDepartmentZone = new UnionCodeGroup(new StrongNameMembershipCondition(blob, null, null), policyMyDepartment);
        myDepartmentZone.Name = "MyDepartmentCodeGroup";

        // Move through the policy levels looking for the Machine policy level. 
        // Create two new code groups at that level.
        IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
        while(policyEnumerator.MoveNext())
        {
            // At the Machine level delete already existing copies of the custom code groups, 
            // then create the new code groups.
            PolicyLevel currentLevel = (PolicyLevel)policyEnumerator.Current;
            if (currentLevel.Label == "Machine")
            {

                // Remove old instances of the custom groups.
                DeleteCustomCodeGroups();
                // Add the new code groups. 
                //******************************************************* 
                // To add a child code group, add the child to the parent prior to adding 
                // the parent to the root.
                myCompanyZone.AddChild(myDepartmentZone);
                // Add the parent to the root code group.
                currentLevel.RootCodeGroup.AddChild(myCompanyZone);
                SecurityManager.SavePolicy();
            }
        }
        // Save the security policy.
        SecurityManager.SavePolicy();
        Console.WriteLine("Security policy modified.");
        Console.WriteLine("New code groups added at the Machine policy level.");
    }
Example #33
0
 public static void StrongNamePublicKeyBlobTests()
 {
     StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(new byte[1]);
     bool testbool = snpkb.Equals(new object());
     int hash = snpkb.GetHashCode();
     string teststring = snpkb.ToString();
 }