| | | 1 | | using System; |
| | | 2 | | using Renci.SshNet.Common; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Messages.Transport |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents SSH_MSG_KEXECDH_INIT message. |
| | | 8 | | /// </summary> |
| | | 9 | | [Message("SSH_MSG_KEX_ECDH_INIT", 30)] |
| | | 10 | | internal sealed class KeyExchangeEcdhInitMessage : Message, IKeyExchangedAllowed |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets the client's ephemeral contribution to the ECDH exchange, encoded as an octet string. |
| | | 14 | | /// </summary> |
| | 3543 | 15 | | public byte[] QC { get; private set; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets the size of the message in bytes. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <value> |
| | | 21 | | /// The size of the messages in bytes. |
| | | 22 | | /// </value> |
| | | 23 | | protected override int BufferCapacity |
| | | 24 | | { |
| | | 25 | | get |
| | 1181 | 26 | | { |
| | 1181 | 27 | | var capacity = base.BufferCapacity; |
| | 1181 | 28 | | capacity += 4; // QC length |
| | 1181 | 29 | | capacity += QC.Length; // QC |
| | 1181 | 30 | | return capacity; |
| | 1181 | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class. |
| | | 36 | | /// </summary> |
| | 1181 | 37 | | public KeyExchangeEcdhInitMessage(byte[] q) |
| | 1181 | 38 | | { |
| | 1181 | 39 | | QC = q; |
| | 1181 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class. |
| | | 44 | | /// </summary> |
| | 0 | 45 | | public KeyExchangeEcdhInitMessage(BigInteger d, BigInteger q) |
| | 0 | 46 | | { |
| | 0 | 47 | | var dBytes = d.ToByteArray().Reverse(); |
| | 0 | 48 | | var qBytes = q.ToByteArray().Reverse(); |
| | | 49 | | |
| | 0 | 50 | | var data = new byte[dBytes.Length + qBytes.Length + 1]; |
| | 0 | 51 | | data[0] = 0x04; |
| | 0 | 52 | | Buffer.BlockCopy(dBytes, 0, data, 1, dBytes.Length); |
| | 0 | 53 | | Buffer.BlockCopy(qBytes, 0, data, dBytes.Length + 1, qBytes.Length); |
| | 0 | 54 | | QC = data; |
| | 0 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Called when type specific data need to be loaded. |
| | | 59 | | /// </summary> |
| | | 60 | | protected override void LoadData() |
| | 0 | 61 | | { |
| | 0 | 62 | | QC = ReadBinary(); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Called when type specific data need to be saved. |
| | | 67 | | /// </summary> |
| | | 68 | | protected override void SaveData() |
| | 1181 | 69 | | { |
| | 1181 | 70 | | WriteBinaryString(QC); |
| | 1181 | 71 | | } |
| | | 72 | | |
| | | 73 | | internal override void Process(Session session) |
| | 0 | 74 | | { |
| | 0 | 75 | | throw new NotImplementedException(); |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |