16 private static string s_machineConfigFile;
22 [SecuritySafeCritical]
35 [SecuritySafeCritical]
39 if (m_appTrustManager ==
null)
41 m_appTrustManager = DecodeAppTrustManager();
42 if (m_appTrustManager ==
null)
47 return m_appTrustManager;
51 [SecuritySafeCritical]
54 m_appTrustManager =
null;
55 s_machineConfigFile = Config.MachineDirectory +
"applicationtrust.config";
68 if (activationContext ==
null)
74 if (domainManager !=
null)
79 return hostSecurityManager.
DetermineApplicationTrust(CmsUtils.MergeApplicationEvidence(
null, activationContext.
Identity, activationContext,
null),
null, context)?.IsApplicationTrustedToRun ??
false;
92 applicationTrust = applicationTrustCollection[activationContext.
Identity.
FullName];
93 if (applicationTrust !=
null)
95 return applicationTrust;
99 if (applicationTrust ==
null)
101 applicationTrust =
new ApplicationTrust(activationContext.
Identity);
106 applicationTrustCollection.
Add(applicationTrust);
108 return applicationTrust;
112 private static IApplicationTrustManager DecodeAppTrustManager()
114 if (
File.InternalExists(s_machineConfigFile))
121 SecurityElement securityElement = SecurityElement.FromString(xml);
122 SecurityElement securityElement2 = securityElement.SearchForChildByTag(
"mscorlib");
123 if (securityElement2 !=
null)
125 SecurityElement securityElement3 = securityElement2.SearchForChildByTag(
"security");
126 if (securityElement3 !=
null)
128 SecurityElement securityElement4 = securityElement3.SearchForChildByTag(
"policy");
129 if (securityElement4 !=
null)
131 SecurityElement securityElement5 = securityElement4.SearchForChildByTag(
"ApplicationSecurityManager");
132 if (securityElement5 !=
null)
134 SecurityElement securityElement6 = securityElement5.SearchForChildByTag(
"IApplicationTrustManager");
135 if (securityElement6 !=
null)
137 IApplicationTrustManager applicationTrustManager = DecodeAppTrustManagerFromElement(securityElement6);
138 if (applicationTrustManager !=
null)
140 return applicationTrustManager;
148 return DecodeAppTrustManagerFromElement(CreateDefaultApplicationTrustManagerElement());
152 private static SecurityElement CreateDefaultApplicationTrustManagerElement()
154 SecurityElement securityElement =
new SecurityElement(
"IApplicationTrustManager");
155 securityElement.AddAttribute(
"class",
"System.Security.Policy.TrustManager, System.Windows.Forms, Version=" + ((RuntimeAssembly)
Assembly.
GetExecutingAssembly()).GetVersion() +
", Culture=neutral, PublicKeyToken=b77a5c561934e089");
156 securityElement.AddAttribute(
"version",
"1");
157 return securityElement;
161 private static IApplicationTrustManager DecodeAppTrustManagerFromElement(SecurityElement elTrustManager)
164 string typeName = elTrustManager.Attribute(
"class");
165 Type type =
Type.GetType(typeName, throwOnError:
false, ignoreCase:
false);
170 IApplicationTrustManager applicationTrustManager = Activator.CreateInstance(type) as IApplicationTrustManager;
171 applicationTrustManager?.FromXml(elTrustManager);
172 return applicationTrustManager;
static Assembly GetExecutingAssembly()
Gets the assembly that contains the code that is currently executing.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Encapsulates security decisions about an application. This class cannot be inherited.
Describes a set of security permissions applied to code. This class cannot be inherited.
bool Persist
Gets or sets a value indicating whether application trust information is persisted.
virtual ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
Determines whether an application should be executed.
ReflectionPermissionFlag
Specifies the permitted use of the N:System.Reflection and N:System.Reflection.Emit namespaces.
int Add(ApplicationTrust trust)
Adds an element to the collection.
virtual bool IgnorePersistedDecision
Gets or sets a value indicating whether the application security manager should ignore any persisted ...
Determines whether an application should be executed and which set of permissions should be granted t...
FileMode
Specifies how the operating system should open a file.
Identifies the activation context for the current application. This class cannot be inherited.
HostSecurityManagerOptions
Specifies the security policy components to be used by the host security manager.
override string ReadToEnd()
Reads all characters from the current position to the end of the stream.
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
ApplicationIdentity Identity
Gets the application identity for the current application.
Manages trust decisions for manifest-activated applications.
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Represents an application domain, which is an isolated environment where applications execute....
Represents the context for the trust manager to consider when making the decision to run an applicati...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
ApplicationTrust DetermineApplicationTrust(ActivationContext activationContext, TrustManagerContext context)
Determines whether an application should be executed and which set of permissions should be granted t...
static bool DetermineApplicationTrust(ActivationContext activationContext, TrustManagerContext context)
Determines whether the user approves the specified application to execute with the requested permissi...
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
virtual HostSecurityManager HostSecurityManager
Gets the host security manager that participates in security decisions for the application domain.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
static IApplicationTrustManager ApplicationTrustManager
Gets the current application trust manager.
bool IsApplicationTrustedToRun
Gets or sets a value indicating whether the application has the required permission grants and is tru...
ApplicationIdentity ApplicationIdentity
Gets or sets the application identity for the application trust object.
Provides a managed equivalent of an unmanaged host.
Represents a collection of T:System.Security.Policy.ApplicationTrust objects. This class cannot be in...
FileAccess
Defines constants for read, write, or read/write access to a file.
AppDomainManager DomainManager
Gets the domain manager that was provided by the host when the application domain was initialized.
virtual HostSecurityManagerOptions Flags
Gets the flag representing the security policy components of concern to the host.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
SecurityPermissionFlag
Specifies access flags for the security permission object.
string FullName
Gets the full name of the application.
Controls access to non-public types and members through the N:System.Reflection APIs....
static ApplicationTrustCollection UserApplicationTrusts
Gets an application trust collection that contains the cached trust decisions for the user.
The exception that is thrown when policy forbids code to run.
Allows the control and customization of security behavior for application domains.