15 [OptionalField(VersionAdded = 2)]
18 [OptionalField(VersionAdded = 2)]
21 private const string c_IgnoreUserInfo =
"";
23 private const string c_AnyScheme =
"([0-9a-z+\\-\\.]+)://";
25 private static readonly
char[] c_SomeRegexChars =
new char[12]
60 [Conditional(
"_DEBUG")]
61 private static void DEBUG_OUT(
string str)
72 internal NetCodeGroup()
104 if (originScheme ==
null)
116 if (m_schemesList ==
null)
122 for (
int i = 0; i < m_schemesList.Count; i++)
124 if (!((
string)m_schemesList[i] == originScheme))
128 if (connectAccess ==
null)
133 for (i = 0; i < arrayList.
Count; i++)
140 arrayList.
Add(connectAccess);
143 m_schemesList.Add(originScheme);
145 m_accessList.
Add(arrayList2);
146 if (connectAccess !=
null)
148 arrayList2.
Add(connectAccess);
156 if (m_schemesList ==
null)
161 for (
int i = 0; i < array.Length; i++)
163 array[i].Key = m_schemesList[i];
174 [SecuritySafeCritical]
177 if (evidence ==
null)
181 object usedEvidence =
null;
182 if (PolicyManager.CheckMembershipCondition(base.MembershipCondition, evidence, out usedEvidence))
185 IDelayEvaluatedEvidence delayEvaluatedEvidence = usedEvidence as IDelayEvaluatedEvidence;
186 if (delayEvaluatedEvidence !=
null && !delayEvaluatedEvidence.IsVerified)
188 policyStatement.AddDependentEvidence(delayEvaluatedEvidence);
191 IEnumerator enumerator = base.Children.GetEnumerator();
192 while (enumerator.
MoveNext() && !flag)
195 if (policyStatement2 !=
null)
197 policyStatement.InplaceUnion(policyStatement2);
204 return policyStatement;
211 if (evidence ==
null)
215 if (base.MembershipCondition.Check(evidence))
217 return CalculateAssemblyPolicy(evidence);
228 if (evidence ==
null)
232 if (base.MembershipCondition.Check(evidence))
236 IEnumerator enumerator = base.Children.GetEnumerator();
240 if (codeGroup2 !=
null)
250 private string EscapeStringForRegex(
string str)
255 while (num < str.Length && (num2 = str.IndexOfAny(c_SomeRegexChars, num)) != -1)
257 if (stringBuilder ==
null)
264 if (stringBuilder ==
null)
268 if (num < str.Length)
270 stringBuilder.
Append(str, num, str.Length - num);
275 internal SecurityElement CreateWebPermission(
string host,
string scheme,
string port,
string assemblyOverride)
279 scheme =
string.Empty;
281 if (host ==
null || host.Length == 0)
288 if (port !=
null && port.Length != 0)
296 CodeConnectAccess[] array = FindAccessRulesForScheme(scheme);
297 if (array ==
null || array.Length == 0)
301 SecurityElement securityElement =
new SecurityElement(
"IPermission");
302 string str = (assemblyOverride ==
null) ?
"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" : assemblyOverride;
303 securityElement.AddAttribute(
"class",
"System.Net.WebPermission, " + str);
304 securityElement.AddAttribute(
"version",
"1");
305 SecurityElement securityElement2 =
new SecurityElement(
"ConnectAccess");
306 host = EscapeStringForRegex(host);
307 scheme = EscapeStringForRegex(scheme);
308 string text = TryPermissionAsOneString(array, scheme, host, intPort);
311 SecurityElement securityElement3 =
new SecurityElement(
"URI");
312 securityElement3.AddAttribute(
"uri", text);
313 securityElement2.AddChild(securityElement3);
317 if (port.Length != 0)
321 for (
int i = 0; i < array.Length; i++)
323 text = GetPermissionAccessElementString(array[i], scheme, host, port);
324 SecurityElement securityElement4 =
new SecurityElement(
"URI");
325 securityElement4.AddAttribute(
"uri", text);
326 securityElement2.AddChild(securityElement4);
329 securityElement.AddChild(securityElement2);
330 return securityElement;
333 private CodeConnectAccess[] FindAccessRulesForScheme(
string lowerCaseScheme)
335 if (m_schemesList ==
null)
339 int num = m_schemesList.IndexOf(lowerCaseScheme);
345 return (CodeConnectAccess[])arrayList.
ToArray(typeof(CodeConnectAccess));
348 private string TryPermissionAsOneString(CodeConnectAccess[] access,
string escapedScheme,
string escapedHost,
int intPort)
354 for (
int i = 0; i < access.Length; i++)
356 flag &= (access[i].IsDefaultPort || (access[i].IsOriginPort && intPort == -1));
357 flag2 &= (access[i].IsOriginPort || access[i].Port == intPort);
358 if (access[i].Port >= 0)
362 num = access[i].Port;
364 else if (access[i].Port != num)
373 if (access[i].IsAnyScheme)
378 if (!flag && !flag2 && num == -1)
382 StringBuilder stringBuilder =
new StringBuilder(
"([0-9a-z+\\-\\.]+)://".Length * access.Length +
"".Length * 2 + escapedHost.Length);
385 stringBuilder.
Append(
"([0-9a-z+\\-\\.]+)://");
389 stringBuilder.
Append(
'(');
390 for (
int j = 0; j < access.Length; j++)
393 for (k = 0; k < j && !(access[j].Scheme == access[k].Scheme); k++)
400 stringBuilder.
Append(
'|');
402 stringBuilder.
Append(access[j].IsOriginScheme ? escapedScheme : EscapeStringForRegex(access[j].Scheme));
405 stringBuilder.
Append(
")://");
419 stringBuilder.
Append(
"/.*");
423 private string GetPermissionAccessElementString(CodeConnectAccess access,
string escapedScheme,
string escapedHost,
string strPort)
426 if (access.IsAnyScheme)
428 stringBuilder.
Append(
"([0-9a-z+\\-\\.]+)://");
430 else if (access.IsOriginScheme)
436 stringBuilder.
Append(EscapeStringForRegex(access.Scheme)).
Append(
"://");
439 if (!access.IsDefaultPort)
441 if (access.IsOriginPort)
443 stringBuilder.
Append(strPort);
450 stringBuilder.
Append(
"/.*");
454 internal PolicyStatement CalculatePolicy(
string host,
string scheme,
string port)
456 SecurityElement securityElement = CreateWebPermission(host, scheme, port,
null);
457 SecurityElement securityElement2 =
new SecurityElement(
"PolicyStatement");
458 SecurityElement securityElement3 =
new SecurityElement(
"PermissionSet");
459 securityElement3.AddAttribute(
"class",
"System.Security.PermissionSet");
460 securityElement3.AddAttribute(
"version",
"1");
461 if (securityElement !=
null)
463 securityElement3.AddChild(securityElement);
465 securityElement2.AddChild(securityElement3);
467 policyStatement.FromXml(securityElement2);
468 return policyStatement;
474 Url hostEvidence = evidence.GetHostEvidence<Url>();
475 if (hostEvidence !=
null)
477 policyStatement = CalculatePolicy(hostEvidence.GetURLString().Host, hostEvidence.GetURLString().Scheme, hostEvidence.GetURLString().Port);
479 if (policyStatement ==
null)
481 Site hostEvidence2 = evidence.GetHostEvidence<
Site>();
482 if (hostEvidence2 !=
null)
484 policyStatement = CalculatePolicy(hostEvidence2.Name,
null,
null);
487 if (policyStatement ==
null)
491 return policyStatement;
499 netCodeGroup.
Name = base.Name;
501 if (m_schemesList !=
null)
505 for (
int i = 0; i < m_accessList.
Count; i++)
510 IEnumerator enumerator = base.Children.GetEnumerator();
529 if (netCodeGroup ==
null || !base.
Equals((
object)netCodeGroup))
533 if (m_schemesList ==
null != (netCodeGroup.m_schemesList ==
null))
537 if (m_schemesList ==
null)
541 if (m_schemesList.Count != netCodeGroup.m_schemesList.Count)
545 for (
int i = 0; i < m_schemesList.Count; i++)
547 int num = netCodeGroup.m_schemesList.
IndexOf(m_schemesList[i]);
558 for (
int j = 0; j < arrayList.
Count; j++)
560 if (!arrayList2.
Contains(arrayList[j]))
573 return base.GetHashCode() + GetRulesHashCode();
576 private int GetRulesHashCode()
578 if (m_schemesList ==
null)
583 for (
int i = 0; i < m_schemesList.Count; i++)
585 num += ((string)m_schemesList[i]).GetHashCode();
587 foreach (
ArrayList access
in m_accessList)
589 for (
int j = 0; j < access.
Count; j++)
591 num += ((CodeConnectAccess)access[j]).GetHashCode();
600 if (connectAccessRules ==
null)
606 for (
int i = 0; i < array.Length; i++)
615 securityElement3.
AddAttribute(
"scheme", codeConnectAccess.Scheme);
616 securityElement3.
AddAttribute(
"port", codeConnectAccess.StrPort);
617 securityElement2.
AddChild(securityElement3);
619 securityElement.
AddChild(securityElement2);
628 if (securityElement ==
null || securityElement.
Children ==
null)
636 if (child.
Tag.Equals(
"codeOrigin"))
638 string originScheme = child.Attribute(
"scheme");
644 if (child2.
Tag.Equals(
"connectAccess"))
646 string allowScheme = child2.Attribute(
"scheme");
647 string allowPort = child2.Attribute(
"port");
662 internal override string GetTypeName()
664 return "System.Security.Policy.NetCodeGroup";
667 private void SetDefaults()
670 AddConnectAccess(
"http",
new CodeConnectAccess(
"http", CodeConnectAccess.OriginPort));
671 AddConnectAccess(
"http",
new CodeConnectAccess(
"https", CodeConnectAccess.OriginPort));
672 AddConnectAccess(
"https",
new CodeConnectAccess(
"https", CodeConnectAccess.OriginPort));
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
abstract CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
When overridden in a derived class, resolves matching code groups.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Specifies that the object graph is being cloned. Users can assume that the cloned graph will continue...
override void CreateXml(SecurityElement element, PolicyLevel level)
When overridden in a derived class, serializes properties and internal state specific to a derived co...
bool MoveNext()
Advances the enumerator to the next element of the collection.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
override void ParseXml(SecurityElement e, PolicyLevel level)
When overridden in a derived class, reconstructs properties and internal state specific to a derived ...
void AddConnectAccess(string originScheme, CodeConnectAccess connectAccess)
Adds the specified connection access to the current code group.
Represents the security policy levels for the common language runtime. This class cannot be inherited...
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
PolicyStatementAttribute
Defines special attribute flags for security policy on code groups.
override string PermissionSetName
Gets the name of the T:System.Security.NamedPermissionSet for the code group.
string Name
Gets or sets the name of the code group.
SecurityElement SearchForChildByTag(string tag)
Finds a child by its tag name.
static readonly string AbsentOriginScheme
Contains a value used to specify connection access for code with an unknown or unrecognized origin sc...
void ResetConnectAccess()
Removes all connection access information for the current code group.
virtual object Clone()
Creates a shallow copy of the T:System.Collections.ArrayList.
Grants Web permission to the site from which the assembly was downloaded. This class cannot be inheri...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
string Tag
Gets or sets the tag name of an XML element.
Represents the statement of a T:System.Security.Policy.CodeGroup describing the permissions and other...
void AddChild(CodeGroup group)
Adds a child code group to the current code group.
static readonly string AnyScheme
Contains the string value that represents the scheme wildcard.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
Provides information about, and means to manipulate, the current environment and platform....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
IList Children
Gets or sets an ordered list of the child code groups of a code group.
virtual bool Contains(object item)
Determines whether an element is in the T:System.Collections.ArrayList.
Specifies the network resource access that is granted to code.
Defines the test to determine whether a code assembly is a member of a code group.
Represents the XML object model for encoding security objects. This class cannot be inherited.
string Description
Gets or sets the description of the code group.
object Current
Gets the element in the collection at the current position of the enumerator.
Represents the abstract base class from which all implementations of code groups must derive.
PolicyStatement PolicyStatement
Gets or sets the policy statement associated with the code group.
override PolicyStatement Resolve(Evidence evidence)
Resolves policy for the code group and its descendants for a set of evidence.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
Resolves matching code groups.
override int GetHashCode()
Gets the hash code of the current code group.
NetCodeGroup(IMembershipCondition membershipCondition)
Initializes a new instance of the T:System.Security.Policy.NetCodeGroup class.
override string MergeLogic
Gets the logic to use for merging groups.
Defines the set of information that constitutes input to security policy decisions....
object Value
Gets or sets the value in the key/value pair.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
ArrayList Children
Gets or sets the array of child elements of the XML element.
static readonly string AnyOtherOriginScheme
Contains a value used to specify any other unspecified origin scheme.
object Key
Gets or sets the key in the key/value pair.
Provides information about a specific culture (called a locale for unmanaged code development)....
virtual int IndexOf(object value)
Searches for the specified T:System.Object and returns the zero-based index of the first occurrence w...
Defines a dictionary key/value pair that can be set or retrieved.
PolicyStatementAttribute Attributes
Gets or sets the attributes of the policy statement.
override bool Equals(object o)
Determines whether the specified code group is equivalent to the current code group.
override CodeGroup Copy()
Makes a deep copy of the current code group.
Supports a simple iteration over a non-generic collection.
override string AttributeString
Gets a string representation of the attributes of the policy statement for the code group.
virtual object [] ToArray()
Copies the elements of the T:System.Collections.ArrayList to a new T:System.Object array.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
DictionaryEntry [] GetConnectAccessRules()
Gets the connection access information for the current code group.