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