mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-16 02:58:25 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.Kdf;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <remarks>
|
||||
/// Utility class for creating IBasicAgreement objects from their names/Oids
|
||||
/// </remarks>
|
||||
public static class AgreementUtilities
|
||||
{
|
||||
private static readonly IDictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static AgreementUtilities()
|
||||
{
|
||||
Algorithms[X9ObjectIdentifiers.DHSinglePassCofactorDHSha1KdfScheme.Id] = "ECCDHWITHSHA1KDF";
|
||||
Algorithms[X9ObjectIdentifiers.DHSinglePassStdDHSha1KdfScheme.Id] = "ECDHWITHSHA1KDF";
|
||||
Algorithms[X9ObjectIdentifiers.MqvSinglePassSha1KdfScheme.Id] = "ECMQVWITHSHA1KDF";
|
||||
|
||||
Algorithms[EdECObjectIdentifiers.id_X25519.Id] = "X25519";
|
||||
Algorithms[EdECObjectIdentifiers.id_X448.Id] = "X448";
|
||||
}
|
||||
|
||||
public static IBasicAgreement GetBasicAgreement(
|
||||
DerObjectIdentifier oid)
|
||||
{
|
||||
return GetBasicAgreement(oid.Id);
|
||||
}
|
||||
|
||||
public static IBasicAgreement GetBasicAgreement(
|
||||
string algorithm)
|
||||
{
|
||||
string mechanism = GetMechanism(algorithm);
|
||||
|
||||
if (mechanism == "DH" || mechanism == "DIFFIEHELLMAN")
|
||||
return new DHBasicAgreement();
|
||||
|
||||
if (mechanism == "ECDH")
|
||||
return new ECDHBasicAgreement();
|
||||
|
||||
if (mechanism == "ECDHC" || mechanism == "ECCDH")
|
||||
return new ECDHCBasicAgreement();
|
||||
|
||||
if (mechanism == "ECMQV")
|
||||
return new ECMqvBasicAgreement();
|
||||
|
||||
throw new SecurityUtilityException("Basic Agreement " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static IBasicAgreement GetBasicAgreementWithKdf(
|
||||
DerObjectIdentifier oid,
|
||||
string wrapAlgorithm)
|
||||
{
|
||||
return GetBasicAgreementWithKdf(oid.Id, wrapAlgorithm);
|
||||
}
|
||||
|
||||
public static IBasicAgreement GetBasicAgreementWithKdf(
|
||||
string agreeAlgorithm,
|
||||
string wrapAlgorithm)
|
||||
{
|
||||
string mechanism = GetMechanism(agreeAlgorithm);
|
||||
|
||||
// 'DHWITHSHA1KDF' retained for backward compatibility
|
||||
if (mechanism == "DHWITHSHA1KDF" || mechanism == "ECDHWITHSHA1KDF")
|
||||
return new ECDHWithKdfBasicAgreement(
|
||||
wrapAlgorithm,
|
||||
new ECDHKekGenerator(
|
||||
new Sha1Digest()));
|
||||
|
||||
if (mechanism == "ECMQVWITHSHA1KDF")
|
||||
return new ECMqvWithKdfBasicAgreement(
|
||||
wrapAlgorithm,
|
||||
new ECDHKekGenerator(
|
||||
new Sha1Digest()));
|
||||
|
||||
throw new SecurityUtilityException("Basic Agreement (with KDF) " + agreeAlgorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static IRawAgreement GetRawAgreement(
|
||||
DerObjectIdentifier oid)
|
||||
{
|
||||
return GetRawAgreement(oid.Id);
|
||||
}
|
||||
|
||||
public static IRawAgreement GetRawAgreement(string algorithm)
|
||||
{
|
||||
string mechanism = GetMechanism(algorithm);
|
||||
|
||||
if (mechanism == "X25519")
|
||||
return new X25519Agreement();
|
||||
|
||||
if (mechanism == "X448")
|
||||
return new X448Agreement();
|
||||
|
||||
throw new SecurityUtilityException("Raw Agreement " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetAlgorithmName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, oid.Id);
|
||||
}
|
||||
|
||||
private static string GetMechanism(string algorithm)
|
||||
{
|
||||
var mechanism = CollectionUtilities.GetValueOrKey(Algorithms, algorithm);
|
||||
|
||||
return mechanism.ToUpperInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cbde65561e82da43be786150b90a32b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,804 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Kisa;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nsri;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Paddings;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <remarks>
|
||||
/// Cipher Utility class contains methods that can not be specifically grouped into other classes.
|
||||
/// </remarks>
|
||||
public static class CipherUtilities
|
||||
{
|
||||
private enum CipherAlgorithm {
|
||||
AES,
|
||||
ARC4,
|
||||
ARIA,
|
||||
BLOWFISH,
|
||||
CAMELLIA,
|
||||
CAST5,
|
||||
CAST6,
|
||||
CHACHA,
|
||||
CHACHA20_POLY1305,
|
||||
CHACHA7539,
|
||||
DES,
|
||||
DESEDE,
|
||||
ELGAMAL,
|
||||
GOST28147,
|
||||
HC128,
|
||||
HC256,
|
||||
IDEA,
|
||||
NOEKEON,
|
||||
PBEWITHSHAAND128BITRC4,
|
||||
PBEWITHSHAAND40BITRC4,
|
||||
RC2,
|
||||
RC5,
|
||||
RC5_64,
|
||||
RC6,
|
||||
RIJNDAEL,
|
||||
RSA,
|
||||
SALSA20,
|
||||
SEED,
|
||||
SERPENT,
|
||||
SKIPJACK,
|
||||
SM4,
|
||||
TEA,
|
||||
THREEFISH_256,
|
||||
THREEFISH_512,
|
||||
THREEFISH_1024,
|
||||
TNEPRES,
|
||||
TWOFISH,
|
||||
VMPC,
|
||||
VMPC_KSA3,
|
||||
XTEA,
|
||||
};
|
||||
|
||||
private enum CipherMode { ECB, NONE, CBC, CCM, CFB, CTR, CTS, EAX, GCM, GOFB, OCB, OFB, OPENPGPCFB, SIC };
|
||||
private enum CipherPadding
|
||||
{
|
||||
NOPADDING,
|
||||
RAW,
|
||||
ISO10126PADDING,
|
||||
ISO10126D2PADDING,
|
||||
ISO10126_2PADDING,
|
||||
ISO7816_4PADDING,
|
||||
ISO9797_1PADDING,
|
||||
ISO9796_1,
|
||||
ISO9796_1PADDING,
|
||||
OAEP,
|
||||
OAEPPADDING,
|
||||
OAEPWITHMD5ANDMGF1PADDING,
|
||||
OAEPWITHSHA1ANDMGF1PADDING,
|
||||
OAEPWITHSHA_1ANDMGF1PADDING,
|
||||
OAEPWITHSHA224ANDMGF1PADDING,
|
||||
OAEPWITHSHA_224ANDMGF1PADDING,
|
||||
OAEPWITHSHA256ANDMGF1PADDING,
|
||||
OAEPWITHSHA_256ANDMGF1PADDING,
|
||||
OAEPWITHSHA256ANDMGF1WITHSHA256PADDING,
|
||||
OAEPWITHSHA_256ANDMGF1WITHSHA_256PADDING,
|
||||
OAEPWITHSHA256ANDMGF1WITHSHA1PADDING,
|
||||
OAEPWITHSHA_256ANDMGF1WITHSHA_1PADDING,
|
||||
OAEPWITHSHA384ANDMGF1PADDING,
|
||||
OAEPWITHSHA_384ANDMGF1PADDING,
|
||||
OAEPWITHSHA512ANDMGF1PADDING,
|
||||
OAEPWITHSHA_512ANDMGF1PADDING,
|
||||
PKCS1,
|
||||
PKCS1PADDING,
|
||||
PKCS5,
|
||||
PKCS5PADDING,
|
||||
PKCS7,
|
||||
PKCS7PADDING,
|
||||
TBCPADDING,
|
||||
WITHCTS,
|
||||
X923PADDING,
|
||||
ZEROBYTEPADDING,
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static CipherUtilities()
|
||||
{
|
||||
// Signal to obfuscation tools not to change enum constants
|
||||
Enums.GetArbitraryValue<CipherAlgorithm>().ToString();
|
||||
Enums.GetArbitraryValue<CipherMode>().ToString();
|
||||
Enums.GetArbitraryValue<CipherPadding>().ToString();
|
||||
|
||||
// TODO Flesh out the list of aliases
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Cbc.Id] = "AES/CBC/PKCS7PADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Cbc.Id] = "AES/CBC/PKCS7PADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Cbc.Id] = "AES/CBC/PKCS7PADDING";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Ccm.Id] = "AES/CCM/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Ccm.Id] = "AES/CCM/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Ccm.Id] = "AES/CCM/NOPADDING";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Cfb.Id] = "AES/CFB/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Cfb.Id] = "AES/CFB/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Cfb.Id] = "AES/CFB/NOPADDING";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Ecb.Id] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Ecb.Id] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Ecb.Id] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms["AES//PKCS7"] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms["AES//PKCS7PADDING"] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms["AES//PKCS5"] = "AES/ECB/PKCS7PADDING";
|
||||
Algorithms["AES//PKCS5PADDING"] = "AES/ECB/PKCS7PADDING";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Gcm.Id] = "AES/GCM/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Gcm.Id] = "AES/GCM/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Gcm.Id] = "AES/GCM/NOPADDING";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Ofb.Id] = "AES/OFB/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Ofb.Id] = "AES/OFB/NOPADDING";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Ofb.Id] = "AES/OFB/NOPADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_cbc.Id] = "ARIA/CBC/PKCS7PADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_cbc.Id] = "ARIA/CBC/PKCS7PADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_cbc.Id] = "ARIA/CBC/PKCS7PADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_ccm.Id] = "ARIA/CCM/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_ccm.Id] = "ARIA/CCM/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_ccm.Id] = "ARIA/CCM/NOPADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_cfb.Id] = "ARIA/CFB/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_cfb.Id] = "ARIA/CFB/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_cfb.Id] = "ARIA/CFB/NOPADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_ctr.Id] = "ARIA/CTR/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_ctr.Id] = "ARIA/CTR/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_ctr.Id] = "ARIA/CTR/NOPADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_ecb.Id] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_ecb.Id] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_ecb.Id] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms["ARIA//PKCS7"] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms["ARIA//PKCS7PADDING"] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms["ARIA//PKCS5"] = "ARIA/ECB/PKCS7PADDING";
|
||||
Algorithms["ARIA//PKCS5PADDING"] = "ARIA/ECB/PKCS7PADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_gcm.Id] = "ARIA/GCM/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_gcm.Id] = "ARIA/GCM/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_gcm.Id] = "ARIA/GCM/NOPADDING";
|
||||
|
||||
Algorithms[NsriObjectIdentifiers.id_aria128_ofb.Id] = "ARIA/OFB/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria192_ofb.Id] = "ARIA/OFB/NOPADDING";
|
||||
Algorithms[NsriObjectIdentifiers.id_aria256_ofb.Id] = "ARIA/OFB/NOPADDING";
|
||||
|
||||
Algorithms["RSA/ECB/PKCS1"] = "RSA//PKCS1PADDING";
|
||||
Algorithms["RSA/ECB/PKCS1PADDING"] = "RSA//PKCS1PADDING";
|
||||
Algorithms[PkcsObjectIdentifiers.RsaEncryption.Id] = "RSA//PKCS1PADDING";
|
||||
Algorithms[PkcsObjectIdentifiers.IdRsaesOaep.Id] = "RSA//OAEPPADDING";
|
||||
|
||||
Algorithms[OiwObjectIdentifiers.DesCbc.Id] = "DES/CBC";
|
||||
Algorithms[OiwObjectIdentifiers.DesCfb.Id] = "DES/CFB";
|
||||
Algorithms[OiwObjectIdentifiers.DesEcb.Id] = "DES/ECB";
|
||||
Algorithms[OiwObjectIdentifiers.DesOfb.Id] = "DES/OFB";
|
||||
Algorithms[OiwObjectIdentifiers.DesEde.Id] = "DESEDE";
|
||||
Algorithms["TDEA"] = "DESEDE";
|
||||
Algorithms[PkcsObjectIdentifiers.DesEde3Cbc.Id] = "DESEDE/CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.RC2Cbc.Id] = "RC2/CBC";
|
||||
Algorithms["1.3.6.1.4.1.188.7.1.1.2"] = "IDEA/CBC";
|
||||
Algorithms["1.2.840.113533.7.66.10"] = "CAST5/CBC";
|
||||
|
||||
Algorithms["RC4"] = "ARC4";
|
||||
Algorithms["ARCFOUR"] = "ARC4";
|
||||
Algorithms["1.2.840.113549.3.4"] = "ARC4";
|
||||
|
||||
|
||||
|
||||
Algorithms["PBEWITHSHA1AND128BITRC4"] = "PBEWITHSHAAND128BITRC4";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC4.Id] = "PBEWITHSHAAND128BITRC4";
|
||||
Algorithms["PBEWITHSHA1AND40BITRC4"] = "PBEWITHSHAAND40BITRC4";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd40BitRC4.Id] = "PBEWITHSHAAND40BITRC4";
|
||||
|
||||
Algorithms["PBEWITHSHA1ANDDES"] = "PBEWITHSHA1ANDDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithSha1AndDesCbc.Id] = "PBEWITHSHA1ANDDES-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDRC2"] = "PBEWITHSHA1ANDRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithSha1AndRC2Cbc.Id] = "PBEWITHSHA1ANDRC2-CBC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND3-KEYTRIPLEDES-CBC"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC";
|
||||
Algorithms["PBEWITHSHAAND3KEYTRIPLEDES"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc.Id] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDDESEDE"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND2-KEYTRIPLEDES-CBC"] = "PBEWITHSHAAND2-KEYTRIPLEDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd2KeyTripleDesCbc.Id] = "PBEWITHSHAAND2-KEYTRIPLEDES-CBC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND128BITRC2-CBC"] = "PBEWITHSHAAND128BITRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC2Cbc.Id] = "PBEWITHSHAAND128BITRC2-CBC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND40BITRC2-CBC"] = "PBEWITHSHAAND40BITRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbewithShaAnd40BitRC2Cbc.Id] = "PBEWITHSHAAND40BITRC2-CBC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND128BITAES-CBC-BC"] = "PBEWITHSHAAND128BITAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND128BITAES-CBC-BC"] = "PBEWITHSHAAND128BITAES-CBC-BC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND192BITAES-CBC-BC"] = "PBEWITHSHAAND192BITAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND192BITAES-CBC-BC"] = "PBEWITHSHAAND192BITAES-CBC-BC";
|
||||
|
||||
Algorithms["PBEWITHSHA1AND256BITAES-CBC-BC"] = "PBEWITHSHAAND256BITAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND256BITAES-CBC-BC"] = "PBEWITHSHAAND256BITAES-CBC-BC";
|
||||
|
||||
Algorithms["PBEWITHSHA-256AND128BITAES-CBC-BC"] = "PBEWITHSHA256AND128BITAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-256AND192BITAES-CBC-BC"] = "PBEWITHSHA256AND192BITAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-256AND256BITAES-CBC-BC"] = "PBEWITHSHA256AND256BITAES-CBC-BC";
|
||||
|
||||
|
||||
Algorithms["GOST"] = "GOST28147";
|
||||
Algorithms["GOST-28147"] = "GOST28147";
|
||||
Algorithms[CryptoProObjectIdentifiers.GostR28147Gcfb.Id] = "GOST28147/CBC/PKCS7PADDING";
|
||||
|
||||
Algorithms["RC5-32"] = "RC5";
|
||||
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia128Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING";
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia192Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING";
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia256Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING";
|
||||
|
||||
Algorithms[KisaObjectIdentifiers.IdSeedCbc.Id] = "SEED/CBC/PKCS7PADDING";
|
||||
|
||||
Algorithms["1.3.6.1.4.1.3029.1.2"] = "BLOWFISH/CBC";
|
||||
|
||||
Algorithms["CHACHA20"] = "CHACHA7539";
|
||||
Algorithms[PkcsObjectIdentifiers.IdAlgAeadChaCha20Poly1305.Id] = "CHACHA20-POLY1305";
|
||||
}
|
||||
|
||||
public static IBufferedCipher GetCipher(
|
||||
DerObjectIdentifier oid)
|
||||
{
|
||||
return GetCipher(oid.Id);
|
||||
}
|
||||
|
||||
public static IBufferedCipher GetCipher(string algorithm)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
algorithm = CollectionUtilities.GetValueOrKey(Algorithms, algorithm).ToUpperInvariant();
|
||||
|
||||
IBasicAgreement iesAgreement = null;
|
||||
if (algorithm == "IES")
|
||||
{
|
||||
iesAgreement = new DHBasicAgreement();
|
||||
}
|
||||
else if (algorithm == "ECIES")
|
||||
{
|
||||
iesAgreement = new ECDHBasicAgreement();
|
||||
}
|
||||
|
||||
if (iesAgreement != null)
|
||||
{
|
||||
return new BufferedIesCipher(
|
||||
new IesEngine(
|
||||
iesAgreement,
|
||||
new Kdf2BytesGenerator(
|
||||
new Sha1Digest()),
|
||||
new HMac(
|
||||
new Sha1Digest())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "PBE"))
|
||||
{
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(algorithm, "-CBC"))
|
||||
{
|
||||
if (algorithm == "PBEWITHSHA1ANDDES-CBC")
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(
|
||||
new CbcBlockCipher(new DesEngine()));
|
||||
}
|
||||
else if (algorithm == "PBEWITHSHA1ANDRC2-CBC")
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(
|
||||
new CbcBlockCipher(new RC2Engine()));
|
||||
}
|
||||
else if (Strings.IsOneOf(algorithm,
|
||||
"PBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC"))
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(
|
||||
new CbcBlockCipher(new DesEdeEngine()));
|
||||
}
|
||||
else if (Strings.IsOneOf(algorithm,
|
||||
"PBEWITHSHAAND128BITRC2-CBC", "PBEWITHSHAAND40BITRC2-CBC"))
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(
|
||||
new CbcBlockCipher(new RC2Engine()));
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.EndsWith(algorithm, "-BC") || Org.BouncyCastle.Utilities.Platform.EndsWith(algorithm, "-OPENSSL"))
|
||||
{
|
||||
if (Strings.IsOneOf(algorithm,
|
||||
"PBEWITHSHAAND128BITAES-CBC-BC",
|
||||
"PBEWITHSHAAND192BITAES-CBC-BC",
|
||||
"PBEWITHSHAAND256BITAES-CBC-BC",
|
||||
"PBEWITHSHA256AND128BITAES-CBC-BC",
|
||||
"PBEWITHSHA256AND192BITAES-CBC-BC",
|
||||
"PBEWITHSHA256AND256BITAES-CBC-BC",
|
||||
"PBEWITHMD5AND128BITAES-CBC-OPENSSL",
|
||||
"PBEWITHMD5AND192BITAES-CBC-OPENSSL",
|
||||
"PBEWITHMD5AND256BITAES-CBC-OPENSSL"))
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(
|
||||
new CbcBlockCipher(AesUtilities.CreateEngine()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
string[] parts = algorithm.Split('/');
|
||||
|
||||
IAeadCipher aeadCipher = null;
|
||||
IBlockCipher blockCipher = null;
|
||||
IAsymmetricBlockCipher asymBlockCipher = null;
|
||||
IStreamCipher streamCipher = null;
|
||||
|
||||
string algorithmName = CollectionUtilities.GetValueOrKey(Algorithms, parts[0]).ToUpperInvariant();
|
||||
|
||||
CipherAlgorithm cipherAlgorithm;
|
||||
try
|
||||
{
|
||||
cipherAlgorithm = Enums.GetEnumValue<CipherAlgorithm>(algorithmName);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
switch (cipherAlgorithm)
|
||||
{
|
||||
case CipherAlgorithm.AES:
|
||||
blockCipher = AesUtilities.CreateEngine();
|
||||
break;
|
||||
case CipherAlgorithm.ARC4:
|
||||
streamCipher = new RC4Engine();
|
||||
break;
|
||||
case CipherAlgorithm.ARIA:
|
||||
blockCipher = new AriaEngine();
|
||||
break;
|
||||
case CipherAlgorithm.BLOWFISH:
|
||||
blockCipher = new BlowfishEngine();
|
||||
break;
|
||||
case CipherAlgorithm.CAMELLIA:
|
||||
blockCipher = new CamelliaEngine();
|
||||
break;
|
||||
case CipherAlgorithm.CAST5:
|
||||
blockCipher = new Cast5Engine();
|
||||
break;
|
||||
case CipherAlgorithm.CAST6:
|
||||
blockCipher = new Cast6Engine();
|
||||
break;
|
||||
case CipherAlgorithm.CHACHA:
|
||||
streamCipher = new ChaChaEngine();
|
||||
break;
|
||||
case CipherAlgorithm.CHACHA20_POLY1305:
|
||||
aeadCipher = new ChaCha20Poly1305();
|
||||
break;
|
||||
case CipherAlgorithm.CHACHA7539:
|
||||
streamCipher = new ChaCha7539Engine();
|
||||
break;
|
||||
case CipherAlgorithm.DES:
|
||||
blockCipher = new DesEngine();
|
||||
break;
|
||||
case CipherAlgorithm.DESEDE:
|
||||
blockCipher = new DesEdeEngine();
|
||||
break;
|
||||
case CipherAlgorithm.ELGAMAL:
|
||||
asymBlockCipher = new ElGamalEngine();
|
||||
break;
|
||||
case CipherAlgorithm.GOST28147:
|
||||
blockCipher = new Gost28147Engine();
|
||||
break;
|
||||
case CipherAlgorithm.HC128:
|
||||
streamCipher = new HC128Engine();
|
||||
break;
|
||||
case CipherAlgorithm.HC256:
|
||||
streamCipher = new HC256Engine();
|
||||
break;
|
||||
case CipherAlgorithm.IDEA:
|
||||
blockCipher = new IdeaEngine();
|
||||
break;
|
||||
case CipherAlgorithm.NOEKEON:
|
||||
blockCipher = new NoekeonEngine();
|
||||
break;
|
||||
case CipherAlgorithm.PBEWITHSHAAND128BITRC4:
|
||||
case CipherAlgorithm.PBEWITHSHAAND40BITRC4:
|
||||
streamCipher = new RC4Engine();
|
||||
break;
|
||||
case CipherAlgorithm.RC2:
|
||||
blockCipher = new RC2Engine();
|
||||
break;
|
||||
case CipherAlgorithm.RC5:
|
||||
blockCipher = new RC532Engine();
|
||||
break;
|
||||
case CipherAlgorithm.RC5_64:
|
||||
blockCipher = new RC564Engine();
|
||||
break;
|
||||
case CipherAlgorithm.RC6:
|
||||
blockCipher = new RC6Engine();
|
||||
break;
|
||||
case CipherAlgorithm.RIJNDAEL:
|
||||
blockCipher = new RijndaelEngine();
|
||||
break;
|
||||
case CipherAlgorithm.RSA:
|
||||
asymBlockCipher = new RsaBlindedEngine();
|
||||
break;
|
||||
case CipherAlgorithm.SALSA20:
|
||||
streamCipher = new Salsa20Engine();
|
||||
break;
|
||||
case CipherAlgorithm.SEED:
|
||||
blockCipher = new SeedEngine();
|
||||
break;
|
||||
case CipherAlgorithm.SERPENT:
|
||||
blockCipher = new SerpentEngine();
|
||||
break;
|
||||
case CipherAlgorithm.SKIPJACK:
|
||||
blockCipher = new SkipjackEngine();
|
||||
break;
|
||||
case CipherAlgorithm.SM4:
|
||||
blockCipher = new SM4Engine();
|
||||
break;
|
||||
case CipherAlgorithm.TEA:
|
||||
blockCipher = new TeaEngine();
|
||||
break;
|
||||
case CipherAlgorithm.THREEFISH_256:
|
||||
blockCipher = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256);
|
||||
break;
|
||||
case CipherAlgorithm.THREEFISH_512:
|
||||
blockCipher = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512);
|
||||
break;
|
||||
case CipherAlgorithm.THREEFISH_1024:
|
||||
blockCipher = new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024);
|
||||
break;
|
||||
case CipherAlgorithm.TNEPRES:
|
||||
blockCipher = new TnepresEngine();
|
||||
break;
|
||||
case CipherAlgorithm.TWOFISH:
|
||||
blockCipher = new TwofishEngine();
|
||||
break;
|
||||
case CipherAlgorithm.VMPC:
|
||||
streamCipher = new VmpcEngine();
|
||||
break;
|
||||
case CipherAlgorithm.VMPC_KSA3:
|
||||
streamCipher = new VmpcKsa3Engine();
|
||||
break;
|
||||
case CipherAlgorithm.XTEA:
|
||||
blockCipher = new XteaEngine();
|
||||
break;
|
||||
default:
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
if (aeadCipher != null)
|
||||
{
|
||||
if (parts.Length > 1)
|
||||
throw new ArgumentException("Modes and paddings cannot be applied to AEAD ciphers");
|
||||
|
||||
return new BufferedAeadCipher(aeadCipher);
|
||||
}
|
||||
|
||||
if (streamCipher != null)
|
||||
{
|
||||
if (parts.Length > 1)
|
||||
throw new ArgumentException("Modes and paddings not used for stream ciphers");
|
||||
|
||||
return new BufferedStreamCipher(streamCipher);
|
||||
}
|
||||
|
||||
|
||||
bool cts = false;
|
||||
bool padded = true;
|
||||
IBlockCipherPadding padding = null;
|
||||
IAeadBlockCipher aeadBlockCipher = null;
|
||||
|
||||
if (parts.Length > 2)
|
||||
{
|
||||
if (streamCipher != null)
|
||||
throw new ArgumentException("Paddings not used for stream ciphers");
|
||||
|
||||
string paddingName = parts[2];
|
||||
|
||||
CipherPadding cipherPadding;
|
||||
if (paddingName == "")
|
||||
{
|
||||
cipherPadding = CipherPadding.RAW;
|
||||
}
|
||||
else if (paddingName == "X9.23PADDING")
|
||||
{
|
||||
cipherPadding = CipherPadding.X923PADDING;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
cipherPadding = Enums.GetEnumValue<CipherPadding>(paddingName);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
}
|
||||
|
||||
switch (cipherPadding)
|
||||
{
|
||||
case CipherPadding.NOPADDING:
|
||||
padded = false;
|
||||
break;
|
||||
case CipherPadding.RAW:
|
||||
break;
|
||||
case CipherPadding.ISO10126PADDING:
|
||||
case CipherPadding.ISO10126D2PADDING:
|
||||
case CipherPadding.ISO10126_2PADDING:
|
||||
padding = new ISO10126d2Padding();
|
||||
break;
|
||||
case CipherPadding.ISO7816_4PADDING:
|
||||
case CipherPadding.ISO9797_1PADDING:
|
||||
padding = new ISO7816d4Padding();
|
||||
break;
|
||||
case CipherPadding.ISO9796_1:
|
||||
case CipherPadding.ISO9796_1PADDING:
|
||||
asymBlockCipher = new ISO9796d1Encoding(asymBlockCipher);
|
||||
break;
|
||||
case CipherPadding.OAEP:
|
||||
case CipherPadding.OAEPPADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher);
|
||||
break;
|
||||
case CipherPadding.OAEPWITHMD5ANDMGF1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new MD5Digest());
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA1ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_1ANDMGF1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha1Digest());
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA224ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_224ANDMGF1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha224Digest());
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA256ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_256ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA256ANDMGF1WITHSHA256PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_256ANDMGF1WITHSHA_256PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha256Digest());
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA256ANDMGF1WITHSHA1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_256ANDMGF1WITHSHA_1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha256Digest(), new Sha1Digest(), null);
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA384ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_384ANDMGF1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha384Digest());
|
||||
break;
|
||||
case CipherPadding.OAEPWITHSHA512ANDMGF1PADDING:
|
||||
case CipherPadding.OAEPWITHSHA_512ANDMGF1PADDING:
|
||||
asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha512Digest());
|
||||
break;
|
||||
case CipherPadding.PKCS1:
|
||||
case CipherPadding.PKCS1PADDING:
|
||||
asymBlockCipher = new Pkcs1Encoding(asymBlockCipher);
|
||||
break;
|
||||
case CipherPadding.PKCS5:
|
||||
case CipherPadding.PKCS5PADDING:
|
||||
case CipherPadding.PKCS7:
|
||||
case CipherPadding.PKCS7PADDING:
|
||||
padding = new Pkcs7Padding();
|
||||
break;
|
||||
case CipherPadding.TBCPADDING:
|
||||
padding = new TbcPadding();
|
||||
break;
|
||||
case CipherPadding.WITHCTS:
|
||||
cts = true;
|
||||
break;
|
||||
case CipherPadding.X923PADDING:
|
||||
padding = new X923Padding();
|
||||
break;
|
||||
case CipherPadding.ZEROBYTEPADDING:
|
||||
padding = new ZeroBytePadding();
|
||||
break;
|
||||
default:
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
}
|
||||
|
||||
string mode = "";
|
||||
IBlockCipherMode blockCipherMode = null;
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
mode = parts[1];
|
||||
|
||||
int di = GetDigitIndex(mode);
|
||||
string modeName = di >= 0 ? mode.Substring(0, di) : mode;
|
||||
|
||||
try
|
||||
{
|
||||
CipherMode cipherMode = modeName == ""
|
||||
? CipherMode.NONE
|
||||
: Enums.GetEnumValue<CipherMode>(modeName);
|
||||
|
||||
switch (cipherMode)
|
||||
{
|
||||
case CipherMode.ECB:
|
||||
case CipherMode.NONE:
|
||||
break;
|
||||
case CipherMode.CBC:
|
||||
blockCipherMode = new CbcBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.CCM:
|
||||
aeadBlockCipher = new CcmBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.CFB:
|
||||
{
|
||||
int bits = (di < 0)
|
||||
? 8 * blockCipher.GetBlockSize()
|
||||
: int.Parse(mode.Substring(di));
|
||||
|
||||
blockCipherMode = new CfbBlockCipher(blockCipher, bits);
|
||||
break;
|
||||
}
|
||||
case CipherMode.CTR:
|
||||
blockCipherMode = new SicBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.CTS:
|
||||
cts = true;
|
||||
blockCipherMode = new CbcBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.EAX:
|
||||
aeadBlockCipher = new EaxBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.GCM:
|
||||
aeadBlockCipher = new GcmBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.GOFB:
|
||||
blockCipherMode = new GOfbBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.OCB:
|
||||
aeadBlockCipher = new OcbBlockCipher(blockCipher, CreateBlockCipher(cipherAlgorithm));
|
||||
break;
|
||||
case CipherMode.OFB:
|
||||
{
|
||||
int bits = (di < 0)
|
||||
? 8 * blockCipher.GetBlockSize()
|
||||
: int.Parse(mode.Substring(di));
|
||||
|
||||
blockCipherMode = new OfbBlockCipher(blockCipher, bits);
|
||||
break;
|
||||
}
|
||||
case CipherMode.OPENPGPCFB:
|
||||
blockCipherMode = new OpenPgpCfbBlockCipher(blockCipher);
|
||||
break;
|
||||
case CipherMode.SIC:
|
||||
if (blockCipher.GetBlockSize() < 16)
|
||||
{
|
||||
throw new ArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)");
|
||||
}
|
||||
blockCipherMode = new SicBlockCipher(blockCipher);
|
||||
break;
|
||||
default:
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
}
|
||||
|
||||
if (aeadBlockCipher != null)
|
||||
{
|
||||
if (cts)
|
||||
throw new SecurityUtilityException("CTS mode not valid for AEAD ciphers.");
|
||||
if (padded && parts.Length > 2 && parts[2] != "")
|
||||
throw new SecurityUtilityException("Bad padding specified for AEAD cipher.");
|
||||
|
||||
return new BufferedAeadBlockCipher(aeadBlockCipher);
|
||||
}
|
||||
|
||||
if (blockCipher != null)
|
||||
{
|
||||
if (blockCipherMode == null)
|
||||
{
|
||||
blockCipherMode = EcbBlockCipher.GetBlockCipherMode(blockCipher);
|
||||
}
|
||||
|
||||
if (cts)
|
||||
{
|
||||
return new CtsBlockCipher(blockCipherMode);
|
||||
}
|
||||
|
||||
if (padding != null)
|
||||
{
|
||||
return new PaddedBufferedBlockCipher(blockCipherMode, padding);
|
||||
}
|
||||
|
||||
if (!padded || blockCipherMode.IsPartialBlockOkay)
|
||||
{
|
||||
return new BufferedBlockCipher(blockCipherMode);
|
||||
}
|
||||
|
||||
return new PaddedBufferedBlockCipher(blockCipherMode);
|
||||
}
|
||||
|
||||
if (asymBlockCipher != null)
|
||||
{
|
||||
return new BufferedAsymmetricBlockCipher(asymBlockCipher);
|
||||
}
|
||||
|
||||
throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetAlgorithmName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, oid.Id);
|
||||
}
|
||||
|
||||
private static int GetDigitIndex(string s)
|
||||
{
|
||||
for (int i = 0; i < s.Length; ++i)
|
||||
{
|
||||
if (char.IsDigit(s[i]))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static IBlockCipher CreateBlockCipher(CipherAlgorithm cipherAlgorithm)
|
||||
{
|
||||
switch (cipherAlgorithm)
|
||||
{
|
||||
case CipherAlgorithm.AES: return AesUtilities.CreateEngine();
|
||||
case CipherAlgorithm.ARIA: return new AriaEngine();
|
||||
case CipherAlgorithm.BLOWFISH: return new BlowfishEngine();
|
||||
case CipherAlgorithm.CAMELLIA: return new CamelliaEngine();
|
||||
case CipherAlgorithm.CAST5: return new Cast5Engine();
|
||||
case CipherAlgorithm.CAST6: return new Cast6Engine();
|
||||
case CipherAlgorithm.DES: return new DesEngine();
|
||||
case CipherAlgorithm.DESEDE: return new DesEdeEngine();
|
||||
case CipherAlgorithm.GOST28147: return new Gost28147Engine();
|
||||
case CipherAlgorithm.IDEA: return new IdeaEngine();
|
||||
case CipherAlgorithm.NOEKEON: return new NoekeonEngine();
|
||||
case CipherAlgorithm.RC2: return new RC2Engine();
|
||||
case CipherAlgorithm.RC5: return new RC532Engine();
|
||||
case CipherAlgorithm.RC5_64: return new RC564Engine();
|
||||
case CipherAlgorithm.RC6: return new RC6Engine();
|
||||
case CipherAlgorithm.RIJNDAEL: return new RijndaelEngine();
|
||||
case CipherAlgorithm.SEED: return new SeedEngine();
|
||||
case CipherAlgorithm.SERPENT: return new SerpentEngine();
|
||||
case CipherAlgorithm.SKIPJACK: return new SkipjackEngine();
|
||||
case CipherAlgorithm.SM4: return new SM4Engine();
|
||||
case CipherAlgorithm.TEA: return new TeaEngine();
|
||||
case CipherAlgorithm.THREEFISH_256: return new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256);
|
||||
case CipherAlgorithm.THREEFISH_512: return new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512);
|
||||
case CipherAlgorithm.THREEFISH_1024: return new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024);
|
||||
case CipherAlgorithm.TNEPRES: return new TnepresEngine();
|
||||
case CipherAlgorithm.TWOFISH: return new TwofishEngine();
|
||||
case CipherAlgorithm.XTEA: return new XteaEngine();
|
||||
default:
|
||||
throw new SecurityUtilityException("Cipher " + cipherAlgorithm + " not recognised or not a block cipher");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3576aacdad56d6a45a71b7f377ae1fcc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,320 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.GM;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.UA;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <remarks>
|
||||
/// Utility class for creating IDigest objects from their names/Oids
|
||||
/// </remarks>
|
||||
public static class DigestUtilities
|
||||
{
|
||||
private enum DigestAlgorithm {
|
||||
BLAKE2B_160, BLAKE2B_256, BLAKE2B_384, BLAKE2B_512,
|
||||
BLAKE2S_128, BLAKE2S_160, BLAKE2S_224, BLAKE2S_256,
|
||||
BLAKE3_256,
|
||||
DSTU7564_256, DSTU7564_384, DSTU7564_512,
|
||||
GOST3411,
|
||||
GOST3411_2012_256, GOST3411_2012_512,
|
||||
KECCAK_224, KECCAK_256, KECCAK_288, KECCAK_384, KECCAK_512,
|
||||
MD2, MD4, MD5,
|
||||
NONE,
|
||||
RIPEMD128, RIPEMD160, RIPEMD256, RIPEMD320,
|
||||
SHA_1, SHA_224, SHA_256, SHA_384, SHA_512,
|
||||
SHA_512_224, SHA_512_256,
|
||||
SHA3_224, SHA3_256, SHA3_384, SHA3_512,
|
||||
SHAKE128_256, SHAKE256_512,
|
||||
SM3,
|
||||
TIGER,
|
||||
WHIRLPOOL,
|
||||
};
|
||||
|
||||
private static readonly IDictionary<string, string> Aliases =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, DerObjectIdentifier> Oids =
|
||||
new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static DigestUtilities()
|
||||
{
|
||||
// Signal to obfuscation tools not to change enum constants
|
||||
Enums.GetArbitraryValue<DigestAlgorithm>().ToString();
|
||||
|
||||
Aliases[PkcsObjectIdentifiers.MD2.Id] = "MD2";
|
||||
Aliases[PkcsObjectIdentifiers.MD4.Id] = "MD4";
|
||||
Aliases[PkcsObjectIdentifiers.MD5.Id] = "MD5";
|
||||
|
||||
Aliases["SHA1"] = "SHA-1";
|
||||
Aliases[OiwObjectIdentifiers.IdSha1.Id] = "SHA-1";
|
||||
Aliases[PkcsObjectIdentifiers.IdHmacWithSha1.Id] = "SHA-1";
|
||||
Aliases[MiscObjectIdentifiers.HMAC_SHA1.Id] = "SHA-1";
|
||||
Aliases["SHA224"] = "SHA-224";
|
||||
Aliases[NistObjectIdentifiers.IdSha224.Id] = "SHA-224";
|
||||
Aliases[PkcsObjectIdentifiers.IdHmacWithSha224.Id] = "SHA-224";
|
||||
Aliases["SHA256"] = "SHA-256";
|
||||
Aliases[NistObjectIdentifiers.IdSha256.Id] = "SHA-256";
|
||||
Aliases[PkcsObjectIdentifiers.IdHmacWithSha256.Id] = "SHA-256";
|
||||
Aliases["SHA384"] = "SHA-384";
|
||||
Aliases[NistObjectIdentifiers.IdSha384.Id] = "SHA-384";
|
||||
Aliases[PkcsObjectIdentifiers.IdHmacWithSha384.Id] = "SHA-384";
|
||||
Aliases["SHA512"] = "SHA-512";
|
||||
Aliases[NistObjectIdentifiers.IdSha512.Id] = "SHA-512";
|
||||
Aliases[PkcsObjectIdentifiers.IdHmacWithSha512.Id] = "SHA-512";
|
||||
|
||||
Aliases["SHA512/224"] = "SHA-512/224";
|
||||
Aliases["SHA512(224)"] = "SHA-512/224";
|
||||
Aliases["SHA-512(224)"] = "SHA-512/224";
|
||||
Aliases[NistObjectIdentifiers.IdSha512_224.Id] = "SHA-512/224";
|
||||
Aliases["SHA512/256"] = "SHA-512/256";
|
||||
Aliases["SHA512(256)"] = "SHA-512/256";
|
||||
Aliases["SHA-512(256)"] = "SHA-512/256";
|
||||
Aliases[NistObjectIdentifiers.IdSha512_256.Id] = "SHA-512/256";
|
||||
|
||||
Aliases["RIPEMD-128"] = "RIPEMD128";
|
||||
Aliases[TeleTrusTObjectIdentifiers.RipeMD128.Id] = "RIPEMD128";
|
||||
Aliases["RIPEMD-160"] = "RIPEMD160";
|
||||
Aliases[TeleTrusTObjectIdentifiers.RipeMD160.Id] = "RIPEMD160";
|
||||
Aliases["RIPEMD-256"] = "RIPEMD256";
|
||||
Aliases[TeleTrusTObjectIdentifiers.RipeMD256.Id] = "RIPEMD256";
|
||||
Aliases["RIPEMD-320"] = "RIPEMD320";
|
||||
//Aliases[TeleTrusTObjectIdentifiers.RipeMD320.Id] = "RIPEMD320";
|
||||
|
||||
Aliases[CryptoProObjectIdentifiers.GostR3411.Id] = "GOST3411";
|
||||
|
||||
Aliases["KECCAK224"] = "KECCAK-224";
|
||||
Aliases["KECCAK256"] = "KECCAK-256";
|
||||
Aliases["KECCAK288"] = "KECCAK-288";
|
||||
Aliases["KECCAK384"] = "KECCAK-384";
|
||||
Aliases["KECCAK512"] = "KECCAK-512";
|
||||
|
||||
Aliases[NistObjectIdentifiers.IdSha3_224.Id] = "SHA3-224";
|
||||
Aliases[NistObjectIdentifiers.IdHMacWithSha3_224.Id] = "SHA3-224";
|
||||
Aliases[NistObjectIdentifiers.IdSha3_256.Id] = "SHA3-256";
|
||||
Aliases[NistObjectIdentifiers.IdHMacWithSha3_256.Id] = "SHA3-256";
|
||||
Aliases[NistObjectIdentifiers.IdSha3_384.Id] = "SHA3-384";
|
||||
Aliases[NistObjectIdentifiers.IdHMacWithSha3_384.Id] = "SHA3-384";
|
||||
Aliases[NistObjectIdentifiers.IdSha3_512.Id] = "SHA3-512";
|
||||
Aliases[NistObjectIdentifiers.IdHMacWithSha3_512.Id] = "SHA3-512";
|
||||
Aliases["SHAKE128"] = "SHAKE128-256";
|
||||
Aliases[NistObjectIdentifiers.IdShake128.Id] = "SHAKE128-256";
|
||||
Aliases["SHAKE256"] = "SHAKE256-512";
|
||||
Aliases[NistObjectIdentifiers.IdShake256.Id] = "SHAKE256-512";
|
||||
|
||||
Aliases[GMObjectIdentifiers.sm3.Id] = "SM3";
|
||||
|
||||
Aliases[MiscObjectIdentifiers.id_blake2b160.Id] = "BLAKE2B-160";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2b256.Id] = "BLAKE2B-256";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2b384.Id] = "BLAKE2B-384";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2b512.Id] = "BLAKE2B-512";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2s128.Id] = "BLAKE2S-128";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2s160.Id] = "BLAKE2S-160";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2s224.Id] = "BLAKE2S-224";
|
||||
Aliases[MiscObjectIdentifiers.id_blake2s256.Id] = "BLAKE2S-256";
|
||||
Aliases[MiscObjectIdentifiers.blake3_256.Id] = "BLAKE3-256";
|
||||
|
||||
Aliases[RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256.Id] = "GOST3411-2012-256";
|
||||
Aliases[RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512.Id] = "GOST3411-2012-512";
|
||||
|
||||
Aliases[UAObjectIdentifiers.dstu7564digest_256.Id] = "DSTU7564-256";
|
||||
Aliases[UAObjectIdentifiers.dstu7564digest_384.Id] = "DSTU7564-384";
|
||||
Aliases[UAObjectIdentifiers.dstu7564digest_512.Id] = "DSTU7564-512";
|
||||
|
||||
Oids["MD2"] = PkcsObjectIdentifiers.MD2;
|
||||
Oids["MD4"] = PkcsObjectIdentifiers.MD4;
|
||||
Oids["MD5"] = PkcsObjectIdentifiers.MD5;
|
||||
Oids["SHA-1"] = OiwObjectIdentifiers.IdSha1;
|
||||
Oids["SHA-224"] = NistObjectIdentifiers.IdSha224;
|
||||
Oids["SHA-256"] = NistObjectIdentifiers.IdSha256;
|
||||
Oids["SHA-384"] = NistObjectIdentifiers.IdSha384;
|
||||
Oids["SHA-512"] = NistObjectIdentifiers.IdSha512;
|
||||
Oids["SHA-512/224"] = NistObjectIdentifiers.IdSha512_224;
|
||||
Oids["SHA-512/256"] = NistObjectIdentifiers.IdSha512_256;
|
||||
Oids["SHA3-224"] = NistObjectIdentifiers.IdSha3_224;
|
||||
Oids["SHA3-256"] = NistObjectIdentifiers.IdSha3_256;
|
||||
Oids["SHA3-384"] = NistObjectIdentifiers.IdSha3_384;
|
||||
Oids["SHA3-512"] = NistObjectIdentifiers.IdSha3_512;
|
||||
Oids["SHAKE128-256"] = NistObjectIdentifiers.IdShake128;
|
||||
Oids["SHAKE256-512"] = NistObjectIdentifiers.IdShake256;
|
||||
Oids["RIPEMD128"] = TeleTrusTObjectIdentifiers.RipeMD128;
|
||||
Oids["RIPEMD160"] = TeleTrusTObjectIdentifiers.RipeMD160;
|
||||
Oids["RIPEMD256"] = TeleTrusTObjectIdentifiers.RipeMD256;
|
||||
Oids["GOST3411"] = CryptoProObjectIdentifiers.GostR3411;
|
||||
Oids["SM3"] = GMObjectIdentifiers.sm3;
|
||||
Oids["BLAKE2B-160"] = MiscObjectIdentifiers.id_blake2b160;
|
||||
Oids["BLAKE2B-256"] = MiscObjectIdentifiers.id_blake2b256;
|
||||
Oids["BLAKE2B-384"] = MiscObjectIdentifiers.id_blake2b384;
|
||||
Oids["BLAKE2B-512"] = MiscObjectIdentifiers.id_blake2b512;
|
||||
Oids["BLAKE2S-128"] = MiscObjectIdentifiers.id_blake2s128;
|
||||
Oids["BLAKE2S-160"] = MiscObjectIdentifiers.id_blake2s160;
|
||||
Oids["BLAKE2S-224"] = MiscObjectIdentifiers.id_blake2s224;
|
||||
Oids["BLAKE2S-256"] = MiscObjectIdentifiers.id_blake2s256;
|
||||
Oids["BLAKE3-256"] = MiscObjectIdentifiers.blake3_256;
|
||||
Oids["GOST3411-2012-256"] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256;
|
||||
Oids["GOST3411-2012-512"] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512;
|
||||
Oids["DSTU7564-256"] = UAObjectIdentifiers.dstu7564digest_256;
|
||||
Oids["DSTU7564-384"] = UAObjectIdentifiers.dstu7564digest_384;
|
||||
Oids["DSTU7564-512"] = UAObjectIdentifiers.dstu7564digest_512;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ObjectIdentifier for a given digest mechanism.
|
||||
/// </summary>
|
||||
/// <param name="mechanism">A string representation of the digest meanism.</param>
|
||||
/// <returns>A DerObjectIdentifier, null if the Oid is not available.</returns>
|
||||
|
||||
public static DerObjectIdentifier GetObjectIdentifier(string mechanism)
|
||||
{
|
||||
if (mechanism == null)
|
||||
throw new ArgumentNullException(nameof(mechanism));
|
||||
|
||||
mechanism = CollectionUtilities.GetValueOrKey(Aliases, mechanism).ToUpperInvariant();
|
||||
|
||||
return CollectionUtilities.GetValueOrNull(Oids, mechanism);
|
||||
}
|
||||
|
||||
public static IDigest GetDigest(DerObjectIdentifier id)
|
||||
{
|
||||
return GetDigest(id.Id);
|
||||
}
|
||||
|
||||
public static IDigest GetDigest(string algorithm)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
string mechanism = CollectionUtilities.GetValueOrKey(Aliases, algorithm).ToUpperInvariant();
|
||||
|
||||
try
|
||||
{
|
||||
DigestAlgorithm digestAlgorithm = Enums.GetEnumValue<DigestAlgorithm>(mechanism);
|
||||
|
||||
switch (digestAlgorithm)
|
||||
{
|
||||
case DigestAlgorithm.BLAKE2B_160: return new Blake2bDigest(160);
|
||||
case DigestAlgorithm.BLAKE2B_256: return new Blake2bDigest(256);
|
||||
case DigestAlgorithm.BLAKE2B_384: return new Blake2bDigest(384);
|
||||
case DigestAlgorithm.BLAKE2B_512: return new Blake2bDigest(512);
|
||||
case DigestAlgorithm.BLAKE2S_128: return new Blake2sDigest(128);
|
||||
case DigestAlgorithm.BLAKE2S_160: return new Blake2sDigest(160);
|
||||
case DigestAlgorithm.BLAKE2S_224: return new Blake2sDigest(224);
|
||||
case DigestAlgorithm.BLAKE2S_256: return new Blake2sDigest(256);
|
||||
case DigestAlgorithm.BLAKE3_256: return new Blake3Digest(256);
|
||||
case DigestAlgorithm.DSTU7564_256: return new Dstu7564Digest(256);
|
||||
case DigestAlgorithm.DSTU7564_384: return new Dstu7564Digest(384);
|
||||
case DigestAlgorithm.DSTU7564_512: return new Dstu7564Digest(512);
|
||||
case DigestAlgorithm.GOST3411: return new Gost3411Digest();
|
||||
case DigestAlgorithm.GOST3411_2012_256: return new Gost3411_2012_256Digest();
|
||||
case DigestAlgorithm.GOST3411_2012_512: return new Gost3411_2012_512Digest();
|
||||
case DigestAlgorithm.KECCAK_224: return new KeccakDigest(224);
|
||||
case DigestAlgorithm.KECCAK_256: return new KeccakDigest(256);
|
||||
case DigestAlgorithm.KECCAK_288: return new KeccakDigest(288);
|
||||
case DigestAlgorithm.KECCAK_384: return new KeccakDigest(384);
|
||||
case DigestAlgorithm.KECCAK_512: return new KeccakDigest(512);
|
||||
case DigestAlgorithm.MD2: return new MD2Digest();
|
||||
case DigestAlgorithm.MD4: return new MD4Digest();
|
||||
case DigestAlgorithm.MD5: return new MD5Digest();
|
||||
case DigestAlgorithm.NONE: return new NullDigest();
|
||||
case DigestAlgorithm.RIPEMD128: return new RipeMD128Digest();
|
||||
case DigestAlgorithm.RIPEMD160: return new RipeMD160Digest();
|
||||
case DigestAlgorithm.RIPEMD256: return new RipeMD256Digest();
|
||||
case DigestAlgorithm.RIPEMD320: return new RipeMD320Digest();
|
||||
case DigestAlgorithm.SHA_1: return new Sha1Digest();
|
||||
case DigestAlgorithm.SHA_224: return new Sha224Digest();
|
||||
case DigestAlgorithm.SHA_256: return new Sha256Digest();
|
||||
case DigestAlgorithm.SHA_384: return new Sha384Digest();
|
||||
case DigestAlgorithm.SHA_512: return new Sha512Digest();
|
||||
case DigestAlgorithm.SHA_512_224: return new Sha512tDigest(224);
|
||||
case DigestAlgorithm.SHA_512_256: return new Sha512tDigest(256);
|
||||
case DigestAlgorithm.SHA3_224: return new Sha3Digest(224);
|
||||
case DigestAlgorithm.SHA3_256: return new Sha3Digest(256);
|
||||
case DigestAlgorithm.SHA3_384: return new Sha3Digest(384);
|
||||
case DigestAlgorithm.SHA3_512: return new Sha3Digest(512);
|
||||
case DigestAlgorithm.SHAKE128_256: return new ShakeDigest(128);
|
||||
case DigestAlgorithm.SHAKE256_512: return new ShakeDigest(256);
|
||||
case DigestAlgorithm.SM3: return new SM3Digest();
|
||||
case DigestAlgorithm.TIGER: return new TigerDigest();
|
||||
case DigestAlgorithm.WHIRLPOOL: return new WhirlpoolDigest();
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
|
||||
throw new SecurityUtilityException("Digest " + mechanism + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetAlgorithmName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Aliases, oid.Id);
|
||||
}
|
||||
|
||||
public static byte[] CalculateDigest(DerObjectIdentifier id, byte[] input)
|
||||
{
|
||||
return CalculateDigest(id.Id, input);
|
||||
}
|
||||
|
||||
public static byte[] CalculateDigest(string algorithm, byte[] input)
|
||||
{
|
||||
IDigest digest = GetDigest(algorithm);
|
||||
return DoFinal(digest, input);
|
||||
}
|
||||
|
||||
public static byte[] CalculateDigest(string algorithm, byte[] buf, int off, int len)
|
||||
{
|
||||
IDigest digest = GetDigest(algorithm);
|
||||
return DoFinal(digest, buf, off, len);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public static byte[] CalculateDigest(string algorithm, ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
IDigest digest = GetDigest(algorithm);
|
||||
return DoFinal(digest, buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static byte[] DoFinal(IDigest digest)
|
||||
{
|
||||
byte[] b = new byte[digest.GetDigestSize()];
|
||||
digest.DoFinal(b, 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
public static byte[] DoFinal(IDigest digest, byte[] input)
|
||||
{
|
||||
digest.BlockUpdate(input, 0, input.Length);
|
||||
return DoFinal(digest);
|
||||
}
|
||||
|
||||
public static byte[] DoFinal(IDigest digest, byte[] buf, int off, int len)
|
||||
{
|
||||
digest.BlockUpdate(buf, off, len);
|
||||
return DoFinal(digest);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public static byte[] DoFinal(IDigest digest, ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
digest.BlockUpdate(buffer);
|
||||
return DoFinal(digest);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e02cda66c755ac94ea2ee882e29a2dfe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,325 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
#if NET5_0_OR_GREATER
|
||||
using System.Runtime.Versioning;
|
||||
#endif
|
||||
using System.Security.Cryptography;
|
||||
using SystemX509 = System.Security.Cryptography.X509Certificates;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// A class containing methods to interface the BouncyCastle world to the .NET Crypto world.
|
||||
/// </summary>
|
||||
public static class DotNetUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Create an System.Security.Cryptography.X509Certificate from an X509Certificate Structure.
|
||||
/// </summary>
|
||||
/// <param name="x509Struct"></param>
|
||||
/// <returns>A System.Security.Cryptography.X509Certificate.</returns>
|
||||
public static SystemX509.X509Certificate ToX509Certificate(
|
||||
X509CertificateStructure x509Struct)
|
||||
{
|
||||
return new SystemX509.X509Certificate(x509Struct.GetDerEncoded());
|
||||
}
|
||||
|
||||
public static SystemX509.X509Certificate ToX509Certificate(
|
||||
X509Certificate x509Cert)
|
||||
{
|
||||
return new SystemX509.X509Certificate(x509Cert.GetEncoded());
|
||||
}
|
||||
|
||||
public static X509Certificate FromX509Certificate(
|
||||
SystemX509.X509Certificate x509Cert)
|
||||
{
|
||||
return new X509CertificateParser().ReadCertificate(x509Cert.GetRawCertData());
|
||||
}
|
||||
|
||||
public static AsymmetricCipherKeyPair GetDsaKeyPair(DSA dsa)
|
||||
{
|
||||
return GetDsaKeyPair(dsa.ExportParameters(true));
|
||||
}
|
||||
|
||||
public static AsymmetricCipherKeyPair GetDsaKeyPair(DSAParameters dp)
|
||||
{
|
||||
DsaPublicKeyParameters pubKey = GetDsaPublicKey(dp);
|
||||
|
||||
DsaPrivateKeyParameters privKey = new DsaPrivateKeyParameters(
|
||||
new BigInteger(1, dp.X),
|
||||
pubKey.Parameters);
|
||||
|
||||
return new AsymmetricCipherKeyPair(pubKey, privKey);
|
||||
}
|
||||
|
||||
public static DsaPublicKeyParameters GetDsaPublicKey(DSA dsa)
|
||||
{
|
||||
return GetDsaPublicKey(dsa.ExportParameters(false));
|
||||
}
|
||||
|
||||
public static DsaPublicKeyParameters GetDsaPublicKey(DSAParameters dp)
|
||||
{
|
||||
DsaValidationParameters validationParameters = (dp.Seed != null)
|
||||
? new DsaValidationParameters(dp.Seed, dp.Counter)
|
||||
: null;
|
||||
|
||||
DsaParameters parameters = new DsaParameters(
|
||||
new BigInteger(1, dp.P),
|
||||
new BigInteger(1, dp.Q),
|
||||
new BigInteger(1, dp.G),
|
||||
validationParameters);
|
||||
|
||||
return new DsaPublicKeyParameters(
|
||||
new BigInteger(1, dp.Y),
|
||||
parameters);
|
||||
}
|
||||
|
||||
#if NETCOREAPP1_0_OR_GREATER || NET47_OR_GREATER || NETSTANDARD1_6_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static AsymmetricCipherKeyPair GetECDsaKeyPair(ECDsa ecDsa)
|
||||
{
|
||||
return GetECKeyPair("ECDSA", ecDsa.ExportParameters(true));
|
||||
}
|
||||
|
||||
public static ECPublicKeyParameters GetECDsaPublicKey(ECDsa ecDsa)
|
||||
{
|
||||
return GetECPublicKey("ECDSA", ecDsa.ExportParameters(false));
|
||||
}
|
||||
|
||||
public static AsymmetricCipherKeyPair GetECKeyPair(string algorithm, ECParameters ec)
|
||||
{
|
||||
ECPublicKeyParameters pubKey = GetECPublicKey(algorithm, ec);
|
||||
|
||||
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
|
||||
pubKey.AlgorithmName,
|
||||
new BigInteger(1, ec.D),
|
||||
pubKey.Parameters);
|
||||
|
||||
return new AsymmetricCipherKeyPair(pubKey, privKey);
|
||||
}
|
||||
|
||||
public static ECPublicKeyParameters GetECPublicKey(string algorithm, ECParameters ec)
|
||||
{
|
||||
X9ECParameters x9 = GetX9ECParameters(ec.Curve);
|
||||
if (x9 == null)
|
||||
throw new NotSupportedException("Unrecognized curve");
|
||||
|
||||
return new ECPublicKeyParameters(
|
||||
algorithm,
|
||||
GetECPoint(x9.Curve, ec.Q),
|
||||
new ECDomainParameters(x9));
|
||||
}
|
||||
|
||||
private static Math.EC.ECPoint GetECPoint(Math.EC.ECCurve curve, ECPoint point)
|
||||
{
|
||||
return curve.CreatePoint(new BigInteger(1, point.X), new BigInteger(1, point.Y));
|
||||
}
|
||||
|
||||
private static X9ECParameters GetX9ECParameters(ECCurve curve)
|
||||
{
|
||||
if (!curve.IsNamed)
|
||||
throw new NotSupportedException("Only named curves are supported");
|
||||
|
||||
Oid oid = curve.Oid;
|
||||
if (oid != null)
|
||||
{
|
||||
string oidValue = oid.Value;
|
||||
if (oidValue != null)
|
||||
return ECKeyPairGenerator.FindECCurveByOid(new DerObjectIdentifier(oidValue));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static AsymmetricCipherKeyPair GetRsaKeyPair(RSA rsa)
|
||||
{
|
||||
return GetRsaKeyPair(rsa.ExportParameters(true));
|
||||
}
|
||||
|
||||
public static AsymmetricCipherKeyPair GetRsaKeyPair(RSAParameters rp)
|
||||
{
|
||||
RsaKeyParameters pubKey = GetRsaPublicKey(rp);
|
||||
|
||||
RsaPrivateCrtKeyParameters privKey = new RsaPrivateCrtKeyParameters(
|
||||
pubKey.Modulus,
|
||||
pubKey.Exponent,
|
||||
new BigInteger(1, rp.D),
|
||||
new BigInteger(1, rp.P),
|
||||
new BigInteger(1, rp.Q),
|
||||
new BigInteger(1, rp.DP),
|
||||
new BigInteger(1, rp.DQ),
|
||||
new BigInteger(1, rp.InverseQ));
|
||||
|
||||
return new AsymmetricCipherKeyPair(pubKey, privKey);
|
||||
}
|
||||
|
||||
public static RsaKeyParameters GetRsaPublicKey(RSA rsa)
|
||||
{
|
||||
return GetRsaPublicKey(rsa.ExportParameters(false));
|
||||
}
|
||||
|
||||
public static RsaKeyParameters GetRsaPublicKey(
|
||||
RSAParameters rp)
|
||||
{
|
||||
return new RsaKeyParameters(
|
||||
false,
|
||||
new BigInteger(1, rp.Modulus),
|
||||
new BigInteger(1, rp.Exponent));
|
||||
}
|
||||
|
||||
public static AsymmetricCipherKeyPair GetKeyPair(AsymmetricAlgorithm privateKey)
|
||||
{
|
||||
if (privateKey is DSA dsa)
|
||||
return GetDsaKeyPair(dsa);
|
||||
|
||||
#if NETCOREAPP1_0_OR_GREATER || NET47_OR_GREATER || NETSTANDARD1_6_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
if (privateKey is ECDsa ecDsa)
|
||||
return GetECDsaKeyPair(ecDsa);
|
||||
#endif
|
||||
|
||||
if (privateKey is RSA rsa)
|
||||
return GetRsaKeyPair(rsa);
|
||||
|
||||
throw new ArgumentException("Unsupported algorithm specified", nameof(privateKey));
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaKeyParameters rsaKey)
|
||||
{
|
||||
// TODO This appears to not work for private keys (when no CRT info)
|
||||
return CreateRSAProvider(ToRSAParameters(rsaKey));
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaKeyParameters rsaKey, CspParameters csp)
|
||||
{
|
||||
// TODO This appears to not work for private keys (when no CRT info)
|
||||
return CreateRSAProvider(ToRSAParameters(rsaKey), csp);
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey)
|
||||
{
|
||||
return CreateRSAProvider(ToRSAParameters(privKey));
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey, CspParameters csp)
|
||||
{
|
||||
return CreateRSAProvider(ToRSAParameters(privKey), csp);
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaPrivateKeyStructure privKey)
|
||||
{
|
||||
return CreateRSAProvider(ToRSAParameters(privKey));
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
public static RSA ToRSA(RsaPrivateKeyStructure privKey, CspParameters csp)
|
||||
{
|
||||
return CreateRSAProvider(ToRSAParameters(privKey), csp);
|
||||
}
|
||||
|
||||
public static RSAParameters ToRSAParameters(RsaKeyParameters rsaKey)
|
||||
{
|
||||
RSAParameters rp = new RSAParameters();
|
||||
rp.Modulus = rsaKey.Modulus.ToByteArrayUnsigned();
|
||||
if (rsaKey.IsPrivate)
|
||||
rp.D = ConvertRSAParametersField(rsaKey.Exponent, rp.Modulus.Length);
|
||||
else
|
||||
rp.Exponent = rsaKey.Exponent.ToByteArrayUnsigned();
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static RSAParameters ToRSAParameters(RsaPrivateCrtKeyParameters privKey)
|
||||
{
|
||||
RSAParameters rp = new RSAParameters();
|
||||
rp.Modulus = privKey.Modulus.ToByteArrayUnsigned();
|
||||
rp.Exponent = privKey.PublicExponent.ToByteArrayUnsigned();
|
||||
rp.P = privKey.P.ToByteArrayUnsigned();
|
||||
rp.Q = privKey.Q.ToByteArrayUnsigned();
|
||||
rp.D = ConvertRSAParametersField(privKey.Exponent, rp.Modulus.Length);
|
||||
rp.DP = ConvertRSAParametersField(privKey.DP, rp.P.Length);
|
||||
rp.DQ = ConvertRSAParametersField(privKey.DQ, rp.Q.Length);
|
||||
rp.InverseQ = ConvertRSAParametersField(privKey.QInv, rp.Q.Length);
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static RSAParameters ToRSAParameters(RsaPrivateKeyStructure privKey)
|
||||
{
|
||||
RSAParameters rp = new RSAParameters();
|
||||
rp.Modulus = privKey.Modulus.ToByteArrayUnsigned();
|
||||
rp.Exponent = privKey.PublicExponent.ToByteArrayUnsigned();
|
||||
rp.P = privKey.Prime1.ToByteArrayUnsigned();
|
||||
rp.Q = privKey.Prime2.ToByteArrayUnsigned();
|
||||
rp.D = ConvertRSAParametersField(privKey.PrivateExponent, rp.Modulus.Length);
|
||||
rp.DP = ConvertRSAParametersField(privKey.Exponent1, rp.P.Length);
|
||||
rp.DQ = ConvertRSAParametersField(privKey.Exponent2, rp.Q.Length);
|
||||
rp.InverseQ = ConvertRSAParametersField(privKey.Coefficient, rp.Q.Length);
|
||||
return rp;
|
||||
}
|
||||
|
||||
private static byte[] ConvertRSAParametersField(BigInteger n, int size)
|
||||
{
|
||||
return BigIntegers.AsUnsignedByteArray(size, n);
|
||||
}
|
||||
|
||||
// TODO Why do we use CspParameters instead of just RSA.Create in methods below?
|
||||
// private static RSA CreateRSA(RSAParameters rp)
|
||||
// {
|
||||
//#if NETCOREAPP2_0_OR_GREATER || NET472_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
// return RSA.Create(rp);
|
||||
//#else
|
||||
// var rsa = RSA.Create();
|
||||
// rsa.ImportParameters(rp);
|
||||
// return rsa;
|
||||
//#endif
|
||||
// }
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
private static RSACryptoServiceProvider CreateRSAProvider(RSAParameters rp)
|
||||
{
|
||||
CspParameters csp = new CspParameters();
|
||||
csp.KeyContainerName = string.Format("BouncyCastle-{0}", Guid.NewGuid());
|
||||
return CreateRSAProvider(rp, csp);
|
||||
}
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
private static RSACryptoServiceProvider CreateRSAProvider(RSAParameters rp, CspParameters csp)
|
||||
{
|
||||
RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider(csp);
|
||||
rsaCsp.ImportParameters(rp);
|
||||
return rsaCsp;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d8495888a65d924dac5d55806d57007
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class GeneralSecurityException
|
||||
: Exception
|
||||
{
|
||||
public GeneralSecurityException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public GeneralSecurityException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public GeneralSecurityException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected GeneralSecurityException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0d8c41189aa7a947b6acbdfbd4f0401
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,421 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Iana;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Kisa;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nsri;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public static class GeneratorUtilities
|
||||
{
|
||||
private static readonly IDictionary<string, string> KgAlgorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, string> KpgAlgorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, int> DefaultKeySizes =
|
||||
new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static GeneratorUtilities()
|
||||
{
|
||||
//
|
||||
// key generators.
|
||||
//
|
||||
AddKgAlgorithm("AES",
|
||||
"AESWRAP");
|
||||
AddKgAlgorithm("AES128",
|
||||
"2.16.840.1.101.3.4.2",
|
||||
NistObjectIdentifiers.IdAes128Cbc,
|
||||
NistObjectIdentifiers.IdAes128Ccm,
|
||||
NistObjectIdentifiers.IdAes128Cfb,
|
||||
NistObjectIdentifiers.IdAes128Ecb,
|
||||
NistObjectIdentifiers.IdAes128Gcm,
|
||||
NistObjectIdentifiers.IdAes128Ofb,
|
||||
NistObjectIdentifiers.IdAes128Wrap);
|
||||
AddKgAlgorithm("AES192",
|
||||
"2.16.840.1.101.3.4.22",
|
||||
NistObjectIdentifiers.IdAes192Cbc,
|
||||
NistObjectIdentifiers.IdAes192Ccm,
|
||||
NistObjectIdentifiers.IdAes192Cfb,
|
||||
NistObjectIdentifiers.IdAes192Ecb,
|
||||
NistObjectIdentifiers.IdAes192Gcm,
|
||||
NistObjectIdentifiers.IdAes192Ofb,
|
||||
NistObjectIdentifiers.IdAes192Wrap);
|
||||
AddKgAlgorithm("AES256",
|
||||
"2.16.840.1.101.3.4.42",
|
||||
NistObjectIdentifiers.IdAes256Cbc,
|
||||
NistObjectIdentifiers.IdAes256Ccm,
|
||||
NistObjectIdentifiers.IdAes256Cfb,
|
||||
NistObjectIdentifiers.IdAes256Ecb,
|
||||
NistObjectIdentifiers.IdAes256Gcm,
|
||||
NistObjectIdentifiers.IdAes256Ofb,
|
||||
NistObjectIdentifiers.IdAes256Wrap);
|
||||
AddKgAlgorithm("BLOWFISH",
|
||||
"1.3.6.1.4.1.3029.1.2");
|
||||
AddKgAlgorithm("CAMELLIA",
|
||||
"CAMELLIAWRAP");
|
||||
AddKgAlgorithm("ARIA");
|
||||
AddKgAlgorithm("ARIA128",
|
||||
NsriObjectIdentifiers.id_aria128_cbc,
|
||||
NsriObjectIdentifiers.id_aria128_ccm,
|
||||
NsriObjectIdentifiers.id_aria128_cfb,
|
||||
NsriObjectIdentifiers.id_aria128_ctr,
|
||||
NsriObjectIdentifiers.id_aria128_ecb,
|
||||
NsriObjectIdentifiers.id_aria128_gcm,
|
||||
NsriObjectIdentifiers.id_aria128_ocb2,
|
||||
NsriObjectIdentifiers.id_aria128_ofb);
|
||||
AddKgAlgorithm("ARIA192",
|
||||
NsriObjectIdentifiers.id_aria192_cbc,
|
||||
NsriObjectIdentifiers.id_aria192_ccm,
|
||||
NsriObjectIdentifiers.id_aria192_cfb,
|
||||
NsriObjectIdentifiers.id_aria192_ctr,
|
||||
NsriObjectIdentifiers.id_aria192_ecb,
|
||||
NsriObjectIdentifiers.id_aria192_gcm,
|
||||
NsriObjectIdentifiers.id_aria192_ocb2,
|
||||
NsriObjectIdentifiers.id_aria192_ofb);
|
||||
AddKgAlgorithm("ARIA256",
|
||||
NsriObjectIdentifiers.id_aria256_cbc,
|
||||
NsriObjectIdentifiers.id_aria256_ccm,
|
||||
NsriObjectIdentifiers.id_aria256_cfb,
|
||||
NsriObjectIdentifiers.id_aria256_ctr,
|
||||
NsriObjectIdentifiers.id_aria256_ecb,
|
||||
NsriObjectIdentifiers.id_aria256_gcm,
|
||||
NsriObjectIdentifiers.id_aria256_ocb2,
|
||||
NsriObjectIdentifiers.id_aria256_ofb);
|
||||
AddKgAlgorithm("CAMELLIA128",
|
||||
NttObjectIdentifiers.IdCamellia128Cbc,
|
||||
NttObjectIdentifiers.IdCamellia128Wrap);
|
||||
AddKgAlgorithm("CAMELLIA192",
|
||||
NttObjectIdentifiers.IdCamellia192Cbc,
|
||||
NttObjectIdentifiers.IdCamellia192Wrap);
|
||||
AddKgAlgorithm("CAMELLIA256",
|
||||
NttObjectIdentifiers.IdCamellia256Cbc,
|
||||
NttObjectIdentifiers.IdCamellia256Wrap);
|
||||
AddKgAlgorithm("CAST5",
|
||||
"1.2.840.113533.7.66.10");
|
||||
AddKgAlgorithm("CAST6");
|
||||
AddKgAlgorithm("CHACHA");
|
||||
AddKgAlgorithm("CHACHA7539",
|
||||
"CHACHA20",
|
||||
"CHACHA20-POLY1305",
|
||||
PkcsObjectIdentifiers.IdAlgAeadChaCha20Poly1305);
|
||||
AddKgAlgorithm("DES",
|
||||
OiwObjectIdentifiers.DesCbc,
|
||||
OiwObjectIdentifiers.DesCfb,
|
||||
OiwObjectIdentifiers.DesEcb,
|
||||
OiwObjectIdentifiers.DesOfb);
|
||||
AddKgAlgorithm("DESEDE",
|
||||
"DESEDEWRAP",
|
||||
"TDEA",
|
||||
OiwObjectIdentifiers.DesEde);
|
||||
AddKgAlgorithm("DESEDE3",
|
||||
PkcsObjectIdentifiers.DesEde3Cbc,
|
||||
PkcsObjectIdentifiers.IdAlgCms3DesWrap);
|
||||
AddKgAlgorithm("GOST28147",
|
||||
"GOST",
|
||||
"GOST-28147",
|
||||
CryptoProObjectIdentifiers.GostR28147Gcfb);
|
||||
AddKgAlgorithm("HC128");
|
||||
AddKgAlgorithm("HC256");
|
||||
AddKgAlgorithm("IDEA",
|
||||
"1.3.6.1.4.1.188.7.1.1.2");
|
||||
AddKgAlgorithm("NOEKEON");
|
||||
AddKgAlgorithm("RC2",
|
||||
PkcsObjectIdentifiers.RC2Cbc,
|
||||
PkcsObjectIdentifiers.IdAlgCmsRC2Wrap);
|
||||
AddKgAlgorithm("RC4",
|
||||
"ARC4",
|
||||
"1.2.840.113549.3.4");
|
||||
AddKgAlgorithm("RC5",
|
||||
"RC5-32");
|
||||
AddKgAlgorithm("RC5-64");
|
||||
AddKgAlgorithm("RC6");
|
||||
AddKgAlgorithm("RIJNDAEL");
|
||||
AddKgAlgorithm("SALSA20");
|
||||
AddKgAlgorithm("SEED",
|
||||
KisaObjectIdentifiers.IdNpkiAppCmsSeedWrap,
|
||||
KisaObjectIdentifiers.IdSeedCbc);
|
||||
AddKgAlgorithm("SERPENT");
|
||||
AddKgAlgorithm("SKIPJACK");
|
||||
AddKgAlgorithm("SM4");
|
||||
AddKgAlgorithm("TEA");
|
||||
AddKgAlgorithm("THREEFISH-256");
|
||||
AddKgAlgorithm("THREEFISH-512");
|
||||
AddKgAlgorithm("THREEFISH-1024");
|
||||
AddKgAlgorithm("TNEPRES");
|
||||
AddKgAlgorithm("TWOFISH");
|
||||
AddKgAlgorithm("VMPC");
|
||||
AddKgAlgorithm("VMPC-KSA3");
|
||||
AddKgAlgorithm("XTEA");
|
||||
|
||||
//
|
||||
// HMac key generators
|
||||
//
|
||||
AddHMacKeyGenerator("MD2");
|
||||
AddHMacKeyGenerator("MD4");
|
||||
AddHMacKeyGenerator("MD5",
|
||||
IanaObjectIdentifiers.HmacMD5);
|
||||
AddHMacKeyGenerator("SHA1",
|
||||
PkcsObjectIdentifiers.IdHmacWithSha1,
|
||||
IanaObjectIdentifiers.HmacSha1);
|
||||
AddHMacKeyGenerator("SHA224",
|
||||
PkcsObjectIdentifiers.IdHmacWithSha224);
|
||||
AddHMacKeyGenerator("SHA256",
|
||||
PkcsObjectIdentifiers.IdHmacWithSha256);
|
||||
AddHMacKeyGenerator("SHA384",
|
||||
PkcsObjectIdentifiers.IdHmacWithSha384);
|
||||
AddHMacKeyGenerator("SHA512",
|
||||
PkcsObjectIdentifiers.IdHmacWithSha512);
|
||||
AddHMacKeyGenerator("SHA512/224");
|
||||
AddHMacKeyGenerator("SHA512/256");
|
||||
AddHMacKeyGenerator("KECCAK224");
|
||||
AddHMacKeyGenerator("KECCAK256");
|
||||
AddHMacKeyGenerator("KECCAK288");
|
||||
AddHMacKeyGenerator("KECCAK384");
|
||||
AddHMacKeyGenerator("KECCAK512");
|
||||
AddHMacKeyGenerator("SHA3-224",
|
||||
NistObjectIdentifiers.IdHMacWithSha3_224);
|
||||
AddHMacKeyGenerator("SHA3-256",
|
||||
NistObjectIdentifiers.IdHMacWithSha3_256);
|
||||
AddHMacKeyGenerator("SHA3-384",
|
||||
NistObjectIdentifiers.IdHMacWithSha3_384);
|
||||
AddHMacKeyGenerator("SHA3-512",
|
||||
NistObjectIdentifiers.IdHMacWithSha3_512);
|
||||
AddHMacKeyGenerator("RIPEMD128");
|
||||
AddHMacKeyGenerator("RIPEMD160",
|
||||
IanaObjectIdentifiers.HmacRipeMD160);
|
||||
AddHMacKeyGenerator("TIGER",
|
||||
IanaObjectIdentifiers.HmacTiger);
|
||||
AddHMacKeyGenerator("GOST3411-2012-256",
|
||||
RosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_256);
|
||||
AddHMacKeyGenerator("GOST3411-2012-512",
|
||||
RosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_512);
|
||||
|
||||
//
|
||||
// key pair generators.
|
||||
//
|
||||
AddKpgAlgorithm("DH",
|
||||
"DIFFIEHELLMAN");
|
||||
AddKpgAlgorithm("DSA");
|
||||
AddKpgAlgorithm("EC",
|
||||
// TODO Should this be an alias for ECDH?
|
||||
X9ObjectIdentifiers.DHSinglePassStdDHSha1KdfScheme);
|
||||
AddKpgAlgorithm("ECDH",
|
||||
"ECIES");
|
||||
AddKpgAlgorithm("ECDHC");
|
||||
AddKpgAlgorithm("ECMQV",
|
||||
X9ObjectIdentifiers.MqvSinglePassSha1KdfScheme);
|
||||
AddKpgAlgorithm("ECDSA");
|
||||
AddKpgAlgorithm("ECGOST3410",
|
||||
"ECGOST-3410",
|
||||
"GOST-3410-2001");
|
||||
AddKpgAlgorithm("ECGOST3410-2012",
|
||||
"GOST-3410-2012");
|
||||
AddKpgAlgorithm("Ed25519",
|
||||
"Ed25519ctx",
|
||||
"Ed25519ph",
|
||||
EdECObjectIdentifiers.id_Ed25519);
|
||||
AddKpgAlgorithm("Ed448",
|
||||
"Ed448ph",
|
||||
EdECObjectIdentifiers.id_Ed448);
|
||||
AddKpgAlgorithm("ELGAMAL");
|
||||
AddKpgAlgorithm("GOST3410",
|
||||
"GOST-3410",
|
||||
"GOST-3410-94");
|
||||
AddKpgAlgorithm("RSA",
|
||||
"1.2.840.113549.1.1.1");
|
||||
AddKpgAlgorithm("RSASSA-PSS");
|
||||
AddKpgAlgorithm("X25519",
|
||||
EdECObjectIdentifiers.id_X25519);
|
||||
AddKpgAlgorithm("X448",
|
||||
EdECObjectIdentifiers.id_X448);
|
||||
|
||||
AddDefaultKeySizeEntries(64, "DES");
|
||||
AddDefaultKeySizeEntries(80, "SKIPJACK");
|
||||
AddDefaultKeySizeEntries(128, "AES128", "ARIA128", "BLOWFISH", "CAMELLIA128", "CAST5", "CHACHA", "DESEDE",
|
||||
"HC128", "HMACMD2", "HMACMD4", "HMACMD5", "HMACRIPEMD128", "IDEA", "NOEKEON",
|
||||
"RC2", "RC4", "RC5", "SALSA20", "SEED", "SM4", "TEA", "XTEA", "VMPC", "VMPC-KSA3");
|
||||
AddDefaultKeySizeEntries(160, "HMACRIPEMD160", "HMACSHA1");
|
||||
AddDefaultKeySizeEntries(192, "AES", "AES192", "ARIA192", "CAMELLIA192", "DESEDE3", "HMACTIGER",
|
||||
"RIJNDAEL", "SERPENT", "TNEPRES");
|
||||
AddDefaultKeySizeEntries(224, "HMACSHA3-224", "HMACKECCAK224", "HMACSHA224", "HMACSHA512/224");
|
||||
AddDefaultKeySizeEntries(256, "AES256", "ARIA", "ARIA256", "CAMELLIA", "CAMELLIA256", "CAST6",
|
||||
"CHACHA7539", "GOST28147", "HC256", "HMACGOST3411-2012-256", "HMACSHA3-256", "HMACKECCAK256",
|
||||
"HMACSHA256", "HMACSHA512/256", "RC5-64", "RC6", "THREEFISH-256", "TWOFISH");
|
||||
AddDefaultKeySizeEntries(288, "HMACKECCAK288");
|
||||
AddDefaultKeySizeEntries(384, "HMACSHA3-384", "HMACKECCAK384", "HMACSHA384");
|
||||
AddDefaultKeySizeEntries(512, "HMACGOST3411-2012-512", "HMACSHA3-512", "HMACKECCAK512", "HMACSHA512",
|
||||
"THREEFISH-512");
|
||||
AddDefaultKeySizeEntries(1024, "THREEFISH-1024");
|
||||
}
|
||||
|
||||
private static void AddDefaultKeySizeEntries(int size, params string[] algorithms)
|
||||
{
|
||||
foreach (string algorithm in algorithms)
|
||||
{
|
||||
DefaultKeySizes.Add(algorithm, size);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddKgAlgorithm(string canonicalName, params object[] aliases)
|
||||
{
|
||||
KgAlgorithms[canonicalName] = canonicalName;
|
||||
|
||||
foreach (object alias in aliases)
|
||||
{
|
||||
KgAlgorithms[alias.ToString()] = canonicalName;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddKpgAlgorithm(string canonicalName, params object[] aliases)
|
||||
{
|
||||
KpgAlgorithms[canonicalName] = canonicalName;
|
||||
|
||||
foreach (object alias in aliases)
|
||||
{
|
||||
KpgAlgorithms[alias.ToString()] = canonicalName;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddHMacKeyGenerator(string algorithm, params object[] aliases)
|
||||
{
|
||||
string mainName = "HMAC" + algorithm;
|
||||
|
||||
KgAlgorithms[mainName] = mainName;
|
||||
KgAlgorithms["HMAC-" + algorithm] = mainName;
|
||||
KgAlgorithms["HMAC/" + algorithm] = mainName;
|
||||
|
||||
foreach (object alias in aliases)
|
||||
{
|
||||
KgAlgorithms[alias.ToString()] = mainName;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Consider making this public
|
||||
internal static string GetCanonicalKeyGeneratorAlgorithm(string algorithm)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(KgAlgorithms, algorithm);
|
||||
}
|
||||
|
||||
// TODO Consider making this public
|
||||
internal static string GetCanonicalKeyPairGeneratorAlgorithm(string algorithm)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(KpgAlgorithms, algorithm);
|
||||
}
|
||||
|
||||
public static CipherKeyGenerator GetKeyGenerator(DerObjectIdentifier oid)
|
||||
{
|
||||
return GetKeyGenerator(oid.Id);
|
||||
}
|
||||
|
||||
public static CipherKeyGenerator GetKeyGenerator(string algorithm)
|
||||
{
|
||||
string canonicalName = GetCanonicalKeyGeneratorAlgorithm(algorithm);
|
||||
|
||||
if (canonicalName == null)
|
||||
throw new SecurityUtilityException("KeyGenerator " + algorithm + " not recognised.");
|
||||
|
||||
int defaultKeySize = FindDefaultKeySize(canonicalName);
|
||||
if (defaultKeySize == -1)
|
||||
throw new SecurityUtilityException("KeyGenerator " + algorithm
|
||||
+ " (" + canonicalName + ") not supported.");
|
||||
|
||||
if (canonicalName == "DES")
|
||||
return new DesKeyGenerator(defaultKeySize);
|
||||
|
||||
if (canonicalName == "DESEDE" || canonicalName == "DESEDE3")
|
||||
return new DesEdeKeyGenerator(defaultKeySize);
|
||||
|
||||
return new CipherKeyGenerator(defaultKeySize);
|
||||
}
|
||||
|
||||
public static IAsymmetricCipherKeyPairGenerator GetKeyPairGenerator(DerObjectIdentifier oid)
|
||||
{
|
||||
return GetKeyPairGenerator(oid.Id);
|
||||
}
|
||||
|
||||
public static IAsymmetricCipherKeyPairGenerator GetKeyPairGenerator(string algorithm)
|
||||
{
|
||||
string canonicalName = GetCanonicalKeyPairGeneratorAlgorithm(algorithm);
|
||||
|
||||
if (canonicalName == null)
|
||||
throw new SecurityUtilityException("KeyPairGenerator " + algorithm + " not recognised.");
|
||||
|
||||
if (canonicalName == "DH")
|
||||
return new DHKeyPairGenerator();
|
||||
|
||||
if (canonicalName == "DSA")
|
||||
return new DsaKeyPairGenerator();
|
||||
|
||||
// "EC", "ECDH", "ECDHC", "ECDSA", "ECGOST3410", "ECGOST3410-2012", "ECMQV"
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(canonicalName, "EC"))
|
||||
return new ECKeyPairGenerator(canonicalName);
|
||||
|
||||
if (canonicalName == "Ed25519")
|
||||
return new Ed25519KeyPairGenerator();
|
||||
|
||||
if (canonicalName == "Ed448")
|
||||
return new Ed448KeyPairGenerator();
|
||||
|
||||
if (canonicalName == "ELGAMAL")
|
||||
return new ElGamalKeyPairGenerator();
|
||||
|
||||
if (canonicalName == "GOST3410")
|
||||
return new Gost3410KeyPairGenerator();
|
||||
|
||||
if (canonicalName == "RSA" || canonicalName == "RSASSA-PSS")
|
||||
return new RsaKeyPairGenerator();
|
||||
|
||||
if (canonicalName == "X25519")
|
||||
return new X25519KeyPairGenerator();
|
||||
|
||||
if (canonicalName == "X448")
|
||||
return new X448KeyPairGenerator();
|
||||
|
||||
throw new SecurityUtilityException("KeyPairGenerator " + algorithm
|
||||
+ " (" + canonicalName + ") not supported.");
|
||||
}
|
||||
|
||||
internal static int GetDefaultKeySize(DerObjectIdentifier oid)
|
||||
{
|
||||
return GetDefaultKeySize(oid.Id);
|
||||
}
|
||||
|
||||
internal static int GetDefaultKeySize(string algorithm)
|
||||
{
|
||||
string canonicalName = GetCanonicalKeyGeneratorAlgorithm(algorithm);
|
||||
|
||||
if (canonicalName == null)
|
||||
throw new SecurityUtilityException("KeyGenerator " + algorithm + " not recognised.");
|
||||
|
||||
int defaultKeySize = FindDefaultKeySize(canonicalName);
|
||||
if (defaultKeySize == -1)
|
||||
throw new SecurityUtilityException("KeyGenerator " + algorithm
|
||||
+ " (" + canonicalName + ") not supported.");
|
||||
|
||||
return defaultKeySize;
|
||||
}
|
||||
|
||||
private static int FindDefaultKeySize(string canonicalName)
|
||||
{
|
||||
return DefaultKeySizes.TryGetValue(canonicalName, out int keySize) ? keySize : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71114e4af0270f34ba2d802c33a9bd5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class InvalidKeyException
|
||||
: KeyException
|
||||
{
|
||||
public InvalidKeyException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidKeyException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidKeyException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected InvalidKeyException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9842e68a8ae8895468c08cc98231c060
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class InvalidParameterException
|
||||
: KeyException
|
||||
{
|
||||
public InvalidParameterException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidParameterException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidParameterException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected InvalidParameterException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a02c4f553fcf8d749801284afc4da77a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,600 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public class JksStore
|
||||
{
|
||||
private static readonly int Magic = unchecked((int)0xFEEDFEED);
|
||||
|
||||
private static readonly AlgorithmIdentifier JksObfuscationAlg = new AlgorithmIdentifier(
|
||||
new DerObjectIdentifier("1.3.6.1.4.1.42.2.17.1.1"), DerNull.Instance);
|
||||
|
||||
private readonly Dictionary<string, JksTrustedCertEntry> m_certificateEntries =
|
||||
new Dictionary<string, JksTrustedCertEntry>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, JksKeyEntry> m_keyEntries =
|
||||
new Dictionary<string, JksKeyEntry>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public JksStore()
|
||||
{
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public bool Probe(Stream stream)
|
||||
{
|
||||
using (var br = new BinaryReader(stream))
|
||||
try
|
||||
{
|
||||
return Magic == BinaryReaders.ReadInt32BigEndian(br);
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public AsymmetricKeyParameter GetKey(string alias, char[] password)
|
||||
{
|
||||
if (alias == null)
|
||||
throw new ArgumentNullException(nameof(alias));
|
||||
if (password == null)
|
||||
throw new ArgumentNullException(nameof(password));
|
||||
|
||||
if (!m_keyEntries.TryGetValue(alias, out JksKeyEntry keyEntry))
|
||||
return null;
|
||||
|
||||
if (!JksObfuscationAlg.Equals(keyEntry.keyData.EncryptionAlgorithm))
|
||||
throw new IOException("unknown encryption algorithm");
|
||||
|
||||
byte[] encryptedData = keyEntry.keyData.GetEncryptedData();
|
||||
|
||||
// key length is encryptedData - salt - checksum
|
||||
int pkcs8Len = encryptedData.Length - 40;
|
||||
|
||||
IDigest digest = DigestUtilities.GetDigest("SHA-1");
|
||||
|
||||
// key decryption
|
||||
byte[] keyStream = CalculateKeyStream(digest, password, encryptedData, pkcs8Len);
|
||||
byte[] pkcs8Key = new byte[pkcs8Len];
|
||||
for (int i = 0; i < pkcs8Len; ++i)
|
||||
{
|
||||
pkcs8Key[i] = (byte)(encryptedData[20 + i] ^ keyStream[i]);
|
||||
}
|
||||
Array.Clear(keyStream, 0, keyStream.Length);
|
||||
|
||||
// integrity check
|
||||
byte[] checksum = GetKeyChecksum(digest, password, pkcs8Key);
|
||||
|
||||
if (!Arrays.ConstantTimeAreEqual(20, encryptedData, pkcs8Len + 20, checksum, 0))
|
||||
throw new IOException("cannot recover key");
|
||||
|
||||
return PrivateKeyFactory.CreateKey(pkcs8Key);
|
||||
}
|
||||
|
||||
private byte[] GetKeyChecksum(IDigest digest, char[] password, byte[] pkcs8Key)
|
||||
{
|
||||
AddPassword(digest, password);
|
||||
|
||||
return DigestUtilities.DoFinal(digest, pkcs8Key);
|
||||
}
|
||||
|
||||
private byte[] CalculateKeyStream(IDigest digest, char[] password, byte[] salt, int count)
|
||||
{
|
||||
byte[] keyStream = new byte[count];
|
||||
byte[] hash = Arrays.CopyOf(salt, 20);
|
||||
|
||||
int index = 0;
|
||||
while (index < count)
|
||||
{
|
||||
AddPassword(digest, password);
|
||||
|
||||
digest.BlockUpdate(hash, 0, hash.Length);
|
||||
digest.DoFinal(hash, 0);
|
||||
|
||||
int length = System.Math.Min(hash.Length, keyStream.Length - index);
|
||||
Array.Copy(hash, 0, keyStream, index, length);
|
||||
index += length;
|
||||
}
|
||||
|
||||
return keyStream;
|
||||
}
|
||||
|
||||
public X509Certificate[] GetCertificateChain(string alias)
|
||||
{
|
||||
if (m_keyEntries.TryGetValue(alias, out var keyEntry))
|
||||
return CloneChain(keyEntry.chain);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public X509Certificate GetCertificate(string alias)
|
||||
{
|
||||
if (m_certificateEntries.TryGetValue(alias, out var certEntry))
|
||||
return certEntry.cert;
|
||||
|
||||
if (m_keyEntries.TryGetValue(alias, out var keyEntry))
|
||||
return keyEntry.chain?[0];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public DateTime? GetCreationDate(string alias)
|
||||
{
|
||||
if (m_certificateEntries.TryGetValue(alias, out var certEntry))
|
||||
return certEntry.date;
|
||||
|
||||
if (m_keyEntries.TryGetValue(alias, out var keyEntry))
|
||||
return keyEntry.date;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public void SetKeyEntry(string alias, AsymmetricKeyParameter key, char[] password, X509Certificate[] chain)
|
||||
{
|
||||
alias = ConvertAlias(alias);
|
||||
|
||||
if (ContainsAlias(alias))
|
||||
throw new IOException("alias [" + alias + "] already in use");
|
||||
|
||||
byte[] pkcs8Key = PrivateKeyInfoFactory.CreatePrivateKeyInfo(key).GetEncoded();
|
||||
byte[] protectedKey = new byte[pkcs8Key.Length + 40];
|
||||
|
||||
SecureRandom rnd = CryptoServicesRegistrar.GetSecureRandom();
|
||||
rnd.NextBytes(protectedKey, 0, 20);
|
||||
|
||||
IDigest digest = DigestUtilities.GetDigest("SHA-1");
|
||||
|
||||
byte[] checksum = GetKeyChecksum(digest, password, pkcs8Key);
|
||||
Array.Copy(checksum, 0, protectedKey, 20 + pkcs8Key.Length, 20);
|
||||
|
||||
byte[] keyStream = CalculateKeyStream(digest, password, protectedKey, pkcs8Key.Length);
|
||||
for (int i = 0; i != keyStream.Length; i++)
|
||||
{
|
||||
protectedKey[20 + i] = (byte)(pkcs8Key[i] ^ keyStream[i]);
|
||||
}
|
||||
Array.Clear(keyStream, 0, keyStream.Length);
|
||||
|
||||
try
|
||||
{
|
||||
var epki = new EncryptedPrivateKeyInfo(JksObfuscationAlg, protectedKey);
|
||||
m_keyEntries.Add(alias, new JksKeyEntry(DateTime.UtcNow, epki.GetEncoded(), CloneChain(chain)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IOException("unable to encode encrypted private key", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public void SetKeyEntry(string alias, byte[] key, X509Certificate[] chain)
|
||||
{
|
||||
alias = ConvertAlias(alias);
|
||||
|
||||
if (ContainsAlias(alias))
|
||||
throw new IOException("alias [" + alias + "] already in use");
|
||||
|
||||
m_keyEntries.Add(alias, new JksKeyEntry(DateTime.UtcNow, key, CloneChain(chain)));
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public void SetCertificateEntry(string alias, X509Certificate cert)
|
||||
{
|
||||
alias = ConvertAlias(alias);
|
||||
|
||||
if (ContainsAlias(alias))
|
||||
throw new IOException("alias [" + alias + "] already in use");
|
||||
|
||||
m_certificateEntries.Add(alias, new JksTrustedCertEntry(DateTime.UtcNow, cert));
|
||||
}
|
||||
|
||||
public void DeleteEntry(string alias)
|
||||
{
|
||||
if (!m_keyEntries.Remove(alias))
|
||||
{
|
||||
m_certificateEntries.Remove(alias);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> Aliases
|
||||
{
|
||||
get
|
||||
{
|
||||
var aliases = new HashSet<string>(m_certificateEntries.Keys);
|
||||
aliases.UnionWith(m_keyEntries.Keys);
|
||||
return CollectionUtilities.Proxy(aliases);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsAlias(string alias)
|
||||
{
|
||||
return IsCertificateEntry(alias) || IsKeyEntry(alias);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return m_certificateEntries.Count + m_keyEntries.Count; }
|
||||
}
|
||||
|
||||
public bool IsKeyEntry(string alias)
|
||||
{
|
||||
return m_keyEntries.ContainsKey(alias);
|
||||
}
|
||||
|
||||
public bool IsCertificateEntry(string alias)
|
||||
{
|
||||
return m_certificateEntries.ContainsKey(alias);
|
||||
}
|
||||
|
||||
public string GetCertificateAlias(X509Certificate cert)
|
||||
{
|
||||
foreach (var entry in m_certificateEntries)
|
||||
{
|
||||
if (entry.Value.cert.Equals(cert))
|
||||
return entry.Key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public void Save(Stream stream, char[] password)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
if (password == null)
|
||||
throw new ArgumentNullException(nameof(password));
|
||||
|
||||
IDigest checksumDigest = CreateChecksumDigest(password);
|
||||
BinaryWriter bw = new BinaryWriter(new DigestStream(stream, null, checksumDigest));
|
||||
|
||||
BinaryWriters.WriteInt32BigEndian(bw, Magic);
|
||||
BinaryWriters.WriteInt32BigEndian(bw, 2);
|
||||
|
||||
BinaryWriters.WriteInt32BigEndian(bw, Count);
|
||||
|
||||
foreach (var entry in m_keyEntries)
|
||||
{
|
||||
string alias = entry.Key;
|
||||
JksKeyEntry keyEntry = entry.Value;
|
||||
|
||||
BinaryWriters.WriteInt32BigEndian(bw, 1);
|
||||
WriteUtf(bw, alias);
|
||||
WriteDateTime(bw, keyEntry.date);
|
||||
WriteBufferWithInt32Length(bw, keyEntry.keyData.GetEncoded());
|
||||
|
||||
X509Certificate[] chain = keyEntry.chain;
|
||||
int chainLength = chain == null ? 0 : chain.Length;
|
||||
BinaryWriters.WriteInt32BigEndian(bw, chainLength);
|
||||
for (int i = 0; i < chainLength; ++i)
|
||||
{
|
||||
WriteTypedCertificate(bw, chain[i]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entry in m_certificateEntries)
|
||||
{
|
||||
string alias = entry.Key;
|
||||
JksTrustedCertEntry certEntry = entry.Value;
|
||||
|
||||
BinaryWriters.WriteInt32BigEndian(bw, 2);
|
||||
WriteUtf(bw, alias);
|
||||
WriteDateTime(bw, certEntry.date);
|
||||
WriteTypedCertificate(bw, certEntry.cert);
|
||||
}
|
||||
|
||||
byte[] checksum = DigestUtilities.DoFinal(checksumDigest);
|
||||
bw.Write(checksum);
|
||||
bw.Flush();
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public void Load(Stream stream, char[] password)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
m_certificateEntries.Clear();
|
||||
m_keyEntries.Clear();
|
||||
|
||||
using (var storeStream = ValidateStream(stream, password))
|
||||
{
|
||||
BinaryReader br = new BinaryReader(storeStream);
|
||||
|
||||
int magic = BinaryReaders.ReadInt32BigEndian(br);
|
||||
int storeVersion = BinaryReaders.ReadInt32BigEndian(br);
|
||||
|
||||
if (!(magic == Magic && (storeVersion == 1 || storeVersion == 2)))
|
||||
throw new IOException("Invalid keystore format");
|
||||
|
||||
int numEntries = BinaryReaders.ReadInt32BigEndian(br);
|
||||
|
||||
for (int t = 0; t < numEntries; t++)
|
||||
{
|
||||
int tag = BinaryReaders.ReadInt32BigEndian(br);
|
||||
|
||||
switch (tag)
|
||||
{
|
||||
case 1: // keys
|
||||
{
|
||||
string alias = ReadUtf(br);
|
||||
DateTime date = ReadDateTime(br);
|
||||
|
||||
// encrypted key data
|
||||
byte[] keyData = ReadBufferWithInt32Length(br);
|
||||
|
||||
// certificate chain
|
||||
int chainLength = BinaryReaders.ReadInt32BigEndian(br);
|
||||
X509Certificate[] chain = null;
|
||||
if (chainLength > 0)
|
||||
{
|
||||
var certs = new List<X509Certificate>(System.Math.Min(10, chainLength));
|
||||
for (int certNo = 0; certNo != chainLength; certNo++)
|
||||
{
|
||||
certs.Add(ReadTypedCertificate(br, storeVersion));
|
||||
}
|
||||
chain = certs.ToArray();
|
||||
}
|
||||
m_keyEntries.Add(alias, new JksKeyEntry(date, keyData, chain));
|
||||
break;
|
||||
}
|
||||
case 2: // certificate
|
||||
{
|
||||
string alias = ReadUtf(br);
|
||||
DateTime date = ReadDateTime(br);
|
||||
|
||||
X509Certificate cert = ReadTypedCertificate(br, storeVersion);
|
||||
|
||||
m_certificateEntries.Add(alias, new JksTrustedCertEntry(date, cert));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IOException("unable to discern entry type");
|
||||
}
|
||||
}
|
||||
|
||||
if (storeStream.Position != storeStream.Length)
|
||||
throw new IOException("password incorrect or store tampered with");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate password takes the checksum of the store and will either.
|
||||
* 1. If password is null, load the store into memory, return the result.
|
||||
* 2. If password is not null, load the store into memory, test the checksum, and if successful return
|
||||
* a new input stream instance of the store.
|
||||
* 3. Fail if there is a password and an invalid checksum.
|
||||
*
|
||||
* @param inputStream The input stream.
|
||||
* @param password the password.
|
||||
* @return Either the passed in input stream or a new input stream.
|
||||
*/
|
||||
/// <exception cref="IOException"/>
|
||||
private ErasableByteStream ValidateStream(Stream inputStream, char[] password)
|
||||
{
|
||||
byte[] rawStore = Streams.ReadAll(inputStream);
|
||||
int checksumPos = rawStore.Length - 20;
|
||||
|
||||
if (password != null)
|
||||
{
|
||||
byte[] checksum = CalculateChecksum(password, rawStore, 0, checksumPos);
|
||||
|
||||
if (!Arrays.ConstantTimeAreEqual(20, checksum, 0, rawStore, checksumPos))
|
||||
{
|
||||
Array.Clear(rawStore, 0, rawStore.Length);
|
||||
throw new IOException("password incorrect or store tampered with");
|
||||
}
|
||||
}
|
||||
|
||||
return new ErasableByteStream(rawStore, 0, checksumPos);
|
||||
}
|
||||
|
||||
private static void AddPassword(IDigest digest, char[] password)
|
||||
{
|
||||
// Encoding.BigEndianUnicode
|
||||
for (int i = 0; i < password.Length; ++i)
|
||||
{
|
||||
digest.Update((byte)(password[i] >> 8));
|
||||
digest.Update((byte)password[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] CalculateChecksum(char[] password, byte[] buffer, int offset, int length)
|
||||
{
|
||||
IDigest checksumDigest = CreateChecksumDigest(password);
|
||||
checksumDigest.BlockUpdate(buffer, offset, length);
|
||||
return DigestUtilities.DoFinal(checksumDigest);
|
||||
}
|
||||
|
||||
private static X509Certificate[] CloneChain(X509Certificate[] chain)
|
||||
{
|
||||
return (X509Certificate[])chain?.Clone();
|
||||
}
|
||||
|
||||
private static string ConvertAlias(string alias)
|
||||
{
|
||||
return alias.ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static IDigest CreateChecksumDigest(char[] password)
|
||||
{
|
||||
IDigest digest = DigestUtilities.GetDigest("SHA-1");
|
||||
AddPassword(digest, password);
|
||||
|
||||
//
|
||||
// This "Mighty Aphrodite" string goes all the way back to the
|
||||
// first java betas in the mid 90's, why who knows? But see
|
||||
// https://cryptosense.com/mighty-aphrodite-dark-secrets-of-the-java-keystore/
|
||||
//
|
||||
byte[] prefix = Encoding.UTF8.GetBytes("Mighty Aphrodite");
|
||||
digest.BlockUpdate(prefix, 0, prefix.Length);
|
||||
return digest;
|
||||
}
|
||||
|
||||
private static byte[] ReadBufferWithInt16Length(BinaryReader br)
|
||||
{
|
||||
int length = BinaryReaders.ReadInt16BigEndian(br);
|
||||
return BinaryReaders.ReadBytesFully(br, length);
|
||||
}
|
||||
|
||||
private static byte[] ReadBufferWithInt32Length(BinaryReader br)
|
||||
{
|
||||
int length = BinaryReaders.ReadInt32BigEndian(br);
|
||||
return BinaryReaders.ReadBytesFully(br, length);
|
||||
}
|
||||
|
||||
private static DateTime ReadDateTime(BinaryReader br)
|
||||
{
|
||||
long unixMS = BinaryReaders.ReadInt64BigEndian(br);
|
||||
return DateTimeUtilities.UnixMsToDateTime(unixMS);
|
||||
}
|
||||
|
||||
private static X509Certificate ReadTypedCertificate(BinaryReader br, int storeVersion)
|
||||
{
|
||||
if (storeVersion == 2)
|
||||
{
|
||||
string certFormat = ReadUtf(br);
|
||||
if ("X.509" != certFormat)
|
||||
throw new IOException("Unsupported certificate format: " + certFormat);
|
||||
}
|
||||
|
||||
byte[] certData = ReadBufferWithInt32Length(br);
|
||||
try
|
||||
{
|
||||
return new X509Certificate(certData);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(certData, 0, certData.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReadUtf(BinaryReader br)
|
||||
{
|
||||
byte[] utfBytes = ReadBufferWithInt16Length(br);
|
||||
|
||||
/*
|
||||
* FIXME JKS actually uses a "modified UTF-8" format. For the moment we will just support single-byte
|
||||
* encodings that aren't null bytes.
|
||||
*/
|
||||
for (int i = 0; i < utfBytes.Length; ++i)
|
||||
{
|
||||
byte utfByte = utfBytes[i];
|
||||
if (utfByte == 0 || (utfByte & 0x80) != 0)
|
||||
throw new NotSupportedException("Currently missing support for modified UTF-8 encoding in JKS");
|
||||
}
|
||||
|
||||
return Encoding.UTF8.GetString(utfBytes);
|
||||
}
|
||||
|
||||
private static void WriteBufferWithInt16Length(BinaryWriter bw, byte[] buffer)
|
||||
{
|
||||
BinaryWriters.WriteInt16BigEndian(bw, Convert.ToInt16(buffer.Length));
|
||||
bw.Write(buffer);
|
||||
}
|
||||
|
||||
private static void WriteBufferWithInt32Length(BinaryWriter bw, byte[] buffer)
|
||||
{
|
||||
BinaryWriters.WriteInt32BigEndian(bw, buffer.Length);
|
||||
bw.Write(buffer);
|
||||
}
|
||||
|
||||
private static void WriteDateTime(BinaryWriter bw, DateTime dateTime)
|
||||
{
|
||||
long unixMS = DateTimeUtilities.DateTimeToUnixMs(dateTime);
|
||||
BinaryWriters.WriteInt64BigEndian(bw, unixMS);
|
||||
}
|
||||
|
||||
private static void WriteTypedCertificate(BinaryWriter bw, X509Certificate cert)
|
||||
{
|
||||
WriteUtf(bw, "X.509");
|
||||
WriteBufferWithInt32Length(bw, cert.GetEncoded());
|
||||
}
|
||||
|
||||
private static void WriteUtf(BinaryWriter bw, string s)
|
||||
{
|
||||
byte[] utfBytes = Encoding.UTF8.GetBytes(s);
|
||||
|
||||
/*
|
||||
* FIXME JKS actually uses a "modified UTF-8" format. For the moment we will just support single-byte
|
||||
* encodings that aren't null bytes.
|
||||
*/
|
||||
for (int i = 0; i < utfBytes.Length; ++i)
|
||||
{
|
||||
byte utfByte = utfBytes[i];
|
||||
if (utfByte == 0 || (utfByte & 0x80) != 0)
|
||||
throw new NotSupportedException("Currently missing support for modified UTF-8 encoding in JKS");
|
||||
}
|
||||
|
||||
WriteBufferWithInt16Length(bw, utfBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* JksTrustedCertEntry is a internal container for the certificate entry.
|
||||
*/
|
||||
private sealed class JksTrustedCertEntry
|
||||
{
|
||||
internal readonly DateTime date;
|
||||
internal readonly X509Certificate cert;
|
||||
|
||||
internal JksTrustedCertEntry(DateTime date, X509Certificate cert)
|
||||
{
|
||||
this.date = date;
|
||||
this.cert = cert;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class JksKeyEntry
|
||||
{
|
||||
internal readonly DateTime date;
|
||||
internal readonly EncryptedPrivateKeyInfo keyData;
|
||||
internal readonly X509Certificate[] chain;
|
||||
|
||||
internal JksKeyEntry(DateTime date, byte[] keyData, X509Certificate[] chain)
|
||||
{
|
||||
this.date = date;
|
||||
this.keyData = EncryptedPrivateKeyInfo.GetInstance(Asn1Sequence.GetInstance(keyData));
|
||||
this.chain = chain;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ErasableByteStream
|
||||
: MemoryStream
|
||||
{
|
||||
internal ErasableByteStream(byte[] buffer, int index, int count)
|
||||
: base(buffer, index, count, false, true)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Position = 0L;
|
||||
|
||||
byte[] rawStore = GetBuffer();
|
||||
Array.Clear(rawStore, 0, rawStore.Length);
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76c504517a951fc4e8508cc041cd8ec8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class KeyException
|
||||
: GeneralSecurityException
|
||||
{
|
||||
public KeyException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public KeyException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public KeyException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected KeyException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 981c3b6a3e40ccc479b9b7c4a5e4568e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,238 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Iana;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Paddings;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <remarks>
|
||||
/// Utility class for creating HMac object from their names/Oids
|
||||
/// </remarks>
|
||||
public static class MacUtilities
|
||||
{
|
||||
private static readonly IDictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static MacUtilities()
|
||||
{
|
||||
Algorithms[IanaObjectIdentifiers.HmacMD5.Id] = "HMAC-MD5";
|
||||
Algorithms[IanaObjectIdentifiers.HmacRipeMD160.Id] = "HMAC-RIPEMD160";
|
||||
Algorithms[IanaObjectIdentifiers.HmacSha1.Id] = "HMAC-SHA1";
|
||||
Algorithms[IanaObjectIdentifiers.HmacTiger.Id] = "HMAC-TIGER";
|
||||
|
||||
Algorithms[PkcsObjectIdentifiers.IdHmacWithSha1.Id] = "HMAC-SHA1";
|
||||
Algorithms[MiscObjectIdentifiers.HMAC_SHA1.Id] = "HMAC-SHA1";
|
||||
Algorithms[PkcsObjectIdentifiers.IdHmacWithSha224.Id] = "HMAC-SHA224";
|
||||
Algorithms[PkcsObjectIdentifiers.IdHmacWithSha256.Id] = "HMAC-SHA256";
|
||||
Algorithms[PkcsObjectIdentifiers.IdHmacWithSha384.Id] = "HMAC-SHA384";
|
||||
Algorithms[PkcsObjectIdentifiers.IdHmacWithSha512.Id] = "HMAC-SHA512";
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdHMacWithSha3_224.Id] = "HMAC-SHA3-224";
|
||||
Algorithms[NistObjectIdentifiers.IdHMacWithSha3_256.Id] = "HMAC-SHA3-256";
|
||||
Algorithms[NistObjectIdentifiers.IdHMacWithSha3_384.Id] = "HMAC-SHA3-384";
|
||||
Algorithms[NistObjectIdentifiers.IdHMacWithSha3_512.Id] = "HMAC-SHA3-512";
|
||||
|
||||
Algorithms[RosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_256.Id] = "HMAC-GOST3411-2012-256";
|
||||
Algorithms[RosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_512.Id] = "HMAC-GOST3411-2012-512";
|
||||
|
||||
// TODO AESMAC?
|
||||
|
||||
Algorithms["DES"] = "DESMAC";
|
||||
Algorithms["DES/CFB8"] = "DESMAC/CFB8";
|
||||
Algorithms["DES64"] = "DESMAC64";
|
||||
Algorithms["DESEDE"] = "DESEDEMAC";
|
||||
Algorithms[PkcsObjectIdentifiers.DesEde3Cbc.Id] = "DESEDEMAC";
|
||||
Algorithms["DESEDE/CFB8"] = "DESEDEMAC/CFB8";
|
||||
Algorithms["DESISO9797MAC"] = "DESWITHISO9797";
|
||||
Algorithms["DESEDE64"] = "DESEDEMAC64";
|
||||
|
||||
Algorithms["DESEDE64WITHISO7816-4PADDING"] = "DESEDEMAC64WITHISO7816-4PADDING";
|
||||
Algorithms["DESEDEISO9797ALG1MACWITHISO7816-4PADDING"] = "DESEDEMAC64WITHISO7816-4PADDING";
|
||||
Algorithms["DESEDEISO9797ALG1WITHISO7816-4PADDING"] = "DESEDEMAC64WITHISO7816-4PADDING";
|
||||
|
||||
Algorithms["ISO9797ALG3"] = "ISO9797ALG3MAC";
|
||||
Algorithms["ISO9797ALG3MACWITHISO7816-4PADDING"] = "ISO9797ALG3WITHISO7816-4PADDING";
|
||||
|
||||
Algorithms["SKIPJACK"] = "SKIPJACKMAC";
|
||||
Algorithms["SKIPJACK/CFB8"] = "SKIPJACKMAC/CFB8";
|
||||
Algorithms["IDEA"] = "IDEAMAC";
|
||||
Algorithms["IDEA/CFB8"] = "IDEAMAC/CFB8";
|
||||
Algorithms["RC2"] = "RC2MAC";
|
||||
Algorithms["RC2/CFB8"] = "RC2MAC/CFB8";
|
||||
Algorithms["RC5"] = "RC5MAC";
|
||||
Algorithms["RC5/CFB8"] = "RC5MAC/CFB8";
|
||||
Algorithms["GOST28147"] = "GOST28147MAC";
|
||||
Algorithms["VMPC"] = "VMPCMAC";
|
||||
Algorithms["VMPC-MAC"] = "VMPCMAC";
|
||||
Algorithms["SIPHASH"] = "SIPHASH-2-4";
|
||||
|
||||
Algorithms["PBEWITHHMACSHA"] = "PBEWITHHMACSHA1";
|
||||
Algorithms["1.3.14.3.2.26"] = "PBEWITHHMACSHA1";
|
||||
}
|
||||
|
||||
public static IMac GetMac(DerObjectIdentifier id)
|
||||
{
|
||||
return GetMac(id.Id);
|
||||
}
|
||||
|
||||
public static IMac GetMac(string algorithm)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
string mechanism = CollectionUtilities.GetValueOrKey(Algorithms, algorithm).ToUpperInvariant();
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEWITH"))
|
||||
{
|
||||
mechanism = mechanism.Substring("PBEWITH".Length);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC"))
|
||||
{
|
||||
string digestName;
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC-") || Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC/"))
|
||||
{
|
||||
digestName = mechanism.Substring(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
digestName = mechanism.Substring(4);
|
||||
}
|
||||
|
||||
return new HMac(DigestUtilities.GetDigest(digestName));
|
||||
}
|
||||
|
||||
if (mechanism == "AESCMAC")
|
||||
{
|
||||
return new CMac(AesUtilities.CreateEngine());
|
||||
}
|
||||
if (mechanism == "DESMAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new DesEngine());
|
||||
}
|
||||
if (mechanism == "DESMAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new DesEngine());
|
||||
}
|
||||
if (mechanism == "DESMAC64")
|
||||
{
|
||||
return new CbcBlockCipherMac(new DesEngine(), 64);
|
||||
}
|
||||
if (mechanism == "DESEDECMAC")
|
||||
{
|
||||
return new CMac(new DesEdeEngine());
|
||||
}
|
||||
if (mechanism == "DESEDEMAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new DesEdeEngine());
|
||||
}
|
||||
if (mechanism == "DESEDEMAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new DesEdeEngine());
|
||||
}
|
||||
if (mechanism == "DESEDEMAC64")
|
||||
{
|
||||
return new CbcBlockCipherMac(new DesEdeEngine(), 64);
|
||||
}
|
||||
if (mechanism == "DESEDEMAC64WITHISO7816-4PADDING")
|
||||
{
|
||||
return new CbcBlockCipherMac(new DesEdeEngine(), 64, new ISO7816d4Padding());
|
||||
}
|
||||
if (mechanism == "DESWITHISO9797"
|
||||
|| mechanism == "ISO9797ALG3MAC")
|
||||
{
|
||||
return new ISO9797Alg3Mac(new DesEngine());
|
||||
}
|
||||
if (mechanism == "ISO9797ALG3WITHISO7816-4PADDING")
|
||||
{
|
||||
return new ISO9797Alg3Mac(new DesEngine(), new ISO7816d4Padding());
|
||||
}
|
||||
if (mechanism == "SKIPJACKMAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new SkipjackEngine());
|
||||
}
|
||||
if (mechanism == "SKIPJACKMAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new SkipjackEngine());
|
||||
}
|
||||
if (mechanism == "IDEAMAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new IdeaEngine());
|
||||
}
|
||||
if (mechanism == "IDEAMAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new IdeaEngine());
|
||||
}
|
||||
if (mechanism == "RC2MAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new RC2Engine());
|
||||
}
|
||||
if (mechanism == "RC2MAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new RC2Engine());
|
||||
}
|
||||
if (mechanism == "RC5MAC")
|
||||
{
|
||||
return new CbcBlockCipherMac(new RC532Engine());
|
||||
}
|
||||
if (mechanism == "RC5MAC/CFB8")
|
||||
{
|
||||
return new CfbBlockCipherMac(new RC532Engine());
|
||||
}
|
||||
if (mechanism == "GOST28147MAC")
|
||||
{
|
||||
return new Gost28147Mac();
|
||||
}
|
||||
if (mechanism == "VMPCMAC")
|
||||
{
|
||||
return new VmpcMac();
|
||||
}
|
||||
if (mechanism == "SIPHASH-2-4")
|
||||
{
|
||||
return new SipHash();
|
||||
}
|
||||
throw new SecurityUtilityException("Mac " + mechanism + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetAlgorithmName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, oid.Id);
|
||||
}
|
||||
|
||||
public static byte[] CalculateMac(string algorithm, ICipherParameters cp, byte[] input)
|
||||
{
|
||||
IMac mac = GetMac(algorithm);
|
||||
mac.Init(cp);
|
||||
mac.BlockUpdate(input, 0, input.Length);
|
||||
return DoFinal(mac);
|
||||
}
|
||||
|
||||
public static byte[] DoFinal(IMac mac)
|
||||
{
|
||||
byte[] b = new byte[mac.GetMacSize()];
|
||||
mac.DoFinal(b, 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
public static byte[] DoFinal(IMac mac, byte[] input)
|
||||
{
|
||||
mac.BlockUpdate(input, 0, input.Length);
|
||||
return DoFinal(mac);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc8314b890aed0843acbd81d9e6db0cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,361 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Kisa;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nsri;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public static class ParameterUtilities
|
||||
{
|
||||
private static readonly IDictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, int> BasicIVSizes =
|
||||
new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static ParameterUtilities()
|
||||
{
|
||||
AddAlgorithm("AES",
|
||||
"AESWRAP");
|
||||
AddAlgorithm("AES128",
|
||||
"2.16.840.1.101.3.4.2",
|
||||
NistObjectIdentifiers.IdAes128Cbc,
|
||||
NistObjectIdentifiers.IdAes128Ccm,
|
||||
NistObjectIdentifiers.IdAes128Cfb,
|
||||
NistObjectIdentifiers.IdAes128Ecb,
|
||||
NistObjectIdentifiers.IdAes128Gcm,
|
||||
NistObjectIdentifiers.IdAes128Ofb,
|
||||
NistObjectIdentifiers.IdAes128Wrap);
|
||||
AddAlgorithm("AES192",
|
||||
"2.16.840.1.101.3.4.22",
|
||||
NistObjectIdentifiers.IdAes192Cbc,
|
||||
NistObjectIdentifiers.IdAes192Ccm,
|
||||
NistObjectIdentifiers.IdAes192Cfb,
|
||||
NistObjectIdentifiers.IdAes192Ecb,
|
||||
NistObjectIdentifiers.IdAes192Gcm,
|
||||
NistObjectIdentifiers.IdAes192Ofb,
|
||||
NistObjectIdentifiers.IdAes192Wrap);
|
||||
AddAlgorithm("AES256",
|
||||
"2.16.840.1.101.3.4.42",
|
||||
NistObjectIdentifiers.IdAes256Cbc,
|
||||
NistObjectIdentifiers.IdAes256Ccm,
|
||||
NistObjectIdentifiers.IdAes256Cfb,
|
||||
NistObjectIdentifiers.IdAes256Ecb,
|
||||
NistObjectIdentifiers.IdAes256Gcm,
|
||||
NistObjectIdentifiers.IdAes256Ofb,
|
||||
NistObjectIdentifiers.IdAes256Wrap);
|
||||
AddAlgorithm("ARIA");
|
||||
AddAlgorithm("ARIA128",
|
||||
NsriObjectIdentifiers.id_aria128_cbc,
|
||||
NsriObjectIdentifiers.id_aria128_ccm,
|
||||
NsriObjectIdentifiers.id_aria128_cfb,
|
||||
NsriObjectIdentifiers.id_aria128_ctr,
|
||||
NsriObjectIdentifiers.id_aria128_ecb,
|
||||
NsriObjectIdentifiers.id_aria128_gcm,
|
||||
NsriObjectIdentifiers.id_aria128_ocb2,
|
||||
NsriObjectIdentifiers.id_aria128_ofb);
|
||||
AddAlgorithm("ARIA192",
|
||||
NsriObjectIdentifiers.id_aria192_cbc,
|
||||
NsriObjectIdentifiers.id_aria192_ccm,
|
||||
NsriObjectIdentifiers.id_aria192_cfb,
|
||||
NsriObjectIdentifiers.id_aria192_ctr,
|
||||
NsriObjectIdentifiers.id_aria192_ecb,
|
||||
NsriObjectIdentifiers.id_aria192_gcm,
|
||||
NsriObjectIdentifiers.id_aria192_ocb2,
|
||||
NsriObjectIdentifiers.id_aria192_ofb);
|
||||
AddAlgorithm("ARIA256",
|
||||
NsriObjectIdentifiers.id_aria256_cbc,
|
||||
NsriObjectIdentifiers.id_aria256_ccm,
|
||||
NsriObjectIdentifiers.id_aria256_cfb,
|
||||
NsriObjectIdentifiers.id_aria256_ctr,
|
||||
NsriObjectIdentifiers.id_aria256_ecb,
|
||||
NsriObjectIdentifiers.id_aria256_gcm,
|
||||
NsriObjectIdentifiers.id_aria256_ocb2,
|
||||
NsriObjectIdentifiers.id_aria256_ofb);
|
||||
AddAlgorithm("BLOWFISH",
|
||||
"1.3.6.1.4.1.3029.1.2");
|
||||
AddAlgorithm("CAMELLIA",
|
||||
"CAMELLIAWRAP");
|
||||
AddAlgorithm("CAMELLIA128",
|
||||
NttObjectIdentifiers.IdCamellia128Cbc,
|
||||
NttObjectIdentifiers.IdCamellia128Wrap);
|
||||
AddAlgorithm("CAMELLIA192",
|
||||
NttObjectIdentifiers.IdCamellia192Cbc,
|
||||
NttObjectIdentifiers.IdCamellia192Wrap);
|
||||
AddAlgorithm("CAMELLIA256",
|
||||
NttObjectIdentifiers.IdCamellia256Cbc,
|
||||
NttObjectIdentifiers.IdCamellia256Wrap);
|
||||
AddAlgorithm("CAST5",
|
||||
"1.2.840.113533.7.66.10");
|
||||
AddAlgorithm("CAST6");
|
||||
AddAlgorithm("CHACHA");
|
||||
AddAlgorithm("CHACHA7539",
|
||||
"CHACHA20",
|
||||
"CHACHA20-POLY1305",
|
||||
PkcsObjectIdentifiers.IdAlgAeadChaCha20Poly1305);
|
||||
AddAlgorithm("DES",
|
||||
OiwObjectIdentifiers.DesCbc,
|
||||
OiwObjectIdentifiers.DesCfb,
|
||||
OiwObjectIdentifiers.DesEcb,
|
||||
OiwObjectIdentifiers.DesOfb);
|
||||
AddAlgorithm("DESEDE",
|
||||
"DESEDEWRAP",
|
||||
"TDEA",
|
||||
OiwObjectIdentifiers.DesEde,
|
||||
PkcsObjectIdentifiers.IdAlgCms3DesWrap);
|
||||
AddAlgorithm("DESEDE3",
|
||||
PkcsObjectIdentifiers.DesEde3Cbc);
|
||||
AddAlgorithm("GOST28147",
|
||||
"GOST",
|
||||
"GOST-28147",
|
||||
CryptoProObjectIdentifiers.GostR28147Gcfb);
|
||||
AddAlgorithm("HC128");
|
||||
AddAlgorithm("HC256");
|
||||
AddAlgorithm("IDEA",
|
||||
"1.3.6.1.4.1.188.7.1.1.2");
|
||||
AddAlgorithm("NOEKEON");
|
||||
AddAlgorithm("RC2",
|
||||
PkcsObjectIdentifiers.RC2Cbc,
|
||||
PkcsObjectIdentifiers.IdAlgCmsRC2Wrap);
|
||||
AddAlgorithm("RC4",
|
||||
"ARC4",
|
||||
"1.2.840.113549.3.4");
|
||||
AddAlgorithm("RC5",
|
||||
"RC5-32");
|
||||
AddAlgorithm("RC5-64");
|
||||
AddAlgorithm("RC6");
|
||||
AddAlgorithm("RIJNDAEL");
|
||||
AddAlgorithm("SALSA20");
|
||||
AddAlgorithm("SEED",
|
||||
KisaObjectIdentifiers.IdNpkiAppCmsSeedWrap,
|
||||
KisaObjectIdentifiers.IdSeedCbc);
|
||||
AddAlgorithm("SERPENT");
|
||||
AddAlgorithm("SKIPJACK");
|
||||
AddAlgorithm("SM4");
|
||||
AddAlgorithm("TEA");
|
||||
AddAlgorithm("THREEFISH-256");
|
||||
AddAlgorithm("THREEFISH-512");
|
||||
AddAlgorithm("THREEFISH-1024");
|
||||
AddAlgorithm("TNEPRES");
|
||||
AddAlgorithm("TWOFISH");
|
||||
AddAlgorithm("VMPC");
|
||||
AddAlgorithm("VMPC-KSA3");
|
||||
AddAlgorithm("XTEA");
|
||||
|
||||
AddBasicIVSizeEntries(8, "BLOWFISH", "CHACHA", "DES", "DESEDE", "DESEDE3", "SALSA20");
|
||||
AddBasicIVSizeEntries(12, "CHACHA7539");
|
||||
AddBasicIVSizeEntries(16, "AES", "AES128", "AES192", "AES256", "ARIA", "ARIA128", "ARIA192", "ARIA256",
|
||||
"CAMELLIA", "CAMELLIA128", "CAMELLIA192", "CAMELLIA256", "NOEKEON", "SEED", "SM4");
|
||||
|
||||
// TODO These algorithms support an IV
|
||||
// but JCE doesn't seem to provide an AlgorithmParametersGenerator for them
|
||||
// "RIJNDAEL", "SKIPJACK", "TWOFISH"
|
||||
}
|
||||
|
||||
private static void AddAlgorithm(string canonicalName, params object[] aliases)
|
||||
{
|
||||
Algorithms[canonicalName] = canonicalName;
|
||||
|
||||
foreach (object alias in aliases)
|
||||
{
|
||||
Algorithms[alias.ToString()] = canonicalName;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddBasicIVSizeEntries(int size, params string[] algorithms)
|
||||
{
|
||||
foreach (string algorithm in algorithms)
|
||||
{
|
||||
BasicIVSizes.Add(algorithm, size);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetCanonicalAlgorithmName(string algorithm)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, algorithm);
|
||||
}
|
||||
|
||||
public static KeyParameter CreateKeyParameter(DerObjectIdentifier algOid, byte[] keyBytes)
|
||||
{
|
||||
return CreateKeyParameter(algOid.Id, keyBytes, 0, keyBytes.Length);
|
||||
}
|
||||
|
||||
public static KeyParameter CreateKeyParameter(string algorithm, byte[] keyBytes)
|
||||
{
|
||||
return CreateKeyParameter(algorithm, keyBytes, 0, keyBytes.Length);
|
||||
}
|
||||
|
||||
public static KeyParameter CreateKeyParameter(
|
||||
DerObjectIdentifier algOid,
|
||||
byte[] keyBytes,
|
||||
int offset,
|
||||
int length)
|
||||
{
|
||||
return CreateKeyParameter(algOid.Id, keyBytes, offset, length);
|
||||
}
|
||||
|
||||
public static KeyParameter CreateKeyParameter(
|
||||
string algorithm,
|
||||
byte[] keyBytes,
|
||||
int offset,
|
||||
int length)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
string canonical = GetCanonicalAlgorithmName(algorithm);
|
||||
|
||||
if (canonical == null)
|
||||
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
|
||||
|
||||
if (canonical == "DES")
|
||||
return new DesParameters(keyBytes, offset, length);
|
||||
|
||||
if (canonical == "DESEDE" || canonical =="DESEDE3")
|
||||
return new DesEdeParameters(keyBytes, offset, length);
|
||||
|
||||
if (canonical == "RC2")
|
||||
return new RC2Parameters(keyBytes, offset, length);
|
||||
|
||||
return new KeyParameter(keyBytes, offset, length);
|
||||
}
|
||||
|
||||
public static ICipherParameters GetCipherParameters(
|
||||
DerObjectIdentifier algOid,
|
||||
ICipherParameters key,
|
||||
Asn1Object asn1Params)
|
||||
{
|
||||
return GetCipherParameters(algOid.Id, key, asn1Params);
|
||||
}
|
||||
|
||||
public static ICipherParameters GetCipherParameters(
|
||||
string algorithm,
|
||||
ICipherParameters key,
|
||||
Asn1Object asn1Params)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException("algorithm");
|
||||
|
||||
string canonical = GetCanonicalAlgorithmName(algorithm);
|
||||
|
||||
if (canonical == null)
|
||||
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
|
||||
|
||||
byte[] iv = null;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO These algorithms support an IV
|
||||
// but JCE doesn't seem to provide an AlgorithmParametersGenerator for them
|
||||
// "RIJNDAEL", "SKIPJACK", "TWOFISH"
|
||||
|
||||
int basicIVKeySize = FindBasicIVSize(canonical);
|
||||
if (basicIVKeySize != -1
|
||||
|| canonical == "RIJNDAEL" || canonical == "SKIPJACK" || canonical == "TWOFISH")
|
||||
{
|
||||
iv = ((Asn1OctetString) asn1Params).GetOctets();
|
||||
}
|
||||
else if (canonical == "CAST5")
|
||||
{
|
||||
iv = Cast5CbcParameters.GetInstance(asn1Params).GetIV();
|
||||
}
|
||||
else if (canonical == "IDEA")
|
||||
{
|
||||
iv = IdeaCbcPar.GetInstance(asn1Params).GetIV();
|
||||
}
|
||||
else if (canonical == "RC2")
|
||||
{
|
||||
iv = RC2CbcParameter.GetInstance(asn1Params).GetIV();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentException("Could not process ASN.1 parameters", e);
|
||||
}
|
||||
|
||||
if (iv != null)
|
||||
{
|
||||
return new ParametersWithIV(key, iv);
|
||||
}
|
||||
|
||||
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static Asn1Encodable GenerateParameters(
|
||||
DerObjectIdentifier algID,
|
||||
SecureRandom random)
|
||||
{
|
||||
return GenerateParameters(algID.Id, random);
|
||||
}
|
||||
|
||||
public static Asn1Encodable GenerateParameters(
|
||||
string algorithm,
|
||||
SecureRandom random)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException("algorithm");
|
||||
|
||||
string canonical = GetCanonicalAlgorithmName(algorithm);
|
||||
|
||||
if (canonical == null)
|
||||
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
|
||||
|
||||
// TODO These algorithms support an IV
|
||||
// but JCE doesn't seem to provide an AlgorithmParametersGenerator for them
|
||||
// "RIJNDAEL", "SKIPJACK", "TWOFISH"
|
||||
|
||||
int basicIVKeySize = FindBasicIVSize(canonical);
|
||||
if (basicIVKeySize != -1)
|
||||
return CreateIVOctetString(random, basicIVKeySize);
|
||||
|
||||
if (canonical == "CAST5")
|
||||
return new Cast5CbcParameters(CreateIV(random, 8), 128);
|
||||
|
||||
if (canonical == "IDEA")
|
||||
return new IdeaCbcPar(CreateIV(random, 8));
|
||||
|
||||
if (canonical == "RC2")
|
||||
return new RC2CbcParameter(CreateIV(random, 8));
|
||||
|
||||
throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static ICipherParameters WithRandom(ICipherParameters cp, SecureRandom random)
|
||||
{
|
||||
if (random != null)
|
||||
{
|
||||
cp = new ParametersWithRandom(cp, random);
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
private static Asn1OctetString CreateIVOctetString(SecureRandom random, int ivLength)
|
||||
{
|
||||
return new DerOctetString(CreateIV(random, ivLength));
|
||||
}
|
||||
|
||||
private static byte[] CreateIV(SecureRandom random, int ivLength)
|
||||
{
|
||||
return SecureRandom.GetNextBytes(random, ivLength);
|
||||
}
|
||||
|
||||
private static int FindBasicIVSize(string canonicalName)
|
||||
{
|
||||
return BasicIVSizes.TryGetValue(canonicalName, out int keySize) ? keySize : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c1511264e2b6be42bd6afc367283966
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,696 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.BC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class PbeUtilities
|
||||
{
|
||||
const string Pkcs5S1 = "Pkcs5S1";
|
||||
const string Pkcs5S2 = "Pkcs5S2";
|
||||
const string Pkcs12 = "Pkcs12";
|
||||
const string OpenSsl = "OpenSsl";
|
||||
|
||||
private static readonly IDictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, string> AlgorithmType =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly IDictionary<string, DerObjectIdentifier> Oids =
|
||||
new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static PbeUtilities()
|
||||
{
|
||||
Algorithms["PKCS5SCHEME1"] = "Pkcs5scheme1";
|
||||
Algorithms["PKCS5SCHEME2"] = "Pkcs5scheme2";
|
||||
Algorithms["PBKDF2"] = "Pkcs5scheme2";
|
||||
Algorithms[PkcsObjectIdentifiers.IdPbeS2.Id] = "Pkcs5scheme2";
|
||||
// algorithms[PkcsObjectIdentifiers.IdPbkdf2.Id] = "Pkcs5scheme2";
|
||||
|
||||
// FIXME Add support for these? (see Pkcs8Generator)
|
||||
// algorithms[PkcsObjectIdentifiers.DesEde3Cbc.Id] = "Pkcs5scheme2";
|
||||
// algorithms[NistObjectIdentifiers.IdAes128Cbc.Id] = "Pkcs5scheme2";
|
||||
// algorithms[NistObjectIdentifiers.IdAes192Cbc.Id] = "Pkcs5scheme2";
|
||||
// algorithms[NistObjectIdentifiers.IdAes256Cbc.Id] = "Pkcs5scheme2";
|
||||
|
||||
Algorithms["PBEWITHMD2ANDDES-CBC"] = "PBEwithMD2andDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithMD2AndDesCbc.Id] = "PBEwithMD2andDES-CBC";
|
||||
Algorithms["PBEWITHMD2ANDRC2-CBC"] = "PBEwithMD2andRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithMD2AndRC2Cbc.Id] = "PBEwithMD2andRC2-CBC";
|
||||
Algorithms["PBEWITHMD5ANDDES-CBC"] = "PBEwithMD5andDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithMD5AndDesCbc.Id] = "PBEwithMD5andDES-CBC";
|
||||
Algorithms["PBEWITHMD5ANDRC2-CBC"] = "PBEwithMD5andRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithMD5AndRC2Cbc.Id] = "PBEwithMD5andRC2-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDDES"] = "PBEwithSHA-1andDES-CBC";
|
||||
Algorithms["PBEWITHSHA-1ANDDES"] = "PBEwithSHA-1andDES-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDDES-CBC"] = "PBEwithSHA-1andDES-CBC";
|
||||
Algorithms["PBEWITHSHA-1ANDDES-CBC"] = "PBEwithSHA-1andDES-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithSha1AndDesCbc.Id] = "PBEwithSHA-1andDES-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDRC2"] = "PBEwithSHA-1andRC2-CBC";
|
||||
Algorithms["PBEWITHSHA-1ANDRC2"] = "PBEwithSHA-1andRC2-CBC";
|
||||
Algorithms["PBEWITHSHA1ANDRC2-CBC"] = "PBEwithSHA-1andRC2-CBC";
|
||||
Algorithms["PBEWITHSHA-1ANDRC2-CBC"] = "PBEwithSHA-1andRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithSha1AndRC2Cbc.Id] = "PBEwithSHA-1andRC2-CBC";
|
||||
Algorithms["PKCS12"] = "Pkcs12";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc.Id] = "PBEwithSHA-1and128bitAES-CBC-BC";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc.Id] = "PBEwithSHA-1and192bitAES-CBC-BC";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc.Id] = "PBEwithSHA-1and256bitAES-CBC-BC";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.Id] = "PBEwithSHA-256and128bitAES-CBC-BC";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.Id] = "PBEwithSHA-256and192bitAES-CBC-BC";
|
||||
Algorithms[BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.Id] = "PBEwithSHA-256and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHAAND128BITRC4"] = "PBEwithSHA-1and128bitRC4";
|
||||
Algorithms["PBEWITHSHA1AND128BITRC4"] = "PBEwithSHA-1and128bitRC4";
|
||||
Algorithms["PBEWITHSHA-1AND128BITRC4"] = "PBEwithSHA-1and128bitRC4";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC4.Id] = "PBEwithSHA-1and128bitRC4";
|
||||
Algorithms["PBEWITHSHAAND40BITRC4"] = "PBEwithSHA-1and40bitRC4";
|
||||
Algorithms["PBEWITHSHA1AND40BITRC4"] = "PBEwithSHA-1and40bitRC4";
|
||||
Algorithms["PBEWITHSHA-1AND40BITRC4"] = "PBEwithSHA-1and40bitRC4";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd40BitRC4.Id] = "PBEwithSHA-1and40bitRC4";
|
||||
Algorithms["PBEWITHSHAAND3-KEYDESEDE-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHAAND3-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA1AND3-KEYDESEDE-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA1AND3-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND3-KEYDESEDE-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND3-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc.Id] = "PBEwithSHA-1and3-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHAAND2-KEYDESEDE-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHAAND2-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA1AND2-KEYDESEDE-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA1AND2-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND2-KEYDESEDE-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND2-KEYTRIPLEDES-CBC"] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd2KeyTripleDesCbc.Id] = "PBEwithSHA-1and2-keyDESEDE-CBC";
|
||||
Algorithms["PBEWITHSHAAND128BITRC2-CBC"] = "PBEwithSHA-1and128bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHA1AND128BITRC2-CBC"] = "PBEwithSHA-1and128bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND128BITRC2-CBC"] = "PBEwithSHA-1and128bitRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC2Cbc.Id] = "PBEwithSHA-1and128bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHAAND40BITRC2-CBC"] = "PBEwithSHA-1and40bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHA1AND40BITRC2-CBC"] = "PBEwithSHA-1and40bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHA-1AND40BITRC2-CBC"] = "PBEwithSHA-1and40bitRC2-CBC";
|
||||
Algorithms[PkcsObjectIdentifiers.PbewithShaAnd40BitRC2Cbc.Id] = "PBEwithSHA-1and40bitRC2-CBC";
|
||||
Algorithms["PBEWITHSHAAND128BITAES-CBC-BC"] = "PBEwithSHA-1and128bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA1AND128BITAES-CBC-BC"] = "PBEwithSHA-1and128bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND128BITAES-CBC-BC"] = "PBEwithSHA-1and128bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHAAND192BITAES-CBC-BC"] = "PBEwithSHA-1and192bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA1AND192BITAES-CBC-BC"] = "PBEwithSHA-1and192bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND192BITAES-CBC-BC"] = "PBEwithSHA-1and192bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHAAND256BITAES-CBC-BC"] = "PBEwithSHA-1and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA1AND256BITAES-CBC-BC"] = "PBEwithSHA-1and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-1AND256BITAES-CBC-BC"] = "PBEwithSHA-1and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA256AND128BITAES-CBC-BC"] = "PBEwithSHA-256and128bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-256AND128BITAES-CBC-BC"] = "PBEwithSHA-256and128bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA256AND192BITAES-CBC-BC"] = "PBEwithSHA-256and192bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-256AND192BITAES-CBC-BC"] = "PBEwithSHA-256and192bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA256AND256BITAES-CBC-BC"] = "PBEwithSHA-256and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHA-256AND256BITAES-CBC-BC"] = "PBEwithSHA-256and256bitAES-CBC-BC";
|
||||
Algorithms["PBEWITHSHAANDIDEA"] = "PBEwithSHA-1andIDEA-CBC";
|
||||
Algorithms["PBEWITHSHAANDIDEA-CBC"] = "PBEwithSHA-1andIDEA-CBC";
|
||||
Algorithms["PBEWITHSHAANDTWOFISH"] = "PBEwithSHA-1andTWOFISH-CBC";
|
||||
Algorithms["PBEWITHSHAANDTWOFISH-CBC"] = "PBEwithSHA-1andTWOFISH-CBC";
|
||||
Algorithms["PBEWITHHMACSHA1"] = "PBEwithHmacSHA-1";
|
||||
Algorithms["PBEWITHHMACSHA-1"] = "PBEwithHmacSHA-1";
|
||||
Algorithms[OiwObjectIdentifiers.IdSha1.Id] = "PBEwithHmacSHA-1";
|
||||
Algorithms["PBEWITHHMACSHA224"] = "PBEwithHmacSHA-224";
|
||||
Algorithms["PBEWITHHMACSHA-224"] = "PBEwithHmacSHA-224";
|
||||
Algorithms[NistObjectIdentifiers.IdSha224.Id] = "PBEwithHmacSHA-224";
|
||||
Algorithms["PBEWITHHMACSHA256"] = "PBEwithHmacSHA-256";
|
||||
Algorithms["PBEWITHHMACSHA-256"] = "PBEwithHmacSHA-256";
|
||||
Algorithms[NistObjectIdentifiers.IdSha256.Id] = "PBEwithHmacSHA-256";
|
||||
Algorithms["PBEWITHHMACRIPEMD128"] = "PBEwithHmacRipeMD128";
|
||||
Algorithms[TeleTrusTObjectIdentifiers.RipeMD128.Id] = "PBEwithHmacRipeMD128";
|
||||
Algorithms["PBEWITHHMACRIPEMD160"] = "PBEwithHmacRipeMD160";
|
||||
Algorithms[TeleTrusTObjectIdentifiers.RipeMD160.Id] = "PBEwithHmacRipeMD160";
|
||||
Algorithms["PBEWITHHMACRIPEMD256"] = "PBEwithHmacRipeMD256";
|
||||
Algorithms[TeleTrusTObjectIdentifiers.RipeMD256.Id] = "PBEwithHmacRipeMD256";
|
||||
Algorithms["PBEWITHHMACTIGER"] = "PBEwithHmacTiger";
|
||||
|
||||
Algorithms["PBEWITHMD5AND128BITAES-CBC-OPENSSL"] = "PBEwithMD5and128bitAES-CBC-OpenSSL";
|
||||
Algorithms["PBEWITHMD5AND192BITAES-CBC-OPENSSL"] = "PBEwithMD5and192bitAES-CBC-OpenSSL";
|
||||
Algorithms["PBEWITHMD5AND256BITAES-CBC-OPENSSL"] = "PBEwithMD5and256bitAES-CBC-OpenSSL";
|
||||
|
||||
AlgorithmType["Pkcs5scheme1"] = Pkcs5S1;
|
||||
AlgorithmType["Pkcs5scheme2"] = Pkcs5S2;
|
||||
AlgorithmType["PBEwithMD2andDES-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["PBEwithMD2andRC2-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["PBEwithMD5andDES-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["PBEwithMD5andRC2-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["PBEwithSHA-1andDES-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["PBEwithSHA-1andRC2-CBC"] = Pkcs5S1;
|
||||
AlgorithmType["Pkcs12"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and128bitRC4"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and40bitRC4"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and3-keyDESEDE-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and2-keyDESEDE-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and128bitRC2-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and40bitRC2-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and128bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and192bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1and256bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-256and128bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-256and192bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-256and256bitAES-CBC-BC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1andIDEA-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithSHA-1andTWOFISH-CBC"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacSHA-1"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacSHA-224"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacSHA-256"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacRipeMD128"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacRipeMD160"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacRipeMD256"] = Pkcs12;
|
||||
AlgorithmType["PBEwithHmacTiger"] = Pkcs12;
|
||||
|
||||
AlgorithmType["PBEwithMD5and128bitAES-CBC-OpenSSL"] = OpenSsl;
|
||||
AlgorithmType["PBEwithMD5and192bitAES-CBC-OpenSSL"] = OpenSsl;
|
||||
AlgorithmType["PBEwithMD5and256bitAES-CBC-OpenSSL"] = OpenSsl;
|
||||
|
||||
Oids["PBEwithMD2andDES-CBC"] = PkcsObjectIdentifiers.PbeWithMD2AndDesCbc;
|
||||
Oids["PBEwithMD2andRC2-CBC"] = PkcsObjectIdentifiers.PbeWithMD2AndRC2Cbc;
|
||||
Oids["PBEwithMD5andDES-CBC"] = PkcsObjectIdentifiers.PbeWithMD5AndDesCbc;
|
||||
Oids["PBEwithMD5andRC2-CBC"] = PkcsObjectIdentifiers.PbeWithMD5AndRC2Cbc;
|
||||
Oids["PBEwithSHA-1andDES-CBC"] = PkcsObjectIdentifiers.PbeWithSha1AndDesCbc;
|
||||
Oids["PBEwithSHA-1andRC2-CBC"] = PkcsObjectIdentifiers.PbeWithSha1AndRC2Cbc;
|
||||
Oids["PBEwithSHA-1and128bitRC4"] = PkcsObjectIdentifiers.PbeWithShaAnd128BitRC4;
|
||||
Oids["PBEwithSHA-1and40bitRC4"] = PkcsObjectIdentifiers.PbeWithShaAnd40BitRC4;
|
||||
Oids["PBEwithSHA-1and3-keyDESEDE-CBC"] = PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc;
|
||||
Oids["PBEwithSHA-1and2-keyDESEDE-CBC"] = PkcsObjectIdentifiers.PbeWithShaAnd2KeyTripleDesCbc;
|
||||
Oids["PBEwithSHA-1and128bitRC2-CBC"] = PkcsObjectIdentifiers.PbeWithShaAnd128BitRC2Cbc;
|
||||
Oids["PBEwithSHA-1and40bitRC2-CBC"] = PkcsObjectIdentifiers.PbewithShaAnd40BitRC2Cbc;
|
||||
Oids["PBEwithHmacSHA-1"] = OiwObjectIdentifiers.IdSha1;
|
||||
Oids["PBEwithHmacSHA-224"] = NistObjectIdentifiers.IdSha224;
|
||||
Oids["PBEwithHmacSHA-256"] = NistObjectIdentifiers.IdSha256;
|
||||
Oids["PBEwithHmacRipeMD128"] = TeleTrusTObjectIdentifiers.RipeMD128;
|
||||
Oids["PBEwithHmacRipeMD160"] = TeleTrusTObjectIdentifiers.RipeMD160;
|
||||
Oids["PBEwithHmacRipeMD256"] = TeleTrusTObjectIdentifiers.RipeMD256;
|
||||
Oids["Pkcs5scheme2"] = PkcsObjectIdentifiers.IdPbeS2;
|
||||
}
|
||||
|
||||
static PbeParametersGenerator MakePbeGenerator(
|
||||
string type,
|
||||
IDigest digest,
|
||||
byte[] key,
|
||||
byte[] salt,
|
||||
int iterationCount)
|
||||
{
|
||||
PbeParametersGenerator generator;
|
||||
|
||||
if (type.Equals(Pkcs5S1))
|
||||
{
|
||||
generator = new Pkcs5S1ParametersGenerator(digest);
|
||||
}
|
||||
else if (type.Equals(Pkcs5S2))
|
||||
{
|
||||
generator = new Pkcs5S2ParametersGenerator(digest);
|
||||
}
|
||||
else if (type.Equals(Pkcs12))
|
||||
{
|
||||
generator = new Pkcs12ParametersGenerator(digest);
|
||||
}
|
||||
else if (type.Equals(OpenSsl))
|
||||
{
|
||||
generator = new OpenSslPbeParametersGenerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Unknown PBE type: " + type, "type");
|
||||
}
|
||||
|
||||
generator.Init(key, salt, iterationCount);
|
||||
return generator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ObjectIdentifier for a give encoding.
|
||||
/// </summary>
|
||||
/// <param name="mechanism">A string representation of the encoding.</param>
|
||||
/// <returns>A DerObjectIdentifier, null if the Oid is not available.</returns>
|
||||
public static DerObjectIdentifier GetObjectIdentifier(string mechanism)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(mechanism, out var algorithm))
|
||||
return null;
|
||||
|
||||
return CollectionUtilities.GetValueOrNull(Oids, algorithm);
|
||||
}
|
||||
|
||||
//public static ICollection Algorithms
|
||||
//{
|
||||
// get { return oids.Keys; }
|
||||
//}
|
||||
|
||||
public static bool IsPkcs12(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var mechanism))
|
||||
return false;
|
||||
if (!AlgorithmType.TryGetValue(mechanism, out var algorithmType))
|
||||
return false;
|
||||
|
||||
return Pkcs12.Equals(algorithmType);
|
||||
}
|
||||
|
||||
public static bool IsPkcs5Scheme1(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var mechanism))
|
||||
return false;
|
||||
if (!AlgorithmType.TryGetValue(mechanism, out var algorithmType))
|
||||
return false;
|
||||
|
||||
return Pkcs5S1.Equals(algorithmType);
|
||||
}
|
||||
|
||||
public static bool IsPkcs5Scheme2(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var mechanism))
|
||||
return false;
|
||||
if (!AlgorithmType.TryGetValue(mechanism, out var algorithmType))
|
||||
return false;
|
||||
|
||||
return Pkcs5S2.Equals(algorithmType);
|
||||
}
|
||||
|
||||
public static bool IsOpenSsl(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var mechanism))
|
||||
return false;
|
||||
if (!AlgorithmType.TryGetValue(mechanism, out var algorithmType))
|
||||
return false;
|
||||
|
||||
return OpenSsl.Equals(algorithmType);
|
||||
}
|
||||
|
||||
public static bool IsPbeAlgorithm(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var mechanism))
|
||||
return false;
|
||||
|
||||
return AlgorithmType.ContainsKey(mechanism);
|
||||
}
|
||||
|
||||
public static Asn1Encodable GenerateAlgorithmParameters(
|
||||
DerObjectIdentifier algorithmOid,
|
||||
byte[] salt,
|
||||
int iterationCount)
|
||||
{
|
||||
return GenerateAlgorithmParameters(algorithmOid.Id, salt, iterationCount);
|
||||
}
|
||||
|
||||
public static Asn1Encodable GenerateAlgorithmParameters(
|
||||
string algorithm,
|
||||
byte[] salt,
|
||||
int iterationCount)
|
||||
{
|
||||
if (IsPkcs12(algorithm))
|
||||
{
|
||||
return new Pkcs12PbeParams(salt, iterationCount);
|
||||
}
|
||||
else if (IsPkcs5Scheme2(algorithm))
|
||||
{
|
||||
return new Pbkdf2Params(salt, iterationCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new PbeParameter(salt, iterationCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static Asn1Encodable GenerateAlgorithmParameters(
|
||||
DerObjectIdentifier cipherAlgorithm,
|
||||
DerObjectIdentifier hashAlgorithm,
|
||||
byte[] salt,
|
||||
int iterationCount,
|
||||
SecureRandom secureRandom)
|
||||
{
|
||||
EncryptionScheme encScheme;
|
||||
if (NistObjectIdentifiers.IdAes128Cbc.Equals(cipherAlgorithm)
|
||||
|| NistObjectIdentifiers.IdAes192Cbc.Equals(cipherAlgorithm)
|
||||
|| NistObjectIdentifiers.IdAes256Cbc.Equals(cipherAlgorithm)
|
||||
|| NistObjectIdentifiers.IdAes128Cfb.Equals(cipherAlgorithm)
|
||||
|| NistObjectIdentifiers.IdAes192Cfb.Equals(cipherAlgorithm)
|
||||
|| NistObjectIdentifiers.IdAes256Cfb.Equals(cipherAlgorithm))
|
||||
{
|
||||
byte[] iv = new byte[16];
|
||||
secureRandom.NextBytes(iv);
|
||||
encScheme = new EncryptionScheme(cipherAlgorithm, new DerOctetString(iv));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("unknown cipher: " + cipherAlgorithm);
|
||||
}
|
||||
|
||||
KeyDerivationFunc func = new KeyDerivationFunc(PkcsObjectIdentifiers.IdPbkdf2, new Pbkdf2Params(salt, iterationCount, new AlgorithmIdentifier(hashAlgorithm, DerNull.Instance)));
|
||||
|
||||
return new PbeS2Parameters(func, encScheme);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
DerObjectIdentifier algorithmOid,
|
||||
char[] password,
|
||||
Asn1Encodable pbeParameters)
|
||||
{
|
||||
return GenerateCipherParameters(algorithmOid.Id, password, false, pbeParameters);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
DerObjectIdentifier algorithmOid,
|
||||
char[] password,
|
||||
bool wrongPkcs12Zero,
|
||||
Asn1Encodable pbeParameters)
|
||||
{
|
||||
return GenerateCipherParameters(algorithmOid.Id, password, wrongPkcs12Zero, pbeParameters);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
AlgorithmIdentifier algID,
|
||||
char[] password)
|
||||
{
|
||||
return GenerateCipherParameters(algID.Algorithm.Id, password, false, algID.Parameters);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
AlgorithmIdentifier algID,
|
||||
char[] password,
|
||||
bool wrongPkcs12Zero)
|
||||
{
|
||||
return GenerateCipherParameters(algID.Algorithm.Id, password, wrongPkcs12Zero, algID.Parameters);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
string algorithm,
|
||||
char[] password,
|
||||
Asn1Encodable pbeParameters)
|
||||
{
|
||||
return GenerateCipherParameters(algorithm, password, false, pbeParameters);
|
||||
}
|
||||
|
||||
public static ICipherParameters GenerateCipherParameters(
|
||||
string algorithm,
|
||||
char[] password,
|
||||
bool wrongPkcs12Zero,
|
||||
Asn1Encodable pbeParameters)
|
||||
{
|
||||
string mechanism = CollectionUtilities.GetValueOrNull(Algorithms, algorithm);
|
||||
|
||||
byte[] keyBytes = null;
|
||||
byte[] salt = null;
|
||||
int iterationCount = 0;
|
||||
|
||||
if (IsPkcs12(mechanism))
|
||||
{
|
||||
Pkcs12PbeParams pbeParams = Pkcs12PbeParams.GetInstance(pbeParameters);
|
||||
salt = pbeParams.GetIV();
|
||||
iterationCount = pbeParams.Iterations.IntValue;
|
||||
keyBytes = PbeParametersGenerator.Pkcs12PasswordToBytes(password, wrongPkcs12Zero);
|
||||
}
|
||||
else if (IsPkcs5Scheme2(mechanism))
|
||||
{
|
||||
// See below
|
||||
}
|
||||
else
|
||||
{
|
||||
PbeParameter pbeParams = PbeParameter.GetInstance(pbeParameters);
|
||||
salt = pbeParams.GetSalt();
|
||||
iterationCount = pbeParams.IterationCount.IntValue;
|
||||
keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);
|
||||
}
|
||||
|
||||
ICipherParameters parameters = null;
|
||||
|
||||
if (IsPkcs5Scheme2(mechanism))
|
||||
{
|
||||
PbeS2Parameters s2p = PbeS2Parameters.GetInstance(pbeParameters.ToAsn1Object());
|
||||
AlgorithmIdentifier encScheme = s2p.EncryptionScheme;
|
||||
DerObjectIdentifier encOid = encScheme.Algorithm;
|
||||
Asn1Object encParams = encScheme.Parameters.ToAsn1Object();
|
||||
|
||||
Pbkdf2Params pbeParams = Pbkdf2Params.GetInstance(s2p.KeyDerivationFunc.Parameters.ToAsn1Object());
|
||||
IDigest digest = DigestUtilities.GetDigest(pbeParams.Prf.Algorithm);
|
||||
|
||||
byte[] iv;
|
||||
if (encOid.Equals(PkcsObjectIdentifiers.RC2Cbc)) // PKCS5.B.2.3
|
||||
{
|
||||
RC2CbcParameter rc2Params = RC2CbcParameter.GetInstance(encParams);
|
||||
iv = rc2Params.GetIV();
|
||||
}
|
||||
else
|
||||
{
|
||||
iv = Asn1OctetString.GetInstance(encParams).GetOctets();
|
||||
}
|
||||
|
||||
salt = pbeParams.GetSalt();
|
||||
iterationCount = pbeParams.IterationCount.IntValue;
|
||||
keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);
|
||||
|
||||
int keyLength = pbeParams.KeyLength != null
|
||||
? pbeParams.KeyLength.IntValue * 8
|
||||
: GeneratorUtilities.GetDefaultKeySize(encOid);
|
||||
|
||||
PbeParametersGenerator gen = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], digest, keyBytes, salt, iterationCount);
|
||||
|
||||
parameters = gen.GenerateDerivedParameters(encOid.Id, keyLength);
|
||||
|
||||
if (iv != null)
|
||||
{
|
||||
// FIXME? OpenSSL weirdness with IV of zeros (for ECB keys?)
|
||||
if (Arrays.AreEqual(iv, new byte[iv.Length]))
|
||||
{
|
||||
//Console.Error.Write("***** IV all 0 (length " + iv.Length + ") *****");
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters = new ParametersWithIV(parameters, iv);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithSHA-1"))
|
||||
{
|
||||
PbeParametersGenerator generator = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], new Sha1Digest(), keyBytes, salt, iterationCount);
|
||||
|
||||
if (mechanism.Equals("PBEwithSHA-1and128bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 128, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and192bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 192, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and256bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 256, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and128bitRC4"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC4", 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and40bitRC4"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC4", 40);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and3-keyDESEDE-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("DESEDE", 192, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and2-keyDESEDE-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("DESEDE", 128, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and128bitRC2-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC2", 128, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1and40bitRC2-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC2", 40, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1andDES-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("DES", 64, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-1andRC2-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithSHA-256"))
|
||||
{
|
||||
PbeParametersGenerator generator = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], new Sha256Digest(), keyBytes, salt, iterationCount);
|
||||
|
||||
if (mechanism.Equals("PBEwithSHA-256and128bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 128, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-256and192bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 192, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithSHA-256and256bitAES-CBC-BC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 256, 128);
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithMD5"))
|
||||
{
|
||||
PbeParametersGenerator generator = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], new MD5Digest(), keyBytes, salt, iterationCount);
|
||||
|
||||
if (mechanism.Equals("PBEwithMD5andDES-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("DES", 64, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithMD5andRC2-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithMD5and128bitAES-CBC-OpenSSL"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 128, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithMD5and192bitAES-CBC-OpenSSL"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 192, 128);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithMD5and256bitAES-CBC-OpenSSL"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("AES", 256, 128);
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithMD2"))
|
||||
{
|
||||
PbeParametersGenerator generator = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], new MD2Digest(), keyBytes, salt, iterationCount);
|
||||
if (mechanism.Equals("PBEwithMD2andDES-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("DES", 64, 64);
|
||||
}
|
||||
else if (mechanism.Equals("PBEwithMD2andRC2-CBC"))
|
||||
{
|
||||
parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
|
||||
}
|
||||
}
|
||||
else if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithHmac"))
|
||||
{
|
||||
string digestName = mechanism.Substring("PBEwithHmac".Length);
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
|
||||
PbeParametersGenerator generator = MakePbeGenerator(
|
||||
AlgorithmType[mechanism], digest, keyBytes, salt, iterationCount);
|
||||
|
||||
int bitLen = digest.GetDigestSize() * 8;
|
||||
parameters = generator.GenerateDerivedMacParameters(bitLen);
|
||||
}
|
||||
|
||||
Array.Clear(keyBytes, 0, keyBytes.Length);
|
||||
|
||||
return FixDesParity(mechanism, parameters);
|
||||
}
|
||||
|
||||
public static object CreateEngine(
|
||||
DerObjectIdentifier algorithmOid)
|
||||
{
|
||||
return CreateEngine(algorithmOid.Id);
|
||||
}
|
||||
|
||||
public static object CreateEngine(
|
||||
AlgorithmIdentifier algID)
|
||||
{
|
||||
string algorithm = algID.Algorithm.Id;
|
||||
|
||||
if (IsPkcs5Scheme2(algorithm))
|
||||
{
|
||||
PbeS2Parameters s2p = PbeS2Parameters.GetInstance(algID.Parameters.ToAsn1Object());
|
||||
AlgorithmIdentifier encScheme = s2p.EncryptionScheme;
|
||||
return CipherUtilities.GetCipher(encScheme.Algorithm);
|
||||
}
|
||||
|
||||
return CreateEngine(algorithm);
|
||||
}
|
||||
|
||||
public static object CreateEngine(string algorithm)
|
||||
{
|
||||
string mechanism = CollectionUtilities.GetValueOrNull(Algorithms, algorithm);
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithHmac"))
|
||||
{
|
||||
string digestName = mechanism.Substring("PBEwithHmac".Length);
|
||||
|
||||
return MacUtilities.GetMac("HMAC/" + digestName);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithMD2")
|
||||
|| Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithMD5")
|
||||
|| Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithSHA-1")
|
||||
|| Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEwithSHA-256"))
|
||||
{
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "AES-CBC-BC") || Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "AES-CBC-OPENSSL"))
|
||||
{
|
||||
return CipherUtilities.GetCipher("AES/CBC");
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "DES-CBC"))
|
||||
{
|
||||
return CipherUtilities.GetCipher("DES/CBC");
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "DESEDE-CBC"))
|
||||
{
|
||||
return CipherUtilities.GetCipher("DESEDE/CBC");
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "RC2-CBC"))
|
||||
{
|
||||
return CipherUtilities.GetCipher("RC2/CBC");
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "RC4"))
|
||||
{
|
||||
return CipherUtilities.GetCipher("RC4");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetEncodingName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, oid.Id);
|
||||
}
|
||||
|
||||
private static ICipherParameters FixDesParity(string mechanism, ICipherParameters parameters)
|
||||
{
|
||||
if (!Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "DES-CBC") && !Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "DESEDE-CBC"))
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
if (parameters is ParametersWithIV)
|
||||
{
|
||||
ParametersWithIV ivParams = (ParametersWithIV)parameters;
|
||||
return new ParametersWithIV(FixDesParity(mechanism, ivParams.Parameters), ivParams.GetIV());
|
||||
}
|
||||
|
||||
KeyParameter kParam = (KeyParameter)parameters;
|
||||
byte[] keyBytes = kParam.GetKey();
|
||||
DesParameters.SetOddParity(keyBytes);
|
||||
return new KeyParameter(keyBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfc85a93228ca944eb2c23feecec2821
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,412 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cryptlib;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Gnu;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Sec;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public static class PrivateKeyFactory
|
||||
{
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
byte[] privateKeyInfoData)
|
||||
{
|
||||
return CreateKey(
|
||||
PrivateKeyInfo.GetInstance(
|
||||
Asn1Object.FromByteArray(privateKeyInfoData)));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
Stream inStr)
|
||||
{
|
||||
return CreateKey(
|
||||
PrivateKeyInfo.GetInstance(
|
||||
Asn1Object.FromStream(inStr)));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
PrivateKeyInfo keyInfo)
|
||||
{
|
||||
AlgorithmIdentifier algID = keyInfo.PrivateKeyAlgorithm;
|
||||
DerObjectIdentifier algOid = algID.Algorithm;
|
||||
|
||||
// TODO See RSAUtil.isRsaOid in Java build
|
||||
if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
|
||||
|| algOid.Equals(X509ObjectIdentifiers.IdEARsa)
|
||||
|| algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
|
||||
|| algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
|
||||
{
|
||||
RsaPrivateKeyStructure keyStructure = RsaPrivateKeyStructure.GetInstance(keyInfo.ParsePrivateKey());
|
||||
|
||||
return new RsaPrivateCrtKeyParameters(
|
||||
keyStructure.Modulus,
|
||||
keyStructure.PublicExponent,
|
||||
keyStructure.PrivateExponent,
|
||||
keyStructure.Prime1,
|
||||
keyStructure.Prime2,
|
||||
keyStructure.Exponent1,
|
||||
keyStructure.Exponent2,
|
||||
keyStructure.Coefficient);
|
||||
}
|
||||
// TODO?
|
||||
// else if (algOid.Equals(X9ObjectIdentifiers.DHPublicNumber))
|
||||
else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement))
|
||||
{
|
||||
DHParameter para = new DHParameter(
|
||||
Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
|
||||
DerInteger derX = (DerInteger)keyInfo.ParsePrivateKey();
|
||||
|
||||
BigInteger lVal = para.L;
|
||||
int l = lVal == null ? 0 : lVal.IntValue;
|
||||
DHParameters dhParams = new DHParameters(para.P, para.G, null, l);
|
||||
|
||||
return new DHPrivateKeyParameters(derX.Value, dhParams, algOid);
|
||||
}
|
||||
else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm))
|
||||
{
|
||||
ElGamalParameter para = new ElGamalParameter(
|
||||
Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
|
||||
DerInteger derX = (DerInteger)keyInfo.ParsePrivateKey();
|
||||
|
||||
return new ElGamalPrivateKeyParameters(
|
||||
derX.Value,
|
||||
new ElGamalParameters(para.P, para.G));
|
||||
}
|
||||
else if (algOid.Equals(X9ObjectIdentifiers.IdDsa))
|
||||
{
|
||||
DerInteger derX = (DerInteger)keyInfo.ParsePrivateKey();
|
||||
Asn1Encodable ae = algID.Parameters;
|
||||
|
||||
DsaParameters parameters = null;
|
||||
if (ae != null)
|
||||
{
|
||||
DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object());
|
||||
parameters = new DsaParameters(para.P, para.Q, para.G);
|
||||
}
|
||||
|
||||
return new DsaPrivateKeyParameters(derX.Value, parameters);
|
||||
}
|
||||
else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey))
|
||||
{
|
||||
X962Parameters para = X962Parameters.GetInstance(algID.Parameters.ToAsn1Object());
|
||||
|
||||
X9ECParameters x9;
|
||||
if (para.IsNamedCurve)
|
||||
{
|
||||
x9 = ECKeyPairGenerator.FindECCurveByOid((DerObjectIdentifier)para.Parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
x9 = new X9ECParameters((Asn1Sequence)para.Parameters);
|
||||
}
|
||||
|
||||
ECPrivateKeyStructure ec = ECPrivateKeyStructure.GetInstance(keyInfo.ParsePrivateKey());
|
||||
BigInteger d = ec.GetKey();
|
||||
|
||||
if (para.IsNamedCurve)
|
||||
{
|
||||
return new ECPrivateKeyParameters("EC", d, (DerObjectIdentifier)para.Parameters);
|
||||
}
|
||||
|
||||
ECDomainParameters dParams = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed());
|
||||
return new ECPrivateKeyParameters(d, dParams);
|
||||
}
|
||||
else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x2001) ||
|
||||
algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512) ||
|
||||
algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256))
|
||||
{
|
||||
Asn1Object p = algID.Parameters.ToAsn1Object();
|
||||
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(p);
|
||||
|
||||
ECGost3410Parameters ecSpec;
|
||||
BigInteger d;
|
||||
|
||||
if (p is Asn1Sequence seq && (seq.Count == 2 || seq.Count == 3))
|
||||
{
|
||||
X9ECParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);
|
||||
if (ecP == null)
|
||||
throw new ArgumentException("Unrecognized curve OID for GostR3410x2001 private key");
|
||||
|
||||
ecSpec = new ECGost3410Parameters(
|
||||
new ECNamedDomainParameters(gostParams.PublicKeyParamSet, ecP),
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
|
||||
Asn1OctetString privEnc = keyInfo.PrivateKeyData;
|
||||
if (privEnc.GetOctets().Length == 32 || privEnc.GetOctets().Length == 64)
|
||||
{
|
||||
d = new BigInteger(1, Arrays.Reverse(privEnc.GetOctets()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Asn1Object privKey = keyInfo.ParsePrivateKey();
|
||||
if (privKey is DerInteger derInteger)
|
||||
{
|
||||
d = derInteger.PositiveValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] dVal = Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets());
|
||||
d = new BigInteger(1, dVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
X962Parameters x962Parameters = X962Parameters.GetInstance(p);
|
||||
|
||||
if (x962Parameters.IsNamedCurve)
|
||||
{
|
||||
DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(x962Parameters.Parameters);
|
||||
X9ECParameters ecP = ECNamedCurveTable.GetByOid(oid);
|
||||
if (ecP == null)
|
||||
throw new ArgumentException("Unrecognized curve OID for GostR3410x2001 private key");
|
||||
|
||||
ecSpec = new ECGost3410Parameters(
|
||||
new ECNamedDomainParameters(oid, ecP),
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
}
|
||||
else if (x962Parameters.IsImplicitlyCA)
|
||||
{
|
||||
ecSpec = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
X9ECParameters ecP = X9ECParameters.GetInstance(x962Parameters.Parameters);
|
||||
|
||||
ecSpec = new ECGost3410Parameters(
|
||||
new ECNamedDomainParameters(algOid, ecP),
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
}
|
||||
|
||||
Asn1Object privKey = keyInfo.ParsePrivateKey();
|
||||
if (privKey is DerInteger derD)
|
||||
{
|
||||
d = derD.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECPrivateKeyStructure ec = ECPrivateKeyStructure.GetInstance(privKey);
|
||||
|
||||
d = ec.GetKey();
|
||||
}
|
||||
}
|
||||
|
||||
return new ECPrivateKeyParameters(
|
||||
d,
|
||||
new ECGost3410Parameters(
|
||||
ecSpec,
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet));
|
||||
}
|
||||
else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94))
|
||||
{
|
||||
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(algID.Parameters);
|
||||
|
||||
Asn1Object privKey = keyInfo.ParsePrivateKey();
|
||||
BigInteger x;
|
||||
|
||||
if (privKey is DerInteger)
|
||||
{
|
||||
x = DerInteger.GetInstance(privKey).PositiveValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = new BigInteger(1, Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets()));
|
||||
}
|
||||
|
||||
return new Gost3410PrivateKeyParameters(x, gostParams.PublicKeyParamSet);
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_X25519)
|
||||
|| algOid.Equals(CryptlibObjectIdentifiers.curvey25519))
|
||||
{
|
||||
return new X25519PrivateKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_X448))
|
||||
{
|
||||
return new X448PrivateKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_Ed25519)
|
||||
|| algOid.Equals(GnuObjectIdentifiers.Ed25519))
|
||||
{
|
||||
return new Ed25519PrivateKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_Ed448))
|
||||
{
|
||||
return new Ed448PrivateKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_agreement_gost_3410_12_256)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_agreement_gost_3410_12_512))
|
||||
{
|
||||
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(
|
||||
keyInfo.PrivateKeyAlgorithm.Parameters);
|
||||
ECGost3410Parameters ecSpec;
|
||||
BigInteger d;
|
||||
Asn1Object p = keyInfo.PrivateKeyAlgorithm.Parameters.ToAsn1Object();
|
||||
if (p is Asn1Sequence && (Asn1Sequence.GetInstance(p).Count == 2 || Asn1Sequence.GetInstance(p).Count == 3))
|
||||
{
|
||||
X9ECParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);
|
||||
|
||||
ecSpec = new ECGost3410Parameters(
|
||||
new ECNamedDomainParameters(
|
||||
gostParams.PublicKeyParamSet, ecP),
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
|
||||
Asn1OctetString privEnc = keyInfo.PrivateKeyData;
|
||||
if (privEnc.GetOctets().Length == 32 || privEnc.GetOctets().Length == 64)
|
||||
{
|
||||
byte[] dVal = Arrays.Reverse(privEnc.GetOctets());
|
||||
d = new BigInteger(1, dVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
Asn1Encodable privKey = keyInfo.ParsePrivateKey();
|
||||
if (privKey is DerInteger)
|
||||
{
|
||||
d = DerInteger.GetInstance(privKey).PositiveValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] dVal = Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets());
|
||||
d = new BigInteger(1, dVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
X962Parameters parameters = X962Parameters.GetInstance(keyInfo.PrivateKeyAlgorithm.Parameters);
|
||||
|
||||
if (parameters.IsNamedCurve)
|
||||
{
|
||||
DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(parameters.Parameters);
|
||||
X9ECParameters ecP = ECKeyPairGenerator.FindECCurveByOid(oid);
|
||||
|
||||
ecSpec = new ECGost3410Parameters(new ECNamedDomainParameters(oid, ecP),
|
||||
gostParams.PublicKeyParamSet, gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
}
|
||||
else if (parameters.IsImplicitlyCA)
|
||||
{
|
||||
ecSpec = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
X9ECParameters ecP = X9ECParameters.GetInstance(parameters.Parameters);
|
||||
ecSpec = new ECGost3410Parameters(new ECNamedDomainParameters(algOid, ecP),
|
||||
gostParams.PublicKeyParamSet, gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
}
|
||||
|
||||
Asn1Encodable privKey = keyInfo.ParsePrivateKey();
|
||||
if (privKey is DerInteger)
|
||||
{
|
||||
DerInteger derD = DerInteger.GetInstance(privKey);
|
||||
d = derD.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECPrivateKeyStructure ec = ECPrivateKeyStructure.GetInstance(privKey);
|
||||
d = ec.GetKey();
|
||||
}
|
||||
}
|
||||
|
||||
return new ECPrivateKeyParameters(
|
||||
d,
|
||||
new ECGost3410Parameters(
|
||||
ecSpec,
|
||||
gostParams.PublicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SecurityUtilityException("algorithm identifier in private key not recognised");
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] GetRawKey(PrivateKeyInfo keyInfo)
|
||||
{
|
||||
return Asn1OctetString.GetInstance(keyInfo.ParsePrivateKey()).GetOctets();
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter DecryptKey(
|
||||
char[] passPhrase,
|
||||
EncryptedPrivateKeyInfo encInfo)
|
||||
{
|
||||
return CreateKey(PrivateKeyInfoFactory.CreatePrivateKeyInfo(passPhrase, encInfo));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter DecryptKey(
|
||||
char[] passPhrase,
|
||||
byte[] encryptedPrivateKeyInfoData)
|
||||
{
|
||||
return DecryptKey(passPhrase, Asn1Object.FromByteArray(encryptedPrivateKeyInfoData));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter DecryptKey(
|
||||
char[] passPhrase,
|
||||
Stream encryptedPrivateKeyInfoStream)
|
||||
{
|
||||
return DecryptKey(passPhrase, Asn1Object.FromStream(encryptedPrivateKeyInfoStream));
|
||||
}
|
||||
|
||||
private static AsymmetricKeyParameter DecryptKey(
|
||||
char[] passPhrase,
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
return DecryptKey(passPhrase, EncryptedPrivateKeyInfo.GetInstance(asn1Object));
|
||||
}
|
||||
|
||||
public static byte[] EncryptKey(
|
||||
DerObjectIdentifier algorithm,
|
||||
char[] passPhrase,
|
||||
byte[] salt,
|
||||
int iterationCount,
|
||||
AsymmetricKeyParameter key)
|
||||
{
|
||||
return EncryptedPrivateKeyInfoFactory.CreateEncryptedPrivateKeyInfo(
|
||||
algorithm, passPhrase, salt, iterationCount, key).GetEncoded();
|
||||
}
|
||||
|
||||
public static byte[] EncryptKey(
|
||||
string algorithm,
|
||||
char[] passPhrase,
|
||||
byte[] salt,
|
||||
int iterationCount,
|
||||
AsymmetricKeyParameter key)
|
||||
{
|
||||
return EncryptedPrivateKeyInfoFactory.CreateEncryptedPrivateKeyInfo(
|
||||
algorithm, passPhrase, salt, iterationCount, key).GetEncoded();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8352ae57e5012f4a946e51451ff22a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,322 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cryptlib;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Gnu;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public static class PublicKeyFactory
|
||||
{
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
byte[] keyInfoData)
|
||||
{
|
||||
return CreateKey(
|
||||
SubjectPublicKeyInfo.GetInstance(
|
||||
Asn1Object.FromByteArray(keyInfoData)));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
Stream inStr)
|
||||
{
|
||||
return CreateKey(
|
||||
SubjectPublicKeyInfo.GetInstance(
|
||||
Asn1Object.FromStream(inStr)));
|
||||
}
|
||||
|
||||
public static AsymmetricKeyParameter CreateKey(
|
||||
SubjectPublicKeyInfo keyInfo)
|
||||
{
|
||||
AlgorithmIdentifier algID = keyInfo.AlgorithmID;
|
||||
DerObjectIdentifier algOid = algID.Algorithm;
|
||||
|
||||
// TODO See RSAUtil.isRsaOid in Java build
|
||||
if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
|
||||
|| algOid.Equals(X509ObjectIdentifiers.IdEARsa)
|
||||
|| algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
|
||||
|| algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
|
||||
{
|
||||
RsaPublicKeyStructure pubKey = RsaPublicKeyStructure.GetInstance(
|
||||
keyInfo.ParsePublicKey());
|
||||
|
||||
return new RsaKeyParameters(false, pubKey.Modulus, pubKey.PublicExponent);
|
||||
}
|
||||
else if (algOid.Equals(X9ObjectIdentifiers.DHPublicNumber))
|
||||
{
|
||||
Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object());
|
||||
|
||||
DHPublicKey dhPublicKey = DHPublicKey.GetInstance(keyInfo.ParsePublicKey());
|
||||
|
||||
BigInteger y = dhPublicKey.Y.Value;
|
||||
|
||||
if (IsPkcsDHParam(seq))
|
||||
return ReadPkcsDHParam(algOid, y, seq);
|
||||
|
||||
DHDomainParameters dhParams = DHDomainParameters.GetInstance(seq);
|
||||
|
||||
BigInteger p = dhParams.P.Value;
|
||||
BigInteger g = dhParams.G.Value;
|
||||
BigInteger q = dhParams.Q.Value;
|
||||
|
||||
BigInteger j = null;
|
||||
if (dhParams.J != null)
|
||||
{
|
||||
j = dhParams.J.Value;
|
||||
}
|
||||
|
||||
DHValidationParameters validation = null;
|
||||
DHValidationParms dhValidationParms = dhParams.ValidationParms;
|
||||
if (dhValidationParms != null)
|
||||
{
|
||||
byte[] seed = dhValidationParms.Seed.GetBytes();
|
||||
BigInteger pgenCounter = dhValidationParms.PgenCounter.Value;
|
||||
|
||||
// TODO Check pgenCounter size?
|
||||
|
||||
validation = new DHValidationParameters(seed, pgenCounter.IntValue);
|
||||
}
|
||||
|
||||
return new DHPublicKeyParameters(y, new DHParameters(p, g, q, j, validation));
|
||||
}
|
||||
else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement))
|
||||
{
|
||||
Asn1Sequence seq = Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object());
|
||||
|
||||
DerInteger derY = (DerInteger)keyInfo.ParsePublicKey();
|
||||
|
||||
return ReadPkcsDHParam(algOid, derY.Value, seq);
|
||||
}
|
||||
else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm))
|
||||
{
|
||||
ElGamalParameter para = new ElGamalParameter(
|
||||
Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
|
||||
DerInteger derY = (DerInteger)keyInfo.ParsePublicKey();
|
||||
|
||||
return new ElGamalPublicKeyParameters(
|
||||
derY.Value,
|
||||
new ElGamalParameters(para.P, para.G));
|
||||
}
|
||||
else if (algOid.Equals(X9ObjectIdentifiers.IdDsa)
|
||||
|| algOid.Equals(OiwObjectIdentifiers.DsaWithSha1))
|
||||
{
|
||||
DerInteger derY = (DerInteger)keyInfo.ParsePublicKey();
|
||||
Asn1Encodable ae = algID.Parameters;
|
||||
|
||||
DsaParameters parameters = null;
|
||||
if (ae != null)
|
||||
{
|
||||
DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object());
|
||||
parameters = new DsaParameters(para.P, para.Q, para.G);
|
||||
}
|
||||
|
||||
return new DsaPublicKeyParameters(derY.Value, parameters);
|
||||
}
|
||||
else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey))
|
||||
{
|
||||
X962Parameters para = X962Parameters.GetInstance(algID.Parameters.ToAsn1Object());
|
||||
|
||||
X9ECParameters x9;
|
||||
if (para.IsNamedCurve)
|
||||
{
|
||||
x9 = ECKeyPairGenerator.FindECCurveByOid((DerObjectIdentifier)para.Parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
x9 = new X9ECParameters((Asn1Sequence)para.Parameters);
|
||||
}
|
||||
|
||||
Asn1OctetString key = new DerOctetString(keyInfo.PublicKeyData.GetBytes());
|
||||
X9ECPoint derQ = new X9ECPoint(x9.Curve, key);
|
||||
ECPoint q = derQ.Point;
|
||||
|
||||
if (para.IsNamedCurve)
|
||||
{
|
||||
return new ECPublicKeyParameters("EC", q, (DerObjectIdentifier)para.Parameters);
|
||||
}
|
||||
|
||||
ECDomainParameters dParams = new ECDomainParameters(x9);
|
||||
return new ECPublicKeyParameters(q, dParams);
|
||||
}
|
||||
else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x2001))
|
||||
{
|
||||
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(algID.Parameters);
|
||||
DerObjectIdentifier publicKeyParamSet = gostParams.PublicKeyParamSet;
|
||||
|
||||
X9ECParameters ecP = ECGost3410NamedCurves.GetByOid(publicKeyParamSet);
|
||||
if (ecP == null)
|
||||
return null;
|
||||
|
||||
Asn1OctetString key;
|
||||
try
|
||||
{
|
||||
key = (Asn1OctetString)keyInfo.ParsePublicKey();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("error recovering GOST3410_2001 public key", e);
|
||||
}
|
||||
|
||||
int fieldSize = 32;
|
||||
int keySize = 2 * fieldSize;
|
||||
|
||||
byte[] keyEnc = key.GetOctets();
|
||||
if (keyEnc.Length != keySize)
|
||||
throw new ArgumentException("invalid length for GOST3410_2001 public key");
|
||||
|
||||
byte[] x9Encoding = new byte[1 + keySize];
|
||||
x9Encoding[0] = 0x04;
|
||||
for (int i = 1; i <= fieldSize; ++i)
|
||||
{
|
||||
x9Encoding[i] = keyEnc[fieldSize - i];
|
||||
x9Encoding[i + fieldSize] = keyEnc[keySize - i];
|
||||
}
|
||||
|
||||
ECPoint q = ecP.Curve.DecodePoint(x9Encoding);
|
||||
|
||||
return new ECPublicKeyParameters("ECGOST3410", q, publicKeyParamSet);
|
||||
}
|
||||
else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94))
|
||||
{
|
||||
Gost3410PublicKeyAlgParameters algParams = Gost3410PublicKeyAlgParameters.GetInstance(algID.Parameters);
|
||||
|
||||
Asn1OctetString key;
|
||||
try
|
||||
{
|
||||
key = (Asn1OctetString)keyInfo.ParsePublicKey();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("error recovering GOST3410_94 public key", e);
|
||||
}
|
||||
|
||||
byte[] keyBytes = Arrays.Reverse(key.GetOctets()); // was little endian
|
||||
|
||||
BigInteger y = new BigInteger(1, keyBytes);
|
||||
|
||||
return new Gost3410PublicKeyParameters(y, algParams.PublicKeyParamSet);
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_X25519)
|
||||
|| algOid.Equals(CryptlibObjectIdentifiers.curvey25519))
|
||||
{
|
||||
return new X25519PublicKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_X448))
|
||||
{
|
||||
return new X448PublicKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_Ed25519)
|
||||
|| algOid.Equals(GnuObjectIdentifiers.Ed25519))
|
||||
{
|
||||
return new Ed25519PublicKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(EdECObjectIdentifiers.id_Ed448))
|
||||
{
|
||||
return new Ed448PublicKeyParameters(GetRawKey(keyInfo));
|
||||
}
|
||||
else if (algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_agreement_gost_3410_12_256)
|
||||
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_agreement_gost_3410_12_512))
|
||||
{
|
||||
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(algID.Parameters);
|
||||
DerObjectIdentifier publicKeyParamSet = gostParams.PublicKeyParamSet;
|
||||
|
||||
ECGost3410Parameters ecDomainParameters =new ECGost3410Parameters(
|
||||
new ECNamedDomainParameters(publicKeyParamSet, ECGost3410NamedCurves.GetByOid(publicKeyParamSet)),
|
||||
publicKeyParamSet,
|
||||
gostParams.DigestParamSet,
|
||||
gostParams.EncryptionParamSet);
|
||||
|
||||
Asn1OctetString key;
|
||||
try
|
||||
{
|
||||
key = (Asn1OctetString)keyInfo.ParsePublicKey();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("error recovering GOST3410_2012 public key", e);
|
||||
}
|
||||
|
||||
int fieldSize = 32;
|
||||
if (algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512))
|
||||
{
|
||||
fieldSize = 64;
|
||||
}
|
||||
int keySize = 2 * fieldSize;
|
||||
|
||||
byte[] keyEnc = key.GetOctets();
|
||||
if (keyEnc.Length != keySize)
|
||||
throw new ArgumentException("invalid length for GOST3410_2012 public key");
|
||||
|
||||
byte[] x9Encoding = new byte[1 + keySize];
|
||||
x9Encoding[0] = 0x04;
|
||||
for (int i = 1; i <= fieldSize; ++i)
|
||||
{
|
||||
x9Encoding[i] = keyEnc[fieldSize - i];
|
||||
x9Encoding[i + fieldSize] = keyEnc[keySize - i];
|
||||
}
|
||||
|
||||
ECPoint q = ecDomainParameters.Curve.DecodePoint(x9Encoding);
|
||||
|
||||
return new ECPublicKeyParameters(q, ecDomainParameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SecurityUtilityException("algorithm identifier in public key not recognised: " + algOid);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] GetRawKey(SubjectPublicKeyInfo keyInfo)
|
||||
{
|
||||
/*
|
||||
* TODO[RFC 8422]
|
||||
* - Require keyInfo.Algorithm.Parameters == null?
|
||||
*/
|
||||
return keyInfo.PublicKeyData.GetOctets();
|
||||
}
|
||||
|
||||
private static bool IsPkcsDHParam(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count == 2)
|
||||
return true;
|
||||
|
||||
if (seq.Count > 3)
|
||||
return false;
|
||||
|
||||
DerInteger l = DerInteger.GetInstance(seq[2]);
|
||||
DerInteger p = DerInteger.GetInstance(seq[0]);
|
||||
|
||||
return l.Value.CompareTo(BigInteger.ValueOf(p.Value.BitLength)) <= 0;
|
||||
}
|
||||
|
||||
private static DHPublicKeyParameters ReadPkcsDHParam(DerObjectIdentifier algOid,
|
||||
BigInteger y, Asn1Sequence seq)
|
||||
{
|
||||
DHParameter para = new DHParameter(seq);
|
||||
|
||||
BigInteger lVal = para.L;
|
||||
int l = lVal == null ? 0 : lVal.IntValue;
|
||||
DHParameters dhParams = new DHParameters(para.P, para.G, null, l);
|
||||
|
||||
return new DHPublicKeyParameters(y, dhParams, algOid);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd0cb884524a32c429146ce48d62f30d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,267 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
public class SecureRandom
|
||||
: Random
|
||||
{
|
||||
private static long counter = DateTime.UtcNow.Ticks;
|
||||
|
||||
private static long NextCounterValue()
|
||||
{
|
||||
return Interlocked.Increment(ref counter);
|
||||
}
|
||||
|
||||
private static readonly SecureRandom MasterRandom = new SecureRandom(new CryptoApiRandomGenerator());
|
||||
internal static readonly SecureRandom ArbitraryRandom = new SecureRandom(new VmpcRandomGenerator(), 16);
|
||||
|
||||
private static DigestRandomGenerator CreatePrng(string digestName, bool autoSeed)
|
||||
{
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
if (digest == null)
|
||||
return null;
|
||||
DigestRandomGenerator prng = new DigestRandomGenerator(digest);
|
||||
if (autoSeed)
|
||||
{
|
||||
AutoSeed(prng, digest.GetDigestSize());
|
||||
}
|
||||
return prng;
|
||||
}
|
||||
|
||||
public static byte[] GetNextBytes(SecureRandom secureRandom, int length)
|
||||
{
|
||||
byte[] result = new byte[length];
|
||||
secureRandom.NextBytes(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create and auto-seed an instance based on the given algorithm.
|
||||
/// </summary>
|
||||
/// <remarks>Equivalent to GetInstance(algorithm, true)</remarks>
|
||||
/// <param name="algorithm">e.g. "SHA256PRNG"</param>
|
||||
public static SecureRandom GetInstance(string algorithm)
|
||||
{
|
||||
return GetInstance(algorithm, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance based on the given algorithm, with optional auto-seeding
|
||||
/// </summary>
|
||||
/// <param name="algorithm">e.g. "SHA256PRNG"</param>
|
||||
/// <param name="autoSeed">If true, the instance will be auto-seeded.</param>
|
||||
public static SecureRandom GetInstance(string algorithm, bool autoSeed)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
if (algorithm.EndsWith("PRNG", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string digestName = algorithm.Substring(0, algorithm.Length - "PRNG".Length);
|
||||
|
||||
DigestRandomGenerator prng = CreatePrng(digestName, autoSeed);
|
||||
if (prng != null)
|
||||
return new SecureRandom(prng);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm");
|
||||
}
|
||||
|
||||
protected readonly IRandomGenerator generator;
|
||||
|
||||
public SecureRandom()
|
||||
: this(CreatePrng("SHA256", true))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Use the specified instance of IRandomGenerator as random source.</summary>
|
||||
/// <remarks>
|
||||
/// This constructor performs no seeding of either the <c>IRandomGenerator</c> or the
|
||||
/// constructed <c>SecureRandom</c>. It is the responsibility of the client to provide
|
||||
/// proper seed material as necessary/appropriate for the given <c>IRandomGenerator</c>
|
||||
/// implementation.
|
||||
/// </remarks>
|
||||
/// <param name="generator">The source to generate all random bytes from.</param>
|
||||
public SecureRandom(IRandomGenerator generator)
|
||||
: base(0)
|
||||
{
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public SecureRandom(IRandomGenerator generator, int autoSeedLengthInBytes)
|
||||
: base(0)
|
||||
{
|
||||
AutoSeed(generator, autoSeedLengthInBytes);
|
||||
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateSeed(int length)
|
||||
{
|
||||
return GetNextBytes(MasterRandom, length);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public virtual void GenerateSeed(Span<byte> seed)
|
||||
{
|
||||
MasterRandom.NextBytes(seed);
|
||||
}
|
||||
#endif
|
||||
|
||||
public virtual void SetSeed(byte[] seed)
|
||||
{
|
||||
generator.AddSeedMaterial(seed);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public virtual void SetSeed(Span<byte> seed)
|
||||
{
|
||||
generator.AddSeedMaterial(seed);
|
||||
}
|
||||
#endif
|
||||
|
||||
public virtual void SetSeed(long seed)
|
||||
{
|
||||
generator.AddSeedMaterial(seed);
|
||||
}
|
||||
|
||||
public override int Next()
|
||||
{
|
||||
return NextInt() & int.MaxValue;
|
||||
}
|
||||
|
||||
public override int Next(int maxValue)
|
||||
{
|
||||
if (maxValue < 2)
|
||||
{
|
||||
if (maxValue < 0)
|
||||
throw new ArgumentOutOfRangeException("maxValue", "cannot be negative");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bits;
|
||||
|
||||
// Test whether maxValue is a power of 2
|
||||
if ((maxValue & (maxValue - 1)) == 0)
|
||||
{
|
||||
bits = NextInt() & int.MaxValue;
|
||||
return (int)(((long)bits * maxValue) >> 31);
|
||||
}
|
||||
|
||||
int result;
|
||||
do
|
||||
{
|
||||
bits = NextInt() & int.MaxValue;
|
||||
result = bits % maxValue;
|
||||
}
|
||||
while (bits - result + (maxValue - 1) < 0); // Ignore results near overflow
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override int Next(int minValue, int maxValue)
|
||||
{
|
||||
if (maxValue <= minValue)
|
||||
{
|
||||
if (maxValue == minValue)
|
||||
return minValue;
|
||||
|
||||
throw new ArgumentException("maxValue cannot be less than minValue");
|
||||
}
|
||||
|
||||
int diff = maxValue - minValue;
|
||||
if (diff > 0)
|
||||
return minValue + Next(diff);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i = NextInt();
|
||||
|
||||
if (i >= minValue && i < maxValue)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public override void NextBytes(byte[] buf)
|
||||
{
|
||||
generator.NextBytes(buf);
|
||||
}
|
||||
|
||||
public virtual void NextBytes(byte[] buf, int off, int len)
|
||||
{
|
||||
generator.NextBytes(buf, off, len);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override void NextBytes(Span<byte> buffer)
|
||||
{
|
||||
if (generator != null)
|
||||
{
|
||||
generator.NextBytes(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] tmp = new byte[buffer.Length];
|
||||
NextBytes(tmp);
|
||||
tmp.CopyTo(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private static readonly double DoubleScale = 1.0 / Convert.ToDouble(1L << 53);
|
||||
|
||||
public override double NextDouble()
|
||||
{
|
||||
ulong x = (ulong)NextLong() >> 11;
|
||||
|
||||
return Convert.ToDouble(x) * DoubleScale;
|
||||
}
|
||||
|
||||
public virtual int NextInt()
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
Span<byte> bytes = stackalloc byte[4];
|
||||
#else
|
||||
byte[] bytes = new byte[4];
|
||||
#endif
|
||||
NextBytes(bytes);
|
||||
return (int)Pack.BE_To_UInt32(bytes);
|
||||
}
|
||||
|
||||
public virtual long NextLong()
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
Span<byte> bytes = stackalloc byte[8];
|
||||
#else
|
||||
byte[] bytes = new byte[8];
|
||||
#endif
|
||||
NextBytes(bytes);
|
||||
return (long)Pack.BE_To_UInt64(bytes);
|
||||
}
|
||||
|
||||
private static void AutoSeed(IRandomGenerator generator, int seedLength)
|
||||
{
|
||||
generator.AddSeedMaterial(NextCounterValue());
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
Span<byte> seed = seedLength <= 128
|
||||
? stackalloc byte[seedLength]
|
||||
: new byte[seedLength];
|
||||
#else
|
||||
byte[] seed = new byte[seedLength];
|
||||
#endif
|
||||
MasterRandom.NextBytes(seed);
|
||||
generator.AddSeedMaterial(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dad6d1b180992fa4bbefb141195487f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class SecurityUtilityException
|
||||
: Exception
|
||||
{
|
||||
public SecurityUtilityException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public SecurityUtilityException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public SecurityUtilityException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected SecurityUtilityException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 776c8efaf8c3b3843aa42677ef63afd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
[Serializable]
|
||||
public class SignatureException
|
||||
: GeneralSecurityException
|
||||
{
|
||||
public SignatureException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public SignatureException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public SignatureException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected SignatureException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 464c53a8485e7d44e828bede8f580c3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,711 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Bsi;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Eac;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.GM;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// Signer Utility class contains methods that can not be specifically grouped into other classes.
|
||||
/// </summary>
|
||||
public static class SignerUtilities
|
||||
{
|
||||
internal static readonly IDictionary<string, string> AlgorithmMap =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
internal static readonly IDictionary<string, DerObjectIdentifier> Oids =
|
||||
new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static SignerUtilities()
|
||||
{
|
||||
AlgorithmMap["MD2WITHRSA"] = "MD2withRSA";
|
||||
AlgorithmMap["MD2WITHRSAENCRYPTION"] = "MD2withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.MD2WithRsaEncryption.Id] = "MD2withRSA";
|
||||
|
||||
AlgorithmMap["MD4WITHRSA"] = "MD4withRSA";
|
||||
AlgorithmMap["MD4WITHRSAENCRYPTION"] = "MD4withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.MD4WithRsaEncryption.Id] = "MD4withRSA";
|
||||
AlgorithmMap[OiwObjectIdentifiers.MD4WithRsa.Id] = "MD4withRSA";
|
||||
AlgorithmMap[OiwObjectIdentifiers.MD4WithRsaEncryption.Id] = "MD4withRSA";
|
||||
|
||||
AlgorithmMap["MD5WITHRSA"] = "MD5withRSA";
|
||||
AlgorithmMap["MD5WITHRSAENCRYPTION"] = "MD5withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.MD5WithRsaEncryption.Id] = "MD5withRSA";
|
||||
AlgorithmMap[OiwObjectIdentifiers.MD5WithRsa.Id] = "MD5withRSA";
|
||||
|
||||
AlgorithmMap["SHA1WITHRSA"] = "SHA-1withRSA";
|
||||
AlgorithmMap["SHA-1WITHRSA"] = "SHA-1withRSA";
|
||||
AlgorithmMap["SHA1WITHRSAENCRYPTION"] = "SHA-1withRSA";
|
||||
AlgorithmMap["SHA-1WITHRSAENCRYPTION"] = "SHA-1withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha1WithRsaEncryption.Id] = "SHA-1withRSA";
|
||||
AlgorithmMap[OiwObjectIdentifiers.Sha1WithRsa.Id] = "SHA-1withRSA";
|
||||
|
||||
AlgorithmMap["SHA224WITHRSA"] = "SHA-224withRSA";
|
||||
AlgorithmMap["SHA-224WITHRSA"] = "SHA-224withRSA";
|
||||
AlgorithmMap["SHA224WITHRSAENCRYPTION"] = "SHA-224withRSA";
|
||||
AlgorithmMap["SHA-224WITHRSAENCRYPTION"] = "SHA-224withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha224WithRsaEncryption.Id] = "SHA-224withRSA";
|
||||
|
||||
AlgorithmMap["SHA256WITHRSA"] = "SHA-256withRSA";
|
||||
AlgorithmMap["SHA-256WITHRSA"] = "SHA-256withRSA";
|
||||
AlgorithmMap["SHA256WITHRSAENCRYPTION"] = "SHA-256withRSA";
|
||||
AlgorithmMap["SHA-256WITHRSAENCRYPTION"] = "SHA-256withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha256WithRsaEncryption.Id] = "SHA-256withRSA";
|
||||
|
||||
AlgorithmMap["SHA384WITHRSA"] = "SHA-384withRSA";
|
||||
AlgorithmMap["SHA-384WITHRSA"] = "SHA-384withRSA";
|
||||
AlgorithmMap["SHA384WITHRSAENCRYPTION"] = "SHA-384withRSA";
|
||||
AlgorithmMap["SHA-384WITHRSAENCRYPTION"] = "SHA-384withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha384WithRsaEncryption.Id] = "SHA-384withRSA";
|
||||
|
||||
AlgorithmMap["SHA512WITHRSA"] = "SHA-512withRSA";
|
||||
AlgorithmMap["SHA-512WITHRSA"] = "SHA-512withRSA";
|
||||
AlgorithmMap["SHA512WITHRSAENCRYPTION"] = "SHA-512withRSA";
|
||||
AlgorithmMap["SHA-512WITHRSAENCRYPTION"] = "SHA-512withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha512WithRsaEncryption.Id] = "SHA-512withRSA";
|
||||
|
||||
AlgorithmMap["SHA512(224)WITHRSA"] = "SHA-512(224)withRSA";
|
||||
AlgorithmMap["SHA-512(224)WITHRSA"] = "SHA-512(224)withRSA";
|
||||
AlgorithmMap["SHA512(224)WITHRSAENCRYPTION"] = "SHA-512(224)withRSA";
|
||||
AlgorithmMap["SHA-512(224)WITHRSAENCRYPTION"] = "SHA-512(224)withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha512_224WithRSAEncryption.Id] = "SHA-512(224)withRSA";
|
||||
|
||||
AlgorithmMap["SHA512(256)WITHRSA"] = "SHA-512(256)withRSA";
|
||||
AlgorithmMap["SHA-512(256)WITHRSA"] = "SHA-512(256)withRSA";
|
||||
AlgorithmMap["SHA512(256)WITHRSAENCRYPTION"] = "SHA-512(256)withRSA";
|
||||
AlgorithmMap["SHA-512(256)WITHRSAENCRYPTION"] = "SHA-512(256)withRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.Sha512_256WithRSAEncryption.Id] = "SHA-512(256)withRSA";
|
||||
|
||||
AlgorithmMap["SHA3-224WITHRSA"] = "SHA3-224withRSA";
|
||||
AlgorithmMap["SHA3-224WITHRSAENCRYPTION"] = "SHA3-224withRSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224.Id] = "SHA3-224withRSA";
|
||||
AlgorithmMap["SHA3-256WITHRSA"] = "SHA3-256withRSA";
|
||||
AlgorithmMap["SHA3-256WITHRSAENCRYPTION"] = "SHA3-256withRSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256.Id] = "SHA3-256withRSA";
|
||||
AlgorithmMap["SHA3-384WITHRSA"] = "SHA3-384withRSA";
|
||||
AlgorithmMap["SHA3-384WITHRSAENCRYPTION"] = "SHA3-384withRSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384.Id] = "SHA3-384withRSA";
|
||||
AlgorithmMap["SHA3-512WITHRSA"] = "SHA3-512withRSA";
|
||||
AlgorithmMap["SHA3-512WITHRSAENCRYPTION"] = "SHA3-512withRSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512.Id] = "SHA3-512withRSA";
|
||||
|
||||
AlgorithmMap["PSSWITHRSA"] = "PSSwithRSA";
|
||||
AlgorithmMap["RSASSA-PSS"] = "PSSwithRSA";
|
||||
AlgorithmMap[PkcsObjectIdentifiers.IdRsassaPss.Id] = "PSSwithRSA";
|
||||
AlgorithmMap["RSAPSS"] = "PSSwithRSA";
|
||||
|
||||
AlgorithmMap["SHA1WITHRSAANDMGF1"] = "SHA-1withRSAandMGF1";
|
||||
AlgorithmMap["SHA-1WITHRSAANDMGF1"] = "SHA-1withRSAandMGF1";
|
||||
AlgorithmMap["SHA1WITHRSA/PSS"] = "SHA-1withRSAandMGF1";
|
||||
AlgorithmMap["SHA-1WITHRSA/PSS"] = "SHA-1withRSAandMGF1";
|
||||
AlgorithmMap["SHA1WITHRSASSA-PSS"] = "SHA-1withRSAandMGF1";
|
||||
AlgorithmMap["SHA-1WITHRSASSA-PSS"] = "SHA-1withRSAandMGF1";
|
||||
|
||||
AlgorithmMap["SHA224WITHRSAANDMGF1"] = "SHA-224withRSAandMGF1";
|
||||
AlgorithmMap["SHA-224WITHRSAANDMGF1"] = "SHA-224withRSAandMGF1";
|
||||
AlgorithmMap["SHA224WITHRSA/PSS"] = "SHA-224withRSAandMGF1";
|
||||
AlgorithmMap["SHA-224WITHRSA/PSS"] = "SHA-224withRSAandMGF1";
|
||||
AlgorithmMap["SHA224WITHRSASSA-PSS"] = "SHA-224withRSAandMGF1";
|
||||
AlgorithmMap["SHA-224WITHRSASSA-PSS"] = "SHA-224withRSAandMGF1";
|
||||
|
||||
AlgorithmMap["SHA256WITHRSAANDMGF1"] = "SHA-256withRSAandMGF1";
|
||||
AlgorithmMap["SHA-256WITHRSAANDMGF1"] = "SHA-256withRSAandMGF1";
|
||||
AlgorithmMap["SHA256WITHRSA/PSS"] = "SHA-256withRSAandMGF1";
|
||||
AlgorithmMap["SHA-256WITHRSA/PSS"] = "SHA-256withRSAandMGF1";
|
||||
AlgorithmMap["SHA256WITHRSASSA-PSS"] = "SHA-256withRSAandMGF1";
|
||||
AlgorithmMap["SHA-256WITHRSASSA-PSS"] = "SHA-256withRSAandMGF1";
|
||||
|
||||
AlgorithmMap["SHA384WITHRSAANDMGF1"] = "SHA-384withRSAandMGF1";
|
||||
AlgorithmMap["SHA-384WITHRSAANDMGF1"] = "SHA-384withRSAandMGF1";
|
||||
AlgorithmMap["SHA384WITHRSA/PSS"] = "SHA-384withRSAandMGF1";
|
||||
AlgorithmMap["SHA-384WITHRSA/PSS"] = "SHA-384withRSAandMGF1";
|
||||
AlgorithmMap["SHA384WITHRSASSA-PSS"] = "SHA-384withRSAandMGF1";
|
||||
AlgorithmMap["SHA-384WITHRSASSA-PSS"] = "SHA-384withRSAandMGF1";
|
||||
|
||||
AlgorithmMap["SHA512WITHRSAANDMGF1"] = "SHA-512withRSAandMGF1";
|
||||
AlgorithmMap["SHA-512WITHRSAANDMGF1"] = "SHA-512withRSAandMGF1";
|
||||
AlgorithmMap["SHA512WITHRSA/PSS"] = "SHA-512withRSAandMGF1";
|
||||
AlgorithmMap["SHA-512WITHRSA/PSS"] = "SHA-512withRSAandMGF1";
|
||||
AlgorithmMap["SHA512WITHRSASSA-PSS"] = "SHA-512withRSAandMGF1";
|
||||
AlgorithmMap["SHA-512WITHRSASSA-PSS"] = "SHA-512withRSAandMGF1";
|
||||
|
||||
AlgorithmMap["RIPEMD128WITHRSA"] = "RIPEMD128withRSA";
|
||||
AlgorithmMap["RIPEMD128WITHRSAENCRYPTION"] = "RIPEMD128withRSA";
|
||||
AlgorithmMap[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128.Id] = "RIPEMD128withRSA";
|
||||
|
||||
AlgorithmMap["RIPEMD160WITHRSA"] = "RIPEMD160withRSA";
|
||||
AlgorithmMap["RIPEMD160WITHRSAENCRYPTION"] = "RIPEMD160withRSA";
|
||||
AlgorithmMap[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160.Id] = "RIPEMD160withRSA";
|
||||
|
||||
AlgorithmMap["RIPEMD256WITHRSA"] = "RIPEMD256withRSA";
|
||||
AlgorithmMap["RIPEMD256WITHRSAENCRYPTION"] = "RIPEMD256withRSA";
|
||||
AlgorithmMap[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256.Id] = "RIPEMD256withRSA";
|
||||
|
||||
AlgorithmMap["NONEWITHRSA"] = "RSA";
|
||||
AlgorithmMap["RSAWITHNONE"] = "RSA";
|
||||
AlgorithmMap["RAWRSA"] = "RSA";
|
||||
|
||||
AlgorithmMap["RAWRSAPSS"] = "RAWRSASSA-PSS";
|
||||
AlgorithmMap["NONEWITHRSAPSS"] = "RAWRSASSA-PSS";
|
||||
AlgorithmMap["NONEWITHRSASSA-PSS"] = "RAWRSASSA-PSS";
|
||||
|
||||
AlgorithmMap["NONEWITHDSA"] = "NONEwithDSA";
|
||||
AlgorithmMap["DSAWITHNONE"] = "NONEwithDSA";
|
||||
AlgorithmMap["RAWDSA"] = "NONEwithDSA";
|
||||
|
||||
AlgorithmMap["DSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap["DSAWITHSHA1"] = "SHA-1withDSA";
|
||||
AlgorithmMap["DSAWITHSHA-1"] = "SHA-1withDSA";
|
||||
AlgorithmMap["SHA/DSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap["SHA1/DSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap["SHA-1/DSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap["SHA1WITHDSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap["SHA-1WITHDSA"] = "SHA-1withDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.IdDsaWithSha1.Id] = "SHA-1withDSA";
|
||||
AlgorithmMap[OiwObjectIdentifiers.DsaWithSha1.Id] = "SHA-1withDSA";
|
||||
|
||||
AlgorithmMap["DSAWITHSHA224"] = "SHA-224withDSA";
|
||||
AlgorithmMap["DSAWITHSHA-224"] = "SHA-224withDSA";
|
||||
AlgorithmMap["SHA224/DSA"] = "SHA-224withDSA";
|
||||
AlgorithmMap["SHA-224/DSA"] = "SHA-224withDSA";
|
||||
AlgorithmMap["SHA224WITHDSA"] = "SHA-224withDSA";
|
||||
AlgorithmMap["SHA-224WITHDSA"] = "SHA-224withDSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.DsaWithSha224.Id] = "SHA-224withDSA";
|
||||
|
||||
AlgorithmMap["DSAWITHSHA256"] = "SHA-256withDSA";
|
||||
AlgorithmMap["DSAWITHSHA-256"] = "SHA-256withDSA";
|
||||
AlgorithmMap["SHA256/DSA"] = "SHA-256withDSA";
|
||||
AlgorithmMap["SHA-256/DSA"] = "SHA-256withDSA";
|
||||
AlgorithmMap["SHA256WITHDSA"] = "SHA-256withDSA";
|
||||
AlgorithmMap["SHA-256WITHDSA"] = "SHA-256withDSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.DsaWithSha256.Id] = "SHA-256withDSA";
|
||||
|
||||
AlgorithmMap["DSAWITHSHA384"] = "SHA-384withDSA";
|
||||
AlgorithmMap["DSAWITHSHA-384"] = "SHA-384withDSA";
|
||||
AlgorithmMap["SHA384/DSA"] = "SHA-384withDSA";
|
||||
AlgorithmMap["SHA-384/DSA"] = "SHA-384withDSA";
|
||||
AlgorithmMap["SHA384WITHDSA"] = "SHA-384withDSA";
|
||||
AlgorithmMap["SHA-384WITHDSA"] = "SHA-384withDSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.DsaWithSha384.Id] = "SHA-384withDSA";
|
||||
|
||||
AlgorithmMap["DSAWITHSHA512"] = "SHA-512withDSA";
|
||||
AlgorithmMap["DSAWITHSHA-512"] = "SHA-512withDSA";
|
||||
AlgorithmMap["SHA512/DSA"] = "SHA-512withDSA";
|
||||
AlgorithmMap["SHA-512/DSA"] = "SHA-512withDSA";
|
||||
AlgorithmMap["SHA512WITHDSA"] = "SHA-512withDSA";
|
||||
AlgorithmMap["SHA-512WITHDSA"] = "SHA-512withDSA";
|
||||
AlgorithmMap[NistObjectIdentifiers.DsaWithSha512.Id] = "SHA-512withDSA";
|
||||
|
||||
AlgorithmMap["NONEWITHECDSA"] = "NONEwithECDSA";
|
||||
AlgorithmMap["ECDSAWITHNONE"] = "NONEwithECDSA";
|
||||
|
||||
AlgorithmMap["ECDSA"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["SHA1/ECDSA"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["SHA-1/ECDSA"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA1"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA-1"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["SHA1WITHECDSA"] = "SHA-1withECDSA";
|
||||
AlgorithmMap["SHA-1WITHECDSA"] = "SHA-1withECDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.ECDsaWithSha1.Id] = "SHA-1withECDSA";
|
||||
AlgorithmMap[TeleTrusTObjectIdentifiers.ECSignWithSha1.Id] = "SHA-1withECDSA";
|
||||
|
||||
AlgorithmMap["SHA224/ECDSA"] = "SHA-224withECDSA";
|
||||
AlgorithmMap["SHA-224/ECDSA"] = "SHA-224withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA224"] = "SHA-224withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA-224"] = "SHA-224withECDSA";
|
||||
AlgorithmMap["SHA224WITHECDSA"] = "SHA-224withECDSA";
|
||||
AlgorithmMap["SHA-224WITHECDSA"] = "SHA-224withECDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.ECDsaWithSha224.Id] = "SHA-224withECDSA";
|
||||
|
||||
AlgorithmMap["SHA256/ECDSA"] = "SHA-256withECDSA";
|
||||
AlgorithmMap["SHA-256/ECDSA"] = "SHA-256withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA256"] = "SHA-256withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA-256"] = "SHA-256withECDSA";
|
||||
AlgorithmMap["SHA256WITHECDSA"] = "SHA-256withECDSA";
|
||||
AlgorithmMap["SHA-256WITHECDSA"] = "SHA-256withECDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.ECDsaWithSha256.Id] = "SHA-256withECDSA";
|
||||
|
||||
AlgorithmMap["SHA384/ECDSA"] = "SHA-384withECDSA";
|
||||
AlgorithmMap["SHA-384/ECDSA"] = "SHA-384withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA384"] = "SHA-384withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA-384"] = "SHA-384withECDSA";
|
||||
AlgorithmMap["SHA384WITHECDSA"] = "SHA-384withECDSA";
|
||||
AlgorithmMap["SHA-384WITHECDSA"] = "SHA-384withECDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.ECDsaWithSha384.Id] = "SHA-384withECDSA";
|
||||
|
||||
AlgorithmMap["SHA512/ECDSA"] = "SHA-512withECDSA";
|
||||
AlgorithmMap["SHA-512/ECDSA"] = "SHA-512withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA512"] = "SHA-512withECDSA";
|
||||
AlgorithmMap["ECDSAWITHSHA-512"] = "SHA-512withECDSA";
|
||||
AlgorithmMap["SHA512WITHECDSA"] = "SHA-512withECDSA";
|
||||
AlgorithmMap["SHA-512WITHECDSA"] = "SHA-512withECDSA";
|
||||
AlgorithmMap[X9ObjectIdentifiers.ECDsaWithSha512.Id] = "SHA-512withECDSA";
|
||||
|
||||
AlgorithmMap["RIPEMD160/ECDSA"] = "RIPEMD160withECDSA";
|
||||
AlgorithmMap["ECDSAWITHRIPEMD160"] = "RIPEMD160withECDSA";
|
||||
AlgorithmMap["RIPEMD160WITHECDSA"] = "RIPEMD160withECDSA";
|
||||
AlgorithmMap[TeleTrusTObjectIdentifiers.ECSignWithRipeMD160.Id] = "RIPEMD160withECDSA";
|
||||
|
||||
AlgorithmMap["NONEWITHCVC-ECDSA"] = "NONEwithCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHNONE"] = "NONEwithCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA1/CVC-ECDSA"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-1/CVC-ECDSA"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA1"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA-1"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap["SHA1WITHCVC-ECDSA"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-1WITHCVC-ECDSA"] = "SHA-1withCVC-ECDSA";
|
||||
AlgorithmMap[EacObjectIdentifiers.id_TA_ECDSA_SHA_1.Id] = "SHA-1withCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA224/CVC-ECDSA"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-224/CVC-ECDSA"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA224"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA-224"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap["SHA224WITHCVC-ECDSA"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-224WITHCVC-ECDSA"] = "SHA-224withCVC-ECDSA";
|
||||
AlgorithmMap[EacObjectIdentifiers.id_TA_ECDSA_SHA_224.Id] = "SHA-224withCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA256/CVC-ECDSA"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-256/CVC-ECDSA"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA256"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA-256"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap["SHA256WITHCVC-ECDSA"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-256WITHCVC-ECDSA"] = "SHA-256withCVC-ECDSA";
|
||||
AlgorithmMap[EacObjectIdentifiers.id_TA_ECDSA_SHA_256.Id] = "SHA-256withCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA384/CVC-ECDSA"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-384/CVC-ECDSA"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA384"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA-384"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap["SHA384WITHCVC-ECDSA"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-384WITHCVC-ECDSA"] = "SHA-384withCVC-ECDSA";
|
||||
AlgorithmMap[EacObjectIdentifiers.id_TA_ECDSA_SHA_384.Id] = "SHA-384withCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA512/CVC-ECDSA"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-512/CVC-ECDSA"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA512"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap["CVC-ECDSAWITHSHA-512"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap["SHA512WITHCVC-ECDSA"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap["SHA-512WITHCVC-ECDSA"] = "SHA-512withCVC-ECDSA";
|
||||
AlgorithmMap[EacObjectIdentifiers.id_TA_ECDSA_SHA_512.Id] = "SHA-512withCVC-ECDSA";
|
||||
|
||||
AlgorithmMap["NONEWITHPLAIN-ECDSA"] = "NONEwithPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHNONE"] = "NONEwithPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA1/PLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-1/PLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA1"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA-1"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA1WITHPLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-1WITHPLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_SHA1.Id] = "SHA-1withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA224/PLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-224/PLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA224"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA-224"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA224WITHPLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-224WITHPLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_SHA224.Id] = "SHA-224withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA256/PLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-256/PLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA256"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA-256"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA256WITHPLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-256WITHPLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_SHA256.Id] = "SHA-256withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA384/PLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-384/PLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA384"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA-384"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA384WITHPLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-384WITHPLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_SHA384.Id] = "SHA-384withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA512/PLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-512/PLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA512"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHSHA-512"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA512WITHPLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap["SHA-512WITHPLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_SHA512.Id] = "SHA-512withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["RIPEMD160/PLAIN-ECDSA"] = "RIPEMD160withPLAIN-ECDSA";
|
||||
AlgorithmMap["PLAIN-ECDSAWITHRIPEMD160"] = "RIPEMD160withPLAIN-ECDSA";
|
||||
AlgorithmMap["RIPEMD160WITHPLAIN-ECDSA"] = "RIPEMD160withPLAIN-ECDSA";
|
||||
AlgorithmMap[BsiObjectIdentifiers.ecdsa_plain_RIPEMD160.Id] = "RIPEMD160withPLAIN-ECDSA";
|
||||
|
||||
AlgorithmMap["SHA1WITHECNR"] = "SHA-1withECNR";
|
||||
AlgorithmMap["SHA-1WITHECNR"] = "SHA-1withECNR";
|
||||
AlgorithmMap["SHA224WITHECNR"] = "SHA-224withECNR";
|
||||
AlgorithmMap["SHA-224WITHECNR"] = "SHA-224withECNR";
|
||||
AlgorithmMap["SHA256WITHECNR"] = "SHA-256withECNR";
|
||||
AlgorithmMap["SHA-256WITHECNR"] = "SHA-256withECNR";
|
||||
AlgorithmMap["SHA384WITHECNR"] = "SHA-384withECNR";
|
||||
AlgorithmMap["SHA-384WITHECNR"] = "SHA-384withECNR";
|
||||
AlgorithmMap["SHA512WITHECNR"] = "SHA-512withECNR";
|
||||
AlgorithmMap["SHA-512WITHECNR"] = "SHA-512withECNR";
|
||||
|
||||
AlgorithmMap["GOST-3410"] = "GOST3410";
|
||||
AlgorithmMap["GOST-3410-94"] = "GOST3410";
|
||||
AlgorithmMap["GOST3411WITHGOST3410"] = "GOST3410";
|
||||
AlgorithmMap["GOST3411/GOST3410"] = "GOST3410";
|
||||
AlgorithmMap[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94.Id] = "GOST3410";
|
||||
|
||||
AlgorithmMap["ECGOST-3410"] = "ECGOST3410";
|
||||
AlgorithmMap["GOST-3410-2001"] = "ECGOST3410";
|
||||
AlgorithmMap["GOST3411WITHECGOST3410"] = "ECGOST3410";
|
||||
AlgorithmMap["GOST3411/ECGOST3410"] = "ECGOST3410";
|
||||
AlgorithmMap[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001.Id] = "ECGOST3410";
|
||||
|
||||
AlgorithmMap["GOST-3410-2012-256"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap["GOST3411WITHECGOST3410-2012-256"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap["GOST3411-2012-256WITHECGOST3410"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap["GOST3411-2012-256WITHECGOST3410-2012-256"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap["GOST3411-2012-256/ECGOST3410"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap["GOST3411-2012-256/ECGOST3410-2012-256"] = "ECGOST3410-2012-256";
|
||||
AlgorithmMap[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256.Id] =
|
||||
"ECGOST3410-2012-256";
|
||||
|
||||
AlgorithmMap["GOST-3410-2012-512"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap["GOST3411WITHECGOST3410-2012-512"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap["GOST3411-2012-512WITHECGOST3410"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap["GOST3411-2012-512WITHECGOST3410-2012-512"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap["GOST3411-2012-512/ECGOST3410"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap["GOST3411-2012-512/ECGOST3410-2012-512"] = "ECGOST3410-2012-512";
|
||||
AlgorithmMap[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512.Id] =
|
||||
"ECGOST3410-2012-512";
|
||||
|
||||
AlgorithmMap["ED25519"] = "Ed25519";
|
||||
AlgorithmMap[EdECObjectIdentifiers.id_Ed25519.Id] = "Ed25519";
|
||||
AlgorithmMap["ED25519CTX"] = "Ed25519ctx";
|
||||
AlgorithmMap["ED25519PH"] = "Ed25519ph";
|
||||
AlgorithmMap["ED448"] = "Ed448";
|
||||
AlgorithmMap[EdECObjectIdentifiers.id_Ed448.Id] = "Ed448";
|
||||
AlgorithmMap["ED448PH"] = "Ed448ph";
|
||||
|
||||
AlgorithmMap["SHA256WITHSM2"] = "SHA256withSM2";
|
||||
AlgorithmMap[GMObjectIdentifiers.sm2sign_with_sha256.Id] = "SHA256withSM2";
|
||||
AlgorithmMap["SM3WITHSM2"] = "SM3withSM2";
|
||||
AlgorithmMap[GMObjectIdentifiers.sm2sign_with_sm3.Id] = "SM3withSM2";
|
||||
|
||||
Oids["MD2withRSA"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
|
||||
Oids["MD4withRSA"] = PkcsObjectIdentifiers.MD4WithRsaEncryption;
|
||||
Oids["MD5withRSA"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
|
||||
|
||||
Oids["SHA-1withRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
|
||||
Oids["SHA-224withRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
|
||||
Oids["SHA-256withRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
|
||||
Oids["SHA-384withRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
|
||||
Oids["SHA-512withRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
|
||||
Oids["SHA-512(224)withRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
|
||||
Oids["SHA-512(256)withRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
|
||||
Oids["SHA3-224withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
|
||||
Oids["SHA3-256withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
|
||||
Oids["SHA3-384withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
|
||||
Oids["SHA3-512withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
|
||||
|
||||
Oids["PSSwithRSA"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
Oids["SHA-1withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
Oids["SHA-224withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
Oids["SHA-256withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
Oids["SHA-384withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
Oids["SHA-512withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
|
||||
|
||||
Oids["RIPEMD128withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
|
||||
Oids["RIPEMD160withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
|
||||
Oids["RIPEMD256withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
|
||||
|
||||
Oids["SHA-1withDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
|
||||
|
||||
Oids["SHA-1withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha1;
|
||||
Oids["SHA-224withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha224;
|
||||
Oids["SHA-256withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha256;
|
||||
Oids["SHA-384withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha384;
|
||||
Oids["SHA-512withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha512;
|
||||
Oids["RIPEMD160withECDSA"] = TeleTrusTObjectIdentifiers.ECSignWithRipeMD160;
|
||||
|
||||
Oids["SHA-1withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_1;
|
||||
Oids["SHA-224withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_224;
|
||||
Oids["SHA-256withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_256;
|
||||
Oids["SHA-384withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_384;
|
||||
Oids["SHA-512withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_512;
|
||||
|
||||
Oids["SHA-1withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA1;
|
||||
Oids["SHA-224withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA224;
|
||||
Oids["SHA-256withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA256;
|
||||
Oids["SHA-384withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA384;
|
||||
Oids["SHA-512withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA512;
|
||||
Oids["RIPEMD160withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_RIPEMD160;
|
||||
|
||||
Oids["GOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
|
||||
Oids["ECGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
|
||||
|
||||
Oids["ECGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
|
||||
Oids["ECGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
|
||||
|
||||
Oids["Ed25519"] = EdECObjectIdentifiers.id_Ed25519;
|
||||
Oids["Ed448"] = EdECObjectIdentifiers.id_Ed448;
|
||||
|
||||
Oids["SHA256withSM2"] = GMObjectIdentifiers.sm2sign_with_sha256;
|
||||
Oids["SM3withSM2"] = GMObjectIdentifiers.sm2sign_with_sm3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an ObjectIdentifier for a given encoding.
|
||||
/// </summary>
|
||||
/// <param name="mechanism">A string representation of the encoding.</param>
|
||||
/// <returns>A DerObjectIdentifier, null if the OID is not available.</returns>
|
||||
// TODO Don't really want to support this
|
||||
public static DerObjectIdentifier GetObjectIdentifier(string mechanism)
|
||||
{
|
||||
if (mechanism == null)
|
||||
throw new ArgumentNullException(nameof(mechanism));
|
||||
|
||||
string algorithm = CollectionUtilities.GetValueOrKey(AlgorithmMap, mechanism);
|
||||
|
||||
return CollectionUtilities.GetValueOrNull(Oids, algorithm);
|
||||
}
|
||||
|
||||
public static ICollection<string> Algorithms
|
||||
{
|
||||
get { return CollectionUtilities.ReadOnly(Oids.Keys); }
|
||||
}
|
||||
|
||||
public static Asn1Encodable GetDefaultX509Parameters(DerObjectIdentifier id)
|
||||
{
|
||||
return GetDefaultX509Parameters(id.Id);
|
||||
}
|
||||
|
||||
public static Asn1Encodable GetDefaultX509Parameters(string algorithm)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
string mechanism = CollectionUtilities.GetValueOrKey(AlgorithmMap, algorithm);
|
||||
|
||||
if (mechanism == "PSSwithRSA")
|
||||
{
|
||||
// TODO The Sha1Digest here is a default. In JCE version, the actual digest
|
||||
// to be used can be overridden by subsequent parameter settings.
|
||||
return GetPssX509Parameters("SHA-1");
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSAandMGF1"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.Length - "withRSAandMGF1".Length);
|
||||
return GetPssX509Parameters(digestName);
|
||||
}
|
||||
|
||||
return DerNull.Instance;
|
||||
}
|
||||
|
||||
private static Asn1Encodable GetPssX509Parameters(
|
||||
string digestName)
|
||||
{
|
||||
AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
|
||||
DigestUtilities.GetObjectIdentifier(digestName), DerNull.Instance);
|
||||
|
||||
// TODO Is it possible for the MGF hash alg to be different from the PSS one?
|
||||
AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
|
||||
PkcsObjectIdentifiers.IdMgf1, hashAlgorithm);
|
||||
|
||||
int saltLen = DigestUtilities.GetDigest(digestName).GetDigestSize();
|
||||
return new RsassaPssParameters(hashAlgorithm, maskGenAlgorithm,
|
||||
new DerInteger(saltLen), new DerInteger(1));
|
||||
}
|
||||
|
||||
public static ISigner GetSigner(DerObjectIdentifier id)
|
||||
{
|
||||
return GetSigner(id.Id);
|
||||
}
|
||||
|
||||
public static ISigner GetSigner(string algorithm)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException(nameof(algorithm));
|
||||
|
||||
string mechanism = CollectionUtilities.GetValueOrKey(AlgorithmMap, algorithm.ToUpperInvariant());
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "Ed"))
|
||||
{
|
||||
if (mechanism.Equals("Ed25519"))
|
||||
{
|
||||
return new Ed25519Signer();
|
||||
}
|
||||
if (mechanism.Equals("Ed25519ctx"))
|
||||
{
|
||||
return new Ed25519ctxSigner(Arrays.EmptyBytes);
|
||||
}
|
||||
if (mechanism.Equals("Ed25519ph"))
|
||||
{
|
||||
return new Ed25519phSigner(Arrays.EmptyBytes);
|
||||
}
|
||||
if (mechanism.Equals("Ed448"))
|
||||
{
|
||||
return new Ed448Signer(Arrays.EmptyBytes);
|
||||
}
|
||||
if (mechanism.Equals("Ed448ph"))
|
||||
{
|
||||
return new Ed448phSigner(Arrays.EmptyBytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (mechanism.Equals("RSA"))
|
||||
{
|
||||
return (new RsaDigestSigner(new NullDigest(), (AlgorithmIdentifier)null));
|
||||
}
|
||||
if (mechanism.Equals("RAWRSASSA-PSS"))
|
||||
{
|
||||
// TODO Add support for other parameter settings
|
||||
return PssSigner.CreateRawSigner(new RsaBlindedEngine(), new Sha1Digest());
|
||||
}
|
||||
if (mechanism.Equals("PSSwithRSA"))
|
||||
{
|
||||
// TODO The Sha1Digest here is a default. In JCE version, the actual digest
|
||||
// to be used can be overridden by subsequent parameter settings.
|
||||
return new PssSigner(new RsaBlindedEngine(), new Sha1Digest());
|
||||
}
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSA"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new RsaDigestSigner(digest);
|
||||
}
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSAandMGF1"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new PssSigner(new RsaBlindedEngine(), digest);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withDSA"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new DsaDigestSigner(new DsaSigner(), digest);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withECDSA"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new DsaDigestSigner(new ECDsaSigner(), digest);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withCVC-ECDSA")
|
||||
|| Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withPLAIN-ECDSA"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new DsaDigestSigner(new ECDsaSigner(), digest, PlainDsaEncoding.Instance);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withECNR"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new DsaDigestSigner(new ECNRSigner(), digest);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withSM2"))
|
||||
{
|
||||
string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
return new SM2Signer(digest);
|
||||
}
|
||||
|
||||
if (mechanism.Equals("GOST3410"))
|
||||
{
|
||||
return new Gost3410DigestSigner(new Gost3410Signer(), new Gost3411Digest());
|
||||
}
|
||||
if (mechanism.Equals("ECGOST3410"))
|
||||
{
|
||||
return new Gost3410DigestSigner(new ECGost3410Signer(), new Gost3411Digest());
|
||||
}
|
||||
if (mechanism.Equals("ECGOST3410-2012-256"))
|
||||
{
|
||||
return new Gost3410DigestSigner(new ECGost3410Signer(), new Gost3411_2012_256Digest());
|
||||
}
|
||||
if (mechanism.Equals("ECGOST3410-2012-512"))
|
||||
{
|
||||
return new Gost3410DigestSigner(new ECGost3410Signer(), new Gost3411_2012_512Digest());
|
||||
}
|
||||
|
||||
if (mechanism.Equals("SHA1WITHRSA/ISO9796-2"))
|
||||
{
|
||||
return new Iso9796d2Signer(new RsaBlindedEngine(), new Sha1Digest(), true);
|
||||
}
|
||||
if (mechanism.Equals("MD5WITHRSA/ISO9796-2"))
|
||||
{
|
||||
return new Iso9796d2Signer(new RsaBlindedEngine(), new MD5Digest(), true);
|
||||
}
|
||||
if (mechanism.Equals("RIPEMD160WITHRSA/ISO9796-2"))
|
||||
{
|
||||
return new Iso9796d2Signer(new RsaBlindedEngine(), new RipeMD160Digest(), true);
|
||||
}
|
||||
|
||||
if (Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "/X9.31"))
|
||||
{
|
||||
string x931 = mechanism.Substring(0, mechanism.Length - "/X9.31".Length);
|
||||
int withPos = Org.BouncyCastle.Utilities.Platform.IndexOf(x931, "WITH");
|
||||
if (withPos > 0)
|
||||
{
|
||||
int endPos = withPos + "WITH".Length;
|
||||
|
||||
string digestName = x931.Substring(0, withPos);
|
||||
IDigest digest = DigestUtilities.GetDigest(digestName);
|
||||
|
||||
string cipherName = x931.Substring(endPos, x931.Length - endPos);
|
||||
if (cipherName.Equals("RSA"))
|
||||
{
|
||||
IAsymmetricBlockCipher cipher = new RsaBlindedEngine();
|
||||
return new X931Signer(cipher, digest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SecurityUtilityException("Signer " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetEncodingName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(AlgorithmMap, oid.Id);
|
||||
}
|
||||
|
||||
public static ISigner InitSigner(DerObjectIdentifier algorithmOid, bool forSigning, AsymmetricKeyParameter privateKey, SecureRandom random)
|
||||
{
|
||||
return InitSigner(algorithmOid.Id, forSigning, privateKey, random);
|
||||
}
|
||||
|
||||
public static ISigner InitSigner(string algorithm, bool forSigning, AsymmetricKeyParameter privateKey, SecureRandom random)
|
||||
{
|
||||
ISigner signer = GetSigner(algorithm);
|
||||
signer.Init(forSigning, ParameterUtilities.WithRandom(privateKey, random));
|
||||
return signer;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06997fffd3bfe604f912392f70471c57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,144 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Kisa;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
|
||||
{
|
||||
/// <remarks>
|
||||
/// Utility class for creating IWrapper objects from their names/Oids
|
||||
/// </remarks>
|
||||
public static class WrapperUtilities
|
||||
{
|
||||
private enum WrapAlgorithm { AESWRAP, CAMELLIAWRAP, DESEDEWRAP, RC2WRAP, SEEDWRAP,
|
||||
DESEDERFC3211WRAP, AESRFC3211WRAP, CAMELLIARFC3211WRAP };
|
||||
|
||||
private static readonly IDictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
static WrapperUtilities()
|
||||
{
|
||||
// Signal to obfuscation tools not to change enum constants
|
||||
Enums.GetArbitraryValue<WrapAlgorithm>().ToString();
|
||||
|
||||
Algorithms[NistObjectIdentifiers.IdAes128Wrap.Id] = "AESWRAP";
|
||||
Algorithms[NistObjectIdentifiers.IdAes192Wrap.Id] = "AESWRAP";
|
||||
Algorithms[NistObjectIdentifiers.IdAes256Wrap.Id] = "AESWRAP";
|
||||
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia128Wrap.Id] = "CAMELLIAWRAP";
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia192Wrap.Id] = "CAMELLIAWRAP";
|
||||
Algorithms[NttObjectIdentifiers.IdCamellia256Wrap.Id] = "CAMELLIAWRAP";
|
||||
|
||||
Algorithms[PkcsObjectIdentifiers.IdAlgCms3DesWrap.Id] = "DESEDEWRAP";
|
||||
Algorithms["TDEAWRAP"] = "DESEDEWRAP";
|
||||
|
||||
Algorithms[PkcsObjectIdentifiers.IdAlgCmsRC2Wrap.Id] = "RC2WRAP";
|
||||
|
||||
Algorithms[KisaObjectIdentifiers.IdNpkiAppCmsSeedWrap.Id] = "SEEDWRAP";
|
||||
}
|
||||
|
||||
public static IWrapper GetWrapper(DerObjectIdentifier oid)
|
||||
{
|
||||
return GetWrapper(oid.Id);
|
||||
}
|
||||
|
||||
public static IWrapper GetWrapper(string algorithm)
|
||||
{
|
||||
string mechanism = CollectionUtilities.GetValueOrKey(Algorithms, algorithm).ToUpperInvariant();
|
||||
|
||||
try
|
||||
{
|
||||
WrapAlgorithm wrapAlgorithm = Enums.GetEnumValue<WrapAlgorithm>(mechanism);
|
||||
|
||||
switch (wrapAlgorithm)
|
||||
{
|
||||
case WrapAlgorithm.AESWRAP: return new AesWrapEngine();
|
||||
case WrapAlgorithm.CAMELLIAWRAP: return new CamelliaWrapEngine();
|
||||
case WrapAlgorithm.DESEDEWRAP: return new DesEdeWrapEngine();
|
||||
case WrapAlgorithm.RC2WRAP: return new RC2WrapEngine();
|
||||
case WrapAlgorithm.SEEDWRAP: return new SeedWrapEngine();
|
||||
case WrapAlgorithm.DESEDERFC3211WRAP: return new Rfc3211WrapEngine(new DesEdeEngine());
|
||||
case WrapAlgorithm.AESRFC3211WRAP: return new Rfc3211WrapEngine(AesUtilities.CreateEngine());
|
||||
case WrapAlgorithm.CAMELLIARFC3211WRAP: return new Rfc3211WrapEngine(new CamelliaEngine());
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
|
||||
// Create an IBufferedCipher and use it as IWrapper (via BufferedCipherWrapper)
|
||||
IBufferedCipher blockCipher = CipherUtilities.GetCipher(algorithm);
|
||||
|
||||
if (blockCipher != null)
|
||||
return new BufferedCipherWrapper(blockCipher);
|
||||
|
||||
throw new SecurityUtilityException("Wrapper " + algorithm + " not recognised.");
|
||||
}
|
||||
|
||||
public static string GetAlgorithmName(DerObjectIdentifier oid)
|
||||
{
|
||||
return CollectionUtilities.GetValueOrNull(Algorithms, oid.Id);
|
||||
}
|
||||
|
||||
private class BufferedCipherWrapper
|
||||
: IWrapper
|
||||
{
|
||||
private readonly IBufferedCipher cipher;
|
||||
private bool forWrapping;
|
||||
|
||||
public BufferedCipherWrapper(
|
||||
IBufferedCipher cipher)
|
||||
{
|
||||
this.cipher = cipher;
|
||||
}
|
||||
|
||||
public string AlgorithmName
|
||||
{
|
||||
get { return cipher.AlgorithmName; }
|
||||
}
|
||||
|
||||
public void Init(
|
||||
bool forWrapping,
|
||||
ICipherParameters parameters)
|
||||
{
|
||||
this.forWrapping = forWrapping;
|
||||
|
||||
cipher.Init(forWrapping, parameters);
|
||||
}
|
||||
|
||||
public byte[] Wrap(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (!forWrapping)
|
||||
throw new InvalidOperationException("Not initialised for wrapping");
|
||||
|
||||
return cipher.DoFinal(input, inOff, length);
|
||||
}
|
||||
|
||||
public byte[] Unwrap(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (forWrapping)
|
||||
throw new InvalidOperationException("Not initialised for unwrapping");
|
||||
|
||||
return cipher.DoFinal(input, inOff, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ae39e593069a449ae3656aa207a8c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d73ca49e92fed5341b3ab5351606b988
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CertificateEncodingException
|
||||
: CertificateException
|
||||
{
|
||||
public CertificateEncodingException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateEncodingException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateEncodingException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CertificateEncodingException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d13d171e5bd63a43857b59678c5b634
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CertificateException
|
||||
: GeneralSecurityException
|
||||
{
|
||||
public CertificateException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CertificateException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 312dba7b3b4d2b64f9f51f95db4ee1ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CertificateExpiredException
|
||||
: CertificateException
|
||||
{
|
||||
public CertificateExpiredException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateExpiredException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateExpiredException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CertificateExpiredException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94e5534bd782d1d4aa1d9cdf658ef365
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CertificateNotYetValidException
|
||||
: CertificateException
|
||||
{
|
||||
public CertificateNotYetValidException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateNotYetValidException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateNotYetValidException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CertificateNotYetValidException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c062f71e1e45684aaa24f6ec45dc08c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CertificateParsingException
|
||||
: CertificateException
|
||||
{
|
||||
public CertificateParsingException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateParsingException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateParsingException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CertificateParsingException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf1c2ef4e5eeedd4aac155d8a36837c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates
|
||||
{
|
||||
[Serializable]
|
||||
public class CrlException
|
||||
: GeneralSecurityException
|
||||
{
|
||||
public CrlException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CrlException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CrlException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CrlException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0c28bc603c44ba4cae418797434e798
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user