Key Exchange Negotiation Failed
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 993
- Avg merge
- 9d 21h
- Merged PRs (30d)
- 1
Description
Hi Folks,
I am using the latest NuGet package - 2023.0.1 in a .NET 6 console app. Below is the stack trace.
Code:
var password = _encryptionManager.Decrypt(sftpSetting.EncryptedUserPassword);
ConnectionInfo connectionInfo;
var methods = new List<AuthenticationMethod>
{
new PasswordAuthenticationMethod(sftpSetting.Username,password)
};
connectionInfo = new ConnectionInfo(sftpSetting.HostName, sftpSetting.Port, sftpSetting.Username, methods.ToArray());
using (var sftpClient = new Renci.SshNet.SftpClient(connectionInfo))
{
sftpClient.HostKeyReceived += (sender, e) =>
{
e.CanTrust = GetHostFingerPrint(sftpSetting).Equals(e.FingerPrintSHA256);
};
sftpClient.Connect();
sftpClient.UploadFile(fileStream, remotePath);
sftpClient.Disconnect();
}
Stack Trace:
Renci.SshNet.Common.SshConnectionException
HResult=0x80131500
Message=Key exchange negotiation failed.
Source=Renci.SshNet
StackTrace:
at Renci.SshNet.Security.KeyExchange.Finish()
at Renci.SshNet.Security.KeyExchangeECDH.Finish()
at Renci.SshNet.Session.MessageListener()
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
Is there anything I can do to workaround this issue? Thank you!
EDIT:
To add to the scenario, I have no issues connecting and uploading using a WinSCP client with the same configuration used above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the .NET 6 connection code at SftpClient.Connect and the KeyExchangeECDH.Finish stack-trace entry. Compare the SSH negotiation configuration with the working WinSCP setup and identify the missing compatibility detail. Done means a reproducible cause and a documented workaround or confirmed fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100