You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -1 +1 @@
|
||||
16df8b1e453f752136d149af4f886d022e26981b
|
||||
674cdd48519ccfe6647e02616a8fb92824397ce6
|
||||
@@ -67,7 +67,7 @@ namespace System.Security.AccessControl
|
||||
|
||||
#region Constructors
|
||||
|
||||
private ObjectSecurity()
|
||||
protected ObjectSecurity()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace System.Security.AccessControl
|
||||
_securityDescriptor = new CommonSecurityDescriptor( isContainer, isDS, ControlFlags.None, null, null, null, dacl );
|
||||
}
|
||||
|
||||
internal ObjectSecurity( CommonSecurityDescriptor securityDescriptor )
|
||||
protected ObjectSecurity( CommonSecurityDescriptor securityDescriptor )
|
||||
: this()
|
||||
{
|
||||
if ( securityDescriptor == null )
|
||||
|
||||
@@ -171,11 +171,11 @@ namespace System.Security.AccessControl
|
||||
private bool disposed = false;
|
||||
private int referenceCount = 1;
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
private SafeTokenHandle threadHandle = new SafeTokenHandle( IntPtr.Zero );
|
||||
private SafeAccessTokenHandle threadHandle = new SafeAccessTokenHandle( IntPtr.Zero );
|
||||
private bool isImpersonating = false;
|
||||
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
private static volatile SafeTokenHandle processHandle = new SafeTokenHandle( IntPtr.Zero );
|
||||
private static volatile SafeAccessTokenHandle processHandle = new SafeAccessTokenHandle( IntPtr.Zero );
|
||||
private static readonly object syncRoot = new object();
|
||||
|
||||
#region Constructor and Finalizer
|
||||
@@ -201,7 +201,7 @@ namespace System.Security.AccessControl
|
||||
{
|
||||
if ( processHandle.IsInvalid)
|
||||
{
|
||||
SafeTokenHandle localProcessHandle;
|
||||
SafeAccessTokenHandle localProcessHandle;
|
||||
if ( false == Win32Native.OpenProcessToken(
|
||||
Win32Native.GetCurrentProcess(),
|
||||
TokenAccessLevels.Duplicate,
|
||||
@@ -229,7 +229,7 @@ namespace System.Security.AccessControl
|
||||
// the process token by impersonating self.
|
||||
//
|
||||
|
||||
SafeTokenHandle threadHandleBefore = this.threadHandle;
|
||||
SafeAccessTokenHandle threadHandleBefore = this.threadHandle;
|
||||
error = FCall.OpenThreadToken(
|
||||
TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges,
|
||||
WinSecurityContext.Process,
|
||||
@@ -386,7 +386,7 @@ namespace System.Security.AccessControl
|
||||
|
||||
#region Properties
|
||||
|
||||
public SafeTokenHandle ThreadHandle
|
||||
public SafeAccessTokenHandle ThreadHandle
|
||||
{
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
get { return this.threadHandle; }
|
||||
|
||||
@@ -346,16 +346,16 @@ namespace System.Security.AccessControl
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
internal AuthorizationRuleCollection()
|
||||
public AuthorizationRuleCollection()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal methods
|
||||
#region Public methods
|
||||
|
||||
internal void AddRule( AuthorizationRule rule )
|
||||
public void AddRule( AuthorizationRule rule )
|
||||
{
|
||||
InnerList.Add( rule );
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace System.Security.AccessControl
|
||||
SelfRelative = 0x8000, // must always be on
|
||||
}
|
||||
|
||||
|
||||
public abstract class GenericSecurityDescriptor
|
||||
{
|
||||
#region Protected Members
|
||||
@@ -1241,6 +1240,18 @@ namespace System.Security.AccessControl
|
||||
}
|
||||
}
|
||||
|
||||
public void AddDiscretionaryAcl(byte revision, int trusted)
|
||||
{
|
||||
this.DiscretionaryAcl = new DiscretionaryAcl(this.IsContainer, this.IsDS, revision, trusted);
|
||||
this.AddControlFlags(ControlFlags.DiscretionaryAclPresent);
|
||||
}
|
||||
|
||||
public void AddSystemAcl(byte revision, int trusted)
|
||||
{
|
||||
this.SystemAcl = new SystemAcl(this.IsContainer, this.IsDS, revision, trusted);
|
||||
this.AddControlFlags(ControlFlags.SystemAclPresent);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal Methods
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace System.Security.Claims
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
@@ -36,6 +37,9 @@ namespace System.Security.Claims
|
||||
string m_value;
|
||||
string m_valueType;
|
||||
|
||||
[NonSerialized]
|
||||
byte[] m_userSerializationData;
|
||||
|
||||
Dictionary<string, string> m_properties;
|
||||
|
||||
[NonSerialized]
|
||||
@@ -43,9 +47,48 @@ namespace System.Security.Claims
|
||||
|
||||
[NonSerialized]
|
||||
ClaimsIdentity m_subject;
|
||||
|
||||
|
||||
private enum SerializationMask
|
||||
{
|
||||
None = 0,
|
||||
NameClaimType = 1,
|
||||
RoleClaimType = 2,
|
||||
StringType = 4,
|
||||
Issuer = 8,
|
||||
OriginalIssuerEqualsIssuer = 16,
|
||||
OriginalIssuer = 32,
|
||||
HasProperties = 64,
|
||||
UserData = 128,
|
||||
}
|
||||
|
||||
#region Claim Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="Claim"/> using a <see cref="BinaryReader"/>.
|
||||
/// Normally the <see cref="BinaryReader"/> is constructed using the bytes from <see cref="WriteTo(BinaryWriter)"/> and initialized in the same way as the <see cref="BinaryWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="Claim"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
public Claim(BinaryReader reader)
|
||||
: this(reader, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="Claim"/> using a <see cref="BinaryReader"/>.
|
||||
/// Normally the <see cref="BinaryReader"/> is constructed using the bytes from <see cref="WriteTo(BinaryWriter)"/> and initialized in the same way as the <see cref="BinaryWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="Claim"/>.</param>
|
||||
/// <param name="subject"> the value for <see cref="Claim.Subject"/>, which is the <see cref="ClaimsIdentity"/> that has these claims.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
public Claim(BinaryReader reader, ClaimsIdentity subject)
|
||||
{
|
||||
if (reader == null)
|
||||
throw new ArgumentNullException("reader");
|
||||
|
||||
Initialize(reader, subject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Claim"/> with the specified type and value.
|
||||
/// </summary>
|
||||
@@ -203,8 +246,63 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor for <see cref="Claim"/>
|
||||
/// </summary>
|
||||
/// <param name="other">the <see cref="Claim"/> to copy.</param>
|
||||
/// <remarks><see cref="Claim.Subject"/>will be set to 'null'.</remarks>
|
||||
/// <exception cref="ArgumentNullException">if 'other' is null.</exception>
|
||||
protected Claim(Claim other)
|
||||
: this(other, (other == null ? (ClaimsIdentity)null : other.m_subject))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor for <see cref="Claim"/>
|
||||
/// </summary>
|
||||
/// <param name="other">the <see cref="Claim"/> to copy.</param>
|
||||
/// <param name="subject">the <see cref="ClaimsIdentity"/> to assign to <see cref="Claim.Subject"/>.</param>
|
||||
/// <remarks><see cref="Claim.Subject"/>will be set to 'subject'.</remarks>
|
||||
/// <exception cref="ArgumentNullException">if 'other' is null.</exception>
|
||||
protected Claim(Claim other, ClaimsIdentity subject)
|
||||
{
|
||||
if (other == null)
|
||||
throw new ArgumentNullException("other");
|
||||
|
||||
m_issuer = other.m_issuer;
|
||||
m_originalIssuer = other.m_originalIssuer;
|
||||
m_subject = subject;
|
||||
m_type = other.m_type;
|
||||
m_value = other.m_value;
|
||||
m_valueType = other.m_valueType;
|
||||
if (other.m_properties != null)
|
||||
{
|
||||
m_properties = new Dictionary<string, string>();
|
||||
foreach (var key in other.m_properties.Keys)
|
||||
{
|
||||
m_properties.Add(key, other.m_properties[key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (other.m_userSerializationData != null)
|
||||
{
|
||||
m_userSerializationData = other.m_userSerializationData.Clone() as byte[];
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Contains any additional data provided by a derived type, typically set when calling <see cref="WriteTo(BinaryWriter, byte[])"/>.</param>
|
||||
/// </summary>
|
||||
protected virtual byte[] CustomSerializationData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_userSerializationData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the issuer of the <see cref="Claim"/>.
|
||||
/// </summary>
|
||||
@@ -266,6 +364,7 @@ namespace System.Security.Claims
|
||||
/// <summary>
|
||||
/// Gets the claim type of the <see cref="Claim"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="ClaimTypes"/>.
|
||||
public string Type
|
||||
{
|
||||
get { return m_type; }
|
||||
@@ -282,39 +381,233 @@ namespace System.Security.Claims
|
||||
/// <summary>
|
||||
/// Gets the value type of the <see cref="Claim"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="ClaimValueTypes"/>
|
||||
public string ValueType
|
||||
{
|
||||
get { return m_valueType; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Claim"/> object copied from this object. The subject of the new claim object is set to null.
|
||||
/// Creates a new instance <see cref="Claim"/> with values copied from this object.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="Claim"/> object copied from this object.</returns>
|
||||
/// <remarks>This is a shallow copy operation.</remarks>
|
||||
public virtual Claim Clone()
|
||||
{
|
||||
return Clone((ClaimsIdentity)null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Claim"/> object copied from this object. The subject of the new claim object is set to identity.
|
||||
/// Creates a new instance <see cref="Claim"/> with values copied from this object.
|
||||
/// </summary>
|
||||
/// <param name="identity">The <see cref="ClaimsIdentity"/> that this <see cref="Claim"/> is associated with.</param>
|
||||
/// <returns>A new <see cref="Claim"/> object copied from this object.</returns>
|
||||
/// <remarks>This is a shallow copy operation.</remarks>
|
||||
/// <param name="identity">the value for <see cref="Claim.Subject"/>, which is the <see cref="ClaimsIdentity"/> that has these claims.
|
||||
/// <remarks><see cref="Claim.Subject"/> will be set to 'identity'.</remarks>
|
||||
public virtual Claim Clone(ClaimsIdentity identity)
|
||||
{
|
||||
Claim newClaim = new Claim(m_type, m_value, m_valueType, m_issuer, m_originalIssuer, identity);
|
||||
if (m_properties != null)
|
||||
return new Claim(this, identity);
|
||||
}
|
||||
|
||||
private void Initialize(BinaryReader reader, ClaimsIdentity subject)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
foreach (string key in m_properties.Keys)
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
m_subject = subject;
|
||||
|
||||
SerializationMask mask = (SerializationMask)reader.ReadInt32();
|
||||
int numPropertiesRead = 1;
|
||||
int numPropertiesToRead = reader.ReadInt32();
|
||||
m_value = reader.ReadString();
|
||||
|
||||
if ((mask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType)
|
||||
{
|
||||
m_type = ClaimsIdentity.DefaultNameClaimType;
|
||||
}
|
||||
else if ((mask & SerializationMask.RoleClaimType) == SerializationMask.RoleClaimType)
|
||||
{
|
||||
m_type = ClaimsIdentity.DefaultRoleClaimType;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_type = reader.ReadString();
|
||||
numPropertiesRead++;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.StringType) == SerializationMask.StringType)
|
||||
{
|
||||
m_valueType = reader.ReadString();
|
||||
numPropertiesRead++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_valueType = ClaimValueTypes.String;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.Issuer) == SerializationMask.Issuer)
|
||||
{
|
||||
m_issuer = reader.ReadString();
|
||||
numPropertiesRead++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_issuer = ClaimsIdentity.DefaultIssuer;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.OriginalIssuerEqualsIssuer) == SerializationMask.OriginalIssuerEqualsIssuer)
|
||||
{
|
||||
m_originalIssuer = m_issuer;
|
||||
}
|
||||
else if ((mask & SerializationMask.OriginalIssuer) == SerializationMask.OriginalIssuer)
|
||||
{
|
||||
m_originalIssuer = reader.ReadString();
|
||||
numPropertiesRead++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_originalIssuer = ClaimsIdentity.DefaultIssuer;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.HasProperties) == SerializationMask.HasProperties)
|
||||
{
|
||||
//
|
||||
int numProperties = reader.ReadInt32();
|
||||
for (int i = 0; i < numProperties; i++)
|
||||
{
|
||||
newClaim.Properties[key] = m_properties[key];
|
||||
Properties.Add(reader.ReadString(), reader.ReadString());
|
||||
}
|
||||
}
|
||||
|
||||
return newClaim;
|
||||
if ((mask & SerializationMask.UserData) == SerializationMask.UserData)
|
||||
{
|
||||
//
|
||||
int cb = reader.ReadInt32();
|
||||
m_userSerializationData = reader.ReadBytes(cb);
|
||||
numPropertiesRead++;
|
||||
}
|
||||
|
||||
for (int i = numPropertiesRead; i < numPropertiesToRead; i++)
|
||||
{
|
||||
reader.ReadString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <param name="writer">the <see cref="BinaryWriter"/> to use for data storage.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
public virtual void WriteTo(BinaryWriter writer)
|
||||
{
|
||||
WriteTo(writer, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <param name="writer">the <see cref="BinaryWriter"/> to use for data storage.</param>
|
||||
/// <param name="userData">additional data provided by derived type.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
protected virtual void WriteTo(BinaryWriter writer, byte[] userData)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
int numberOfPropertiesWritten = 1;
|
||||
SerializationMask mask = SerializationMask.None;
|
||||
if (string.Equals(m_type, ClaimsIdentity.DefaultNameClaimType))
|
||||
{
|
||||
mask |= SerializationMask.NameClaimType;
|
||||
}
|
||||
else if (string.Equals(m_type, ClaimsIdentity.DefaultRoleClaimType))
|
||||
{
|
||||
mask |= SerializationMask.RoleClaimType;
|
||||
}
|
||||
else
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (!string.Equals(m_valueType, ClaimValueTypes.String, StringComparison.Ordinal))
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.StringType;
|
||||
}
|
||||
|
||||
if (!string.Equals(m_issuer, ClaimsIdentity.DefaultIssuer, StringComparison.Ordinal))
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.Issuer;
|
||||
}
|
||||
|
||||
if (string.Equals(m_originalIssuer, m_issuer, StringComparison.Ordinal))
|
||||
{
|
||||
mask |= SerializationMask.OriginalIssuerEqualsIssuer;
|
||||
}
|
||||
else if (!string.Equals(m_originalIssuer, ClaimsIdentity.DefaultIssuer, StringComparison.Ordinal))
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.OriginalIssuer;
|
||||
}
|
||||
|
||||
if (Properties.Count > 0)
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.HasProperties;
|
||||
}
|
||||
|
||||
//
|
||||
if (userData != null && userData.Length > 0)
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.UserData;
|
||||
}
|
||||
|
||||
writer.Write((Int32)mask);
|
||||
writer.Write((Int32)numberOfPropertiesWritten);
|
||||
writer.Write(m_value);
|
||||
|
||||
if (((mask & SerializationMask.NameClaimType) != SerializationMask.NameClaimType) && ((mask & SerializationMask.RoleClaimType) != SerializationMask.RoleClaimType))
|
||||
{
|
||||
writer.Write(m_type);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.StringType) == SerializationMask.StringType)
|
||||
{
|
||||
writer.Write(m_valueType);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.Issuer) == SerializationMask.Issuer)
|
||||
{
|
||||
writer.Write(m_issuer);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.OriginalIssuer) == SerializationMask.OriginalIssuer)
|
||||
{
|
||||
writer.Write(m_originalIssuer);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.HasProperties) == SerializationMask.HasProperties)
|
||||
{
|
||||
writer.Write(Properties.Count);
|
||||
foreach (var key in Properties.Keys)
|
||||
{
|
||||
writer.Write(key);
|
||||
writer.Write(Properties[key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.UserData) == SerializationMask.UserData)
|
||||
{
|
||||
writer.Write((Int32)userData.Length);
|
||||
writer.Write(userData);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
// <OWNER>[....]</OWNER>
|
||||
// <OWNER>Brentsch</OWNER>
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
// <OWNER>[....]</OWNER>
|
||||
// <OWNER>Brentsch</OWNER>
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
@@ -30,6 +30,22 @@ namespace System.Security.Claims
|
||||
[ComVisible(true)]
|
||||
public class ClaimsIdentity : IIdentity
|
||||
{
|
||||
private enum SerializationMask
|
||||
{
|
||||
None = 0,
|
||||
AuthenticationType = 1,
|
||||
BootstrapConext = 2,
|
||||
NameClaimType = 4,
|
||||
RoleClaimType = 8,
|
||||
HasClaims = 16,
|
||||
HasLabel = 32,
|
||||
Actor = 64,
|
||||
UserData = 128,
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
private byte[] m_userSerializationData;
|
||||
|
||||
[NonSerialized]
|
||||
const string PreFix = "System.Security.ClaimsIdentity.";
|
||||
[NonSerialized]
|
||||
@@ -333,6 +349,49 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes an instance of <see cref="ClaimsIdentity"/> using a <see cref="BinaryReader"/>.
|
||||
/// Normally the reader is constructed from the bytes returned from <see cref="WriteTo"/>
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="ClaimsIdentity"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
public ClaimsIdentity(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
throw new ArgumentNullException("reader");
|
||||
|
||||
Initialize(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor.
|
||||
/// </summary>
|
||||
/// <param name="other"><see cref="ClaimsIdentity"/> to copy.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'other' is null.</exception>
|
||||
protected ClaimsIdentity(ClaimsIdentity other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException("other");
|
||||
}
|
||||
|
||||
if (other.m_actor != null)
|
||||
{
|
||||
m_actor = other.m_actor.Clone();
|
||||
}
|
||||
|
||||
m_authenticationType = other.m_authenticationType;
|
||||
m_bootstrapContext = other.m_bootstrapContext;
|
||||
m_label = other.m_label;
|
||||
m_nameType = other.m_nameType;
|
||||
m_roleType = other.m_roleType;
|
||||
if (other.m_userSerializationData != null)
|
||||
{
|
||||
m_userSerializationData = other.m_userSerializationData.Clone() as byte[];
|
||||
}
|
||||
|
||||
SafeAddClaims(other.m_instanceClaims);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="Identity"/> from a serialized stream created via
|
||||
/// <see cref="ISerializable"/>.
|
||||
@@ -450,6 +509,17 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains any additional data provided by a derived type, typically set when calling <see cref="WriteTo(BinaryWriter, byte[])"/>.</param>
|
||||
/// </summary>
|
||||
protected virtual byte[] CustomSerializationData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_userSerializationData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allow the association of claims with this instance of <see cref="ClaimsIdentity"/>.
|
||||
/// The claims will not be serialized or added in Clone(). They will be included in searches, finds and returned from the call to Claims.
|
||||
@@ -998,6 +1068,203 @@ namespace System.Security.Claims
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes from a <see cref="BinaryReader"/>. Normally the reader is initialized in the same as the one passed to <see cref="Serialize(BinaryWriter)"/>
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="ClaimsIdentity"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
private void Initialize(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
//
|
||||
SerializationMask mask = (SerializationMask)reader.ReadInt32();
|
||||
|
||||
if ((mask & SerializationMask.AuthenticationType) == SerializationMask.AuthenticationType)
|
||||
{
|
||||
m_authenticationType = reader.ReadString();
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.BootstrapConext) == SerializationMask.BootstrapConext)
|
||||
{
|
||||
m_bootstrapContext = reader.ReadString();
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType)
|
||||
{
|
||||
m_nameType = reader.ReadString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nameType = ClaimsIdentity.DefaultNameClaimType;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.RoleClaimType) == SerializationMask.RoleClaimType)
|
||||
{
|
||||
m_roleType = reader.ReadString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_roleType = ClaimsIdentity.DefaultRoleClaimType;
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.HasClaims) == SerializationMask.HasClaims)
|
||||
{
|
||||
//
|
||||
int numberOfClaims = reader.ReadInt32();
|
||||
for (int index = 0; index < numberOfClaims; ++index)
|
||||
{
|
||||
Claim claim = new Claim(reader, this);
|
||||
m_instanceClaims.Add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides and extensibility point for derived types to create a custom <see cref="Claim"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">the <see cref="BinaryReader"/>that points at the claim.</param>
|
||||
/// <returns>a new <see cref="Claim"/>.</returns>
|
||||
protected virtual Claim CreateClaim(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
return new Claim(reader, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <param name="writer">the <see cref="BinaryWriter"/> to use for data storage.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
public virtual void WriteTo(BinaryWriter writer)
|
||||
{
|
||||
WriteTo(writer, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <param name="writer">the <see cref="BinaryWriter"/> to use for data storage.</param>
|
||||
/// <param name="userData">additional data provided by derived type.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
protected virtual void WriteTo(BinaryWriter writer, byte[] userData)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
int numberOfPropertiesWritten = 0;
|
||||
var mask = SerializationMask.None;
|
||||
if (m_authenticationType != null)
|
||||
{
|
||||
mask |= SerializationMask.AuthenticationType;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (m_bootstrapContext != null)
|
||||
{
|
||||
string rawData = m_bootstrapContext as string;
|
||||
if (rawData != null)
|
||||
{
|
||||
mask |= SerializationMask.BootstrapConext;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.Equals(m_nameType, ClaimsIdentity.DefaultNameClaimType, StringComparison.Ordinal))
|
||||
{
|
||||
mask |= SerializationMask.NameClaimType;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (!string.Equals(m_roleType, ClaimsIdentity.DefaultRoleClaimType, StringComparison.Ordinal))
|
||||
{
|
||||
mask |= SerializationMask.RoleClaimType;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(m_label))
|
||||
{
|
||||
mask |= SerializationMask.HasLabel;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (m_instanceClaims.Count > 0)
|
||||
{
|
||||
mask |= SerializationMask.HasClaims;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (m_actor != null)
|
||||
{
|
||||
mask |= SerializationMask.Actor;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (userData != null && userData.Length > 0)
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.UserData;
|
||||
}
|
||||
|
||||
writer.Write((Int32)mask);
|
||||
writer.Write((Int32)numberOfPropertiesWritten);
|
||||
if ((mask & SerializationMask.AuthenticationType) == SerializationMask.AuthenticationType)
|
||||
{
|
||||
writer.Write(m_authenticationType);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.BootstrapConext) == SerializationMask.BootstrapConext)
|
||||
{
|
||||
writer.Write(m_bootstrapContext as string);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType)
|
||||
{
|
||||
writer.Write(m_nameType);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.RoleClaimType) == SerializationMask.RoleClaimType)
|
||||
{
|
||||
writer.Write(m_roleType);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.HasLabel) == SerializationMask.HasLabel)
|
||||
{
|
||||
writer.Write(m_label);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.HasClaims) == SerializationMask.HasClaims)
|
||||
{
|
||||
writer.Write((Int32)m_instanceClaims.Count);
|
||||
foreach (var claim in m_instanceClaims)
|
||||
{
|
||||
claim.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.Actor) == SerializationMask.Actor)
|
||||
{
|
||||
m_actor.WriteTo(writer);
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.UserData) == SerializationMask.UserData)
|
||||
{
|
||||
writer.Write((Int32)userData.Length);
|
||||
writer.Write(userData);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
// <param name="useContext"></param> The reason for this param is due to WindowsIdentity deciding to have an
|
||||
// api that doesn't pass the context to its internal constructor.
|
||||
[SecurityCritical]
|
||||
|
||||
@@ -36,6 +36,16 @@ namespace System.Security.Claims
|
||||
[ComVisible(true)]
|
||||
public class ClaimsPrincipal : IPrincipal
|
||||
{
|
||||
private enum SerializationMask
|
||||
{
|
||||
None = 0,
|
||||
HasIdentities = 1,
|
||||
UserData = 2
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
private byte[] m_userSerializationData;
|
||||
|
||||
[NonSerialized]
|
||||
const string PreFix = "System.Security.ClaimsPrincipal.";
|
||||
[NonSerialized]
|
||||
@@ -230,6 +240,21 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="ClaimsPrincipal"/> using a <see cref="BinaryReader"/>.
|
||||
/// Normally the <see cref="BinaryReader"/> is constructed using the bytes from <see cref="WriteTo(BinaryWriter)"/> and initialized in the same way as the <see cref="BinaryWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="ClaimsPrincipal"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
public ClaimsPrincipal(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
throw new ArgumentNullException("reader");
|
||||
|
||||
Initialize(reader);
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
protected ClaimsPrincipal(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
@@ -241,6 +266,41 @@ namespace System.Security.Claims
|
||||
Deserialize(info, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains any additional data provided by derived type, typically set when calling <see cref="WriteTo(BinaryWriter, byte[])"/>.</param>
|
||||
/// </summary>
|
||||
protected virtual byte[] CustomSerializationData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_userSerializationData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="ClaimsPrincipal"/> with values copied from this object.
|
||||
/// </summary>
|
||||
public virtual ClaimsPrincipal Clone()
|
||||
{
|
||||
return new ClaimsPrincipal(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides and extensibility point for derived types to create a custom <see cref="ClaimsIdentity"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">the <see cref="BinaryReader"/>that points at the claim.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
/// <returns>a new <see cref="ClaimsIdentity"/>.</returns>
|
||||
protected virtual ClaimsIdentity CreateClaimsIdentity(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
return new ClaimsIdentity(reader);
|
||||
}
|
||||
|
||||
#endregion ClaimsPrincipal Constructors
|
||||
|
||||
[OnSerializing()]
|
||||
@@ -717,6 +777,104 @@ namespace System.Security.Claims
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes from a <see cref="BinaryReader"/>. Normally the reader is initialized with the results from <see cref="WriteTo(BinaryWriter)"/>
|
||||
/// Normally the <see cref="BinaryReader"/> is initialized in the same way as the <see cref="BinaryWriter"/> passed to <see cref="WriteTo(BinaryWriter)"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">a <see cref="BinaryReader"/> pointing to a <see cref="ClaimsPrincipal"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'reader' is null.</exception>
|
||||
private void Initialize(BinaryReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
SerializationMask mask = (SerializationMask)reader.ReadInt32();
|
||||
int numPropertiesToRead = reader.ReadInt32();
|
||||
int numPropertiesRead = 0;
|
||||
if ((mask & SerializationMask.HasIdentities) == SerializationMask.HasIdentities)
|
||||
{
|
||||
numPropertiesRead++;
|
||||
int numberOfIdentities = reader.ReadInt32();
|
||||
for (int index = 0; index < numberOfIdentities; ++index)
|
||||
{
|
||||
// directly add to m_identities as that is what we serialized from
|
||||
m_identities.Add(CreateClaimsIdentity(reader));
|
||||
}
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.UserData) == SerializationMask.UserData)
|
||||
{
|
||||
//
|
||||
int cb = reader.ReadInt32();
|
||||
m_userSerializationData = reader.ReadBytes(cb);
|
||||
numPropertiesRead++;
|
||||
}
|
||||
|
||||
for (int i = numPropertiesRead; i < numPropertiesToRead; i++)
|
||||
{
|
||||
reader.ReadString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
public virtual void WriteTo(BinaryWriter writer)
|
||||
{
|
||||
WriteTo(writer, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes using a <see cref="BinaryWriter"/>
|
||||
/// </summary>
|
||||
/// <param name="writer">the <see cref="BinaryWriter"/> to use for data storage.</param>
|
||||
/// <param name="userData">additional data provided by derived type.</param>
|
||||
/// <exception cref="ArgumentNullException">if 'writer' is null.</exception>
|
||||
protected virtual void WriteTo(BinaryWriter writer, byte[] userData)
|
||||
{
|
||||
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
int numberOfPropertiesWritten = 0;
|
||||
var mask = SerializationMask.None;
|
||||
if (m_identities.Count > 0)
|
||||
{
|
||||
mask |= SerializationMask.HasIdentities;
|
||||
numberOfPropertiesWritten++;
|
||||
}
|
||||
|
||||
if (userData != null && userData.Length > 0)
|
||||
{
|
||||
numberOfPropertiesWritten++;
|
||||
mask |= SerializationMask.UserData;
|
||||
}
|
||||
|
||||
writer.Write((Int32)mask);
|
||||
writer.Write((Int32)numberOfPropertiesWritten);
|
||||
if ((mask & SerializationMask.HasIdentities) == SerializationMask.HasIdentities)
|
||||
{
|
||||
writer.Write(m_identities.Count);
|
||||
foreach (var identity in m_identities)
|
||||
{
|
||||
identity.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mask & SerializationMask.UserData) == SerializationMask.UserData)
|
||||
{
|
||||
writer.Write((Int32)userData.Length);
|
||||
writer.Write(userData);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
109
external/referencesource/mscorlib/system/security/cryptography/HashAlgorithmName.cs
vendored
Normal file
109
external/referencesource/mscorlib/system/security/cryptography/HashAlgorithmName.cs
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
// Strongly typed string representing the name of a hash algorithm.
|
||||
// Open ended to allow extensibility while giving the discoverable feel of an enum for common values.
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the name of a cryptographic hash algorithm.
|
||||
/// </summary>
|
||||
/// Asymmetric Algorithms implemented using Microsoft's CNG (Cryptography Next Generation) API
|
||||
/// will interpret the underlying string value as a CNG algorithm identifier:
|
||||
/// * https://msdn.microsoft.com/en-us/library/windows/desktop/aa375534(v=vs.85).aspx
|
||||
///
|
||||
/// As with CNG, the names are case-sensitive.
|
||||
///
|
||||
/// Asymmetric Algorithms implemented using other technologies:
|
||||
/// * Must recognize at least "MD5", "SHA1", "SHA256", "SHA384", and "SHA512".
|
||||
/// * Should recognize additional CNG IDs for any other hash algorithms that they also support.
|
||||
/// </remarks>
|
||||
public struct HashAlgorithmName : IEquatable<HashAlgorithmName>
|
||||
{
|
||||
// Returning a new instance every time is free here since HashAlgorithmName is a struct with
|
||||
// a single string field. The optimized codegen should be equivalent to return "MD5".
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing "MD5"
|
||||
/// </summary>
|
||||
public static HashAlgorithmName MD5 { get { return new HashAlgorithmName("MD5"); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA1"
|
||||
/// </summary>
|
||||
public static HashAlgorithmName SHA1 { get { return new HashAlgorithmName("SHA1"); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA256"
|
||||
/// </summary>
|
||||
public static HashAlgorithmName SHA256 { get { return new HashAlgorithmName("SHA256"); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA384"
|
||||
/// </summary>
|
||||
public static HashAlgorithmName SHA384 { get { return new HashAlgorithmName("SHA384"); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA512"
|
||||
/// </summary>
|
||||
public static HashAlgorithmName SHA512 { get { return new HashAlgorithmName("SHA512"); } }
|
||||
|
||||
private readonly string _name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="HashAlgorithmName" /> representing a custom name.
|
||||
/// </summary>
|
||||
/// <param name="name">The custom hash algorithm name.</param>
|
||||
public HashAlgorithmName(string name)
|
||||
{
|
||||
// Note: No validation because we have to deal with default(HashAlgorithmName) regardless.
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying string representation of the algorithm name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// May be null or empty to indicate that no hash algorithm is applicable.
|
||||
/// </remarks>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _name ?? String.Empty;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HashAlgorithmName && Equals((HashAlgorithmName)obj);
|
||||
}
|
||||
|
||||
public bool Equals(HashAlgorithmName other)
|
||||
{
|
||||
// NOTE: intentionally ordinal and case sensitive, matches CNG.
|
||||
return _name == other._name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _name == null ? 0 : _name.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(HashAlgorithmName left, HashAlgorithmName right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(HashAlgorithmName left, HashAlgorithmName right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
130
external/referencesource/mscorlib/system/security/cryptography/RSAEncryptionPadding.cs
vendored
Normal file
130
external/referencesource/mscorlib/system/security/cryptography/RSAEncryptionPadding.cs
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the padding mode and parameters to use with RSA encryption or decryption operations.
|
||||
/// </summary>
|
||||
public sealed class RSAEncryptionPadding : IEquatable<RSAEncryptionPadding>
|
||||
{
|
||||
private static readonly RSAEncryptionPadding s_pkcs1 = new RSAEncryptionPadding(RSAEncryptionPaddingMode.Pkcs1, default(HashAlgorithmName));
|
||||
private static readonly RSAEncryptionPadding s_oaepSHA1 = CreateOaep(HashAlgorithmName.SHA1);
|
||||
private static readonly RSAEncryptionPadding s_oaepSHA256 = CreateOaep(HashAlgorithmName.SHA256);
|
||||
private static readonly RSAEncryptionPadding s_oaepSHA384 = CreateOaep(HashAlgorithmName.SHA384);
|
||||
private static readonly RSAEncryptionPadding s_oaepSHA512 = CreateOaep(HashAlgorithmName.SHA512);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSAEncryptionPaddingMode.Pkcs1"/> mode.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding Pkcs1 { get { return s_pkcs1; } }
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSAEncryptionPaddingMode.Oaep"/> mode with SHA1 hash algorithm.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding OaepSHA1 { get { return s_oaepSHA1; } }
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSAEncrytpionPaddingMode.Oaep"/> mode with SHA256 hash algorithm.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding OaepSHA256 { get { return s_oaepSHA256; } }
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSAEncrytpionPaddingMode.Oaep"/> mode with SHA384 hash algorithm.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding OaepSHA384 { get { return s_oaepSHA384; } }
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSAEncrytpionPaddingMode.Oaep"/> mode with SHA512 hash algorithm.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding OaepSHA512 { get { return s_oaepSHA512; } }
|
||||
|
||||
private RSAEncryptionPaddingMode _mode;
|
||||
private HashAlgorithmName _oaepHashAlgorithm;
|
||||
|
||||
private RSAEncryptionPadding(RSAEncryptionPaddingMode mode, HashAlgorithmName oaepHashAlgorithm)
|
||||
{
|
||||
_mode = mode;
|
||||
_oaepHashAlgorithm = oaepHashAlgorithm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance instance representing <see cref="RSAEncryptionPaddingMode.Oaep"/>
|
||||
/// with the given hash algorithm.
|
||||
/// </summary>
|
||||
public static RSAEncryptionPadding CreateOaep(HashAlgorithmName hashAlgorithm)
|
||||
{
|
||||
if (String.IsNullOrEmpty(hashAlgorithm.Name))
|
||||
{
|
||||
throw new ArgumentException(Environment.GetResourceString("Cryptography_HashAlgorithmNameNullOrEmpty"), "hashAlgorithm");
|
||||
}
|
||||
|
||||
return new RSAEncryptionPadding(RSAEncryptionPaddingMode.Oaep, hashAlgorithm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the padding mode to use.
|
||||
/// </summary>
|
||||
public RSAEncryptionPaddingMode Mode
|
||||
{
|
||||
get { return _mode; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the padding mode to use in conjunction with <see cref="RSAEncryptionPaddingMode.Oaep"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <see cref="Mode"/> is not <see cref="RSAEncryptionPaddingMode.Oaep"/>, then <see cref="HashAlgorithmName.Name" /> will be null.
|
||||
/// </remarks>
|
||||
public HashAlgorithmName OaepHashAlgorithm
|
||||
{
|
||||
get { return _oaepHashAlgorithm; }
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return CombineHashCodes(_mode.GetHashCode(), _oaepHashAlgorithm.GetHashCode());
|
||||
}
|
||||
|
||||
// Same as non-public Tuple.CombineHashCodes
|
||||
private static int CombineHashCodes(int h1, int h2)
|
||||
{
|
||||
return (((h1 << 5) + h1) ^ h2);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as RSAEncryptionPadding);
|
||||
}
|
||||
|
||||
public bool Equals(RSAEncryptionPadding other)
|
||||
{
|
||||
return other != null
|
||||
&& _mode == other._mode
|
||||
&& _oaepHashAlgorithm == other._oaepHashAlgorithm;
|
||||
}
|
||||
|
||||
public static bool operator ==(RSAEncryptionPadding left, RSAEncryptionPadding right)
|
||||
{
|
||||
if (Object.ReferenceEquals(left, null))
|
||||
{
|
||||
return Object.ReferenceEquals(right, null);
|
||||
}
|
||||
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(RSAEncryptionPadding left, RSAEncryptionPadding right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _mode.ToString() + _oaepHashAlgorithm.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
external/referencesource/mscorlib/system/security/cryptography/RSAEncryptionPaddingMode.cs
vendored
Normal file
32
external/referencesource/mscorlib/system/security/cryptography/RSAEncryptionPaddingMode.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the padding mode to use with RSA encryption or decryption operations.
|
||||
/// </summary>
|
||||
public enum RSAEncryptionPaddingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// PKCS #1 v1.5.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This mode correpsonds to the RSAES-PKCS1-v1_5 encryption scheme described in the PKCS #1 RSA Encryption Standard.
|
||||
/// It is supported for compatibility with existing applications.
|
||||
/// </remarks>
|
||||
Pkcs1,
|
||||
|
||||
/// <summary>
|
||||
/// Optimal Asymmetric Encryption Padding.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This mode corresponds to the RSAES-OEAP encryption scheme described in the PKCS #1 RSA Encryption Standard.
|
||||
/// It is recommended for new applications.
|
||||
/// </remarks>
|
||||
Oaep,
|
||||
}
|
||||
}
|
||||
87
external/referencesource/mscorlib/system/security/cryptography/RSASignaturePadding.cs
vendored
Normal file
87
external/referencesource/mscorlib/system/security/cryptography/RSASignaturePadding.cs
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
// NOTE: This is *currently* 1:1 with the enum, but it exists to reserve room for more options
|
||||
// such as custom # of PSS salt bytes without having to modify other parts of the API
|
||||
// surface.
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the padding mode and parameters to use with RSA signature creation or verification operations.
|
||||
/// </summary>
|
||||
public sealed class RSASignaturePadding : IEquatable<RSASignaturePadding>
|
||||
{
|
||||
private static readonly RSASignaturePadding s_pkcs1 = new RSASignaturePadding(RSASignaturePaddingMode.Pkcs1);
|
||||
private static readonly RSASignaturePadding s_pss = new RSASignaturePadding(RSASignaturePaddingMode.Pss);
|
||||
|
||||
private readonly RSASignaturePaddingMode _mode;
|
||||
|
||||
private RSASignaturePadding(RSASignaturePaddingMode mode)
|
||||
{
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSASignaturePaddingMode.Pkcs1"/> mode.
|
||||
/// </summary>
|
||||
public static RSASignaturePadding Pkcs1
|
||||
{
|
||||
get { return s_pkcs1; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="RSASignaturePaddingMode.Pss"/> mode with the number of salt bytes equal to the size of the hash.
|
||||
/// </summary>
|
||||
public static RSASignaturePadding Pss
|
||||
{
|
||||
get { return s_pss; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the padding mode to use.
|
||||
/// </summary>
|
||||
public RSASignaturePaddingMode Mode
|
||||
{
|
||||
get { return _mode; }
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _mode.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as RSASignaturePadding);
|
||||
}
|
||||
|
||||
public bool Equals(RSASignaturePadding other)
|
||||
{
|
||||
return other != null && _mode == other._mode;
|
||||
}
|
||||
|
||||
public static bool operator ==(RSASignaturePadding left, RSASignaturePadding right)
|
||||
{
|
||||
if (Object.ReferenceEquals(left, null))
|
||||
{
|
||||
return Object.ReferenceEquals(right, null);
|
||||
}
|
||||
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(RSASignaturePadding left, RSASignaturePadding right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _mode.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
external/referencesource/mscorlib/system/security/cryptography/RSASignaturePaddingMode.cs
vendored
Normal file
32
external/referencesource/mscorlib/system/security/cryptography/RSASignaturePaddingMode.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the padding mode to use with RSA signature creation or verification operations.
|
||||
/// </summary>
|
||||
public enum RSASignaturePaddingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// PKCS #1 v1.5.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This corresponds to the RSASSA-PKCS1-v1.5 signature scheme of the PKCS #1 RSA Encryption Standard.
|
||||
/// It is supported for compatibility with existing applications.
|
||||
/// </remarks>
|
||||
Pkcs1,
|
||||
|
||||
/// <summary>
|
||||
/// Probabilistic Signature Scheme.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This corresponds to the RSASSA-PKCS1-v1.5 signature scheme of the PKCS #1 RSA Encryption Standard.
|
||||
/// It is recommended for new applications.
|
||||
/// </remarks>
|
||||
Pss,
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
//
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
[System.Runtime.InteropServices.ComVisible(true)]
|
||||
[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public abstract class AsymmetricAlgorithm : IDisposable {
|
||||
protected int KeySizeValue;
|
||||
protected KeySizes[] LegalKeySizesValue;
|
||||
@@ -71,13 +71,19 @@ namespace System.Security.Cryptography {
|
||||
public virtual KeySizes[] LegalKeySizes {
|
||||
get { return (KeySizes[]) LegalKeySizesValue.Clone(); }
|
||||
}
|
||||
|
||||
public abstract String SignatureAlgorithm {
|
||||
get;
|
||||
|
||||
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
|
||||
public virtual String SignatureAlgorithm {
|
||||
get {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String KeyExchangeAlgorithm {
|
||||
get;
|
||||
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
|
||||
public virtual String KeyExchangeAlgorithm {
|
||||
get {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -98,7 +104,14 @@ namespace System.Security.Cryptography {
|
||||
return (AsymmetricAlgorithm) CryptoConfig.CreateFromName(algName);
|
||||
}
|
||||
|
||||
public abstract void FromXmlString(String xmlString);
|
||||
public abstract String ToXmlString(bool includePrivateParameters);
|
||||
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
|
||||
public virtual void FromXmlString(String xmlString) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
|
||||
public virtual String ToXmlString(bool includePrivateParameters) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
598
external/referencesource/mscorlib/system/security/cryptography/capinative.cs
vendored
Normal file
598
external/referencesource/mscorlib/system/security/cryptography/capinative.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -332,7 +332,7 @@ namespace System.Security.Cryptography {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FEATURE_CRYPTO && FEATURE_X509_SECURESTRINGS
|
||||
#if (FEATURE_CRYPTO && FEATURE_X509_SECURESTRINGS) || FEATURE_CORECLR
|
||||
private SecureString m_keyPassword;
|
||||
public SecureString KeyPassword {
|
||||
get {
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace System.Security.Cryptography {
|
||||
// on Vista and the FIPS registry key downlevel.
|
||||
//
|
||||
|
||||
#if !FEATURE_CORECLR
|
||||
if (Utils._GetEnforceFipsPolicySetting()) {
|
||||
if (Environment.OSVersion.Version.Major >= 6) {
|
||||
bool fipsEnabled;
|
||||
@@ -73,7 +74,9 @@ namespace System.Security.Cryptography {
|
||||
s_haveFipsAlgorithmPolicy = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif // !FEATURE_CORECLR
|
||||
{
|
||||
s_fipsAlgorithmPolicy = false;
|
||||
s_haveFipsAlgorithmPolicy = true;
|
||||
}
|
||||
@@ -194,7 +197,7 @@ namespace System.Security.Cryptography {
|
||||
#if FEATURE_CRYPTO || FEATURE_LEGACYNETCFCRYPTO
|
||||
Type RSACryptoServiceProviderType = typeof(System.Security.Cryptography.RSACryptoServiceProvider);
|
||||
#endif //FEATURE_CRYPTO || FEATURE_LEGACYNETCFCRYPTO
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FEATURE_CORECLR
|
||||
Type DSACryptoServiceProviderType = typeof(System.Security.Cryptography.DSACryptoServiceProvider);
|
||||
Type DESCryptoServiceProviderType = typeof(System.Security.Cryptography.DESCryptoServiceProvider);
|
||||
Type TripleDESCryptoServiceProviderType = typeof(System.Security.Cryptography.TripleDESCryptoServiceProvider);
|
||||
@@ -308,7 +311,7 @@ namespace System.Security.Cryptography {
|
||||
ht.Add("System.Security.Cryptography.RSA", RSACryptoServiceProviderType);
|
||||
ht.Add("System.Security.Cryptography.AsymmetricAlgorithm", RSACryptoServiceProviderType);
|
||||
#endif //FEATURE_CRYPTO || FEATURE_LEGACYNETCFCRYPTO
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FEATURE_CORECLR
|
||||
ht.Add("DSA", DSACryptoServiceProviderType);
|
||||
ht.Add("System.Security.Cryptography.DSA", DSACryptoServiceProviderType);
|
||||
ht.Add("ECDsa", ECDsaCngType);
|
||||
@@ -362,7 +365,7 @@ namespace System.Security.Cryptography {
|
||||
#if FEATURE_CRYPTO || FEATURE_LEGACYNETCFCRYPTO
|
||||
ht.Add("http://www.w3.org/2001/04/xmlenc#sha256", SHA256ManagedType);
|
||||
#endif //FEATURE_CRYPTO || FEATURE_LEGACYNETCFCRYPTO
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FEATURE_CORECLR
|
||||
ht.Add("http://www.w3.org/2001/04/xmlenc#sha512", SHA512ManagedType);
|
||||
ht.Add("http://www.w3.org/2001/04/xmlenc#ripemd160", RIPEMD160ManagedType);
|
||||
|
||||
@@ -461,7 +464,7 @@ namespace System.Security.Cryptography {
|
||||
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
|
||||
private static void InitializeConfigInfo()
|
||||
{
|
||||
#if FEATURE_CRYPTO
|
||||
#if FEATURE_CRYPTO && !FEATURE_CORECLR
|
||||
if (machineNameHT == null)
|
||||
{
|
||||
lock(InternalSyncObject)
|
||||
|
||||
@@ -13,12 +13,7 @@
|
||||
namespace System.Security.Cryptography {
|
||||
[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public abstract class DeriveBytes
|
||||
// On Orcas DeriveBytes is not disposable, so we cannot add the IDisposable implementation to the
|
||||
// CoreCLR mscorlib. However, this type does need to be disposable since subtypes can and do hold onto
|
||||
// native resources. Therefore, on desktop mscorlibs we add an IDisposable implementation.
|
||||
#if !FEATURE_CORECLR
|
||||
: IDisposable
|
||||
#endif // !FEATURE_CORECLR
|
||||
{
|
||||
//
|
||||
// public methods
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user