summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@nokia.com>2011-12-02 11:24:39 +0100
committerChristian Kandeler <christian.kandeler@nokia.com>2011-12-02 11:40:26 +0100
commit1166dcd441cff1228689494be68f273ede763dc3 (patch)
treead334ba4bef3868585de1c23947868ea0937b881
parentd8add9504926add171f76f97ea65b49d13b6d823 (diff)
downloadqt-creator-1166dcd441cff1228689494be68f273ede763dc3.tar.gz
SSH: Ask for private key password right on connection start.
This prevents event loop issues (e.g. connection timeout). Task-number: QTCREATORBUG-6641 Change-Id: Ibeecaac2621e171a0590621fd9fdde8f7e3ab9c5 Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
-rw-r--r--src/libs/utils/ssh/sshconnection.cpp35
-rw-r--r--src/libs/utils/ssh/sshconnection_p.h1
2 files changed, 29 insertions, 7 deletions
diff --git a/src/libs/utils/ssh/sshconnection.cpp b/src/libs/utils/ssh/sshconnection.cpp
index 647a3d26be..cd5d552349 100644
--- a/src/libs/utils/ssh/sshconnection.cpp
+++ b/src/libs/utils/ssh/sshconnection.cpp
@@ -453,12 +453,6 @@ void SshConnectionPrivate::handleServiceAcceptPacket()
m_sendFacility.sendUserAuthByPwdRequestPacket(m_connParams.userName.toUtf8(),
SshCapabilities::SshConnectionService, m_connParams.password.toUtf8());
} else {
- Utils::FileReader reader;
- if (!reader.fetch(m_connParams.privateKeyFile))
- throw SshClientException(SshKeyFileError,
- tr("Private key error: %1").arg(reader.errorString()));
-
- m_sendFacility.createAuthenticationKey(reader.data());
m_sendFacility.sendUserAuthByKeyRequestPacket(m_connParams.userName.toUtf8(),
SshCapabilities::SshConnectionService);
}
@@ -637,6 +631,22 @@ void SshConnectionPrivate::connectToHost()
m_error = SshNoError;
m_ignoreNextPacket = false;
m_errorString.clear();
+
+ try {
+ if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationByKey)
+ createPrivateKey();
+ } catch (const SshClientException &ex) {
+ m_error = ex.error;
+ m_errorString = ex.errorString;
+ emit error(m_error);
+ return;
+ } catch (const Botan::Exception &ex) {
+ m_error = SshKeyFileError;
+ m_errorString = QString::fromAscii(ex.what());
+ emit error(m_error);
+ return;
+ }
+
connect(m_socket, SIGNAL(connected()), this, SLOT(handleSocketConnected()));
connect(m_socket, SIGNAL(readyRead()), this, SLOT(handleIncomingData()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
@@ -681,7 +691,18 @@ void SshConnectionPrivate::closeConnection(SshErrorCode sshError,
bool SshConnectionPrivate::canUseSocket() const
{
return m_socket->isValid()
- && m_socket->state() == QAbstractSocket::ConnectedState;
+ && m_socket->state() == QAbstractSocket::ConnectedState;
+}
+
+void SshConnectionPrivate::createPrivateKey()
+{
+ Utils::FileReader reader;
+ if (m_connParams.privateKeyFile.isEmpty())
+ throw SshClientException(SshKeyFileError, tr("No private key file given."));
+ if (!reader.fetch(m_connParams.privateKeyFile))
+ throw SshClientException(SshKeyFileError,
+ tr("Private key file error: %1").arg(reader.errorString()));
+ m_sendFacility.createAuthenticationKey(reader.data());
}
QSharedPointer<SshRemoteProcess> SshConnectionPrivate::createRemoteProcess(const QByteArray &command)
diff --git a/src/libs/utils/ssh/sshconnection_p.h b/src/libs/utils/ssh/sshconnection_p.h
index 45f1ea03b0..d02cdcb177 100644
--- a/src/libs/utils/ssh/sshconnection_p.h
+++ b/src/libs/utils/ssh/sshconnection_p.h
@@ -137,6 +137,7 @@ private:
void handleChannelClose();
void handleDisconnect();
bool canUseSocket() const;
+ void createPrivateKey();
void sendData(const QByteArray &data);