TlsClient.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  7. {
  8. public interface TlsClient
  9. : TlsPeer
  10. {
  11. void Init(TlsClientContext context);
  12. /// <summary>Return the session this client wants to resume, if any.</summary>
  13. /// <remarks>
  14. /// Note that the peer's certificate chain for the session (if any) may need to be periodically revalidated.
  15. /// </remarks>
  16. /// <returns>A <see cref="TlsSession"/> representing the resumable session to be used for this connection, or
  17. /// null to use a new session.</returns>
  18. /// <seealso cref="SessionParameters.PeerCertificate"/>
  19. TlsSession GetSessionToResume();
  20. /// <summary>Return the <see cref="TlsPskExternal">external PSKs</see> to offer in the ClientHello.</summary>
  21. /// <remarks>This will only be called when TLS 1.3 or higher is amongst the offered protocol versions.</remarks>
  22. /// <returns>an <see cref="IList{T}"/> of <see cref="TlsPskExternal"/> instances, or null if none should be
  23. /// offered.</returns>
  24. IList<TlsPskExternal> GetExternalPsks();
  25. bool IsFallback();
  26. /// <returns>(Int32 -> byte[])</returns>
  27. /// <exception cref="IOException"/>
  28. IDictionary<int, byte[]> GetClientExtensions();
  29. /// <summary>If this client is offering TLS 1.3 or higher, this method may be called to determine for which
  30. /// groups a key share should be included in the initial ClientHello.</summary>
  31. /// <remarks>
  32. /// Groups that were not included in the supported_groups extension (by <see cref="GetClientExtensions"/> will
  33. /// be ignored. The protocol will then add a suitable key_share extension to the ClientHello extensions.
  34. /// </remarks>
  35. /// <returns>an <see cref="IList{T}"/> of <see cref="NamedGroup">named group</see> values, possibly empty or
  36. /// null.
  37. /// </returns>
  38. IList<int> GetEarlyKeyShareGroups();
  39. /// <exception cref="IOException"/>
  40. void NotifyServerVersion(ProtocolVersion selectedVersion);
  41. /// <summary>Notifies the client of the session that will be offered in ClientHello for resumption, if any.
  42. /// </summary>
  43. /// <remarks>
  44. /// This will be either the session returned from {@link #getSessionToResume()} or null if that session was
  45. /// unusable. NOTE: the actual negotiated session_id is notified by <see cref="NotifySessionID(byte[])"/>.
  46. /// </remarks>
  47. /// <param name="session">The <see cref="TlsSession"/> representing the resumable session to be offered for
  48. /// this connection, or null if there is none.</param>
  49. /// <seealso cref="NotifySessionID(byte[])"/>
  50. void NotifySessionToResume(TlsSession session);
  51. /// <summary>Notifies the client of the session_id sent in the ServerHello.</summary>
  52. /// <param name="sessionID"/>
  53. /// <seealso cref="TlsContext.Session"/>
  54. void NotifySessionID(byte[] sessionID);
  55. void NotifySelectedCipherSuite(int selectedCipherSuite);
  56. /// <exception cref="IOException"/>
  57. void NotifySelectedPsk(TlsPsk selectedPsk);
  58. /// <summary>The protocol implementation validates that any server extensions received correspond to client
  59. /// extensions sent.</summary>
  60. /// <remarks>
  61. /// If further processing of the server extensions is needed, it can be done in this callback. NOTE: This is
  62. /// not called for session resumption handshakes.
  63. /// </remarks>
  64. /// <param name="serverExtensions">(Int32 -> byte[])</param>
  65. /// <exception cref="IOException"/>
  66. void ProcessServerExtensions(IDictionary<int, byte[]> serverExtensions);
  67. /// <param name="serverSupplementalData">(SupplementalDataEntry)</param>
  68. /// <exception cref="IOException"/>
  69. void ProcessServerSupplementalData(IList<SupplementalDataEntry> serverSupplementalData);
  70. /// <exception cref="IOException"/>
  71. TlsPskIdentity GetPskIdentity();
  72. /// <exception cref="IOException"/>
  73. TlsSrpIdentity GetSrpIdentity();
  74. /// <exception cref="IOException"/>
  75. TlsDHGroupVerifier GetDHGroupVerifier();
  76. /// <exception cref="IOException"/>
  77. TlsSrpConfigVerifier GetSrpConfigVerifier();
  78. /// <exception cref="IOException"/>
  79. TlsAuthentication GetAuthentication();
  80. /// <returns>(SupplementalDataEntry)</returns>
  81. /// <exception cref="IOException"/>
  82. IList<SupplementalDataEntry> GetClientSupplementalData();
  83. /// <summary>RFC 5077 3.3. NewSessionTicket Handshake Message</summary>
  84. /// <remarks>
  85. /// This method will be called (only) when a NewSessionTicket handshake message is received. The ticket is
  86. /// opaque to the client and clients MUST NOT examine the ticket under the assumption that it complies with e.g.
  87. /// RFC 5077 4. "Recommended Ticket Construction".
  88. /// </remarks>
  89. /// <param name="newSessionTicket">The ticket.</param>
  90. /// <exception cref="IOException"/>
  91. void NotifyNewSessionTicket(NewSessionTicket newSessionTicket);
  92. }
  93. }
  94. #pragma warning restore
  95. #endif