| | | 1 | | using Renci.SshNet.Messages.Transport; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Security |
| | | 4 | | { |
| | | 5 | | internal abstract class KeyExchangeEC : KeyExchange |
| | | 6 | | { |
| | | 7 | | #pragma warning disable SA1401 // Fields should be private |
| | | 8 | | /// <summary> |
| | | 9 | | /// Specifies client payload. |
| | | 10 | | /// </summary> |
| | | 11 | | protected byte[] _clientPayload; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Specifies server payload. |
| | | 15 | | /// </summary> |
| | | 16 | | protected byte[] _serverPayload; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Specifies client exchange. |
| | | 20 | | /// </summary> |
| | | 21 | | protected byte[] _clientExchangeValue; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Specifies server exchange. |
| | | 25 | | /// </summary> |
| | | 26 | | protected byte[] _serverExchangeValue; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Specifies host key data. |
| | | 30 | | /// </summary> |
| | | 31 | | protected byte[] _hostKey; |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Specifies signature data. |
| | | 35 | | /// </summary> |
| | | 36 | | protected byte[] _signature; |
| | | 37 | | #pragma warning restore SA1401 // Fields should be private |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the size, in bits, of the computed hash code. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <value> |
| | | 43 | | /// The size, in bits, of the computed hash code. |
| | | 44 | | /// </value> |
| | | 45 | | protected abstract int HashSize { get; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Calculates key exchange hash value. |
| | | 49 | | /// </summary> |
| | | 50 | | /// <returns> |
| | | 51 | | /// Key exchange hash. |
| | | 52 | | /// </returns> |
| | | 53 | | protected override byte[] CalculateHash() |
| | 2361 | 54 | | { |
| | 2361 | 55 | | var hashData = new KeyExchangeHashData |
| | 2361 | 56 | | { |
| | 2361 | 57 | | ClientVersion = Session.ClientVersion, |
| | 2361 | 58 | | ServerVersion = Session.ServerVersion, |
| | 2361 | 59 | | ClientPayload = _clientPayload, |
| | 2361 | 60 | | ServerPayload = _serverPayload, |
| | 2361 | 61 | | HostKey = _hostKey, |
| | 2361 | 62 | | ClientExchangeValue = _clientExchangeValue, |
| | 2361 | 63 | | ServerExchangeValue = _serverExchangeValue, |
| | 2361 | 64 | | SharedKey = SharedKey, |
| | 2361 | 65 | | }; |
| | | 66 | | |
| | 2361 | 67 | | return Hash(hashData.GetBytes()); |
| | 2361 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Validates the exchange hash. |
| | | 72 | | /// </summary> |
| | | 73 | | /// <returns> |
| | | 74 | | /// true if exchange hash is valid; otherwise false. |
| | | 75 | | /// </returns> |
| | | 76 | | protected override bool ValidateExchangeHash() |
| | 1181 | 77 | | { |
| | 1181 | 78 | | return ValidateExchangeHash(_hostKey, _signature); |
| | 1181 | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Starts key exchange algorithm. |
| | | 83 | | /// </summary> |
| | | 84 | | /// <param name="session">The session.</param> |
| | | 85 | | /// <param name="message">Key exchange init message.</param> |
| | | 86 | | public override void Start(Session session, KeyExchangeInitMessage message) |
| | 1181 | 87 | | { |
| | 1181 | 88 | | base.Start(session, message); |
| | | 89 | | |
| | 1181 | 90 | | _serverPayload = message.GetBytes(); |
| | 1181 | 91 | | _clientPayload = Session.ClientInitMessage.GetBytes(); |
| | 1181 | 92 | | } |
| | | 93 | | } |
| | | 94 | | } |