sshnet / sshnet/SSH.NET

Using SshClient on Linux under Wine throws System.Security.Cryptography.CryptographicException

Aperta
#1,828 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
4.4k
Fork
993
Merge medio
9g 21h
PR unite (30g)
1

Descrizione

SSH.NET Version: 2026.0.0
.NET Version: 10.0.11
Wine Version: 11.0

When trying to connect a SshClient from a Windows Application running under Wine, I get the following exception:

System.PlatformNotSupportedException: The specified curve 'Curve25519' or its parameters are not valid for this platform.
---> System.Security.Cryptography.CryptographicException: Unknown error (0x80090029)
at System.Security.Cryptography.CngKey.Create(CngAlgorithm algorithm, String keyName, CngKeyCreationParameters creationParameters)
at System.Security.Cryptography.CngAlgorithmCore.GetOrGenerateKey(Nullable`1 curve)
--- End of inner exception stack trace ---
at System.Security.Cryptography.CngAlgorithmCore.GetOrGenerateKey(Nullable`1 curve)
at System.Security.Cryptography.ECDiffieHellmanCng.GenerateKey(ECCurve curve)
at Renci.SshNet.Security.KeyExchangeECCurve25519.BclImpl.GenerateClientPublicKey()
at Renci.SshNet.Security.KeyExchangeECCurve25519.StartImpl()
at Renci.SshNet.Security.KeyExchangeECCurve25519.Start(Session session, KeyExchangeInitMessage message, Boolean sendClientInitMessage)
at Renci.SshNet.Session.OnKeyExchangeInitReceived(KeyExchangeInitMessage message)
at Renci.SshNet.Messages.Transport.KeyExchangeInitMessage.Process(Session session)
at Renci.SshNet.Session.MessageListener()
--- End of stack trace from previous location ---
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
at <my code>

Code executed:

var sshClient = new Renci.SshNet.SshClient(hostname, port, username, password);
sshClient.Connect();

I understand this is a Wine specific issue, because the bcrypt.dll / ncrypt.dll are heavily stubbed under Wine and Windows CNG (ECDH kex algorithms) is not fully supported as of right now. So not really a SSH.NET bug.

I was able to circumvent the issue by removing ECDH key exchange algorithms before connecting via my SshClient:

foreach (var algo in sshClient.ConnectionInfo.KeyExchangeAlgorithms.Keys.ToList())
{
    if (!algo.StartsWith("diffie-hellman-group", StringComparison.Ordinal))
        sshClient.ConnectionInfo.KeyExchangeAlgorithms.Remove(algo);
}

Obviously this is not really a good solution.

As a suggestion, it would be nice to have an option to switch to the BouncyCastle implementations via e.g. some config option.

For example in KeyExchangeECCurve25519:

        public override void Start(Session session, KeyExchangeInitMessage message, bool sendClientInitMessage)
        {
            base.Start(session, message, sendClientInitMessage);
#if NET
            if (!_forceBouncyCastleImpl && System.OperatingSystem.IsWindowsVersionAtLeast(10))
            {
                _impl = new BclImpl();
            }
            else
#endif
            {
                _impl = new BouncyCastleImpl();
            }

            StartImpl();
        }

where _forceBouncyCastleImpl is just some placeholder to force using the BouncyCastle implementation that can be somehow configured.

(As a side note: This issues did not occur with older SSH.NET versions or on .NET Framework)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da KeyExchangeECCurve25519 e analizza il modo in cui SshClient espone ConnectionInfo.KeyExchangeAlgorithms. Esamina la selezione tra BclImpl e BouncyCastleImpl mostrata nell’issue, quindi determina come un chiamante potrebbe configurare l’implementazione prima della connessione. Il lavoro è completo quando è possibile selezionare il percorso BouncyCastle configurato per Wine senza rimuovere manualmente gli algoritmi di scambio delle chiavi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
cryptography
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.