| | | 1 | | using System; |
| | | 2 | | using Renci.SshNet.Common; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Security |
| | | 5 | | { |
| | | 6 | | internal sealed class GroupExchangeHashData : SshData |
| | | 7 | | { |
| | | 8 | | private byte[] _serverVersion; |
| | | 9 | | private byte[] _clientVersion; |
| | | 10 | | private byte[] _prime; |
| | | 11 | | private byte[] _subGroup; |
| | | 12 | | |
| | | 13 | | public string ServerVersion |
| | | 14 | | { |
| | 0 | 15 | | private get { return Utf8.GetString(_serverVersion, 0, _serverVersion.Length); } |
| | 36 | 16 | | set { _serverVersion = Utf8.GetBytes(value); } |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | public string ClientVersion |
| | | 20 | | { |
| | 0 | 21 | | private get { return Utf8.GetString(_clientVersion, 0, _clientVersion.Length); } |
| | 36 | 22 | | set { _clientVersion = Utf8.GetBytes(value); } |
| | | 23 | | } |
| | | 24 | | |
| | 36 | 25 | | public byte[] ClientPayload { get; set; } |
| | | 26 | | |
| | 36 | 27 | | public byte[] ServerPayload { get; set; } |
| | | 28 | | |
| | 36 | 29 | | public byte[] HostKey { get; set; } |
| | | 30 | | |
| | 24 | 31 | | public uint MinimumGroupSize { get; set; } |
| | | 32 | | |
| | 24 | 33 | | public uint PreferredGroupSize { get; set; } |
| | | 34 | | |
| | 24 | 35 | | public uint MaximumGroupSize { get; set; } |
| | | 36 | | |
| | | 37 | | public BigInteger Prime |
| | | 38 | | { |
| | 0 | 39 | | private get { return _prime.ToBigInteger(); } |
| | 36 | 40 | | set { _prime = value.ToByteArray().Reverse(); } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public BigInteger SubGroup |
| | | 44 | | { |
| | 0 | 45 | | private get { return _subGroup.ToBigInteger(); } |
| | 36 | 46 | | set { _subGroup = value.ToByteArray().Reverse(); } |
| | | 47 | | } |
| | | 48 | | |
| | 36 | 49 | | public byte[] ClientExchangeValue { get; set; } |
| | | 50 | | |
| | 36 | 51 | | public byte[] ServerExchangeValue { get; set; } |
| | | 52 | | |
| | 36 | 53 | | public byte[] SharedKey { get; set; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets the size of the message in bytes. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <value> |
| | | 59 | | /// The size of the messages in bytes. |
| | | 60 | | /// </value> |
| | | 61 | | protected override int BufferCapacity |
| | | 62 | | { |
| | | 63 | | get |
| | 12 | 64 | | { |
| | 12 | 65 | | var capacity = base.BufferCapacity; |
| | 12 | 66 | | capacity += 4; // ClientVersion length |
| | 12 | 67 | | capacity += _clientVersion.Length; // ClientVersion |
| | 12 | 68 | | capacity += 4; // ServerVersion length |
| | 12 | 69 | | capacity += _serverVersion.Length; // ServerVersion |
| | 12 | 70 | | capacity += 4; // ClientPayload length |
| | 12 | 71 | | capacity += ClientPayload.Length; // ClientPayload |
| | 12 | 72 | | capacity += 4; // ServerPayload length |
| | 12 | 73 | | capacity += ServerPayload.Length; // ServerPayload |
| | 12 | 74 | | capacity += 4; // HostKey length |
| | 12 | 75 | | capacity += HostKey.Length; // HostKey |
| | 12 | 76 | | capacity += 4; // MinimumGroupSize |
| | 12 | 77 | | capacity += 4; // PreferredGroupSize |
| | 12 | 78 | | capacity += 4; // MaximumGroupSize |
| | 12 | 79 | | capacity += 4; // Prime length |
| | 12 | 80 | | capacity += _prime.Length; // Prime |
| | 12 | 81 | | capacity += 4; // SubGroup length |
| | 12 | 82 | | capacity += _subGroup.Length; // SubGroup |
| | 12 | 83 | | capacity += 4; // ClientExchangeValue length |
| | 12 | 84 | | capacity += ClientExchangeValue.Length; // ClientExchangeValue |
| | 12 | 85 | | capacity += 4; // ServerExchangeValue length |
| | 12 | 86 | | capacity += ServerExchangeValue.Length; // ServerExchangeValue |
| | 12 | 87 | | capacity += 4; // SharedKey length |
| | 12 | 88 | | capacity += SharedKey.Length; // SharedKey |
| | 12 | 89 | | return capacity; |
| | 12 | 90 | | } |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | protected override void LoadData() |
| | 0 | 94 | | { |
| | 0 | 95 | | throw new NotImplementedException(); |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | protected override void SaveData() |
| | 12 | 99 | | { |
| | 12 | 100 | | WriteBinaryString(_clientVersion); |
| | 12 | 101 | | WriteBinaryString(_serverVersion); |
| | 12 | 102 | | WriteBinaryString(ClientPayload); |
| | 12 | 103 | | WriteBinaryString(ServerPayload); |
| | 12 | 104 | | WriteBinaryString(HostKey); |
| | 12 | 105 | | Write(MinimumGroupSize); |
| | 12 | 106 | | Write(PreferredGroupSize); |
| | 12 | 107 | | Write(MaximumGroupSize); |
| | 12 | 108 | | WriteBinaryString(_prime); |
| | 12 | 109 | | WriteBinaryString(_subGroup); |
| | 12 | 110 | | WriteBinaryString(ClientExchangeValue); |
| | 12 | 111 | | WriteBinaryString(ServerExchangeValue); |
| | 12 | 112 | | WriteBinaryString(SharedKey); |
| | 12 | 113 | | } |
| | | 114 | | } |
| | | 115 | | } |