protected static ObjectHandle CreateInstanceHelper(AppDomainSetup adSetup) { if (adSetup.ActivationArguments == null) { throw new ArgumentException(Environment.GetResourceString("Arg_MissingActivationArguments")); } adSetup.ActivationArguments.ActivateInstance = true; Evidence evidence = AppDomain.CurrentDomain.Evidence; Evidence applicationEvidence = CmsUtils.MergeApplicationEvidence((Evidence)null, adSetup.ActivationArguments.ApplicationIdentity, adSetup.ActivationArguments.ActivationContext, adSetup.ActivationArguments.ActivationData); ApplicationTrust applicationTrust = AppDomain.CurrentDomain.HostSecurityManager.DetermineApplicationTrust(applicationEvidence, evidence, new TrustManagerContext()); if (applicationTrust == null || !applicationTrust.IsApplicationTrustedToRun) { throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"), -2146233320, (Exception)null); } string fullName = adSetup.ActivationArguments.ApplicationIdentity.FullName; AppDomainSetup setup = adSetup; Evidence providedSecurityInfo = applicationEvidence; Evidence creatorsSecurityInfo = providedSecurityInfo == null ? AppDomain.CurrentDomain.InternalEvidence : (Evidence)null; IntPtr securityDescriptor = AppDomain.CurrentDomain.GetSecurityDescriptor(); ObjRef instance = AppDomain.nCreateInstance(fullName, setup, providedSecurityInfo, creatorsSecurityInfo, securityDescriptor); if (instance == null) { return((ObjectHandle)null); } return(RemotingServices.Unmarshal(instance) as ObjectHandle); }
public static bool DetermineApplicationTrust(ActivationContext activationContext, TrustManagerContext context) { if (activationContext == null) { throw new ArgumentNullException("activationContext"); } ApplicationTrust appTrust = null; AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager; if (domainManager != null) { HostSecurityManager securityManager = domainManager.HostSecurityManager; if ((securityManager != null) && ((securityManager.Flags & HostSecurityManagerOptions.HostDetermineApplicationTrust) == HostSecurityManagerOptions.HostDetermineApplicationTrust)) { appTrust = securityManager.DetermineApplicationTrust(CmsUtils.MergeApplicationEvidence(null, activationContext.Identity, activationContext, null), null, context); if (appTrust == null) { return(false); } return(appTrust.IsApplicationTrustedToRun); } } appTrust = DetermineApplicationTrustInternal(activationContext, context); if (appTrust == null) { return(false); } return(appTrust.IsApplicationTrustedToRun); }
[System.Security.SecuritySafeCritical] // auto-generated protected static ObjectHandle CreateInstanceHelper(AppDomainSetup adSetup) { if (adSetup.ActivationArguments == null) { throw new ArgumentException(Environment.GetResourceString("Arg_MissingActivationArguments")); } Contract.EndContractBlock(); adSetup.ActivationArguments.ActivateInstance = true; // inherit the caller's domain evidence for the activation. Evidence activatorEvidence = AppDomain.CurrentDomain.Evidence; // add the application identity as an evidence. Evidence appEvidence = CmsUtils.MergeApplicationEvidence(null, adSetup.ActivationArguments.ApplicationIdentity, adSetup.ActivationArguments.ActivationContext, adSetup.ActivationArguments.ActivationData); HostSecurityManager securityManager = AppDomain.CurrentDomain.HostSecurityManager; ApplicationTrust appTrust = securityManager.DetermineApplicationTrust(appEvidence, activatorEvidence, new TrustManagerContext()); if (appTrust == null || !appTrust.IsApplicationTrustedToRun) { throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"), System.__HResults.CORSEC_E_NO_EXEC_PERM, null); } ObjRef or = AppDomain.nCreateInstance(adSetup.ActivationArguments.ApplicationIdentity.FullName, adSetup, appEvidence, appEvidence == null ? AppDomain.CurrentDomain.InternalEvidence : null, AppDomain.CurrentDomain.GetSecurityDescriptor()); if (or == null) { return(null); } return(RemotingServices.Unmarshal(or) as ObjectHandle); }
protected static ObjectHandle CreateInstanceHelper(AppDomainSetup adSetup) { if (adSetup.ActivationArguments == null) { throw new ArgumentException(Environment.GetResourceString("Arg_MissingActivationArguments")); } adSetup.ActivationArguments.ActivateInstance = true; Evidence activatorEvidence = AppDomain.CurrentDomain.Evidence; Evidence applicationEvidence = CmsUtils.MergeApplicationEvidence(null, adSetup.ActivationArguments.ApplicationIdentity, adSetup.ActivationArguments.ActivationContext, adSetup.ActivationArguments.ActivationData); ApplicationTrust trust = AppDomain.CurrentDomain.HostSecurityManager.DetermineApplicationTrust(applicationEvidence, activatorEvidence, new TrustManagerContext()); if ((trust == null) || !trust.IsApplicationTrustedToRun) { throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"), -2146233320, null); } ObjRef objectRef = AppDomain.nCreateInstance(adSetup.ActivationArguments.ApplicationIdentity.FullName, adSetup, applicationEvidence, (applicationEvidence == null) ? AppDomain.CurrentDomain.InternalEvidence : null, AppDomain.CurrentDomain.GetSecurityDescriptor()); if (objectRef == null) { return(null); } return(RemotingServices.Unmarshal(objectRef) as ObjectHandle); }