You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -73,7 +73,10 @@ public partial class CryptoConfig {
|
||||
static Type defaultMAC3DES = typeof (MACTripleDES);
|
||||
// LAMESPEC: undocumented classes (also undocumented in CryptoConfig ;-)
|
||||
static Type defaultDSASigDesc = typeof (DSASignatureDescription);
|
||||
static Type defaultRSASigDesc = typeof (RSAPKCS1SHA1SignatureDescription);
|
||||
static Type defaultRSAPKCS1SHA1SigDesc = typeof (RSAPKCS1SHA1SignatureDescription);
|
||||
static Type defaultRSAPKCS1SHA256SigDesc = typeof (RSAPKCS1SHA256SignatureDescription);
|
||||
static Type defaultRSAPKCS1SHA384SigDesc = typeof (RSAPKCS1SHA384SignatureDescription);
|
||||
static Type defaultRSAPKCS1SHA512SigDesc = typeof (RSAPKCS1SHA512SignatureDescription);
|
||||
static Type defaultRIPEMD160 = typeof (RIPEMD160Managed);
|
||||
static Type defaultHMACMD5 = typeof (HMACMD5);
|
||||
static Type defaultHMACRIPEMD160 = typeof (HMACRIPEMD160);
|
||||
@@ -185,6 +188,9 @@ public partial class CryptoConfig {
|
||||
// LAMESPEC: undocumented URLs in CryptoConfig
|
||||
private const string urlDSASHA1 = urlXmlDsig + "dsa-sha1"; // no space
|
||||
private const string urlRSASHA1 = urlXmlDsig + "rsa-sha1"; // no space
|
||||
private const string urlRSASHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"; // no space
|
||||
private const string urlRSASHA384 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"; // no space
|
||||
private const string urlRSASHA512 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"; // no space
|
||||
private const string urlSHA1 = urlXmlDsig + "sha1"; // no space
|
||||
private const string urlC14N = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
||||
private const string urlC14NWithComments = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
|
||||
@@ -196,6 +202,7 @@ public partial class CryptoConfig {
|
||||
private const string urlExcC14NWithComments = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
|
||||
private const string urlExcC14N = "http://www.w3.org/2001/10/xml-exc-c14n#";
|
||||
private const string urlSHA256 = "http://www.w3.org/2001/04/xmlenc#sha256";
|
||||
private const string urlSHA384 = "http://www.w3.org/2001/04/xmldsig-more#sha384";
|
||||
private const string urlSHA512 = "http://www.w3.org/2001/04/xmlenc#sha512";
|
||||
private const string urlHMACSHA256 = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
|
||||
private const string urlHMACSHA384 = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384";
|
||||
@@ -360,7 +367,10 @@ public partial class CryptoConfig {
|
||||
// add some of the XMLDSIG urls into machine.config (and they make a LOT
|
||||
// of sense for implementing XMLDSIG in System.Security.Cryptography.Xml)
|
||||
algorithms.Add (urlDSASHA1, defaultDSASigDesc);
|
||||
algorithms.Add (urlRSASHA1, defaultRSASigDesc);
|
||||
algorithms.Add (urlRSASHA1, defaultRSAPKCS1SHA1SigDesc);
|
||||
algorithms.Add (urlRSASHA256, defaultRSAPKCS1SHA256SigDesc);
|
||||
algorithms.Add (urlRSASHA384, defaultRSAPKCS1SHA384SigDesc);
|
||||
algorithms.Add (urlRSASHA512, defaultRSAPKCS1SHA512SigDesc);
|
||||
algorithms.Add (urlSHA1, defaultSHA1);
|
||||
unresolved_algorithms.Add (urlC14N, defaultC14N);
|
||||
unresolved_algorithms.Add (urlC14NWithComments, defaultC14NWithComments);
|
||||
@@ -372,7 +382,7 @@ public partial class CryptoConfig {
|
||||
unresolved_algorithms.Add (urlExcC14NWithComments, defaultExcC14NWithComments);
|
||||
unresolved_algorithms.Add (urlXmlDecryption, defaultXmlDecryption);
|
||||
algorithms.Add (urlSHA256, defaultSHA256);
|
||||
// xmlenc does not include a definition for SHA384
|
||||
algorithms.Add (urlSHA384, defaultSHA384);
|
||||
algorithms.Add (urlSHA512, defaultSHA512);
|
||||
algorithms.Add (urlHMACSHA256, defaultHMACSHA256);
|
||||
algorithms.Add (urlHMACSHA384, defaultHMACSHA384);
|
||||
@@ -406,6 +416,15 @@ public partial class CryptoConfig {
|
||||
unresolved_algorithms.Add (nameECDsa_2, defaultECDsa);
|
||||
unresolved_algorithms.Add (nameECDsa_3, defaultECDsa);
|
||||
|
||||
#if MONODROID
|
||||
algorithms.Add (nameSHA1Cng, defaultSHA1);
|
||||
algorithms.Add (nameSHA256Cng, defaultSHA256);
|
||||
algorithms.Add (nameSHA256Provider, defaultSHA256);
|
||||
algorithms.Add (nameSHA384Cng, defaultSHA384);
|
||||
algorithms.Add (nameSHA384Provider, defaultSHA384);
|
||||
algorithms.Add (nameSHA512Cng, defaultSHA512);
|
||||
algorithms.Add (nameSHA512Provider, defaultSHA512);
|
||||
#else
|
||||
unresolved_algorithms.Add (nameSHA1Cng, defaultSHA1Cng);
|
||||
unresolved_algorithms.Add (nameSHA256Cng, defaultSHA256Cng);
|
||||
unresolved_algorithms.Add (nameSHA256Provider, defaultSHA256Provider);
|
||||
@@ -413,6 +432,7 @@ public partial class CryptoConfig {
|
||||
unresolved_algorithms.Add (nameSHA384Provider, defaultSHA384Provider);
|
||||
unresolved_algorithms.Add (nameSHA512Cng, defaultSHA512Cng);
|
||||
unresolved_algorithms.Add (nameSHA512Provider, defaultSHA512Provider);
|
||||
#endif
|
||||
Dictionary<string,string> oid = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// comments here are to match with MS implementation (but not with doc)
|
||||
@@ -421,6 +441,7 @@ public partial class CryptoConfig {
|
||||
oid.Add (managedSHA1, oidSHA1);
|
||||
oid.Add (nameSHA1b, oidSHA1);
|
||||
oid.Add (nameSHA1c, oidSHA1);
|
||||
oid.Add (nameSHA1Cng, oidSHA1);
|
||||
|
||||
oid.Add (nameMD5, oidMD5);
|
||||
oid.Add (nameMD5a, oidMD5);
|
||||
@@ -429,14 +450,20 @@ public partial class CryptoConfig {
|
||||
oid.Add (nameSHA256, oidSHA256);
|
||||
oid.Add (nameSHA256a, oidSHA256);
|
||||
oid.Add (nameSHA256c, oidSHA256);
|
||||
oid.Add (nameSHA256Cng, oidSHA256);
|
||||
oid.Add (nameSHA256Provider, oidSHA256);
|
||||
|
||||
oid.Add (nameSHA384, oidSHA384);
|
||||
oid.Add (nameSHA384a, oidSHA384);
|
||||
oid.Add (nameSHA384c, oidSHA384);
|
||||
oid.Add (nameSHA384Cng, oidSHA384);
|
||||
oid.Add (nameSHA384Provider, oidSHA384);
|
||||
|
||||
oid.Add (nameSHA512, oidSHA512);
|
||||
oid.Add (nameSHA512a, oidSHA512);
|
||||
oid.Add (nameSHA512c, oidSHA512);
|
||||
oid.Add (nameSHA512Cng, oidSHA512);
|
||||
oid.Add (nameSHA512Provider, oidSHA512);
|
||||
|
||||
oid.Add (nameRIPEMD160, oidRIPEMD160);
|
||||
oid.Add (nameRIPEMD160a, oidRIPEMD160);
|
||||
|
@@ -44,6 +44,16 @@ namespace System.Security.Cryptography {
|
||||
[ComVisible (true)]
|
||||
public partial class CryptoConfig {
|
||||
|
||||
public static void AddAlgorithm (Type algorithm, params string[] names)
|
||||
{
|
||||
throw new PlatformNotSupportedException ();
|
||||
}
|
||||
|
||||
public static void AddOID (string oid, params string[] names)
|
||||
{
|
||||
throw new PlatformNotSupportedException ();
|
||||
}
|
||||
|
||||
// try to avoid hitting the CreateFromName overloads to help the linker
|
||||
|
||||
public static object CreateFromName (string name)
|
||||
@@ -133,9 +143,19 @@ namespace System.Security.Cryptography {
|
||||
case "system.security.cryptography.rsapkcs1sha1signaturedescription":
|
||||
case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
|
||||
return new RSAPKCS1SHA1SignatureDescription ();
|
||||
case "system.security.cryptography.rsapkcs1sha256signaturedescription":
|
||||
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":
|
||||
return new RSAPKCS1SHA256SignatureDescription ();
|
||||
case "system.security.cryptography.rsapkcs1sha384signaturedescription":
|
||||
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384":
|
||||
return new RSAPKCS1SHA384SignatureDescription ();
|
||||
case "system.security.cryptography.rsapkcs1sha512signaturedescription":
|
||||
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":
|
||||
return new RSAPKCS1SHA512SignatureDescription ();
|
||||
case "system.security.cryptography.hashalgorithm":
|
||||
case "system.security.cryptography.sha1":
|
||||
case "system.security.cryptography.sha1cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha1cng":
|
||||
case "sha1":
|
||||
case "sha":
|
||||
case "http://www.w3.org/2000/09/xmldsig#sha1":
|
||||
@@ -144,17 +164,24 @@ namespace System.Security.Cryptography {
|
||||
return new SHA1Managed ();
|
||||
case "system.security.cryptography.sha256managed":
|
||||
case "system.security.cryptography.sha256":
|
||||
case "system.security.cryptography.sha256cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha256cng":
|
||||
case "sha256":
|
||||
case "sha-256":
|
||||
case "http://www.w3.org/2001/04/xmlenc#sha256":
|
||||
return new SHA256Managed ();
|
||||
case "system.security.cryptography.sha384managed":
|
||||
case "system.security.cryptography.sha384":
|
||||
case "system.security.cryptography.sha384cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha384cng":
|
||||
case "sha384":
|
||||
case "sha-384":
|
||||
case "http://www.w3.org/2001/04/xmldsig-more#sha384":
|
||||
return new SHA384Managed ();
|
||||
case "system.security.cryptography.sha512managed":
|
||||
case "system.security.cryptography.sha512":
|
||||
case "system.security.cryptography.sha512cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha512cng":
|
||||
case "sha512":
|
||||
case "sha-512":
|
||||
case "http://www.w3.org/2001/04/xmlenc#sha512":
|
||||
@@ -201,6 +228,7 @@ namespace System.Security.Cryptography {
|
||||
|
||||
switch (name.ToLowerInvariant ()) {
|
||||
case "system.security.cryptography.sha1cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha1cng":
|
||||
case "system.security.cryptography.sha1managed":
|
||||
case "system.security.cryptography.sha1":
|
||||
case "sha1":
|
||||
@@ -209,14 +237,20 @@ namespace System.Security.Cryptography {
|
||||
case "system.security.cryptography.md5":
|
||||
case "md5":
|
||||
return "1.2.840.113549.2.5";
|
||||
case "system.security.cryptography.sha256cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha256cng":
|
||||
case "system.security.cryptography.sha256managed":
|
||||
case "system.security.cryptography.sha256":
|
||||
case "sha256":
|
||||
return "2.16.840.1.101.3.4.2.1";
|
||||
case "system.security.cryptography.sha384cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha384cng":
|
||||
case "system.security.cryptography.sha384managed":
|
||||
case "system.security.cryptography.sha384":
|
||||
case "sha384":
|
||||
return "2.16.840.1.101.3.4.2.2";
|
||||
case "system.security.cryptography.sha512cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha512cng":
|
||||
case "system.security.cryptography.sha512managed":
|
||||
case "system.security.cryptography.sha512":
|
||||
case "sha512":
|
||||
|
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// IncrementalHash.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar <marek.safar@gmail.com>
|
||||
//
|
||||
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NETSTANDARD
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
public sealed class IncrementalHash : IDisposable
|
||||
{
|
||||
public IncrementalHash () { }
|
||||
public HashAlgorithmName AlgorithmName { get { throw new NotImplementedException (); } }
|
||||
public void AppendData (byte[] data) { }
|
||||
public void AppendData (byte[] data, int offset, int count) { }
|
||||
public static IncrementalHash CreateHash (HashAlgorithmName hashAlgorithm) { throw new NotImplementedException (); }
|
||||
public static IncrementalHash CreateHMAC (HashAlgorithmName hashAlgorithm, byte[] key) { throw new NotImplementedException (); }
|
||||
public void Dispose () { }
|
||||
public byte[] GetHashAndReset () { throw new NotImplementedException (); }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -40,7 +40,7 @@ using System.Text;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
#if !NET_2_1
|
||||
#if !MOBILE
|
||||
[ComVisible (true)]
|
||||
#endif
|
||||
public sealed class RNGCryptoServiceProvider : RandomNumberGenerator {
|
||||
@@ -58,7 +58,7 @@ namespace System.Security.Cryptography {
|
||||
_handle = RngInitialize (null);
|
||||
Check ();
|
||||
}
|
||||
#if !NET_2_1
|
||||
|
||||
public RNGCryptoServiceProvider (byte[] rgb)
|
||||
{
|
||||
_handle = RngInitialize (rgb);
|
||||
@@ -81,7 +81,7 @@ namespace System.Security.Cryptography {
|
||||
_handle = RngInitialize (Encoding.UTF8.GetBytes (str));
|
||||
Check ();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void Check ()
|
||||
{
|
||||
if (_handle == IntPtr.Zero) {
|
||||
|
@@ -36,8 +36,7 @@ using Mono.Security.Cryptography;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public sealed class RSACryptoServiceProvider : RSA, ICspAsymmetricAlgorithm {
|
||||
public partial class RSACryptoServiceProvider {
|
||||
private const int PROV_RSA_FULL = 1; // from WinCrypt.h
|
||||
private const int AT_KEYEXCHANGE = 1;
|
||||
private const int AT_SIGNATURE = 2;
|
||||
@@ -102,7 +101,7 @@ namespace System.Security.Cryptography {
|
||||
|
||||
// no need to load - it cannot exists
|
||||
var p = new CspParameters (PROV_RSA_FULL);
|
||||
if (useMachineKeyStore)
|
||||
if (UseMachineKeyStore)
|
||||
p.Flags |= CspProviderFlags.UseMachineKeyStore;
|
||||
store = new KeyPairPersistence (p);
|
||||
}
|
||||
@@ -121,13 +120,6 @@ namespace System.Security.Cryptography {
|
||||
FromXmlString (store.KeyValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool useMachineKeyStore;
|
||||
|
||||
public static bool UseMachineKeyStore {
|
||||
get { return useMachineKeyStore; }
|
||||
set { useMachineKeyStore = value; }
|
||||
}
|
||||
|
||||
~RSACryptoServiceProvider ()
|
||||
{
|
||||
@@ -161,11 +153,7 @@ namespace System.Security.Cryptography {
|
||||
public bool PublicOnly {
|
||||
get { return rsa.PublicOnly; }
|
||||
}
|
||||
|
||||
public override string SignatureAlgorithm {
|
||||
get { return "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; }
|
||||
}
|
||||
|
||||
|
||||
public byte[] Decrypt (byte[] rgb, bool fOAEP)
|
||||
{
|
||||
if (rgb == null)
|
||||
@@ -339,6 +327,29 @@ namespace System.Security.Cryptography {
|
||||
return PKCS1.Sign_v15 (this, hash, rgbHash);
|
||||
}
|
||||
|
||||
byte[] SignHash(byte[] rgbHash, int calgHash)
|
||||
{
|
||||
return PKCS1.Sign_v15 (this, InternalHashToHashAlgorithm (calgHash), rgbHash);
|
||||
}
|
||||
|
||||
static HashAlgorithm InternalHashToHashAlgorithm (int calgHash)
|
||||
{
|
||||
switch (calgHash) {
|
||||
case Constants.CALG_MD5:
|
||||
return MD5.Create ();
|
||||
case Constants.CALG_SHA1:
|
||||
return SHA1.Create ();
|
||||
case Constants.CALG_SHA_256:
|
||||
return SHA256.Create ();
|
||||
case Constants.CALG_SHA_384:
|
||||
return SHA384.Create ();
|
||||
case Constants.CALG_SHA_512:
|
||||
return SHA512.Create ();
|
||||
}
|
||||
|
||||
throw new NotImplementedException (calgHash.ToString ());
|
||||
}
|
||||
|
||||
// NOTE: this method can work with ANY configured (OID in machine.config)
|
||||
// HashAlgorithm descendant
|
||||
public bool VerifyData (byte[] buffer, object halg, byte[] signature)
|
||||
@@ -364,6 +375,11 @@ namespace System.Security.Cryptography {
|
||||
HashAlgorithm hash = HashAlgorithm.Create (hashName);
|
||||
return PKCS1.Verify_v15 (this, hash, rgbHash, rgbSignature);
|
||||
}
|
||||
|
||||
bool VerifyHash(byte[] rgbHash, int calgHash, byte[] rgbSignature)
|
||||
{
|
||||
return PKCS1.Verify_v15 (this, InternalHashToHashAlgorithm (calgHash), rgbHash, rgbSignature);
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
@@ -444,7 +460,7 @@ namespace System.Security.Cryptography {
|
||||
|
||||
var p = new CspParameters (PROV_RSA_FULL);
|
||||
p.KeyNumber = keyBlob [5] == 0x24 ? AT_SIGNATURE : AT_KEYEXCHANGE;
|
||||
if (useMachineKeyStore)
|
||||
if (UseMachineKeyStore)
|
||||
p.Flags |= CspProviderFlags.UseMachineKeyStore;
|
||||
store = new KeyPairPersistence (p);
|
||||
}
|
||||
|
Reference in New Issue
Block a user