]> granicus.if.org Git - curl/commitdiff
SSH: Fix state machine for ssh-agent authentication
authorMichael Gmelin <mg@grem.de>
Thu, 18 Jan 2018 00:28:19 +0000 (01:28 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 18 Jan 2018 16:08:13 +0000 (17:08 +0100)
In case an identity didn't match[0], the state machine would fail in
state SSH_AUTH_AGENT instead of progressing to the next identity in
ssh-agent. As a result, ssh-agent authentication only worked if the
identity required happened to be the first added to ssh-agent.

This was introduced as part of commit c4eb10e2f06fbd6cc904f1d78e4, which
stated that the "else" statement was required to prevent getting stuck
in state SSH_AUTH_AGENT. Given the state machine's logic and libssh2's
interface I couldn't see how this could happen or reproduce it and I
also couldn't find a more detailed description of the problem which
would explain a test case to reproduce the problem this was supposed to
fix.

[0] libssh2_agent_userauth returning LIBSSH2_ERROR_AUTHENTICATION_FAILED

Closes #2248

lib/ssh.c

index 6516c5d377fe837cd612b8aca021f444b26c1a95..a86ed706e180eab8524de6e7c4bdf600809d7893 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -955,11 +955,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
                                     sshc->sshagent_identity);
 
         if(rc < 0) {
-          if(rc != LIBSSH2_ERROR_EAGAIN)
+          if(rc != LIBSSH2_ERROR_EAGAIN) {
             /* tried and failed? go to next identity */
             sshc->sshagent_prev_identity = sshc->sshagent_identity;
-          else
-            break;
+          }
+          break;
         }
       }