Implement ssh key generation dialog.

Reviewed-by: ck
This commit is contained in:
kh1
2010-04-15 16:11:12 +02:00
parent cfe771cc37
commit c57e2eaff4
7 changed files with 623 additions and 496 deletions

View File

@@ -38,6 +38,7 @@
#include "maemoconfigtestdialog.h"
#include "maemodeviceconfigurations.h"
#include "maemosshconfigdialog.h"
#include "maemosshthread.h"
#include <QtCore/QRegExp>
@@ -118,7 +119,6 @@ MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent)
m_nameValidator(new NameValidator(m_devConfs)),
m_timeoutValidator(new TimeoutValidator),
m_keyDeployer(0)
{
initGui();
}
@@ -160,6 +160,7 @@ void MaemoSettingsWidget::initGui()
m_ui->nameLineEdit->setValidator(m_nameValidator);
m_ui->timeoutLineEdit->setValidator(m_timeoutValidator);
m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File);
foreach (const MaemoDeviceConfig &devConf, m_devConfs)
m_ui->configurationComboBox->addItem(devConf.name);
connect(m_ui->configurationComboBox, SIGNAL(currentIndexChanged(int)),
@@ -350,27 +351,49 @@ void MaemoSettingsWidget::testConfig()
dialog->open();
}
void MaemoSettingsWidget::showGenerateSshKeyDialog()
{
MaemoSshConfigDialog dialog(this);
connect(&dialog, SIGNAL(publicKeyGenerated(QString)), this,
SLOT(setPublicKey(QString)));
connect(&dialog, SIGNAL(privateKeyGenerated(QString)), this,
SLOT(setPrivateKey(QString)));
dialog.exec();
}
void MaemoSettingsWidget::setPublicKey(const QString &path)
{
m_publicKey = path;
}
void MaemoSettingsWidget::setPrivateKey(const QString &path)
{
m_ui->keyFileLineEdit->setPath(path);
keyFileEditingFinished();
}
void MaemoSettingsWidget::deployKey()
{
if (m_keyDeployer)
return;
const QString &dir = QFileInfo(currentConfig().keyFile).path();
const QString &keyFile = QFileDialog::getOpenFileName(this,
tr("Choose public key file"), dir,
tr("Public Key Files(*.pub);;All Files (*)"));
if (keyFile.isEmpty())
if (!QFileInfo(m_publicKey).exists()) {
const QString &dir = QFileInfo(currentConfig().keyFile).path();
m_publicKey = QFileDialog::getOpenFileName(this,
tr("Choose public key file"), dir,
tr("Public Key Files(*.pub);;All Files (*)"));
}
if (m_publicKey.isEmpty())
return;
m_ui->deployKeyButton->disconnect();
SshDeploySpec deploySpec(keyFile, homeDirOnDevice(currentConfig().uname)
SshDeploySpec deploySpec(m_publicKey, homeDirOnDevice(currentConfig().uname)
+ QLatin1String("/.ssh/authorized_keys"), true);
m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList<SshDeploySpec>() << deploySpec);
connect(m_keyDeployer, SIGNAL(finished()),
this, SLOT(handleDeployThreadFinished()));
connect(m_keyDeployer, SIGNAL(finished()), this, SLOT(handleDeployThreadFinished()));
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();
}
@@ -410,11 +433,13 @@ void MaemoSettingsWidget::currentConfigChanged(int index)
if (index == -1) {
m_ui->removeConfigButton->setEnabled(false);
m_ui->testConfigButton->setEnabled(false);
m_ui->generateKeyButton->setEnabled(false);
clearDetails();
m_ui->detailsWidget->setEnabled(false);
} else {
m_ui->removeConfigButton->setEnabled(true);
m_ui->testConfigButton->setEnabled(true);
m_ui->generateKeyButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(index);
display(currentConfig());
}

View File

@@ -82,6 +82,10 @@ private slots:
// For configuration testing.
void testConfig();
void showGenerateSshKeyDialog();
void setPublicKey(const QString &path);
void setPrivateKey(const QString &path);
// For key deploying.
void deployKey();
void handleDeployThreadFinished();
@@ -104,6 +108,7 @@ private:
NameValidator * const m_nameValidator;
TimeoutValidator * const m_timeoutValidator;
MaemoSshDeployer *m_keyDeployer;
QString m_publicKey;
};
} // namespace Internal

View File

@@ -6,39 +6,262 @@
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>350</height>
<width>484</width>
<height>307</height>
</rect>
</property>
<property name="windowTitle">
<string>Maemo Device Configurations</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="configurationLabel">
<property name="text">
<string>Configuration:</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="configurationLabel">
<property name="text">
<string>Configuration:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="configurationComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="configurationComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="editable">
<bool>false</bool>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="detailsWidget" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="deviceNameLabel">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="deviceTypeLabel">
<property name="text">
<string>Device type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="deviceTypeButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="deviceButton">
<property name="text">
<string>Remote Device</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="simulatorButton">
<property name="text">
<string>Local Simulator</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="authTypeLabel">
<property name="text">
<string>Authentication type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="authTypeButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="passwordButton">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="keyButton">
<property name="text">
<string>Key</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="hostNameLabel">
<property name="text">
<string>Host Name:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="hostLineEdit">
<property name="placeholderText">
<string>IP or host name of the device</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="portsLabel">
<property name="text">
<string>Ports:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="sshPortLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SSH:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sshPortSpinBox">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>22</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gdbServerLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Gdb server:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="gdbServerPortSpinBox">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="connectionTimeoutLabel">
<property name="text">
<string>Connection Timeout:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="timeoutLineEdit">
<property name="placeholderText">
<string>Timeout value in milliseconds</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="userNameLabel">
<property name="text">
<string>User Name:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="userLineEdit"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="pwdLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="Utils::PathChooser" name="keyFileLineEdit" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="0" column="2" rowspan="2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addConfigButton">
@@ -67,13 +290,23 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="generateKeyButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Generate SSH Key ...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deployKeyButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Deploy Key ...</string>
<string>Deploy public Key ...</string>
</property>
</widget>
</item>
@@ -92,226 +325,6 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="detailsWidget" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="deviceNameLabel">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="deviceTypeLabel">
<property name="text">
<string>Device type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="deviceTypeButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="deviceButton">
<property name="text">
<string>Remote device</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="simulatorButton">
<property name="text">
<string>Local simulator</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="authTypeLabel">
<property name="text">
<string>Authentication type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="authTypeButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="passwordButton">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="keyButton">
<property name="text">
<string>Key</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="hostNameLabel">
<property name="text">
<string>Host name:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="hostLineEdit">
<property name="placeholderText">
<string>IP or host name of the device</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="portsLabel">
<property name="text">
<string>Ports:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="sshPortLabel">
<property name="text">
<string>SSH:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sshPortSpinBox">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>22</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gdbServerLabel">
<property name="text">
<string>Gdb server:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="gdbServerPortSpinBox">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="connectionTimeoutLabel">
<property name="text">
<string>Connection timeout:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="timeoutLineEdit">
<property name="placeholderText">
<string>Timeout value in milliseconds</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="userNameLabel">
<property name="text">
<string>User name:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="userLineEdit"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="pwdLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="Utils::PathChooser" name="keyFileLineEdit" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
@@ -335,8 +348,8 @@
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>273</x>
<y>108</y>
<x>231</x>
<y>99</y>
</hint>
<hint type="destinationlabel">
<x>511</x>
@@ -351,8 +364,8 @@
<slot>hostNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>163</y>
<x>335</x>
<y>148</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
@@ -367,8 +380,8 @@
<slot>timeoutEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>225</y>
<x>335</x>
<y>202</y>
</hint>
<hint type="destinationlabel">
<x>425</x>
@@ -383,8 +396,8 @@
<slot>userNameEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>255</y>
<x>335</x>
<y>228</y>
</hint>
<hint type="destinationlabel">
<x>422</x>
@@ -399,8 +412,8 @@
<slot>passwordEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>285</y>
<x>335</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>423</x>
@@ -415,8 +428,8 @@
<slot>deviceTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>108</y>
<x>335</x>
<y>99</y>
</hint>
<hint type="destinationlabel">
<x>426</x>
@@ -447,8 +460,8 @@
<slot>deleteConfig()</slot>
<hints>
<hint type="sourcelabel">
<x>523</x>
<y>69</y>
<x>473</x>
<y>61</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
@@ -463,8 +476,8 @@
<slot>authenticationTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>273</x>
<y>133</y>
<x>231</x>
<y>122</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
@@ -479,8 +492,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>305</y>
<x>335</x>
<y>273</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
@@ -495,8 +508,8 @@
<slot>keyFileEditingFinished()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>305</y>
<x>335</x>
<y>273</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
@@ -511,8 +524,8 @@
<slot>testConfig()</slot>
<hints>
<hint type="sourcelabel">
<x>523</x>
<y>102</y>
<x>473</x>
<y>90</y>
</hint>
<hint type="destinationlabel">
<x>428</x>
@@ -527,8 +540,8 @@
<slot>deployKey()</slot>
<hints>
<hint type="sourcelabel">
<x>523</x>
<y>135</y>
<x>473</x>
<y>148</y>
</hint>
<hint type="destinationlabel">
<x>510</x>
@@ -543,8 +556,8 @@
<slot>authenticationTypeChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>133</y>
<x>335</x>
<y>122</y>
</hint>
<hint type="destinationlabel">
<x>525</x>
@@ -568,6 +581,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>generateKeyButton</sender>
<signal>clicked()</signal>
<receiver>MaemoSettingsWidget</receiver>
<slot>showGenerateSshKeyDialog()</slot>
<hints>
<hint type="sourcelabel">
<x>403</x>
<y>107</y>
</hint>
<hint type="destinationlabel">
<x>358</x>
<y>-11</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>configNameEditingFinished()</slot>
@@ -586,5 +615,6 @@
<slot>deployKey()</slot>
<slot>gdbServerPortEditingFinished()</slot>
<slot>currentConfigChanged(int)</slot>
<slot>showGenerateSshKeyDialog()</slot>
</slots>
</ui>

View File

@@ -33,96 +33,105 @@
****************************************************************************/
#include "maemosshconfigdialog.h"
#include "maemosshthread.h"
#include <coreplugin/icore.h>
#include "maemodeviceconfigurations.h"
#include "ne7sshobject.h"
#include <ne7ssh.h>
#include <QtCore/QDir>
#include <QtNetwork/QHostInfo>
#include <QtGui/QApplication>
#include <QtGui/QDesktopServices>
#include <QtGui/QFileDialog>
using namespace Qt4ProjectManager::Internal;
MaemoSshConfigDialog::MaemoSshConfigDialog(QWidget *parent)
: QDialog(parent)
, m_keyDeployer(0)
, home(QDesktopServices::storageLocation(QDesktopServices::HomeLocation))
{
m_ui.setupUi(this);
const QLatin1String root("MaemoSsh/");
QSettings *settings = Core::ICore::instance()->settings();
m_ui.useKeyFromPath->setChecked(settings->value(root + QLatin1String("userKey"),
false).toBool());
m_ui.keyFileLineEdit->setExpectedKind(Utils::PathChooser::File);
m_ui.keyFileLineEdit->setPath(settings->value(root + QLatin1String("keyPath"),
QDir::toNativeSeparators(QDir::homePath() + QLatin1String("/.ssh/id_rsa.pub")))
.toString());
connect(m_ui.rsa, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
connect(m_ui.dsa, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(deployKey()));
connect(m_ui.generateButton, SIGNAL(clicked()), this, SLOT(generateSshKey()));
connect(m_ui.savePublicKey, SIGNAL(clicked()), this, SLOT(savePublicKey()));
connect(m_ui.savePrivateKey, SIGNAL(clicked()), this, SLOT(savePrivateKey()));
}
MaemoSshConfigDialog::~MaemoSshConfigDialog()
{
}
void MaemoSshConfigDialog::slotToggled()
{
m_ui.comboBox->setCurrentIndex(0);
m_ui.comboBox->setEnabled(m_ui.rsa->isChecked());
}
void MaemoSshConfigDialog::generateSshKey()
{
if (!m_ui.keyFileLineEdit->isValid()) {
ne7ssh ssh;
ssh.generateKeyPair("rsa", "test", "id_rsa", "id_rsa.pub");
algorithm = m_ui.rsa->isChecked() ? "rsa" : "dsa";
tmpKey = QDir::tempPath().append(QLatin1Char('/') + algorithm).toUtf8();
QByteArray userId = QString(home.mid(home.lastIndexOf(QLatin1Char('/')) + 1)
+ QLatin1Char('@') + QHostInfo::localHostName()).toUtf8();
QFile::remove(tmpKey);
QFile::remove(tmpKey + ".pub");
QApplication::setOverrideCursor(Qt::BusyCursor);
QSharedPointer<ne7ssh> ssh = Ne7SshObject::instance()->get();
if (ssh->generateKeyPair(algorithm, userId, tmpKey, tmpKey + ".pub",
m_ui.comboBox->currentText().toUShort())) {
QFile file(tmpKey + ".pub");
if (file.open(QIODevice::ReadOnly))
m_ui.plainTextEdit->setPlainText(file.readAll());
m_ui.savePublicKey->setEnabled(true);
m_ui.savePrivateKey->setEnabled(true);
} else {
m_ui.infoLabel->setText("An public key has been created already.");
m_ui.plainTextEdit->setPlainText(tr("Could not create SSH key pair."));
}
QApplication::restoreOverrideCursor();
}
void MaemoSshConfigDialog::deployKey()
void MaemoSshConfigDialog::savePublicKey()
{
if (m_keyDeployer)
return;
checkSshDir();
copyFile(QFileDialog::getSaveFileName(this, tr("Choose folder to save "
"public key file"), home + QString::fromLatin1("/.ssh/id_%1.pub")
.arg(algorithm.constData())), true);
}
if (m_ui.keyFileLineEdit->validatePath(m_ui.keyFileLineEdit->path())) {
m_ui.deployButton->disconnect();
//SshDeploySpec deploySpec(keyFile, homeDirOnDevice(currentConfig().uname)
// + QLatin1String("/.ssh/authorized_keys"), true);
//m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList<SshDeploySpec>()
// << deploySpec);
//connect(m_keyDeployer, SIGNAL(finished()), this,
// SLOT(handleDeployThreadFinished()));
if (m_keyDeployer) {
m_keyDeployer->start();
m_ui.deployButton->setText(tr("Stop deploying"));
connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(stopDeploying()));
void MaemoSshConfigDialog::savePrivateKey()
{
checkSshDir();
copyFile(QFileDialog::getSaveFileName(this, tr("Choose folder to save "
"private key file"), home + QString::fromLatin1("/.ssh/id_%1")
.arg(algorithm.constData())), false);
}
void MaemoSshConfigDialog::checkSshDir()
{
QDir dir(home + QString::fromLatin1("/.ssh"));
if (!dir.exists())
dir.mkpath(home + QString::fromLatin1("/.ssh"));
}
void MaemoSshConfigDialog::copyFile(const QString &file, bool pubKey)
{
if (!file.isEmpty()) {
if (!QFile::exists(file) || QFile::remove(file)) {
QFile(tmpKey + (pubKey ? ".pub" : "")).copy(file);
if (pubKey)
emit publicKeyGenerated(file);
else
emit privateKeyGenerated(file);
}
} else {
m_ui.infoLabel->setText("The public key path is invalid.");
}
}
void MaemoSshConfigDialog::handleDeployThreadFinished()
{
if (!m_keyDeployer)
return;
if (m_keyDeployer->hasError()) {
m_ui.infoLabel->setText(tr("Key deployment failed: %1")
.arg(m_keyDeployer->error()));
} else {
m_ui.infoLabel->setText(tr("Key was successfully deployed."));
}
stopDeploying();
}
void MaemoSshConfigDialog::stopDeploying()
{
if (m_keyDeployer) {
m_ui.deployButton->disconnect();
const bool buttonWasEnabled = m_ui.deployButton->isEnabled();
m_keyDeployer->disconnect();
m_keyDeployer->stop();
delete m_keyDeployer;
m_keyDeployer = 0;
m_ui.deployButton->setText(tr("Deploy Public Key"));
connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(deployKey()));
m_ui.deployButton->setEnabled(buttonWasEnabled);
}
}

View File

@@ -42,8 +42,6 @@
namespace Qt4ProjectManager {
namespace Internal {
class MaemoSshDeployer;
class MaemoSshConfigDialog : public QDialog
{
Q_OBJECT
@@ -51,15 +49,25 @@ public:
MaemoSshConfigDialog(QWidget *parent = 0);
~MaemoSshConfigDialog();
signals:
void publicKeyGenerated(const QString &path);
void privateKeyGenerated(const QString &path);
private slots:
void slotToggled();
void generateSshKey();
void deployKey();
void handleDeployThreadFinished();
void stopDeploying();
void savePublicKey();
void savePrivateKey();
private:
void checkSshDir();
void copyFile(const QString &file, bool pubKey);
private:
QString home;
QByteArray tmpKey;
QByteArray algorithm;
Ui::MaemoSshConfigDialog m_ui;
MaemoSshDeployer *m_keyDeployer;
};
} // Qt4ProjectManager

View File

@@ -9,117 +9,218 @@
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>128</height>
<width>500</width>
<height>275</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>275</height>
</size>
</property>
<property name="windowTitle">
<string>SSH Key Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="useKeyFromPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Use key from location:</string>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="keySize">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Key size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string notr="true">1024</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">2048</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">4096</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>328</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="keyAlgo">
<property name="text">
<string>Key algorithm:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="rsa">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>RSA</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="dsa">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>DSA</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Key</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="plainText">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="generateButton">
<property name="text">
<string>Generate SSH Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="savePublicKey">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save public Key...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="savePrivateKey">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save private Key...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="keyLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="keyFileLineEdit" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="generateButton">
<property name="text">
<string>Generate SSH Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -131,13 +232,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="deployButton">
<property name="text">
<string>Deploy Public Key</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="text">
@@ -149,23 +243,8 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
<slots>
<signal>editingFinished()</signal>
<signal>browsingFinished()</signal>
</slots>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>closeButton</tabstop>
<tabstop>deployButton</tabstop>
<tabstop>generateButton</tabstop>
<tabstop>useKeyFromPath</tabstop>
</tabstops>
<resources/>
<connections>
@@ -185,37 +264,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>useKeyFromPath</sender>
<signal>toggled(bool)</signal>
<receiver>keyLabel</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>83</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>73</x>
<y>42</y>
</hint>
</hints>
</connection>
<connection>
<sender>useKeyFromPath</sender>
<signal>toggled(bool)</signal>
<receiver>keyFileLineEdit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>193</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>246</x>
<y>42</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -13,6 +13,7 @@ HEADERS += \
$$PWD/maemorunfactories.h \
$$PWD/maemosettingspage.h \
$$PWD/maemosettingswidget.h \
$$PWD/maemosshconfigdialog.h \
$$PWD/maemosshconnection.h \
$$PWD/maemosshthread.h \
$$PWD/maemotoolchain.h \
@@ -31,6 +32,7 @@ SOURCES += \
$$PWD/maemorunfactories.cpp \
$$PWD/maemosettingspage.cpp \
$$PWD/maemosettingswidget.cpp \
$$PWD/maemosshconfigdialog.cpp \
$$PWD/maemosshconnection.cpp \
$$PWD/maemosshthread.cpp \
$$PWD/maemotoolchain.cpp \
@@ -41,6 +43,7 @@ SOURCES += \
FORMS += \
$$PWD/maemoconfigtestdialog.ui \
$$PWD/maemosettingswidget.ui
$$PWD/maemosettingswidget.ui \
$$PWD/maemosshconfigdialog.ui
RESOURCES += $$PWD/qt-maemo.qrc