TlsContext.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. /// <summary>Base interface for a TLS context implementation.</summary>
  8. public interface TlsContext
  9. {
  10. TlsCrypto Crypto { get; }
  11. TlsNonceGenerator NonceGenerator { get; }
  12. SecurityParameters SecurityParameters { get; }
  13. /// <summary>Return true if this context is for a server, false otherwise.</summary>
  14. /// <returns>true for a server based context, false for a client based one.</returns>
  15. bool IsServer { get; }
  16. ProtocolVersion[] ClientSupportedVersions { get; }
  17. ProtocolVersion ClientVersion { get; }
  18. ProtocolVersion RsaPreMasterSecretVersion { get; }
  19. ProtocolVersion ServerVersion { get; }
  20. /// <summary>Used to get the resumable session, if any, used by this connection.</summary>
  21. /// <remarks>
  22. /// Only available after the handshake has successfully completed.
  23. /// </remarks>
  24. /// <returns>A <see cref="TlsSession"/> representing the resumable session used by this connection, or null if
  25. /// no resumable session available.</returns>
  26. /// <seealso cref="TlsPeer.NotifyHandshakeComplete"/>
  27. TlsSession ResumableSession { get; }
  28. /// <summary>Used to get the session information for this connection.</summary>
  29. /// <remarks>
  30. /// Only available after the handshake has successfully completed. Use <see cref="TlsSession.IsResumable"/>
  31. /// to find out if the session is resumable.
  32. /// </remarks>
  33. /// <returns>A <see cref="TlsSession"/> representing the session used by this connection.</returns>
  34. /// <seealso cref="TlsPeer.NotifyHandshakeComplete"/>
  35. TlsSession Session { get; }
  36. object UserObject { get; set; }
  37. /// <summary>Export the value of the specified channel binding.</summary>
  38. /// <remarks>
  39. /// Only available after the handshake has successfully completed.
  40. /// </remarks>
  41. /// <param name="channelBinding">A <see cref="ChannelBinding"/> constant specifying the channel binding to
  42. /// export.</param>
  43. /// <returns>A copy of the channel binding data as a <c>byte[]</c>, or null if the binding could not be
  44. /// determined.</returns>
  45. byte[] ExportChannelBinding(int channelBinding);
  46. /// <summary>Export (early data) keying material according to RFC 5705: "Keying Material Exporters for TLS", as
  47. /// updated for TLS 1.3 (RFC 8446).</summary>
  48. /// <remarks>
  49. /// NOTE: for use in settings where an exporter is needed for 0-RTT data.
  50. /// </remarks>
  51. /// <param name="asciiLabel">indicates which application will use the exported keys.</param>
  52. /// <param name="context_value">allows the application using the exporter to mix its own data with the TLS PRF
  53. /// for the exporter output.</param>
  54. /// <param name="length">the number of bytes to generate.</param>
  55. /// <returns>a pseudorandom bit string of 'length' bytes generated from the (exporter_)master_secret.</returns>
  56. byte[] ExportEarlyKeyingMaterial(string asciiLabel, byte[] context_value, int length);
  57. /// <summary>Export keying material according to RFC 5705: "Keying Material Exporters for TLS", as updated for
  58. /// TLS 1.3 (RFC 8446) when negotiated.</summary>
  59. /// <param name="asciiLabel">indicates which application will use the exported keys.</param>
  60. /// <param name="context_value">allows the application using the exporter to mix its own data with the TLS PRF
  61. /// for the exporter output.</param>
  62. /// <param name="length">the number of bytes to generate.</param>
  63. /// <returns>a pseudorandom bit string of 'length' bytes generated from the (exporter_)master_secret.</returns>
  64. byte[] ExportKeyingMaterial(string asciiLabel, byte[] context_value, int length);
  65. }
  66. }
  67. #pragma warning restore
  68. #endif