TlsClient.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using System.IO;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls
  7. {
  8. public interface TlsClient
  9. : TlsPeer
  10. {
  11. System.Collections.Generic.List<string> HostNames { get; set; }
  12. /// <summary>
  13. /// Called at the start of a new TLS session, before any other methods.
  14. /// </summary>
  15. /// <param name="context">
  16. /// A <see cref="TlsProtocolHandler"/>
  17. /// </param>
  18. void Init(TlsClientContext context);
  19. /// <summary>Return the session this client wants to resume, if any.</summary>
  20. /// <remarks>Note that the peer's certificate chain for the session (if any) may need to be periodically revalidated.</remarks>
  21. /// <returns>
  22. /// A <see cref="TlsSession"/> representing the resumable session to be used for this connection,
  23. /// or null to use a new session.
  24. /// </returns>
  25. TlsSession GetSessionToResume();
  26. /// <summary>
  27. /// Return the <see cref="ProtocolVersion"/> to use for the <c>TLSPlaintext.version</c> field prior to
  28. /// receiving the server version. NOTE: This method is <b>not</b> called for DTLS.
  29. /// </summary>
  30. /// <remarks>
  31. /// See RFC 5246 E.1.: "TLS clients that wish to negotiate with older servers MAY send any value
  32. /// {03,XX} as the record layer version number. Typical values would be {03,00}, the lowest
  33. /// version number supported by the client, and the value of ClientHello.client_version. No
  34. /// single value will guarantee interoperability with all old servers, but this is a complex
  35. /// topic beyond the scope of this document."
  36. /// </remarks>
  37. /// <returns>The <see cref="ProtocolVersion"/> to use.</returns>
  38. ProtocolVersion ClientHelloRecordLayerVersion { get; }
  39. ProtocolVersion ClientVersion { get; }
  40. bool IsFallback { get; }
  41. /// <summary>
  42. /// Get the list of cipher suites that this client supports.
  43. /// </summary>
  44. /// <returns>
  45. /// An array of <see cref="CipherSuite"/> values, each specifying a supported cipher suite.
  46. /// </returns>
  47. int[] GetCipherSuites();
  48. /// <summary>
  49. /// Get the list of compression methods that this client supports.
  50. /// </summary>
  51. /// <returns>
  52. /// An array of <see cref="CompressionMethod"/> values, each specifying a supported compression method.
  53. /// </returns>
  54. byte[] GetCompressionMethods();
  55. /// <summary>
  56. /// Get the (optional) table of client extensions to be included in (extended) client hello.
  57. /// </summary>
  58. /// <returns>
  59. /// A <see cref="IDictionary"/> (Int32 -> byte[]). May be null.
  60. /// </returns>
  61. /// <exception cref="IOException"></exception>
  62. IDictionary GetClientExtensions();
  63. /// <exception cref="IOException"></exception>
  64. void NotifyServerVersion(ProtocolVersion selectedVersion);
  65. /// <summary>
  66. /// Notifies the client of the session_id sent in the ServerHello.
  67. /// </summary>
  68. /// <param name="sessionID">An array of <see cref="System.Byte"/></param>
  69. void NotifySessionID(byte[] sessionID);
  70. /// <summary>
  71. /// Report the cipher suite that was selected by the server.
  72. /// </summary>
  73. /// <remarks>
  74. /// The protocol handler validates this value against the offered cipher suites
  75. /// <seealso cref="GetCipherSuites"/>
  76. /// </remarks>
  77. /// <param name="selectedCipherSuite">
  78. /// A <see cref="CipherSuite"/>
  79. /// </param>
  80. void NotifySelectedCipherSuite(int selectedCipherSuite);
  81. /// <summary>
  82. /// Report the compression method that was selected by the server.
  83. /// </summary>
  84. /// <remarks>
  85. /// The protocol handler validates this value against the offered compression methods
  86. /// <seealso cref="GetCompressionMethods"/>
  87. /// </remarks>
  88. /// <param name="selectedCompressionMethod">
  89. /// A <see cref="CompressionMethod"/>
  90. /// </param>
  91. void NotifySelectedCompressionMethod(byte selectedCompressionMethod);
  92. /// <summary>
  93. /// Report the extensions from an extended server hello.
  94. /// </summary>
  95. /// <remarks>
  96. /// Will only be called if we returned a non-null result from <see cref="GetClientExtensions"/>.
  97. /// </remarks>
  98. /// <param name="serverExtensions">
  99. /// A <see cref="IDictionary"/> (Int32 -> byte[])
  100. /// </param>
  101. void ProcessServerExtensions(IDictionary serverExtensions);
  102. /// <param name="serverSupplementalData">A <see cref="IList">list</see> of <see cref="SupplementalDataEntry"/></param>
  103. /// <exception cref="IOException"/>
  104. void ProcessServerSupplementalData(IList serverSupplementalData);
  105. /// <summary>
  106. /// Return an implementation of <see cref="TlsKeyExchange"/> to negotiate the key exchange
  107. /// part of the protocol.
  108. /// </summary>
  109. /// <returns>
  110. /// A <see cref="TlsKeyExchange"/>
  111. /// </returns>
  112. /// <exception cref="IOException"/>
  113. TlsKeyExchange GetKeyExchange();
  114. /// <summary>
  115. /// Return an implementation of <see cref="TlsAuthentication"/> to handle authentication
  116. /// part of the protocol.
  117. /// </summary>
  118. /// <exception cref="IOException"/>
  119. TlsAuthentication GetAuthentication();
  120. /// <returns>A <see cref="IList">list</see> of <see cref="SupplementalDataEntry"/></returns>
  121. /// <exception cref="IOException"/>
  122. IList GetClientSupplementalData();
  123. /// <summary>RFC 5077 3.3. NewSessionTicket Handshake Message</summary>
  124. /// <remarks>
  125. /// This method will be called (only) when a NewSessionTicket handshake message is received. The
  126. /// ticket is opaque to the client and clients MUST NOT examine the ticket under the assumption
  127. /// that it complies with e.g. <i>RFC 5077 4. Recommended Ticket Construction</i>.
  128. /// </remarks>
  129. /// <param name="newSessionTicket">The <see cref="NewSessionTicket">ticket</see></param>
  130. /// <exception cref="IOException"/>
  131. void NotifyNewSessionTicket(NewSessionTicket newSessionTicket);
  132. }
  133. }
  134. #pragma warning restore
  135. #endif