2
0

IKeyExchange.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Security.Cryptography;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Compression;
  5. using Renci.SshNet.Messages.Transport;
  6. using Renci.SshNet.Security.Cryptography;
  7. namespace Renci.SshNet.Security
  8. {
  9. /// <summary>
  10. /// Represents a key exchange algorithm.
  11. /// </summary>
  12. public interface IKeyExchange : IDisposable
  13. {
  14. /// <summary>
  15. /// Occurs when the host key is received.
  16. /// </summary>
  17. event EventHandler<HostKeyEventArgs> HostKeyReceived;
  18. /// <summary>
  19. /// Gets the name of the algorithm.
  20. /// </summary>
  21. /// <value>
  22. /// The name of the algorithm.
  23. /// </value>
  24. string Name { get; }
  25. /// <summary>
  26. /// Gets the exchange hash.
  27. /// </summary>
  28. /// <value>
  29. /// The exchange hash.
  30. /// </value>
  31. byte[] ExchangeHash { get; }
  32. /// <summary>
  33. /// Starts the key exchange algorithm.
  34. /// </summary>
  35. /// <param name="session">The session.</param>
  36. /// <param name="message">The key exchange init message received from the server.</param>
  37. /// <param name="sendClientInitMessage">Whether to send a key exchange init message in response.</param>
  38. void Start(Session session, KeyExchangeInitMessage message, bool sendClientInitMessage);
  39. /// <summary>
  40. /// Finishes the key exchange algorithm.
  41. /// </summary>
  42. void Finish();
  43. /// <summary>
  44. /// Creates the client-side cipher to use.
  45. /// </summary>
  46. /// <returns>
  47. /// The client cipher.
  48. /// </returns>
  49. Cipher CreateClientCipher();
  50. /// <summary>
  51. /// Creates the server-side cipher to use.
  52. /// </summary>
  53. /// <returns>
  54. /// The server cipher.
  55. /// </returns>
  56. Cipher CreateServerCipher();
  57. /// <summary>
  58. /// Creates the server-side hash algorithm to use.
  59. /// </summary>
  60. /// <param name="isEncryptThenMAC"><see langword="true"/> to enable encrypt-then-MAC, <see langword="false"/> to use encrypt-and-MAC.</param>
  61. /// <returns>
  62. /// The server hash algorithm.
  63. /// </returns>
  64. HashAlgorithm CreateServerHash(out bool isEncryptThenMAC);
  65. /// <summary>
  66. /// Creates the client-side hash algorithm to use.
  67. /// </summary>
  68. /// <param name="isEncryptThenMAC"><see langword="true"/> to enable encrypt-then-MAC, <see langword="false"/> to use encrypt-and-MAC.</param>
  69. /// <returns>
  70. /// The client hash algorithm.
  71. /// </returns>
  72. HashAlgorithm CreateClientHash(out bool isEncryptThenMAC);
  73. /// <summary>
  74. /// Creates the compression algorithm to use to deflate data.
  75. /// </summary>
  76. /// <returns>
  77. /// The compression method to deflate data.
  78. /// </returns>
  79. Compressor CreateCompressor();
  80. /// <summary>
  81. /// Creates the compression algorithm to use to inflate data.
  82. /// </summary>
  83. /// <returns>
  84. /// The compression method to inflate data.
  85. /// </returns>
  86. Compressor CreateDecompressor();
  87. }
  88. }