You've already forked linux-packaging-mono
Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
parent
e9207cf623
commit
ef583813eb
@@ -117,6 +117,7 @@ namespace System.Security.Claims
|
||||
return selectedClaimsIdentity;
|
||||
}
|
||||
|
||||
#if !DISABLE_SECURITY
|
||||
/// <summary>
|
||||
/// Used to set a custom claims principal.
|
||||
/// </summary>
|
||||
@@ -131,6 +132,7 @@ namespace System.Security.Claims
|
||||
|
||||
return new ClaimsPrincipal(Thread.CurrentPrincipal);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static Func<IEnumerable<ClaimsIdentity>, ClaimsIdentity> PrimaryIdentitySelector
|
||||
{
|
||||
@@ -519,6 +521,7 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
|
||||
#if !DISABLE_SECURITY
|
||||
/// <summary>
|
||||
/// Returns the Current Principal by calling a delegate. Users may specify the delegate.
|
||||
/// </summary>
|
||||
@@ -537,6 +540,9 @@ namespace System.Security.Claims
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
public static ClaimsPrincipal Current => throw new PlatformNotSupportedException ();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="IEnumerable{Claim}"/> where each claim is matched by <param name="match"/>.
|
||||
|
||||
@@ -113,5 +113,31 @@ namespace System.Security.Cryptography {
|
||||
public virtual String ToXmlString(bool includePrivateParameters) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#if MONO
|
||||
public virtual byte[] ExportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual byte[] ExportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual byte[] ExportPkcs8PrivateKey () => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual byte[] ExportSubjectPublicKeyInfo () => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<byte> passwordBytes, System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<char> password, System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportPkcs8PrivateKey (System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportSubjectPublicKeyInfo (System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportEncryptedPkcs8PrivateKey (System.ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters, System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportPkcs8PrivateKey (System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportSubjectPublicKeyInfo (System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace System.Security.Cryptography {
|
||||
using System.Security.Util;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
#if MONO
|
||||
using System.Buffers;
|
||||
#endif
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
// DSAParameters is serializable so that one could pass the public parameters
|
||||
@@ -266,5 +269,128 @@ namespace System.Security.Cryptography {
|
||||
{
|
||||
return new ArgumentException(Environment.GetResourceString("Cryptography_HashAlgorithmNameNullOrEmpty"), "hashAlgorithm");
|
||||
}
|
||||
|
||||
#if MONO
|
||||
// these methods were copied from CoreFX for NS2.1 support
|
||||
public static DSA Create(int keySizeInBits)
|
||||
{
|
||||
DSA dsa = Create();
|
||||
|
||||
try
|
||||
{
|
||||
dsa.KeySize = keySizeInBits;
|
||||
return dsa;
|
||||
}
|
||||
catch
|
||||
{
|
||||
dsa.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static DSA Create(DSAParameters parameters)
|
||||
{
|
||||
DSA dsa = Create();
|
||||
|
||||
try
|
||||
{
|
||||
dsa.ImportParameters(parameters);
|
||||
return dsa;
|
||||
}
|
||||
catch
|
||||
{
|
||||
dsa.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TryCreateSignature(ReadOnlySpan<byte> hash, Span<byte> destination, out int bytesWritten)
|
||||
{
|
||||
byte[] sig = CreateSignature(hash.ToArray());
|
||||
if (sig.Length <= destination.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(sig).CopyTo(destination);
|
||||
bytesWritten = sig.Length;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
|
||||
{
|
||||
byte[] array = ArrayPool<byte>.Shared.Rent(data.Length);
|
||||
try
|
||||
{
|
||||
data.CopyTo(array);
|
||||
byte[] hash = HashData(array, 0, data.Length, hashAlgorithm);
|
||||
if (destination.Length >= hash.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(hash).CopyTo(destination);
|
||||
bytesWritten = hash.Length;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(array, 0, data.Length);
|
||||
ArrayPool<byte>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TrySignData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hashAlgorithm.Name))
|
||||
{
|
||||
throw HashAlgorithmNameNullOrEmpty();
|
||||
}
|
||||
|
||||
if (TryHashData(data, destination, hashAlgorithm, out int hashLength) &&
|
||||
TryCreateSignature(destination.Slice(0, hashLength), destination, out bytesWritten))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool VerifyData(ReadOnlySpan<byte> data, ReadOnlySpan<byte> signature, HashAlgorithmName hashAlgorithm)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hashAlgorithm.Name))
|
||||
{
|
||||
throw HashAlgorithmNameNullOrEmpty();
|
||||
}
|
||||
|
||||
for (int i = 256; ; i = checked(i * 2))
|
||||
{
|
||||
int hashLength = 0;
|
||||
byte[] hash = ArrayPool<byte>.Shared.Rent(i);
|
||||
try
|
||||
{
|
||||
if (TryHashData(data, hash, hashAlgorithm, out hashLength))
|
||||
{
|
||||
return VerifySignature(new ReadOnlySpan<byte>(hash, 0, hashLength), signature);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(hash, 0, hashLength);
|
||||
ArrayPool<byte>.Shared.Return(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool VerifySignature(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature) =>
|
||||
VerifySignature(hash.ToArray(), signature.ToArray());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace System.Security.Cryptography {
|
||||
using System.Security.Util;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics.Contracts;
|
||||
#if MONO
|
||||
using System.Buffers;
|
||||
#endif
|
||||
|
||||
// We allow only the public components of an RSAParameters object, the Modulus and Exponent
|
||||
// to be serializable.
|
||||
@@ -338,5 +341,176 @@ namespace System.Security.Cryptography {
|
||||
abstract public RSAParameters ExportParameters(bool includePrivateParameters);
|
||||
|
||||
abstract public void ImportParameters(RSAParameters parameters);
|
||||
|
||||
#if MONO // these methods were copied from CoreFX for NS2.1 support
|
||||
public static RSA Create(int keySizeInBits)
|
||||
{
|
||||
RSA rsa = Create();
|
||||
|
||||
try
|
||||
{
|
||||
rsa.KeySize = keySizeInBits;
|
||||
return rsa;
|
||||
}
|
||||
catch
|
||||
{
|
||||
rsa.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static RSA Create(RSAParameters parameters)
|
||||
{
|
||||
RSA rsa = Create();
|
||||
|
||||
try
|
||||
{
|
||||
rsa.ImportParameters(parameters);
|
||||
return rsa;
|
||||
}
|
||||
catch
|
||||
{
|
||||
rsa.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TryDecrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
|
||||
{
|
||||
byte[] result = Decrypt(data.ToArray(), padding);
|
||||
|
||||
if (destination.Length >= result.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(result).CopyTo(destination);
|
||||
bytesWritten = result.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TryEncrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
|
||||
{
|
||||
byte[] result = Encrypt(data.ToArray(), padding);
|
||||
|
||||
if (destination.Length >= result.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(result).CopyTo(destination);
|
||||
bytesWritten = result.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
|
||||
{
|
||||
byte[] result;
|
||||
byte[] array = ArrayPool<byte>.Shared.Rent(data.Length);
|
||||
try
|
||||
{
|
||||
data.CopyTo(array);
|
||||
result = HashData(array, 0, data.Length, hashAlgorithm);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(array, 0, data.Length);
|
||||
ArrayPool<byte>.Shared.Return(array);
|
||||
}
|
||||
|
||||
if (destination.Length >= result.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(result).CopyTo(destination);
|
||||
bytesWritten = result.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySignHash(ReadOnlySpan<byte> hash, Span<byte> destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
|
||||
{
|
||||
byte[] result = SignHash(hash.ToArray(), hashAlgorithm, padding);
|
||||
|
||||
if (destination.Length >= result.Length)
|
||||
{
|
||||
new ReadOnlySpan<byte>(result).CopyTo(destination);
|
||||
bytesWritten = result.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySignData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hashAlgorithm.Name))
|
||||
{
|
||||
throw HashAlgorithmNameNullOrEmpty();
|
||||
}
|
||||
if (padding == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(padding));
|
||||
}
|
||||
|
||||
if (TryHashData(data, destination, hashAlgorithm, out int hashLength) &&
|
||||
TrySignHash(destination.Slice(0, hashLength), destination, hashAlgorithm, padding, out bytesWritten))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bytesWritten = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool VerifyData(ReadOnlySpan<byte> data, ReadOnlySpan<byte> signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hashAlgorithm.Name))
|
||||
{
|
||||
throw HashAlgorithmNameNullOrEmpty();
|
||||
}
|
||||
if (padding == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(padding));
|
||||
}
|
||||
|
||||
for (int i = 256; ; i = checked(i * 2))
|
||||
{
|
||||
int hashLength = 0;
|
||||
byte[] hash = ArrayPool<byte>.Shared.Rent(i);
|
||||
try
|
||||
{
|
||||
if (TryHashData(data, hash, hashAlgorithm, out hashLength))
|
||||
{
|
||||
return VerifyHash(new ReadOnlySpan<byte>(hash, 0, hashLength), signature, hashAlgorithm, padding);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(hash, 0, hashLength);
|
||||
ArrayPool<byte>.Shared.Return(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool VerifyHash(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding) =>
|
||||
VerifyHash(hash.ToArray(), signature.ToArray(), hashAlgorithm, padding);
|
||||
|
||||
public virtual byte[] ExportRSAPrivateKey () => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual byte[] ExportRSAPublicKey () => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportRSAPrivateKey (System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual void ImportRSAPublicKey (System.ReadOnlySpan<byte> source, out int bytesRead) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportRSAPrivateKey (System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
|
||||
public virtual bool TryExportRSAPublicKey (System.Span<byte> destination, out int bytesWritten) => throw new PlatformNotSupportedException ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user