diff --git a/Renci.SshClient/Renci.SshClient/Security/KeyExchange.cs b/Renci.SshClient/Renci.SshClient/Security/KeyExchange.cs index 186b7e38..dca31dab 100644 --- a/Renci.SshClient/Renci.SshClient/Security/KeyExchange.cs +++ b/Renci.SshClient/Renci.SshClient/Security/KeyExchange.cs @@ -177,13 +177,7 @@ namespace Renci.SshClient.Security public virtual void Finish() { // Validate hash - var validated = this.ValidateExchangeHash(); - - if (validated) - { - this.SendMessage(new NewKeysMessage()); - } - else + if (!this.ValidateExchangeHash()) { throw new SshConnectionException("Key exchange negotiation failed.", DisconnectReasons.KeyExchangeFailed); } diff --git a/Renci.SshClient/Renci.SshClient/Security/KeyExchangeDiffieHellman.cs b/Renci.SshClient/Renci.SshClient/Security/KeyExchangeDiffieHellman.cs index 3bd9df97..1d806d81 100644 --- a/Renci.SshClient/Renci.SshClient/Security/KeyExchangeDiffieHellman.cs +++ b/Renci.SshClient/Renci.SshClient/Security/KeyExchangeDiffieHellman.cs @@ -138,6 +138,9 @@ namespace Renci.SshClient.Security this._hostKey = hostKey; this.SharedKey = System.Numerics.BigInteger.ModPow(serverExchangeValue, this._randomValue, this._prime); this._signature = signature; + + // Whare DH reply received key exchange is completed + this.SendMessage(new NewKeysMessage()); } } }