| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using Renci.SshNet.Messages.Transport;
- namespace Renci.SshNet.Security
- {
- internal abstract class KeyExchangeEC : KeyExchange
- {
- #pragma warning disable SA1401 // Fields should be private
- /// <summary>
- /// Specifies client payload.
- /// </summary>
- protected byte[] _clientPayload;
- /// <summary>
- /// Specifies server payload.
- /// </summary>
- protected byte[] _serverPayload;
- /// <summary>
- /// Specifies client exchange.
- /// </summary>
- protected byte[] _clientExchangeValue;
- /// <summary>
- /// Specifies server exchange.
- /// </summary>
- protected byte[] _serverExchangeValue;
- /// <summary>
- /// Specifies host key data.
- /// </summary>
- protected byte[] _hostKey;
- /// <summary>
- /// Specifies signature data.
- /// </summary>
- protected byte[] _signature;
- #pragma warning restore SA1401 // Fields should be private
- /// <summary>
- /// Gets the size, in bits, of the computed hash code.
- /// </summary>
- /// <value>
- /// The size, in bits, of the computed hash code.
- /// </value>
- protected abstract int HashSize { get; }
- /// <summary>
- /// Calculates key exchange hash value.
- /// </summary>
- /// <returns>
- /// Key exchange hash.
- /// </returns>
- protected override byte[] CalculateHash()
- {
- var hashData = new KeyExchangeHashData
- {
- ClientVersion = Session.ClientVersion,
- ServerVersion = Session.ServerVersion,
- ClientPayload = _clientPayload,
- ServerPayload = _serverPayload,
- HostKey = _hostKey,
- ClientExchangeValue = _clientExchangeValue,
- ServerExchangeValue = _serverExchangeValue,
- SharedKey = SharedKey,
- };
- return Hash(hashData.GetBytes());
- }
- /// <summary>
- /// Validates the exchange hash.
- /// </summary>
- /// <returns>
- /// true if exchange hash is valid; otherwise false.
- /// </returns>
- protected override bool ValidateExchangeHash()
- {
- return ValidateExchangeHash(_hostKey, _signature);
- }
- /// <inheritdoc/>
- public override void Start(Session session, KeyExchangeInitMessage message, bool sendClientInitMessage)
- {
- base.Start(session, message, sendClientInitMessage);
- _serverPayload = message.GetBytes();
- _clientPayload = Session.ClientInitMessage.GetBytes();
- }
- }
- }
|