KeyExchangeHash.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Renci.SshNet.Common;
  2. using System;
  3. using System.Linq;
  4. namespace Renci.SshNet.Security
  5. {
  6. internal class KeyExchangeHashData : SshData
  7. {
  8. private byte[] _serverVersion;
  9. private byte[] _clientVersion;
  10. public string ServerVersion
  11. {
  12. private get { return Utf8.GetString(_serverVersion, 0, _serverVersion.Length); }
  13. set { _serverVersion = Utf8.GetBytes(value); }
  14. }
  15. public string ClientVersion
  16. {
  17. private get { return Utf8.GetString(_clientVersion, 0, _clientVersion.Length); }
  18. set { _clientVersion = Utf8.GetBytes(value); }
  19. }
  20. public byte[] ClientPayload { get; set; }
  21. public byte[] ServerPayload { get; set; }
  22. public byte[] HostKey { get; set; }
  23. public byte[] ClientExchangeValue { get; set; }
  24. public byte[] ServerExchangeValue { get; set; }
  25. public byte[] SharedKey { get; set; }
  26. /// <summary>
  27. /// Gets the size of the message in bytes.
  28. /// </summary>
  29. /// <value>
  30. /// The size of the messages in bytes.
  31. /// </value>
  32. protected override int BufferCapacity
  33. {
  34. get
  35. {
  36. var capacity = base.BufferCapacity;
  37. capacity += 4; // ClientVersion length
  38. capacity += _clientVersion.Length; // ClientVersion
  39. capacity += 4; // ServerVersion length
  40. capacity += _serverVersion.Length; // ServerVersion
  41. capacity += 4; // ClientPayload length
  42. capacity += ClientPayload.Length; // ClientPayload
  43. capacity += 4; // ServerPayload length
  44. capacity += ServerPayload.Length; // ServerPayload
  45. capacity += 4; // HostKey length
  46. capacity += HostKey.Length; // HostKey
  47. capacity += 4; // ClientExchangeValue length
  48. capacity += ClientExchangeValue.Length; // ClientExchangeValue
  49. capacity += 4; // ServerExchangeValue length
  50. capacity += ServerExchangeValue.Length; // ServerExchangeValue
  51. capacity += 4; // SharedKey length
  52. capacity += SharedKey.Length; // SharedKey
  53. return capacity;
  54. }
  55. }
  56. protected override void LoadData()
  57. {
  58. throw new NotImplementedException();
  59. }
  60. protected override void SaveData()
  61. {
  62. WriteBinaryString(_clientVersion);
  63. WriteBinaryString(_serverVersion);
  64. WriteBinaryString(ClientPayload);
  65. WriteBinaryString(ServerPayload);
  66. WriteBinaryString(HostKey);
  67. WriteBinaryString(ClientExchangeValue);
  68. WriteBinaryString(ServerExchangeValue);
  69. WriteBinaryString(SharedKey);
  70. }
  71. }
  72. }