Files
Dec2017-Script-Dump/System/Net/CredentialCache.cs
T
2026-06-04 11:42:34 +02:00

395 lines
15 KiB
C#

using System;
using System.Collections;
namespace System.Net
{
/// <summary>Provides storage for multiple credentials.</summary>
// Token: 0x0200020A RID: 522
public class CredentialCache : IEnumerable, ICredentials, ICredentialsByHost
{
/// <summary>Creates a new instance of the <see cref="T:System.Net.CredentialCache" /> class.</summary>
// Token: 0x060011CB RID: 4555 RVA: 0x00034E94 File Offset: 0x00033094
public CredentialCache()
{
this.cache = new Hashtable();
this.cacheForHost = new Hashtable();
}
/// <summary>Gets the system credentials of the application.</summary>
/// <returns>An <see cref="T:System.Net.ICredentials" /> that represents the system credentials of the application.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="USERNAME" />
/// </PermissionSet>
// Token: 0x170005D3 RID: 1491
// (get) Token: 0x060011CD RID: 4557 RVA: 0x00034ED0 File Offset: 0x000330D0
[global::System.MonoTODO("Need EnvironmentPermission implementation first")]
public static ICredentials DefaultCredentials
{
get
{
return CredentialCache.empty;
}
}
/// <summary>Gets the network credentials of the current security context.</summary>
/// <returns>An <see cref="T:System.Net.NetworkCredential" /> that represents the network credentials of the current user or application.</returns>
// Token: 0x170005D4 RID: 1492
// (get) Token: 0x060011CE RID: 4558 RVA: 0x00034ED8 File Offset: 0x000330D8
public static NetworkCredential DefaultNetworkCredentials
{
get
{
return CredentialCache.empty;
}
}
/// <summary>Returns the <see cref="T:System.Net.NetworkCredential" /> instance associated with the specified Uniform Resource Identifier (URI) and authentication type.</summary>
/// <returns>A <see cref="T:System.Net.NetworkCredential" /> or, if there is no matching credential in the cache, null.</returns>
/// <param name="uriPrefix">A <see cref="T:System.Uri" /> that specifies the URI prefix of the resources that the credential grants access to. </param>
/// <param name="authType">The authentication scheme used by the resource named in <paramref name="uriPrefix" />. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="uriPrefix" /> or <paramref name="authType" /> is null. </exception>
// Token: 0x060011CF RID: 4559 RVA: 0x00034EE0 File Offset: 0x000330E0
public NetworkCredential GetCredential(global::System.Uri uriPrefix, string authType)
{
int num = -1;
NetworkCredential networkCredential = null;
if (uriPrefix == null || authType == null)
{
return null;
}
string text = uriPrefix.AbsolutePath;
text = text.Substring(0, text.LastIndexOf('/'));
IDictionaryEnumerator enumerator = this.cache.GetEnumerator();
while (enumerator.MoveNext())
{
CredentialCache.CredentialCacheKey credentialCacheKey = enumerator.Key as CredentialCache.CredentialCacheKey;
if (credentialCacheKey.Length > num)
{
if (string.Compare(credentialCacheKey.AuthType, authType, true) == 0)
{
global::System.Uri uriPrefix2 = credentialCacheKey.UriPrefix;
if (!(uriPrefix2.Scheme != uriPrefix.Scheme))
{
if (uriPrefix2.Port == uriPrefix.Port)
{
if (!(uriPrefix2.Host != uriPrefix.Host))
{
if (text.StartsWith(credentialCacheKey.AbsPath))
{
num = credentialCacheKey.Length;
networkCredential = (NetworkCredential)enumerator.Value;
}
}
}
}
}
}
}
return networkCredential;
}
/// <summary>Returns an enumerator that can iterate through the <see cref="T:System.Net.CredentialCache" /> instance.</summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> for the <see cref="T:System.Net.CredentialCache" />.</returns>
// Token: 0x060011D0 RID: 4560 RVA: 0x00034FF4 File Offset: 0x000331F4
public IEnumerator GetEnumerator()
{
return this.cache.Values.GetEnumerator();
}
/// <summary>Adds a <see cref="T:System.Net.NetworkCredential" /> instance to the credential cache for use with protocols other than SMTP and associates it with a Uniform Resource Identifier (URI) prefix and authentication protocol. </summary>
/// <param name="uriPrefix">A <see cref="T:System.Uri" /> that specifies the URI prefix of the resources that the credential grants access to. </param>
/// <param name="authType">The authentication scheme used by the resource named in <paramref name="uriPrefix" />. </param>
/// <param name="cred">The <see cref="T:System.Net.NetworkCredential" /> to add to the credential cache. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="uriPrefix" /> is null. -or- <paramref name="authType" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">The same credentials are added more than once. </exception>
// Token: 0x060011D1 RID: 4561 RVA: 0x00035008 File Offset: 0x00033208
public void Add(global::System.Uri uriPrefix, string authType, NetworkCredential cred)
{
if (uriPrefix == null)
{
throw new ArgumentNullException("uriPrefix");
}
if (authType == null)
{
throw new ArgumentNullException("authType");
}
this.cache.Add(new CredentialCache.CredentialCacheKey(uriPrefix, authType), cred);
}
/// <summary>Deletes a <see cref="T:System.Net.NetworkCredential" /> instance from the cache if it is associated with the specified Uniform Resource Identifier (URI) prefix and authentication protocol.</summary>
/// <param name="uriPrefix">A <see cref="T:System.Uri" /> that specifies the URI prefix of the resources that the credential is used for. </param>
/// <param name="authType">The authentication scheme used by the host named in <paramref name="uriPrefix" />. </param>
// Token: 0x060011D2 RID: 4562 RVA: 0x00035048 File Offset: 0x00033248
public void Remove(global::System.Uri uriPrefix, string authType)
{
if (uriPrefix == null)
{
throw new ArgumentNullException("uriPrefix");
}
if (authType == null)
{
throw new ArgumentNullException("authType");
}
this.cache.Remove(new CredentialCache.CredentialCacheKey(uriPrefix, authType));
}
/// <summary>Returns the <see cref="T:System.Net.NetworkCredential" /> instance associated with the specified host, port, and authentication protocol.</summary>
/// <returns>A <see cref="T:System.Net.NetworkCredential" /> or, if there is no matching credential in the cache, null.</returns>
/// <param name="host">A <see cref="T:System.String" /> that identifies the host computer.</param>
/// <param name="port">A <see cref="T:System.Int32" /> that specifies the port to connect to on <paramref name="host" />.</param>
/// <param name="authenticationType">A <see cref="T:System.String" /> that identifies the authentication scheme used when connecting to <paramref name="host" />. See Remarks.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="host" /> is null. -or- <paramref name="authType" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="authType" /> not an accepted value. See Remarks. -or-<paramref name="host" /> is equal to the empty string ("").</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="port" /> is less than zero.</exception>
// Token: 0x060011D3 RID: 4563 RVA: 0x00035090 File Offset: 0x00033290
public NetworkCredential GetCredential(string host, int port, string authenticationType)
{
NetworkCredential networkCredential = null;
if (host == null || port < 0 || authenticationType == null)
{
return null;
}
IDictionaryEnumerator enumerator = this.cacheForHost.GetEnumerator();
while (enumerator.MoveNext())
{
CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = enumerator.Key as CredentialCache.CredentialCacheForHostKey;
if (string.Compare(credentialCacheForHostKey.AuthType, authenticationType, true) == 0)
{
if (!(credentialCacheForHostKey.Host != host))
{
if (credentialCacheForHostKey.Port == port)
{
networkCredential = (NetworkCredential)enumerator.Value;
}
}
}
}
return networkCredential;
}
/// <summary>Adds a <see cref="T:System.Net.NetworkCredential" /> instance for use with SMTP to the credential cache and associates it with a host computer, port, and authentication protocol. Credentials added using this method are valid for SMTP only. This method does not work for HTTP or FTP requests.</summary>
/// <param name="host">A <see cref="T:System.String" /> that identifies the host computer.</param>
/// <param name="port">A <see cref="T:System.Int32" /> that specifies the port to connect to on <paramref name="host" />.</param>
/// <param name="authenticationType">A <see cref="T:System.String" /> that identifies the authentication scheme used when connecting to <paramref name="host" /> using <paramref name="cred" />. See Remarks.</param>
/// <param name="credential">The <see cref="T:System.Net.NetworkCredential" /> to add to the credential cache. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="host" /> is null. -or-<paramref name="authType" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="authType" /> not an accepted value. See Remarks. </exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="port" /> is less than zero.</exception>
// Token: 0x060011D4 RID: 4564 RVA: 0x00035128 File Offset: 0x00033328
public void Add(string host, int port, string authenticationType, NetworkCredential credential)
{
if (host == null)
{
throw new ArgumentNullException("host");
}
if (port < 0)
{
throw new ArgumentOutOfRangeException("port");
}
if (authenticationType == null)
{
throw new ArgumentOutOfRangeException("authenticationType");
}
this.cacheForHost.Add(new CredentialCache.CredentialCacheForHostKey(host, port, authenticationType), credential);
}
/// <summary>Deletes a <see cref="T:System.Net.NetworkCredential" /> instance from the cache if it is associated with the specified host, port, and authentication protocol.</summary>
/// <param name="host">A <see cref="T:System.String" /> that identifies the host computer.</param>
/// <param name="port">A <see cref="T:System.Int32" /> that specifies the port to connect to on <paramref name="host" />.</param>
/// <param name="authenticationType">A <see cref="T:System.String" /> that identifies the authentication scheme used when connecting to <paramref name="host" />. See Remarks.</param>
// Token: 0x060011D5 RID: 4565 RVA: 0x00035180 File Offset: 0x00033380
public void Remove(string host, int port, string authenticationType)
{
if (host == null)
{
return;
}
if (authenticationType == null)
{
return;
}
this.cacheForHost.Remove(new CredentialCache.CredentialCacheForHostKey(host, port, authenticationType));
}
// Token: 0x04000F94 RID: 3988
private static NetworkCredential empty = new NetworkCredential(string.Empty, string.Empty, string.Empty);
// Token: 0x04000F95 RID: 3989
private Hashtable cache;
// Token: 0x04000F96 RID: 3990
private Hashtable cacheForHost;
// Token: 0x0200020B RID: 523
private class CredentialCacheKey
{
// Token: 0x060011D6 RID: 4566 RVA: 0x000351A4 File Offset: 0x000333A4
internal CredentialCacheKey(global::System.Uri uriPrefix, string authType)
{
this.uriPrefix = uriPrefix;
this.authType = authType;
this.absPath = uriPrefix.AbsolutePath;
this.absPath = this.absPath.Substring(0, this.absPath.LastIndexOf('/'));
this.len = uriPrefix.AbsoluteUri.Length;
this.hash = uriPrefix.GetHashCode() + authType.GetHashCode();
}
// Token: 0x170005D5 RID: 1493
// (get) Token: 0x060011D7 RID: 4567 RVA: 0x00035214 File Offset: 0x00033414
public int Length
{
get
{
return this.len;
}
}
// Token: 0x170005D6 RID: 1494
// (get) Token: 0x060011D8 RID: 4568 RVA: 0x0003521C File Offset: 0x0003341C
public string AbsPath
{
get
{
return this.absPath;
}
}
// Token: 0x170005D7 RID: 1495
// (get) Token: 0x060011D9 RID: 4569 RVA: 0x00035224 File Offset: 0x00033424
public global::System.Uri UriPrefix
{
get
{
return this.uriPrefix;
}
}
// Token: 0x170005D8 RID: 1496
// (get) Token: 0x060011DA RID: 4570 RVA: 0x0003522C File Offset: 0x0003342C
public string AuthType
{
get
{
return this.authType;
}
}
// Token: 0x060011DB RID: 4571 RVA: 0x00035234 File Offset: 0x00033434
public override int GetHashCode()
{
return this.hash;
}
// Token: 0x060011DC RID: 4572 RVA: 0x0003523C File Offset: 0x0003343C
public override bool Equals(object obj)
{
CredentialCache.CredentialCacheKey credentialCacheKey = obj as CredentialCache.CredentialCacheKey;
return credentialCacheKey != null && this.hash == credentialCacheKey.hash;
}
// Token: 0x060011DD RID: 4573 RVA: 0x00035268 File Offset: 0x00033468
public override string ToString()
{
return string.Concat(new object[] { this.absPath, " : ", this.authType, " : len=", this.len });
}
// Token: 0x04000F97 RID: 3991
private global::System.Uri uriPrefix;
// Token: 0x04000F98 RID: 3992
private string authType;
// Token: 0x04000F99 RID: 3993
private string absPath;
// Token: 0x04000F9A RID: 3994
private int len;
// Token: 0x04000F9B RID: 3995
private int hash;
}
// Token: 0x0200020C RID: 524
private class CredentialCacheForHostKey
{
// Token: 0x060011DE RID: 4574 RVA: 0x000352A8 File Offset: 0x000334A8
internal CredentialCacheForHostKey(string host, int port, string authType)
{
this.host = host;
this.port = port;
this.authType = authType;
this.hash = host.GetHashCode() + port.GetHashCode() + authType.GetHashCode();
}
// Token: 0x170005D9 RID: 1497
// (get) Token: 0x060011DF RID: 4575 RVA: 0x000352EC File Offset: 0x000334EC
public string Host
{
get
{
return this.host;
}
}
// Token: 0x170005DA RID: 1498
// (get) Token: 0x060011E0 RID: 4576 RVA: 0x000352F4 File Offset: 0x000334F4
public int Port
{
get
{
return this.port;
}
}
// Token: 0x170005DB RID: 1499
// (get) Token: 0x060011E1 RID: 4577 RVA: 0x000352FC File Offset: 0x000334FC
public string AuthType
{
get
{
return this.authType;
}
}
// Token: 0x060011E2 RID: 4578 RVA: 0x00035304 File Offset: 0x00033504
public override int GetHashCode()
{
return this.hash;
}
// Token: 0x060011E3 RID: 4579 RVA: 0x0003530C File Offset: 0x0003350C
public override bool Equals(object obj)
{
CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = obj as CredentialCache.CredentialCacheForHostKey;
return credentialCacheForHostKey != null && this.hash == credentialCacheForHostKey.hash;
}
// Token: 0x060011E4 RID: 4580 RVA: 0x00035338 File Offset: 0x00033538
public override string ToString()
{
return this.host + " : " + this.authType;
}
// Token: 0x04000F9C RID: 3996
private string host;
// Token: 0x04000F9D RID: 3997
private int port;
// Token: 0x04000F9E RID: 3998
private string authType;
// Token: 0x04000F9F RID: 3999
private int hash;
}
}
}