KeyExchangeInitMessage.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using Renci.SshNet.Abstractions;
  2. namespace Renci.SshNet.Messages.Transport
  3. {
  4. /// <summary>
  5. /// Represents SSH_MSG_KEXINIT message.
  6. /// </summary>
  7. [Message("SSH_MSG_KEXINIT", 20)]
  8. public class KeyExchangeInitMessage : Message, IKeyExchangedAllowed
  9. {
  10. /// <summary>
  11. /// Initializes a new instance of the <see cref="KeyExchangeInitMessage"/> class.
  12. /// </summary>
  13. public KeyExchangeInitMessage()
  14. {
  15. var cookie = new byte[16];
  16. CryptoAbstraction.GenerateRandom(cookie);
  17. Cookie = cookie;
  18. }
  19. #region Message Properties
  20. /// <summary>
  21. /// Gets session cookie.
  22. /// </summary>
  23. public byte[] Cookie { get; private set; }
  24. /// <summary>
  25. /// Gets or sets supported key exchange algorithms.
  26. /// </summary>
  27. /// <value>
  28. /// Supported key exchange algorithms.
  29. /// </value>
  30. public string[] KeyExchangeAlgorithms { get; set; }
  31. /// <summary>
  32. /// Gets or sets supported server host key algorithms.
  33. /// </summary>
  34. /// <value>
  35. /// Supported server host key algorithms.
  36. /// </value>
  37. public string[] ServerHostKeyAlgorithms { get; set; }
  38. /// <summary>
  39. /// Gets or sets supported encryption algorithms client to server.
  40. /// </summary>
  41. /// <value>
  42. /// Supported encryption algorithms client to server.
  43. /// </value>
  44. public string[] EncryptionAlgorithmsClientToServer { get; set; }
  45. /// <summary>
  46. /// Gets or sets supported encryption algorithms server to client.
  47. /// </summary>
  48. /// <value>
  49. /// Supported encryption algorithms server to client.
  50. /// </value>
  51. public string[] EncryptionAlgorithmsServerToClient { get; set; }
  52. /// <summary>
  53. /// Gets or sets supported hash algorithms client to server.
  54. /// </summary>
  55. /// <value>
  56. /// Supported hash algorithms client to server.
  57. /// </value>
  58. public string[] MacAlgorithmsClientToServer { get; set; }
  59. /// <summary>
  60. /// Gets or sets supported hash algorithms server to client.
  61. /// </summary>
  62. /// <value>
  63. /// Supported hash algorithms server to client.
  64. /// </value>
  65. public string[] MacAlgorithmsServerToClient { get; set; }
  66. /// <summary>
  67. /// Gets or sets supported compression algorithms client to server.
  68. /// </summary>
  69. /// <value>
  70. /// Supported compression algorithms client to server.
  71. /// </value>
  72. public string[] CompressionAlgorithmsClientToServer { get; set; }
  73. /// <summary>
  74. /// Gets or sets supported compression algorithms server to client.
  75. /// </summary>
  76. /// <value>
  77. /// Supported compression algorithms server to client.
  78. /// </value>
  79. public string[] CompressionAlgorithmsServerToClient { get; set; }
  80. /// <summary>
  81. /// Gets or sets supported languages client to server.
  82. /// </summary>
  83. /// <value>
  84. /// Supported languages client to server.
  85. /// </value>
  86. public string[] LanguagesClientToServer { get; set; }
  87. /// <summary>
  88. /// Gets or sets supported languages server to client.
  89. /// </summary>
  90. /// <value>
  91. /// The languages server to client.
  92. /// </value>
  93. public string[] LanguagesServerToClient { get; set; }
  94. /// <summary>
  95. /// Gets or sets a value indicating whether first key exchange packet follows.
  96. /// </summary>
  97. /// <value>
  98. /// <c>true</c> if first key exchange packet follows; otherwise, <c>false</c>.
  99. /// </value>
  100. public bool FirstKexPacketFollows { get; set; }
  101. /// <summary>
  102. /// Gets or sets the reserved value.
  103. /// </summary>
  104. /// <value>
  105. /// The reserved value.
  106. /// </value>
  107. public uint Reserved { get; set; }
  108. #endregion
  109. /// <summary>
  110. /// Gets the size of the message in bytes.
  111. /// </summary>
  112. /// <value>
  113. /// <c>-1</c> to indicate that the size of the message cannot be determined,
  114. /// or is too costly to calculate.
  115. /// </value>
  116. protected override int BufferCapacity
  117. {
  118. get { return -1; }
  119. }
  120. /// <summary>
  121. /// Called when type specific data need to be loaded.
  122. /// </summary>
  123. protected override void LoadData()
  124. {
  125. Cookie = ReadBytes(16);
  126. KeyExchangeAlgorithms = ReadNamesList();
  127. ServerHostKeyAlgorithms = ReadNamesList();
  128. EncryptionAlgorithmsClientToServer = ReadNamesList();
  129. EncryptionAlgorithmsServerToClient = ReadNamesList();
  130. MacAlgorithmsClientToServer = ReadNamesList();
  131. MacAlgorithmsServerToClient = ReadNamesList();
  132. CompressionAlgorithmsClientToServer = ReadNamesList();
  133. CompressionAlgorithmsServerToClient = ReadNamesList();
  134. LanguagesClientToServer = ReadNamesList();
  135. LanguagesServerToClient = ReadNamesList();
  136. FirstKexPacketFollows = ReadBoolean();
  137. Reserved = ReadUInt32();
  138. }
  139. /// <summary>
  140. /// Called when type specific data need to be saved.
  141. /// </summary>
  142. protected override void SaveData()
  143. {
  144. Write(Cookie);
  145. Write(KeyExchangeAlgorithms);
  146. Write(ServerHostKeyAlgorithms);
  147. Write(EncryptionAlgorithmsClientToServer);
  148. Write(EncryptionAlgorithmsServerToClient);
  149. Write(MacAlgorithmsClientToServer);
  150. Write(MacAlgorithmsServerToClient);
  151. Write(CompressionAlgorithmsClientToServer);
  152. Write(CompressionAlgorithmsServerToClient);
  153. Write(LanguagesClientToServer);
  154. Write(LanguagesServerToClient);
  155. Write(FirstKexPacketFollows);
  156. Write(Reserved);
  157. }
  158. }
  159. }