Skip to content

Commit ad7a553

Browse files
committed
Do not send extra ssh_message_reply_default()
Keyboard-interactive sends a reply when it initializes, in which case we should manipulate connection state: we have not succeeded in auth nor have we failed. This state needs to be recognized, so we do not call ssh_message_reply_default(), as that translates in an immediate SSH_MSG_USERAUTH_FAILURE, which means on retry this message will leak into the open session, where it is not a valid command. Change auth_ret into a tri-state, with a new -1 state. Fixes #68. Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
1 parent 1b1d2a5 commit ad7a553

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/session_server_ssh.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,19 +855,26 @@ nc_sshcb_auth_kbdint(struct nc_session *session, ssh_message msg)
855855
char echo[] = {0};
856856

857857
ssh_message_auth_interactive_request(msg, "Interactive SSH Authentication", "Type your password:", 1, prompts, echo);
858+
auth_ret = -1;
858859
} else {
859860
if (ssh_userauth_kbdint_getnanswers(session->ti.libssh.session) != 1) {// failed session
860861
ssh_message_reply_default(msg);
861862
return;
862863
}
863864
pass_hash = auth_password_get_pwd_hash(session->username);// get hashed password
864865
if (pass_hash) {
865-
auth_ret = auth_password_compare_pwd(pass_hash, ssh_userauth_kbdint_getanswer(session->ti.libssh.session, 0));
866+
/* Normalize auth_password_compare_pwd result to 0 or 1 */
867+
auth_ret = !!auth_password_compare_pwd(pass_hash, ssh_userauth_kbdint_getanswer(session->ti.libssh.session, 0));
866868
free(pass_hash);// free hashed password
867869
}
868870
}
869871
}
870872

873+
/* We have already sent a reply */
874+
if (auth_ret == -1) {
875+
return;
876+
}
877+
871878
/* Authenticate message based on outcome */
872879
if (!auth_ret) {
873880
session->flags |= NC_SESSION_SSH_AUTHENTICATED;

0 commit comments

Comments
 (0)