TlsClient.cs 6.3 KB

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