sshnet / sshnet/SSH.NET

Connection Abort on Key Auth causes problem on reconnect

Offen
#557 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

I'm using SSH.NET v2016.1.0 to connect to many UNIX servers. We have logic to retry connecting if an attempt fails. One of the servers uses keyboard authentication and intermittently aborts the connection during login. We have not found the cause of abort but that is not of concern here. When an abort occurs, the ConnectionInfo object is not being properly disposed when the client is Disconnected or Disposed. This is causing subsequent connection attempts to fail with client is not connected errors or errant events to be logged.

Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()

We have worked around by recreating the ConnectionInfo object on each attempt and unsubscribing handlers for the AuthenticationPrompt and AuthenticationBanners events before Disposing the client when a failure occurs.

private void DisposeClient(BaseClient client)
        {
            if (client != null)
            {
                if (client.ConnectionInfo != null)
                {
                    // Unregister events
                    foreach (AuthenticationMethod authenticationMethod in client.ConnectionInfo.AuthenticationMethods)
                    {
                        if (authenticationMethod is KeyboardInteractiveAuthenticationMethod)
                        {                            
                       ((KeyboardInteractiveAuthenticationMethod)authenticationMethod).AuthenticationPrompt -= KeyboardInteractive_AuthenticationPrompt;
                            break;
                        }
                    }

                    client.ConnectionInfo.AuthenticationBanner -= ConnectionInfo_AuthenticationBanner;
                }

                client.Dispose();

                client = null;
            }
        }

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, BaseClient.Dispose und Disconnect durch ConnectionInfo, Session.Connect und KeyboardInteractiveAuthenticationMethod.Authenticate nachzuverfolgen, wobei du dich auf den im Stack Trace gezeigten Pfad des abgebrochenen Logins konzentrierst. Prüfe, wie Authentifizierungsereignishandler und der Verbindungsstatus nach einem Abbruch beibehalten werden. Als abgeschlossen gilt, dass das Freigeben oder erneute Verbinden nach einem fehlgeschlagenen Tastatur-Authentifizierungsversuch keine veralteten Ereignisse oder client-is-not-connected-Fehler erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.