Ejemplo n.º 1
0
        private static Evidence CreateSecurityIdentity(SafePEFileHandle peFile, Evidence hostProvidedEvidence)
        {
            Evidence evidence = new Evidence((IRuntimeEvidenceFactory) new PEFileEvidenceFactory(peFile));

            if (hostProvidedEvidence != null)
            {
                evidence.MergeWithNoDuplicates(hostProvidedEvidence);
            }
            return(evidence);
        }
 private static Evidence CreateSecurityIdentity(SafePEFileHandle peFile, Evidence hostProvidedEvidence)
 {
     PEFileEvidenceFactory target = new PEFileEvidenceFactory(peFile);
     Evidence evidence = new Evidence(target);
     if (hostProvidedEvidence != null)
     {
         evidence.MergeWithNoDuplicates(hostProvidedEvidence);
     }
     return evidence;
 }
Ejemplo n.º 3
0
        private static Evidence CreateSecurityIdentity(SafePEFileHandle peFile,
                                                       Evidence hostProvidedEvidence)
        {
            PEFileEvidenceFactory evidenceFactory = new PEFileEvidenceFactory(peFile);
            Evidence evidence = new Evidence(evidenceFactory);

            // If the host (caller of Assembly.Load) provided evidence, merge it with the evidence we've just
            // created. The host evidence takes priority.
            if (hostProvidedEvidence != null)
            {
                evidence.MergeWithNoDuplicates(hostProvidedEvidence);
            }

            return(evidence);
        }
        private static Evidence CreateSecurityIdentity(SafePEFileHandle peFile,
                                                       Evidence hostProvidedEvidence)
        {

            PEFileEvidenceFactory evidenceFactory = new PEFileEvidenceFactory(peFile);
            Evidence evidence = new Evidence(evidenceFactory);

            // If the host (caller of Assembly.Load) provided evidence, merge it with the evidence we've just
            // created. The host evidence takes priority.
            if (hostProvidedEvidence != null)
            {
                evidence.MergeWithNoDuplicates(hostProvidedEvidence);
            }

            return evidence;
        }
Ejemplo n.º 5
0
        private Evidence CreateSecurityIdentity(String url,
                                                byte[] uniqueID,
                                                int zone,
                                                byte[] cert,
                                                byte[] serializedEvidence,
                                                Evidence additionalEvidence)
        {
            Evidence evidence = new Evidence();

            if (zone != -1)
                evidence.AddHost( new Zone((SecurityZone)zone) );
            if (url != null)
            {
                evidence.AddHost( new Url(url, true) );

                // Only create a site piece of evidence if we are not loading from a file.
                if (String.Compare( url, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) != 0)
                    evidence.AddHost( Site.CreateFromUrl( url ) );
            }


            // This code was moved to a different function because:
            // 1) it is rarely called so we should only JIT it if we need it.
            // 2) it references lots of classes that otherwise aren't loaded.
            if (serializedEvidence != null)
                DecodeSerializedEvidence( evidence, serializedEvidence );

            byte[] blob = nGetPublicKey();

            if ((blob != null) &&
                (blob.Length != 0))
                AddStrongName( evidence, blob );
            // If the host (caller of Assembly.Load) provided evidence, merge it
            // with the evidence we've just created. The host evidence takes
            // priority.
            if (additionalEvidence != null)
                evidence.MergeWithNoDuplicates(additionalEvidence);

            return evidence;
        }
Ejemplo n.º 6
0
        internal static Evidence MergeApplicationEvidence(Evidence evidence,
                                                          ApplicationIdentity applicationIdentity,
                                                          ActivationContext activationContext,
                                                          string[] activationData,
                                                          ApplicationTrust applicationTrust)
        {
            Evidence appEvidence = new Evidence();

            ActivationArguments activationArgs = (activationContext == null ? new ActivationArguments(applicationIdentity, activationData) : new ActivationArguments(activationContext, activationData));
            appEvidence = new Evidence();
            appEvidence.AddHostEvidence(activationArgs);

            if (applicationTrust != null)
                appEvidence.AddHostEvidence(applicationTrust);

            if (activationContext != null)
            {
                Evidence asiEvidence = new ApplicationSecurityInfo(activationContext).ApplicationEvidence;
                if (asiEvidence != null)
                    appEvidence.MergeWithNoDuplicates(asiEvidence);
            }

            if (evidence != null)
                appEvidence.MergeWithNoDuplicates(evidence);

            return appEvidence;
        }
Ejemplo n.º 7
0
 private static System.Security.Policy.Evidence CreateSecurityIdentity(Assembly asm, string strUrl, int zone, byte[] cert, byte[] publicKeyBlob, string strSimpleName, int major, int minor, int build, int revision, byte[] serializedEvidence, System.Security.Policy.Evidence additionalEvidence)
 {
     System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence();
     if (zone != -1)
     {
         evidence.AddHost(new Zone((SecurityZone) zone));
     }
     if (strUrl != null)
     {
         evidence.AddHost(new Url(strUrl, true));
         if (string.Compare(strUrl, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) != 0)
         {
             evidence.AddHost(Site.CreateFromUrl(strUrl));
         }
     }
     if (cert != null)
     {
         AddX509Certificate(evidence, cert);
     }
     if ((asm != null) && RuntimeEnvironment.FromGlobalAccessCache(asm))
     {
         evidence.AddHost(new GacInstalled());
     }
     if (serializedEvidence != null)
     {
         DecodeSerializedEvidence(evidence, serializedEvidence);
     }
     if ((publicKeyBlob != null) && (publicKeyBlob.Length != 0))
     {
         AddStrongName(evidence, publicKeyBlob, strSimpleName, major, minor, build, revision, asm);
     }
     if ((asm != null) && !asm.nIsDynamic())
     {
         evidence.AddHost(new Hash(asm));
     }
     if (additionalEvidence != null)
     {
         evidence.MergeWithNoDuplicates(additionalEvidence);
     }
     if (asm != null)
     {
         HostSecurityManager hostSecurityManager = AppDomain.CurrentDomain.HostSecurityManager;
         if ((hostSecurityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) == HostSecurityManagerOptions.HostAssemblyEvidence)
         {
             return hostSecurityManager.ProvideAssemblyEvidence(asm, evidence);
         }
     }
     return evidence;
 }
Ejemplo n.º 8
0
 internal static Evidence MergeApplicationEvidence(Evidence evidence, ApplicationIdentity applicationIdentity, ActivationContext activationContext, string[] activationData, ApplicationTrust applicationTrust)
 {
     Evidence evidence2 = new Evidence();
     ActivationArguments id = (activationContext == null) ? new ActivationArguments(applicationIdentity, activationData) : new ActivationArguments(activationContext, activationData);
     evidence2 = new Evidence();
     evidence2.AddHost(id);
     if (applicationTrust != null)
     {
         evidence2.AddHost(applicationTrust);
     }
     if (activationContext != null)
     {
         Evidence applicationEvidence = new ApplicationSecurityInfo(activationContext).ApplicationEvidence;
         if (applicationEvidence != null)
         {
             evidence2.MergeWithNoDuplicates(applicationEvidence);
         }
     }
     if (evidence != null)
     {
         evidence2.MergeWithNoDuplicates(evidence);
     }
     return evidence2;
 }
Ejemplo n.º 9
0
        private static Evidence CreateSecurityIdentity(Assembly asm,
                                                String strUrl,
                                                int zone,
                                                byte[] cert,
                                                byte[] publicKeyBlob,
                                                String strSimpleName,
                                                int major,
                                                int minor,
                                                int build,
                                                int revision,
                                                byte[] serializedEvidence,
                                                Evidence additionalEvidence)
        {
            Evidence evidence = new Evidence();

            if (zone != -1)
                evidence.AddHost( new Zone((SecurityZone)zone) );
            if (strUrl != null)
            {
                evidence.AddHost( new Url(strUrl, true) );

                // Only create a site piece of evidence if we are not loading from a file.
                if (String.Compare( strUrl, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0)
                    evidence.AddHost( Site.CreateFromUrl( strUrl ) );
            }


            // Determine if it's in the GAC and add some evidence about it
            if(asm != null && System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(asm))
                evidence.AddHost( new GacInstalled() );

            // This code was moved to a different function because:
            // 1) it is rarely called so we should only JIT it if we need it.
            // 2) it references lots of classes that otherwise aren't loaded.
            if (serializedEvidence != null)
                DecodeSerializedEvidence( evidence, serializedEvidence );

            if ((publicKeyBlob != null) &&
                (publicKeyBlob.Length != 0))
                AddStrongName( evidence, publicKeyBlob, strSimpleName, major, minor, build, revision );


            // If the host (caller of Assembly.Load) provided evidence, merge it
            // with the evidence we've just created. The host evidence takes
            // priority.
            if (additionalEvidence != null)
                evidence.MergeWithNoDuplicates(additionalEvidence);

            if (asm != null) {
                // The host might want to modify the evidence of the assembly through
                // the HostSecurityManager provided in AppDomainManager, so take that into account.
                HostSecurityManager securityManager = AppDomain.CurrentDomain.HostSecurityManager;
                if ((securityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) == HostSecurityManagerOptions.HostAssemblyEvidence)
                    return securityManager.ProvideAssemblyEvidence(asm, evidence);
            }

            return evidence;
        }