Commit 8b925007 authored by David Kaspar's avatar David Kaspar

Qnx: Auto-generating SSH key used for connecting to a BB10 device

BlackBerryDeviceConfigurationWizardSshKeyPage wizard page has been removed.
It is not needed anymore. The wizard automatically generates or reuses
a SSH key that is stores in __settings__/qnx/id_rsa file. The same SSH key
is used for connecting to all BB10 devices.
The generation of 'default' SSH key is gone as a second step of
BlackBerryDeviceConfigurationWizardQueryPage wizard page.

Disabling device-tester for BlackBerryDeviceConfiguration.
Task-number: QTCREATORBUG-9977

Change-Id: Ice6068530c9c72fa82907decaaa3dca6077e9c3a
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarDavid Kaspar <dkaspar@blackberry.com>
parent 772e6698
......@@ -98,6 +98,13 @@ IDevice::Ptr BlackBerryDeviceConfiguration::clone() const
return Ptr(new BlackBerryDeviceConfiguration(*this));
}
bool BlackBerryDeviceConfiguration::hasDeviceTester() const
{
// we are unable to easily verify that a device is available unless we duplicate
// 'Connect to device' functionality, therefore disabling device-tester
return false;
}
BlackBerryDeviceConfiguration::ConstPtr BlackBerryDeviceConfiguration::device(const Kit *k)
{
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
......
......@@ -64,6 +64,7 @@ public:
QString displayNameForActionId(Core::Id actionId) const;
void executeAction(Core::Id actionId, QWidget *parent) const;
ProjectExplorer::IDevice::Ptr clone() const;
bool hasDeviceTester() const;
static ConstPtr device(const ProjectExplorer::Kit *k);
......
......@@ -33,6 +33,7 @@
#include "blackberrydeviceconfigurationwizardpages.h"
#include "qnxconstants.h"
#include "blackberrydeviceconfiguration.h"
#include "blackberrydeviceconnectionmanager.h"
#include <ssh/sshconnection.h>
......@@ -46,13 +47,11 @@ BlackBerryDeviceConfigurationWizard::BlackBerryDeviceConfigurationWizard(QWidget
m_setupPage = new BlackBerryDeviceConfigurationWizardSetupPage(this);
m_queryPage = new BlackBerryDeviceConfigurationWizardQueryPage(m_holder, this);
m_sshKeyPage = new BlackBerryDeviceConfigurationWizardSshKeyPage(this);
m_configPage = new BlackBerryDeviceConfigurationWizardConfigPage(m_holder, this);
m_finalPage = new BlackBerryDeviceConfigurationWizardFinalPage(this);
setPage(SetupPageId, m_setupPage);
setPage(QueryPageId, m_queryPage);
setPage(SshKeyPageId, m_sshKeyPage);
setPage(ConfigPageId, m_configPage);
setPage(FinalPageId, m_finalPage);
m_finalPage->setCommitPage(true);
......@@ -65,7 +64,7 @@ ProjectExplorer::IDevice::Ptr BlackBerryDeviceConfigurationWizard::device()
sshParams.host = m_setupPage->hostName();
sshParams.password = m_setupPage->password();
sshParams.authenticationType = QSsh::SshConnectionParameters::AuthenticationTypePublicKey;
sshParams.privateKeyFile = m_sshKeyPage->privateKey();
sshParams.privateKeyFile = BlackBerryDeviceConnectionManager::instance()->privateKeyPath();
sshParams.userName = QLatin1String("devuser");
sshParams.timeout = 10;
sshParams.port = 22;
......
......@@ -53,14 +53,12 @@ private:
enum PageId {
SetupPageId,
QueryPageId,
SshKeyPageId,
ConfigPageId,
FinalPageId
};
BlackBerryDeviceConfigurationWizardSetupPage *m_setupPage;
BlackBerryDeviceConfigurationWizardQueryPage *m_queryPage;
BlackBerryDeviceConfigurationWizardSshKeyPage *m_sshKeyPage;
BlackBerryDeviceConfigurationWizardConfigPage *m_configPage;
BlackBerryDeviceConfigurationWizardFinalPage *m_finalPage;
......
......@@ -102,6 +102,11 @@ private:
class BlackBerryDeviceConfigurationWizardQueryPage : public QWizardPage
{
Q_OBJECT
enum QueryState
{
Querying = 0, GeneratingSshKey, Done
};
public:
explicit BlackBerryDeviceConfigurationWizardQueryPage(BlackBerryDeviceConfigurationWizardHolder &holder, QWidget *parent = 0);
~BlackBerryDeviceConfigurationWizardQueryPage();
......@@ -111,38 +116,18 @@ public:
private slots:
void processQueryFinished(int status);
void sshKeysGenerationFailed(const QString &error);
void processSshKeys(const QByteArray &privateKey, const QByteArray &publicKey);
private:
void checkAndGenerateSSHKeys();
void queryDone();
void setState(QueryState state, const QString &message);
Ui::BlackBerryDeviceConfigurationWizardQueryPage *m_ui;
BlackBerryDeviceConfigurationWizardHolder &m_holder;
BlackBerryDeviceInformation *m_deviceInformation;
};
class BlackBerryDeviceConfigurationWizardSshKeyPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryDeviceConfigurationWizardSshKeyPage(QWidget *parent = 0);
~BlackBerryDeviceConfigurationWizardSshKeyPage();
void initializePage();
bool isComplete() const;
QString privateKey() const;
QString publicKey() const;
private slots:
void findMatchingPublicKey(const QString &privateKeyPath);
void sshKeysGenerationFailed(const QString &error);
void processSshKeys(const QString &privateKeyPath, const QByteArray &privateKey, const QByteArray &publicKey);
void generateSshKeys();
private:
bool saveKeys(const QByteArray &privateKey, const QByteArray &publicKey, const QString &privateKeyPath, const QString &publicKeyPath);
void setBusy(bool busy);
Ui::BlackBerryDeviceConfigurationWizardSshKeyPage *m_ui;
QueryState m_state;
};
class BlackBerryDeviceConfigurationWizardConfigPage : public QWizardPage
......
......@@ -25,11 +25,7 @@
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>0</number>
</property>
</widget>
<widget class="QProgressBar" name="progressBar"/>
</item>
<item>
<spacer name="verticalSpacer">
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BlackBerryDeviceConfigurationWizardSshKeyPage</class>
<widget class="QWizardPage" name="Qnx::Internal::BlackBerryDeviceConfigurationWizardSshKeyPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>409</width>
<height>185</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="publicKey">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Utils::PathChooser" name="privateKey" native="true"/>
</item>
<item>
<widget class="QPushButton" name="generate">
<property name="text">
<string>Generate...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Public key file:</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>SSH public key is used for securing a connection to a device.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</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>generate</tabstop>
<tabstop>publicKey</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
......@@ -35,10 +35,16 @@
#include "blackberrydeviceconnection.h"
#include "qnxconstants.h"
#include <coreplugin/icore.h>
#include <projectexplorer/devicesupport/devicemanager.h>
#include <ssh/sshconnection.h>
#include <ssh/sshkeygenerator.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <QDir>
using namespace Qnx;
using namespace Qnx::Internal;
......@@ -164,6 +170,59 @@ void BlackBerryDeviceConnectionManager::disconnectDevice(const ProjectExplorer::
disconnectDevice(device->id());
}
/*!
* @brief Returns default private key path in local settings.
* @return the default private key path
*/
const QString BlackBerryDeviceConnectionManager::privateKeyPath() const
{
return QFileInfo(Core::ICore::settings()->fileName()).absolutePath() + QLatin1String("/qtcreator/qnx/id_rsa");
}
/*!
* @brief Checks validity of default SSH keys used for connecting to a device.
* @return true, if the default SSH keys are valid
*/
bool BlackBerryDeviceConnectionManager::hasValidSSHKeys() const
{
const QString privateKey = privateKeyPath();
QFileInfo privateKeyFileInfo(privateKey);
QFileInfo publicKeyFileInfo(privateKey + QLatin1String(".pub"));
return privateKeyFileInfo.exists() && privateKeyFileInfo.isReadable()
&& publicKeyFileInfo.exists() && publicKeyFileInfo.isReadable();
}
/*!
* @brief Stores a new private and public SSH key in local settings.
* @param privateKeyContent the private key content
* @param publicKeyContent the public key content
*/
bool BlackBerryDeviceConnectionManager::setSSHKeys(const QByteArray privateKeyContent,
const QByteArray publicKeyContent, QString *error)
{
const QString privateKey = privateKeyPath();
const QString publicKey = privateKey + QLatin1String(".pub");
QFileInfo fileInfo(privateKey);
QDir dir = fileInfo.dir();
if (!dir.exists())
dir.mkpath(QLatin1String("."));
Utils::FileSaver privSaver(privateKey);
privSaver.write(privateKeyContent);
if (!privSaver.finalize(error))
return false;
QFile::setPermissions(privateKey, QFile::ReadOwner | QFile::WriteOwner);
Utils::FileSaver pubSaver(publicKey);
pubSaver.write(publicKeyContent);
if (!pubSaver.finalize(error))
return false;
return true;
}
void BlackBerryDeviceConnectionManager::disconnectDevice(Core::Id deviceId)
{
BlackBerryDeviceConnection *connection = m_connections.key(deviceId);
......
......@@ -60,6 +60,11 @@ public:
void connectDevice(const ProjectExplorer::IDevice::ConstPtr &device);
void disconnectDevice(const ProjectExplorer::IDevice::ConstPtr &device);
const QString privateKeyPath() const;
bool hasValidSSHKeys() const;
bool setSSHKeys(const QByteArray privateKeyContent, const QByteArray publicKeyContent,
QString *error);
signals:
void connectionOutput(Core::Id deviceId, const QString &output);
void deviceAboutToConnect(Core::Id deviceId);
......
......@@ -34,10 +34,9 @@
using namespace Qnx::Internal;
BlackBerrySshKeysGenerator::BlackBerrySshKeysGenerator(const QString &privateKeyPath)
BlackBerrySshKeysGenerator::BlackBerrySshKeysGenerator()
: QThread(0)
, m_keyGen(new QSsh::SshKeyGenerator)
, m_privateKeyPath(privateKeyPath)
{
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
}
......@@ -66,7 +65,7 @@ void BlackBerrySshKeysGenerator::run()
publicKey.truncate(secondSpace);
}
emit sshKeysGenerationFinished(m_privateKeyPath, m_keyGen->privateKey(), publicKey);
emit sshKeysGenerationFinished(m_keyGen->privateKey(), publicKey);
} else
emit sshKeysGenerationFailed(m_keyGen->error());
}
......@@ -44,16 +44,15 @@ class BlackBerrySshKeysGenerator : public QThread
{
Q_OBJECT
public:
BlackBerrySshKeysGenerator(const QString &privateKeyPath);
BlackBerrySshKeysGenerator();
~BlackBerrySshKeysGenerator();
signals:
void sshKeysGenerationFailed(const QString &error);
void sshKeysGenerationFinished(const QString &privateKeyPath, const QByteArray &privateKey, const QByteArray &publicKey);
void sshKeysGenerationFinished(const QByteArray &privateKey, const QByteArray &publicKey);
private:
QSsh::SshKeyGenerator *m_keyGen;
const QString m_privateKeyPath;
void run();
};
......
......@@ -195,7 +195,6 @@ HEADERS += qnxplugin.h\
FORMS += \
blackberrydeviceconfigurationwizardsetuppage.ui \
blackberryrunconfigurationwidget.ui \
blackberrydeviceconfigurationwizardsshkeypage.ui \
blackberrydeployconfigurationwidget.ui \
blackberrydeviceconfigurationwidget.ui \
qnxbaseqtconfigwidget.ui \
......
......@@ -110,7 +110,6 @@ QtcPlugin {
"blackberrydeviceconfigurationwizardpages.h",
"blackberrydeviceconfigurationwizardquerypage.ui",
"blackberrydeviceconfigurationwizardsetuppage.ui",
"blackberrydeviceconfigurationwizardsshkeypage.ui",
"blackberrydeviceconnection.cpp",
"blackberrydeviceconnection.h",
"blackberrydeviceconnectionmanager.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment