- Initial commit
This commit is contained in:
149
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcChaCha20Poly1305.cs
vendored
Normal file
149
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcChaCha20Poly1305.cs
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public sealed class BcChaCha20Poly1305
|
||||
: TlsAeadCipherImpl
|
||||
{
|
||||
private static readonly byte[] Zeroes = new byte[15];
|
||||
|
||||
private readonly ChaCha7539Engine m_cipher = new ChaCha7539Engine();
|
||||
private readonly Poly1305 m_mac = new Poly1305();
|
||||
|
||||
private readonly bool m_isEncrypting;
|
||||
|
||||
private int m_additionalDataLength;
|
||||
|
||||
public BcChaCha20Poly1305(bool isEncrypting)
|
||||
{
|
||||
this.m_isEncrypting = isEncrypting;
|
||||
}
|
||||
|
||||
public int DoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset)
|
||||
{
|
||||
if (m_isEncrypting)
|
||||
{
|
||||
int ciphertextLength = inputLength;
|
||||
|
||||
m_cipher.DoFinal(input, inputOffset, inputLength, output, outputOffset);
|
||||
int outputLength = inputLength;
|
||||
|
||||
if (ciphertextLength != outputLength)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
UpdateMac(output, outputOffset, ciphertextLength);
|
||||
|
||||
byte[] lengths = new byte[16];
|
||||
Pack.UInt64_To_LE((ulong)m_additionalDataLength, lengths, 0);
|
||||
Pack.UInt64_To_LE((ulong)ciphertextLength, lengths, 8);
|
||||
m_mac.BlockUpdate(lengths, 0, 16);
|
||||
|
||||
m_mac.DoFinal(output, outputOffset + ciphertextLength);
|
||||
|
||||
return ciphertextLength + 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ciphertextLength = inputLength - 16;
|
||||
|
||||
UpdateMac(input, inputOffset, ciphertextLength);
|
||||
|
||||
byte[] expectedMac = new byte[16];
|
||||
Pack.UInt64_To_LE((ulong)m_additionalDataLength, expectedMac, 0);
|
||||
Pack.UInt64_To_LE((ulong)ciphertextLength, expectedMac, 8);
|
||||
m_mac.BlockUpdate(expectedMac, 0, 16);
|
||||
m_mac.DoFinal(expectedMac, 0);
|
||||
|
||||
bool badMac = !TlsUtilities.ConstantTimeAreEqual(16, expectedMac, 0, input, inputOffset + ciphertextLength);
|
||||
if (badMac)
|
||||
throw new TlsFatalAlert(AlertDescription.bad_record_mac);
|
||||
|
||||
m_cipher.DoFinal(input, inputOffset, ciphertextLength, output, outputOffset);
|
||||
int outputLength = ciphertextLength;
|
||||
|
||||
if (ciphertextLength != outputLength)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
return ciphertextLength;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetOutputSize(int inputLength)
|
||||
{
|
||||
return m_isEncrypting ? inputLength + 16 : inputLength - 16;
|
||||
}
|
||||
|
||||
public void Init(byte[] nonce, int macSize, byte[] additionalData)
|
||||
{
|
||||
if (nonce == null || nonce.Length != 12 || macSize != 16)
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
|
||||
m_cipher.Init(m_isEncrypting, new ParametersWithIV(null, nonce));
|
||||
InitMac();
|
||||
if (additionalData == null)
|
||||
{
|
||||
this.m_additionalDataLength = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_additionalDataLength = additionalData.Length;
|
||||
UpdateMac(additionalData, 0, additionalData.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_cipher.Reset();
|
||||
m_mac.Reset();
|
||||
}
|
||||
|
||||
public void SetKey(byte[] key, int keyOff, int keyLen)
|
||||
{
|
||||
KeyParameter cipherKey = new KeyParameter(key, keyOff, keyLen);
|
||||
m_cipher.Init(m_isEncrypting, new ParametersWithIV(cipherKey, Zeroes, 0, 12));
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void SetKey(ReadOnlySpan<byte> key)
|
||||
{
|
||||
KeyParameter cipherKey = new KeyParameter(key);
|
||||
m_cipher.Init(m_isEncrypting, new ParametersWithIV(cipherKey, Zeroes.AsSpan(0, 12)));
|
||||
}
|
||||
#endif
|
||||
|
||||
private void InitMac()
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
Span<byte> firstBlock = stackalloc byte[64];
|
||||
m_cipher.ProcessBytes(firstBlock, firstBlock);
|
||||
m_mac.Init(new KeyParameter(firstBlock[..32]));
|
||||
firstBlock.Fill(0x00);
|
||||
#else
|
||||
byte[] firstBlock = new byte[64];
|
||||
m_cipher.ProcessBytes(firstBlock, 0, 64, firstBlock, 0);
|
||||
m_mac.Init(new KeyParameter(firstBlock, 0, 32));
|
||||
Array.Clear(firstBlock, 0, firstBlock.Length);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void UpdateMac(byte[] buf, int off, int len)
|
||||
{
|
||||
m_mac.BlockUpdate(buf, off, len);
|
||||
|
||||
int partial = len % 16;
|
||||
if (partial != 0)
|
||||
{
|
||||
m_mac.BlockUpdate(Zeroes, 0, 16 - partial);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcChaCha20Poly1305.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcChaCha20Poly1305.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a547c44455703b94e8a66138181bac45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcChaCha20Poly1305.cs
|
||||
uploadId: 783279
|
||||
116
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedAgreement.cs
vendored
Normal file
116
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedAgreement.cs
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summay>Credentialed class generating agreed secrets from a peer's public key for our end of the TLS connection
|
||||
/// using the BC light-weight API.</summay>
|
||||
public class BcDefaultTlsCredentialedAgreement
|
||||
: TlsCredentialedAgreement
|
||||
{
|
||||
protected readonly TlsCredentialedAgreement m_agreementCredentials;
|
||||
|
||||
public BcDefaultTlsCredentialedAgreement(BcTlsCrypto crypto, Certificate certificate,
|
||||
AsymmetricKeyParameter privateKey)
|
||||
{
|
||||
if (crypto == null)
|
||||
throw new ArgumentNullException("crypto");
|
||||
if (certificate == null)
|
||||
throw new ArgumentNullException("certificate");
|
||||
if (certificate.IsEmpty)
|
||||
throw new ArgumentException("cannot be empty", "certificate");
|
||||
if (privateKey == null)
|
||||
throw new ArgumentNullException("privateKey");
|
||||
if (!privateKey.IsPrivate)
|
||||
throw new ArgumentException("must be private", "privateKey");
|
||||
|
||||
if (privateKey is DHPrivateKeyParameters)
|
||||
{
|
||||
this.m_agreementCredentials = new DHCredentialedAgreement(crypto, certificate,
|
||||
(DHPrivateKeyParameters)privateKey);
|
||||
}
|
||||
else if (privateKey is ECPrivateKeyParameters)
|
||||
{
|
||||
this.m_agreementCredentials = new ECCredentialedAgreement(crypto, certificate,
|
||||
(ECPrivateKeyParameters)privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("'privateKey' type not supported: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(privateKey));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Certificate Certificate
|
||||
{
|
||||
get { return m_agreementCredentials.Certificate; }
|
||||
}
|
||||
|
||||
public virtual TlsSecret GenerateAgreement(TlsCertificate peerCertificate)
|
||||
{
|
||||
return m_agreementCredentials.GenerateAgreement(peerCertificate);
|
||||
}
|
||||
|
||||
private sealed class DHCredentialedAgreement
|
||||
: TlsCredentialedAgreement
|
||||
{
|
||||
private readonly BcTlsCrypto m_crypto;
|
||||
private readonly Certificate m_certificate;
|
||||
private readonly DHPrivateKeyParameters m_privateKey;
|
||||
|
||||
internal DHCredentialedAgreement(BcTlsCrypto crypto, Certificate certificate,
|
||||
DHPrivateKeyParameters privateKey)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_certificate = certificate;
|
||||
this.m_privateKey = privateKey;
|
||||
}
|
||||
|
||||
public TlsSecret GenerateAgreement(TlsCertificate peerCertificate)
|
||||
{
|
||||
BcTlsCertificate bcCert = BcTlsCertificate.Convert(m_crypto, peerCertificate);
|
||||
DHPublicKeyParameters peerPublicKey = bcCert.GetPubKeyDH();
|
||||
return BcTlsDHDomain.CalculateDHAgreement(m_crypto, m_privateKey, peerPublicKey, false);
|
||||
}
|
||||
|
||||
public Certificate Certificate
|
||||
{
|
||||
get { return m_certificate; }
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ECCredentialedAgreement
|
||||
: TlsCredentialedAgreement
|
||||
{
|
||||
private readonly BcTlsCrypto m_crypto;
|
||||
private readonly Certificate m_certificate;
|
||||
private readonly ECPrivateKeyParameters m_privateKey;
|
||||
|
||||
internal ECCredentialedAgreement(BcTlsCrypto crypto, Certificate certificate,
|
||||
ECPrivateKeyParameters privateKey)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_certificate = certificate;
|
||||
this.m_privateKey = privateKey;
|
||||
}
|
||||
|
||||
public TlsSecret GenerateAgreement(TlsCertificate peerCertificate)
|
||||
{
|
||||
BcTlsCertificate bcCert = BcTlsCertificate.Convert(m_crypto, peerCertificate);
|
||||
ECPublicKeyParameters peerPublicKey = bcCert.GetPubKeyEC();
|
||||
return BcTlsECDomain.CalculateECDHAgreement(m_crypto, m_privateKey, peerPublicKey);
|
||||
}
|
||||
|
||||
public Certificate Certificate
|
||||
{
|
||||
get { return m_certificate; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedAgreement.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedAgreement.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84303c0f198bc434b870377ae76edfec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedAgreement.cs
|
||||
uploadId: 783279
|
||||
143
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedDecryptor.cs
vendored
Normal file
143
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedDecryptor.cs
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Credentialed class decrypting RSA encrypted secrets sent from a peer for our end of the TLS connection
|
||||
/// using the BC light-weight API.</summary>
|
||||
public class BcDefaultTlsCredentialedDecryptor
|
||||
: TlsCredentialedDecryptor
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly Certificate m_certificate;
|
||||
protected readonly AsymmetricKeyParameter m_privateKey;
|
||||
|
||||
public BcDefaultTlsCredentialedDecryptor(BcTlsCrypto crypto, Certificate certificate,
|
||||
AsymmetricKeyParameter privateKey)
|
||||
{
|
||||
if (crypto == null)
|
||||
throw new ArgumentNullException("crypto");
|
||||
if (certificate == null)
|
||||
throw new ArgumentNullException("certificate");
|
||||
if (certificate.IsEmpty)
|
||||
throw new ArgumentException("cannot be empty", "certificate");
|
||||
if (privateKey == null)
|
||||
throw new ArgumentNullException("privateKey");
|
||||
if (!privateKey.IsPrivate)
|
||||
throw new ArgumentException("must be private", "privateKey");
|
||||
|
||||
if (privateKey is RsaKeyParameters)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("'privateKey' type not supported: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(privateKey));
|
||||
}
|
||||
|
||||
this.m_crypto = crypto;
|
||||
this.m_certificate = certificate;
|
||||
this.m_privateKey = privateKey;
|
||||
}
|
||||
|
||||
public virtual Certificate Certificate
|
||||
{
|
||||
get { return m_certificate; }
|
||||
}
|
||||
|
||||
public virtual TlsSecret Decrypt(TlsCryptoParameters cryptoParams, byte[] ciphertext)
|
||||
{
|
||||
// TODO Keep only the decryption itself here - move error handling outside
|
||||
return SafeDecryptPreMasterSecret(cryptoParams, (RsaKeyParameters)m_privateKey, ciphertext);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO[tls-ops] Probably need to make RSA encryption/decryption into TlsCrypto functions so
|
||||
* that users can implement "generic" encryption credentials externally
|
||||
*/
|
||||
protected virtual TlsSecret SafeDecryptPreMasterSecret(TlsCryptoParameters cryptoParams,
|
||||
RsaKeyParameters rsaServerPrivateKey, byte[] encryptedPreMasterSecret)
|
||||
{
|
||||
SecureRandom secureRandom = m_crypto.SecureRandom;
|
||||
|
||||
/*
|
||||
* RFC 5246 7.4.7.1.
|
||||
*/
|
||||
ProtocolVersion expectedVersion = cryptoParams.RsaPreMasterSecretVersion;
|
||||
|
||||
// TODO Provide as configuration option?
|
||||
bool versionNumberCheckDisabled = false;
|
||||
|
||||
/*
|
||||
* Generate 48 random bytes we can use as a Pre-Master-Secret, if the
|
||||
* PKCS1 padding check should fail.
|
||||
*/
|
||||
byte[] fallback = new byte[48];
|
||||
secureRandom.NextBytes(fallback);
|
||||
|
||||
byte[] M = Arrays.Clone(fallback);
|
||||
try
|
||||
{
|
||||
Pkcs1Encoding encoding = new Pkcs1Encoding(new RsaBlindedEngine(), fallback);
|
||||
encoding.Init(false, new ParametersWithRandom(rsaServerPrivateKey, secureRandom));
|
||||
|
||||
M = encoding.ProcessBlock(encryptedPreMasterSecret, 0, encryptedPreMasterSecret.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/*
|
||||
* This should never happen since the decryption should never throw an exception
|
||||
* and return a random value instead.
|
||||
*
|
||||
* In any case, a TLS server MUST NOT generate an alert if processing an
|
||||
* RSA-encrypted premaster secret message fails, or the version number is not as
|
||||
* expected. Instead, it MUST continue the handshake with a randomly generated
|
||||
* premaster secret.
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* If ClientHello.legacy_version is TLS 1.1 or higher, server implementations MUST check the
|
||||
* version number [..].
|
||||
*/
|
||||
if (versionNumberCheckDisabled && !TlsImplUtilities.IsTlsV11(expectedVersion))
|
||||
{
|
||||
/*
|
||||
* If the version number is TLS 1.0 or earlier, server implementations SHOULD check the
|
||||
* version number, but MAY have a configuration option to disable the check.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Compare the version number in the decrypted Pre-Master-Secret with the legacy_version
|
||||
* field from the ClientHello. If they don't match, continue the handshake with the
|
||||
* randomly generated 'fallback' value.
|
||||
*
|
||||
* NOTE: The comparison and replacement must be constant-time.
|
||||
*/
|
||||
int mask = (expectedVersion.MajorVersion ^ (M[0] & 0xFF))
|
||||
| (expectedVersion.MinorVersion ^ (M[1] & 0xFF));
|
||||
|
||||
// 'mask' will be all 1s if the versions matched, or else all 0s.
|
||||
mask = (mask - 1) >> 31;
|
||||
|
||||
for (int i = 0; i < 48; i++)
|
||||
{
|
||||
M[i] = (byte)((M[i] & mask) | (fallback[i] & ~mask));
|
||||
}
|
||||
}
|
||||
|
||||
return m_crypto.CreateSecret(M);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedDecryptor.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedDecryptor.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e593abd1a2506c4d9e25120fce65765
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedDecryptor.cs
|
||||
uploadId: 783279
|
||||
89
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedSigner.cs
vendored
Normal file
89
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedSigner.cs
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Credentialed class for generating signatures based on the use of primitives from the BC light-weight API.</summary>
|
||||
public class BcDefaultTlsCredentialedSigner
|
||||
: DefaultTlsCredentialedSigner
|
||||
{
|
||||
private static BcTlsCertificate GetEndEntity(BcTlsCrypto crypto, Certificate certificate)
|
||||
{
|
||||
if (certificate == null || certificate.IsEmpty)
|
||||
throw new ArgumentException("No certificate");
|
||||
|
||||
return BcTlsCertificate.Convert(crypto, certificate.GetCertificateAt(0));
|
||||
}
|
||||
|
||||
private static TlsSigner MakeSigner(BcTlsCrypto crypto, AsymmetricKeyParameter privateKey,
|
||||
Certificate certificate, SignatureAndHashAlgorithm signatureAndHashAlgorithm)
|
||||
{
|
||||
TlsSigner signer;
|
||||
if (privateKey is RsaKeyParameters)
|
||||
{
|
||||
RsaKeyParameters privKeyRsa = (RsaKeyParameters)privateKey;
|
||||
|
||||
if (signatureAndHashAlgorithm != null)
|
||||
{
|
||||
int signatureScheme = SignatureScheme.From(signatureAndHashAlgorithm);
|
||||
if (SignatureScheme.IsRsaPss(signatureScheme))
|
||||
{
|
||||
return new BcTlsRsaPssSigner(crypto, privKeyRsa, signatureScheme);
|
||||
}
|
||||
}
|
||||
|
||||
RsaKeyParameters pubKeyRsa = GetEndEntity(crypto, certificate).GetPubKeyRsa();
|
||||
|
||||
signer = new BcTlsRsaSigner(crypto, privKeyRsa, pubKeyRsa);
|
||||
}
|
||||
else if (privateKey is DsaPrivateKeyParameters)
|
||||
{
|
||||
signer = new BcTlsDsaSigner(crypto, (DsaPrivateKeyParameters)privateKey);
|
||||
}
|
||||
else if (privateKey is ECPrivateKeyParameters)
|
||||
{
|
||||
ECPrivateKeyParameters privKeyEC = (ECPrivateKeyParameters)privateKey;
|
||||
|
||||
if (signatureAndHashAlgorithm != null)
|
||||
{
|
||||
int signatureScheme = SignatureScheme.From(signatureAndHashAlgorithm);
|
||||
if (SignatureScheme.IsECDsa(signatureScheme))
|
||||
{
|
||||
return new BcTlsECDsa13Signer(crypto, privKeyEC, signatureScheme);
|
||||
}
|
||||
}
|
||||
|
||||
signer = new BcTlsECDsaSigner(crypto, privKeyEC);
|
||||
}
|
||||
else if (privateKey is Ed25519PrivateKeyParameters)
|
||||
{
|
||||
signer = new BcTlsEd25519Signer(crypto, (Ed25519PrivateKeyParameters)privateKey);
|
||||
}
|
||||
else if (privateKey is Ed448PrivateKeyParameters)
|
||||
{
|
||||
signer = new BcTlsEd448Signer(crypto, (Ed448PrivateKeyParameters)privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("'privateKey' type not supported: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(privateKey));
|
||||
}
|
||||
|
||||
return signer;
|
||||
}
|
||||
|
||||
public BcDefaultTlsCredentialedSigner(TlsCryptoParameters cryptoParams, BcTlsCrypto crypto,
|
||||
AsymmetricKeyParameter privateKey, Certificate certificate,
|
||||
SignatureAndHashAlgorithm signatureAndHashAlgorithm)
|
||||
: base(cryptoParams, MakeSigner(crypto, privateKey, certificate, signatureAndHashAlgorithm), certificate,
|
||||
signatureAndHashAlgorithm)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e58111d54937dc94f843131c59731115
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcDefaultTlsCredentialedSigner.cs
|
||||
uploadId: 783279
|
||||
133
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcSsl3Hmac.cs
vendored
Normal file
133
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcSsl3Hmac.cs
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>HMAC implementation based on original internet draft for HMAC (RFC 2104).</summary>
|
||||
/// <remarks>
|
||||
/// The difference is that padding is concatenated versus XORed with the key, e.g:
|
||||
/// <code>H(K + opad, H(K + ipad, text))</code>
|
||||
/// </remarks>
|
||||
internal class BcSsl3Hmac
|
||||
: TlsHmac
|
||||
{
|
||||
private const byte IPAD_BYTE = (byte)0x36;
|
||||
private const byte OPAD_BYTE = (byte)0x5C;
|
||||
|
||||
private static readonly byte[] IPAD = GenPad(IPAD_BYTE, 48);
|
||||
private static readonly byte[] OPAD = GenPad(OPAD_BYTE, 48);
|
||||
|
||||
private readonly IDigest m_digest;
|
||||
private readonly int m_padLength;
|
||||
|
||||
private byte[] m_secret;
|
||||
|
||||
/// <summary>Base constructor for one of the standard digest algorithms for which the byteLength is known.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Behaviour is undefined for digests other than MD5 or SHA1.
|
||||
/// </remarks>
|
||||
/// <param name="digest">the digest.</param>
|
||||
internal BcSsl3Hmac(IDigest digest)
|
||||
{
|
||||
this.m_digest = digest;
|
||||
|
||||
if (digest.GetDigestSize() == 20)
|
||||
{
|
||||
this.m_padLength = 40;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_padLength = 48;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetKey(byte[] key, int keyOff, int keyLen)
|
||||
{
|
||||
this.m_secret = TlsUtilities.CopyOfRangeExact(key, keyOff, keyOff + keyLen);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void SetKey(ReadOnlySpan<byte> key)
|
||||
{
|
||||
this.m_secret = key.ToArray();
|
||||
|
||||
Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
public virtual void Update(byte[] input, int inOff, int len)
|
||||
{
|
||||
m_digest.BlockUpdate(input, inOff, len);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Update(ReadOnlySpan<byte> input)
|
||||
{
|
||||
m_digest.BlockUpdate(input);
|
||||
}
|
||||
#endif
|
||||
|
||||
public virtual byte[] CalculateMac()
|
||||
{
|
||||
byte[] result = new byte[m_digest.GetDigestSize()];
|
||||
DoFinal(result, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual void CalculateMac(byte[] output, int outOff)
|
||||
{
|
||||
DoFinal(output, outOff);
|
||||
}
|
||||
|
||||
public virtual int InternalBlockSize
|
||||
{
|
||||
get { return m_digest.GetByteLength(); }
|
||||
}
|
||||
|
||||
public virtual int MacLength
|
||||
{
|
||||
get { return m_digest.GetDigestSize(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the mac generator.
|
||||
*/
|
||||
public virtual void Reset()
|
||||
{
|
||||
m_digest.Reset();
|
||||
m_digest.BlockUpdate(m_secret, 0, m_secret.Length);
|
||||
m_digest.BlockUpdate(IPAD, 0, m_padLength);
|
||||
}
|
||||
|
||||
private void DoFinal(byte[] output, int outOff)
|
||||
{
|
||||
byte[] tmp = new byte[m_digest.GetDigestSize()];
|
||||
m_digest.DoFinal(tmp, 0);
|
||||
|
||||
m_digest.BlockUpdate(m_secret, 0, m_secret.Length);
|
||||
m_digest.BlockUpdate(OPAD, 0, m_padLength);
|
||||
m_digest.BlockUpdate(tmp, 0, tmp.Length);
|
||||
|
||||
m_digest.DoFinal(output, outOff);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
private static byte[] GenPad(byte b, int count)
|
||||
{
|
||||
byte[] padding = new byte[count];
|
||||
Arrays.Fill(padding, b);
|
||||
return padding;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcSsl3Hmac.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcSsl3Hmac.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1cf89108ae984c499e7cf5dba3cbde6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcSsl3Hmac.cs
|
||||
uploadId: 783279
|
||||
36
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTls13Verifier.cs
vendored
Normal file
36
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTls13Verifier.cs
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTls13Verifier
|
||||
: Tls13Verifier
|
||||
{
|
||||
private readonly SignerSink m_output;
|
||||
|
||||
internal BcTls13Verifier(ISigner verifier)
|
||||
{
|
||||
if (verifier == null)
|
||||
throw new ArgumentNullException("verifier");
|
||||
|
||||
this.m_output = new SignerSink(verifier);
|
||||
}
|
||||
|
||||
public Stream Stream
|
||||
{
|
||||
get { return m_output; }
|
||||
}
|
||||
|
||||
public bool VerifySignature(byte[] signature)
|
||||
{
|
||||
return m_output.Signer.VerifySignature(signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTls13Verifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTls13Verifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aa938c0bce81eb4dba1f37cc3bb491d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTls13Verifier.cs
|
||||
uploadId: 783279
|
||||
70
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs
vendored
Normal file
70
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsAeadCipherImpl
|
||||
: TlsAeadCipherImpl
|
||||
{
|
||||
private readonly bool m_isEncrypting;
|
||||
private readonly IAeadCipher m_cipher;
|
||||
|
||||
private KeyParameter key;
|
||||
|
||||
internal BcTlsAeadCipherImpl(IAeadCipher cipher, bool isEncrypting)
|
||||
{
|
||||
this.m_cipher = cipher;
|
||||
this.m_isEncrypting = isEncrypting;
|
||||
}
|
||||
|
||||
public void SetKey(byte[] key, int keyOff, int keyLen)
|
||||
{
|
||||
this.key = new KeyParameter(key, keyOff, keyLen);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void SetKey(ReadOnlySpan<byte> key)
|
||||
{
|
||||
this.key = new KeyParameter(key);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Init(byte[] nonce, int macSize, byte[] additionalData)
|
||||
{
|
||||
m_cipher.Init(m_isEncrypting, new AeadParameters(key, macSize * 8, nonce, additionalData));
|
||||
}
|
||||
|
||||
public int GetOutputSize(int inputLength)
|
||||
{
|
||||
return m_cipher.GetOutputSize(inputLength);
|
||||
}
|
||||
|
||||
public int DoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset)
|
||||
{
|
||||
int len = m_cipher.ProcessBytes(input, inputOffset, inputLength, output, outputOffset);
|
||||
|
||||
try
|
||||
{
|
||||
len += m_cipher.DoFinal(output, outputOffset + len);
|
||||
}
|
||||
catch (InvalidCipherTextException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.bad_record_mac, e);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_cipher.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 445248e82182d894baa56e1df879c8cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs
|
||||
uploadId: 783279
|
||||
67
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsBlockCipherImpl.cs
vendored
Normal file
67
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsBlockCipherImpl.cs
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsBlockCipherImpl
|
||||
: TlsBlockCipherImpl
|
||||
{
|
||||
private readonly bool m_isEncrypting;
|
||||
private readonly IBlockCipher m_cipher;
|
||||
|
||||
private KeyParameter key;
|
||||
|
||||
internal BcTlsBlockCipherImpl(IBlockCipher cipher, bool isEncrypting)
|
||||
{
|
||||
this.m_cipher = cipher;
|
||||
this.m_isEncrypting = isEncrypting;
|
||||
}
|
||||
|
||||
public void SetKey(byte[] key, int keyOff, int keyLen)
|
||||
{
|
||||
this.key = new KeyParameter(key, keyOff, keyLen);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void SetKey(ReadOnlySpan<byte> key)
|
||||
{
|
||||
this.key = new KeyParameter(key);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Init(byte[] iv, int ivOff, int ivLen)
|
||||
{
|
||||
m_cipher.Init(m_isEncrypting, new ParametersWithIV(key, iv, ivOff, ivLen));
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Init(ReadOnlySpan<byte> iv)
|
||||
{
|
||||
m_cipher.Init(m_isEncrypting, new ParametersWithIV(key, iv));
|
||||
}
|
||||
#endif
|
||||
|
||||
public int DoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset)
|
||||
{
|
||||
int blockSize = m_cipher.GetBlockSize();
|
||||
|
||||
for (int i = 0; i < inputLength; i += blockSize)
|
||||
{
|
||||
m_cipher.ProcessBlock(input, inputOffset + i, output, outputOffset + i);
|
||||
}
|
||||
|
||||
return inputLength;
|
||||
}
|
||||
|
||||
public int GetBlockSize()
|
||||
{
|
||||
return m_cipher.GetBlockSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsBlockCipherImpl.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsBlockCipherImpl.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a239f59225989d442bc5c8187707e487
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsBlockCipherImpl.cs
|
||||
uploadId: 783279
|
||||
101
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCertificate.cs
vendored
Normal file
101
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCertificate.cs
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for a single X.509 certificate based on the BC light-weight API.</summary>
|
||||
public class BcTlsCertificate
|
||||
: BcTlsRawKeyCertificate
|
||||
{
|
||||
/// <exception cref="IOException"/>
|
||||
public static BcTlsCertificate Convert(BcTlsCrypto crypto, TlsCertificate certificate)
|
||||
{
|
||||
if (certificate is BcTlsCertificate)
|
||||
return (BcTlsCertificate)certificate;
|
||||
|
||||
return new BcTlsCertificate(crypto, certificate.GetEncoded());
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public static X509CertificateStructure ParseCertificate(byte[] encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
Asn1Object asn1 = TlsUtilities.ReadAsn1Object(encoding);
|
||||
return X509CertificateStructure.GetInstance(asn1);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.bad_certificate, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly X509CertificateStructure m_certificate;
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public BcTlsCertificate(BcTlsCrypto crypto, byte[] encoding)
|
||||
: this(crypto, ParseCertificate(encoding))
|
||||
{
|
||||
}
|
||||
|
||||
public BcTlsCertificate(BcTlsCrypto crypto, X509CertificateStructure certificate)
|
||||
: base(crypto, certificate.SubjectPublicKeyInfo)
|
||||
{
|
||||
m_certificate = certificate;
|
||||
}
|
||||
|
||||
public virtual X509CertificateStructure X509CertificateStructure => m_certificate;
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public override byte[] GetEncoded()
|
||||
{
|
||||
return m_certificate.GetEncoded(Asn1Encodable.Der);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public override byte[] GetExtension(DerObjectIdentifier extensionOid)
|
||||
{
|
||||
X509Extensions extensions = m_certificate.TbsCertificate.Extensions;
|
||||
if (extensions != null)
|
||||
{
|
||||
X509Extension extension = extensions.GetExtension(extensionOid);
|
||||
if (extension != null)
|
||||
{
|
||||
return Arrays.Clone(extension.Value.GetOctets());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override BigInteger SerialNumber => m_certificate.SerialNumber.Value;
|
||||
|
||||
public override string SigAlgOid => m_certificate.SignatureAlgorithm.Algorithm.Id;
|
||||
|
||||
public override Asn1Encodable GetSigAlgParams() => m_certificate.SignatureAlgorithm.Parameters;
|
||||
|
||||
protected override bool SupportsKeyUsage(int keyUsageBits)
|
||||
{
|
||||
X509Extensions exts = m_certificate.TbsCertificate.Extensions;
|
||||
if (exts != null)
|
||||
{
|
||||
KeyUsage ku = KeyUsage.FromExtensions(exts);
|
||||
if (ku != null)
|
||||
{
|
||||
int bits = ku.GetBytes()[0] & 0xff;
|
||||
if ((bits & keyUsageBits) != keyUsageBits)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCertificate.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCertificate.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f90dea4e64a35bc4cb84ba6c806af5c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCertificate.cs
|
||||
uploadId: 783279
|
||||
774
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCrypto.cs
vendored
Normal file
774
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCrypto.cs
vendored
Normal file
@ -0,0 +1,774 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.Srp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/**
|
||||
* Class for providing cryptographic services for TLS based on implementations in the BC light-weight API.
|
||||
* <p>
|
||||
* This class provides default implementations for everything. If you need to customise it, extend the class
|
||||
* and override the appropriate methods.
|
||||
* </p>
|
||||
*/
|
||||
public class BcTlsCrypto
|
||||
: AbstractTlsCrypto
|
||||
{
|
||||
private readonly SecureRandom m_entropySource;
|
||||
|
||||
public BcTlsCrypto()
|
||||
: this(CryptoServicesRegistrar.GetSecureRandom())
|
||||
{
|
||||
}
|
||||
|
||||
public BcTlsCrypto(SecureRandom entropySource)
|
||||
{
|
||||
if (entropySource == null)
|
||||
throw new ArgumentNullException(nameof(entropySource));
|
||||
|
||||
this.m_entropySource = entropySource;
|
||||
}
|
||||
|
||||
internal virtual BcTlsSecret AdoptLocalSecret(byte[] data)
|
||||
{
|
||||
return new BcTlsSecret(this, data);
|
||||
}
|
||||
|
||||
public override SecureRandom SecureRandom
|
||||
{
|
||||
get { return m_entropySource; }
|
||||
}
|
||||
|
||||
public override TlsCertificate CreateCertificate(short type, byte[] encoding)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CertificateType.X509:
|
||||
return new BcTlsCertificate(this, encoding);
|
||||
case CertificateType.RawPublicKey:
|
||||
return new BcTlsRawKeyCertificate(this, encoding);
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsCipher CreateCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm,
|
||||
int macAlgorithm)
|
||||
{
|
||||
switch (encryptionAlgorithm)
|
||||
{
|
||||
case EncryptionAlgorithm.AES_128_CBC:
|
||||
case EncryptionAlgorithm.ARIA_128_CBC:
|
||||
case EncryptionAlgorithm.CAMELLIA_128_CBC:
|
||||
case EncryptionAlgorithm.SEED_CBC:
|
||||
case EncryptionAlgorithm.SM4_CBC:
|
||||
return CreateCipher_Cbc(cryptoParams, encryptionAlgorithm, 16, macAlgorithm);
|
||||
|
||||
case EncryptionAlgorithm.cls_3DES_EDE_CBC:
|
||||
return CreateCipher_Cbc(cryptoParams, encryptionAlgorithm, 24, macAlgorithm);
|
||||
|
||||
case EncryptionAlgorithm.AES_256_CBC:
|
||||
case EncryptionAlgorithm.ARIA_256_CBC:
|
||||
case EncryptionAlgorithm.CAMELLIA_256_CBC:
|
||||
return CreateCipher_Cbc(cryptoParams, encryptionAlgorithm, 32, macAlgorithm);
|
||||
|
||||
case EncryptionAlgorithm.AES_128_CCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(cryptoParams, 16, 16);
|
||||
case EncryptionAlgorithm.AES_128_CCM_8:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(cryptoParams, 16, 8);
|
||||
case EncryptionAlgorithm.AES_128_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Gcm(cryptoParams, 16, 16);
|
||||
case EncryptionAlgorithm.AES_256_CCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(cryptoParams, 32, 16);
|
||||
case EncryptionAlgorithm.AES_256_CCM_8:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(cryptoParams, 32, 8);
|
||||
case EncryptionAlgorithm.AES_256_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Gcm(cryptoParams, 32, 16);
|
||||
case EncryptionAlgorithm.ARIA_128_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aria_Gcm(cryptoParams, 16, 16);
|
||||
case EncryptionAlgorithm.ARIA_256_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aria_Gcm(cryptoParams, 32, 16);
|
||||
case EncryptionAlgorithm.CAMELLIA_128_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Camellia_Gcm(cryptoParams, 16, 16);
|
||||
case EncryptionAlgorithm.CAMELLIA_256_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Camellia_Gcm(cryptoParams, 32, 16);
|
||||
case EncryptionAlgorithm.CHACHA20_POLY1305:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateChaCha20Poly1305(cryptoParams);
|
||||
case EncryptionAlgorithm.NULL:
|
||||
return CreateNullCipher(cryptoParams, macAlgorithm);
|
||||
case EncryptionAlgorithm.SM4_CCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_SM4_Ccm(cryptoParams);
|
||||
case EncryptionAlgorithm.SM4_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_SM4_Gcm(cryptoParams);
|
||||
|
||||
case EncryptionAlgorithm.DES40_CBC:
|
||||
case EncryptionAlgorithm.DES_CBC:
|
||||
case EncryptionAlgorithm.IDEA_CBC:
|
||||
case EncryptionAlgorithm.RC2_CBC_40:
|
||||
case EncryptionAlgorithm.RC4_128:
|
||||
case EncryptionAlgorithm.RC4_40:
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsDHDomain CreateDHDomain(TlsDHConfig dhConfig)
|
||||
{
|
||||
return new BcTlsDHDomain(this, dhConfig);
|
||||
}
|
||||
|
||||
public override TlsECDomain CreateECDomain(TlsECConfig ecConfig)
|
||||
{
|
||||
switch (ecConfig.NamedGroup)
|
||||
{
|
||||
case NamedGroup.x25519:
|
||||
return new BcX25519Domain(this);
|
||||
case NamedGroup.x448:
|
||||
return new BcX448Domain(this);
|
||||
default:
|
||||
return new BcTlsECDomain(this, ecConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsNonceGenerator CreateNonceGenerator(byte[] additionalSeedMaterial)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return CreateNonceGenerator(Spans.FromNullableReadOnly(additionalSeedMaterial));
|
||||
#else
|
||||
int cryptoHashAlgorithm = CryptoHashAlgorithm.sha256;
|
||||
IDigest digest = CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
int seedLength = TlsCryptoUtilities.GetHashOutputSize(cryptoHashAlgorithm);
|
||||
byte[] seed = new byte[seedLength];
|
||||
SecureRandom.NextBytes(seed);
|
||||
|
||||
DigestRandomGenerator randomGenerator = new DigestRandomGenerator(digest);
|
||||
randomGenerator.AddSeedMaterial(additionalSeedMaterial);
|
||||
randomGenerator.AddSeedMaterial(seed);
|
||||
|
||||
return new BcTlsNonceGenerator(randomGenerator);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override TlsNonceGenerator CreateNonceGenerator(ReadOnlySpan<byte> additionalSeedMaterial)
|
||||
{
|
||||
int cryptoHashAlgorithm = CryptoHashAlgorithm.sha256;
|
||||
IDigest digest = CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
int seedLength = TlsCryptoUtilities.GetHashOutputSize(cryptoHashAlgorithm);
|
||||
Span<byte> seed = seedLength <= 128
|
||||
? stackalloc byte[seedLength]
|
||||
: new byte[seedLength];
|
||||
SecureRandom.NextBytes(seed);
|
||||
|
||||
DigestRandomGenerator randomGenerator = new DigestRandomGenerator(digest);
|
||||
randomGenerator.AddSeedMaterial(additionalSeedMaterial);
|
||||
randomGenerator.AddSeedMaterial(seed);
|
||||
|
||||
return new BcTlsNonceGenerator(randomGenerator);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override bool HasAnyStreamVerifiers(IList<SignatureAndHashAlgorithm> signatureAndHashAlgorithms)
|
||||
{
|
||||
foreach (SignatureAndHashAlgorithm algorithm in signatureAndHashAlgorithms)
|
||||
{
|
||||
switch (SignatureScheme.From(algorithm))
|
||||
{
|
||||
case SignatureScheme.ed25519:
|
||||
case SignatureScheme.ed448:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool HasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool HasCryptoHashAlgorithm(int cryptoHashAlgorithm)
|
||||
{
|
||||
switch (cryptoHashAlgorithm)
|
||||
{
|
||||
case CryptoHashAlgorithm.md5:
|
||||
case CryptoHashAlgorithm.sha1:
|
||||
case CryptoHashAlgorithm.sha224:
|
||||
case CryptoHashAlgorithm.sha256:
|
||||
case CryptoHashAlgorithm.sha384:
|
||||
case CryptoHashAlgorithm.sha512:
|
||||
case CryptoHashAlgorithm.sm3:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
|
||||
{
|
||||
switch (cryptoSignatureAlgorithm)
|
||||
{
|
||||
case CryptoSignatureAlgorithm.rsa:
|
||||
case CryptoSignatureAlgorithm.dsa:
|
||||
case CryptoSignatureAlgorithm.ecdsa:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_rsae_sha256:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_rsae_sha384:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_rsae_sha512:
|
||||
case CryptoSignatureAlgorithm.ed25519:
|
||||
case CryptoSignatureAlgorithm.ed448:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_pss_sha256:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_pss_sha384:
|
||||
case CryptoSignatureAlgorithm.rsa_pss_pss_sha512:
|
||||
return true;
|
||||
|
||||
// TODO[draft-smyshlyaev-tls12-gost-suites-10]
|
||||
case CryptoSignatureAlgorithm.gostr34102012_256:
|
||||
case CryptoSignatureAlgorithm.gostr34102012_512:
|
||||
|
||||
// TODO[RFC 8998]
|
||||
case CryptoSignatureAlgorithm.sm2:
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasDHAgreement()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HasECDHAgreement()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HasEncryptionAlgorithm(int encryptionAlgorithm)
|
||||
{
|
||||
switch (encryptionAlgorithm)
|
||||
{
|
||||
case EncryptionAlgorithm.AES_128_CBC:
|
||||
case EncryptionAlgorithm.AES_128_CCM:
|
||||
case EncryptionAlgorithm.AES_128_CCM_8:
|
||||
case EncryptionAlgorithm.AES_128_GCM:
|
||||
case EncryptionAlgorithm.AES_256_CBC:
|
||||
case EncryptionAlgorithm.AES_256_CCM:
|
||||
case EncryptionAlgorithm.AES_256_CCM_8:
|
||||
case EncryptionAlgorithm.AES_256_GCM:
|
||||
case EncryptionAlgorithm.ARIA_128_CBC:
|
||||
case EncryptionAlgorithm.ARIA_128_GCM:
|
||||
case EncryptionAlgorithm.ARIA_256_CBC:
|
||||
case EncryptionAlgorithm.ARIA_256_GCM:
|
||||
case EncryptionAlgorithm.CAMELLIA_128_CBC:
|
||||
case EncryptionAlgorithm.CAMELLIA_128_GCM:
|
||||
case EncryptionAlgorithm.CAMELLIA_256_CBC:
|
||||
case EncryptionAlgorithm.CAMELLIA_256_GCM:
|
||||
case EncryptionAlgorithm.CHACHA20_POLY1305:
|
||||
case EncryptionAlgorithm.cls_3DES_EDE_CBC:
|
||||
case EncryptionAlgorithm.NULL:
|
||||
case EncryptionAlgorithm.SEED_CBC:
|
||||
case EncryptionAlgorithm.SM4_CBC:
|
||||
case EncryptionAlgorithm.SM4_CCM:
|
||||
case EncryptionAlgorithm.SM4_GCM:
|
||||
return true;
|
||||
|
||||
case EncryptionAlgorithm.DES_CBC:
|
||||
case EncryptionAlgorithm.DES40_CBC:
|
||||
case EncryptionAlgorithm.IDEA_CBC:
|
||||
case EncryptionAlgorithm.RC2_CBC_40:
|
||||
case EncryptionAlgorithm.RC4_128:
|
||||
case EncryptionAlgorithm.RC4_40:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasHkdfAlgorithm(int cryptoHashAlgorithm)
|
||||
{
|
||||
switch (cryptoHashAlgorithm)
|
||||
{
|
||||
case CryptoHashAlgorithm.sha256:
|
||||
case CryptoHashAlgorithm.sha384:
|
||||
case CryptoHashAlgorithm.sha512:
|
||||
case CryptoHashAlgorithm.sm3:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasMacAlgorithm(int macAlgorithm)
|
||||
{
|
||||
switch (macAlgorithm)
|
||||
{
|
||||
case MacAlgorithm.hmac_md5:
|
||||
case MacAlgorithm.hmac_sha1:
|
||||
case MacAlgorithm.hmac_sha256:
|
||||
case MacAlgorithm.hmac_sha384:
|
||||
case MacAlgorithm.hmac_sha512:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasNamedGroup(int namedGroup)
|
||||
{
|
||||
return NamedGroup.RefersToASpecificGroup(namedGroup);
|
||||
}
|
||||
|
||||
public override bool HasRsaEncryption()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HasSignatureAlgorithm(short signatureAlgorithm)
|
||||
{
|
||||
switch (signatureAlgorithm)
|
||||
{
|
||||
case SignatureAlgorithm.rsa:
|
||||
case SignatureAlgorithm.dsa:
|
||||
case SignatureAlgorithm.ecdsa:
|
||||
case SignatureAlgorithm.ed25519:
|
||||
case SignatureAlgorithm.ed448:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha512:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha512:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP256r1tls13_sha256:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP384r1tls13_sha384:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP512r1tls13_sha512:
|
||||
return true;
|
||||
|
||||
// TODO[draft-smyshlyaev-tls12-gost-suites-10]
|
||||
case SignatureAlgorithm.gostr34102012_256:
|
||||
case SignatureAlgorithm.gostr34102012_512:
|
||||
// TODO[RFC 8998]
|
||||
//case SignatureAlgorithm.sm2:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)
|
||||
{
|
||||
short signature = sigAndHashAlgorithm.Signature;
|
||||
|
||||
switch (sigAndHashAlgorithm.Hash)
|
||||
{
|
||||
case HashAlgorithm.md5:
|
||||
return SignatureAlgorithm.rsa == signature && HasSignatureAlgorithm(signature);
|
||||
default:
|
||||
return HasSignatureAlgorithm(signature);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasSignatureScheme(int signatureScheme)
|
||||
{
|
||||
switch (signatureScheme)
|
||||
{
|
||||
case SignatureScheme.sm2sig_sm3:
|
||||
return false;
|
||||
default:
|
||||
{
|
||||
short signature = SignatureScheme.GetSignatureAlgorithm(signatureScheme);
|
||||
|
||||
switch(SignatureScheme.GetCryptoHashAlgorithm(signatureScheme))
|
||||
{
|
||||
case CryptoHashAlgorithm.md5:
|
||||
return SignatureAlgorithm.rsa == signature && HasSignatureAlgorithm(signature);
|
||||
default:
|
||||
return HasSignatureAlgorithm(signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasSrpAuthentication()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override TlsSecret CreateSecret(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return AdoptLocalSecret(Arrays.Clone(data));
|
||||
}
|
||||
finally
|
||||
{
|
||||
// TODO[tls-ops] Add this after checking all callers
|
||||
//if (data != null)
|
||||
//{
|
||||
// Array.Clear(data, 0, data.Length);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsSecret GenerateRsaPreMasterSecret(ProtocolVersion version)
|
||||
{
|
||||
byte[] data = new byte[48];
|
||||
SecureRandom.NextBytes(data);
|
||||
TlsUtilities.WriteVersion(version, data, 0);
|
||||
return AdoptLocalSecret(data);
|
||||
}
|
||||
|
||||
public virtual IDigest CloneDigest(int cryptoHashAlgorithm, IDigest digest)
|
||||
{
|
||||
switch (cryptoHashAlgorithm)
|
||||
{
|
||||
case CryptoHashAlgorithm.md5:
|
||||
return new MD5Digest((MD5Digest)digest);
|
||||
case CryptoHashAlgorithm.sha1:
|
||||
return new Sha1Digest((Sha1Digest)digest);
|
||||
case CryptoHashAlgorithm.sha224:
|
||||
return new Sha224Digest((Sha224Digest)digest);
|
||||
case CryptoHashAlgorithm.sha256:
|
||||
return new Sha256Digest((Sha256Digest)digest);
|
||||
case CryptoHashAlgorithm.sha384:
|
||||
return new Sha384Digest((Sha384Digest)digest);
|
||||
case CryptoHashAlgorithm.sha512:
|
||||
return new Sha512Digest((Sha512Digest)digest);
|
||||
case CryptoHashAlgorithm.sm3:
|
||||
return new SM3Digest((SM3Digest)digest);
|
||||
default:
|
||||
throw new ArgumentException("invalid CryptoHashAlgorithm: " + cryptoHashAlgorithm);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IDigest CreateDigest(int cryptoHashAlgorithm)
|
||||
{
|
||||
switch (cryptoHashAlgorithm)
|
||||
{
|
||||
case CryptoHashAlgorithm.md5:
|
||||
return new MD5Digest();
|
||||
case CryptoHashAlgorithm.sha1:
|
||||
return new Sha1Digest();
|
||||
case CryptoHashAlgorithm.sha224:
|
||||
return new Sha224Digest();
|
||||
case CryptoHashAlgorithm.sha256:
|
||||
return new Sha256Digest();
|
||||
case CryptoHashAlgorithm.sha384:
|
||||
return new Sha384Digest();
|
||||
case CryptoHashAlgorithm.sha512:
|
||||
return new Sha512Digest();
|
||||
case CryptoHashAlgorithm.sm3:
|
||||
return new SM3Digest();
|
||||
default:
|
||||
throw new ArgumentException("invalid CryptoHashAlgorithm: " + cryptoHashAlgorithm);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsHash CreateHash(int cryptoHashAlgorithm)
|
||||
{
|
||||
return new BcTlsHash(this, cryptoHashAlgorithm);
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateBlockCipher(int encryptionAlgorithm)
|
||||
{
|
||||
switch (encryptionAlgorithm)
|
||||
{
|
||||
case EncryptionAlgorithm.cls_3DES_EDE_CBC:
|
||||
return CreateDesEdeEngine();
|
||||
case EncryptionAlgorithm.AES_128_CBC:
|
||||
case EncryptionAlgorithm.AES_256_CBC:
|
||||
return CreateAesEngine();
|
||||
case EncryptionAlgorithm.ARIA_128_CBC:
|
||||
case EncryptionAlgorithm.ARIA_256_CBC:
|
||||
return CreateAriaEngine();
|
||||
case EncryptionAlgorithm.CAMELLIA_128_CBC:
|
||||
case EncryptionAlgorithm.CAMELLIA_256_CBC:
|
||||
return CreateCamelliaEngine();
|
||||
case EncryptionAlgorithm.SEED_CBC:
|
||||
return CreateSeedEngine();
|
||||
case EncryptionAlgorithm.SM4_CBC:
|
||||
return CreateSM4Engine();
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateCbcBlockCipher(IBlockCipher blockCipher)
|
||||
{
|
||||
return new CbcBlockCipher(blockCipher);
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateCbcBlockCipher(int encryptionAlgorithm)
|
||||
{
|
||||
return CreateCbcBlockCipher(CreateBlockCipher(encryptionAlgorithm));
|
||||
}
|
||||
|
||||
protected virtual TlsCipher CreateChaCha20Poly1305(TlsCryptoParameters cryptoParams)
|
||||
{
|
||||
BcChaCha20Poly1305 encrypt = new BcChaCha20Poly1305(true);
|
||||
BcChaCha20Poly1305 decrypt = new BcChaCha20Poly1305(false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, 32, 16, TlsAeadCipher.AEAD_CHACHA20_POLY1305);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_Aes_Ccm(TlsCryptoParameters cryptoParams, int cipherKeySize,
|
||||
int macSize)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aes_Ccm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aes_Ccm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, cipherKeySize, macSize, TlsAeadCipher.AEAD_CCM);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_Aes_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize,
|
||||
int macSize)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aes_Gcm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aes_Gcm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, cipherKeySize, macSize, TlsAeadCipher.AEAD_GCM);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_Aria_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize,
|
||||
int macSize)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aria_Gcm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Aria_Gcm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, cipherKeySize, macSize, TlsAeadCipher.AEAD_GCM);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_Camellia_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize,
|
||||
int macSize)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Camellia_Gcm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_Camellia_Gcm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, cipherKeySize, macSize, TlsAeadCipher.AEAD_GCM);
|
||||
}
|
||||
|
||||
protected virtual TlsCipher CreateCipher_Cbc(TlsCryptoParameters cryptoParams, int encryptionAlgorithm,
|
||||
int cipherKeySize, int macAlgorithm)
|
||||
{
|
||||
BcTlsBlockCipherImpl encrypt = new BcTlsBlockCipherImpl(CreateCbcBlockCipher(encryptionAlgorithm), true);
|
||||
BcTlsBlockCipherImpl decrypt = new BcTlsBlockCipherImpl(CreateCbcBlockCipher(encryptionAlgorithm), false);
|
||||
|
||||
TlsHmac clientMac = CreateMac(cryptoParams, macAlgorithm);
|
||||
TlsHmac serverMac = CreateMac(cryptoParams, macAlgorithm);
|
||||
|
||||
return new TlsBlockCipher(cryptoParams, encrypt, decrypt, clientMac, serverMac, cipherKeySize);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_SM4_Ccm(TlsCryptoParameters cryptoParams)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_SM4_Ccm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_SM4_Ccm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, 16, 16, TlsAeadCipher.AEAD_CCM);
|
||||
}
|
||||
|
||||
protected virtual TlsAeadCipher CreateCipher_SM4_Gcm(TlsCryptoParameters cryptoParams)
|
||||
{
|
||||
BcTlsAeadCipherImpl encrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_SM4_Gcm(), true);
|
||||
BcTlsAeadCipherImpl decrypt = new BcTlsAeadCipherImpl(CreateAeadCipher_SM4_Gcm(), false);
|
||||
|
||||
return new TlsAeadCipher(cryptoParams, encrypt, decrypt, 16, 16, TlsAeadCipher.AEAD_GCM);
|
||||
}
|
||||
|
||||
protected virtual TlsNullCipher CreateNullCipher(TlsCryptoParameters cryptoParams, int macAlgorithm)
|
||||
{
|
||||
return new TlsNullCipher(cryptoParams, CreateMac(cryptoParams, macAlgorithm),
|
||||
CreateMac(cryptoParams, macAlgorithm));
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateAesEngine()
|
||||
{
|
||||
return AesUtilities.CreateEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateAriaEngine()
|
||||
{
|
||||
return new AriaEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateCamelliaEngine()
|
||||
{
|
||||
return new CamelliaEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateDesEdeEngine()
|
||||
{
|
||||
return new DesEdeEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateSeedEngine()
|
||||
{
|
||||
return new SeedEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateSM4Engine()
|
||||
{
|
||||
return new SM4Engine();
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateCcmMode(IBlockCipher engine)
|
||||
{
|
||||
return new CcmBlockCipher(engine);
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateGcmMode(IBlockCipher engine)
|
||||
{
|
||||
// TODO Consider allowing custom configuration of multiplier
|
||||
return new GcmBlockCipher(engine);
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_Aes_Ccm()
|
||||
{
|
||||
return CreateCcmMode(CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_Aes_Gcm()
|
||||
{
|
||||
return CreateGcmMode(CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_Aria_Gcm()
|
||||
{
|
||||
return CreateGcmMode(CreateAriaEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_Camellia_Gcm()
|
||||
{
|
||||
return CreateGcmMode(CreateCamelliaEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_SM4_Ccm()
|
||||
{
|
||||
return CreateCcmMode(CreateSM4Engine());
|
||||
}
|
||||
|
||||
protected virtual IAeadCipher CreateAeadCipher_SM4_Gcm()
|
||||
{
|
||||
return CreateGcmMode(CreateSM4Engine());
|
||||
}
|
||||
|
||||
public override TlsHmac CreateHmac(int macAlgorithm)
|
||||
{
|
||||
switch (macAlgorithm)
|
||||
{
|
||||
case MacAlgorithm.hmac_md5:
|
||||
case MacAlgorithm.hmac_sha1:
|
||||
case MacAlgorithm.hmac_sha256:
|
||||
case MacAlgorithm.hmac_sha384:
|
||||
case MacAlgorithm.hmac_sha512:
|
||||
return CreateHmacForHash(TlsCryptoUtilities.GetHashForHmac(macAlgorithm));
|
||||
|
||||
default:
|
||||
throw new ArgumentException("invalid MacAlgorithm: " + macAlgorithm);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsHmac CreateHmacForHash(int cryptoHashAlgorithm)
|
||||
{
|
||||
return new BcTlsHmac(new HMac(CreateDigest(cryptoHashAlgorithm)));
|
||||
}
|
||||
|
||||
protected virtual TlsHmac CreateHmac_Ssl(int macAlgorithm)
|
||||
{
|
||||
switch (macAlgorithm)
|
||||
{
|
||||
case MacAlgorithm.hmac_md5:
|
||||
return new BcSsl3Hmac(CreateDigest(CryptoHashAlgorithm.md5));
|
||||
case MacAlgorithm.hmac_sha1:
|
||||
return new BcSsl3Hmac(CreateDigest(CryptoHashAlgorithm.sha1));
|
||||
case MacAlgorithm.hmac_sha256:
|
||||
return new BcSsl3Hmac(CreateDigest(CryptoHashAlgorithm.sha256));
|
||||
case MacAlgorithm.hmac_sha384:
|
||||
return new BcSsl3Hmac(CreateDigest(CryptoHashAlgorithm.sha384));
|
||||
case MacAlgorithm.hmac_sha512:
|
||||
return new BcSsl3Hmac(CreateDigest(CryptoHashAlgorithm.sha512));
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual TlsHmac CreateMac(TlsCryptoParameters cryptoParams, int macAlgorithm)
|
||||
{
|
||||
if (TlsImplUtilities.IsSsl(cryptoParams))
|
||||
{
|
||||
return CreateHmac_Ssl(macAlgorithm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CreateHmac(macAlgorithm);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsSrp6Client CreateSrp6Client(TlsSrpConfig srpConfig)
|
||||
{
|
||||
BigInteger[] ng = srpConfig.GetExplicitNG();
|
||||
Srp6GroupParameters srpGroup = new Srp6GroupParameters(ng[0], ng[1]);
|
||||
|
||||
Srp6Client srp6Client = new Srp6Client();
|
||||
srp6Client.Init(srpGroup, CreateDigest(CryptoHashAlgorithm.sha1), SecureRandom);
|
||||
|
||||
return new BcTlsSrp6Client(srp6Client);
|
||||
}
|
||||
|
||||
public override TlsSrp6Server CreateSrp6Server(TlsSrpConfig srpConfig, BigInteger srpVerifier)
|
||||
{
|
||||
BigInteger[] ng = srpConfig.GetExplicitNG();
|
||||
Srp6GroupParameters srpGroup = new Srp6GroupParameters(ng[0], ng[1]);
|
||||
|
||||
Srp6Server srp6Server = new Srp6Server();
|
||||
srp6Server.Init(srpGroup, srpVerifier, CreateDigest(CryptoHashAlgorithm.sha1), SecureRandom);
|
||||
|
||||
return new BcTlsSrp6Server(srp6Server);
|
||||
}
|
||||
|
||||
public override TlsSrp6VerifierGenerator CreateSrp6VerifierGenerator(TlsSrpConfig srpConfig)
|
||||
{
|
||||
BigInteger[] ng = srpConfig.GetExplicitNG();
|
||||
|
||||
Srp6VerifierGenerator srp6VerifierGenerator = new Srp6VerifierGenerator();
|
||||
srp6VerifierGenerator.Init(ng[0], ng[1], CreateDigest(CryptoHashAlgorithm.sha1));
|
||||
|
||||
return new BcTlsSrp6VerifierGenerator(srp6VerifierGenerator);
|
||||
}
|
||||
|
||||
public override TlsSecret HkdfInit(int cryptoHashAlgorithm)
|
||||
{
|
||||
return AdoptLocalSecret(new byte[TlsCryptoUtilities.GetHashOutputSize(cryptoHashAlgorithm)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCrypto.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCrypto.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36e6d3f8becfe7d46a9fe2a9c8a37c3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsCrypto.cs
|
||||
uploadId: 783279
|
||||
43
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDH.cs
vendored
Normal file
43
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDH.cs
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Support class for ephemeral Diffie-Hellman using the BC light-weight library.</summary>
|
||||
public class BcTlsDH
|
||||
: TlsAgreement
|
||||
{
|
||||
protected readonly BcTlsDHDomain m_domain;
|
||||
|
||||
protected AsymmetricCipherKeyPair m_localKeyPair;
|
||||
protected DHPublicKeyParameters m_peerPublicKey;
|
||||
|
||||
public BcTlsDH(BcTlsDHDomain domain)
|
||||
{
|
||||
this.m_domain = domain;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateEphemeral()
|
||||
{
|
||||
this.m_localKeyPair = m_domain.GenerateKeyPair();
|
||||
|
||||
return m_domain.EncodePublicKey((DHPublicKeyParameters)m_localKeyPair.Public);
|
||||
}
|
||||
|
||||
public virtual void ReceivePeerValue(byte[] peerValue)
|
||||
{
|
||||
this.m_peerPublicKey = m_domain.DecodePublicKey(peerValue);
|
||||
}
|
||||
|
||||
public virtual TlsSecret CalculateSecret()
|
||||
{
|
||||
return m_domain.CalculateDHAgreement((DHPrivateKeyParameters)m_localKeyPair.Private, m_peerPublicKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDH.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDH.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9191048a1d0bd014090167375a36ec73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDH.cs
|
||||
uploadId: 783279
|
||||
121
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDHDomain.cs
vendored
Normal file
121
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDHDomain.cs
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>BC light-weight support class for Diffie-Hellman key pair generation and key agreement over a
|
||||
/// specified Diffie-Hellman configuration.</summary>
|
||||
public class BcTlsDHDomain
|
||||
: TlsDHDomain
|
||||
{
|
||||
private static byte[] EncodeValue(DHParameters dh, bool padded, BigInteger x)
|
||||
{
|
||||
return padded
|
||||
? BigIntegers.AsUnsignedByteArray(GetValueLength(dh), x)
|
||||
: BigIntegers.AsUnsignedByteArray(x);
|
||||
}
|
||||
|
||||
private static int GetValueLength(DHParameters dh)
|
||||
{
|
||||
return BigIntegers.GetUnsignedByteLength(dh.P);
|
||||
}
|
||||
|
||||
public static BcTlsSecret CalculateDHAgreement(BcTlsCrypto crypto, DHPrivateKeyParameters privateKey,
|
||||
DHPublicKeyParameters publicKey, bool padded)
|
||||
{
|
||||
DHBasicAgreement basicAgreement = new DHBasicAgreement();
|
||||
basicAgreement.Init(privateKey);
|
||||
BigInteger agreementValue = basicAgreement.CalculateAgreement(publicKey);
|
||||
byte[] secret = EncodeValue(privateKey.Parameters, padded, agreementValue);
|
||||
return crypto.AdoptLocalSecret(secret);
|
||||
}
|
||||
|
||||
public static DHParameters GetDomainParameters(TlsDHConfig dhConfig)
|
||||
{
|
||||
DHGroup dhGroup = TlsDHUtilities.GetDHGroup(dhConfig);
|
||||
if (dhGroup == null)
|
||||
throw new ArgumentException("No DH configuration provided");
|
||||
|
||||
return new DHParameters(dhGroup.P, dhGroup.G, dhGroup.Q, dhGroup.L);
|
||||
}
|
||||
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly TlsDHConfig m_config;
|
||||
protected readonly DHParameters m_domainParameters;
|
||||
|
||||
public BcTlsDHDomain(BcTlsCrypto crypto, TlsDHConfig dhConfig)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_config = dhConfig;
|
||||
this.m_domainParameters = GetDomainParameters(dhConfig);
|
||||
}
|
||||
|
||||
public virtual BcTlsSecret CalculateDHAgreement(DHPrivateKeyParameters privateKey,
|
||||
DHPublicKeyParameters publicKey)
|
||||
{
|
||||
return CalculateDHAgreement(m_crypto, privateKey, publicKey, m_config.IsPadded);
|
||||
}
|
||||
|
||||
public virtual TlsAgreement CreateDH()
|
||||
{
|
||||
return new BcTlsDH(this);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual BigInteger DecodeParameter(byte[] encoding)
|
||||
{
|
||||
if (m_config.IsPadded && GetValueLength(m_domainParameters) != encoding.Length)
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
|
||||
return new BigInteger(1, encoding);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual DHPublicKeyParameters DecodePublicKey(byte[] encoding)
|
||||
{
|
||||
/*
|
||||
* RFC 7919 3. [..] the client MUST verify that dh_Ys is in the range 1 < dh_Ys < dh_p - 1.
|
||||
* If dh_Ys is not in this range, the client MUST terminate the connection with a fatal
|
||||
* handshake_failure(40) alert.
|
||||
*/
|
||||
try
|
||||
{
|
||||
BigInteger y = DecodeParameter(encoding);
|
||||
|
||||
return new DHPublicKeyParameters(y, m_domainParameters);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure, e);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual byte[] EncodeParameter(BigInteger x)
|
||||
{
|
||||
return EncodeValue(m_domainParameters, m_config.IsPadded, x);
|
||||
}
|
||||
|
||||
public virtual byte[] EncodePublicKey(DHPublicKeyParameters publicKey)
|
||||
{
|
||||
return EncodeValue(m_domainParameters, true, publicKey.Y);
|
||||
}
|
||||
|
||||
public virtual AsymmetricCipherKeyPair GenerateKeyPair()
|
||||
{
|
||||
DHBasicKeyPairGenerator keyPairGenerator = new DHBasicKeyPairGenerator();
|
||||
keyPairGenerator.Init(new DHKeyGenerationParameters(m_crypto.SecureRandom, m_domainParameters));
|
||||
return keyPairGenerator.GenerateKeyPair();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDHDomain.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDHDomain.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30ef06c298d99664b9cf05c5a42e22ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDHDomain.cs
|
||||
uploadId: 783279
|
||||
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaSigner.cs
vendored
Normal file
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaSigner.cs
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for generation of the raw DSA signature type using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsDsaSigner
|
||||
: BcTlsDssSigner
|
||||
{
|
||||
public BcTlsDsaSigner(BcTlsCrypto crypto, DsaPrivateKeyParameters privateKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IDsa CreateDsaImpl(int cryptoHashAlgorithm)
|
||||
{
|
||||
return new DsaSigner(new HMacDsaKCalculator(m_crypto.CreateDigest(cryptoHashAlgorithm)));
|
||||
}
|
||||
|
||||
protected override short SignatureAlgorithm
|
||||
{
|
||||
get { return Tls.SignatureAlgorithm.dsa; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0baf4b33ad021e44bab408cea5773ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaSigner.cs
|
||||
uploadId: 783279
|
||||
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaVerifier.cs
vendored
Normal file
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaVerifier.cs
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for the verification of the raw DSA signature type using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsDsaVerifier
|
||||
: BcTlsDssVerifier
|
||||
{
|
||||
public BcTlsDsaVerifier(BcTlsCrypto crypto, DsaPublicKeyParameters publicKey)
|
||||
: base(crypto, publicKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IDsa CreateDsaImpl()
|
||||
{
|
||||
return new DsaSigner();
|
||||
}
|
||||
|
||||
protected override short SignatureAlgorithm
|
||||
{
|
||||
get { return Tls.SignatureAlgorithm.dsa; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd8d1f47f4d96d4c83c665b309cc52d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDsaVerifier.cs
|
||||
uploadId: 783279
|
||||
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssSigner.cs
vendored
Normal file
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssSigner.cs
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>BC light-weight base class for the signers implementing the two DSA style algorithms from FIPS PUB
|
||||
/// 186-4: DSA and ECDSA.</summary>
|
||||
public abstract class BcTlsDssSigner
|
||||
: BcTlsSigner
|
||||
{
|
||||
protected BcTlsDssSigner(BcTlsCrypto crypto, AsymmetricKeyParameter privateKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected abstract IDsa CreateDsaImpl(int cryptoHashAlgorithm);
|
||||
|
||||
protected abstract short SignatureAlgorithm { get; }
|
||||
|
||||
public override byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash)
|
||||
{
|
||||
if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
int cryptoHashAlgorithm = (null == algorithm)
|
||||
? CryptoHashAlgorithm.sha1
|
||||
: TlsCryptoUtilities.GetHash(algorithm.Hash);
|
||||
|
||||
ISigner signer = new DsaDigestSigner(CreateDsaImpl(cryptoHashAlgorithm), new NullDigest());
|
||||
signer.Init(true, new ParametersWithRandom(m_privateKey, m_crypto.SecureRandom));
|
||||
if (algorithm == null)
|
||||
{
|
||||
// Note: Only use the SHA1 part of the (MD5/SHA1) hash
|
||||
signer.BlockUpdate(hash, 16, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
}
|
||||
try
|
||||
{
|
||||
return signer.GenerateSignature();
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c2ca5e7e6ad55c489e5936b0beccc9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssSigner.cs
|
||||
uploadId: 783279
|
||||
47
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssVerifier.cs
vendored
Normal file
47
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssVerifier.cs
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>BC light-weight base class for the verifiers supporting the two DSA style algorithms from FIPS PUB
|
||||
/// 186-4: DSA and ECDSA.</summary>
|
||||
public abstract class BcTlsDssVerifier
|
||||
: BcTlsVerifier
|
||||
{
|
||||
protected BcTlsDssVerifier(BcTlsCrypto crypto, AsymmetricKeyParameter publicKey)
|
||||
: base(crypto, publicKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected abstract IDsa CreateDsaImpl();
|
||||
|
||||
protected abstract short SignatureAlgorithm { get; }
|
||||
|
||||
public override bool VerifyRawSignature(DigitallySigned digitallySigned, byte[] hash)
|
||||
{
|
||||
SignatureAndHashAlgorithm algorithm = digitallySigned.Algorithm;
|
||||
if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
ISigner signer = new DsaDigestSigner(CreateDsaImpl(), new NullDigest());
|
||||
signer.Init(false, m_publicKey);
|
||||
if (algorithm == null)
|
||||
{
|
||||
// Note: Only use the SHA1 part of the (MD5/SHA1) hash
|
||||
signer.BlockUpdate(hash, 16, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
}
|
||||
return signer.VerifySignature(digitallySigned.Signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82bc57525eb1d6847bd0f677aa9ffc1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsDssVerifier.cs
|
||||
uploadId: 783279
|
||||
43
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDH.cs
vendored
Normal file
43
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDH.cs
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Support class for ephemeral Elliptic Curve Diffie-Hellman using the BC light-weight library.</summary>
|
||||
public class BcTlsECDH
|
||||
: TlsAgreement
|
||||
{
|
||||
protected readonly BcTlsECDomain m_domain;
|
||||
|
||||
protected AsymmetricCipherKeyPair m_localKeyPair;
|
||||
protected ECPublicKeyParameters m_peerPublicKey;
|
||||
|
||||
public BcTlsECDH(BcTlsECDomain domain)
|
||||
{
|
||||
this.m_domain = domain;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateEphemeral()
|
||||
{
|
||||
this.m_localKeyPair = m_domain.GenerateKeyPair();
|
||||
|
||||
return m_domain.EncodePublicKey((ECPublicKeyParameters)m_localKeyPair.Public);
|
||||
}
|
||||
|
||||
public virtual void ReceivePeerValue(byte[] peerValue)
|
||||
{
|
||||
this.m_peerPublicKey = m_domain.DecodePublicKey(peerValue);
|
||||
}
|
||||
|
||||
public virtual TlsSecret CalculateSecret()
|
||||
{
|
||||
return m_domain.CalculateECDHAgreement((ECPrivateKeyParameters)m_localKeyPair.Private, m_peerPublicKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDH.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDH.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6aa1f94604e5f1944b98d536face36a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDH.cs
|
||||
uploadId: 783279
|
||||
125
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDomain.cs
vendored
Normal file
125
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDomain.cs
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/**
|
||||
* EC domain class for generating key pairs and performing key agreement.
|
||||
*/
|
||||
public class BcTlsECDomain
|
||||
: TlsECDomain
|
||||
{
|
||||
public static BcTlsSecret CalculateECDHAgreement(BcTlsCrypto crypto, ECPrivateKeyParameters privateKey,
|
||||
ECPublicKeyParameters publicKey)
|
||||
{
|
||||
ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
|
||||
basicAgreement.Init(privateKey);
|
||||
BigInteger agreementValue = basicAgreement.CalculateAgreement(publicKey);
|
||||
|
||||
/*
|
||||
* RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
|
||||
* FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
|
||||
* any given field; leading zeros found in this octet string MUST NOT be truncated.
|
||||
*/
|
||||
byte[] secret = BigIntegers.AsUnsignedByteArray(basicAgreement.GetFieldSize(), agreementValue);
|
||||
return crypto.AdoptLocalSecret(secret);
|
||||
}
|
||||
|
||||
public static ECDomainParameters GetDomainParameters(TlsECConfig ecConfig)
|
||||
{
|
||||
return GetDomainParameters(ecConfig.NamedGroup);
|
||||
}
|
||||
|
||||
public static ECDomainParameters GetDomainParameters(int namedGroup)
|
||||
{
|
||||
if (!NamedGroup.RefersToASpecificCurve(namedGroup))
|
||||
return null;
|
||||
|
||||
// Parameters are lazily created the first time a particular curve is accessed
|
||||
|
||||
string curveName = NamedGroup.GetCurveName(namedGroup);
|
||||
X9ECParameters ecP = ECKeyPairGenerator.FindECCurveByName(curveName);
|
||||
if (ecP == null)
|
||||
return null;
|
||||
|
||||
// It's a bit inefficient to do this conversion every time
|
||||
return new ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed());
|
||||
}
|
||||
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly TlsECConfig m_config;
|
||||
protected readonly ECDomainParameters m_domainParameters;
|
||||
|
||||
public BcTlsECDomain(BcTlsCrypto crypto, TlsECConfig ecConfig)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_config = ecConfig;
|
||||
this.m_domainParameters = GetDomainParameters(ecConfig);
|
||||
}
|
||||
|
||||
public virtual BcTlsSecret CalculateECDHAgreement(ECPrivateKeyParameters privateKey,
|
||||
ECPublicKeyParameters publicKey)
|
||||
{
|
||||
return CalculateECDHAgreement(m_crypto, privateKey, publicKey);
|
||||
}
|
||||
|
||||
public virtual TlsAgreement CreateECDH()
|
||||
{
|
||||
return new BcTlsECDH(this);
|
||||
}
|
||||
|
||||
public virtual ECPoint DecodePoint(byte[] encoding)
|
||||
{
|
||||
return m_domainParameters.Curve.DecodePoint(encoding);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual ECPublicKeyParameters DecodePublicKey(byte[] encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
ECPoint point = DecodePoint(encoding);
|
||||
|
||||
return new ECPublicKeyParameters(point, m_domainParameters);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual byte[] EncodePoint(ECPoint point)
|
||||
{
|
||||
return point.GetEncoded(false);
|
||||
}
|
||||
|
||||
public virtual byte[] EncodePublicKey(ECPublicKeyParameters publicKey)
|
||||
{
|
||||
return EncodePoint(publicKey.Q);
|
||||
}
|
||||
|
||||
public virtual AsymmetricCipherKeyPair GenerateKeyPair()
|
||||
{
|
||||
ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator();
|
||||
keyPairGenerator.Init(new ECKeyGenerationParameters(m_domainParameters, m_crypto.SecureRandom));
|
||||
return keyPairGenerator.GenerateKeyPair();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDomain.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDomain.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fd27ec13a575ea4c8600311dcb18f69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDomain.cs
|
||||
uploadId: 783279
|
||||
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsa13Signer.cs
vendored
Normal file
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsa13Signer.cs
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for generation of ECDSA signatures in TLS 1.3+ using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsECDsa13Signer
|
||||
: BcTlsSigner
|
||||
{
|
||||
private readonly int m_signatureScheme;
|
||||
|
||||
public BcTlsECDsa13Signer(BcTlsCrypto crypto, ECPrivateKeyParameters privateKey, int signatureScheme)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
if (!SignatureScheme.IsECDsa(signatureScheme))
|
||||
throw new ArgumentException("signatureScheme");
|
||||
|
||||
this.m_signatureScheme = signatureScheme;
|
||||
}
|
||||
|
||||
public override byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash)
|
||||
{
|
||||
if (algorithm == null || SignatureScheme.From(algorithm) != m_signatureScheme)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(m_signatureScheme);
|
||||
IDsa dsa = new ECDsaSigner(new HMacDsaKCalculator(m_crypto.CreateDigest(cryptoHashAlgorithm)));
|
||||
|
||||
ISigner signer = new DsaDigestSigner(dsa, new NullDigest());
|
||||
signer.Init(true, new ParametersWithRandom(m_privateKey, m_crypto.SecureRandom));
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
try
|
||||
{
|
||||
return signer.GenerateSignature();
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsa13Signer.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsa13Signer.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42b7da95e44910341b4de9117adf94bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsa13Signer.cs
|
||||
uploadId: 783279
|
||||
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaSigner.cs
vendored
Normal file
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaSigner.cs
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for generation of the raw ECDSA signature type using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsECDsaSigner
|
||||
: BcTlsDssSigner
|
||||
{
|
||||
public BcTlsECDsaSigner(BcTlsCrypto crypto, ECPrivateKeyParameters privateKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IDsa CreateDsaImpl(int cryptoHashAlgorithm)
|
||||
{
|
||||
return new ECDsaSigner(new HMacDsaKCalculator(m_crypto.CreateDigest(cryptoHashAlgorithm)));
|
||||
}
|
||||
|
||||
protected override short SignatureAlgorithm
|
||||
{
|
||||
get { return Tls.SignatureAlgorithm.ecdsa; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc174da35b6a95c43b4f9fd3ff8f9601
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaSigner.cs
|
||||
uploadId: 783279
|
||||
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaVerifier.cs
vendored
Normal file
33
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaVerifier.cs
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for the verification of the raw ECDSA signature type using the BC light-weight
|
||||
/// API.</summary>
|
||||
public class BcTlsECDsaVerifier
|
||||
: BcTlsDssVerifier
|
||||
{
|
||||
public BcTlsECDsaVerifier(BcTlsCrypto crypto, ECPublicKeyParameters publicKey)
|
||||
: base(crypto, publicKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IDsa CreateDsaImpl()
|
||||
{
|
||||
return new ECDsaSigner();
|
||||
}
|
||||
|
||||
protected override short SignatureAlgorithm
|
||||
{
|
||||
get { return Tls.SignatureAlgorithm.ecdsa; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92d29c21e5ab5ce409a87a091497c11b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsECDsaVerifier.cs
|
||||
uploadId: 783279
|
||||
31
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd25519Signer.cs
vendored
Normal file
31
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd25519Signer.cs
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public class BcTlsEd25519Signer
|
||||
: BcTlsSigner
|
||||
{
|
||||
public BcTlsEd25519Signer(BcTlsCrypto crypto, Ed25519PrivateKeyParameters privateKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
}
|
||||
|
||||
public override TlsStreamSigner GetStreamSigner(SignatureAndHashAlgorithm algorithm)
|
||||
{
|
||||
if (algorithm == null || SignatureScheme.From(algorithm) != SignatureScheme.ed25519)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
Ed25519Signer signer = new Ed25519Signer();
|
||||
signer.Init(true, m_privateKey);
|
||||
|
||||
return new BcTlsStreamSigner(signer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd25519Signer.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd25519Signer.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 815dee36ad3d2184fa77798c223a4b38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd25519Signer.cs
|
||||
uploadId: 783279
|
||||
31
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd448Signer.cs
vendored
Normal file
31
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd448Signer.cs
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public class BcTlsEd448Signer
|
||||
: BcTlsSigner
|
||||
{
|
||||
public BcTlsEd448Signer(BcTlsCrypto crypto, Ed448PrivateKeyParameters privateKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
}
|
||||
|
||||
public override TlsStreamSigner GetStreamSigner(SignatureAndHashAlgorithm algorithm)
|
||||
{
|
||||
if (algorithm == null || SignatureScheme.From(algorithm) != SignatureScheme.ed448)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
Ed448Signer signer = new Ed448Signer(TlsUtilities.EmptyBytes);
|
||||
signer.Init(true, m_privateKey);
|
||||
|
||||
return new BcTlsStreamSigner(signer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd448Signer.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd448Signer.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5ec0d7e05eb7cc43bc8fd211f9ba4c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsEd448Signer.cs
|
||||
uploadId: 783279
|
||||
60
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHash.cs
vendored
Normal file
60
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHash.cs
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsHash
|
||||
: TlsHash
|
||||
{
|
||||
private readonly BcTlsCrypto m_crypto;
|
||||
private readonly int m_cryptoHashAlgorithm;
|
||||
private readonly IDigest m_digest;
|
||||
|
||||
internal BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm)
|
||||
: this(crypto, cryptoHashAlgorithm, crypto.CreateDigest(cryptoHashAlgorithm))
|
||||
{
|
||||
}
|
||||
|
||||
private BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm, IDigest digest)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_cryptoHashAlgorithm = cryptoHashAlgorithm;
|
||||
this.m_digest = digest;
|
||||
}
|
||||
|
||||
public void Update(byte[] data, int offSet, int length)
|
||||
{
|
||||
m_digest.BlockUpdate(data, offSet, length);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Update(ReadOnlySpan<byte> input)
|
||||
{
|
||||
m_digest.BlockUpdate(input);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] CalculateHash()
|
||||
{
|
||||
byte[] rv = new byte[m_digest.GetDigestSize()];
|
||||
m_digest.DoFinal(rv, 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public TlsHash CloneHash()
|
||||
{
|
||||
IDigest clone = m_crypto.CloneDigest(m_cryptoHashAlgorithm, m_digest);
|
||||
return new BcTlsHash(m_crypto, m_cryptoHashAlgorithm, clone);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_digest.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHash.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHash.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a4db1fa62387dd4bbae89d4aeca62fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHash.cs
|
||||
uploadId: 783279
|
||||
73
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHmac.cs
vendored
Normal file
73
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHmac.cs
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsHmac
|
||||
: TlsHmac
|
||||
{
|
||||
private readonly HMac m_hmac;
|
||||
|
||||
internal BcTlsHmac(HMac hmac)
|
||||
{
|
||||
this.m_hmac = hmac;
|
||||
}
|
||||
|
||||
public void SetKey(byte[] key, int keyOff, int keyLen)
|
||||
{
|
||||
m_hmac.Init(new KeyParameter(key, keyOff, keyLen));
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void SetKey(ReadOnlySpan<byte> key)
|
||||
{
|
||||
m_hmac.Init(new KeyParameter(key));
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Update(byte[] input, int inOff, int length)
|
||||
{
|
||||
m_hmac.BlockUpdate(input, inOff, length);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Update(ReadOnlySpan<byte> input)
|
||||
{
|
||||
m_hmac.BlockUpdate(input);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] CalculateMac()
|
||||
{
|
||||
byte[] rv = new byte[m_hmac.GetMacSize()];
|
||||
m_hmac.DoFinal(rv, 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void CalculateMac(byte[] output, int outOff)
|
||||
{
|
||||
m_hmac.DoFinal(output, outOff);
|
||||
}
|
||||
|
||||
public int InternalBlockSize
|
||||
{
|
||||
get { return m_hmac.GetUnderlyingDigest().GetByteLength(); }
|
||||
}
|
||||
|
||||
public int MacLength
|
||||
{
|
||||
get { return m_hmac.GetMacSize(); }
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_hmac.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHmac.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHmac.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef25266360b4f04db436903e852505d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsHmac.cs
|
||||
uploadId: 783279
|
||||
28
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsNonceGenerator.cs
vendored
Normal file
28
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsNonceGenerator.cs
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Prng;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsNonceGenerator
|
||||
: TlsNonceGenerator
|
||||
{
|
||||
private readonly IRandomGenerator m_randomGenerator;
|
||||
|
||||
internal BcTlsNonceGenerator(IRandomGenerator randomGenerator)
|
||||
{
|
||||
this.m_randomGenerator = randomGenerator;
|
||||
}
|
||||
|
||||
public byte[] GenerateNonce(int size)
|
||||
{
|
||||
byte[] nonce = new byte[size];
|
||||
m_randomGenerator.NextBytes(nonce);
|
||||
return nonce;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsNonceGenerator.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsNonceGenerator.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bd9a1921160b7d4d982cb9241e1f81f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsNonceGenerator.cs
|
||||
uploadId: 783279
|
||||
511
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRawKeyCertificate.cs
vendored
Normal file
511
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRawKeyCertificate.cs
vendored
Normal file
@ -0,0 +1,511 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Implementation class for a single X.509 certificate based on the BC light-weight API.</summary>
|
||||
public class BcTlsRawKeyCertificate
|
||||
: TlsCertificate
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly SubjectPublicKeyInfo m_keyInfo;
|
||||
|
||||
protected DHPublicKeyParameters m_pubKeyDH = null;
|
||||
protected ECPublicKeyParameters m_pubKeyEC = null;
|
||||
protected Ed25519PublicKeyParameters m_pubKeyEd25519 = null;
|
||||
protected Ed448PublicKeyParameters m_pubKeyEd448 = null;
|
||||
protected RsaKeyParameters m_pubKeyRsa = null;
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public BcTlsRawKeyCertificate(BcTlsCrypto crypto, byte[] encoding)
|
||||
: this(crypto, SubjectPublicKeyInfo.GetInstance(encoding))
|
||||
{
|
||||
}
|
||||
|
||||
public BcTlsRawKeyCertificate(BcTlsCrypto crypto, SubjectPublicKeyInfo keyInfo)
|
||||
{
|
||||
m_crypto = crypto;
|
||||
m_keyInfo = keyInfo;
|
||||
}
|
||||
|
||||
public virtual SubjectPublicKeyInfo SubjectPublicKeyInfo => m_keyInfo;
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual TlsEncryptor CreateEncryptor(int tlsCertificateRole)
|
||||
{
|
||||
ValidateKeyUsage(KeyUsage.KeyEncipherment);
|
||||
|
||||
switch (tlsCertificateRole)
|
||||
{
|
||||
case TlsCertificateRole.RsaEncryption:
|
||||
{
|
||||
this.m_pubKeyRsa = GetPubKeyRsa();
|
||||
return new BcTlsRsaEncryptor(m_crypto, m_pubKeyRsa);
|
||||
}
|
||||
// TODO[gmssl]
|
||||
//case TlsCertificateRole.Sm2Encryption:
|
||||
//{
|
||||
// this.m_pubKeyEC = GetPubKeyEC();
|
||||
// return new BcTlsSM2Encryptor(m_crypto, m_pubKeyEC);
|
||||
//}
|
||||
}
|
||||
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual TlsVerifier CreateVerifier(short signatureAlgorithm)
|
||||
{
|
||||
switch (signatureAlgorithm)
|
||||
{
|
||||
case SignatureAlgorithm.ed25519:
|
||||
case SignatureAlgorithm.ed448:
|
||||
{
|
||||
int signatureScheme = SignatureScheme.From(HashAlgorithm.Intrinsic, signatureAlgorithm);
|
||||
Tls13Verifier tls13Verifier = CreateVerifier(signatureScheme);
|
||||
return new LegacyTls13Verifier(signatureScheme, tls13Verifier);
|
||||
}
|
||||
}
|
||||
|
||||
ValidateKeyUsage(KeyUsage.DigitalSignature);
|
||||
|
||||
switch (signatureAlgorithm)
|
||||
{
|
||||
case SignatureAlgorithm.dsa:
|
||||
return new BcTlsDsaVerifier(m_crypto, GetPubKeyDss());
|
||||
|
||||
case SignatureAlgorithm.ecdsa:
|
||||
return new BcTlsECDsaVerifier(m_crypto, GetPubKeyEC());
|
||||
|
||||
case SignatureAlgorithm.rsa:
|
||||
{
|
||||
ValidateRsa_Pkcs1();
|
||||
return new BcTlsRsaVerifier(m_crypto, GetPubKeyRsa());
|
||||
}
|
||||
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha512:
|
||||
{
|
||||
ValidateRsa_Pss_Pss(signatureAlgorithm);
|
||||
int signatureScheme = SignatureScheme.From(HashAlgorithm.Intrinsic, signatureAlgorithm);
|
||||
return new BcTlsRsaPssVerifier(m_crypto, GetPubKeyRsa(), signatureScheme);
|
||||
}
|
||||
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha512:
|
||||
{
|
||||
ValidateRsa_Pss_Rsae();
|
||||
int signatureScheme = SignatureScheme.From(HashAlgorithm.Intrinsic, signatureAlgorithm);
|
||||
return new BcTlsRsaPssVerifier(m_crypto, GetPubKeyRsa(), signatureScheme);
|
||||
}
|
||||
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual Tls13Verifier CreateVerifier(int signatureScheme)
|
||||
{
|
||||
ValidateKeyUsage(KeyUsage.DigitalSignature);
|
||||
|
||||
switch (signatureScheme)
|
||||
{
|
||||
case SignatureScheme.ecdsa_brainpoolP256r1tls13_sha256:
|
||||
case SignatureScheme.ecdsa_brainpoolP384r1tls13_sha384:
|
||||
case SignatureScheme.ecdsa_brainpoolP512r1tls13_sha512:
|
||||
case SignatureScheme.ecdsa_secp256r1_sha256:
|
||||
case SignatureScheme.ecdsa_secp384r1_sha384:
|
||||
case SignatureScheme.ecdsa_secp521r1_sha512:
|
||||
case SignatureScheme.ecdsa_sha1:
|
||||
{
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
ISigner verifier = new DsaDigestSigner(new ECDsaSigner(), digest);
|
||||
verifier.Init(false, GetPubKeyEC());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
case SignatureScheme.ed25519:
|
||||
{
|
||||
Ed25519Signer verifier = new Ed25519Signer();
|
||||
verifier.Init(false, GetPubKeyEd25519());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
case SignatureScheme.ed448:
|
||||
{
|
||||
Ed448Signer verifier = new Ed448Signer(TlsUtilities.EmptyBytes);
|
||||
verifier.Init(false, GetPubKeyEd448());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
case SignatureScheme.rsa_pkcs1_sha1:
|
||||
case SignatureScheme.rsa_pkcs1_sha256:
|
||||
case SignatureScheme.rsa_pkcs1_sha384:
|
||||
case SignatureScheme.rsa_pkcs1_sha512:
|
||||
{
|
||||
ValidateRsa_Pkcs1();
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
RsaDigestSigner verifier = new RsaDigestSigner(digest,
|
||||
TlsCryptoUtilities.GetOidForHash(cryptoHashAlgorithm));
|
||||
verifier.Init(false, GetPubKeyRsa());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
case SignatureScheme.rsa_pss_pss_sha256:
|
||||
case SignatureScheme.rsa_pss_pss_sha384:
|
||||
case SignatureScheme.rsa_pss_pss_sha512:
|
||||
{
|
||||
ValidateRsa_Pss_Pss(SignatureScheme.GetSignatureAlgorithm(signatureScheme));
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
PssSigner verifier = new PssSigner(new RsaEngine(), digest, digest.GetDigestSize());
|
||||
verifier.Init(false, GetPubKeyRsa());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
case SignatureScheme.rsa_pss_rsae_sha256:
|
||||
case SignatureScheme.rsa_pss_rsae_sha384:
|
||||
case SignatureScheme.rsa_pss_rsae_sha512:
|
||||
{
|
||||
ValidateRsa_Pss_Rsae();
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
PssSigner verifier = new PssSigner(new RsaEngine(), digest, digest.GetDigestSize());
|
||||
verifier.Init(false, GetPubKeyRsa());
|
||||
|
||||
return new BcTls13Verifier(verifier);
|
||||
}
|
||||
|
||||
// TODO[RFC 8998]
|
||||
//case SignatureScheme.sm2sig_sm3:
|
||||
//{
|
||||
// ParametersWithID parametersWithID = new ParametersWithID(GetPubKeyEC(),
|
||||
// Strings.ToByteArray("TLSv1.3+GM+Cipher+Suite"));
|
||||
|
||||
// SM2Signer verifier = new SM2Signer();
|
||||
// verifier.Init(false, parametersWithID);
|
||||
|
||||
// return new BcTls13Verifier(verifier);
|
||||
//}
|
||||
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual byte[] GetEncoded()
|
||||
{
|
||||
return m_keyInfo.GetEncoded(Asn1Encodable.Der);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual byte[] GetExtension(DerObjectIdentifier extensionOid)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual BigInteger SerialNumber => null;
|
||||
|
||||
public virtual string SigAlgOid => null;
|
||||
|
||||
public virtual Asn1Encodable GetSigAlgParams() => null;
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual short GetLegacySignatureAlgorithm()
|
||||
{
|
||||
AsymmetricKeyParameter publicKey = GetPublicKey();
|
||||
if (publicKey.IsPrivate)
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
|
||||
if (!SupportsKeyUsage(KeyUsage.DigitalSignature))
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* RFC 5246 7.4.6. Client Certificate
|
||||
*/
|
||||
|
||||
/*
|
||||
* RSA public key; the certificate MUST allow the key to be used for signing with the
|
||||
* signature scheme and hash algorithm that will be employed in the certificate verify
|
||||
* message.
|
||||
*/
|
||||
if (publicKey is RsaKeyParameters)
|
||||
return SignatureAlgorithm.rsa;
|
||||
|
||||
/*
|
||||
* DSA public key; the certificate MUST allow the key to be used for signing with the
|
||||
* hash algorithm that will be employed in the certificate verify message.
|
||||
*/
|
||||
if (publicKey is DsaPublicKeyParameters)
|
||||
return SignatureAlgorithm.dsa;
|
||||
|
||||
/*
|
||||
* ECDSA-capable public key; the certificate MUST allow the key to be used for signing
|
||||
* with the hash algorithm that will be employed in the certificate verify message; the
|
||||
* public key MUST use a curve and point format supported by the server.
|
||||
*/
|
||||
if (publicKey is ECPublicKeyParameters)
|
||||
{
|
||||
// TODO Check the curve and point format
|
||||
return SignatureAlgorithm.ecdsa;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual DHPublicKeyParameters GetPubKeyDH()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (DHPublicKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual DsaPublicKeyParameters GetPubKeyDss()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (DsaPublicKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual ECPublicKeyParameters GetPubKeyEC()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (ECPublicKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual Ed25519PublicKeyParameters GetPubKeyEd25519()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Ed25519PublicKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual Ed448PublicKeyParameters GetPubKeyEd448()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Ed448PublicKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual RsaKeyParameters GetPubKeyRsa()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (RsaKeyParameters)GetPublicKey();
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual bool SupportsSignatureAlgorithm(short signatureAlgorithm)
|
||||
{
|
||||
return SupportsSignatureAlgorithm(signatureAlgorithm, KeyUsage.DigitalSignature);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual bool SupportsSignatureAlgorithmCA(short signatureAlgorithm)
|
||||
{
|
||||
return SupportsSignatureAlgorithm(signatureAlgorithm, KeyUsage.KeyCertSign);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual TlsCertificate CheckUsageInRole(int tlsCertificateRole)
|
||||
{
|
||||
switch (tlsCertificateRole)
|
||||
{
|
||||
case TlsCertificateRole.DH:
|
||||
{
|
||||
ValidateKeyUsage(KeyUsage.KeyAgreement);
|
||||
this.m_pubKeyDH = GetPubKeyDH();
|
||||
return this;
|
||||
}
|
||||
case TlsCertificateRole.ECDH:
|
||||
{
|
||||
ValidateKeyUsage(KeyUsage.KeyAgreement);
|
||||
this.m_pubKeyEC = GetPubKeyEC();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
protected virtual AsymmetricKeyParameter GetPublicKey()
|
||||
{
|
||||
try
|
||||
{
|
||||
return PublicKeyFactory.CreateKey(m_keyInfo);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool SupportsKeyUsage(int keyUsageBits)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool SupportsRsa_Pkcs1()
|
||||
{
|
||||
AlgorithmIdentifier pubKeyAlgID = m_keyInfo.AlgorithmID;
|
||||
return RsaUtilities.SupportsPkcs1(pubKeyAlgID);
|
||||
}
|
||||
|
||||
protected virtual bool SupportsRsa_Pss_Pss(short signatureAlgorithm)
|
||||
{
|
||||
AlgorithmIdentifier pubKeyAlgID = m_keyInfo.AlgorithmID;
|
||||
return RsaUtilities.SupportsPss_Pss(signatureAlgorithm, pubKeyAlgID);
|
||||
}
|
||||
|
||||
protected virtual bool SupportsRsa_Pss_Rsae()
|
||||
{
|
||||
AlgorithmIdentifier pubKeyAlgID = m_keyInfo.AlgorithmID;
|
||||
return RsaUtilities.SupportsPss_Rsae(pubKeyAlgID);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
protected virtual bool SupportsSignatureAlgorithm(short signatureAlgorithm, int keyUsage)
|
||||
{
|
||||
if (!SupportsKeyUsage(keyUsage))
|
||||
return false;
|
||||
|
||||
AsymmetricKeyParameter publicKey = GetPublicKey();
|
||||
|
||||
switch (signatureAlgorithm)
|
||||
{
|
||||
case SignatureAlgorithm.rsa:
|
||||
return SupportsRsa_Pkcs1()
|
||||
&& publicKey is RsaKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.dsa:
|
||||
return publicKey is DsaPublicKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.ecdsa:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP256r1tls13_sha256:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP384r1tls13_sha384:
|
||||
case SignatureAlgorithm.ecdsa_brainpoolP512r1tls13_sha512:
|
||||
return publicKey is ECPublicKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.ed25519:
|
||||
return publicKey is Ed25519PublicKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.ed448:
|
||||
return publicKey is Ed448PublicKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_rsae_sha512:
|
||||
return SupportsRsa_Pss_Rsae()
|
||||
&& publicKey is RsaKeyParameters;
|
||||
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha256:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha384:
|
||||
case SignatureAlgorithm.rsa_pss_pss_sha512:
|
||||
return SupportsRsa_Pss_Pss(signatureAlgorithm)
|
||||
&& publicKey is RsaKeyParameters;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
public virtual void ValidateKeyUsage(int keyUsageBits)
|
||||
{
|
||||
if (!SupportsKeyUsage(keyUsageBits))
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
protected virtual void ValidateRsa_Pkcs1()
|
||||
{
|
||||
if (!SupportsRsa_Pkcs1())
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
protected virtual void ValidateRsa_Pss_Pss(short signatureAlgorithm)
|
||||
{
|
||||
if (!SupportsRsa_Pss_Pss(signatureAlgorithm))
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
protected virtual void ValidateRsa_Pss_Rsae()
|
||||
{
|
||||
if (!SupportsRsa_Pss_Rsae())
|
||||
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRawKeyCertificate.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRawKeyCertificate.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f956740c47d73ee42b06809b11ca0fd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRawKeyCertificate.cs
|
||||
uploadId: 783279
|
||||
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaEncryptor.cs
vendored
Normal file
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaEncryptor.cs
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsRsaEncryptor
|
||||
: TlsEncryptor
|
||||
{
|
||||
private static RsaKeyParameters CheckPublicKey(RsaKeyParameters pubKeyRsa)
|
||||
{
|
||||
if (null == pubKeyRsa || pubKeyRsa.IsPrivate)
|
||||
throw new ArgumentException("No public RSA key provided", "pubKeyRsa");
|
||||
|
||||
return pubKeyRsa;
|
||||
}
|
||||
|
||||
private readonly BcTlsCrypto m_crypto;
|
||||
private readonly RsaKeyParameters m_pubKeyRsa;
|
||||
|
||||
internal BcTlsRsaEncryptor(BcTlsCrypto crypto, RsaKeyParameters pubKeyRsa)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
this.m_pubKeyRsa = CheckPublicKey(pubKeyRsa);
|
||||
}
|
||||
|
||||
public byte[] Encrypt(byte[] input, int inOff, int length)
|
||||
{
|
||||
try
|
||||
{
|
||||
Pkcs1Encoding encoding = new Pkcs1Encoding(new RsaBlindedEngine());
|
||||
encoding.Init(true, new ParametersWithRandom(m_pubKeyRsa, m_crypto.SecureRandom));
|
||||
return encoding.ProcessBlock(input, inOff, length);
|
||||
}
|
||||
catch (InvalidCipherTextException e)
|
||||
{
|
||||
/*
|
||||
* This should never happen, only during decryption.
|
||||
*/
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaEncryptor.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaEncryptor.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2fbf26ff4db16e4ab6d7a66dc1b2734
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaEncryptor.cs
|
||||
uploadId: 783279
|
||||
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssSigner.cs
vendored
Normal file
51
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssSigner.cs
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Operator supporting the generation of RSASSA-PSS signatures using the BC light-weight API.</summary>
|
||||
public class BcTlsRsaPssSigner
|
||||
: BcTlsSigner
|
||||
{
|
||||
private readonly int m_signatureScheme;
|
||||
|
||||
public BcTlsRsaPssSigner(BcTlsCrypto crypto, RsaKeyParameters privateKey, int signatureScheme)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
if (!SignatureScheme.IsRsaPss(signatureScheme))
|
||||
throw new ArgumentException("signatureScheme");
|
||||
|
||||
this.m_signatureScheme = signatureScheme;
|
||||
}
|
||||
|
||||
public override byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash)
|
||||
{
|
||||
if (algorithm == null || SignatureScheme.From(algorithm) != m_signatureScheme)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(m_signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
PssSigner signer = PssSigner.CreateRawSigner(new RsaBlindedEngine(), digest, digest, digest.GetDigestSize(),
|
||||
PssSigner.TrailerImplicit);
|
||||
signer.Init(true, new ParametersWithRandom(m_privateKey, m_crypto.SecureRandom));
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
try
|
||||
{
|
||||
return signer.GenerateSignature();
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32c0adc0dc01c7048b8ef04bb6a0ab9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssSigner.cs
|
||||
uploadId: 783279
|
||||
45
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssVerifier.cs
vendored
Normal file
45
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssVerifier.cs
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Operator supporting the verification of RSASSA-PSS signatures using the BC light-weight API.</summary>
|
||||
public class BcTlsRsaPssVerifier
|
||||
: BcTlsVerifier
|
||||
{
|
||||
private readonly int m_signatureScheme;
|
||||
|
||||
public BcTlsRsaPssVerifier(BcTlsCrypto crypto, RsaKeyParameters publicKey, int signatureScheme)
|
||||
: base(crypto, publicKey)
|
||||
{
|
||||
if (!SignatureScheme.IsRsaPss(signatureScheme))
|
||||
throw new ArgumentException("signatureScheme");
|
||||
|
||||
this.m_signatureScheme = signatureScheme;
|
||||
}
|
||||
|
||||
public override bool VerifyRawSignature(DigitallySigned digitallySigned, byte[] hash)
|
||||
{
|
||||
SignatureAndHashAlgorithm algorithm = digitallySigned.Algorithm;
|
||||
if (algorithm == null || SignatureScheme.From(algorithm) != m_signatureScheme)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(m_signatureScheme);
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
|
||||
PssSigner verifier = PssSigner.CreateRawSigner(new RsaEngine(), digest, digest, digest.GetDigestSize(),
|
||||
PssSigner.TrailerImplicit);
|
||||
verifier.Init(false, m_publicKey);
|
||||
verifier.BlockUpdate(hash, 0, hash.Length);
|
||||
return verifier.VerifySignature(digitallySigned.Signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 394d3707553c52046b3e608d23561d65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaPssVerifier.cs
|
||||
uploadId: 783279
|
||||
75
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaSigner.cs
vendored
Normal file
75
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaSigner.cs
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Operator supporting the generation of RSASSA-PKCS1-v1_5 signatures using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsRsaSigner
|
||||
: BcTlsSigner
|
||||
{
|
||||
private readonly RsaKeyParameters m_publicKey;
|
||||
|
||||
public BcTlsRsaSigner(BcTlsCrypto crypto, RsaKeyParameters privateKey, RsaKeyParameters publicKey)
|
||||
: base(crypto, privateKey)
|
||||
{
|
||||
this.m_publicKey = publicKey;
|
||||
}
|
||||
|
||||
public override byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash)
|
||||
{
|
||||
IDigest nullDigest = new NullDigest();
|
||||
|
||||
ISigner signer;
|
||||
if (algorithm != null)
|
||||
{
|
||||
if (algorithm.Signature != SignatureAlgorithm.rsa)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
/*
|
||||
* RFC 5246 4.7. In RSA signing, the opaque vector contains the signature generated
|
||||
* using the RSASSA-PKCS1-v1_5 signature scheme defined in [PKCS1].
|
||||
*/
|
||||
signer = new RsaDigestSigner(nullDigest, TlsUtilities.GetOidForHashAlgorithm(algorithm.Hash));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* RFC 5246 4.7. Note that earlier versions of TLS used a different RSA signature scheme
|
||||
* that did not include a DigestInfo encoding.
|
||||
*/
|
||||
signer = new GenericSigner(new Pkcs1Encoding(new RsaBlindedEngine()), nullDigest);
|
||||
}
|
||||
signer.Init(true, new ParametersWithRandom(m_privateKey, m_crypto.SecureRandom));
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
try
|
||||
{
|
||||
byte[] signature = signer.GenerateSignature();
|
||||
|
||||
signer.Init(false, m_publicKey);
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
|
||||
if (signer.VerifySignature(signature))
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 493cafec07827344580a19f8e73a15fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaSigner.cs
|
||||
uploadId: 783279
|
||||
56
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaVerifier.cs
vendored
Normal file
56
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaVerifier.cs
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Encodings;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Operator supporting the verification of RSASSA-PKCS1-v1_5 signatures using the BC light-weight API.
|
||||
/// </summary>
|
||||
public class BcTlsRsaVerifier
|
||||
: BcTlsVerifier
|
||||
{
|
||||
public BcTlsRsaVerifier(BcTlsCrypto crypto, RsaKeyParameters publicKey)
|
||||
: base(crypto, publicKey)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool VerifyRawSignature(DigitallySigned digitallySigned, byte[] hash)
|
||||
{
|
||||
IDigest nullDigest = new NullDigest();
|
||||
|
||||
SignatureAndHashAlgorithm algorithm = digitallySigned.Algorithm;
|
||||
ISigner signer;
|
||||
if (algorithm != null)
|
||||
{
|
||||
if (algorithm.Signature != SignatureAlgorithm.rsa)
|
||||
throw new InvalidOperationException("Invalid algorithm: " + algorithm);
|
||||
|
||||
/*
|
||||
* RFC 5246 4.7. In RSA signing, the opaque vector contains the signature generated
|
||||
* using the RSASSA-PKCS1-v1_5 signature scheme defined in [PKCS1].
|
||||
*/
|
||||
signer = new RsaDigestSigner(nullDigest, TlsUtilities.GetOidForHashAlgorithm(algorithm.Hash));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* RFC 5246 4.7. Note that earlier versions of TLS used a different RSA signature scheme
|
||||
* that did not include a DigestInfo encoding.
|
||||
*/
|
||||
signer = new GenericSigner(new Pkcs1Encoding(new RsaBlindedEngine()), nullDigest);
|
||||
}
|
||||
signer.Init(false, m_publicKey);
|
||||
signer.BlockUpdate(hash, 0, hash.Length);
|
||||
return signer.VerifySignature(digitallySigned.Signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 262b99bbd5b956c45a02f2057583f956
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsRsaVerifier.cs
|
||||
uploadId: 783279
|
||||
416
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSecret.cs
vendored
Normal file
416
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSecret.cs
vendored
Normal file
@ -0,0 +1,416 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>BC light-weight support class for handling TLS secrets and deriving key material and other secrets
|
||||
/// from them.</summary>
|
||||
public class BcTlsSecret
|
||||
: AbstractTlsSecret
|
||||
{
|
||||
public static BcTlsSecret Convert(BcTlsCrypto crypto, TlsSecret secret)
|
||||
{
|
||||
if (secret is BcTlsSecret)
|
||||
return (BcTlsSecret)secret;
|
||||
|
||||
if (secret is AbstractTlsSecret)
|
||||
{
|
||||
AbstractTlsSecret abstractTlsSecret = (AbstractTlsSecret)secret;
|
||||
|
||||
return crypto.AdoptLocalSecret(CopyData(abstractTlsSecret));
|
||||
}
|
||||
|
||||
throw new ArgumentException("unrecognized TlsSecret - cannot copy data: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(secret));
|
||||
}
|
||||
|
||||
// SSL3 magic mix constants ("A", "BB", "CCC", ...)
|
||||
private static readonly byte[] Ssl3Const = GenerateSsl3Constants();
|
||||
|
||||
private static byte[] GenerateSsl3Constants()
|
||||
{
|
||||
int n = 15;
|
||||
byte[] result = new byte[n * (n + 1) / 2];
|
||||
int pos = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
byte b = (byte)('A' + i);
|
||||
for (int j = 0; j <= i; ++j)
|
||||
{
|
||||
result[pos++] = b;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
|
||||
public BcTlsSecret(BcTlsCrypto crypto, byte[] data)
|
||||
: base(data)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
}
|
||||
|
||||
public override TlsSecret DeriveUsingPrf(int prfAlgorithm, string label, byte[] seed, int length)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
CheckAlive();
|
||||
|
||||
switch (prfAlgorithm)
|
||||
{
|
||||
case PrfAlgorithm.tls13_hkdf_sha256:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sha256, label, seed, length);
|
||||
case PrfAlgorithm.tls13_hkdf_sha384:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sha384, label, seed, length);
|
||||
case PrfAlgorithm.tls13_hkdf_sm3:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sm3, label, seed, length);
|
||||
default:
|
||||
return m_crypto.AdoptLocalSecret(Prf(prfAlgorithm, label, seed, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override TlsSecret DeriveUsingPrf(int prfAlgorithm, ReadOnlySpan<char> label, ReadOnlySpan<byte> seed,
|
||||
int length)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
CheckAlive();
|
||||
|
||||
switch (prfAlgorithm)
|
||||
{
|
||||
case PrfAlgorithm.tls13_hkdf_sha256:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sha256, label, seed, length);
|
||||
case PrfAlgorithm.tls13_hkdf_sha384:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sha384, label, seed, length);
|
||||
case PrfAlgorithm.tls13_hkdf_sm3:
|
||||
return TlsCryptoUtilities.HkdfExpandLabel(this, CryptoHashAlgorithm.sm3, label, seed, length);
|
||||
default:
|
||||
return m_crypto.AdoptLocalSecret(Prf(prfAlgorithm, label, seed, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override TlsSecret HkdfExpand(int cryptoHashAlgorithm, byte[] info, int length)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return HkdfExpand(cryptoHashAlgorithm, info.AsSpan(), length);
|
||||
#else
|
||||
lock (this)
|
||||
{
|
||||
if (length < 1)
|
||||
return m_crypto.AdoptLocalSecret(TlsUtilities.EmptyBytes);
|
||||
|
||||
int hashLen = TlsCryptoUtilities.GetHashOutputSize(cryptoHashAlgorithm);
|
||||
if (length > (255 * hashLen))
|
||||
throw new ArgumentException("must be <= 255 * (output size of 'hashAlgorithm')", "length");
|
||||
|
||||
CheckAlive();
|
||||
|
||||
byte[] prk = m_data;
|
||||
|
||||
HMac hmac = new HMac(m_crypto.CreateDigest(cryptoHashAlgorithm));
|
||||
hmac.Init(new KeyParameter(prk));
|
||||
|
||||
byte[] okm = new byte[length];
|
||||
|
||||
byte[] t = new byte[hashLen];
|
||||
byte counter = 0x00;
|
||||
|
||||
int pos = 0;
|
||||
for (;;)
|
||||
{
|
||||
hmac.BlockUpdate(info, 0, info.Length);
|
||||
hmac.Update(++counter);
|
||||
hmac.DoFinal(t, 0);
|
||||
|
||||
int remaining = length - pos;
|
||||
if (remaining <= hashLen)
|
||||
{
|
||||
Array.Copy(t, 0, okm, pos, remaining);
|
||||
break;
|
||||
}
|
||||
|
||||
Array.Copy(t, 0, okm, pos, hashLen);
|
||||
pos += hashLen;
|
||||
hmac.BlockUpdate(t, 0, t.Length);
|
||||
}
|
||||
|
||||
return m_crypto.AdoptLocalSecret(okm);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override TlsSecret HkdfExpand(int cryptoHashAlgorithm, ReadOnlySpan<byte> info, int length)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (length < 1)
|
||||
return m_crypto.AdoptLocalSecret(TlsUtilities.EmptyBytes);
|
||||
|
||||
int hashLen = TlsCryptoUtilities.GetHashOutputSize(cryptoHashAlgorithm);
|
||||
if (length > (255 * hashLen))
|
||||
throw new ArgumentException("must be <= 255 * (output size of 'hashAlgorithm')", "length");
|
||||
|
||||
CheckAlive();
|
||||
|
||||
ReadOnlySpan<byte> prk = m_data;
|
||||
|
||||
HMac hmac = new HMac(m_crypto.CreateDigest(cryptoHashAlgorithm));
|
||||
hmac.Init(new KeyParameter(prk));
|
||||
|
||||
byte[] okm = new byte[length];
|
||||
|
||||
Span<byte> t = hashLen <= 128
|
||||
? stackalloc byte[hashLen]
|
||||
: new byte[hashLen];
|
||||
byte counter = 0x00;
|
||||
|
||||
int pos = 0;
|
||||
for (;;)
|
||||
{
|
||||
hmac.BlockUpdate(info);
|
||||
hmac.Update(++counter);
|
||||
hmac.DoFinal(t);
|
||||
|
||||
int remaining = length - pos;
|
||||
if (remaining <= hashLen)
|
||||
{
|
||||
t[..remaining].CopyTo(okm.AsSpan(pos));
|
||||
break;
|
||||
}
|
||||
|
||||
t.CopyTo(okm.AsSpan(pos));
|
||||
pos += hashLen;
|
||||
hmac.BlockUpdate(t);
|
||||
}
|
||||
|
||||
return m_crypto.AdoptLocalSecret(okm);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override TlsSecret HkdfExtract(int cryptoHashAlgorithm, TlsSecret ikm)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
CheckAlive();
|
||||
|
||||
byte[] salt = m_data;
|
||||
this.m_data = null;
|
||||
|
||||
HMac hmac = new HMac(m_crypto.CreateDigest(cryptoHashAlgorithm));
|
||||
hmac.Init(new KeyParameter(salt));
|
||||
|
||||
Convert(m_crypto, ikm).UpdateMac(hmac);
|
||||
|
||||
byte[] prk = new byte[hmac.GetMacSize()];
|
||||
hmac.DoFinal(prk, 0);
|
||||
|
||||
return m_crypto.AdoptLocalSecret(prk);
|
||||
}
|
||||
}
|
||||
|
||||
protected override AbstractTlsCrypto Crypto
|
||||
{
|
||||
get { return m_crypto; }
|
||||
}
|
||||
|
||||
protected virtual void HmacHash(int cryptoHashAlgorithm, byte[] secret, int secretOff, int secretLen,
|
||||
byte[] seed, byte[] output)
|
||||
{
|
||||
IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
|
||||
HMac hmac = new HMac(digest);
|
||||
hmac.Init(new KeyParameter(secret, secretOff, secretLen));
|
||||
|
||||
byte[] a = seed;
|
||||
|
||||
int macSize = hmac.GetMacSize();
|
||||
|
||||
byte[] b1 = new byte[macSize];
|
||||
byte[] b2 = new byte[macSize];
|
||||
|
||||
int pos = 0;
|
||||
while (pos < output.Length)
|
||||
{
|
||||
hmac.BlockUpdate(a, 0, a.Length);
|
||||
hmac.DoFinal(b1, 0);
|
||||
a = b1;
|
||||
hmac.BlockUpdate(a, 0, a.Length);
|
||||
hmac.BlockUpdate(seed, 0, seed.Length);
|
||||
hmac.DoFinal(b2, 0);
|
||||
Array.Copy(b2, 0, output, pos, System.Math.Min(macSize, output.Length - pos));
|
||||
pos += macSize;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual byte[] Prf(int prfAlgorithm, string label, byte[] seed, int length)
|
||||
{
|
||||
if (PrfAlgorithm.ssl_prf_legacy == prfAlgorithm)
|
||||
return Prf_Ssl(seed, length);
|
||||
|
||||
byte[] labelSeed = Arrays.Concatenate(Strings.ToByteArray(label), seed);
|
||||
|
||||
if (PrfAlgorithm.tls_prf_legacy == prfAlgorithm)
|
||||
return Prf_1_0(labelSeed, length);
|
||||
|
||||
return Prf_1_2(prfAlgorithm, labelSeed, length);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
protected virtual byte[] Prf(int prfAlgorithm, ReadOnlySpan<char> label, ReadOnlySpan<byte> seed, int length)
|
||||
{
|
||||
if (PrfAlgorithm.ssl_prf_legacy == prfAlgorithm)
|
||||
return Prf_Ssl(seed, length);
|
||||
|
||||
byte[] labelSeed = new byte[label.Length + seed.Length];
|
||||
|
||||
for (int i = 0; i < label.Length; ++i)
|
||||
{
|
||||
labelSeed[i] = (byte)label[i];
|
||||
}
|
||||
|
||||
seed.CopyTo(labelSeed.AsSpan(label.Length));
|
||||
|
||||
if (PrfAlgorithm.tls_prf_legacy == prfAlgorithm)
|
||||
return Prf_1_0(labelSeed, length);
|
||||
|
||||
return Prf_1_2(prfAlgorithm, labelSeed, length);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual byte[] Prf_Ssl(byte[] seed, int length)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return Prf_Ssl(seed.AsSpan(), length);
|
||||
#else
|
||||
IDigest md5 = m_crypto.CreateDigest(CryptoHashAlgorithm.md5);
|
||||
IDigest sha1 = m_crypto.CreateDigest(CryptoHashAlgorithm.sha1);
|
||||
|
||||
int md5Size = md5.GetDigestSize();
|
||||
int sha1Size = sha1.GetDigestSize();
|
||||
|
||||
byte[] tmp = new byte[System.Math.Max(md5Size, sha1Size)];
|
||||
byte[] result = new byte[length];
|
||||
|
||||
int constLen = 1, constPos = 0, resultPos = 0;
|
||||
while (resultPos < length)
|
||||
{
|
||||
sha1.BlockUpdate(Ssl3Const, constPos, constLen);
|
||||
constPos += constLen++;
|
||||
|
||||
sha1.BlockUpdate(m_data, 0, m_data.Length);
|
||||
sha1.BlockUpdate(seed, 0, seed.Length);
|
||||
sha1.DoFinal(tmp, 0);
|
||||
|
||||
md5.BlockUpdate(m_data, 0, m_data.Length);
|
||||
md5.BlockUpdate(tmp, 0, sha1Size);
|
||||
|
||||
int remaining = length - resultPos;
|
||||
if (remaining < md5Size)
|
||||
{
|
||||
md5.DoFinal(tmp, 0);
|
||||
Array.Copy(tmp, 0, result, resultPos, remaining);
|
||||
resultPos += remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
md5.DoFinal(result, resultPos);
|
||||
resultPos += md5Size;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
protected virtual byte[] Prf_Ssl(ReadOnlySpan<byte> seed, int length)
|
||||
{
|
||||
IDigest md5 = m_crypto.CreateDigest(CryptoHashAlgorithm.md5);
|
||||
IDigest sha1 = m_crypto.CreateDigest(CryptoHashAlgorithm.sha1);
|
||||
|
||||
int md5Size = md5.GetDigestSize();
|
||||
int sha1Size = sha1.GetDigestSize();
|
||||
|
||||
Span<byte> tmp = stackalloc byte[System.Math.Max(md5Size, sha1Size)];
|
||||
byte[] result = new byte[length];
|
||||
|
||||
int constLen = 1, constPos = 0, resultPos = 0;
|
||||
while (resultPos < length)
|
||||
{
|
||||
sha1.BlockUpdate(Ssl3Const.AsSpan(constPos, constLen));
|
||||
constPos += constLen++;
|
||||
|
||||
sha1.BlockUpdate(m_data);
|
||||
sha1.BlockUpdate(seed);
|
||||
sha1.DoFinal(tmp);
|
||||
|
||||
md5.BlockUpdate(m_data);
|
||||
md5.BlockUpdate(tmp[..sha1Size]);
|
||||
|
||||
int remaining = length - resultPos;
|
||||
if (remaining < md5Size)
|
||||
{
|
||||
md5.DoFinal(tmp);
|
||||
tmp[..remaining].CopyTo(result.AsSpan(resultPos));
|
||||
resultPos += remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
md5.DoFinal(result.AsSpan(resultPos));
|
||||
resultPos += md5Size;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual byte[] Prf_1_0(byte[] labelSeed, int length)
|
||||
{
|
||||
int s_half = (m_data.Length + 1) / 2;
|
||||
|
||||
byte[] b1 = new byte[length];
|
||||
HmacHash(CryptoHashAlgorithm.md5, m_data, 0, s_half, labelSeed, b1);
|
||||
|
||||
byte[] b2 = new byte[length];
|
||||
HmacHash(CryptoHashAlgorithm.sha1, m_data, m_data.Length - s_half, s_half, labelSeed, b2);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
b1[i] ^= b2[i];
|
||||
}
|
||||
return b1;
|
||||
}
|
||||
|
||||
protected virtual byte[] Prf_1_2(int prfAlgorithm, byte[] labelSeed, int length)
|
||||
{
|
||||
int cryptoHashAlgorithm = TlsCryptoUtilities.GetHashForPrf(prfAlgorithm);
|
||||
byte[] result = new byte[length];
|
||||
HmacHash(cryptoHashAlgorithm, m_data, 0, m_data.Length, labelSeed, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual void UpdateMac(IMac mac)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
CheckAlive();
|
||||
|
||||
mac.BlockUpdate(m_data, 0, m_data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSecret.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSecret.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85a721fd49f4902428c3caa39ac83b40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSecret.cs
|
||||
uploadId: 783279
|
||||
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSigner.cs
vendored
Normal file
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSigner.cs
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public abstract class BcTlsSigner
|
||||
: TlsSigner
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly AsymmetricKeyParameter m_privateKey;
|
||||
|
||||
protected BcTlsSigner(BcTlsCrypto crypto, AsymmetricKeyParameter privateKey)
|
||||
{
|
||||
if (crypto == null)
|
||||
throw new ArgumentNullException("crypto");
|
||||
if (privateKey == null)
|
||||
throw new ArgumentNullException("privateKey");
|
||||
if (!privateKey.IsPrivate)
|
||||
throw new ArgumentException("must be private", "privateKey");
|
||||
|
||||
this.m_crypto = crypto;
|
||||
this.m_privateKey = privateKey;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public virtual TlsStreamSigner GetStreamSigner(SignatureAndHashAlgorithm algorithm)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 305b37d61fbd1214a8eea941cb9d1f8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSigner.cs
|
||||
uploadId: 783279
|
||||
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Client.cs
vendored
Normal file
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Client.cs
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.Srp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsSrp6Client
|
||||
: TlsSrp6Client
|
||||
{
|
||||
private readonly Srp6Client m_srp6Client;
|
||||
|
||||
internal BcTlsSrp6Client(Srp6Client srpClient)
|
||||
{
|
||||
this.m_srp6Client = srpClient;
|
||||
}
|
||||
|
||||
public BigInteger CalculateSecret(BigInteger serverB)
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_srp6Client.CalculateSecret(serverB);
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
|
||||
}
|
||||
}
|
||||
|
||||
public BigInteger GenerateClientCredentials(byte[] srpSalt, byte[] identity, byte[] password)
|
||||
{
|
||||
return m_srp6Client.GenerateClientCredentials(srpSalt, identity, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Client.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Client.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05a4b14ea34033a45b780e27139d8afb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Client.cs
|
||||
uploadId: 783279
|
||||
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Server.cs
vendored
Normal file
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Server.cs
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.Srp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsSrp6Server
|
||||
: TlsSrp6Server
|
||||
{
|
||||
private readonly Srp6Server m_srp6Server;
|
||||
|
||||
internal BcTlsSrp6Server(Srp6Server srp6Server)
|
||||
{
|
||||
this.m_srp6Server = srp6Server;
|
||||
}
|
||||
|
||||
public BigInteger GenerateServerCredentials()
|
||||
{
|
||||
return m_srp6Server.GenerateServerCredentials();
|
||||
}
|
||||
|
||||
public BigInteger CalculateSecret(BigInteger clientA)
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_srp6Server.CalculateSecret(clientA);
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Server.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Server.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bf7dfb7ec324f74285eae7d974ae28e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6Server.cs
|
||||
uploadId: 783279
|
||||
27
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6VerifierGenerator.cs
vendored
Normal file
27
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6VerifierGenerator.cs
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.Srp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsSrp6VerifierGenerator
|
||||
: TlsSrp6VerifierGenerator
|
||||
{
|
||||
private readonly Srp6VerifierGenerator m_srp6VerifierGenerator;
|
||||
|
||||
internal BcTlsSrp6VerifierGenerator(Srp6VerifierGenerator srp6VerifierGenerator)
|
||||
{
|
||||
this.m_srp6VerifierGenerator = srp6VerifierGenerator;
|
||||
}
|
||||
|
||||
public BigInteger GenerateVerifier(byte[] salt, byte[] identity, byte[] password)
|
||||
{
|
||||
return m_srp6VerifierGenerator.GenerateVerifier(salt, identity, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6VerifierGenerator.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6VerifierGenerator.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b8f68e434e3a3142977e4da775abc98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsSrp6VerifierGenerator.cs
|
||||
uploadId: 783279
|
||||
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamSigner.cs
vendored
Normal file
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamSigner.cs
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsStreamSigner
|
||||
: TlsStreamSigner
|
||||
{
|
||||
private readonly SignerSink m_output;
|
||||
|
||||
internal BcTlsStreamSigner(ISigner signer)
|
||||
{
|
||||
this.m_output = new SignerSink(signer);
|
||||
}
|
||||
|
||||
public Stream Stream
|
||||
{
|
||||
get { return m_output; }
|
||||
}
|
||||
|
||||
public byte[] GetSignature()
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_output.Signer.GenerateSignature();
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e74faffd2aa527d4a845f6498e758812
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamSigner.cs
|
||||
uploadId: 783279
|
||||
35
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamVerifier.cs
vendored
Normal file
35
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamVerifier.cs
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcTlsStreamVerifier
|
||||
: TlsStreamVerifier
|
||||
{
|
||||
private readonly SignerSink m_output;
|
||||
private readonly byte[] m_signature;
|
||||
|
||||
internal BcTlsStreamVerifier(ISigner verifier, byte[] signature)
|
||||
{
|
||||
this.m_output = new SignerSink(verifier);
|
||||
this.m_signature = signature;
|
||||
}
|
||||
|
||||
public Stream Stream
|
||||
{
|
||||
get { return m_output; }
|
||||
}
|
||||
|
||||
public bool IsVerified()
|
||||
{
|
||||
return m_output.Signer.VerifySignature(m_signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d424ccba0cab9ee46aae3a380e1e802d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsStreamVerifier.cs
|
||||
uploadId: 783279
|
||||
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsVerifier.cs
vendored
Normal file
40
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsVerifier.cs
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public abstract class BcTlsVerifier
|
||||
: TlsVerifier
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly AsymmetricKeyParameter m_publicKey;
|
||||
|
||||
protected BcTlsVerifier(BcTlsCrypto crypto, AsymmetricKeyParameter publicKey)
|
||||
{
|
||||
if (crypto == null)
|
||||
throw new ArgumentNullException("crypto");
|
||||
if (publicKey == null)
|
||||
throw new ArgumentNullException("publicKey");
|
||||
if (publicKey.IsPrivate)
|
||||
throw new ArgumentException("must be public", "publicKey");
|
||||
|
||||
this.m_crypto = crypto;
|
||||
this.m_publicKey = publicKey;
|
||||
}
|
||||
|
||||
public virtual TlsStreamVerifier GetStreamVerifier(DigitallySigned digitallySigned)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual bool VerifyRawSignature(DigitallySigned digitallySigned, byte[] hash)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsVerifier.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsVerifier.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56e0a640f551a734ca82598ca760c05d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcTlsVerifier.cs
|
||||
uploadId: 783279
|
||||
52
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcVerifyingStreamSigner.cs
vendored
Normal file
52
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcVerifyingStreamSigner.cs
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
internal sealed class BcVerifyingStreamSigner
|
||||
: TlsStreamSigner
|
||||
{
|
||||
private readonly ISigner m_signer;
|
||||
private readonly ISigner m_verifier;
|
||||
private readonly TeeOutputStream m_output;
|
||||
|
||||
internal BcVerifyingStreamSigner(ISigner signer, ISigner verifier)
|
||||
{
|
||||
Stream outputSigner = new SignerSink(signer);
|
||||
Stream outputVerifier = new SignerSink(verifier);
|
||||
|
||||
this.m_signer = signer;
|
||||
this.m_verifier = verifier;
|
||||
this.m_output = new TeeOutputStream(outputSigner, outputVerifier);
|
||||
}
|
||||
|
||||
public Stream Stream
|
||||
{
|
||||
get { return m_output; }
|
||||
}
|
||||
|
||||
public byte[] GetSignature()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] signature = m_signer.GenerateSignature();
|
||||
if (m_verifier.VerifySignature(signature))
|
||||
return signature;
|
||||
}
|
||||
catch (CryptoException e)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error, e);
|
||||
}
|
||||
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcVerifyingStreamSigner.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcVerifyingStreamSigner.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de67313ac565c424ca92712d06026c38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcVerifyingStreamSigner.cs
|
||||
uploadId: 783279
|
||||
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519.cs
vendored
Normal file
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519.cs
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc7748;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Support class for X25519 using the BC light-weight library.</summary>
|
||||
public class BcX25519
|
||||
: TlsAgreement
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly byte[] m_privateKey = new byte[X25519.ScalarSize];
|
||||
protected readonly byte[] m_peerPublicKey = new byte[X25519.PointSize];
|
||||
|
||||
public BcX25519(BcTlsCrypto crypto)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateEphemeral()
|
||||
{
|
||||
m_crypto.SecureRandom.NextBytes(m_privateKey);
|
||||
|
||||
byte[] publicKey = new byte[X25519.PointSize];
|
||||
X25519.ScalarMultBase(m_privateKey, 0, publicKey, 0);
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public virtual void ReceivePeerValue(byte[] peerValue)
|
||||
{
|
||||
if (peerValue == null || peerValue.Length != X25519.PointSize)
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
|
||||
Array.Copy(peerValue, 0, m_peerPublicKey, 0, X25519.PointSize);
|
||||
}
|
||||
|
||||
public virtual TlsSecret CalculateSecret()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] secret = new byte[X25519.PointSize];
|
||||
if (!X25519.CalculateAgreement(m_privateKey, 0, m_peerPublicKey, 0, secret, 0))
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure);
|
||||
|
||||
return m_crypto.AdoptLocalSecret(secret);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(m_privateKey, 0, m_privateKey.Length);
|
||||
Array.Clear(m_peerPublicKey, 0, m_peerPublicKey.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd6451fbd7aba3d4893ed53b2bfbbf65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519.cs
|
||||
uploadId: 783279
|
||||
24
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519Domain.cs
vendored
Normal file
24
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519Domain.cs
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public class BcX25519Domain
|
||||
: TlsECDomain
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
|
||||
public BcX25519Domain(BcTlsCrypto crypto)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
}
|
||||
|
||||
public virtual TlsAgreement CreateECDH()
|
||||
{
|
||||
return new BcX25519(m_crypto);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519Domain.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519Domain.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 056ee7f6926a7dc479bfb4209e64cea9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX25519Domain.cs
|
||||
uploadId: 783279
|
||||
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448.cs
vendored
Normal file
58
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448.cs
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc7748;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
/// <summary>Support class for X448 using the BC light-weight library.</summary>
|
||||
public class BcX448
|
||||
: TlsAgreement
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
protected readonly byte[] m_privateKey = new byte[X448.ScalarSize];
|
||||
protected readonly byte[] m_peerPublicKey = new byte[X448.PointSize];
|
||||
|
||||
public BcX448(BcTlsCrypto crypto)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateEphemeral()
|
||||
{
|
||||
m_crypto.SecureRandom.NextBytes(m_privateKey);
|
||||
|
||||
byte[] publicKey = new byte[X448.PointSize];
|
||||
X448.ScalarMultBase(m_privateKey, 0, publicKey, 0);
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public virtual void ReceivePeerValue(byte[] peerValue)
|
||||
{
|
||||
if (peerValue == null || peerValue.Length != X448.PointSize)
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
|
||||
Array.Copy(peerValue, 0, m_peerPublicKey, 0, X448.PointSize);
|
||||
}
|
||||
|
||||
public virtual TlsSecret CalculateSecret()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] secret = new byte[X448.PointSize];
|
||||
if (!X448.CalculateAgreement(m_privateKey, 0, m_peerPublicKey, 0, secret, 0))
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure);
|
||||
|
||||
return m_crypto.AdoptLocalSecret(secret);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(m_privateKey, 0, m_privateKey.Length);
|
||||
Array.Clear(m_peerPublicKey, 0, m_peerPublicKey.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53ebfdfdf1d0c9d45a98c18b97154411
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448.cs
|
||||
uploadId: 783279
|
||||
24
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448Domain.cs
vendored
Normal file
24
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448Domain.cs
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
|
||||
{
|
||||
public class BcX448Domain
|
||||
: TlsECDomain
|
||||
{
|
||||
protected readonly BcTlsCrypto m_crypto;
|
||||
|
||||
public BcX448Domain(BcTlsCrypto crypto)
|
||||
{
|
||||
this.m_crypto = crypto;
|
||||
}
|
||||
|
||||
public virtual TlsAgreement CreateECDH()
|
||||
{
|
||||
return new BcX448(m_crypto);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448Domain.cs.meta
vendored
Normal file
18
Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448Domain.cs.meta
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2096d96b2625a8479fd8090c2114e21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 267636
|
||||
packageName: Best HTTP
|
||||
packageVersion: 3.0.17
|
||||
assetPath: Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/tls/crypto/impl/bc/BcX448Domain.cs
|
||||
uploadId: 783279
|
||||
Reference in New Issue
Block a user