From 1166dcd441cff1228689494be68f273ede763dc3 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 2 Dec 2011 11:24:39 +0100 Subject: 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 --- src/libs/utils/ssh/sshconnection.cpp | 35 ++++++++++++++++++++++++++++------- src/libs/utils/ssh/sshconnection_p.h | 1 + 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 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); -- cgit v1.2.1