TlsPeer.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 interface for a (D)TLS endpoint.</summary>
  9. public interface TlsPeer
  10. {
  11. TlsCrypto Crypto { get; }
  12. void NotifyCloseHandle(TlsCloseable closehandle);
  13. /// <exception cref="IOException"/>
  14. void Cancel();
  15. ProtocolVersion[] GetProtocolVersions();
  16. int[] GetCipherSuites();
  17. /// <summary>Notifies the peer that a new handshake is about to begin.</summary>
  18. /// <exception cref="IOException"/>
  19. void NotifyHandshakeBeginning();
  20. /// <summary>Specify the timeout, in milliseconds, to use for the complete handshake process.</summary>
  21. /// <remarks>
  22. /// NOTE: Currently only respected by DTLS protocols. Negative values are not allowed. A timeout of zero means
  23. /// an infinite timeout (i.e.the handshake will never time out).
  24. /// </remarks>
  25. /// <returns>the handshake timeout, in milliseconds.</returns>
  26. int GetHandshakeTimeoutMillis();
  27. bool AllowLegacyResumption();
  28. int GetMaxCertificateChainLength();
  29. int GetMaxHandshakeMessageSize();
  30. short[] GetPskKeyExchangeModes();
  31. /// <remarks>
  32. /// This option is provided as a last resort for interoperability with TLS peers that fail to correctly send a
  33. /// close_notify alert at end of stream. Implementations SHOULD return true; caution is advised if returning
  34. /// false without a full understanding of the implications.
  35. /// </remarks>
  36. bool RequiresCloseNotify();
  37. /// <remarks>This implementation supports RFC 7627 and will always negotiate the extended_master_secret
  38. /// extension where possible. When connecting to a peer that does not offer/accept this extension, it is
  39. /// recommended to abort the handshake.This option is provided for interoperability with legacy peers, although
  40. /// some TLS features will be disabled in that case (see RFC 7627 5.4).
  41. /// </remarks>
  42. /// <returns><c>true</c> if the handshake should be aborted when the peer does not negotiate the
  43. /// extended_master_secret extension, or <c>false</c> to support legacy interoperability.</returns>
  44. bool RequiresExtendedMasterSecret();
  45. bool ShouldUseExtendedMasterSecret();
  46. /// <summary>See RFC 5246 6.2.3.2. Controls whether block cipher encryption may randomly add extra padding
  47. /// beyond the minimum.</summary>
  48. /// <remarks>
  49. /// Note that in configurations where this is known to be potential security risk this setting will be ignored
  50. /// (and extended padding disabled). Extra padding is always supported when decrypting received records.
  51. /// </remarks>
  52. /// <returns><c>true</c> if random extra padding should be added during block cipher encryption, or
  53. /// <c>false</c> to always use the minimum amount of required padding.</returns>
  54. bool ShouldUseExtendedPadding();
  55. /// <summary> draft-mathewson-no-gmtunixtime-00 2. "If existing users of a TLS implementation may rely on
  56. /// gmt_unix_time containing the current time, we recommend that implementors MAY provide the ability to set
  57. /// gmt_unix_time as an option only, off by default.".</summary>
  58. /// <remarks>
  59. /// NOTE: For a server that has negotiated TLS 1.3 (or later), or a client that has offered TLS 1.3 (or later),
  60. /// this is not called and gmt_unix_time is not used.
  61. /// </remarks>
  62. /// <returns><c>true</c> if the current time should be used in the gmt_unix_time field of Random, or
  63. /// <c>false</c> if gmt_unix_time should contain a cryptographically random value.</returns>
  64. bool ShouldUseGmtUnixTime();
  65. /// <summary>RFC 5746 3.4/3.6. In case this is false, peers may want to terminate the handshake instead of
  66. /// continuing; see Section 4.1/4.3 for discussion.</summary>
  67. /// <remarks>
  68. /// NOTE: TLS 1.3 forbids renegotiation, so this is never called when TLS 1.3 (or later) was negotiated.
  69. /// </remarks>
  70. /// <exception cref="IOException"/>
  71. void NotifySecureRenegotiation(bool secureRenegotiation);
  72. /// <exception cref="IOException"/>
  73. TlsKeyExchangeFactory GetKeyExchangeFactory();
  74. /// <summary>This method will be called when an alert is raised by the protocol.</summary>
  75. /// <param name="alertLevel"><see cref="AlertLevel"/></param>
  76. /// <param name="alertDescription"><see cref="AlertDescription"/></param>
  77. /// <param name="message">A human-readable message explaining what caused this alert. May be null.</param>
  78. /// <param name="cause">The <see cref="Exception"/> that caused this alert to be raised. May be null.</param>
  79. void NotifyAlertRaised(short alertLevel, short alertDescription, string message, Exception cause);
  80. /// <summary>This method will be called when an alert is received from the remote peer.</summary>
  81. /// <param name="alertLevel"><see cref="AlertLevel"/></param>
  82. /// <param name="alertDescription"><see cref="AlertDescription"/></param>
  83. void NotifyAlertReceived(short alertLevel, short alertDescription);
  84. /// <summary>Notifies the peer that the handshake has been successfully completed.</summary>
  85. /// <exception cref="IOException"/>
  86. void NotifyHandshakeComplete();
  87. /// <summary>Return a <see cref="TlsHeartbeat"/> instance that will control the generation of heartbeats
  88. /// locally (if permitted by the remote peer), or null to not generate heartbeats. Heartbeats are described in
  89. /// RFC 6520.</summary>
  90. /// <returns>an instance of <see cref="TlsHeartbeat"/>.</returns>
  91. /// <seealso cref="DefaultTlsHeartbeat"/>
  92. TlsHeartbeat GetHeartbeat();
  93. /// <summary>Return the heartbeat mode applicable to the remote peer. Heartbeats are described in RFC 6520.
  94. /// </summary>
  95. /// <remarks>
  96. /// See enumeration class <see cref="HeartbeatMode"/> for appropriate return values.
  97. /// </remarks>
  98. /// <returns>the <see cref="HeartbeatMode"/> value.</returns>
  99. short GetHeartbeatPolicy();
  100. }
  101. }
  102. #pragma warning restore
  103. #endif