up
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsAgreementCredentials
|
||||
: AbstractTlsCredentials, TlsAgreementCredentials
|
||||
{
|
||||
/// <exception cref="IOException"></exception>
|
||||
public abstract byte[] GenerateAgreement(AsymmetricKeyParameter peerPublicKey);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e77cff473b7c41ff85ef6aa30c6624e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class AbstractTlsCipherFactory
|
||||
: TlsCipherFactory
|
||||
{
|
||||
/// <exception cref="IOException"></exception>
|
||||
public virtual TlsCipher CreateCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0c3ec6af7a0c4b7ba19b1f918b9c967
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
272
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsClient.cs
Normal file
272
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsClient.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsClient
|
||||
: AbstractTlsPeer, TlsClient
|
||||
{
|
||||
protected TlsCipherFactory mCipherFactory;
|
||||
|
||||
protected TlsClientContext mContext;
|
||||
|
||||
protected IList mSupportedSignatureAlgorithms;
|
||||
protected int[] mNamedCurves;
|
||||
protected byte[] mClientECPointFormats, mServerECPointFormats;
|
||||
|
||||
protected int mSelectedCipherSuite;
|
||||
protected short mSelectedCompressionMethod;
|
||||
|
||||
public System.Collections.Generic.List<string> HostNames { get; set; }
|
||||
|
||||
public AbstractTlsClient()
|
||||
: this(new DefaultTlsCipherFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public AbstractTlsClient(TlsCipherFactory cipherFactory)
|
||||
{
|
||||
this.mCipherFactory = cipherFactory;
|
||||
}
|
||||
|
||||
protected virtual bool AllowUnexpectedServerExtension(int extensionType, byte[] extensionData)
|
||||
{
|
||||
switch (extensionType)
|
||||
{
|
||||
case ExtensionType.elliptic_curves:
|
||||
/*
|
||||
* Exception added based on field reports that some servers do send this, although the
|
||||
* Supported Elliptic Curves Extension is clearly intended to be client-only. If
|
||||
* present, we still require that it is a valid EllipticCurveList.
|
||||
*/
|
||||
TlsEccUtilities.ReadSupportedEllipticCurvesExtension(extensionData);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CheckForUnexpectedServerExtension(IDictionary serverExtensions, int extensionType)
|
||||
{
|
||||
byte[] extensionData = TlsUtilities.GetExtensionData(serverExtensions, extensionType);
|
||||
if (extensionData != null && !AllowUnexpectedServerExtension(extensionType, extensionData))
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Init(TlsClientContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public virtual TlsSession GetSessionToResume()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual ProtocolVersion ClientHelloRecordLayerVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
// "{03,00}"
|
||||
//return ProtocolVersion.SSLv3;
|
||||
|
||||
// "the lowest version number supported by the client"
|
||||
//return MinimumVersion;
|
||||
|
||||
// "the value of ClientHello.client_version"
|
||||
return ClientVersion;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ProtocolVersion ClientVersion
|
||||
{
|
||||
get { return ProtocolVersion.TLSv12; }
|
||||
}
|
||||
|
||||
public virtual bool IsFallback
|
||||
{
|
||||
/*
|
||||
* RFC 7507 4. The TLS_FALLBACK_SCSV cipher suite value is meant for use by clients that
|
||||
* repeat a connection attempt with a downgraded protocol (perform a "fallback retry") in
|
||||
* order to work around interoperability problems with legacy servers.
|
||||
*/
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public virtual IDictionary GetClientExtensions()
|
||||
{
|
||||
IDictionary clientExtensions = null;
|
||||
|
||||
ProtocolVersion clientVersion = mContext.ClientVersion;
|
||||
|
||||
/*
|
||||
* RFC 5246 7.4.1.4.1. Note: this extension is not meaningful for TLS versions prior to 1.2.
|
||||
* Clients MUST NOT offer it if they are offering prior versions.
|
||||
*/
|
||||
if (TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(clientVersion))
|
||||
{
|
||||
// TODO Provide a way for the user to specify the acceptable hash/signature algorithms.
|
||||
|
||||
this.mSupportedSignatureAlgorithms = TlsUtilities.GetDefaultSupportedSignatureAlgorithms();
|
||||
|
||||
clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised(clientExtensions);
|
||||
|
||||
TlsUtilities.AddSignatureAlgorithmsExtension(clientExtensions, mSupportedSignatureAlgorithms);
|
||||
}
|
||||
|
||||
if (TlsEccUtilities.ContainsEccCipherSuites(GetCipherSuites()))
|
||||
{
|
||||
/*
|
||||
* RFC 4492 5.1. A client that proposes ECC cipher suites in its ClientHello message
|
||||
* appends these extensions (along with any others), enumerating the curves it supports
|
||||
* and the point formats it can parse. Clients SHOULD send both the Supported Elliptic
|
||||
* Curves Extension and the Supported Point Formats Extension.
|
||||
*/
|
||||
/*
|
||||
* TODO Could just add all the curves since we support them all, but users may not want
|
||||
* to use unnecessarily large fields. Need configuration options.
|
||||
*/
|
||||
this.mNamedCurves = new int[]{ NamedCurve.secp256r1, NamedCurve.secp384r1 };
|
||||
this.mClientECPointFormats = new byte[]{ ECPointFormat.uncompressed,
|
||||
ECPointFormat.ansiX962_compressed_prime, ECPointFormat.ansiX962_compressed_char2, };
|
||||
|
||||
clientExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised(clientExtensions);
|
||||
|
||||
TlsEccUtilities.AddSupportedEllipticCurvesExtension(clientExtensions, mNamedCurves);
|
||||
TlsEccUtilities.AddSupportedPointFormatsExtension(clientExtensions, mClientECPointFormats);
|
||||
}
|
||||
|
||||
if (this.HostNames != null && this.HostNames.Count > 0)
|
||||
{
|
||||
var list = new System.Collections.Generic.List<ServerName>(this.HostNames.Count);
|
||||
|
||||
for (int i = 0; i < this.HostNames.Count; ++i)
|
||||
list.Add(new ServerName(Tls.NameType.host_name, this.HostNames[i]));
|
||||
|
||||
TlsExtensionsUtilities.AddServerNameExtension(clientExtensions, new ServerNameList(list));
|
||||
}
|
||||
|
||||
return clientExtensions;
|
||||
}
|
||||
|
||||
public virtual ProtocolVersion MinimumVersion
|
||||
{
|
||||
get { return ProtocolVersion.TLSv10; }
|
||||
}
|
||||
|
||||
public virtual void NotifyServerVersion(ProtocolVersion serverVersion)
|
||||
{
|
||||
if (!MinimumVersion.IsEqualOrEarlierVersionOf(serverVersion))
|
||||
throw new TlsFatalAlert(AlertDescription.protocol_version);
|
||||
}
|
||||
|
||||
public abstract int[] GetCipherSuites();
|
||||
|
||||
public virtual byte[] GetCompressionMethods()
|
||||
{
|
||||
return new byte[]{ CompressionMethod.cls_null };
|
||||
}
|
||||
|
||||
public virtual void NotifySessionID(byte[] sessionID)
|
||||
{
|
||||
// Currently ignored
|
||||
}
|
||||
|
||||
public virtual void NotifySelectedCipherSuite(int selectedCipherSuite)
|
||||
{
|
||||
this.mSelectedCipherSuite = selectedCipherSuite;
|
||||
}
|
||||
|
||||
public virtual void NotifySelectedCompressionMethod(byte selectedCompressionMethod)
|
||||
{
|
||||
this.mSelectedCompressionMethod = selectedCompressionMethod;
|
||||
}
|
||||
|
||||
public virtual void ProcessServerExtensions(IDictionary serverExtensions)
|
||||
{
|
||||
/*
|
||||
* TlsProtocol implementation validates that any server extensions received correspond to
|
||||
* client extensions sent. By default, we don't send any, and this method is not called.
|
||||
*/
|
||||
if (serverExtensions != null)
|
||||
{
|
||||
/*
|
||||
* RFC 5246 7.4.1.4.1. Servers MUST NOT send this extension.
|
||||
*/
|
||||
CheckForUnexpectedServerExtension(serverExtensions, ExtensionType.signature_algorithms);
|
||||
|
||||
CheckForUnexpectedServerExtension(serverExtensions, ExtensionType.elliptic_curves);
|
||||
|
||||
if (TlsEccUtilities.IsEccCipherSuite(this.mSelectedCipherSuite))
|
||||
{
|
||||
this.mServerECPointFormats = TlsEccUtilities.GetSupportedPointFormatsExtension(serverExtensions);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckForUnexpectedServerExtension(serverExtensions, ExtensionType.ec_point_formats);
|
||||
}
|
||||
|
||||
/*
|
||||
* RFC 7685 3. The server MUST NOT echo the extension.
|
||||
*/
|
||||
CheckForUnexpectedServerExtension(serverExtensions, ExtensionType.padding);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessServerSupplementalData(IList serverSupplementalData)
|
||||
{
|
||||
if (serverSupplementalData != null)
|
||||
throw new TlsFatalAlert(AlertDescription.unexpected_message);
|
||||
}
|
||||
|
||||
public abstract TlsKeyExchange GetKeyExchange();
|
||||
|
||||
public abstract TlsAuthentication GetAuthentication();
|
||||
|
||||
public virtual IList GetClientSupplementalData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override TlsCompression GetCompression()
|
||||
{
|
||||
switch (mSelectedCompressionMethod)
|
||||
{
|
||||
case CompressionMethod.cls_null:
|
||||
return new TlsNullCompression();
|
||||
|
||||
case CompressionMethod.DEFLATE:
|
||||
return new TlsDeflateCompression();
|
||||
|
||||
default:
|
||||
/*
|
||||
* Note: internal error here; the TlsProtocol implementation verifies that the
|
||||
* server-selected compression method was in the list of client-offered compression
|
||||
* methods, so if we now can't produce an implementation, we shouldn't have offered it!
|
||||
*/
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsCipher GetCipher()
|
||||
{
|
||||
int encryptionAlgorithm = TlsUtilities.GetEncryptionAlgorithm(mSelectedCipherSuite);
|
||||
int macAlgorithm = TlsUtilities.GetMacAlgorithm(mSelectedCipherSuite);
|
||||
|
||||
return mCipherFactory.CreateCipher(mContext, encryptionAlgorithm, macAlgorithm);
|
||||
}
|
||||
|
||||
public virtual void NotifyNewSessionTicket(NewSessionTicket newSessionTicket)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 047c830ffafef4d7eb39e9fd80a19e26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
156
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsContext.cs
Normal file
156
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsContext.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Prng;
|
||||
using Org.BouncyCastle.Security;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
internal abstract class AbstractTlsContext
|
||||
: TlsContext
|
||||
{
|
||||
private static long counter = Times.NanoTime();
|
||||
|
||||
#if NETCF_1_0
|
||||
private static object counterLock = new object();
|
||||
private static long NextCounterValue()
|
||||
{
|
||||
lock (counterLock)
|
||||
{
|
||||
return ++counter;
|
||||
}
|
||||
}
|
||||
#else
|
||||
private static long NextCounterValue()
|
||||
{
|
||||
return Interlocked.Increment(ref counter);
|
||||
}
|
||||
#endif
|
||||
|
||||
private readonly IRandomGenerator mNonceRandom;
|
||||
private readonly SecureRandom mSecureRandom;
|
||||
private readonly SecurityParameters mSecurityParameters;
|
||||
|
||||
private ProtocolVersion mClientVersion = null;
|
||||
private ProtocolVersion mServerVersion = null;
|
||||
private TlsSession mSession = null;
|
||||
private object mUserObject = null;
|
||||
|
||||
internal AbstractTlsContext(SecureRandom secureRandom, SecurityParameters securityParameters)
|
||||
{
|
||||
IDigest d = TlsUtilities.CreateHash(HashAlgorithm.sha256);
|
||||
byte[] seed = new byte[d.GetDigestSize()];
|
||||
secureRandom.NextBytes(seed);
|
||||
|
||||
this.mNonceRandom = new DigestRandomGenerator(d);
|
||||
mNonceRandom.AddSeedMaterial(NextCounterValue());
|
||||
mNonceRandom.AddSeedMaterial(Times.NanoTime());
|
||||
mNonceRandom.AddSeedMaterial(seed);
|
||||
|
||||
this.mSecureRandom = secureRandom;
|
||||
this.mSecurityParameters = securityParameters;
|
||||
}
|
||||
|
||||
public virtual IRandomGenerator NonceRandomGenerator
|
||||
{
|
||||
get { return mNonceRandom; }
|
||||
}
|
||||
|
||||
public virtual SecureRandom SecureRandom
|
||||
{
|
||||
get { return mSecureRandom; }
|
||||
}
|
||||
|
||||
public virtual SecurityParameters SecurityParameters
|
||||
{
|
||||
get { return mSecurityParameters; }
|
||||
}
|
||||
|
||||
public abstract bool IsServer { get; }
|
||||
|
||||
public virtual ProtocolVersion ClientVersion
|
||||
{
|
||||
get { return mClientVersion; }
|
||||
}
|
||||
|
||||
internal virtual void SetClientVersion(ProtocolVersion clientVersion)
|
||||
{
|
||||
this.mClientVersion = clientVersion;
|
||||
}
|
||||
|
||||
public virtual ProtocolVersion ServerVersion
|
||||
{
|
||||
get { return mServerVersion; }
|
||||
}
|
||||
|
||||
internal virtual void SetServerVersion(ProtocolVersion serverVersion)
|
||||
{
|
||||
this.mServerVersion = serverVersion;
|
||||
}
|
||||
|
||||
public virtual TlsSession ResumableSession
|
||||
{
|
||||
get { return mSession; }
|
||||
}
|
||||
|
||||
internal virtual void SetResumableSession(TlsSession session)
|
||||
{
|
||||
this.mSession = session;
|
||||
}
|
||||
|
||||
public virtual object UserObject
|
||||
{
|
||||
get { return mUserObject; }
|
||||
set { this.mUserObject = value; }
|
||||
}
|
||||
|
||||
public virtual byte[] ExportKeyingMaterial(string asciiLabel, byte[] context_value, int length)
|
||||
{
|
||||
/*
|
||||
* TODO[session-hash]
|
||||
*
|
||||
* draft-ietf-tls-session-hash-04 5.4. If a client or server chooses to continue with a full
|
||||
* handshake without the extended master secret extension, [..] the client or server MUST
|
||||
* NOT export any key material based on the new master secret for any subsequent
|
||||
* application-level authentication. In particular, it MUST disable [RFC5705] [..].
|
||||
*/
|
||||
|
||||
if (context_value != null && !TlsUtilities.IsValidUint16(context_value.Length))
|
||||
throw new ArgumentException("must have length less than 2^16 (or be null)", "context_value");
|
||||
|
||||
SecurityParameters sp = SecurityParameters;
|
||||
byte[] cr = sp.ClientRandom, sr = sp.ServerRandom;
|
||||
|
||||
int seedLength = cr.Length + sr.Length;
|
||||
if (context_value != null)
|
||||
{
|
||||
seedLength += (2 + context_value.Length);
|
||||
}
|
||||
|
||||
byte[] seed = new byte[seedLength];
|
||||
int seedPos = 0;
|
||||
|
||||
Array.Copy(cr, 0, seed, seedPos, cr.Length);
|
||||
seedPos += cr.Length;
|
||||
Array.Copy(sr, 0, seed, seedPos, sr.Length);
|
||||
seedPos += sr.Length;
|
||||
if (context_value != null)
|
||||
{
|
||||
TlsUtilities.WriteUint16(context_value.Length, seed, seedPos);
|
||||
seedPos += 2;
|
||||
Array.Copy(context_value, 0, seed, seedPos, context_value.Length);
|
||||
seedPos += context_value.Length;
|
||||
}
|
||||
|
||||
if (seedPos != seedLength)
|
||||
throw new InvalidOperationException("error in calculation of seed for export");
|
||||
|
||||
return TlsUtilities.PRF(this, sp.MasterSecret, asciiLabel, seed, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb6e062022d2544b09f3e6c9ed019b73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsCredentials
|
||||
: TlsCredentials
|
||||
{
|
||||
public abstract Certificate Certificate { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d88eca800b42e4799863e0251b3397ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsEncryptionCredentials
|
||||
: AbstractTlsCredentials, TlsEncryptionCredentials
|
||||
{
|
||||
/// <exception cref="IOException"></exception>
|
||||
public abstract byte[] DecryptPreMasterSecret(byte[] encryptedPreMasterSecret);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf7c42122b957465e940ab559708f045
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,181 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsKeyExchange
|
||||
: TlsKeyExchange
|
||||
{
|
||||
protected readonly int mKeyExchange;
|
||||
protected IList mSupportedSignatureAlgorithms;
|
||||
|
||||
protected TlsContext mContext;
|
||||
|
||||
protected AbstractTlsKeyExchange(int keyExchange, IList supportedSignatureAlgorithms)
|
||||
{
|
||||
this.mKeyExchange = keyExchange;
|
||||
this.mSupportedSignatureAlgorithms = supportedSignatureAlgorithms;
|
||||
}
|
||||
|
||||
protected virtual DigitallySigned ParseSignature(Stream input)
|
||||
{
|
||||
DigitallySigned signature = DigitallySigned.Parse(mContext, input);
|
||||
SignatureAndHashAlgorithm signatureAlgorithm = signature.Algorithm;
|
||||
if (signatureAlgorithm != null)
|
||||
{
|
||||
TlsUtilities.VerifySupportedSignatureAlgorithm(mSupportedSignatureAlgorithms, signatureAlgorithm);
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
public virtual void Init(TlsContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
|
||||
ProtocolVersion clientVersion = context.ClientVersion;
|
||||
|
||||
if (TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(clientVersion))
|
||||
{
|
||||
/*
|
||||
* RFC 5264 7.4.1.4.1. If the client does not send the signature_algorithms extension,
|
||||
* the server MUST do the following:
|
||||
*
|
||||
* - If the negotiated key exchange algorithm is one of (RSA, DHE_RSA, DH_RSA, RSA_PSK,
|
||||
* ECDH_RSA, ECDHE_RSA), behave as if client had sent the value {sha1,rsa}.
|
||||
*
|
||||
* - If the negotiated key exchange algorithm is one of (DHE_DSS, DH_DSS), behave as if
|
||||
* the client had sent the value {sha1,dsa}.
|
||||
*
|
||||
* - If the negotiated key exchange algorithm is one of (ECDH_ECDSA, ECDHE_ECDSA),
|
||||
* behave as if the client had sent value {sha1,ecdsa}.
|
||||
*/
|
||||
if (this.mSupportedSignatureAlgorithms == null)
|
||||
{
|
||||
switch (mKeyExchange)
|
||||
{
|
||||
case KeyExchangeAlgorithm.DH_DSS:
|
||||
case KeyExchangeAlgorithm.DHE_DSS:
|
||||
case KeyExchangeAlgorithm.SRP_DSS:
|
||||
{
|
||||
this.mSupportedSignatureAlgorithms = TlsUtilities.GetDefaultDssSignatureAlgorithms();
|
||||
break;
|
||||
}
|
||||
|
||||
case KeyExchangeAlgorithm.ECDH_ECDSA:
|
||||
case KeyExchangeAlgorithm.ECDHE_ECDSA:
|
||||
{
|
||||
this.mSupportedSignatureAlgorithms = TlsUtilities.GetDefaultECDsaSignatureAlgorithms();
|
||||
break;
|
||||
}
|
||||
|
||||
case KeyExchangeAlgorithm.DH_RSA:
|
||||
case KeyExchangeAlgorithm.DHE_RSA:
|
||||
case KeyExchangeAlgorithm.ECDH_RSA:
|
||||
case KeyExchangeAlgorithm.ECDHE_RSA:
|
||||
case KeyExchangeAlgorithm.RSA:
|
||||
case KeyExchangeAlgorithm.RSA_PSK:
|
||||
case KeyExchangeAlgorithm.SRP_RSA:
|
||||
{
|
||||
this.mSupportedSignatureAlgorithms = TlsUtilities.GetDefaultRsaSignatureAlgorithms();
|
||||
break;
|
||||
}
|
||||
|
||||
case KeyExchangeAlgorithm.DHE_PSK:
|
||||
case KeyExchangeAlgorithm.ECDHE_PSK:
|
||||
case KeyExchangeAlgorithm.PSK:
|
||||
case KeyExchangeAlgorithm.SRP:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("unsupported key exchange algorithm");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (this.mSupportedSignatureAlgorithms != null)
|
||||
{
|
||||
throw new InvalidOperationException("supported_signature_algorithms not allowed for " + clientVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void SkipServerCredentials();
|
||||
|
||||
public virtual void ProcessServerCertificate(Certificate serverCertificate)
|
||||
{
|
||||
if (mSupportedSignatureAlgorithms == null)
|
||||
{
|
||||
/*
|
||||
* TODO RFC 2264 7.4.2. Unless otherwise specified, the signing algorithm for the
|
||||
* certificate must be the same as the algorithm for the certificate key.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* TODO RFC 5264 7.4.2. If the client provided a "signature_algorithms" extension, then
|
||||
* all certificates provided by the server MUST be signed by a hash/signature algorithm
|
||||
* pair that appears in that extension.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessServerCredentials(TlsCredentials serverCredentials)
|
||||
{
|
||||
ProcessServerCertificate(serverCredentials.Certificate);
|
||||
}
|
||||
|
||||
public virtual bool RequiresServerKeyExchange
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateServerKeyExchange()
|
||||
{
|
||||
if (RequiresServerKeyExchange)
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void SkipServerKeyExchange()
|
||||
{
|
||||
if (RequiresServerKeyExchange)
|
||||
throw new TlsFatalAlert(AlertDescription.unexpected_message);
|
||||
}
|
||||
|
||||
public virtual void ProcessServerKeyExchange(Stream input)
|
||||
{
|
||||
if (!RequiresServerKeyExchange)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.unexpected_message);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ValidateCertificateRequest(CertificateRequest certificateRequest);
|
||||
|
||||
public virtual void SkipClientCredentials()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void ProcessClientCredentials(TlsCredentials clientCredentials);
|
||||
|
||||
public virtual void ProcessClientCertificate(Certificate clientCertificate)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void GenerateClientKeyExchange(Stream output);
|
||||
|
||||
public virtual void ProcessClientKeyExchange(Stream input)
|
||||
{
|
||||
// Key exchange implementation MUST support client key exchange
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
|
||||
public abstract byte[] GeneratePremasterSecret();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a6df7ddd7fd4434d9d26dddcb8a05f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsPeer.cs
Normal file
52
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsPeer.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsPeer
|
||||
: TlsPeer
|
||||
{
|
||||
public virtual bool ShouldUseGmtUnixTime()
|
||||
{
|
||||
/*
|
||||
* draft-mathewson-no-gmtunixtime-00 2. For the reasons we discuss above, we recommend that
|
||||
* TLS implementors MUST by default set the entire value the ClientHello.Random and
|
||||
* ServerHello.Random fields, including gmt_unix_time, to a cryptographically random
|
||||
* sequence.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void NotifySecureRenegotiation(bool secureRenegotiation)
|
||||
{
|
||||
if (!secureRenegotiation)
|
||||
{
|
||||
/*
|
||||
* RFC 5746 3.4/3.6. In this case, some clients/servers may want to terminate the handshake instead
|
||||
* of continuing; see Section 4.1/4.3 for discussion.
|
||||
*/
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract TlsCompression GetCompression();
|
||||
|
||||
public abstract TlsCipher GetCipher();
|
||||
|
||||
public virtual void NotifyAlertRaised(byte alertLevel, byte alertDescription, string message, Exception cause)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void NotifyAlertReceived(byte alertLevel, byte alertDescription)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void NotifyHandshakeComplete()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 180614144d5954f8da66c6950158ff14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
353
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsServer.cs
Normal file
353
Assets/BestHTTP/SecureProtocol/crypto/tls/AbstractTlsServer.cs
Normal file
@@ -0,0 +1,353 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsServer
|
||||
: AbstractTlsPeer, TlsServer
|
||||
{
|
||||
protected TlsCipherFactory mCipherFactory;
|
||||
|
||||
protected TlsServerContext mContext;
|
||||
|
||||
protected ProtocolVersion mClientVersion;
|
||||
protected int[] mOfferedCipherSuites;
|
||||
protected byte[] mOfferedCompressionMethods;
|
||||
protected IDictionary mClientExtensions;
|
||||
|
||||
protected bool mEncryptThenMacOffered;
|
||||
protected short mMaxFragmentLengthOffered;
|
||||
protected bool mTruncatedHMacOffered;
|
||||
protected IList mSupportedSignatureAlgorithms;
|
||||
protected bool mEccCipherSuitesOffered;
|
||||
protected int[] mNamedCurves;
|
||||
protected byte[] mClientECPointFormats, mServerECPointFormats;
|
||||
|
||||
protected ProtocolVersion mServerVersion;
|
||||
protected int mSelectedCipherSuite;
|
||||
protected byte mSelectedCompressionMethod;
|
||||
protected IDictionary mServerExtensions;
|
||||
|
||||
public AbstractTlsServer()
|
||||
: this(new DefaultTlsCipherFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public AbstractTlsServer(TlsCipherFactory cipherFactory)
|
||||
{
|
||||
this.mCipherFactory = cipherFactory;
|
||||
}
|
||||
|
||||
protected virtual bool AllowEncryptThenMac
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected virtual bool AllowTruncatedHMac
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected virtual IDictionary CheckServerExtensions()
|
||||
{
|
||||
return this.mServerExtensions = TlsExtensionsUtilities.EnsureExtensionsInitialised(this.mServerExtensions);
|
||||
}
|
||||
|
||||
protected abstract int[] GetCipherSuites();
|
||||
|
||||
protected byte[] GetCompressionMethods()
|
||||
{
|
||||
return new byte[] { CompressionMethod.cls_null };
|
||||
}
|
||||
|
||||
protected virtual ProtocolVersion MaximumVersion
|
||||
{
|
||||
get { return ProtocolVersion.TLSv11; }
|
||||
}
|
||||
|
||||
protected virtual ProtocolVersion MinimumVersion
|
||||
{
|
||||
get { return ProtocolVersion.TLSv10; }
|
||||
}
|
||||
|
||||
protected virtual bool SupportsClientEccCapabilities(int[] namedCurves, byte[] ecPointFormats)
|
||||
{
|
||||
// NOTE: BC supports all the current set of point formats so we don't check them here
|
||||
|
||||
if (namedCurves == null)
|
||||
{
|
||||
/*
|
||||
* RFC 4492 4. A client that proposes ECC cipher suites may choose not to include these
|
||||
* extensions. In this case, the server is free to choose any one of the elliptic curves
|
||||
* or point formats [...].
|
||||
*/
|
||||
return TlsEccUtilities.HasAnySupportedNamedCurves();
|
||||
}
|
||||
|
||||
for (int i = 0; i < namedCurves.Length; ++i)
|
||||
{
|
||||
int namedCurve = namedCurves[i];
|
||||
if (NamedCurve.IsValid(namedCurve)
|
||||
&& (!NamedCurve.RefersToASpecificNamedCurve(namedCurve) || TlsEccUtilities.IsSupportedNamedCurve(namedCurve)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void Init(TlsServerContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public virtual void NotifyClientVersion(ProtocolVersion clientVersion)
|
||||
{
|
||||
this.mClientVersion = clientVersion;
|
||||
}
|
||||
|
||||
public virtual void NotifyFallback(bool isFallback)
|
||||
{
|
||||
/*
|
||||
* RFC 7507 3. If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest
|
||||
* protocol version supported by the server is higher than the version indicated in
|
||||
* ClientHello.client_version, the server MUST respond with a fatal inappropriate_fallback
|
||||
* alert [..].
|
||||
*/
|
||||
if (isFallback && MaximumVersion.IsLaterVersionOf(mClientVersion))
|
||||
throw new TlsFatalAlert(AlertDescription.inappropriate_fallback);
|
||||
}
|
||||
|
||||
public virtual void NotifyOfferedCipherSuites(int[] offeredCipherSuites)
|
||||
{
|
||||
this.mOfferedCipherSuites = offeredCipherSuites;
|
||||
this.mEccCipherSuitesOffered = TlsEccUtilities.ContainsEccCipherSuites(this.mOfferedCipherSuites);
|
||||
}
|
||||
|
||||
public virtual void NotifyOfferedCompressionMethods(byte[] offeredCompressionMethods)
|
||||
{
|
||||
this.mOfferedCompressionMethods = offeredCompressionMethods;
|
||||
}
|
||||
|
||||
public virtual void ProcessClientExtensions(IDictionary clientExtensions)
|
||||
{
|
||||
this.mClientExtensions = clientExtensions;
|
||||
|
||||
if (clientExtensions != null)
|
||||
{
|
||||
this.mEncryptThenMacOffered = TlsExtensionsUtilities.HasEncryptThenMacExtension(clientExtensions);
|
||||
|
||||
this.mMaxFragmentLengthOffered = TlsExtensionsUtilities.GetMaxFragmentLengthExtension(clientExtensions);
|
||||
if (mMaxFragmentLengthOffered >= 0 && !MaxFragmentLength.IsValid((byte)mMaxFragmentLengthOffered))
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
|
||||
this.mTruncatedHMacOffered = TlsExtensionsUtilities.HasTruncatedHMacExtension(clientExtensions);
|
||||
|
||||
this.mSupportedSignatureAlgorithms = TlsUtilities.GetSignatureAlgorithmsExtension(clientExtensions);
|
||||
if (this.mSupportedSignatureAlgorithms != null)
|
||||
{
|
||||
/*
|
||||
* RFC 5246 7.4.1.4.1. Note: this extension is not meaningful for TLS versions prior
|
||||
* to 1.2. Clients MUST NOT offer it if they are offering prior versions.
|
||||
*/
|
||||
if (!TlsUtilities.IsSignatureAlgorithmsExtensionAllowed(mClientVersion))
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
}
|
||||
|
||||
this.mNamedCurves = TlsEccUtilities.GetSupportedEllipticCurvesExtension(clientExtensions);
|
||||
this.mClientECPointFormats = TlsEccUtilities.GetSupportedPointFormatsExtension(clientExtensions);
|
||||
}
|
||||
|
||||
/*
|
||||
* RFC 4429 4. The client MUST NOT include these extensions in the ClientHello message if it
|
||||
* does not propose any ECC cipher suites.
|
||||
*
|
||||
* NOTE: This was overly strict as there may be ECC cipher suites that we don't recognize.
|
||||
* Also, draft-ietf-tls-negotiated-ff-dhe will be overloading the 'elliptic_curves'
|
||||
* extension to explicitly allow FFDHE (i.e. non-ECC) groups.
|
||||
*/
|
||||
//if (!this.mEccCipherSuitesOffered && (this.mNamedCurves != null || this.mClientECPointFormats != null))
|
||||
// throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
}
|
||||
|
||||
public virtual ProtocolVersion GetServerVersion()
|
||||
{
|
||||
if (MinimumVersion.IsEqualOrEarlierVersionOf(mClientVersion))
|
||||
{
|
||||
ProtocolVersion maximumVersion = MaximumVersion;
|
||||
if (mClientVersion.IsEqualOrEarlierVersionOf(maximumVersion))
|
||||
{
|
||||
return mServerVersion = mClientVersion;
|
||||
}
|
||||
if (mClientVersion.IsLaterVersionOf(maximumVersion))
|
||||
{
|
||||
return mServerVersion = maximumVersion;
|
||||
}
|
||||
}
|
||||
throw new TlsFatalAlert(AlertDescription.protocol_version);
|
||||
}
|
||||
|
||||
public virtual int GetSelectedCipherSuite()
|
||||
{
|
||||
/*
|
||||
* TODO RFC 5246 7.4.3. In order to negotiate correctly, the server MUST check any candidate
|
||||
* cipher suites against the "signature_algorithms" extension before selecting them. This is
|
||||
* somewhat inelegant but is a compromise designed to minimize changes to the original
|
||||
* cipher suite design.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RFC 4429 5.1. A server that receives a ClientHello containing one or both of these
|
||||
* extensions MUST use the client's enumerated capabilities to guide its selection of an
|
||||
* appropriate cipher suite. One of the proposed ECC cipher suites must be negotiated only
|
||||
* if the server can successfully complete the handshake while using the curves and point
|
||||
* formats supported by the client [...].
|
||||
*/
|
||||
bool eccCipherSuitesEnabled = SupportsClientEccCapabilities(this.mNamedCurves, this.mClientECPointFormats);
|
||||
|
||||
int[] cipherSuites = GetCipherSuites();
|
||||
for (int i = 0; i < cipherSuites.Length; ++i)
|
||||
{
|
||||
int cipherSuite = cipherSuites[i];
|
||||
|
||||
if (Arrays.Contains(this.mOfferedCipherSuites, cipherSuite)
|
||||
&& (eccCipherSuitesEnabled || !TlsEccUtilities.IsEccCipherSuite(cipherSuite))
|
||||
&& TlsUtilities.IsValidCipherSuiteForVersion(cipherSuite, mServerVersion))
|
||||
{
|
||||
return this.mSelectedCipherSuite = cipherSuite;
|
||||
}
|
||||
}
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure);
|
||||
}
|
||||
|
||||
public virtual byte GetSelectedCompressionMethod()
|
||||
{
|
||||
byte[] compressionMethods = GetCompressionMethods();
|
||||
for (int i = 0; i < compressionMethods.Length; ++i)
|
||||
{
|
||||
if (Arrays.Contains(mOfferedCompressionMethods, compressionMethods[i]))
|
||||
{
|
||||
return this.mSelectedCompressionMethod = compressionMethods[i];
|
||||
}
|
||||
}
|
||||
throw new TlsFatalAlert(AlertDescription.handshake_failure);
|
||||
}
|
||||
|
||||
// IDictionary is (Int32 -> byte[])
|
||||
public virtual IDictionary GetServerExtensions()
|
||||
{
|
||||
if (this.mEncryptThenMacOffered && AllowEncryptThenMac)
|
||||
{
|
||||
/*
|
||||
* RFC 7366 3. If a server receives an encrypt-then-MAC request extension from a client
|
||||
* and then selects a stream or Authenticated Encryption with Associated Data (AEAD)
|
||||
* ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the
|
||||
* client.
|
||||
*/
|
||||
if (TlsUtilities.IsBlockCipherSuite(this.mSelectedCipherSuite))
|
||||
{
|
||||
TlsExtensionsUtilities.AddEncryptThenMacExtension(CheckServerExtensions());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mMaxFragmentLengthOffered >= 0
|
||||
&& TlsUtilities.IsValidUint8(mMaxFragmentLengthOffered)
|
||||
&& MaxFragmentLength.IsValid((byte)mMaxFragmentLengthOffered))
|
||||
{
|
||||
TlsExtensionsUtilities.AddMaxFragmentLengthExtension(CheckServerExtensions(), (byte)mMaxFragmentLengthOffered);
|
||||
}
|
||||
|
||||
if (this.mTruncatedHMacOffered && AllowTruncatedHMac)
|
||||
{
|
||||
TlsExtensionsUtilities.AddTruncatedHMacExtension(CheckServerExtensions());
|
||||
}
|
||||
|
||||
if (this.mClientECPointFormats != null && TlsEccUtilities.IsEccCipherSuite(this.mSelectedCipherSuite))
|
||||
{
|
||||
/*
|
||||
* RFC 4492 5.2. A server that selects an ECC cipher suite in response to a ClientHello
|
||||
* message including a Supported Point Formats Extension appends this extension (along
|
||||
* with others) to its ServerHello message, enumerating the point formats it can parse.
|
||||
*/
|
||||
this.mServerECPointFormats = new byte[]{ ECPointFormat.uncompressed,
|
||||
ECPointFormat.ansiX962_compressed_prime, ECPointFormat.ansiX962_compressed_char2, };
|
||||
|
||||
TlsEccUtilities.AddSupportedPointFormatsExtension(CheckServerExtensions(), mServerECPointFormats);
|
||||
}
|
||||
|
||||
return mServerExtensions;
|
||||
}
|
||||
|
||||
public virtual IList GetServerSupplementalData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract TlsCredentials GetCredentials();
|
||||
|
||||
public virtual CertificateStatus GetCertificateStatus()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract TlsKeyExchange GetKeyExchange();
|
||||
|
||||
public virtual CertificateRequest GetCertificateRequest()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void ProcessClientSupplementalData(IList clientSupplementalData)
|
||||
{
|
||||
if (clientSupplementalData != null)
|
||||
throw new TlsFatalAlert(AlertDescription.unexpected_message);
|
||||
}
|
||||
|
||||
public virtual void NotifyClientCertificate(Certificate clientCertificate)
|
||||
{
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
|
||||
public override TlsCompression GetCompression()
|
||||
{
|
||||
switch (mSelectedCompressionMethod)
|
||||
{
|
||||
case CompressionMethod.cls_null:
|
||||
return new TlsNullCompression();
|
||||
|
||||
default:
|
||||
/*
|
||||
* Note: internal error here; we selected the compression method, so if we now can't
|
||||
* produce an implementation, we shouldn't have chosen it!
|
||||
*/
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
public override TlsCipher GetCipher()
|
||||
{
|
||||
int encryptionAlgorithm = TlsUtilities.GetEncryptionAlgorithm(mSelectedCipherSuite);
|
||||
int macAlgorithm = TlsUtilities.GetMacAlgorithm(mSelectedCipherSuite);
|
||||
|
||||
return mCipherFactory.CreateCipher(mContext, encryptionAlgorithm, macAlgorithm);
|
||||
}
|
||||
|
||||
public virtual NewSessionTicket GetNewSessionTicket()
|
||||
{
|
||||
/*
|
||||
* RFC 5077 3.3. If the server determines that it does not want to include a ticket after it
|
||||
* has included the SessionTicket extension in the ServerHello, then it sends a zero-length
|
||||
* ticket in the NewSessionTicket handshake message.
|
||||
*/
|
||||
return new NewSessionTicket(0L, TlsUtilities.EmptyBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de22426aa207445829616d848a2edd5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsSigner
|
||||
: TlsSigner
|
||||
{
|
||||
protected TlsContext mContext;
|
||||
|
||||
public virtual void Init(TlsContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public virtual byte[] GenerateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5AndSha1)
|
||||
{
|
||||
return GenerateRawSignature(null, privateKey, md5AndSha1);
|
||||
}
|
||||
|
||||
public abstract byte[] GenerateRawSignature(SignatureAndHashAlgorithm algorithm,
|
||||
AsymmetricKeyParameter privateKey, byte[] hash);
|
||||
|
||||
public virtual bool VerifyRawSignature(byte[] sigBytes, AsymmetricKeyParameter publicKey, byte[] md5AndSha1)
|
||||
{
|
||||
return VerifyRawSignature(null, sigBytes, publicKey, md5AndSha1);
|
||||
}
|
||||
|
||||
public abstract bool VerifyRawSignature(SignatureAndHashAlgorithm algorithm, byte[] sigBytes,
|
||||
AsymmetricKeyParameter publicKey, byte[] hash);
|
||||
|
||||
public virtual ISigner CreateSigner(AsymmetricKeyParameter privateKey)
|
||||
{
|
||||
return CreateSigner(null, privateKey);
|
||||
}
|
||||
|
||||
public abstract ISigner CreateSigner(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey);
|
||||
|
||||
public virtual ISigner CreateVerifyer(AsymmetricKeyParameter publicKey)
|
||||
{
|
||||
return CreateVerifyer(null, publicKey);
|
||||
}
|
||||
|
||||
public abstract ISigner CreateVerifyer(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter publicKey);
|
||||
|
||||
public abstract bool IsValidPublicKey(AsymmetricKeyParameter publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b0dca569dc274d3fbf9690b7dc9f60c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class AbstractTlsSignerCredentials
|
||||
: AbstractTlsCredentials, TlsSignerCredentials
|
||||
{
|
||||
/// <exception cref="IOException"></exception>
|
||||
public abstract byte[] GenerateCertificateSignature(byte[] hash);
|
||||
|
||||
public virtual SignatureAndHashAlgorithm SignatureAndHashAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new InvalidOperationException("TlsSignerCredentials implementation does not support (D)TLS 1.2+");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 961445811d658435d978e80a1bee94e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
308
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertDescription.cs
Normal file
308
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertDescription.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 5246 7.2
|
||||
/// </summary>
|
||||
public abstract class AlertDescription
|
||||
{
|
||||
/**
|
||||
* This message notifies the recipient that the sender will not send any more messages on this
|
||||
* connection. Note that as of TLS 1.1, failure to properly close a connection no longer
|
||||
* requires that a session not be resumed. This is a change from TLS 1.0 ("The session becomes
|
||||
* unresumable if any connection is terminated without proper close_notify messages with level
|
||||
* equal to warning.") to conform with widespread implementation practice.
|
||||
*/
|
||||
public const byte close_notify = 0;
|
||||
|
||||
/**
|
||||
* An inappropriate message was received. This alert is always fatal and should never be
|
||||
* observed in communication between proper implementations.
|
||||
*/
|
||||
public const byte unexpected_message = 10;
|
||||
|
||||
/**
|
||||
* This alert is returned if a record is received with an incorrect MAC. This alert also MUST be
|
||||
* returned if an alert is sent because a TLSCiphertext decrypted in an invalid way: either it
|
||||
* wasn't an even multiple of the block length, or its padding values, when checked, weren't
|
||||
* correct. This message is always fatal and should never be observed in communication between
|
||||
* proper implementations (except when messages were corrupted in the network).
|
||||
*/
|
||||
public const byte bad_record_mac = 20;
|
||||
|
||||
/**
|
||||
* This alert was used in some earlier versions of TLS, and may have permitted certain attacks
|
||||
* against the CBC mode [CBCATT]. It MUST NOT be sent by compliant implementations.
|
||||
*/
|
||||
public const byte decryption_failed = 21;
|
||||
|
||||
/**
|
||||
* A TLSCiphertext record was received that had a length more than 2^14+2048 bytes, or a record
|
||||
* decrypted to a TLSCompressed record with more than 2^14+1024 bytes. This message is always
|
||||
* fatal and should never be observed in communication between proper implementations (except
|
||||
* when messages were corrupted in the network).
|
||||
*/
|
||||
public const byte record_overflow = 22;
|
||||
|
||||
/**
|
||||
* The decompression function received improper input (e.g., data that would expand to excessive
|
||||
* length). This message is always fatal and should never be observed in communication between
|
||||
* proper implementations.
|
||||
*/
|
||||
public const byte decompression_failure = 30;
|
||||
|
||||
/**
|
||||
* Reception of a handshake_failure alert message indicates that the sender was unable to
|
||||
* negotiate an acceptable set of security parameters given the options available. This is a
|
||||
* fatal error.
|
||||
*/
|
||||
public const byte handshake_failure = 40;
|
||||
|
||||
/**
|
||||
* This alert was used in SSLv3 but not any version of TLS. It MUST NOT be sent by compliant
|
||||
* implementations.
|
||||
*/
|
||||
public const byte no_certificate = 41;
|
||||
|
||||
/**
|
||||
* A certificate was corrupt, contained signatures that did not verify correctly, etc.
|
||||
*/
|
||||
public const byte bad_certificate = 42;
|
||||
|
||||
/**
|
||||
* A certificate was of an unsupported type.
|
||||
*/
|
||||
public const byte unsupported_certificate = 43;
|
||||
|
||||
/**
|
||||
* A certificate was revoked by its signer.
|
||||
*/
|
||||
public const byte certificate_revoked = 44;
|
||||
|
||||
/**
|
||||
* A certificate has expired or is not currently valid.
|
||||
*/
|
||||
public const byte certificate_expired = 45;
|
||||
|
||||
/**
|
||||
* Some other (unspecified) issue arose in processing the certificate, rendering it
|
||||
* unacceptable.
|
||||
*/
|
||||
public const byte certificate_unknown = 46;
|
||||
|
||||
/**
|
||||
* A field in the handshake was out of range or inconsistent with other fields. This message is
|
||||
* always fatal.
|
||||
*/
|
||||
public const byte illegal_parameter = 47;
|
||||
|
||||
/**
|
||||
* A valid certificate chain or partial chain was received, but the certificate was not accepted
|
||||
* because the CA certificate could not be located or couldn't be matched with a known, trusted
|
||||
* CA. This message is always fatal.
|
||||
*/
|
||||
public const byte unknown_ca = 48;
|
||||
|
||||
/**
|
||||
* A valid certificate was received, but when access control was applied, the sender decided not
|
||||
* to proceed with negotiation. This message is always fatal.
|
||||
*/
|
||||
public const byte access_denied = 49;
|
||||
|
||||
/**
|
||||
* A message could not be decoded because some field was out of the specified range or the
|
||||
* length of the message was incorrect. This message is always fatal and should never be
|
||||
* observed in communication between proper implementations (except when messages were corrupted
|
||||
* in the network).
|
||||
*/
|
||||
public const byte decode_error = 50;
|
||||
|
||||
/**
|
||||
* A handshake cryptographic operation failed, including being unable to correctly verify a
|
||||
* signature or validate a Finished message. This message is always fatal.
|
||||
*/
|
||||
public const byte decrypt_error = 51;
|
||||
|
||||
/**
|
||||
* This alert was used in some earlier versions of TLS. It MUST NOT be sent by compliant
|
||||
* implementations.
|
||||
*/
|
||||
public const byte export_restriction = 60;
|
||||
|
||||
/**
|
||||
* The protocol version the client has attempted to negotiate is recognized but not supported.
|
||||
* (For example, old protocol versions might be avoided for security reasons.) This message is
|
||||
* always fatal.
|
||||
*/
|
||||
public const byte protocol_version = 70;
|
||||
|
||||
/**
|
||||
* Returned instead of handshake_failure when a negotiation has failed specifically because the
|
||||
* server requires ciphers more secure than those supported by the client. This message is
|
||||
* always fatal.
|
||||
*/
|
||||
public const byte insufficient_security = 71;
|
||||
|
||||
/**
|
||||
* An internal error unrelated to the peer or the correctness of the protocol (such as a memory
|
||||
* allocation failure) makes it impossible to continue. This message is always fatal.
|
||||
*/
|
||||
public const byte internal_error = 80;
|
||||
|
||||
/**
|
||||
* This handshake is being canceled for some reason unrelated to a protocol failure. If the user
|
||||
* cancels an operation after the handshake is complete, just closing the connection by sending
|
||||
* a close_notify is more appropriate. This alert should be followed by a close_notify. This
|
||||
* message is generally a warning.
|
||||
*/
|
||||
public const byte user_canceled = 90;
|
||||
|
||||
/**
|
||||
* Sent by the client in response to a hello request or by the server in response to a client
|
||||
* hello after initial handshaking. Either of these would normally lead to renegotiation; when
|
||||
* that is not appropriate, the recipient should respond with this alert. At that point, the
|
||||
* original requester can decide whether to proceed with the connection. One case where this
|
||||
* would be appropriate is where a server has spawned a process to satisfy a request; the
|
||||
* process might receive security parameters (key length, authentication, etc.) at startup, and
|
||||
* it might be difficult to communicate changes to these parameters after that point. This
|
||||
* message is always a warning.
|
||||
*/
|
||||
public const byte no_renegotiation = 100;
|
||||
|
||||
/**
|
||||
* Sent by clients that receive an extended server hello containing an extension that they did
|
||||
* not put in the corresponding client hello. This message is always fatal.
|
||||
*/
|
||||
public const byte unsupported_extension = 110;
|
||||
|
||||
/*
|
||||
* RFC 3546
|
||||
*/
|
||||
|
||||
/**
|
||||
* This alert is sent by servers who are unable to retrieve a certificate chain from the URL
|
||||
* supplied by the client (see Section 3.3). This message MAY be fatal - for example if client
|
||||
* authentication is required by the server for the handshake to continue and the server is
|
||||
* unable to retrieve the certificate chain, it may send a fatal alert.
|
||||
*/
|
||||
public const byte certificate_unobtainable = 111;
|
||||
|
||||
/**
|
||||
* This alert is sent by servers that receive a server_name extension request, but do not
|
||||
* recognize the server name. This message MAY be fatal.
|
||||
*/
|
||||
public const byte unrecognized_name = 112;
|
||||
|
||||
/**
|
||||
* This alert is sent by clients that receive an invalid certificate status response (see
|
||||
* Section 3.6). This message is always fatal.
|
||||
*/
|
||||
public const byte bad_certificate_status_response = 113;
|
||||
|
||||
/**
|
||||
* This alert is sent by servers when a certificate hash does not match a client provided
|
||||
* certificate_hash. This message is always fatal.
|
||||
*/
|
||||
public const byte bad_certificate_hash_value = 114;
|
||||
|
||||
/*
|
||||
* RFC 4279
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the server does not recognize the PSK identity, it MAY respond with an
|
||||
* "unknown_psk_identity" alert message.
|
||||
*/
|
||||
public const byte unknown_psk_identity = 115;
|
||||
|
||||
/*
|
||||
* RFC 7507
|
||||
*/
|
||||
|
||||
/**
|
||||
* If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest protocol version
|
||||
* supported by the server is higher than the version indicated in ClientHello.client_version,
|
||||
* the server MUST respond with a fatal inappropriate_fallback alert [..].
|
||||
*/
|
||||
public const byte inappropriate_fallback = 86;
|
||||
|
||||
public static string GetName(byte alertDescription)
|
||||
{
|
||||
switch (alertDescription)
|
||||
{
|
||||
case close_notify:
|
||||
return "close_notify";
|
||||
case unexpected_message:
|
||||
return "unexpected_message";
|
||||
case bad_record_mac:
|
||||
return "bad_record_mac";
|
||||
case decryption_failed:
|
||||
return "decryption_failed";
|
||||
case record_overflow:
|
||||
return "record_overflow";
|
||||
case decompression_failure:
|
||||
return "decompression_failure";
|
||||
case handshake_failure:
|
||||
return "handshake_failure";
|
||||
case no_certificate:
|
||||
return "no_certificate";
|
||||
case bad_certificate:
|
||||
return "bad_certificate";
|
||||
case unsupported_certificate:
|
||||
return "unsupported_certificate";
|
||||
case certificate_revoked:
|
||||
return "certificate_revoked";
|
||||
case certificate_expired:
|
||||
return "certificate_expired";
|
||||
case certificate_unknown:
|
||||
return "certificate_unknown";
|
||||
case illegal_parameter:
|
||||
return "illegal_parameter";
|
||||
case unknown_ca:
|
||||
return "unknown_ca";
|
||||
case access_denied:
|
||||
return "access_denied";
|
||||
case decode_error:
|
||||
return "decode_error";
|
||||
case decrypt_error:
|
||||
return "decrypt_error";
|
||||
case export_restriction:
|
||||
return "export_restriction";
|
||||
case protocol_version:
|
||||
return "protocol_version";
|
||||
case insufficient_security:
|
||||
return "insufficient_security";
|
||||
case internal_error:
|
||||
return "internal_error";
|
||||
case user_canceled:
|
||||
return "user_canceled";
|
||||
case no_renegotiation:
|
||||
return "no_renegotiation";
|
||||
case unsupported_extension:
|
||||
return "unsupported_extension";
|
||||
case certificate_unobtainable:
|
||||
return "certificate_unobtainable";
|
||||
case unrecognized_name:
|
||||
return "unrecognized_name";
|
||||
case bad_certificate_status_response:
|
||||
return "bad_certificate_status_response";
|
||||
case bad_certificate_hash_value:
|
||||
return "bad_certificate_hash_value";
|
||||
case unknown_psk_identity:
|
||||
return "unknown_psk_identity";
|
||||
case inappropriate_fallback:
|
||||
return "inappropriate_fallback";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetText(byte alertDescription)
|
||||
{
|
||||
return GetName(alertDescription) + "(" + alertDescription + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c56f91b15a6834bee9f511c98eb824d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertLevel.cs
Normal file
33
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertLevel.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 5246 7.2
|
||||
/// </summary>
|
||||
public abstract class AlertLevel
|
||||
{
|
||||
public const byte warning = 1;
|
||||
public const byte fatal = 2;
|
||||
|
||||
public static string GetName(byte alertDescription)
|
||||
{
|
||||
switch (alertDescription)
|
||||
{
|
||||
case warning:
|
||||
return "warning";
|
||||
case fatal:
|
||||
return "fatal";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetText(byte alertDescription)
|
||||
{
|
||||
return GetName(alertDescription) + "(" + alertDescription + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertLevel.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/crypto/tls/AlertLevel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2aadbd0a8d2e42beaceda103a0601a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <remarks>
|
||||
/// A certificate verifyer, that will always return true.
|
||||
/// <pre>
|
||||
/// DO NOT USE THIS FILE UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING.
|
||||
/// </pre>
|
||||
/// </remarks>
|
||||
//[Obsolete("Perform certificate verification in TlsAuthentication implementation")]
|
||||
public class AlwaysValidVerifyer : ICertificateVerifyer
|
||||
{
|
||||
/// <summary>Return true.</summary>
|
||||
public bool IsValid(Uri targetUri, X509CertificateStructure[] certs)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f2684ae8d19f49ab9cc0cc8190ce337
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
151
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueue.cs
Normal file
151
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueue.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <remarks>
|
||||
/// A queue for bytes.
|
||||
/// <p>
|
||||
/// This file could be more optimized.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
public class ByteQueue
|
||||
{
|
||||
/// <returns>The smallest number which can be written as 2^x which is bigger than i.</returns>
|
||||
public static int NextTwoPow(
|
||||
int i)
|
||||
{
|
||||
/*
|
||||
* This code is based of a lot of code I found on the Internet
|
||||
* which mostly referenced a book called "Hacking delight".
|
||||
*
|
||||
*/
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initial size for our buffer.
|
||||
*/
|
||||
private const int DefaultCapacity = 1024;
|
||||
|
||||
/**
|
||||
* The buffer where we store our data.
|
||||
*/
|
||||
private byte[] databuf;
|
||||
|
||||
/**
|
||||
* How many bytes at the beginning of the buffer are skipped.
|
||||
*/
|
||||
private int skipped = 0;
|
||||
|
||||
/**
|
||||
* How many bytes in the buffer are valid data.
|
||||
*/
|
||||
private int available = 0;
|
||||
|
||||
public ByteQueue()
|
||||
: this(DefaultCapacity)
|
||||
{
|
||||
}
|
||||
|
||||
public ByteQueue(int capacity)
|
||||
{
|
||||
this.databuf = new byte[capacity];
|
||||
}
|
||||
|
||||
/// <summary>Read data from the buffer.</summary>
|
||||
/// <param name="buf">The buffer where the read data will be copied to.</param>
|
||||
/// <param name="offset">How many bytes to skip at the beginning of buf.</param>
|
||||
/// <param name="len">How many bytes to read at all.</param>
|
||||
/// <param name="skip">How many bytes from our data to skip.</param>
|
||||
public void Read(
|
||||
byte[] buf,
|
||||
int offset,
|
||||
int len,
|
||||
int skip)
|
||||
{
|
||||
if ((buf.Length - offset) < len)
|
||||
{
|
||||
throw new ArgumentException("Buffer size of " + buf.Length + " is too small for a read of " + len + " bytes");
|
||||
}
|
||||
if ((available - skip) < len)
|
||||
{
|
||||
throw new InvalidOperationException("Not enough data to read");
|
||||
}
|
||||
Array.Copy(databuf, skipped + skip, buf, offset, len);
|
||||
}
|
||||
|
||||
/// <summary>Add some data to our buffer.</summary>
|
||||
/// <param name="data">A byte-array to read data from.</param>
|
||||
/// <param name="offset">How many bytes to skip at the beginning of the array.</param>
|
||||
/// <param name="len">How many bytes to read from the array.</param>
|
||||
public void AddData(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int len)
|
||||
{
|
||||
if ((skipped + available + len) > databuf.Length)
|
||||
{
|
||||
int desiredSize = ByteQueue.NextTwoPow(available + len);
|
||||
if (desiredSize > databuf.Length)
|
||||
{
|
||||
byte[] tmp = new byte[desiredSize];
|
||||
Array.Copy(databuf, skipped, tmp, 0, available);
|
||||
databuf = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(databuf, skipped, databuf, 0, available);
|
||||
}
|
||||
skipped = 0;
|
||||
}
|
||||
|
||||
Array.Copy(data, offset, databuf, skipped + available, len);
|
||||
available += len;
|
||||
}
|
||||
|
||||
/// <summary>Remove some bytes from our data from the beginning.</summary>
|
||||
/// <param name="i">How many bytes to remove.</param>
|
||||
public void RemoveData(
|
||||
int i)
|
||||
{
|
||||
if (i > available)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot remove " + i + " bytes, only got " + available);
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip the data.
|
||||
*/
|
||||
available -= i;
|
||||
skipped += i;
|
||||
}
|
||||
|
||||
public void RemoveData(byte[] buf, int off, int len, int skip)
|
||||
{
|
||||
Read(buf, off, len, skip);
|
||||
RemoveData(skip + len);
|
||||
}
|
||||
|
||||
public byte[] RemoveData(int len, int skip)
|
||||
{
|
||||
byte[] buf = new byte[len];
|
||||
RemoveData(buf, 0, len, skip);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/// <summary>The number of bytes which are available in this buffer.</summary>
|
||||
public int Available
|
||||
{
|
||||
get { return available; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueue.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueue.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3c98e4e716034a3c9a448dff320c107
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
114
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueueStream.cs
Normal file
114
Assets/BestHTTP/SecureProtocol/crypto/tls/ByteQueueStream.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class ByteQueueStream
|
||||
: Stream
|
||||
{
|
||||
private readonly ByteQueue buffer;
|
||||
|
||||
public ByteQueueStream()
|
||||
{
|
||||
this.buffer = new ByteQueue();
|
||||
}
|
||||
|
||||
public virtual int Available
|
||||
{
|
||||
get { return buffer.Available; }
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public virtual int Peek(byte[] buf)
|
||||
{
|
||||
int bytesToRead = System.Math.Min(buffer.Available, buf.Length);
|
||||
buffer.Read(buf, 0, bytesToRead, 0);
|
||||
return bytesToRead;
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public virtual int Read(byte[] buf)
|
||||
{
|
||||
return Read(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public override int Read(byte[] buf, int off, int len)
|
||||
{
|
||||
int bytesToRead = System.Math.Min(buffer.Available, len);
|
||||
buffer.RemoveData(buf, off, bytesToRead, 0);
|
||||
return bytesToRead;
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (buffer.Available == 0)
|
||||
return -1;
|
||||
|
||||
return buffer.RemoveData(1, 0)[0] & 0xFF;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public virtual int Skip(int n)
|
||||
{
|
||||
int bytesToSkip = System.Math.Min(buffer.Available, n);
|
||||
buffer.RemoveData(bytesToSkip);
|
||||
return bytesToSkip;
|
||||
}
|
||||
|
||||
public virtual void Write(byte[] buf)
|
||||
{
|
||||
buffer.AddData(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buf, int off, int len)
|
||||
{
|
||||
buffer.AddData(buf, off, len);
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b)
|
||||
{
|
||||
buffer.AddData(new byte[]{ b }, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04b40f17515ef4fdca82e86b0ccc03d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/BestHTTP/SecureProtocol/crypto/tls/CertChainType.cs
Normal file
22
Assets/BestHTTP/SecureProtocol/crypto/tls/CertChainType.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/*
|
||||
* RFC 3546 3.3.
|
||||
*/
|
||||
public abstract class CertChainType
|
||||
{
|
||||
public const byte individual_certs = 0;
|
||||
public const byte pkipath = 1;
|
||||
|
||||
public static bool IsValid(byte certChainType)
|
||||
{
|
||||
return certChainType >= individual_certs && certChainType <= pkipath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4f1bb998a6a64f669c95f04f3bc99b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
140
Assets/BestHTTP/SecureProtocol/crypto/tls/Certificate.cs
Normal file
140
Assets/BestHTTP/SecureProtocol/crypto/tls/Certificate.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Asn1;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* Parsing and encoding of a <i>Certificate</i> struct from RFC 4346.
|
||||
* <p/>
|
||||
* <pre>
|
||||
* opaque ASN.1Cert<2^24-1>;
|
||||
*
|
||||
* struct {
|
||||
* ASN.1Cert certificate_list<0..2^24-1>;
|
||||
* } Certificate;
|
||||
* </pre>
|
||||
*
|
||||
* @see Org.BouncyCastle.Asn1.X509.X509CertificateStructure
|
||||
*/
|
||||
public class Certificate
|
||||
{
|
||||
public static readonly Certificate EmptyChain = new Certificate(new X509CertificateStructure[0]);
|
||||
|
||||
/**
|
||||
* The certificates.
|
||||
*/
|
||||
protected readonly X509CertificateStructure[] mCertificateList;
|
||||
|
||||
public Certificate(X509CertificateStructure[] certificateList)
|
||||
{
|
||||
if (certificateList == null)
|
||||
throw new ArgumentNullException("certificateList");
|
||||
|
||||
this.mCertificateList = certificateList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of {@link org.bouncycastle.asn1.x509.Certificate} representing a certificate
|
||||
* chain.
|
||||
*/
|
||||
public virtual X509CertificateStructure[] GetCertificateList()
|
||||
{
|
||||
return CloneCertificateList();
|
||||
}
|
||||
|
||||
public virtual X509CertificateStructure GetCertificateAt(int index)
|
||||
{
|
||||
return mCertificateList[index];
|
||||
}
|
||||
|
||||
public virtual int Length
|
||||
{
|
||||
get { return mCertificateList.Length; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this certificate chain contains no certificates, or
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public virtual bool IsEmpty
|
||||
{
|
||||
get { return mCertificateList.Length == 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link Certificate} to a {@link Stream}.
|
||||
*
|
||||
* @param output the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
IList derEncodings = Platform.CreateArrayList(mCertificateList.Length);
|
||||
|
||||
int totalLength = 0;
|
||||
foreach (Asn1Encodable asn1Cert in mCertificateList)
|
||||
{
|
||||
byte[] derEncoding = asn1Cert.GetEncoded(Asn1Encodable.Der);
|
||||
derEncodings.Add(derEncoding);
|
||||
totalLength += derEncoding.Length + 3;
|
||||
}
|
||||
|
||||
TlsUtilities.CheckUint24(totalLength);
|
||||
TlsUtilities.WriteUint24(totalLength, output);
|
||||
|
||||
foreach (byte[] derEncoding in derEncodings)
|
||||
{
|
||||
TlsUtilities.WriteOpaque24(derEncoding, output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link Certificate} from a {@link Stream}.
|
||||
*
|
||||
* @param input the {@link Stream} to parse from.
|
||||
* @return a {@link Certificate} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Certificate Parse(Stream input)
|
||||
{
|
||||
int totalLength = TlsUtilities.ReadUint24(input);
|
||||
if (totalLength == 0)
|
||||
{
|
||||
return EmptyChain;
|
||||
}
|
||||
|
||||
byte[] certListData = TlsUtilities.ReadFully(totalLength, input);
|
||||
|
||||
MemoryStream buf = new MemoryStream(certListData, false);
|
||||
|
||||
IList certificate_list = Platform.CreateArrayList();
|
||||
while (buf.Position < buf.Length)
|
||||
{
|
||||
byte[] derEncoding = TlsUtilities.ReadOpaque24(buf);
|
||||
Asn1Object asn1Cert = TlsUtilities.ReadDerObject(derEncoding);
|
||||
certificate_list.Add(X509CertificateStructure.GetInstance(asn1Cert));
|
||||
}
|
||||
|
||||
X509CertificateStructure[] certificateList = new X509CertificateStructure[certificate_list.Count];
|
||||
for (int i = 0; i < certificate_list.Count; ++i)
|
||||
{
|
||||
certificateList[i] = (X509CertificateStructure)certificate_list[i];
|
||||
}
|
||||
return new Certificate(certificateList);
|
||||
}
|
||||
|
||||
protected virtual X509CertificateStructure[] CloneCertificateList()
|
||||
{
|
||||
return (X509CertificateStructure[])mCertificateList.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a78dd1997226e4ec0830e3c1089905d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
160
Assets/BestHTTP/SecureProtocol/crypto/tls/CertificateRequest.cs
Normal file
160
Assets/BestHTTP/SecureProtocol/crypto/tls/CertificateRequest.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Asn1;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* Parsing and encoding of a <i>CertificateRequest</i> struct from RFC 4346.
|
||||
* <p/>
|
||||
* <pre>
|
||||
* struct {
|
||||
* ClientCertificateType certificate_types<1..2^8-1>;
|
||||
* DistinguishedName certificate_authorities<3..2^16-1>
|
||||
* } CertificateRequest;
|
||||
* </pre>
|
||||
*
|
||||
* @see ClientCertificateType
|
||||
* @see X509Name
|
||||
*/
|
||||
public class CertificateRequest
|
||||
{
|
||||
protected readonly byte[] mCertificateTypes;
|
||||
protected readonly IList mSupportedSignatureAlgorithms;
|
||||
protected readonly IList mCertificateAuthorities;
|
||||
|
||||
/**
|
||||
* @param certificateTypes see {@link ClientCertificateType} for valid constants.
|
||||
* @param certificateAuthorities an {@link IList} of {@link X509Name}.
|
||||
*/
|
||||
public CertificateRequest(byte[] certificateTypes, IList supportedSignatureAlgorithms,
|
||||
IList certificateAuthorities)
|
||||
{
|
||||
this.mCertificateTypes = certificateTypes;
|
||||
this.mSupportedSignatureAlgorithms = supportedSignatureAlgorithms;
|
||||
this.mCertificateAuthorities = certificateAuthorities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of certificate types
|
||||
* @see {@link ClientCertificateType}
|
||||
*/
|
||||
public virtual byte[] CertificateTypes
|
||||
{
|
||||
get { return mCertificateTypes; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an {@link IList} of {@link SignatureAndHashAlgorithm} (or null before TLS 1.2).
|
||||
*/
|
||||
public virtual IList SupportedSignatureAlgorithms
|
||||
{
|
||||
get { return mSupportedSignatureAlgorithms; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an {@link IList} of {@link X509Name}
|
||||
*/
|
||||
public virtual IList CertificateAuthorities
|
||||
{
|
||||
get { return mCertificateAuthorities; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link CertificateRequest} to a {@link Stream}.
|
||||
*
|
||||
* @param output the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
if (mCertificateTypes == null || mCertificateTypes.Length == 0)
|
||||
{
|
||||
TlsUtilities.WriteUint8(0, output);
|
||||
}
|
||||
else
|
||||
{
|
||||
TlsUtilities.WriteUint8ArrayWithUint8Length(mCertificateTypes, output);
|
||||
}
|
||||
|
||||
if (mSupportedSignatureAlgorithms != null)
|
||||
{
|
||||
// TODO Check whether SignatureAlgorithm.anonymous is allowed here
|
||||
TlsUtilities.EncodeSupportedSignatureAlgorithms(mSupportedSignatureAlgorithms, false, output);
|
||||
}
|
||||
|
||||
if (mCertificateAuthorities == null || mCertificateAuthorities.Count < 1)
|
||||
{
|
||||
TlsUtilities.WriteUint16(0, output);
|
||||
}
|
||||
else
|
||||
{
|
||||
IList derEncodings = Platform.CreateArrayList(mCertificateAuthorities.Count);
|
||||
|
||||
int totalLength = 0;
|
||||
foreach (Asn1Encodable certificateAuthority in mCertificateAuthorities)
|
||||
{
|
||||
byte[] derEncoding = certificateAuthority.GetEncoded(Asn1Encodable.Der);
|
||||
derEncodings.Add(derEncoding);
|
||||
totalLength += derEncoding.Length + 2;
|
||||
}
|
||||
|
||||
TlsUtilities.CheckUint16(totalLength);
|
||||
TlsUtilities.WriteUint16(totalLength, output);
|
||||
|
||||
foreach (byte[] derEncoding in derEncodings)
|
||||
{
|
||||
TlsUtilities.WriteOpaque16(derEncoding, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link CertificateRequest} from a {@link Stream}.
|
||||
*
|
||||
* @param context
|
||||
* the {@link TlsContext} of the current connection.
|
||||
* @param input
|
||||
* the {@link Stream} to parse from.
|
||||
* @return a {@link CertificateRequest} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static CertificateRequest Parse(TlsContext context, Stream input)
|
||||
{
|
||||
int numTypes = TlsUtilities.ReadUint8(input);
|
||||
byte[] certificateTypes = new byte[numTypes];
|
||||
for (int i = 0; i < numTypes; ++i)
|
||||
{
|
||||
certificateTypes[i] = TlsUtilities.ReadUint8(input);
|
||||
}
|
||||
|
||||
IList supportedSignatureAlgorithms = null;
|
||||
if (TlsUtilities.IsTlsV12(context))
|
||||
{
|
||||
// TODO Check whether SignatureAlgorithm.anonymous is allowed here
|
||||
supportedSignatureAlgorithms = TlsUtilities.ParseSupportedSignatureAlgorithms(false, input);
|
||||
}
|
||||
|
||||
IList certificateAuthorities = Platform.CreateArrayList();
|
||||
byte[] certAuthData = TlsUtilities.ReadOpaque16(input);
|
||||
MemoryStream bis = new MemoryStream(certAuthData, false);
|
||||
while (bis.Position < bis.Length)
|
||||
{
|
||||
byte[] derEncoding = TlsUtilities.ReadOpaque16(bis);
|
||||
Asn1Object asn1 = TlsUtilities.ReadDerObject(derEncoding);
|
||||
// TODO Switch to X500Name when available
|
||||
certificateAuthorities.Add(X509Name.GetInstance(asn1));
|
||||
}
|
||||
|
||||
return new CertificateRequest(certificateTypes, supportedSignatureAlgorithms, certificateAuthorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8339c5c4c757b438bab6c5e30bff4448
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Assets/BestHTTP/SecureProtocol/crypto/tls/CertificateStatus.cs
Normal file
106
Assets/BestHTTP/SecureProtocol/crypto/tls/CertificateStatus.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Asn1;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class CertificateStatus
|
||||
{
|
||||
protected readonly byte mStatusType;
|
||||
protected readonly object mResponse;
|
||||
|
||||
public CertificateStatus(byte statusType, object response)
|
||||
{
|
||||
if (!IsCorrectType(statusType, response))
|
||||
throw new ArgumentException("not an instance of the correct type", "response");
|
||||
|
||||
this.mStatusType = statusType;
|
||||
this.mResponse = response;
|
||||
}
|
||||
|
||||
public virtual byte StatusType
|
||||
{
|
||||
get { return mStatusType; }
|
||||
}
|
||||
|
||||
public virtual object Response
|
||||
{
|
||||
get { return mResponse; }
|
||||
}
|
||||
|
||||
public virtual OcspResponse GetOcspResponse()
|
||||
{
|
||||
if (!IsCorrectType(CertificateStatusType.ocsp, mResponse))
|
||||
throw new InvalidOperationException("'response' is not an OcspResponse");
|
||||
|
||||
return (OcspResponse)mResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link CertificateStatus} to a {@link Stream}.
|
||||
*
|
||||
* @param output
|
||||
* the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
TlsUtilities.WriteUint8(mStatusType, output);
|
||||
|
||||
switch (mStatusType)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
byte[] derEncoding = ((OcspResponse)mResponse).GetEncoded(Asn1Encodable.Der);
|
||||
TlsUtilities.WriteOpaque24(derEncoding, output);
|
||||
break;
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link CertificateStatus} from a {@link Stream}.
|
||||
*
|
||||
* @param input
|
||||
* the {@link Stream} to parse from.
|
||||
* @return a {@link CertificateStatus} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static CertificateStatus Parse(Stream input)
|
||||
{
|
||||
byte status_type = TlsUtilities.ReadUint8(input);
|
||||
object response;
|
||||
|
||||
switch (status_type)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
{
|
||||
byte[] derEncoding = TlsUtilities.ReadOpaque24(input);
|
||||
response = OcspResponse.GetInstance(TlsUtilities.ReadDerObject(derEncoding));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.decode_error);
|
||||
}
|
||||
|
||||
return new CertificateStatus(status_type, response);
|
||||
}
|
||||
|
||||
protected static bool IsCorrectType(byte statusType, object response)
|
||||
{
|
||||
switch (statusType)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
return response is OcspResponse;
|
||||
default:
|
||||
throw new ArgumentException("unsupported value", "statusType");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e8cf24db2f345c9bc0857a76debc23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class CertificateStatusRequest
|
||||
{
|
||||
protected readonly byte mStatusType;
|
||||
protected readonly object mRequest;
|
||||
|
||||
public CertificateStatusRequest(byte statusType, Object request)
|
||||
{
|
||||
if (!IsCorrectType(statusType, request))
|
||||
throw new ArgumentException("not an instance of the correct type", "request");
|
||||
|
||||
this.mStatusType = statusType;
|
||||
this.mRequest = request;
|
||||
}
|
||||
|
||||
public virtual byte StatusType
|
||||
{
|
||||
get { return mStatusType; }
|
||||
}
|
||||
|
||||
public virtual object Request
|
||||
{
|
||||
get { return mRequest; }
|
||||
}
|
||||
|
||||
public virtual OcspStatusRequest GetOcspStatusRequest()
|
||||
{
|
||||
if (!IsCorrectType(CertificateStatusType.ocsp, mRequest))
|
||||
throw new InvalidOperationException("'request' is not an OCSPStatusRequest");
|
||||
|
||||
return (OcspStatusRequest)mRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link CertificateStatusRequest} to a {@link Stream}.
|
||||
*
|
||||
* @param output
|
||||
* the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
TlsUtilities.WriteUint8(mStatusType, output);
|
||||
|
||||
switch (mStatusType)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
((OcspStatusRequest)mRequest).Encode(output);
|
||||
break;
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link CertificateStatusRequest} from a {@link Stream}.
|
||||
*
|
||||
* @param input
|
||||
* the {@link Stream} to parse from.
|
||||
* @return a {@link CertificateStatusRequest} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static CertificateStatusRequest Parse(Stream input)
|
||||
{
|
||||
byte status_type = TlsUtilities.ReadUint8(input);
|
||||
object result;
|
||||
|
||||
switch (status_type)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
result = OcspStatusRequest.Parse(input);
|
||||
break;
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.decode_error);
|
||||
}
|
||||
|
||||
return new CertificateStatusRequest(status_type, result);
|
||||
}
|
||||
|
||||
protected static bool IsCorrectType(byte statusType, object request)
|
||||
{
|
||||
switch (statusType)
|
||||
{
|
||||
case CertificateStatusType.ocsp:
|
||||
return request is OcspStatusRequest;
|
||||
default:
|
||||
throw new ArgumentException("unsupported value", "statusType");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 912031f032b064845b1aee6c40814680
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class CertificateStatusType
|
||||
{
|
||||
/*
|
||||
* RFC 3546 3.6
|
||||
*/
|
||||
public const byte ocsp = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c95a0c9a09e16446c8b9092efc2ebdd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
203
Assets/BestHTTP/SecureProtocol/crypto/tls/Chacha20Poly1305.cs
Normal file
203
Assets/BestHTTP/SecureProtocol/crypto/tls/Chacha20Poly1305.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Macs;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Org.BouncyCastle.Crypto.Utilities;
|
||||
using Org.BouncyCastle.Security;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* draft-ietf-tls-chacha20-poly1305-04
|
||||
*/
|
||||
public class Chacha20Poly1305
|
||||
: TlsCipher
|
||||
{
|
||||
private static readonly byte[] Zeroes = new byte[15];
|
||||
|
||||
protected readonly TlsContext context;
|
||||
|
||||
protected readonly ChaCha7539Engine encryptCipher, decryptCipher;
|
||||
protected readonly byte[] encryptIV, decryptIV;
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
public Chacha20Poly1305(TlsContext context)
|
||||
{
|
||||
if (!TlsUtilities.IsTlsV12(context))
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
|
||||
this.context = context;
|
||||
|
||||
int cipherKeySize = 32;
|
||||
// TODO SecurityParameters.fixed_iv_length
|
||||
int fixed_iv_length = 12;
|
||||
// TODO SecurityParameters.record_iv_length = 0
|
||||
|
||||
int key_block_size = (2 * cipherKeySize) + (2 * fixed_iv_length);
|
||||
|
||||
byte[] key_block = TlsUtilities.CalculateKeyBlock(context, key_block_size);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize);
|
||||
offset += cipherKeySize;
|
||||
KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize);
|
||||
offset += cipherKeySize;
|
||||
byte[] client_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
|
||||
offset += fixed_iv_length;
|
||||
byte[] server_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
|
||||
offset += fixed_iv_length;
|
||||
|
||||
if (offset != key_block_size)
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
|
||||
this.encryptCipher = new ChaCha7539Engine();
|
||||
this.decryptCipher = new ChaCha7539Engine();
|
||||
|
||||
KeyParameter encryptKey, decryptKey;
|
||||
if (context.IsServer)
|
||||
{
|
||||
encryptKey = server_write_key;
|
||||
decryptKey = client_write_key;
|
||||
this.encryptIV = server_write_IV;
|
||||
this.decryptIV = client_write_IV;
|
||||
}
|
||||
else
|
||||
{
|
||||
encryptKey = client_write_key;
|
||||
decryptKey = server_write_key;
|
||||
this.encryptIV = client_write_IV;
|
||||
this.decryptIV = server_write_IV;
|
||||
}
|
||||
|
||||
this.encryptCipher.Init(true, new ParametersWithIV(encryptKey, encryptIV));
|
||||
this.decryptCipher.Init(false, new ParametersWithIV(decryptKey, decryptIV));
|
||||
}
|
||||
|
||||
public virtual int GetPlaintextLimit(int ciphertextLimit)
|
||||
{
|
||||
return ciphertextLimit - 16;
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
public virtual byte[] EncodePlaintext(long seqNo, byte type, byte[] plaintext, int offset, int len)
|
||||
{
|
||||
KeyParameter macKey = InitRecord(encryptCipher, true, seqNo, encryptIV);
|
||||
|
||||
byte[] output = new byte[len + 16];
|
||||
encryptCipher.ProcessBytes(plaintext, offset, len, output, 0);
|
||||
|
||||
byte[] additionalData = GetAdditionalData(seqNo, type, len);
|
||||
byte[] mac = CalculateRecordMac(macKey, additionalData, output, 0, len);
|
||||
Array.Copy(mac, 0, output, len, mac.Length);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
public virtual byte[] DecodeCiphertext(long seqNo, byte type, byte[] ciphertext, int offset, int len)
|
||||
{
|
||||
if (GetPlaintextLimit(len) < 0)
|
||||
throw new TlsFatalAlert(AlertDescription.decode_error);
|
||||
|
||||
KeyParameter macKey = InitRecord(decryptCipher, false, seqNo, decryptIV);
|
||||
|
||||
int plaintextLength = len - 16;
|
||||
|
||||
byte[] additionalData = GetAdditionalData(seqNo, type, plaintextLength);
|
||||
byte[] calculatedMac = CalculateRecordMac(macKey, additionalData, ciphertext, offset, plaintextLength);
|
||||
byte[] receivedMac = Arrays.CopyOfRange(ciphertext, offset + plaintextLength, offset + len);
|
||||
|
||||
if (!Arrays.ConstantTimeAreEqual(calculatedMac, receivedMac))
|
||||
throw new TlsFatalAlert(AlertDescription.bad_record_mac);
|
||||
|
||||
byte[] output = new byte[plaintextLength];
|
||||
decryptCipher.ProcessBytes(ciphertext, offset, plaintextLength, output, 0);
|
||||
return output;
|
||||
}
|
||||
|
||||
protected virtual KeyParameter InitRecord(IStreamCipher cipher, bool forEncryption, long seqNo, byte[] iv)
|
||||
{
|
||||
byte[] nonce = CalculateNonce(seqNo, iv);
|
||||
cipher.Init(forEncryption, new ParametersWithIV(null, nonce));
|
||||
return GenerateRecordMacKey(cipher);
|
||||
}
|
||||
|
||||
protected virtual byte[] CalculateNonce(long seqNo, byte[] iv)
|
||||
{
|
||||
byte[] nonce = new byte[12];
|
||||
TlsUtilities.WriteUint64(seqNo, nonce, 4);
|
||||
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
nonce[i] ^= iv[i];
|
||||
}
|
||||
|
||||
return nonce;
|
||||
}
|
||||
|
||||
protected virtual KeyParameter GenerateRecordMacKey(IStreamCipher cipher)
|
||||
{
|
||||
byte[] firstBlock = new byte[64];
|
||||
cipher.ProcessBytes(firstBlock, 0, firstBlock.Length, firstBlock, 0);
|
||||
|
||||
KeyParameter macKey = new KeyParameter(firstBlock, 0, 32);
|
||||
Arrays.Fill(firstBlock, (byte)0);
|
||||
return macKey;
|
||||
}
|
||||
|
||||
protected virtual byte[] CalculateRecordMac(KeyParameter macKey, byte[] additionalData, byte[] buf, int off, int len)
|
||||
{
|
||||
IMac mac = new Poly1305();
|
||||
mac.Init(macKey);
|
||||
|
||||
UpdateRecordMacText(mac, additionalData, 0, additionalData.Length);
|
||||
UpdateRecordMacText(mac, buf, off, len);
|
||||
UpdateRecordMacLength(mac, additionalData.Length);
|
||||
UpdateRecordMacLength(mac, len);
|
||||
|
||||
return MacUtilities.DoFinal(mac);
|
||||
}
|
||||
|
||||
protected virtual void UpdateRecordMacLength(IMac mac, int len)
|
||||
{
|
||||
byte[] longLen = Pack.UInt64_To_LE((ulong)len);
|
||||
mac.BlockUpdate(longLen, 0, longLen.Length);
|
||||
}
|
||||
|
||||
protected virtual void UpdateRecordMacText(IMac mac, byte[] buf, int off, int len)
|
||||
{
|
||||
mac.BlockUpdate(buf, off, len);
|
||||
|
||||
int partial = len % 16;
|
||||
if (partial != 0)
|
||||
{
|
||||
mac.BlockUpdate(Zeroes, 0, 16 - partial);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual byte[] GetAdditionalData(long seqNo, byte type, int len)
|
||||
{
|
||||
/*
|
||||
* additional_data = seq_num + TLSCompressed.type + TLSCompressed.version +
|
||||
* TLSCompressed.length
|
||||
*/
|
||||
byte[] additional_data = new byte[13];
|
||||
TlsUtilities.WriteUint64(seqNo, additional_data, 0);
|
||||
TlsUtilities.WriteUint8(type, additional_data, 8);
|
||||
TlsUtilities.WriteVersion(context.ServerVersion, additional_data, 9);
|
||||
TlsUtilities.WriteUint16(len, additional_data, 11);
|
||||
|
||||
return additional_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bb7a9357ebe44dcabd04ab7e6c5caac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class ChangeCipherSpec
|
||||
{
|
||||
public const byte change_cipher_spec = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7f67549f8a8243fdb32ba07ab87e3d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
381
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherSuite.cs
Normal file
381
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherSuite.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 2246 A.5
|
||||
/// </summary>
|
||||
public abstract class CipherSuite
|
||||
{
|
||||
public const int TLS_NULL_WITH_NULL_NULL = 0x0000;
|
||||
public const int TLS_RSA_WITH_NULL_MD5 = 0x0001;
|
||||
public const int TLS_RSA_WITH_NULL_SHA = 0x0002;
|
||||
public const int TLS_RSA_EXPORT_WITH_RC4_40_MD5 = 0x0003;
|
||||
public const int TLS_RSA_WITH_RC4_128_MD5 = 0x0004;
|
||||
public const int TLS_RSA_WITH_RC4_128_SHA = 0x0005;
|
||||
public const int TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 0x0006;
|
||||
public const int TLS_RSA_WITH_IDEA_CBC_SHA = 0x0007;
|
||||
public const int TLS_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0008;
|
||||
public const int TLS_RSA_WITH_DES_CBC_SHA = 0x0009;
|
||||
public const int TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A;
|
||||
public const int TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x000B;
|
||||
public const int TLS_DH_DSS_WITH_DES_CBC_SHA = 0x000C;
|
||||
public const int TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA = 0x000D;
|
||||
public const int TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x000E;
|
||||
public const int TLS_DH_RSA_WITH_DES_CBC_SHA = 0x000F;
|
||||
public const int TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0010;
|
||||
public const int TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x0011;
|
||||
public const int TLS_DHE_DSS_WITH_DES_CBC_SHA = 0x0012;
|
||||
public const int TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 0x0013;
|
||||
public const int TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0014;
|
||||
public const int TLS_DHE_RSA_WITH_DES_CBC_SHA = 0x0015;
|
||||
public const int TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x0016;
|
||||
public const int TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 = 0x0017;
|
||||
public const int TLS_DH_anon_WITH_RC4_128_MD5 = 0x0018;
|
||||
public const int TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 0x0019;
|
||||
public const int TLS_DH_anon_WITH_DES_CBC_SHA = 0x001A;
|
||||
public const int TLS_DH_anon_WITH_3DES_EDE_CBC_SHA = 0x001B;
|
||||
|
||||
/*
|
||||
* Note: The cipher suite values { 0x00, 0x1C } and { 0x00, 0x1D } are reserved to avoid
|
||||
* collision with Fortezza-based cipher suites in SSL 3.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RFC 3268
|
||||
*/
|
||||
public const int TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F;
|
||||
public const int TLS_DH_DSS_WITH_AES_128_CBC_SHA = 0x0030;
|
||||
public const int TLS_DH_RSA_WITH_AES_128_CBC_SHA = 0x0031;
|
||||
public const int TLS_DHE_DSS_WITH_AES_128_CBC_SHA = 0x0032;
|
||||
public const int TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033;
|
||||
public const int TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x0034;
|
||||
public const int TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035;
|
||||
public const int TLS_DH_DSS_WITH_AES_256_CBC_SHA = 0x0036;
|
||||
public const int TLS_DH_RSA_WITH_AES_256_CBC_SHA = 0x0037;
|
||||
public const int TLS_DHE_DSS_WITH_AES_256_CBC_SHA = 0x0038;
|
||||
public const int TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039;
|
||||
public const int TLS_DH_anon_WITH_AES_256_CBC_SHA = 0x003A;
|
||||
|
||||
/*
|
||||
* RFC 5932
|
||||
*/
|
||||
public const int TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0041;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0042;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0043;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0044;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0045;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA = 0x0046;
|
||||
|
||||
public const int TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0084;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0085;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0086;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0087;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0088;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA = 0x0089;
|
||||
|
||||
public const int TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BA;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BB;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BC;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BD;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BE;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BF;
|
||||
|
||||
public const int TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C0;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C1;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C2;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C3;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C4;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C5;
|
||||
|
||||
/*
|
||||
* RFC 4162
|
||||
*/
|
||||
public const int TLS_RSA_WITH_SEED_CBC_SHA = 0x0096;
|
||||
public const int TLS_DH_DSS_WITH_SEED_CBC_SHA = 0x0097;
|
||||
public const int TLS_DH_RSA_WITH_SEED_CBC_SHA = 0x0098;
|
||||
public const int TLS_DHE_DSS_WITH_SEED_CBC_SHA = 0x0099;
|
||||
public const int TLS_DHE_RSA_WITH_SEED_CBC_SHA = 0x009A;
|
||||
public const int TLS_DH_anon_WITH_SEED_CBC_SHA = 0x009B;
|
||||
|
||||
/*
|
||||
* RFC 4279
|
||||
*/
|
||||
public const int TLS_PSK_WITH_RC4_128_SHA = 0x008A;
|
||||
public const int TLS_PSK_WITH_3DES_EDE_CBC_SHA = 0x008B;
|
||||
public const int TLS_PSK_WITH_AES_128_CBC_SHA = 0x008C;
|
||||
public const int TLS_PSK_WITH_AES_256_CBC_SHA = 0x008D;
|
||||
public const int TLS_DHE_PSK_WITH_RC4_128_SHA = 0x008E;
|
||||
public const int TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA = 0x008F;
|
||||
public const int TLS_DHE_PSK_WITH_AES_128_CBC_SHA = 0x0090;
|
||||
public const int TLS_DHE_PSK_WITH_AES_256_CBC_SHA = 0x0091;
|
||||
public const int TLS_RSA_PSK_WITH_RC4_128_SHA = 0x0092;
|
||||
public const int TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA = 0x0093;
|
||||
public const int TLS_RSA_PSK_WITH_AES_128_CBC_SHA = 0x0094;
|
||||
public const int TLS_RSA_PSK_WITH_AES_256_CBC_SHA = 0x0095;
|
||||
|
||||
/*
|
||||
* RFC 4492
|
||||
*/
|
||||
public const int TLS_ECDH_ECDSA_WITH_NULL_SHA = 0xC001;
|
||||
public const int TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0xC002;
|
||||
public const int TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC003;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0xC004;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0xC005;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0xC006;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0xC007;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC008;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A;
|
||||
public const int TLS_ECDH_RSA_WITH_NULL_SHA = 0xC00B;
|
||||
public const int TLS_ECDH_RSA_WITH_RC4_128_SHA = 0xC00C;
|
||||
public const int TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0xC00D;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0xC00E;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0xC00F;
|
||||
public const int TLS_ECDHE_RSA_WITH_NULL_SHA = 0xC010;
|
||||
public const int TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0xC011;
|
||||
public const int TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0xC012;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014;
|
||||
public const int TLS_ECDH_anon_WITH_NULL_SHA = 0xC015;
|
||||
public const int TLS_ECDH_anon_WITH_RC4_128_SHA = 0xC016;
|
||||
public const int TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = 0xC017;
|
||||
public const int TLS_ECDH_anon_WITH_AES_128_CBC_SHA = 0xC018;
|
||||
public const int TLS_ECDH_anon_WITH_AES_256_CBC_SHA = 0xC019;
|
||||
|
||||
/*
|
||||
* RFC 4785
|
||||
*/
|
||||
public const int TLS_PSK_WITH_NULL_SHA = 0x002C;
|
||||
public const int TLS_DHE_PSK_WITH_NULL_SHA = 0x002D;
|
||||
public const int TLS_RSA_PSK_WITH_NULL_SHA = 0x002E;
|
||||
|
||||
/*
|
||||
* RFC 5054
|
||||
*/
|
||||
public const int TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA = 0xC01A;
|
||||
public const int TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA = 0xC01B;
|
||||
public const int TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA = 0xC01C;
|
||||
public const int TLS_SRP_SHA_WITH_AES_128_CBC_SHA = 0xC01D;
|
||||
public const int TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA = 0xC01E;
|
||||
public const int TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA = 0xC01F;
|
||||
public const int TLS_SRP_SHA_WITH_AES_256_CBC_SHA = 0xC020;
|
||||
public const int TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA = 0xC021;
|
||||
public const int TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA = 0xC022;
|
||||
|
||||
/*
|
||||
* RFC 5246
|
||||
*/
|
||||
public const int TLS_RSA_WITH_NULL_SHA256 = 0x003B;
|
||||
public const int TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x003C;
|
||||
public const int TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x003D;
|
||||
public const int TLS_DH_DSS_WITH_AES_128_CBC_SHA256 = 0x003E;
|
||||
public const int TLS_DH_RSA_WITH_AES_128_CBC_SHA256 = 0x003F;
|
||||
public const int TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 = 0x0040;
|
||||
public const int TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x0067;
|
||||
public const int TLS_DH_DSS_WITH_AES_256_CBC_SHA256 = 0x0068;
|
||||
public const int TLS_DH_RSA_WITH_AES_256_CBC_SHA256 = 0x0069;
|
||||
public const int TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 = 0x006A;
|
||||
public const int TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x006B;
|
||||
public const int TLS_DH_anon_WITH_AES_128_CBC_SHA256 = 0x006C;
|
||||
public const int TLS_DH_anon_WITH_AES_256_CBC_SHA256 = 0x006D;
|
||||
|
||||
/*
|
||||
* RFC 5288
|
||||
*/
|
||||
public const int TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C;
|
||||
public const int TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D;
|
||||
public const int TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E;
|
||||
public const int TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F;
|
||||
public const int TLS_DH_RSA_WITH_AES_128_GCM_SHA256 = 0x00A0;
|
||||
public const int TLS_DH_RSA_WITH_AES_256_GCM_SHA384 = 0x00A1;
|
||||
public const int TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 = 0x00A2;
|
||||
public const int TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 = 0x00A3;
|
||||
public const int TLS_DH_DSS_WITH_AES_128_GCM_SHA256 = 0x00A4;
|
||||
public const int TLS_DH_DSS_WITH_AES_256_GCM_SHA384 = 0x00A5;
|
||||
public const int TLS_DH_anon_WITH_AES_128_GCM_SHA256 = 0x00A6;
|
||||
public const int TLS_DH_anon_WITH_AES_256_GCM_SHA384 = 0x00A7;
|
||||
|
||||
/*
|
||||
* RFC 5289
|
||||
*/
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC023;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC024;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC025;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC026;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0xC027;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0xC028;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0xC029;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0xC02A;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02D;
|
||||
public const int TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02E;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F;
|
||||
public const int TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0xC031;
|
||||
public const int TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0xC032;
|
||||
|
||||
/*
|
||||
* RFC 5487
|
||||
*/
|
||||
public const int TLS_PSK_WITH_AES_128_GCM_SHA256 = 0x00A8;
|
||||
public const int TLS_PSK_WITH_AES_256_GCM_SHA384 = 0x00A9;
|
||||
public const int TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0x00AA;
|
||||
public const int TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0x00AB;
|
||||
public const int TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 = 0x00AC;
|
||||
public const int TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 = 0x00AD;
|
||||
public const int TLS_PSK_WITH_AES_128_CBC_SHA256 = 0x00AE;
|
||||
public const int TLS_PSK_WITH_AES_256_CBC_SHA384 = 0x00AF;
|
||||
public const int TLS_PSK_WITH_NULL_SHA256 = 0x00B0;
|
||||
public const int TLS_PSK_WITH_NULL_SHA384 = 0x00B1;
|
||||
public const int TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0x00B2;
|
||||
public const int TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0x00B3;
|
||||
public const int TLS_DHE_PSK_WITH_NULL_SHA256 = 0x00B4;
|
||||
public const int TLS_DHE_PSK_WITH_NULL_SHA384 = 0x00B5;
|
||||
public const int TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 = 0x00B6;
|
||||
public const int TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 = 0x00B7;
|
||||
public const int TLS_RSA_PSK_WITH_NULL_SHA256 = 0x00B8;
|
||||
public const int TLS_RSA_PSK_WITH_NULL_SHA384 = 0x00B9;
|
||||
|
||||
/*
|
||||
* RFC 5489
|
||||
*/
|
||||
public const int TLS_ECDHE_PSK_WITH_RC4_128_SHA = 0xC033;
|
||||
public const int TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA = 0xC034;
|
||||
public const int TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA = 0xC035;
|
||||
public const int TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA = 0xC036;
|
||||
public const int TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0xC037;
|
||||
public const int TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 = 0xC038;
|
||||
public const int TLS_ECDHE_PSK_WITH_NULL_SHA = 0xC039;
|
||||
public const int TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0xC03A;
|
||||
public const int TLS_ECDHE_PSK_WITH_NULL_SHA384 = 0xC03B;
|
||||
|
||||
/*
|
||||
* RFC 5746
|
||||
*/
|
||||
public const int TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0x00FF;
|
||||
|
||||
/*
|
||||
* RFC 6367
|
||||
*/
|
||||
public const int TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC072;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC073;
|
||||
public const int TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC074;
|
||||
public const int TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC075;
|
||||
public const int TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC076;
|
||||
public const int TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC077;
|
||||
public const int TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC078;
|
||||
public const int TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC079;
|
||||
|
||||
public const int TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07A;
|
||||
public const int TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07B;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07C;
|
||||
public const int TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07D;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07E;
|
||||
public const int TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07F;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 = 0xC080;
|
||||
public const int TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 = 0xC081;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 = 0xC082;
|
||||
public const int TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 = 0xC083;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 = 0xC084;
|
||||
public const int TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 = 0xC085;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC086;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC087;
|
||||
public const int TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC088;
|
||||
public const int TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC089;
|
||||
public const int TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08A;
|
||||
public const int TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08B;
|
||||
public const int TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08C;
|
||||
public const int TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08D;
|
||||
|
||||
public const int TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08E;
|
||||
public const int TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08F;
|
||||
public const int TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC090;
|
||||
public const int TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC091;
|
||||
public const int TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC092;
|
||||
public const int TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC093;
|
||||
public const int TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC094;
|
||||
public const int TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC095;
|
||||
public const int TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC096;
|
||||
public const int TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC097;
|
||||
public const int TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC098;
|
||||
public const int TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC099;
|
||||
public const int TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC09A;
|
||||
public const int TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC09B;
|
||||
|
||||
/*
|
||||
* RFC 6655
|
||||
*/
|
||||
public const int TLS_RSA_WITH_AES_128_CCM = 0xC09C;
|
||||
public const int TLS_RSA_WITH_AES_256_CCM = 0xC09D;
|
||||
public const int TLS_DHE_RSA_WITH_AES_128_CCM = 0xC09E;
|
||||
public const int TLS_DHE_RSA_WITH_AES_256_CCM = 0xC09F;
|
||||
public const int TLS_RSA_WITH_AES_128_CCM_8 = 0xC0A0;
|
||||
public const int TLS_RSA_WITH_AES_256_CCM_8 = 0xC0A1;
|
||||
public const int TLS_DHE_RSA_WITH_AES_128_CCM_8 = 0xC0A2;
|
||||
public const int TLS_DHE_RSA_WITH_AES_256_CCM_8 = 0xC0A3;
|
||||
public const int TLS_PSK_WITH_AES_128_CCM = 0xC0A4;
|
||||
public const int TLS_PSK_WITH_AES_256_CCM = 0xC0A5;
|
||||
public const int TLS_DHE_PSK_WITH_AES_128_CCM = 0xC0A6;
|
||||
public const int TLS_DHE_PSK_WITH_AES_256_CCM = 0xC0A7;
|
||||
public const int TLS_PSK_WITH_AES_128_CCM_8 = 0xC0A8;
|
||||
public const int TLS_PSK_WITH_AES_256_CCM_8 = 0xC0A9;
|
||||
public const int TLS_PSK_DHE_WITH_AES_128_CCM_8 = 0xC0AA;
|
||||
public const int TLS_PSK_DHE_WITH_AES_256_CCM_8 = 0xC0AB;
|
||||
|
||||
/*
|
||||
* RFC 7251
|
||||
*/
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_128_CCM = 0xC0AC;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_256_CCM = 0xC0AD;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xC0AE;
|
||||
public const int TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xC0AF;
|
||||
|
||||
/*
|
||||
* RFC 7507
|
||||
*/
|
||||
public const int TLS_FALLBACK_SCSV = 0x5600;
|
||||
|
||||
/*
|
||||
* draft-ietf-tls-chacha20-poly1305-04
|
||||
*/
|
||||
public const int DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA8;
|
||||
public const int DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA9;
|
||||
public const int DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAA;
|
||||
public const int DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAB;
|
||||
public const int DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAC;
|
||||
public const int DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAD;
|
||||
public const int DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAE;
|
||||
|
||||
/*
|
||||
* draft-zauner-tls-aes-ocb-04 (code points TBD)
|
||||
*/
|
||||
public const int DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB = 0xFF00;
|
||||
public const int DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB = 0xFF01;
|
||||
public const int DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB = 0xFF02;
|
||||
public const int DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB = 0xFF03;
|
||||
public const int DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB = 0xFF04;
|
||||
public const int DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB = 0xFF05;
|
||||
public const int DRAFT_TLS_PSK_WITH_AES_128_OCB = 0xFF10;
|
||||
public const int DRAFT_TLS_PSK_WITH_AES_256_OCB = 0xFF11;
|
||||
public const int DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB = 0xFF12;
|
||||
public const int DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB = 0xFF13;
|
||||
public const int DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB = 0xFF14;
|
||||
public const int DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB = 0xFF15;
|
||||
|
||||
public static bool IsScsv(int cipherSuite)
|
||||
{
|
||||
switch (cipherSuite)
|
||||
{
|
||||
case TLS_EMPTY_RENEGOTIATION_INFO_SCSV:
|
||||
case TLS_FALLBACK_SCSV:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e2271202d4f845fe8bcfbf55c57edc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherType.cs
Normal file
24
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherType.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 2246</summary>
|
||||
/// <remarks>
|
||||
/// Note that the values here are implementation-specific and arbitrary. It is recommended not to
|
||||
/// depend on the particular values (e.g. serialization).
|
||||
/// </remarks>
|
||||
public abstract class CipherType
|
||||
{
|
||||
public const int stream = 0;
|
||||
public const int block = 1;
|
||||
|
||||
/*
|
||||
* RFC 5246
|
||||
*/
|
||||
public const int aead = 2;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherType.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/crypto/tls/CipherType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8db63801e8718436ba1906ada7236d63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class ClientCertificateType
|
||||
{
|
||||
/*
|
||||
* RFC 4346 7.4.4
|
||||
*/
|
||||
public const byte rsa_sign = 1;
|
||||
public const byte dss_sign = 2;
|
||||
public const byte rsa_fixed_dh = 3;
|
||||
public const byte dss_fixed_dh = 4;
|
||||
public const byte rsa_ephemeral_dh_RESERVED = 5;
|
||||
public const byte dss_ephemeral_dh_RESERVED = 6;
|
||||
public const byte fortezza_dms_RESERVED = 20;
|
||||
|
||||
/*
|
||||
* RFC 4492 5.5
|
||||
*/
|
||||
public const byte ecdsa_sign = 64;
|
||||
public const byte rsa_fixed_ecdh = 65;
|
||||
public const byte ecdsa_fixed_ecdh = 66;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bc0880490af9424da22a44302ae0c89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
137
Assets/BestHTTP/SecureProtocol/crypto/tls/CombinedHash.cs
Normal file
137
Assets/BestHTTP/SecureProtocol/crypto/tls/CombinedHash.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Security;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* A combined hash, which implements md5(m) || sha1(m).
|
||||
*/
|
||||
internal class CombinedHash
|
||||
: TlsHandshakeHash
|
||||
{
|
||||
protected TlsContext mContext;
|
||||
protected IDigest mMd5;
|
||||
protected IDigest mSha1;
|
||||
|
||||
internal CombinedHash()
|
||||
{
|
||||
this.mMd5 = TlsUtilities.CreateHash(HashAlgorithm.md5);
|
||||
this.mSha1 = TlsUtilities.CreateHash(HashAlgorithm.sha1);
|
||||
}
|
||||
|
||||
internal CombinedHash(CombinedHash t)
|
||||
{
|
||||
this.mContext = t.mContext;
|
||||
this.mMd5 = TlsUtilities.CloneHash(HashAlgorithm.md5, t.mMd5);
|
||||
this.mSha1 = TlsUtilities.CloneHash(HashAlgorithm.sha1, t.mSha1);
|
||||
}
|
||||
|
||||
public virtual void Init(TlsContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public virtual TlsHandshakeHash NotifyPrfDetermined()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual void TrackHashAlgorithm(byte hashAlgorithm)
|
||||
{
|
||||
throw new InvalidOperationException("CombinedHash only supports calculating the legacy PRF for handshake hash");
|
||||
}
|
||||
|
||||
public virtual void SealHashAlgorithms()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual TlsHandshakeHash StopTracking()
|
||||
{
|
||||
return new CombinedHash(this);
|
||||
}
|
||||
|
||||
public virtual IDigest ForkPrfHash()
|
||||
{
|
||||
return new CombinedHash(this);
|
||||
}
|
||||
|
||||
public virtual byte[] GetFinalHash(byte hashAlgorithm)
|
||||
{
|
||||
throw new InvalidOperationException("CombinedHash doesn't support multiple hashes");
|
||||
}
|
||||
|
||||
public virtual string AlgorithmName
|
||||
{
|
||||
get { return mMd5.AlgorithmName + " and " + mSha1.AlgorithmName; }
|
||||
}
|
||||
|
||||
public virtual int GetByteLength()
|
||||
{
|
||||
return System.Math.Max(mMd5.GetByteLength(), mSha1.GetByteLength());
|
||||
}
|
||||
|
||||
public virtual int GetDigestSize()
|
||||
{
|
||||
return mMd5.GetDigestSize() + mSha1.GetDigestSize();
|
||||
}
|
||||
|
||||
public virtual void Update(byte input)
|
||||
{
|
||||
mMd5.Update(input);
|
||||
mSha1.Update(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.bouncycastle.crypto.Digest#update(byte[], int, int)
|
||||
*/
|
||||
public virtual void BlockUpdate(byte[] input, int inOff, int len)
|
||||
{
|
||||
mMd5.BlockUpdate(input, inOff, len);
|
||||
mSha1.BlockUpdate(input, inOff, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.bouncycastle.crypto.Digest#doFinal(byte[], int)
|
||||
*/
|
||||
public virtual int DoFinal(byte[] output, int outOff)
|
||||
{
|
||||
if (mContext != null && TlsUtilities.IsSsl(mContext))
|
||||
{
|
||||
Ssl3Complete(mMd5, Ssl3Mac.IPAD, Ssl3Mac.OPAD, 48);
|
||||
Ssl3Complete(mSha1, Ssl3Mac.IPAD, Ssl3Mac.OPAD, 40);
|
||||
}
|
||||
|
||||
int i1 = mMd5.DoFinal(output, outOff);
|
||||
int i2 = mSha1.DoFinal(output, outOff + i1);
|
||||
return i1 + i2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.bouncycastle.crypto.Digest#reset()
|
||||
*/
|
||||
public virtual void Reset()
|
||||
{
|
||||
mMd5.Reset();
|
||||
mSha1.Reset();
|
||||
}
|
||||
|
||||
protected virtual void Ssl3Complete(IDigest d, byte[] ipad, byte[] opad, int padLength)
|
||||
{
|
||||
byte[] master_secret = mContext.SecurityParameters.masterSecret;
|
||||
|
||||
d.BlockUpdate(master_secret, 0, master_secret.Length);
|
||||
d.BlockUpdate(ipad, 0, padLength);
|
||||
|
||||
byte[] tmp = DigestUtilities.DoFinal(d);
|
||||
|
||||
d.BlockUpdate(master_secret, 0, master_secret.Length);
|
||||
d.BlockUpdate(opad, 0, padLength);
|
||||
d.BlockUpdate(tmp, 0, tmp.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48c865481036d4681b8b34718ffcd437
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 2246 6.1
|
||||
/// </summary>
|
||||
public abstract class CompressionMethod
|
||||
{
|
||||
public const byte cls_null = 0;
|
||||
|
||||
/*
|
||||
* RFC 3749 2
|
||||
*/
|
||||
public const byte DEFLATE = 1;
|
||||
|
||||
/*
|
||||
* Values from 224 decimal (0xE0) through 255 decimal (0xFF)
|
||||
* inclusive are reserved for private use.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd94071a44d704f8fa9847e6e1dc5fac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/BestHTTP/SecureProtocol/crypto/tls/ConnectionEnd.cs
Normal file
19
Assets/BestHTTP/SecureProtocol/crypto/tls/ConnectionEnd.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 2246</summary>
|
||||
/// <remarks>
|
||||
/// Note that the values here are implementation-specific and arbitrary. It is recommended not to
|
||||
/// depend on the particular values (e.g. serialization).
|
||||
/// </remarks>
|
||||
public abstract class ConnectionEnd
|
||||
{
|
||||
public const int server = 0;
|
||||
public const int client = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71a9f81e6d61e432486d08b0f23676b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/BestHTTP/SecureProtocol/crypto/tls/ContentType.cs
Normal file
18
Assets/BestHTTP/SecureProtocol/crypto/tls/ContentType.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* RFC 2246 6.2.1
|
||||
*/
|
||||
public abstract class ContentType
|
||||
{
|
||||
public const byte change_cipher_spec = 20;
|
||||
public const byte alert = 21;
|
||||
public const byte handshake = 22;
|
||||
public const byte application_data = 23;
|
||||
public const byte heartbeat = 24;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c760acf47710f4f229466dcc5db4f11d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public interface DatagramTransport
|
||||
{
|
||||
/// <exception cref="IOException"/>
|
||||
int GetReceiveLimit();
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
int GetSendLimit();
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
int Receive(byte[] buf, int off, int len, int waitMillis);
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
void Send(byte[] buf, int off, int len);
|
||||
|
||||
/// <exception cref="IOException"/>
|
||||
void Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ab9e306867144537a3228bf25252bd6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,231 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Modes;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class DefaultTlsCipherFactory
|
||||
: AbstractTlsCipherFactory
|
||||
{
|
||||
/// <exception cref="IOException"></exception>
|
||||
public override TlsCipher CreateCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm)
|
||||
{
|
||||
switch (encryptionAlgorithm)
|
||||
{
|
||||
case EncryptionAlgorithm.cls_3DES_EDE_CBC:
|
||||
return CreateDesEdeCipher(context, macAlgorithm);
|
||||
case EncryptionAlgorithm.AES_128_CBC:
|
||||
return CreateAESCipher(context, 16, macAlgorithm);
|
||||
case EncryptionAlgorithm.AES_128_CCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(context, 16, 16);
|
||||
case EncryptionAlgorithm.AES_128_CCM_8:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(context, 16, 8);
|
||||
case EncryptionAlgorithm.AES_128_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Gcm(context, 16, 16);
|
||||
case EncryptionAlgorithm.AES_128_OCB_TAGLEN96:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ocb(context, 16, 12);
|
||||
case EncryptionAlgorithm.AES_256_CBC:
|
||||
return CreateAESCipher(context, 32, macAlgorithm);
|
||||
case EncryptionAlgorithm.AES_256_CCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(context, 32, 16);
|
||||
case EncryptionAlgorithm.AES_256_CCM_8:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ccm(context, 32, 8);
|
||||
case EncryptionAlgorithm.AES_256_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Gcm(context, 32, 16);
|
||||
case EncryptionAlgorithm.AES_256_OCB_TAGLEN96:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Aes_Ocb(context, 32, 12);
|
||||
case EncryptionAlgorithm.CAMELLIA_128_CBC:
|
||||
return CreateCamelliaCipher(context, 16, macAlgorithm);
|
||||
case EncryptionAlgorithm.CAMELLIA_128_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Camellia_Gcm(context, 16, 16);
|
||||
case EncryptionAlgorithm.CAMELLIA_256_CBC:
|
||||
return CreateCamelliaCipher(context, 32, macAlgorithm);
|
||||
case EncryptionAlgorithm.CAMELLIA_256_GCM:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateCipher_Camellia_Gcm(context, 32, 16);
|
||||
case EncryptionAlgorithm.CHACHA20_POLY1305:
|
||||
// NOTE: Ignores macAlgorithm
|
||||
return CreateChaCha20Poly1305(context);
|
||||
case EncryptionAlgorithm.NULL:
|
||||
return CreateNullCipher(context, macAlgorithm);
|
||||
case EncryptionAlgorithm.RC4_128:
|
||||
return CreateRC4Cipher(context, 16, macAlgorithm);
|
||||
case EncryptionAlgorithm.SEED_CBC:
|
||||
return CreateSeedCipher(context, macAlgorithm);
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsBlockCipher CreateAESCipher(TlsContext context, int cipherKeySize, int macAlgorithm)
|
||||
{
|
||||
return new TlsBlockCipher(context, CreateAesBlockCipher(), CreateAesBlockCipher(),
|
||||
CreateHMacDigest(macAlgorithm), CreateHMacDigest(macAlgorithm), cipherKeySize);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsBlockCipher CreateCamelliaCipher(TlsContext context, int cipherKeySize, int macAlgorithm)
|
||||
{
|
||||
return new TlsBlockCipher(context, CreateCamelliaBlockCipher(),
|
||||
CreateCamelliaBlockCipher(), CreateHMacDigest(macAlgorithm),
|
||||
CreateHMacDigest(macAlgorithm), cipherKeySize);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsCipher CreateChaCha20Poly1305(TlsContext context)
|
||||
{
|
||||
return new Chacha20Poly1305(context);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsAeadCipher CreateCipher_Aes_Ccm(TlsContext context, int cipherKeySize, int macSize)
|
||||
{
|
||||
return new TlsAeadCipher(context, CreateAeadBlockCipher_Aes_Ccm(),
|
||||
CreateAeadBlockCipher_Aes_Ccm(), cipherKeySize, macSize);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsAeadCipher CreateCipher_Aes_Gcm(TlsContext context, int cipherKeySize, int macSize)
|
||||
{
|
||||
return new TlsAeadCipher(context, CreateAeadBlockCipher_Aes_Gcm(),
|
||||
CreateAeadBlockCipher_Aes_Gcm(), cipherKeySize, macSize);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsAeadCipher CreateCipher_Aes_Ocb(TlsContext context, int cipherKeySize, int macSize)
|
||||
{
|
||||
return new TlsAeadCipher(context, CreateAeadBlockCipher_Aes_Ocb(),
|
||||
CreateAeadBlockCipher_Aes_Ocb(), cipherKeySize, macSize, TlsAeadCipher.NONCE_DRAFT_CHACHA20_POLY1305);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsAeadCipher CreateCipher_Camellia_Gcm(TlsContext context, int cipherKeySize, int macSize)
|
||||
{
|
||||
return new TlsAeadCipher(context, CreateAeadBlockCipher_Camellia_Gcm(),
|
||||
CreateAeadBlockCipher_Camellia_Gcm(), cipherKeySize, macSize);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsBlockCipher CreateDesEdeCipher(TlsContext context, int macAlgorithm)
|
||||
{
|
||||
return new TlsBlockCipher(context, CreateDesEdeBlockCipher(), CreateDesEdeBlockCipher(),
|
||||
CreateHMacDigest(macAlgorithm), CreateHMacDigest(macAlgorithm), 24);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsNullCipher CreateNullCipher(TlsContext context, int macAlgorithm)
|
||||
{
|
||||
return new TlsNullCipher(context, CreateHMacDigest(macAlgorithm),
|
||||
CreateHMacDigest(macAlgorithm));
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsStreamCipher CreateRC4Cipher(TlsContext context, int cipherKeySize, int macAlgorithm)
|
||||
{
|
||||
return new TlsStreamCipher(context, CreateRC4StreamCipher(), CreateRC4StreamCipher(),
|
||||
CreateHMacDigest(macAlgorithm), CreateHMacDigest(macAlgorithm), cipherKeySize, false);
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual TlsBlockCipher CreateSeedCipher(TlsContext context, int macAlgorithm)
|
||||
{
|
||||
return new TlsBlockCipher(context, CreateSeedBlockCipher(), CreateSeedBlockCipher(),
|
||||
CreateHMacDigest(macAlgorithm), CreateHMacDigest(macAlgorithm), 16);
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateAesEngine()
|
||||
{
|
||||
return new AesEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateCamelliaEngine()
|
||||
{
|
||||
return new CamelliaEngine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateAesBlockCipher()
|
||||
{
|
||||
return new CbcBlockCipher(CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadBlockCipher CreateAeadBlockCipher_Aes_Ccm()
|
||||
{
|
||||
return new CcmBlockCipher(CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadBlockCipher CreateAeadBlockCipher_Aes_Gcm()
|
||||
{
|
||||
// TODO Consider allowing custom configuration of multiplier
|
||||
return new GcmBlockCipher(CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadBlockCipher CreateAeadBlockCipher_Aes_Ocb()
|
||||
{
|
||||
return new OcbBlockCipher(CreateAesEngine(), CreateAesEngine());
|
||||
}
|
||||
|
||||
protected virtual IAeadBlockCipher CreateAeadBlockCipher_Camellia_Gcm()
|
||||
{
|
||||
// TODO Consider allowing custom configuration of multiplier
|
||||
return new GcmBlockCipher(CreateCamelliaEngine());
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateCamelliaBlockCipher()
|
||||
{
|
||||
return new CbcBlockCipher(CreateCamelliaEngine());
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateDesEdeBlockCipher()
|
||||
{
|
||||
return new CbcBlockCipher(new DesEdeEngine());
|
||||
}
|
||||
|
||||
protected virtual IStreamCipher CreateRC4StreamCipher()
|
||||
{
|
||||
return new RC4Engine();
|
||||
}
|
||||
|
||||
protected virtual IBlockCipher CreateSeedBlockCipher()
|
||||
{
|
||||
return new CbcBlockCipher(new SeedEngine());
|
||||
}
|
||||
|
||||
/// <exception cref="IOException"></exception>
|
||||
protected virtual IDigest CreateHMacDigest(int macAlgorithm)
|
||||
{
|
||||
switch (macAlgorithm)
|
||||
{
|
||||
case MacAlgorithm.cls_null:
|
||||
return null;
|
||||
case MacAlgorithm.hmac_md5:
|
||||
return TlsUtilities.CreateHash(HashAlgorithm.md5);
|
||||
case MacAlgorithm.hmac_sha1:
|
||||
return TlsUtilities.CreateHash(HashAlgorithm.sha1);
|
||||
case MacAlgorithm.hmac_sha256:
|
||||
return TlsUtilities.CreateHash(HashAlgorithm.sha256);
|
||||
case MacAlgorithm.hmac_sha384:
|
||||
return TlsUtilities.CreateHash(HashAlgorithm.sha384);
|
||||
case MacAlgorithm.hmac_sha512:
|
||||
return TlsUtilities.CreateHash(HashAlgorithm.sha512);
|
||||
default:
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab31802cefa754d9595ccc86eae3b358
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
Assets/BestHTTP/SecureProtocol/crypto/tls/DefaultTlsClient.cs
Normal file
116
Assets/BestHTTP/SecureProtocol/crypto/tls/DefaultTlsClient.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Modes;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class DefaultTlsClient
|
||||
: AbstractTlsClient
|
||||
{
|
||||
public DefaultTlsClient()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public DefaultTlsClient(TlsCipherFactory cipherFactory)
|
||||
: base(cipherFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public override int[] GetCipherSuites()
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
||||
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
||||
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
|
||||
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
||||
CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,
|
||||
CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,
|
||||
CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
|
||||
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
|
||||
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
|
||||
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
||||
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
||||
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
|
||||
};
|
||||
}
|
||||
|
||||
public override TlsKeyExchange GetKeyExchange()
|
||||
{
|
||||
int keyExchangeAlgorithm = TlsUtilities.GetKeyExchangeAlgorithm(mSelectedCipherSuite);
|
||||
|
||||
switch (keyExchangeAlgorithm)
|
||||
{
|
||||
case KeyExchangeAlgorithm.DH_DSS:
|
||||
case KeyExchangeAlgorithm.DH_RSA:
|
||||
return CreateDHKeyExchange(keyExchangeAlgorithm);
|
||||
|
||||
case KeyExchangeAlgorithm.DHE_DSS:
|
||||
case KeyExchangeAlgorithm.DHE_RSA:
|
||||
return CreateDheKeyExchange(keyExchangeAlgorithm);
|
||||
|
||||
case KeyExchangeAlgorithm.ECDH_anon:
|
||||
case KeyExchangeAlgorithm.ECDH_ECDSA:
|
||||
case KeyExchangeAlgorithm.ECDH_RSA:
|
||||
return CreateECDHKeyExchange(keyExchangeAlgorithm);
|
||||
|
||||
case KeyExchangeAlgorithm.ECDHE_ECDSA:
|
||||
case KeyExchangeAlgorithm.ECDHE_RSA:
|
||||
return CreateECDheKeyExchange(keyExchangeAlgorithm);
|
||||
|
||||
case KeyExchangeAlgorithm.RSA:
|
||||
return CreateRsaKeyExchange();
|
||||
|
||||
default:
|
||||
/*
|
||||
* Note: internal error here; the TlsProtocol implementation verifies that the
|
||||
* server-selected cipher suite was in the list of client-offered cipher suites, so if
|
||||
* we now can't produce an implementation, we shouldn't have offered it!
|
||||
*/
|
||||
throw new TlsFatalAlert(AlertDescription.internal_error);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual TlsKeyExchange CreateDHKeyExchange(int keyExchange)
|
||||
{
|
||||
return new TlsDHKeyExchange(keyExchange, mSupportedSignatureAlgorithms, null);
|
||||
}
|
||||
|
||||
protected virtual TlsKeyExchange CreateDheKeyExchange(int keyExchange)
|
||||
{
|
||||
return new TlsDheKeyExchange(keyExchange, mSupportedSignatureAlgorithms, null);
|
||||
}
|
||||
|
||||
protected virtual TlsKeyExchange CreateECDHKeyExchange(int keyExchange)
|
||||
{
|
||||
return new TlsECDHKeyExchange(keyExchange, mSupportedSignatureAlgorithms, mNamedCurves, mClientECPointFormats,
|
||||
mServerECPointFormats);
|
||||
}
|
||||
|
||||
protected virtual TlsKeyExchange CreateECDheKeyExchange(int keyExchange)
|
||||
{
|
||||
return new TlsECDheKeyExchange(keyExchange, mSupportedSignatureAlgorithms, mNamedCurves, mClientECPointFormats,
|
||||
mServerECPointFormats);
|
||||
}
|
||||
|
||||
protected virtual TlsKeyExchange CreateRsaKeyExchange()
|
||||
{
|
||||
return new TlsRsaKeyExchange(mSupportedSignatureAlgorithms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fde158679ffc42b6a19cebd4faf6b8a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
205
Assets/BestHTTP/SecureProtocol/crypto/tls/DeferredHash.cs
Normal file
205
Assets/BestHTTP/SecureProtocol/crypto/tls/DeferredHash.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Org.BouncyCastle.Security;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/**
|
||||
* Buffers input until the hash algorithm is determined.
|
||||
*/
|
||||
internal class DeferredHash
|
||||
: TlsHandshakeHash
|
||||
{
|
||||
protected const int BUFFERING_HASH_LIMIT = 4;
|
||||
|
||||
protected TlsContext mContext;
|
||||
|
||||
private DigestInputBuffer mBuf;
|
||||
private IDictionary mHashes;
|
||||
private int mPrfHashAlgorithm;
|
||||
|
||||
internal DeferredHash()
|
||||
{
|
||||
this.mBuf = new DigestInputBuffer();
|
||||
this.mHashes = Platform.CreateHashtable();
|
||||
this.mPrfHashAlgorithm = -1;
|
||||
}
|
||||
|
||||
private DeferredHash(byte prfHashAlgorithm, IDigest prfHash)
|
||||
{
|
||||
this.mBuf = null;
|
||||
this.mHashes = Platform.CreateHashtable();
|
||||
this.mPrfHashAlgorithm = prfHashAlgorithm;
|
||||
mHashes[prfHashAlgorithm] = prfHash;
|
||||
}
|
||||
|
||||
public virtual void Init(TlsContext context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public virtual TlsHandshakeHash NotifyPrfDetermined()
|
||||
{
|
||||
int prfAlgorithm = mContext.SecurityParameters.PrfAlgorithm;
|
||||
if (prfAlgorithm == PrfAlgorithm.tls_prf_legacy)
|
||||
{
|
||||
CombinedHash legacyHash = new CombinedHash();
|
||||
legacyHash.Init(mContext);
|
||||
mBuf.UpdateDigest(legacyHash);
|
||||
return legacyHash.NotifyPrfDetermined();
|
||||
}
|
||||
|
||||
this.mPrfHashAlgorithm = TlsUtilities.GetHashAlgorithmForPrfAlgorithm(prfAlgorithm);
|
||||
|
||||
CheckTrackingHash((byte)mPrfHashAlgorithm);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual void TrackHashAlgorithm(byte hashAlgorithm)
|
||||
{
|
||||
if (mBuf == null)
|
||||
throw new InvalidOperationException("Too late to track more hash algorithms");
|
||||
|
||||
CheckTrackingHash(hashAlgorithm);
|
||||
}
|
||||
|
||||
public virtual void SealHashAlgorithms()
|
||||
{
|
||||
CheckStopBuffering();
|
||||
}
|
||||
|
||||
public virtual TlsHandshakeHash StopTracking()
|
||||
{
|
||||
byte prfHashAlgorithm = (byte)mPrfHashAlgorithm;
|
||||
IDigest prfHash = TlsUtilities.CloneHash(prfHashAlgorithm, (IDigest)mHashes[prfHashAlgorithm]);
|
||||
if (mBuf != null)
|
||||
{
|
||||
mBuf.UpdateDigest(prfHash);
|
||||
}
|
||||
DeferredHash result = new DeferredHash(prfHashAlgorithm, prfHash);
|
||||
result.Init(mContext);
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual IDigest ForkPrfHash()
|
||||
{
|
||||
CheckStopBuffering();
|
||||
|
||||
byte prfHashAlgorithm = (byte)mPrfHashAlgorithm;
|
||||
if (mBuf != null)
|
||||
{
|
||||
IDigest prfHash = TlsUtilities.CreateHash(prfHashAlgorithm);
|
||||
mBuf.UpdateDigest(prfHash);
|
||||
return prfHash;
|
||||
}
|
||||
|
||||
return TlsUtilities.CloneHash(prfHashAlgorithm, (IDigest)mHashes[prfHashAlgorithm]);
|
||||
}
|
||||
|
||||
public virtual byte[] GetFinalHash(byte hashAlgorithm)
|
||||
{
|
||||
IDigest d = (IDigest)mHashes[hashAlgorithm];
|
||||
if (d == null)
|
||||
throw new InvalidOperationException("HashAlgorithm." + HashAlgorithm.GetText(hashAlgorithm) + " is not being tracked");
|
||||
|
||||
d = TlsUtilities.CloneHash(hashAlgorithm, d);
|
||||
if (mBuf != null)
|
||||
{
|
||||
mBuf.UpdateDigest(d);
|
||||
}
|
||||
|
||||
return DigestUtilities.DoFinal(d);
|
||||
}
|
||||
|
||||
public virtual string AlgorithmName
|
||||
{
|
||||
get { throw new InvalidOperationException("Use Fork() to get a definite IDigest"); }
|
||||
}
|
||||
|
||||
public virtual int GetByteLength()
|
||||
{
|
||||
throw new InvalidOperationException("Use Fork() to get a definite IDigest");
|
||||
}
|
||||
|
||||
public virtual int GetDigestSize()
|
||||
{
|
||||
throw new InvalidOperationException("Use Fork() to get a definite IDigest");
|
||||
}
|
||||
|
||||
public virtual void Update(byte input)
|
||||
{
|
||||
if (mBuf != null)
|
||||
{
|
||||
mBuf.WriteByte(input);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (IDigest hash in mHashes.Values)
|
||||
{
|
||||
hash.Update(input);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void BlockUpdate(byte[] input, int inOff, int len)
|
||||
{
|
||||
if (mBuf != null)
|
||||
{
|
||||
mBuf.Write(input, inOff, len);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (IDigest hash in mHashes.Values)
|
||||
{
|
||||
hash.BlockUpdate(input, inOff, len);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int DoFinal(byte[] output, int outOff)
|
||||
{
|
||||
throw new InvalidOperationException("Use Fork() to get a definite IDigest");
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
if (mBuf != null)
|
||||
{
|
||||
mBuf.SetLength(0);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (IDigest hash in mHashes.Values)
|
||||
{
|
||||
hash.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CheckStopBuffering()
|
||||
{
|
||||
if (mBuf != null && mHashes.Count <= BUFFERING_HASH_LIMIT)
|
||||
{
|
||||
foreach (IDigest hash in mHashes.Values)
|
||||
{
|
||||
mBuf.UpdateDigest(hash);
|
||||
}
|
||||
|
||||
this.mBuf = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CheckTrackingHash(byte hashAlgorithm)
|
||||
{
|
||||
if (!mHashes.Contains(hashAlgorithm))
|
||||
{
|
||||
IDigest hash = TlsUtilities.CreateHash(hashAlgorithm);
|
||||
mHashes[hashAlgorithm] = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab0c7c33e0c7948e78bef667a72cb719
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
internal class DigestInputBuffer
|
||||
: MemoryStream
|
||||
{
|
||||
internal void UpdateDigest(IDigest d)
|
||||
{
|
||||
WriteTo(new DigStream(d));
|
||||
}
|
||||
|
||||
private class DigStream
|
||||
: BaseOutputStream
|
||||
{
|
||||
private readonly IDigest d;
|
||||
|
||||
internal DigStream(IDigest d)
|
||||
{
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b)
|
||||
{
|
||||
d.Update(b);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buf, int off, int len)
|
||||
{
|
||||
d.BlockUpdate(buf, off, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61975565d88554e6ebae4ba9e4fb07ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/BestHTTP/SecureProtocol/crypto/tls/DigitallySigned.cs
Normal file
74
Assets/BestHTTP/SecureProtocol/crypto/tls/DigitallySigned.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class DigitallySigned
|
||||
{
|
||||
protected readonly SignatureAndHashAlgorithm mAlgorithm;
|
||||
protected readonly byte[] mSignature;
|
||||
|
||||
public DigitallySigned(SignatureAndHashAlgorithm algorithm, byte[] signature)
|
||||
{
|
||||
if (signature == null)
|
||||
throw new ArgumentNullException("signature");
|
||||
|
||||
this.mAlgorithm = algorithm;
|
||||
this.mSignature = signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link SignatureAndHashAlgorithm} (or null before TLS 1.2).
|
||||
*/
|
||||
public virtual SignatureAndHashAlgorithm Algorithm
|
||||
{
|
||||
get { return mAlgorithm; }
|
||||
}
|
||||
|
||||
public virtual byte[] Signature
|
||||
{
|
||||
get { return mSignature; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link DigitallySigned} to a {@link Stream}.
|
||||
*
|
||||
* @param output
|
||||
* the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
if (mAlgorithm != null)
|
||||
{
|
||||
mAlgorithm.Encode(output);
|
||||
}
|
||||
TlsUtilities.WriteOpaque16(mSignature, output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link DigitallySigned} from a {@link Stream}.
|
||||
*
|
||||
* @param context
|
||||
* the {@link TlsContext} of the current connection.
|
||||
* @param input
|
||||
* the {@link Stream} to parse from.
|
||||
* @return a {@link DigitallySigned} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static DigitallySigned Parse(TlsContext context, Stream input)
|
||||
{
|
||||
SignatureAndHashAlgorithm algorithm = null;
|
||||
if (TlsUtilities.IsTlsV12(context))
|
||||
{
|
||||
algorithm = SignatureAndHashAlgorithm.Parse(input);
|
||||
}
|
||||
byte[] signature = TlsUtilities.ReadOpaque16(input);
|
||||
return new DigitallySigned(algorithm, signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c21309e57c2034b31ae0981daeb9cbff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/BestHTTP/SecureProtocol/crypto/tls/ECBasisType.cs
Normal file
20
Assets/BestHTTP/SecureProtocol/crypto/tls/ECBasisType.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 4492 5.4. (Errata ID: 2389)</summary>
|
||||
public abstract class ECBasisType
|
||||
{
|
||||
public const byte ec_basis_trinomial = 1;
|
||||
public const byte ec_basis_pentanomial = 2;
|
||||
|
||||
public static bool IsValid(byte ecBasisType)
|
||||
{
|
||||
return ecBasisType >= ec_basis_trinomial && ecBasisType <= ec_basis_pentanomial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76330eaad6a544937b2cf1f56f736fcc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/BestHTTP/SecureProtocol/crypto/tls/ECCurveType.cs
Normal file
33
Assets/BestHTTP/SecureProtocol/crypto/tls/ECCurveType.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 4492 5.4
|
||||
/// </summary>
|
||||
public abstract class ECCurveType
|
||||
{
|
||||
/**
|
||||
* Indicates the elliptic curve domain parameters are conveyed verbosely, and the
|
||||
* underlying finite field is a prime field.
|
||||
*/
|
||||
public const byte explicit_prime = 1;
|
||||
|
||||
/**
|
||||
* Indicates the elliptic curve domain parameters are conveyed verbosely, and the
|
||||
* underlying finite field is a characteristic-2 field.
|
||||
*/
|
||||
public const byte explicit_char2 = 2;
|
||||
|
||||
/**
|
||||
* Indicates that a named curve is used. This option SHOULD be used when applicable.
|
||||
*/
|
||||
public const byte named_curve = 3;
|
||||
|
||||
/*
|
||||
* Values 248 through 255 are reserved for private use.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5873d33f45da3442687faf8facaecc2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/BestHTTP/SecureProtocol/crypto/tls/ECPointFormat.cs
Normal file
20
Assets/BestHTTP/SecureProtocol/crypto/tls/ECPointFormat.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>
|
||||
/// RFC 4492 5.1.2
|
||||
/// </summary>
|
||||
public abstract class ECPointFormat
|
||||
{
|
||||
public const byte uncompressed = 0;
|
||||
public const byte ansiX962_compressed_prime = 1;
|
||||
public const byte ansiX962_compressed_char2 = 2;
|
||||
|
||||
/*
|
||||
* reserved (248..255)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a8cc53cefdc644f18a28e3568f8cdc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 2246</summary>
|
||||
/// <remarks>
|
||||
/// Note that the values here are implementation-specific and arbitrary. It is recommended not to
|
||||
/// depend on the particular values (e.g. serialization).
|
||||
/// </remarks>
|
||||
public abstract class EncryptionAlgorithm
|
||||
{
|
||||
public const int NULL = 0;
|
||||
public const int RC4_40 = 1;
|
||||
public const int RC4_128 = 2;
|
||||
public const int RC2_CBC_40 = 3;
|
||||
public const int IDEA_CBC = 4;
|
||||
public const int DES40_CBC = 5;
|
||||
public const int DES_CBC = 6;
|
||||
public const int cls_3DES_EDE_CBC = 7;
|
||||
|
||||
/*
|
||||
* RFC 3268
|
||||
*/
|
||||
public const int AES_128_CBC = 8;
|
||||
public const int AES_256_CBC = 9;
|
||||
|
||||
/*
|
||||
* RFC 5289
|
||||
*/
|
||||
public const int AES_128_GCM = 10;
|
||||
public const int AES_256_GCM = 11;
|
||||
|
||||
/*
|
||||
* RFC 4132
|
||||
*/
|
||||
public const int CAMELLIA_128_CBC = 12;
|
||||
public const int CAMELLIA_256_CBC = 13;
|
||||
|
||||
/*
|
||||
* RFC 4162
|
||||
*/
|
||||
public const int SEED_CBC = 14;
|
||||
|
||||
/*
|
||||
* RFC 6655
|
||||
*/
|
||||
public const int AES_128_CCM = 15;
|
||||
public const int AES_128_CCM_8 = 16;
|
||||
public const int AES_256_CCM = 17;
|
||||
public const int AES_256_CCM_8 = 18;
|
||||
|
||||
/*
|
||||
* RFC 6367
|
||||
*/
|
||||
public const int CAMELLIA_128_GCM = 19;
|
||||
public const int CAMELLIA_256_GCM = 20;
|
||||
|
||||
/*
|
||||
* draft-ietf-tls-chacha20-poly1305-04
|
||||
*/
|
||||
public const int CHACHA20_POLY1305 = 102;
|
||||
[Obsolete] public const int AEAD_CHACHA20_POLY1305 = CHACHA20_POLY1305;
|
||||
|
||||
/*
|
||||
* draft-zauner-tls-aes-ocb-04
|
||||
*/
|
||||
public const int AES_128_OCB_TAGLEN96 = 103;
|
||||
public const int AES_256_OCB_TAGLEN96 = 104;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e355092606b244d6aaffd4c0d59169d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/BestHTTP/SecureProtocol/crypto/tls/ExporterLabel.cs
Normal file
41
Assets/BestHTTP/SecureProtocol/crypto/tls/ExporterLabel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 5705</summary>
|
||||
public abstract class ExporterLabel
|
||||
{
|
||||
/*
|
||||
* RFC 5246
|
||||
*/
|
||||
public const string client_finished = "client finished";
|
||||
public const string server_finished = "server finished";
|
||||
public const string master_secret = "master secret";
|
||||
public const string key_expansion = "key expansion";
|
||||
|
||||
/*
|
||||
* RFC 5216
|
||||
*/
|
||||
public const string client_EAP_encryption = "client EAP encryption";
|
||||
|
||||
/*
|
||||
* RFC 5281
|
||||
*/
|
||||
public const string ttls_keying_material = "ttls keying material";
|
||||
public const string ttls_challenge = "ttls challenge";
|
||||
|
||||
/*
|
||||
* RFC 5764
|
||||
*/
|
||||
public const string dtls_srtp = "EXTRACTOR-dtls_srtp";
|
||||
|
||||
/*
|
||||
* draft-ietf-tls-session-hash-04
|
||||
*/
|
||||
public static readonly string extended_master_secret = "extended master secret";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52b4f169e43d44baeb890c87bb499ab0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
121
Assets/BestHTTP/SecureProtocol/crypto/tls/ExtensionType.cs
Normal file
121
Assets/BestHTTP/SecureProtocol/crypto/tls/ExtensionType.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class ExtensionType
|
||||
{
|
||||
/*
|
||||
* RFC 2546 2.3.
|
||||
*/
|
||||
public const int server_name = 0;
|
||||
public const int max_fragment_length = 1;
|
||||
public const int client_certificate_url = 2;
|
||||
public const int trusted_ca_keys = 3;
|
||||
public const int truncated_hmac = 4;
|
||||
public const int status_request = 5;
|
||||
|
||||
/*
|
||||
* RFC 4681
|
||||
*/
|
||||
public const int user_mapping = 6;
|
||||
|
||||
/*
|
||||
* RFC 5878
|
||||
*/
|
||||
public const int client_authz = 7;
|
||||
public const int server_authz = 8;
|
||||
|
||||
/*
|
||||
* RFC RFC6091
|
||||
*/
|
||||
public const int cert_type = 9;
|
||||
|
||||
/*
|
||||
* draft-ietf-tls-negotiated-ff-dhe-10
|
||||
*/
|
||||
public const int supported_groups = 10;
|
||||
|
||||
/*
|
||||
* RFC 4492 5.1.
|
||||
*/
|
||||
public const int elliptic_curves = supported_groups;
|
||||
public const int ec_point_formats = 11;
|
||||
|
||||
/*
|
||||
* RFC 5054 2.8.1.
|
||||
*/
|
||||
public const int srp = 12;
|
||||
|
||||
/*
|
||||
* RFC 5246 7.4.1.4.
|
||||
*/
|
||||
public const int signature_algorithms = 13;
|
||||
|
||||
/*
|
||||
* RFC 5764 9.
|
||||
*/
|
||||
public const int use_srtp = 14;
|
||||
|
||||
/*
|
||||
* RFC 6520 6.
|
||||
*/
|
||||
public const int heartbeat = 15;
|
||||
|
||||
/*
|
||||
* RFC 7301
|
||||
*/
|
||||
public const int application_layer_protocol_negotiation = 16;
|
||||
|
||||
/*
|
||||
* RFC 6961
|
||||
*/
|
||||
public const int status_request_v2 = 17;
|
||||
|
||||
/*
|
||||
* RFC 6962
|
||||
*/
|
||||
public const int signed_certificate_timestamp = 18;
|
||||
|
||||
/*
|
||||
* RFC 7250
|
||||
*/
|
||||
public const int client_certificate_type = 19;
|
||||
public const int server_certificate_type = 20;
|
||||
|
||||
/*
|
||||
* RFC 7685
|
||||
*/
|
||||
public const int padding = 21;
|
||||
|
||||
/*
|
||||
* RFC 7366
|
||||
*/
|
||||
public const int encrypt_then_mac = 22;
|
||||
|
||||
/*
|
||||
* RFC 7627
|
||||
*/
|
||||
public const int extended_master_secret = 23;
|
||||
|
||||
/*
|
||||
* RFC 5077 7.
|
||||
*/
|
||||
public const int session_ticket = 35;
|
||||
|
||||
/*
|
||||
* draft-ietf-tls-negotiated-ff-dhe-01
|
||||
*
|
||||
* WARNING: Placeholder value; the real value is TBA
|
||||
*/
|
||||
public static readonly int negotiated_ff_dhe_groups = 101;
|
||||
|
||||
/*
|
||||
* RFC 5746 3.2.
|
||||
*/
|
||||
public const int renegotiation_info = 0xff01;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b4fa8769a7894b7a89f4b99015e0951
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/*
|
||||
* draft-ietf-tls-negotiated-ff-dhe-01
|
||||
*/
|
||||
public abstract class FiniteFieldDheGroup
|
||||
{
|
||||
public const byte ffdhe2432 = 0;
|
||||
public const byte ffdhe3072 = 1;
|
||||
public const byte ffdhe4096 = 2;
|
||||
public const byte ffdhe6144 = 3;
|
||||
public const byte ffdhe8192 = 4;
|
||||
|
||||
public static bool IsValid(byte group)
|
||||
{
|
||||
return group >= ffdhe2432 && group <= ffdhe8192;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: caf51fc83800a47b193c98d748fabf67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/BestHTTP/SecureProtocol/crypto/tls/HandshakeType.cs
Normal file
44
Assets/BestHTTP/SecureProtocol/crypto/tls/HandshakeType.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public abstract class HandshakeType
|
||||
{
|
||||
/*
|
||||
* RFC 2246 7.4
|
||||
*/
|
||||
public const byte hello_request = 0;
|
||||
public const byte client_hello = 1;
|
||||
public const byte server_hello = 2;
|
||||
public const byte certificate = 11;
|
||||
public const byte server_key_exchange = 12;
|
||||
public const byte certificate_request = 13;
|
||||
public const byte server_hello_done = 14;
|
||||
public const byte certificate_verify = 15;
|
||||
public const byte client_key_exchange = 16;
|
||||
public const byte finished = 20;
|
||||
|
||||
/*
|
||||
* RFC 3546 2.4
|
||||
*/
|
||||
public const byte certificate_url = 21;
|
||||
public const byte certificate_status = 22;
|
||||
|
||||
/*
|
||||
* (DTLS) RFC 4347 4.3.2
|
||||
*/
|
||||
public const byte hello_verify_request = 3;
|
||||
|
||||
/*
|
||||
* RFC 4680
|
||||
*/
|
||||
public const byte supplemental_data = 23;
|
||||
|
||||
/*
|
||||
* RFC 5077
|
||||
*/
|
||||
public const byte session_ticket = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 604ab155888a6420b9c8527260f65d46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/BestHTTP/SecureProtocol/crypto/tls/HashAlgorithm.cs
Normal file
53
Assets/BestHTTP/SecureProtocol/crypto/tls/HashAlgorithm.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <summary>RFC 5246 7.4.1.4.1</summary>
|
||||
public abstract class HashAlgorithm
|
||||
{
|
||||
public const byte none = 0;
|
||||
public const byte md5 = 1;
|
||||
public const byte sha1 = 2;
|
||||
public const byte sha224 = 3;
|
||||
public const byte sha256 = 4;
|
||||
public const byte sha384 = 5;
|
||||
public const byte sha512 = 6;
|
||||
|
||||
public static string GetName(byte hashAlgorithm)
|
||||
{
|
||||
switch (hashAlgorithm)
|
||||
{
|
||||
case none:
|
||||
return "none";
|
||||
case md5:
|
||||
return "md5";
|
||||
case sha1:
|
||||
return "sha1";
|
||||
case sha224:
|
||||
return "sha224";
|
||||
case sha256:
|
||||
return "sha256";
|
||||
case sha384:
|
||||
return "sha384";
|
||||
case sha512:
|
||||
return "sha512";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetText(byte hashAlgorithm)
|
||||
{
|
||||
return GetName(hashAlgorithm) + "(" + hashAlgorithm + ")";
|
||||
}
|
||||
|
||||
public static bool IsPrivate(byte hashAlgorithm)
|
||||
{
|
||||
return 224 <= hashAlgorithm && hashAlgorithm <= 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85b3ff4e121ff4e1ab1e827565ae35c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
public class HeartbeatExtension
|
||||
{
|
||||
protected readonly byte mMode;
|
||||
|
||||
public HeartbeatExtension(byte mode)
|
||||
{
|
||||
if (!HeartbeatMode.IsValid(mode))
|
||||
throw new ArgumentException("not a valid HeartbeatMode value", "mode");
|
||||
|
||||
this.mMode = mode;
|
||||
}
|
||||
|
||||
public virtual byte Mode
|
||||
{
|
||||
get { return mMode; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this {@link HeartbeatExtension} to a {@link Stream}.
|
||||
*
|
||||
* @param output
|
||||
* the {@link Stream} to encode to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public virtual void Encode(Stream output)
|
||||
{
|
||||
TlsUtilities.WriteUint8(mMode, output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link HeartbeatExtension} from a {@link Stream}.
|
||||
*
|
||||
* @param input
|
||||
* the {@link Stream} to parse from.
|
||||
* @return a {@link HeartbeatExtension} object.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static HeartbeatExtension Parse(Stream input)
|
||||
{
|
||||
byte mode = TlsUtilities.ReadUint8(input);
|
||||
if (!HeartbeatMode.IsValid(mode))
|
||||
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
|
||||
|
||||
return new HeartbeatExtension(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0032f3d2cfd6747eb94db5bff3de7120
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/*
|
||||
* RFC 6520 3.
|
||||
*/
|
||||
public abstract class HeartbeatMessageType
|
||||
{
|
||||
public const byte heartbeat_request = 1;
|
||||
public const byte heartbeat_response = 2;
|
||||
|
||||
public static bool IsValid(byte heartbeatMessageType)
|
||||
{
|
||||
return heartbeatMessageType >= heartbeat_request && heartbeatMessageType <= heartbeat_response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6ae1bb55902c417d8bb5e9ab255114f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/BestHTTP/SecureProtocol/crypto/tls/HeartbeatMode.cs
Normal file
22
Assets/BestHTTP/SecureProtocol/crypto/tls/HeartbeatMode.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/*
|
||||
* RFC 6520
|
||||
*/
|
||||
public abstract class HeartbeatMode
|
||||
{
|
||||
public const byte peer_allowed_to_send = 1;
|
||||
public const byte peer_not_allowed_to_send = 2;
|
||||
|
||||
public static bool IsValid(byte heartbeatMode)
|
||||
{
|
||||
return heartbeatMode >= peer_allowed_to_send && heartbeatMode <= peer_not_allowed_to_send;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d96d007dca601420b81defcd4877aa11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Tls
|
||||
{
|
||||
/// <remarks>
|
||||
/// This should be implemented by any class which can find out, if a given
|
||||
/// certificate chain is being accepted by an client.
|
||||
/// </remarks>
|
||||
//[Obsolete("Perform certificate verification in TlsAuthentication implementation")]
|
||||
public interface ICertificateVerifyer
|
||||
{
|
||||
/// <param name="certs">The certs, which are part of the chain.</param>
|
||||
/// <param name="targetUri"></param>
|
||||
/// <returns>True, if the chain is accepted, false otherwise</returns>
|
||||
bool IsValid(Uri targetUri, X509CertificateStructure[] certs);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87fc3eff9f3a9446e804bbf8461b3e52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user