Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

qsshsocket: Also try keys from ssh-agent and defaults #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ext/qsshsocket/qsshsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void QSshSocket::run()
{
m_session = ssh_new();

int timeout_sec = 30;

//set logging to verbose so all errors can be debugged if crash happens
int verbosity = SSH_LOG_NOLOG;

Expand All @@ -84,6 +86,7 @@ void QSshSocket::run()
ssh_options_set(m_session, SSH_OPTIONS_USER, m_user.toUtf8().data());
ssh_options_set(m_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(m_session, SSH_OPTIONS_PORT, &m_port);
ssh_options_set(m_session, SSH_OPTIONS_TIMEOUT, &timeout_sec);

// try to connect given host, user, port
int connectionResponse = ssh_connect(m_session);
Expand Down Expand Up @@ -160,6 +163,24 @@ void QSshSocket::run()
error(KeyAuthenticationFailedError);
}
}
// Just try ssh-agent and default keys
else if (m_user != "")
{
int rc;

rc = ssh_userauth_publickey_auto(m_session,
m_user.toUtf8().data(),
NULL);
if (rc == SSH_OK) {
loginSuccessful();
m_loggedIn = true;
} else {
m_user = "";
m_key = "";
m_key_passphrase = "";
error(KeyAuthenticationFailedError);
}
}
}
// if all ssh setup has been completed, check to see if we have any commands to execute
else if (!m_currentOperation.executed)
Expand Down