Files
2026-06-04 11:42:34 +02:00

294 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;
using Mono.Security.Cryptography;
namespace System.Security.Policy
{
/// <summary>Encapsulates security decisions about an application. This class cannot be inherited.</summary>
// Token: 0x0200057E RID: 1406
[ComVisible(true)]
[Serializable]
public sealed class ApplicationTrust : ISecurityEncodable
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.ApplicationTrust" /> class.</summary>
// Token: 0x0600335C RID: 13148 RVA: 0x000B07D0 File Offset: 0x000AE9D0
public ApplicationTrust()
{
this.fullTrustAssemblies = new List<StrongName>(0);
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.ApplicationTrust" /> class with an <see cref="T:System.ApplicationIdentity" />. </summary>
/// <param name="applicationIdentity">An <see cref="T:System.ApplicationIdentity" /> that uniquely identifies an application.</param>
// Token: 0x0600335D RID: 13149 RVA: 0x000B07E4 File Offset: 0x000AE9E4
public ApplicationTrust(ApplicationIdentity applicationIdentity)
: this()
{
if (applicationIdentity == null)
{
throw new ArgumentNullException("applicationIdentity");
}
this._appid = applicationIdentity;
}
// Token: 0x0600335E RID: 13150 RVA: 0x000B0804 File Offset: 0x000AEA04
internal ApplicationTrust(PermissionSet defaultGrantSet, IEnumerable<StrongName> fullTrustAssemblies)
{
if (defaultGrantSet == null)
{
throw new ArgumentNullException("defaultGrantSet");
}
this._defaultPolicy = new PolicyStatement(defaultGrantSet);
if (fullTrustAssemblies == null)
{
throw new ArgumentNullException("fullTrustAssemblies");
}
this.fullTrustAssemblies = new List<StrongName>();
foreach (StrongName strongName in fullTrustAssemblies)
{
if (strongName == null)
{
throw new ArgumentException("fullTrustAssemblies contains an assembly that does not have a StrongName");
}
this.fullTrustAssemblies.Add((StrongName)strongName.Copy());
}
}
/// <summary>Gets or sets the application identity for the application trust object.</summary>
/// <returns>An <see cref="T:System.ApplicationIdentity" /> for the application trust object.</returns>
/// <exception cref="T:System.ArgumentNullException">
/// <see cref="T:System.ApplicationIdentity" /> cannot be set because it has a value of null.</exception>
// Token: 0x17000A15 RID: 2581
// (get) Token: 0x0600335F RID: 13151 RVA: 0x000B08C4 File Offset: 0x000AEAC4
// (set) Token: 0x06003360 RID: 13152 RVA: 0x000B08CC File Offset: 0x000AEACC
public ApplicationIdentity ApplicationIdentity
{
get
{
return this._appid;
}
set
{
if (value == null)
{
throw new ArgumentNullException("ApplicationIdentity");
}
this._appid = value;
}
}
/// <summary>Gets or sets the policy statement defining the default grant set.</summary>
/// <returns>A <see cref="T:System.Security.Policy.PolicyStatement" /> describing the default grants.</returns>
// Token: 0x17000A16 RID: 2582
// (get) Token: 0x06003361 RID: 13153 RVA: 0x000B08E8 File Offset: 0x000AEAE8
// (set) Token: 0x06003362 RID: 13154 RVA: 0x000B0908 File Offset: 0x000AEB08
public PolicyStatement DefaultGrantSet
{
get
{
if (this._defaultPolicy == null)
{
this._defaultPolicy = this.GetDefaultGrantSet();
}
return this._defaultPolicy;
}
set
{
this._defaultPolicy = value;
}
}
/// <summary>Gets or sets extra security information about the application.</summary>
/// <returns>An object containing additional security information about the application.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x17000A17 RID: 2583
// (get) Token: 0x06003363 RID: 13155 RVA: 0x000B0914 File Offset: 0x000AEB14
// (set) Token: 0x06003364 RID: 13156 RVA: 0x000B091C File Offset: 0x000AEB1C
public object ExtraInfo
{
get
{
return this._xtranfo;
}
set
{
this._xtranfo = value;
}
}
/// <summary>Gets or sets a value indicating whether the application has the required permission grants and is trusted to run.</summary>
/// <returns>true if the application is trusted to run; otherwise, false. The default is false.</returns>
// Token: 0x17000A18 RID: 2584
// (get) Token: 0x06003365 RID: 13157 RVA: 0x000B0928 File Offset: 0x000AEB28
// (set) Token: 0x06003366 RID: 13158 RVA: 0x000B0930 File Offset: 0x000AEB30
public bool IsApplicationTrustedToRun
{
get
{
return this._trustrun;
}
set
{
this._trustrun = value;
}
}
/// <summary>Gets or sets a value indicating whether application trust information is persisted.</summary>
/// <returns>true if application trust information is persisted; otherwise, false. The default is false.</returns>
// Token: 0x17000A19 RID: 2585
// (get) Token: 0x06003367 RID: 13159 RVA: 0x000B093C File Offset: 0x000AEB3C
// (set) Token: 0x06003368 RID: 13160 RVA: 0x000B0944 File Offset: 0x000AEB44
public bool Persist
{
get
{
return this._persist;
}
set
{
this._persist = value;
}
}
/// <summary>Reconstructs an <see cref="T:System.Security.Policy.ApplicationTrust" /> object with a given state from an XML encoding.</summary>
/// <param name="element">The XML encoding to use to reconstruct the <see cref="T:System.Security.Policy.ApplicationTrust" /> object. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="element" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">The XML encoding used for <paramref name="element" /> is invalid.</exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// Token: 0x06003369 RID: 13161 RVA: 0x000B0950 File Offset: 0x000AEB50
public void FromXml(SecurityElement element)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
if (element.Tag != "ApplicationTrust")
{
throw new ArgumentException("element");
}
string text = element.Attribute("FullName");
if (text != null)
{
this._appid = new ApplicationIdentity(text);
}
else
{
this._appid = null;
}
this._defaultPolicy = null;
SecurityElement securityElement = element.SearchForChildByTag("DefaultGrant");
if (securityElement != null)
{
for (int i = 0; i < securityElement.Children.Count; i++)
{
SecurityElement securityElement2 = securityElement.Children[i] as SecurityElement;
if (securityElement2.Tag == "PolicyStatement")
{
this.DefaultGrantSet.FromXml(securityElement2, null);
break;
}
}
}
if (!bool.TryParse(element.Attribute("TrustedToRun"), out this._trustrun))
{
this._trustrun = false;
}
if (!bool.TryParse(element.Attribute("Persist"), out this._persist))
{
this._persist = false;
}
this._xtranfo = null;
SecurityElement securityElement3 = element.SearchForChildByTag("ExtraInfo");
if (securityElement3 != null)
{
text = securityElement3.Attribute("Data");
if (text != null)
{
byte[] array = CryptoConvert.FromHex(text);
using (MemoryStream memoryStream = new MemoryStream(array))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
this._xtranfo = binaryFormatter.Deserialize(memoryStream);
}
}
}
}
/// <summary>Creates an XML encoding of the <see cref="T:System.Security.Policy.ApplicationTrust" /> object and its current state.</summary>
/// <returns>An XML encoding of the security object, including any state information.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*" />
/// <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x0600336A RID: 13162 RVA: 0x000B0AF0 File Offset: 0x000AECF0
public SecurityElement ToXml()
{
SecurityElement securityElement = new SecurityElement("ApplicationTrust");
securityElement.AddAttribute("version", "1");
if (this._appid != null)
{
securityElement.AddAttribute("FullName", this._appid.FullName);
}
if (this._trustrun)
{
securityElement.AddAttribute("TrustedToRun", "true");
}
if (this._persist)
{
securityElement.AddAttribute("Persist", "true");
}
SecurityElement securityElement2 = new SecurityElement("DefaultGrant");
securityElement2.AddChild(this.DefaultGrantSet.ToXml());
securityElement.AddChild(securityElement2);
if (this._xtranfo != null)
{
byte[] array = null;
using (MemoryStream memoryStream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, this._xtranfo);
array = memoryStream.ToArray();
}
SecurityElement securityElement3 = new SecurityElement("ExtraInfo");
securityElement3.AddAttribute("Data", CryptoConvert.ToHex(array));
securityElement.AddChild(securityElement3);
}
return securityElement;
}
// Token: 0x0600336B RID: 13163 RVA: 0x000B0C18 File Offset: 0x000AEE18
private PolicyStatement GetDefaultGrantSet()
{
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
return new PolicyStatement(permissionSet);
}
// Token: 0x0400150C RID: 5388
private ApplicationIdentity _appid;
// Token: 0x0400150D RID: 5389
private PolicyStatement _defaultPolicy;
// Token: 0x0400150E RID: 5390
private object _xtranfo;
// Token: 0x0400150F RID: 5391
private bool _trustrun;
// Token: 0x04001510 RID: 5392
private bool _persist;
// Token: 0x04001511 RID: 5393
private IList<StrongName> fullTrustAssemblies;
}
}