Skip to content

Commit

Permalink
During SSH authentication, try the none auth method first
Browse files Browse the repository at this point in the history
  • Loading branch information
nviennot committed Oct 15, 2019
1 parent 7262aea commit 4efe25d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
44 changes: 32 additions & 12 deletions tmate-ssh-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void on_ssh_client_event(struct tmate_ssh_client *client)
case SSH_INIT:
client->session = session = ssh_new();
if (!session) {
tmate_fatal("cannot initialize");
tmate_fatal("cannot ssh_new()");
return;
}

Expand Down Expand Up @@ -344,13 +344,30 @@ static void on_ssh_client_event(struct tmate_ssh_client *client)
*/
tmate_debug("Connected to %s", client->server_ip);
on_ssh_auth_server_complete(client);
client->state = SSH_AUTH_CLIENT;

client->state = SSH_AUTH_CLIENT_NONE;
/* fall through */

case SSH_AUTH_CLIENT:
case SSH_AUTH_CLIENT_NONE:
switch (ssh_userauth_none(session, NULL)) {
case SSH_AUTH_AGAIN:
return;
case SSH_AUTH_ERROR:
kill_ssh_client(client, "Auth error: %s", ssh_get_error(session));
return;
case SSH_AUTH_SUCCESS:
tmate_debug("Auth successful via none method");
client->state = SSH_NEW_CHANNEL;
goto SSH_NEW_CHANNEL;
case SSH_AUTH_PARTIAL:
case SSH_AUTH_DENIED:
client->state = SSH_AUTH_CLIENT_PUBKEY;
/* fall through */
}

case SSH_AUTH_CLIENT_PUBKEY:
client->tried_passphrase = client->tmate_session->passphrase;
switch (ssh_userauth_autopubkey(session, client->tried_passphrase)) {
switch (ssh_userauth_publickey_auto(session, NULL, client->tried_passphrase)) {
case SSH_AUTH_AGAIN:
return;
case SSH_AUTH_PARTIAL:
Expand All @@ -372,17 +389,20 @@ static void on_ssh_client_event(struct tmate_ssh_client *client)
kill_ssh_client(client, "Auth error: %s", ssh_get_error(session));
return;
case SSH_AUTH_SUCCESS:
tmate_debug("Auth successful");
client->state = SSH_OPEN_CHANNEL;

client->channel = channel = ssh_channel_new(session);
if (!channel) {
tmate_fatal("cannot initialize");
return;
}
tmate_debug("Auth successful with pubkey");
client->state = SSH_NEW_CHANNEL;
/* fall through */
}

SSH_NEW_CHANNEL:
case SSH_NEW_CHANNEL:
client->channel = channel = ssh_channel_new(session);
if (!channel) {
tmate_fatal("cannot ssh_channel_new()");
return;
}
client->state = SSH_OPEN_CHANNEL;

case SSH_OPEN_CHANNEL:
switch (ssh_channel_open_session(channel)) {
case SSH_AGAIN:
Expand Down
4 changes: 3 additions & 1 deletion tmate.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ enum tmate_ssh_client_state_types {
SSH_INIT,
SSH_CONNECT,
SSH_AUTH_SERVER,
SSH_AUTH_CLIENT,
SSH_AUTH_CLIENT_NONE,
SSH_AUTH_CLIENT_PUBKEY,
SSH_NEW_CHANNEL,
SSH_OPEN_CHANNEL,
SSH_BOOTSTRAP,
SSH_READY,
Expand Down

0 comments on commit 4efe25d

Please sign in to comment.