319 lines
12 KiB
C#
319 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
|
|
namespace System.Security.Policy
|
|
{
|
|
/// <summary>Grants Web permission to the site from which the assembly was downloaded. This class cannot be inherited.</summary>
|
|
// Token: 0x02000596 RID: 1430
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public sealed class NetCodeGroup : CodeGroup
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.NetCodeGroup" /> class.</summary>
|
|
/// <param name="membershipCondition">A membership condition that tests evidence to determine whether this code group applies code access security policy. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="membershipCondition" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The type of the <paramref name="membershipCondition" /> parameter is not valid. </exception>
|
|
// Token: 0x06003431 RID: 13361 RVA: 0x000B3514 File Offset: 0x000B1714
|
|
public NetCodeGroup(IMembershipCondition membershipCondition)
|
|
: base(membershipCondition, null)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06003432 RID: 13362 RVA: 0x000B352C File Offset: 0x000B172C
|
|
internal NetCodeGroup(SecurityElement e, PolicyLevel level)
|
|
: base(e, level)
|
|
{
|
|
}
|
|
|
|
/// <summary>Gets a string representation of the attributes of the policy statement for the code group.</summary>
|
|
/// <returns>Always null.</returns>
|
|
// Token: 0x17000A42 RID: 2626
|
|
// (get) Token: 0x06003434 RID: 13364 RVA: 0x000B355C File Offset: 0x000B175C
|
|
public override string AttributeString
|
|
{
|
|
get
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the logic to use for merging groups.</summary>
|
|
/// <returns>The string "Union".</returns>
|
|
// Token: 0x17000A43 RID: 2627
|
|
// (get) Token: 0x06003435 RID: 13365 RVA: 0x000B3560 File Offset: 0x000B1760
|
|
public override string MergeLogic
|
|
{
|
|
get
|
|
{
|
|
return "Union";
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the name of the <see cref="T:System.Security.NamedPermissionSet" /> for the code group.</summary>
|
|
/// <returns>Always the string "Same site Web."</returns>
|
|
// Token: 0x17000A44 RID: 2628
|
|
// (get) Token: 0x06003436 RID: 13366 RVA: 0x000B3568 File Offset: 0x000B1768
|
|
public override string PermissionSetName
|
|
{
|
|
get
|
|
{
|
|
return "Same site Web";
|
|
}
|
|
}
|
|
|
|
/// <summary>Adds the specified connection access to the current code group.</summary>
|
|
/// <param name="originScheme">A <see cref="T:System.String" /> containing the scheme to match against the code's scheme.</param>
|
|
/// <param name="connectAccess">A <see cref="T:System.Security.Policy.CodeConnectAccess" /> that specifies the scheme and port code can use to connect back to its origin server.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="originScheme" /> is null.</exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">
|
|
/// <paramref name="originScheme" /> contains characters that are not permitted in schemes.-or-<paramref name="originScheme" /> = <see cref="F:System.Security.Policy.NetCodeGroup.AbsentOriginScheme" /> and <paramref name="connectAccess" /> specifies <see cref="F:System.Security.Policy.CodeConnectAccess.OriginScheme" /> as its scheme.</exception>
|
|
// Token: 0x06003437 RID: 13367 RVA: 0x000B3570 File Offset: 0x000B1770
|
|
[MonoTODO("(2.0) missing validations")]
|
|
public void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
|
|
{
|
|
if (originScheme == null)
|
|
{
|
|
throw new ArgumentException("originScheme");
|
|
}
|
|
if (originScheme == NetCodeGroup.AbsentOriginScheme && connectAccess.Scheme == CodeConnectAccess.OriginScheme)
|
|
{
|
|
throw new ArgumentOutOfRangeException("connectAccess", Locale.GetText("Schema == CodeConnectAccess.OriginScheme"));
|
|
}
|
|
if (this._rules.ContainsKey(originScheme))
|
|
{
|
|
if (connectAccess != null)
|
|
{
|
|
CodeConnectAccess[] array = (CodeConnectAccess[])this._rules[originScheme];
|
|
CodeConnectAccess[] array2 = new CodeConnectAccess[array.Length + 1];
|
|
Array.Copy(array, 0, array2, 0, array.Length);
|
|
array2[array.Length] = connectAccess;
|
|
this._rules[originScheme] = array2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CodeConnectAccess[] array3 = new CodeConnectAccess[] { connectAccess };
|
|
this._rules.Add(originScheme, array3);
|
|
}
|
|
}
|
|
|
|
/// <summary>Makes a deep copy of the current code group.</summary>
|
|
/// <returns>An equivalent copy of the current code group, including its membership conditions and child code groups.</returns>
|
|
// Token: 0x06003438 RID: 13368 RVA: 0x000B3638 File Offset: 0x000B1838
|
|
public override CodeGroup Copy()
|
|
{
|
|
NetCodeGroup netCodeGroup = new NetCodeGroup(base.MembershipCondition);
|
|
netCodeGroup.Name = base.Name;
|
|
netCodeGroup.Description = base.Description;
|
|
netCodeGroup.PolicyStatement = base.PolicyStatement;
|
|
foreach (object obj in base.Children)
|
|
{
|
|
CodeGroup codeGroup = (CodeGroup)obj;
|
|
netCodeGroup.AddChild(codeGroup.Copy());
|
|
}
|
|
return netCodeGroup;
|
|
}
|
|
|
|
// Token: 0x06003439 RID: 13369 RVA: 0x000B36E0 File Offset: 0x000B18E0
|
|
private bool Equals(CodeConnectAccess[] rules1, CodeConnectAccess[] rules2)
|
|
{
|
|
for (int i = 0; i < rules1.Length; i++)
|
|
{
|
|
bool flag = false;
|
|
for (int j = 0; j < rules2.Length; j++)
|
|
{
|
|
if (rules1[i].Equals(rules2[j]))
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!flag)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Determines whether the specified code group is equivalent to the current code group.</summary>
|
|
/// <returns>true if the specified code group is equivalent to the current code group; otherwise, false.</returns>
|
|
/// <param name="o">The <see cref="T:System.Security.Policy.NetCodeGroup" /> object to compare with the current code group.</param>
|
|
// Token: 0x0600343A RID: 13370 RVA: 0x000B3738 File Offset: 0x000B1938
|
|
public override bool Equals(object o)
|
|
{
|
|
if (!base.Equals(o))
|
|
{
|
|
return false;
|
|
}
|
|
NetCodeGroup netCodeGroup = o as NetCodeGroup;
|
|
if (netCodeGroup == null)
|
|
{
|
|
return false;
|
|
}
|
|
foreach (object obj in this._rules)
|
|
{
|
|
DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
|
|
CodeConnectAccess[] array = (CodeConnectAccess[])netCodeGroup._rules[dictionaryEntry.Key];
|
|
bool flag;
|
|
if (array != null)
|
|
{
|
|
flag = this.Equals((CodeConnectAccess[])dictionaryEntry.Value, array);
|
|
}
|
|
else
|
|
{
|
|
flag = dictionaryEntry.Value == null;
|
|
}
|
|
if (!flag)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Gets the connection access information for the current code group.</summary>
|
|
/// <returns>A <see cref="T:System.Collections.DictionaryEntry" /> array containing connection access information.</returns>
|
|
// Token: 0x0600343B RID: 13371 RVA: 0x000B381C File Offset: 0x000B1A1C
|
|
public DictionaryEntry[] GetConnectAccessRules()
|
|
{
|
|
DictionaryEntry[] array = new DictionaryEntry[this._rules.Count];
|
|
this._rules.CopyTo(array, 0);
|
|
return array;
|
|
}
|
|
|
|
/// <returns>The hash code of the current code group.</returns>
|
|
// Token: 0x0600343C RID: 13372 RVA: 0x000B3848 File Offset: 0x000B1A48
|
|
public override int GetHashCode()
|
|
{
|
|
if (this._hashcode == 0)
|
|
{
|
|
this._hashcode = base.GetHashCode();
|
|
foreach (object obj in this._rules)
|
|
{
|
|
CodeConnectAccess[] array = (CodeConnectAccess[])((DictionaryEntry)obj).Value;
|
|
if (array != null)
|
|
{
|
|
foreach (CodeConnectAccess codeConnectAccess in array)
|
|
{
|
|
this._hashcode ^= codeConnectAccess.GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return this._hashcode;
|
|
}
|
|
|
|
/// <summary>Resolves policy for the code group and its descendants for a set of evidence.</summary>
|
|
/// <returns>A <see cref="T:System.Security.Policy.PolicyStatement" /> that consists of the permissions granted by the code group with optional attributes, or null if the code group does not apply (the membership condition does not match the specified evidence).</returns>
|
|
/// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> for the assembly. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="evidence" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.Security.Policy.PolicyException">More than one code group (including the parent code group and any child code groups) is marked <see cref="F:System.Security.Policy.PolicyStatementAttribute.Exclusive" />. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600343D RID: 13373 RVA: 0x000B3918 File Offset: 0x000B1B18
|
|
public override PolicyStatement Resolve(Evidence evidence)
|
|
{
|
|
if (evidence == null)
|
|
{
|
|
throw new ArgumentNullException("evidence");
|
|
}
|
|
if (!base.MembershipCondition.Check(evidence))
|
|
{
|
|
return null;
|
|
}
|
|
PermissionSet permissionSet = null;
|
|
if (base.PolicyStatement == null)
|
|
{
|
|
permissionSet = new PermissionSet(PermissionState.None);
|
|
}
|
|
else
|
|
{
|
|
permissionSet = base.PolicyStatement.PermissionSet.Copy();
|
|
}
|
|
if (base.Children.Count > 0)
|
|
{
|
|
foreach (object obj in base.Children)
|
|
{
|
|
CodeGroup codeGroup = (CodeGroup)obj;
|
|
PolicyStatement policyStatement = codeGroup.Resolve(evidence);
|
|
if (policyStatement != null)
|
|
{
|
|
permissionSet = permissionSet.Union(policyStatement.PermissionSet);
|
|
}
|
|
}
|
|
}
|
|
PolicyStatement policyStatement2 = base.PolicyStatement.Copy();
|
|
policyStatement2.PermissionSet = permissionSet;
|
|
return policyStatement2;
|
|
}
|
|
|
|
/// <summary>Removes all connection access information for the current code group.</summary>
|
|
// Token: 0x0600343E RID: 13374 RVA: 0x000B3A14 File Offset: 0x000B1C14
|
|
public void ResetConnectAccess()
|
|
{
|
|
this._rules.Clear();
|
|
}
|
|
|
|
/// <summary>Resolves matching code groups.</summary>
|
|
/// <returns>A <see cref="T:System.Security.Policy.CodeGroup" />.</returns>
|
|
/// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> for the assembly. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="evidence" /> parameter is null. </exception>
|
|
// Token: 0x0600343F RID: 13375 RVA: 0x000B3A24 File Offset: 0x000B1C24
|
|
public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
|
|
{
|
|
if (evidence == null)
|
|
{
|
|
throw new ArgumentNullException("evidence");
|
|
}
|
|
CodeGroup codeGroup = null;
|
|
if (base.MembershipCondition.Check(evidence))
|
|
{
|
|
codeGroup = this.Copy();
|
|
foreach (object obj in base.Children)
|
|
{
|
|
CodeGroup codeGroup2 = (CodeGroup)obj;
|
|
CodeGroup codeGroup3 = codeGroup2.ResolveMatchingCodeGroups(evidence);
|
|
if (codeGroup3 != null)
|
|
{
|
|
codeGroup.AddChild(codeGroup3);
|
|
}
|
|
}
|
|
}
|
|
return codeGroup;
|
|
}
|
|
|
|
// Token: 0x06003440 RID: 13376 RVA: 0x000B3AD8 File Offset: 0x000B1CD8
|
|
[MonoTODO("(2.0) Add new stuff (CodeConnectAccess) into XML")]
|
|
protected override void CreateXml(SecurityElement element, PolicyLevel level)
|
|
{
|
|
base.CreateXml(element, level);
|
|
}
|
|
|
|
// Token: 0x06003441 RID: 13377 RVA: 0x000B3AE4 File Offset: 0x000B1CE4
|
|
[MonoTODO("(2.0) Parse new stuff (CodeConnectAccess) from XML")]
|
|
protected override void ParseXml(SecurityElement e, PolicyLevel level)
|
|
{
|
|
base.ParseXml(e, level);
|
|
}
|
|
|
|
/// <summary>Contains a value used to specify connection access for code with an unknown or unrecognized origin scheme.</summary>
|
|
// Token: 0x0400155A RID: 5466
|
|
public static readonly string AbsentOriginScheme = string.Empty;
|
|
|
|
/// <summary>Contains a value used to specify any other unspecified origin scheme.</summary>
|
|
// Token: 0x0400155B RID: 5467
|
|
public static readonly string AnyOtherOriginScheme = "*";
|
|
|
|
// Token: 0x0400155C RID: 5468
|
|
private Hashtable _rules = new Hashtable();
|
|
|
|
// Token: 0x0400155D RID: 5469
|
|
private int _hashcode;
|
|
}
|
|
}
|