From f6d719f90d152775932420e29b90ced1ded51bc3 Mon Sep 17 00:00:00 2001 From: gstewart Date: Fri, 24 Jun 2022 11:13:30 -0400 Subject: [PATCH] Allow the client to initiate the key exchange --- src/Renci.SshNet/ConnectionInfo.cs | 9 +++++++++ src/Renci.SshNet/Session.cs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index af8e1ca5c..551017bfa 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -183,6 +183,14 @@ public class ConnectionInfo : IConnectionInfoInternal /// public int MaxSessions { get; set; } + /// + /// For servers that wait for the Key Exchange message, send the SSH_MSG_KEXINIT explicitly on connect() + /// + /// + /// True to initiate the key exchange on connect(). Default is false. + /// + public bool InitiateKeyExchange { get; set; } + /// /// Occurs when authentication banner is sent by the server. /// @@ -321,6 +329,7 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy ChannelCloseTimeout = DefaultChannelCloseTimeout; RetryAttempts = 10; MaxSessions = 10; + InitiateKeyExchange = false; Encoding = Encoding.UTF8; KeyExchangeAlgorithms = new Dictionary diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 0846cb2cd..dc04857a1 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -624,6 +624,11 @@ public void Connect() // ToDo: Make message pump async, to not consume a thread for every session ThreadAbstraction.ExecuteThreadLongRunning(() => MessageListener()); + if (ConnectionInfo.InitiateKeyExchange) + { + SendMessage(ClientInitMessage); + } + // Wait for key exchange to be completed WaitOnHandle(_keyExchangeCompletedWaitHandle);