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>
This commit is contained in:
Christian Kandeler
2011-12-02 11:24:39 +01:00
parent d8add95049
commit 1166dcd441
2 changed files with 29 additions and 7 deletions

View File

@@ -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)