Maemo: Allow more than one SSH key on the device.

Reviewed-by: kh1
This commit is contained in:
ck
2010-04-16 12:46:08 +02:00
parent de9b203565
commit 0a9087eeca
2 changed files with 26 additions and 15 deletions

View File

@@ -41,10 +41,11 @@
#include "maemosshconfigdialog.h" #include "maemosshconfigdialog.h"
#include "maemosshthread.h" #include "maemosshthread.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QRegExp> #include <QtCore/QRegExp>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QFileInfo>
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QIntValidator> #include <QtGui/QIntValidator>
@@ -297,7 +298,6 @@ void MaemoSettingsWidget::authenticationTypeChanged()
m_ui->passwordLabel->setEnabled(usePassword); m_ui->passwordLabel->setEnabled(usePassword);
m_ui->keyFileLineEdit->setEnabled(!usePassword); m_ui->keyFileLineEdit->setEnabled(!usePassword);
m_ui->keyLabel->setEnabled(!usePassword); m_ui->keyLabel->setEnabled(!usePassword);
m_ui->deployKeyButton->setEnabled(usePassword);
} }
void MaemoSettingsWidget::hostNameEditingFinished() void MaemoSettingsWidget::hostNameEditingFinished()
@@ -363,7 +363,7 @@ void MaemoSettingsWidget::showGenerateSshKeyDialog()
void MaemoSettingsWidget::setPublicKey(const QString &path) void MaemoSettingsWidget::setPublicKey(const QString &path)
{ {
m_publicKey = path; m_publicKeyFileName = path;
} }
void MaemoSettingsWidget::setPrivateKey(const QString &path) void MaemoSettingsWidget::setPrivateKey(const QString &path)
@@ -377,21 +377,32 @@ void MaemoSettingsWidget::deployKey()
if (m_keyDeployer) if (m_keyDeployer)
return; return;
if (!QFileInfo(m_publicKey).exists()) { if (!QFileInfo(m_publicKeyFileName).exists()) {
const QString &dir = QFileInfo(currentConfig().keyFile).path(); const QString &dir = QFileInfo(currentConfig().keyFile).path();
m_publicKey = QFileDialog::getOpenFileName(this, m_publicKeyFileName = QFileDialog::getOpenFileName(this,
tr("Choose public key file"), dir, tr("Choose public key file"), dir,
tr("Public Key Files(*.pub);;All Files (*)")); tr("Public Key Files(*.pub);;All Files (*)"));
} }
if (m_publicKey.isEmpty()) if (m_publicKeyFileName.isEmpty())
return; return;
QFile keyFile(m_publicKeyFileName);
QByteArray key;
const bool keyFileAccessible = keyFile.open(QIODevice::ReadOnly);
if (keyFileAccessible)
key = keyFile.readAll();
if (!keyFileAccessible || keyFile.error() != QFile::NoError) {
QMessageBox::critical(this, tr("Deployment Failed"),
tr("Could not read public key file '%1'.").arg(m_publicKeyFileName));
return;
}
m_ui->deployKeyButton->disconnect(); m_ui->deployKeyButton->disconnect();
SshDeploySpec deploySpec(m_publicKey, homeDirOnDevice(currentConfig().uname) const QString command = QLatin1String("test -d .ssh || mkdir .ssh && echo '")
+ QLatin1String("/.ssh/authorized_keys"), true); + key + QLatin1String("' >> .ssh/authorized_keys");
m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList<SshDeploySpec>() << deploySpec); m_keyDeployer = new MaemoSshRunner(currentConfig(), command);
connect(m_keyDeployer, SIGNAL(finished()), this, SLOT(handleDeployThreadFinished())); connect(m_keyDeployer, SIGNAL(finished()),
this, SLOT(handleDeployThreadFinished()));
m_ui->deployKeyButton->setText(tr("Stop deploying")); m_ui->deployKeyButton->setText(tr("Stop deploying"));
connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(stopDeploying())); connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(stopDeploying()));
m_keyDeployer->start(); m_keyDeployer->start();
@@ -416,14 +427,12 @@ void MaemoSettingsWidget::stopDeploying()
{ {
if (m_keyDeployer) { if (m_keyDeployer) {
m_ui->deployKeyButton->disconnect(); m_ui->deployKeyButton->disconnect();
const bool buttonWasEnabled = m_ui->deployKeyButton->isEnabled();
m_keyDeployer->disconnect(); m_keyDeployer->disconnect();
m_keyDeployer->stop(); m_keyDeployer->stop();
delete m_keyDeployer; delete m_keyDeployer;
m_keyDeployer = 0; m_keyDeployer = 0;
m_ui->deployKeyButton->setText(tr("Deploy Key ...")); m_ui->deployKeyButton->setText(tr("Deploy Key ..."));
connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(deployKey())); connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(deployKey()));
m_ui->deployKeyButton->setEnabled(buttonWasEnabled);
} }
} }
@@ -434,12 +443,14 @@ void MaemoSettingsWidget::currentConfigChanged(int index)
m_ui->removeConfigButton->setEnabled(false); m_ui->removeConfigButton->setEnabled(false);
m_ui->testConfigButton->setEnabled(false); m_ui->testConfigButton->setEnabled(false);
m_ui->generateKeyButton->setEnabled(false); m_ui->generateKeyButton->setEnabled(false);
m_ui->deployKeyButton->setEnabled(false);
clearDetails(); clearDetails();
m_ui->detailsWidget->setEnabled(false); m_ui->detailsWidget->setEnabled(false);
} else { } else {
m_ui->removeConfigButton->setEnabled(true); m_ui->removeConfigButton->setEnabled(true);
m_ui->testConfigButton->setEnabled(true); m_ui->testConfigButton->setEnabled(true);
m_ui->generateKeyButton->setEnabled(true); m_ui->generateKeyButton->setEnabled(true);
m_ui->deployKeyButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(index); m_ui->configurationComboBox->setCurrentIndex(index);
display(currentConfig()); display(currentConfig());
} }

View File

@@ -50,7 +50,7 @@ QT_END_NAMESPACE
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
class MaemoSshDeployer; class MaemoSshRunner;
class NameValidator; class NameValidator;
class TimeoutValidator; class TimeoutValidator;
@@ -107,8 +107,8 @@ private:
MaemoDeviceConfig m_lastConfigSim; MaemoDeviceConfig m_lastConfigSim;
NameValidator * const m_nameValidator; NameValidator * const m_nameValidator;
TimeoutValidator * const m_timeoutValidator; TimeoutValidator * const m_timeoutValidator;
MaemoSshDeployer *m_keyDeployer; MaemoSshRunner *m_keyDeployer;
QString m_publicKey; QString m_publicKeyFileName;
}; };
} // namespace Internal } // namespace Internal