diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-07-12 15:15:36 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-07-12 15:15:36 +0700 |
commit | 68c795fe81277f73aeb90d8ad4c6f4305f32c906 (patch) | |
tree | 59643344aafef91bbd4c4a3a7973deba3d837a00 /crypto/src/tls/AbstractTlsKeyExchange.cs | |
parent | TLS test tweaks (diff) | |
download | BouncyCastle.NET-ed25519-68c795fe81277f73aeb90d8ad4c6f4305f32c906.tar.xz |
Port of new TLS API from bc-java
Diffstat (limited to 'crypto/src/tls/AbstractTlsKeyExchange.cs')
-rw-r--r-- | crypto/src/tls/AbstractTlsKeyExchange.cs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/crypto/src/tls/AbstractTlsKeyExchange.cs b/crypto/src/tls/AbstractTlsKeyExchange.cs new file mode 100644 index 000000000..4e61f4c5a --- /dev/null +++ b/crypto/src/tls/AbstractTlsKeyExchange.cs @@ -0,0 +1,90 @@ +using System; +using System.IO; + +using Org.BouncyCastle.Tls.Crypto; + +namespace Org.BouncyCastle.Tls +{ + /// <summary>Base class for supporting a TLS key exchange implementation.</summary> + public abstract class AbstractTlsKeyExchange + : TlsKeyExchange + { + protected readonly int m_keyExchange; + + protected TlsContext m_context; + + protected AbstractTlsKeyExchange(int keyExchange) + { + this.m_keyExchange = keyExchange; + } + + public virtual void Init(TlsContext context) + { + this.m_context = context; + } + + public abstract void SkipServerCredentials(); + + public abstract void ProcessServerCredentials(TlsCredentials serverCredentials); + + public virtual void ProcessServerCertificate(Certificate serverCertificate) + { + throw new TlsFatalAlert(AlertDescription.internal_error); + } + + 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 virtual short[] GetClientCertificateTypes() + { + return null; + } + + 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 virtual bool RequiresCertificateVerify + { + get { return true; } + } + + public abstract TlsSecret GeneratePreMasterSecret(); + } +} |