336 lines
16 KiB
C#
336 lines
16 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
|
|
namespace System.Security
|
|
{
|
|
/// <summary>Defines the underlying structure of all code access permissions.</summary>
|
|
// Token: 0x020005BC RID: 1468
|
|
[ComVisible(true)]
|
|
[MonoTODO("CAS support is experimental (and unsupported).")]
|
|
[Serializable]
|
|
public abstract class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk
|
|
{
|
|
/// <summary>Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. Using <see cref="M:System.Security.CodeAccessPermission.Assert" /> can create security issues.</summary>
|
|
/// <exception cref="T:System.Security.SecurityException">The calling code does not have <see cref="F:System.Security.Permissions.SecurityPermissionFlag.Assertion" />.-or- There is already an active <see cref="M:System.Security.CodeAccessPermission.Assert" /> for the current frame. </exception>
|
|
// Token: 0x06003595 RID: 13717 RVA: 0x000B7D10 File Offset: 0x000B5F10
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public void Assert()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06003596 RID: 13718 RVA: 0x000B7D14 File Offset: 0x000B5F14
|
|
internal bool CheckAssert(CodeAccessPermission asserted)
|
|
{
|
|
return asserted != null && asserted.GetType() == base.GetType() && this.IsSubsetOf(asserted);
|
|
}
|
|
|
|
// Token: 0x06003597 RID: 13719 RVA: 0x000B7D44 File Offset: 0x000B5F44
|
|
internal bool CheckDemand(CodeAccessPermission target)
|
|
{
|
|
return target != null && target.GetType() == base.GetType() && this.IsSubsetOf(target);
|
|
}
|
|
|
|
// Token: 0x06003598 RID: 13720 RVA: 0x000B7D74 File Offset: 0x000B5F74
|
|
internal bool CheckDeny(CodeAccessPermission denied)
|
|
{
|
|
if (denied == null)
|
|
{
|
|
return true;
|
|
}
|
|
Type type = denied.GetType();
|
|
return type != base.GetType() || this.Intersect(denied) == null || denied.IsSubsetOf(PermissionBuilder.Create(type));
|
|
}
|
|
|
|
// Token: 0x06003599 RID: 13721 RVA: 0x000B7DBC File Offset: 0x000B5FBC
|
|
internal bool CheckPermitOnly(CodeAccessPermission target)
|
|
{
|
|
return target != null && target.GetType() == base.GetType() && this.IsSubsetOf(target);
|
|
}
|
|
|
|
/// <summary>When implemented by a derived class, creates and returns an identical copy of the current permission object.</summary>
|
|
/// <returns>A copy of the current permission object.</returns>
|
|
// Token: 0x0600359A RID: 13722
|
|
public abstract IPermission Copy();
|
|
|
|
/// <summary>Forces a <see cref="T:System.Security.SecurityException" /> at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.</summary>
|
|
/// <exception cref="T:System.Security.SecurityException">A caller higher in the call stack does not have the permission specified by the current instance.-or- A caller higher in the call stack has called <see cref="M:System.Security.CodeAccessPermission.Deny" /> on the current permission object. </exception>
|
|
// Token: 0x0600359B RID: 13723 RVA: 0x000B7DEC File Offset: 0x000B5FEC
|
|
public void Demand()
|
|
{
|
|
}
|
|
|
|
/// <summary>Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.</summary>
|
|
/// <exception cref="T:System.Security.SecurityException">There is already an active <see cref="M:System.Security.CodeAccessPermission.Deny" /> for the current frame. </exception>
|
|
// Token: 0x0600359C RID: 13724 RVA: 0x000B7DF0 File Offset: 0x000B5FF0
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public void Deny()
|
|
{
|
|
}
|
|
|
|
/// <summary>Determines whether the specified <see cref="T:System.Security.CodeAccessPermission" /> object is equal to the current <see cref="T:System.Security.CodeAccessPermission" />.</summary>
|
|
/// <returns>true if the specified <see cref="T:System.Security.CodeAccessPermission" /> object is equal to the current <see cref="T:System.Security.CodeAccessPermission" />; otherwise, false.</returns>
|
|
/// <param name="obj">The <see cref="T:System.Security.CodeAccessPermission" /> object to compare with the current <see cref="T:System.Security.CodeAccessPermission" />. </param>
|
|
// Token: 0x0600359D RID: 13725 RVA: 0x000B7DF4 File Offset: 0x000B5FF4
|
|
[ComVisible(false)]
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (obj.GetType() != base.GetType())
|
|
{
|
|
return false;
|
|
}
|
|
CodeAccessPermission codeAccessPermission = obj as CodeAccessPermission;
|
|
return this.IsSubsetOf(codeAccessPermission) && codeAccessPermission.IsSubsetOf(this);
|
|
}
|
|
|
|
/// <summary>When overridden in a derived class, reconstructs a security object with a specified state from an XML encoding.</summary>
|
|
/// <param name="elem">The XML encoding to use to reconstruct the security object. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="elem" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="elem" /> parameter does not contain the XML encoding for an instance of the same type as the current instance.-or- The version number of the <paramref name="elem" /> parameter is not supported. </exception>
|
|
// Token: 0x0600359E RID: 13726
|
|
public abstract void FromXml(SecurityElement elem);
|
|
|
|
/// <summary>Gets a hash code for the <see cref="T:System.Security.CodeAccessPermission" /> object that is suitable for use in hashing algorithms and data structures such as a hash table.</summary>
|
|
/// <returns>A hash code for the current <see cref="T:System.Security.CodeAccessPermission" /> object.</returns>
|
|
// Token: 0x0600359F RID: 13727 RVA: 0x000B7E3C File Offset: 0x000B603C
|
|
[ComVisible(false)]
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
/// <summary>When implemented by a derived class, creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
|
|
/// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
|
|
/// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not an instance of the same class as the current permission. </exception>
|
|
// Token: 0x060035A0 RID: 13728
|
|
public abstract IPermission Intersect(IPermission target);
|
|
|
|
/// <summary>When implemented by a derived class, determines whether the current permission is a subset of the specified permission.</summary>
|
|
/// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
|
|
/// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
|
|
// Token: 0x060035A1 RID: 13729
|
|
public abstract bool IsSubsetOf(IPermission target);
|
|
|
|
/// <summary>Creates and returns a string representation of the current permission object.</summary>
|
|
/// <returns>A string representation of the current permission object.</returns>
|
|
// Token: 0x060035A2 RID: 13730 RVA: 0x000B7E44 File Offset: 0x000B6044
|
|
public override string ToString()
|
|
{
|
|
SecurityElement securityElement = this.ToXml();
|
|
return securityElement.ToString();
|
|
}
|
|
|
|
/// <summary>When overridden in a derived class, creates an XML encoding of the security object and its current state.</summary>
|
|
/// <returns>An XML encoding of the security object, including any state information.</returns>
|
|
// Token: 0x060035A3 RID: 13731
|
|
public abstract SecurityElement ToXml();
|
|
|
|
/// <summary>When overridden in a derived class, creates a permission that is the union of the current permission and the specified permission.</summary>
|
|
/// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
|
|
/// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
|
|
/// <exception cref="T:System.NotSupportedException">The <paramref name="other" /> parameter is not null. This method is only supported at this level when passed null. </exception>
|
|
// Token: 0x060035A4 RID: 13732 RVA: 0x000B7E60 File Offset: 0x000B6060
|
|
public virtual IPermission Union(IPermission other)
|
|
{
|
|
if (other != null)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.</summary>
|
|
/// <exception cref="T:System.Security.SecurityException">There is already an active <see cref="M:System.Security.CodeAccessPermission.PermitOnly" /> for the current frame. </exception>
|
|
// Token: 0x060035A5 RID: 13733 RVA: 0x000B7E70 File Offset: 0x000B6070
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public void PermitOnly()
|
|
{
|
|
}
|
|
|
|
/// <summary>Causes all previous overrides for the current frame to be removed and no longer in effect.</summary>
|
|
/// <exception cref="T:System.ExecutionEngineException">There is no previous <see cref="M:System.Security.CodeAccessPermission.Assert" />, <see cref="M:System.Security.CodeAccessPermission.Deny" />, or <see cref="M:System.Security.CodeAccessPermission.PermitOnly" /> for the current frame. </exception>
|
|
// Token: 0x060035A6 RID: 13734 RVA: 0x000B7E74 File Offset: 0x000B6074
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public static void RevertAll()
|
|
{
|
|
}
|
|
|
|
/// <summary>Causes any previous <see cref="M:System.Security.CodeAccessPermission.Assert" /> for the current frame to be removed and no longer in effect.</summary>
|
|
/// <exception cref="T:System.ExecutionEngineException">There is no previous <see cref="M:System.Security.CodeAccessPermission.Assert" /> for the current frame. </exception>
|
|
// Token: 0x060035A7 RID: 13735 RVA: 0x000B7E78 File Offset: 0x000B6078
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public static void RevertAssert()
|
|
{
|
|
}
|
|
|
|
/// <summary>Causes any previous <see cref="M:System.Security.CodeAccessPermission.Deny" /> for the current frame to be removed and no longer in effect.</summary>
|
|
/// <exception cref="T:System.ExecutionEngineException">There is no previous <see cref="M:System.Security.CodeAccessPermission.Deny" /> for the current frame. </exception>
|
|
// Token: 0x060035A8 RID: 13736 RVA: 0x000B7E7C File Offset: 0x000B607C
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public static void RevertDeny()
|
|
{
|
|
}
|
|
|
|
/// <summary>Causes any previous <see cref="M:System.Security.CodeAccessPermission.PermitOnly" /> for the current frame to be removed and no longer in effect.</summary>
|
|
/// <exception cref="T:System.ExecutionEngineException">There is no previous <see cref="M:System.Security.CodeAccessPermission.PermitOnly" /> for the current frame. </exception>
|
|
// Token: 0x060035A9 RID: 13737 RVA: 0x000B7E80 File Offset: 0x000B6080
|
|
[MonoTODO("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
|
|
public static void RevertPermitOnly()
|
|
{
|
|
}
|
|
|
|
// Token: 0x060035AA RID: 13738 RVA: 0x000B7E84 File Offset: 0x000B6084
|
|
internal SecurityElement Element(int version)
|
|
{
|
|
SecurityElement securityElement = new SecurityElement("IPermission");
|
|
Type type = base.GetType();
|
|
securityElement.AddAttribute("class", type.FullName + ", " + type.Assembly.ToString().Replace('"', '\''));
|
|
securityElement.AddAttribute("version", version.ToString());
|
|
return securityElement;
|
|
}
|
|
|
|
// Token: 0x060035AB RID: 13739 RVA: 0x000B7EE8 File Offset: 0x000B60E8
|
|
internal static PermissionState CheckPermissionState(PermissionState state, bool allowUnrestricted)
|
|
{
|
|
if (state != PermissionState.None)
|
|
{
|
|
if (state != PermissionState.Unrestricted)
|
|
{
|
|
string text = string.Format(Locale.GetText("Invalid enum {0}"), state);
|
|
throw new ArgumentException(text, "state");
|
|
}
|
|
}
|
|
return state;
|
|
}
|
|
|
|
// Token: 0x060035AC RID: 13740 RVA: 0x000B7F38 File Offset: 0x000B6138
|
|
internal static int CheckSecurityElement(SecurityElement se, string parameterName, int minimumVersion, int maximumVersion)
|
|
{
|
|
if (se == null)
|
|
{
|
|
throw new ArgumentNullException(parameterName);
|
|
}
|
|
if (se.Tag != "IPermission")
|
|
{
|
|
string text = string.Format(Locale.GetText("Invalid tag {0}"), se.Tag);
|
|
throw new ArgumentException(text, parameterName);
|
|
}
|
|
int num = minimumVersion;
|
|
string text2 = se.Attribute("version");
|
|
if (text2 != null)
|
|
{
|
|
try
|
|
{
|
|
num = int.Parse(text2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string text3 = Locale.GetText("Couldn't parse version from '{0}'.");
|
|
text3 = string.Format(text3, text2);
|
|
throw new ArgumentException(text3, parameterName, ex);
|
|
}
|
|
}
|
|
if (num < minimumVersion || num > maximumVersion)
|
|
{
|
|
string text4 = Locale.GetText("Unknown version '{0}', expected versions between ['{1}','{2}'].");
|
|
text4 = string.Format(text4, num, minimumVersion, maximumVersion);
|
|
throw new ArgumentException(text4, parameterName);
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x060035AD RID: 13741 RVA: 0x000B8028 File Offset: 0x000B6228
|
|
internal static bool IsUnrestricted(SecurityElement se)
|
|
{
|
|
string text = se.Attribute("Unrestricted");
|
|
return text != null && string.Compare(text, bool.TrueString, true, CultureInfo.InvariantCulture) == 0;
|
|
}
|
|
|
|
// Token: 0x060035AE RID: 13742 RVA: 0x000B8060 File Offset: 0x000B6260
|
|
internal bool ProcessFrame(SecurityFrame frame)
|
|
{
|
|
if (frame.PermitOnly != null)
|
|
{
|
|
bool flag = frame.PermitOnly.IsUnrestricted();
|
|
if (!flag)
|
|
{
|
|
foreach (object obj in frame.PermitOnly)
|
|
{
|
|
IPermission permission = (IPermission)obj;
|
|
if (this.CheckPermitOnly(permission as CodeAccessPermission))
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!flag)
|
|
{
|
|
CodeAccessPermission.ThrowSecurityException(this, "PermitOnly", frame, SecurityAction.Demand, null);
|
|
}
|
|
}
|
|
if (frame.Deny != null)
|
|
{
|
|
if (frame.Deny.IsUnrestricted())
|
|
{
|
|
CodeAccessPermission.ThrowSecurityException(this, "Deny", frame, SecurityAction.Demand, null);
|
|
}
|
|
foreach (object obj2 in frame.Deny)
|
|
{
|
|
IPermission permission2 = (IPermission)obj2;
|
|
if (!this.CheckDeny(permission2 as CodeAccessPermission))
|
|
{
|
|
CodeAccessPermission.ThrowSecurityException(this, "Deny", frame, SecurityAction.Demand, permission2);
|
|
}
|
|
}
|
|
}
|
|
if (frame.Assert != null)
|
|
{
|
|
if (frame.Assert.IsUnrestricted())
|
|
{
|
|
return true;
|
|
}
|
|
foreach (object obj3 in frame.Assert)
|
|
{
|
|
IPermission permission3 = (IPermission)obj3;
|
|
if (this.CheckAssert(permission3 as CodeAccessPermission))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x060035AF RID: 13743 RVA: 0x000B8260 File Offset: 0x000B6460
|
|
internal static void ThrowInvalidPermission(IPermission target, Type expected)
|
|
{
|
|
string text = Locale.GetText("Invalid permission type '{0}', expected type '{1}'.");
|
|
text = string.Format(text, target.GetType(), expected);
|
|
throw new ArgumentException(text, "target");
|
|
}
|
|
|
|
// Token: 0x060035B0 RID: 13744 RVA: 0x000B8294 File Offset: 0x000B6494
|
|
internal static void ThrowExecutionEngineException(SecurityAction stackmod)
|
|
{
|
|
string text = Locale.GetText("No {0} modifier is present on the current stack frame.");
|
|
text = text + Environment.NewLine + "Currently only declarative stack modifiers are supported.";
|
|
throw new ExecutionEngineException(string.Format(text, stackmod));
|
|
}
|
|
|
|
// Token: 0x060035B1 RID: 13745 RVA: 0x000B82D0 File Offset: 0x000B64D0
|
|
internal static void ThrowSecurityException(object demanded, string message, SecurityFrame frame, SecurityAction action, IPermission failed)
|
|
{
|
|
throw new SecurityException(message);
|
|
}
|
|
}
|
|
}
|