summaryrefslogtreecommitdiff
path: root/src/plugins/qnx/blackberrydeviceconnectionmanager.cpp
diff options
context:
space:
mode:
authorDavid Kaspar <dkaspar@blackberry.com>2013-08-13 18:07:43 +0200
committerDavid Kaspar <dkaspar@blackberry.com>2013-08-14 13:38:02 +0200
commit8b92500769f2d65178f3025d1b1a7505eff58433 (patch)
tree6d199da7d30415bc3f6df427b08ef6610373b1af /src/plugins/qnx/blackberrydeviceconnectionmanager.cpp
parent772e6698d14699eb5fee7ea958da18ca3a9f22e8 (diff)
downloadqt-creator-8b92500769f2d65178f3025d1b1a7505eff58433.tar.gz
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: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: David Kaspar <dkaspar@blackberry.com>
Diffstat (limited to 'src/plugins/qnx/blackberrydeviceconnectionmanager.cpp')
-rw-r--r--src/plugins/qnx/blackberrydeviceconnectionmanager.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/plugins/qnx/blackberrydeviceconnectionmanager.cpp b/src/plugins/qnx/blackberrydeviceconnectionmanager.cpp
index da19bc810d..4355155678 100644
--- a/src/plugins/qnx/blackberrydeviceconnectionmanager.cpp
+++ b/src/plugins/qnx/blackberrydeviceconnectionmanager.cpp
@@ -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);