AbstractTlsKeyExchange.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  7. {
  8. /// <summary>Base class for supporting a TLS key exchange implementation.</summary>
  9. public abstract class AbstractTlsKeyExchange
  10. : TlsKeyExchange
  11. {
  12. protected readonly int m_keyExchange;
  13. protected TlsContext m_context;
  14. protected AbstractTlsKeyExchange(int keyExchange)
  15. {
  16. this.m_keyExchange = keyExchange;
  17. }
  18. public virtual void Init(TlsContext context)
  19. {
  20. this.m_context = context;
  21. }
  22. public abstract void SkipServerCredentials();
  23. public abstract void ProcessServerCredentials(TlsCredentials serverCredentials);
  24. public virtual void ProcessServerCertificate(Certificate serverCertificate)
  25. {
  26. throw new TlsFatalAlert(AlertDescription.internal_error);
  27. }
  28. public virtual bool RequiresServerKeyExchange
  29. {
  30. get { return false; }
  31. }
  32. public virtual byte[] GenerateServerKeyExchange()
  33. {
  34. if (RequiresServerKeyExchange)
  35. throw new TlsFatalAlert(AlertDescription.internal_error);
  36. return null;
  37. }
  38. public virtual void SkipServerKeyExchange()
  39. {
  40. if (RequiresServerKeyExchange)
  41. throw new TlsFatalAlert(AlertDescription.unexpected_message);
  42. }
  43. public virtual void ProcessServerKeyExchange(Stream input)
  44. {
  45. if (!RequiresServerKeyExchange)
  46. throw new TlsFatalAlert(AlertDescription.unexpected_message);
  47. }
  48. public virtual short[] GetClientCertificateTypes()
  49. {
  50. return null;
  51. }
  52. public virtual void SkipClientCredentials()
  53. {
  54. }
  55. public abstract void ProcessClientCredentials(TlsCredentials clientCredentials);
  56. public virtual void ProcessClientCertificate(Certificate clientCertificate)
  57. {
  58. }
  59. public abstract void GenerateClientKeyExchange(Stream output);
  60. public virtual void ProcessClientKeyExchange(Stream input)
  61. {
  62. // Key exchange implementation MUST support client key exchange
  63. throw new TlsFatalAlert(AlertDescription.internal_error);
  64. }
  65. public virtual bool RequiresCertificateVerify
  66. {
  67. get { return true; }
  68. }
  69. public abstract TlsSecret GeneratePreMasterSecret();
  70. }
  71. }
  72. #pragma warning restore
  73. #endif