Beispiel #1
0
        public static bool DetermineApplicationTrust(ActivationContext activationContext, TrustManagerContext context)
        {
            if (activationContext == null)
            {
                throw new ArgumentNullException("activationContext");
            }
            AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager;

            if (domainManager != null)
            {
                HostSecurityManager hostSecurityManager = domainManager.HostSecurityManager;
                if (hostSecurityManager != null && (hostSecurityManager.Flags & HostSecurityManagerOptions.HostDetermineApplicationTrust) == HostSecurityManagerOptions.HostDetermineApplicationTrust)
                {
                    ApplicationTrust applicationTrust = hostSecurityManager.DetermineApplicationTrust(CmsUtils.MergeApplicationEvidence((Evidence)null, activationContext.Identity, activationContext, (string[])null), (Evidence)null, context);
                    if (applicationTrust == null)
                    {
                        return(false);
                    }
                    return(applicationTrust.IsApplicationTrustedToRun);
                }
            }
            ApplicationTrust applicationTrustInternal = ApplicationSecurityManager.DetermineApplicationTrustInternal(activationContext, context);

            if (applicationTrustInternal == null)
            {
                return(false);
            }
            return(applicationTrustInternal.IsApplicationTrustedToRun);
        }
Beispiel #2
0
 private static IApplicationTrustManager DecodeAppTrustManager()
 {
     if (File.InternalExists(ApplicationSecurityManager.s_machineConfigFile))
     {
         string end;
         using (FileStream fileStream = new FileStream(ApplicationSecurityManager.s_machineConfigFile, FileMode.Open, FileAccess.Read))
             end = new StreamReader((Stream)fileStream).ReadToEnd();
         SecurityElement securityElement1 = SecurityElement.FromString(end).SearchForChildByTag("mscorlib");
         if (securityElement1 != null)
         {
             SecurityElement securityElement2 = securityElement1.SearchForChildByTag("security");
             if (securityElement2 != null)
             {
                 SecurityElement securityElement3 = securityElement2.SearchForChildByTag("policy");
                 if (securityElement3 != null)
                 {
                     SecurityElement securityElement4 = securityElement3.SearchForChildByTag("ApplicationSecurityManager");
                     if (securityElement4 != null)
                     {
                         SecurityElement elTrustManager = securityElement4.SearchForChildByTag("IApplicationTrustManager");
                         if (elTrustManager != null)
                         {
                             IApplicationTrustManager applicationTrustManager = ApplicationSecurityManager.DecodeAppTrustManagerFromElement(elTrustManager);
                             if (applicationTrustManager != null)
                             {
                                 return(applicationTrustManager);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(ApplicationSecurityManager.DecodeAppTrustManagerFromElement(ApplicationSecurityManager.CreateDefaultApplicationTrustManagerElement()));
 }