From 41bdf34275145573957bdaeaeb5b6bab035b468c Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Thu, 17 Jan 2013 16:06:13 -0200 Subject: [PATCH] Initial implementation of BB key management Change-Id: Iba9c264b6c5809a0714da69591248fc2962c6526 Reviewed-by: Nicolas Arnaud-Cormos Reviewed-by: Tobias Hunger --- src/plugins/qnx/blackberrycertificate.cpp | 179 +++++++++ src/plugins/qnx/blackberrycertificate.h | 92 +++++ .../qnx/blackberrycertificatemodel.cpp | 206 ++++++++++ src/plugins/qnx/blackberrycertificatemodel.h | 89 +++++ src/plugins/qnx/blackberryconfiguration.cpp | 187 +++++++-- src/plugins/qnx/blackberryconfiguration.h | 30 +- .../qnx/blackberrycreatecertificatedialog.cpp | 208 ++++++++++ .../qnx/blackberrycreatecertificatedialog.h | 82 ++++ .../qnx/blackberrycreatecertificatedialog.ui | 133 +++++++ src/plugins/qnx/blackberrycsjregistrar.cpp | 115 ++++++ src/plugins/qnx/blackberrycsjregistrar.h | 71 ++++ .../qnx/blackberryimportcertificatedialog.cpp | 142 +++++++ .../qnx/blackberryimportcertificatedialog.h | 82 ++++ .../qnx/blackberryimportcertificatedialog.ui | 70 ++++ src/plugins/qnx/blackberrykeyspage.cpp | 70 ++++ src/plugins/qnx/blackberrykeyspage.h | 58 +++ src/plugins/qnx/blackberrykeyswidget.cpp | 209 +++++++++++ src/plugins/qnx/blackberrykeyswidget.h | 84 +++++ src/plugins/qnx/blackberrykeyswidget.ui | 120 ++++++ .../qnx/blackberryndksettingswidget.cpp | 4 +- .../qnx/blackberryregisterkeydialog.cpp | 352 +++++++++++++++++ src/plugins/qnx/blackberryregisterkeydialog.h | 99 +++++ .../qnx/blackberryregisterkeydialog.ui | 354 ++++++++++++++++++ src/plugins/qnx/qnx.pro | 26 +- src/plugins/qnx/qnx.qbs | 22 ++ src/plugins/qnx/qnxconstants.h | 5 + src/plugins/qnx/qnxplugin.cpp | 2 + 27 files changed, 3058 insertions(+), 33 deletions(-) create mode 100644 src/plugins/qnx/blackberrycertificate.cpp create mode 100644 src/plugins/qnx/blackberrycertificate.h create mode 100644 src/plugins/qnx/blackberrycertificatemodel.cpp create mode 100644 src/plugins/qnx/blackberrycertificatemodel.h create mode 100644 src/plugins/qnx/blackberrycreatecertificatedialog.cpp create mode 100644 src/plugins/qnx/blackberrycreatecertificatedialog.h create mode 100644 src/plugins/qnx/blackberrycreatecertificatedialog.ui create mode 100644 src/plugins/qnx/blackberrycsjregistrar.cpp create mode 100644 src/plugins/qnx/blackberrycsjregistrar.h create mode 100644 src/plugins/qnx/blackberryimportcertificatedialog.cpp create mode 100644 src/plugins/qnx/blackberryimportcertificatedialog.h create mode 100644 src/plugins/qnx/blackberryimportcertificatedialog.ui create mode 100644 src/plugins/qnx/blackberrykeyspage.cpp create mode 100644 src/plugins/qnx/blackberrykeyspage.h create mode 100644 src/plugins/qnx/blackberrykeyswidget.cpp create mode 100644 src/plugins/qnx/blackberrykeyswidget.h create mode 100644 src/plugins/qnx/blackberrykeyswidget.ui create mode 100644 src/plugins/qnx/blackberryregisterkeydialog.cpp create mode 100644 src/plugins/qnx/blackberryregisterkeydialog.h create mode 100644 src/plugins/qnx/blackberryregisterkeydialog.ui diff --git a/src/plugins/qnx/blackberrycertificate.cpp b/src/plugins/qnx/blackberrycertificate.cpp new file mode 100644 index 00000000000..a5b008c6ae8 --- /dev/null +++ b/src/plugins/qnx/blackberrycertificate.cpp @@ -0,0 +1,179 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrycertificate.h" +#include "blackberryconfiguration.h" + +#include + +#include +#include +#include + +namespace Qnx { +namespace Internal { + +BlackBerryCertificate::BlackBerryCertificate(const QString &fileName, + const QString &author, const QString &storePass, QObject *parent) : + QObject(parent), + m_fileName(fileName), + m_author(author), + m_storePass(storePass), + m_process(new QProcess(this)) +{ +} + +void BlackBerryCertificate::load() +{ + if (m_process->state() != QProcess::NotRunning) { + emit finished(BlackBerryCertificate::Busy); + return; + } + QStringList arguments; + + arguments << QLatin1String("-keystore") + << m_fileName + << QLatin1String("-list") + << QLatin1String("-verbose") + << QLatin1String("-storepass") + << m_storePass; + + connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), + this, SLOT(loadFinished())); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(processError())); + + m_process->start(command(), arguments); +} + +void BlackBerryCertificate::store() +{ + if (m_process->state() != QProcess::NotRunning) { + emit finished(BlackBerryCertificate::Busy); + return; + } + + QFile file(m_fileName); + + if (file.exists()) + file.remove(); + + QStringList arguments; + + arguments << QLatin1String("-genkeypair") + << QLatin1String("-storepass") + << m_storePass + << QLatin1String("-author") + << m_author + << QLatin1String("-keystore") + << m_fileName; + + connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), + this, SLOT(storeFinished(int))); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(processError())); + + m_process->start(command(), arguments); +} + +QString BlackBerryCertificate::fileName() const +{ + return m_fileName; +} + +QString BlackBerryCertificate::author() const +{ + return m_author; +} + +QString BlackBerryCertificate::id() const +{ + QString tmpId = fileName(); + return tmpId.replace(QLatin1String("/"), QLatin1String("-")); +} + +void BlackBerryCertificate::storeFinished(int status) +{ + m_process->disconnect(); + + if (status == 0) + emit finished(BlackBerryCertificate::Success); + else + emit finished(BlackBerryCertificate::Error); +} + +void BlackBerryCertificate::loadFinished() +{ + m_process->disconnect(); + + ResultCode status = Error; + + QTextStream processOutput(m_process); + + while (!processOutput.atEnd()) { + QString chunk = processOutput.readLine(); + + if (chunk.contains( + QLatin1String("Error: Failed to decrypt keystore, invalid password"))) { + status = WrongPassword; + break; + } else if (chunk.startsWith(QLatin1String("Owner:"))) { + chunk.remove(QLatin1String("Owner:")); + m_author = chunk.remove(QLatin1String("CN=")).trimmed(); + status = Success; + break; + } + } + + emit finished(status); +} + +void BlackBerryCertificate::processError() +{ + m_process->disconnect(); + + emit finished(Error); +} + +QString BlackBerryCertificate::command() const +{ + QString command = BlackBerryConfiguration::instance() + .qnxEnv().value(QLatin1String("QNX_HOST")) + + QLatin1String("/usr/bin/blackberry-keytool"); + + if (Utils::HostOsInfo::isWindowsHost()) + command += QLatin1String(".bat"); + + return command; +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrycertificate.h b/src/plugins/qnx/blackberrycertificate.h new file mode 100644 index 00000000000..3a3069a7ca2 --- /dev/null +++ b/src/plugins/qnx/blackberrycertificate.h @@ -0,0 +1,92 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYCERTIFICATE_H +#define QNX_INTERNAL_BLACKBERRYCERTIFICATE_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QProcess; +QT_END_NAMESPACE + +namespace Qnx { +namespace Internal { + +class BlackBerryCertificate : public QObject +{ +Q_OBJECT + +public: + enum ResultCode { + Success, + Busy, + WrongPassword, + Error + }; + + BlackBerryCertificate(const QString &fileName, + const QString &author = QString(), + const QString &storePass = QString(), + QObject *parent = 0); + + void load(); + void store(); + + QString fileName() const; + QString author() const; + QString id() const; + +signals: + void loaded(); + void stored(); + void finished(int status); + +private slots: + void storeFinished(int status); + void loadFinished(); + void processError(); + +private: + QString command() const; + + QString m_fileName; + QString m_author; + QString m_storePass; + + QProcess *m_process; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYCERTIFICATE_H diff --git a/src/plugins/qnx/blackberrycertificatemodel.cpp b/src/plugins/qnx/blackberrycertificatemodel.cpp new file mode 100644 index 00000000000..e456615e050 --- /dev/null +++ b/src/plugins/qnx/blackberrycertificatemodel.cpp @@ -0,0 +1,206 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrycertificatemodel.h" +#include "blackberrycertificate.h" +#include "blackberryconfiguration.h" + +#include + +#include +#include + +namespace Qnx { +namespace Internal { + +const QLatin1String SettingsGroup("BlackBerryConfiguration"); +const QLatin1String CertificateGroup("Certificates"); + +BlackBerryCertificateModel::BlackBerryCertificateModel(QObject *parent) : + QAbstractTableModel(parent), + m_activeCertificate(0) +{ + load(); +} + +BlackBerryCertificateModel::~BlackBerryCertificateModel() +{ +} + +int BlackBerryCertificateModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return m_certificates.count(); +} + +int BlackBerryCertificateModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return ColumnCount; +} + +QVariant BlackBerryCertificateModel::data(const QModelIndex &index, int role) const +{ + if (index.row() >= rowCount() || index.column() >= columnCount()) + return QVariant(); + + const BlackBerryCertificate *cert = m_certificates.at(index.row()); + + if (role == Qt::CheckStateRole) { + if (index.column() == CertActive) + return (m_activeCertificate == cert) ? Qt::Checked : Qt::Unchecked; + } else if (role == Qt::DisplayRole) { + if (index.column() == CertPath) + return cert->fileName(); + else if (index.column() == CertAuthor) + return cert->author(); + } + + return QVariant(); +} + +QVariant BlackBerryCertificateModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Vertical) + return section; + + switch (section) { + case CertPath: + return tr("Path"); + case CertAuthor: + return tr("Author"); + case CertActive: + return tr("Active"); + default: + break; + } + + return section; +} + +bool BlackBerryCertificateModel::setData(const QModelIndex &ind, + const QVariant &value, int role) +{ + Q_UNUSED(value); + + if (role == Qt::CheckStateRole && ind.column() == CertActive) { + const int oldIndex = m_certificates.indexOf(m_activeCertificate); + + m_activeCertificate = m_certificates.at(ind.row()); + + if (oldIndex >= 0) + emit dataChanged(index(oldIndex, CertActive), index(oldIndex, CertActive)); + + emit dataChanged(ind, ind); + + return true; + } + + return false; +} + +bool BlackBerryCertificateModel::removeRows(int row, int count, + const QModelIndex &parent) +{ + + beginRemoveRows(parent, row, row + count - 1); + + for (int i = 0; i < count; i++) { + BlackBerryCertificate *cert = m_certificates.takeAt(row); + //XXX shall we also delete from disk? + delete cert; + } + + endRemoveRows(); + + return true; +} + +Qt::ItemFlags BlackBerryCertificateModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; + + switch (index.column()) { + case CertActive: + flags |= Qt::ItemIsUserCheckable; + break; + default: + break; + } + + return flags; +} + +BlackBerryCertificate * BlackBerryCertificateModel::activeCertificate() const +{ + return m_activeCertificate; +} + +QList BlackBerryCertificateModel::certificates() const +{ + return m_certificates; +} + +bool BlackBerryCertificateModel::insertCertificate(BlackBerryCertificate *certificate) +{ + if (m_certificates.contains(certificate)) + return false; + + beginInsertRows(QModelIndex(), m_certificates.count(), m_certificates.count()); + + if (m_certificates.isEmpty()) + m_activeCertificate = certificate; + + certificate->setParent(this); + m_certificates << certificate; + + endInsertRows(); + + return true; +} + +void BlackBerryCertificateModel::load() +{ + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + m_certificates = configuration.certificates(); + m_activeCertificate = configuration.activeCertificate(); +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrycertificatemodel.h b/src/plugins/qnx/blackberrycertificatemodel.h new file mode 100644 index 00000000000..a22ce38e407 --- /dev/null +++ b/src/plugins/qnx/blackberrycertificatemodel.h @@ -0,0 +1,89 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYCERTIFICATESTOREMODEL_H +#define QNX_INTERNAL_BLACKBERRYCERTIFICATESTOREMODEL_H + +#include +#include + +namespace Qnx { +namespace Internal { + +class BlackBerryCertificate; + +class BlackBerryCertificateModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit BlackBerryCertificateModel(QObject *parent = 0); + ~BlackBerryCertificateModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + bool removeRows(int row, int count, + const QModelIndex &parent = QModelIndex()); + + bool insertCertificate(BlackBerryCertificate *certificate); + + Qt::ItemFlags flags(const QModelIndex &index) const; + + BlackBerryCertificate *activeCertificate() const; + QList certificates() const; + +private slots: + void load(); + +private: + enum Columns { + CertPath, + CertAuthor, + CertActive, + ColumnCount + }; + + QList m_certificates; + BlackBerryCertificate *m_activeCertificate; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYCERTIFICATESTOREMODEL_H diff --git a/src/plugins/qnx/blackberryconfiguration.cpp b/src/plugins/qnx/blackberryconfiguration.cpp index 23c381afd68..c27a84bdda1 100644 --- a/src/plugins/qnx/blackberryconfiguration.cpp +++ b/src/plugins/qnx/blackberryconfiguration.cpp @@ -31,6 +31,7 @@ #include "blackberryconfiguration.h" #include "blackberryqtversion.h" +#include "blackberrycertificate.h" #include "qnxutils.h" #include @@ -62,22 +63,29 @@ namespace Internal { namespace { const QLatin1String SettingsGroup("BlackBerryConfiguration"); const QLatin1String NDKLocationKey("NDKLocation"); +const QLatin1String CertificateGroup("Certificates"); } BlackBerryConfiguration::BlackBerryConfiguration(QObject *parent) :QObject(parent) { - loadSetting(); - connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSetting())); + loadSettings(); + connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings())); } -bool BlackBerryConfiguration::setConfig(const QString &ndkPath) +bool BlackBerryConfiguration::setNdkPath(const QString &ndkPath) { if (ndkPath.isEmpty()) return false; m_config.ndkPath = ndkPath; - m_config.qnxEnv = QnxUtils::parseEnvironmentFile(QnxUtils::envFilePath(ndkPath)); + + return refresh(); +} + +bool BlackBerryConfiguration::refresh() +{ + m_config.qnxEnv = QnxUtils::parseEnvironmentFile(QnxUtils::envFilePath(m_config.ndkPath)); QString ndkTarget = m_config.qnxEnv.value(QLatin1String("QNX_TARGET")); QString sep = QString::fromLatin1("%1qnx6").arg(QDir::separator()); @@ -120,12 +128,83 @@ bool BlackBerryConfiguration::setConfig(const QString &ndkPath) return true; } -void BlackBerryConfiguration::setupConfiguration(const QString &ndkPath) +void BlackBerryConfiguration::loadCertificates() +{ + QSettings *settings = Core::ICore::instance()->settings(); + + settings->beginGroup(SettingsGroup); + settings->beginGroup(CertificateGroup); + + foreach (QString certificateId, settings->childGroups()) { + settings->beginGroup(certificateId); + + BlackBerryCertificate *cert = + new BlackBerryCertificate(settings->value(QLatin1String(Qnx::Constants::QNX_KEY_PATH)).toString(), + settings->value(QLatin1String(Qnx::Constants::QNX_KEY_AUTHOR)).toString()); + cert->setParent(this); + + if (settings->value(QLatin1String(Qnx::Constants::QNX_KEY_ACTIVE)).toBool()) + m_config.activeCertificate = cert; + + m_config.certificates << cert; + + settings->endGroup(); + } + + settings->endGroup(); + settings->endGroup(); +} + +void BlackBerryConfiguration::loadNdkSettings() +{ + QSettings *settings = Core::ICore::instance()->settings(); + + settings->beginGroup(SettingsGroup); + setNdkPath(settings->value(NDKLocationKey).toString()); + settings->endGroup(); +} + +void BlackBerryConfiguration::saveCertificates() +{ + QSettings *settings = Core::ICore::instance()->settings(); + + settings->beginGroup(SettingsGroup); + settings->beginGroup(CertificateGroup); + + settings->remove(QString()); + + foreach (const BlackBerryCertificate *cert, m_config.certificates) { + settings->beginGroup(cert->id()); + settings->setValue(QLatin1String(Qnx::Constants::QNX_KEY_PATH), cert->fileName()); + settings->setValue(QLatin1String(Qnx::Constants::QNX_KEY_AUTHOR), cert->author()); + + if (cert == m_config.activeCertificate) + settings->setValue(QLatin1String(Qnx::Constants::QNX_KEY_ACTIVE), true); + + settings->endGroup(); + } + + settings->endGroup(); + settings->endGroup(); +} + +void BlackBerryConfiguration::saveNdkSettings() +{ + if (m_config.ndkPath.isEmpty()) + return; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(SettingsGroup); + settings->setValue(NDKLocationKey, m_config.ndkPath); + settings->endGroup(); +} + +void BlackBerryConfiguration::setupNdkConfiguration(const QString &ndkPath) { if (ndkPath.isEmpty()) return; - if (setConfig(ndkPath)) { + if (setNdkPath(ndkPath)) { QtSupport::BaseQtVersion *qtVersion = createQtVersion(); ProjectExplorer::GccToolChain *tc = createGccToolChain(); ProjectExplorer::Kit *deviceKit = createKit(ArmLeV7, qtVersion, tc); @@ -143,7 +222,7 @@ void BlackBerryConfiguration::setupConfiguration(const QString &ndkPath) } } -void BlackBerryConfiguration::cleanConfiguration() +void BlackBerryConfiguration::cleanNdkConfiguration() { QtSupport::BaseQtVersion *version = QtSupport::QtVersionManager::instance()->qtVersionForQMakeBinary(m_config.qmakeBinaryFile); if (version) { @@ -161,10 +240,42 @@ void BlackBerryConfiguration::cleanConfiguration() } BlackBerryConfig conf; + conf.activeCertificate = m_config.activeCertificate; + conf.certificates = m_config.certificates; m_config = conf; emit updated(); - clearSetting(); + clearNdkSettings(); +} + +void BlackBerryConfiguration::syncCertificates(QList certificates, + BlackBerryCertificate *activeCertificate) +{ + m_config.activeCertificate = activeCertificate; + + foreach (BlackBerryCertificate *cert, m_config.certificates) { + if (!certificates.contains(cert)) { + m_config.certificates.removeAll(cert); + delete cert; + } + } + + foreach (BlackBerryCertificate *cert, certificates) { + if (!m_config.certificates.contains(cert)) { + cert->setParent(this); + m_config.certificates << cert; + } + } +} + +QList BlackBerryConfiguration::certificates() const +{ + return m_config.certificates; +} + +BlackBerryCertificate * BlackBerryConfiguration::activeCertificate() +{ + return m_config.activeCertificate; } QtSupport::BaseQtVersion *BlackBerryConfiguration::createQtVersion() @@ -252,26 +363,19 @@ ProjectExplorer::Kit *BlackBerryConfiguration::createKit(QnxArchitecture arch, Q return kit; } -void BlackBerryConfiguration::loadSetting() +void BlackBerryConfiguration::loadSettings() { - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup(SettingsGroup); - setConfig(settings->value(NDKLocationKey).toString()); - settings->endGroup(); + loadNdkSettings(); + loadCertificates(); } -void BlackBerryConfiguration::saveSetting() +void BlackBerryConfiguration::saveSettings() { - if (m_config.ndkPath.isEmpty()) - return; - - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup(SettingsGroup); - settings->setValue(NDKLocationKey, m_config.ndkPath); - settings->endGroup(); + saveNdkSettings(); + saveCertificates(); } -void BlackBerryConfiguration::clearSetting() +void BlackBerryConfiguration::clearNdkSettings() { QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup(SettingsGroup); @@ -326,6 +430,45 @@ Utils::FileName BlackBerryConfiguration::sysRoot() const return m_config.sysRoot; } +QString BlackBerryConfiguration::dataDirPath() const +{ + const QString homeDir = QDir::homePath(); + + if (Utils::HostOsInfo::isMacHost()) + return homeDir + QLatin1String("/Library/Research in Motion"); + + if (Utils::HostOsInfo::isAnyUnixHost()) + return homeDir + QLatin1String("/.rim"); + +#if defined(Q_OS_WIN) + if (Utils::HostOsInfo::isWindowsHost()) { + // needed because QSysInfo::windowsVersion() is not available on other + // platforms. + if (QSysInfo::windowsVersion() == QSysInfo::WV_XP) + return homeDir + + QLatin1String("/Local Settings/Application Data/Research In Motion"); + return homeDir + QLatin1String("/AppData/Local/Research in Motion"); + } +#endif + + return QString(); +} + +QString BlackBerryConfiguration::barsignerCskPath() const +{ + return dataDirPath() + QLatin1String("/barsigner.csk"); +} + +QString BlackBerryConfiguration::barsignerDbPath() const +{ + return dataDirPath() + QLatin1String("/barsigner.db"); +} + +QString BlackBerryConfiguration::defaultKeystorePath() const +{ + return dataDirPath() + QLatin1String("/author.p12"); +} + // TODO: QnxUtils::parseEnvFile() and qnxEnv() to return Util::Enviroment instead(?) QMultiMap BlackBerryConfiguration::qnxEnv() const { diff --git a/src/plugins/qnx/blackberryconfiguration.h b/src/plugins/qnx/blackberryconfiguration.h index 426502aa603..7f6be58f66f 100644 --- a/src/plugins/qnx/blackberryconfiguration.h +++ b/src/plugins/qnx/blackberryconfiguration.h @@ -48,6 +48,8 @@ namespace Qnx { namespace Internal { +class BlackBerryCertificate; + class BlackBerryConfig { QString ndkPath; @@ -58,6 +60,8 @@ class BlackBerryConfig Utils::FileName simulatorDebuger; Utils::FileName sysRoot; QMultiMap qnxEnv; + QList certificates; + BlackBerryCertificate *activeCertificate; friend class BlackBerryConfiguration; }; @@ -74,22 +78,36 @@ public: Utils::FileName simulatorGdbPath() const; Utils::FileName sysRoot() const; QMultiMap qnxEnv() const; - void setupConfiguration(const QString &ndkPath); + void setupNdkConfiguration(const QString &ndkPath); QString ndkPath() const; QString targetName() const; - void loadSetting(); - void clearSetting(); - void cleanConfiguration(); + QString barsignerCskPath() const; + QString barsignerDbPath() const; + QString dataDirPath() const; + QString defaultKeystorePath() const; + void loadSettings(); + void clearNdkSettings(); + void cleanNdkConfiguration(); + void syncCertificates(QList certificates, + BlackBerryCertificate *activeCertificate); + + QList certificates() const; + BlackBerryCertificate *activeCertificate(); public slots: - void saveSetting(); + void saveSettings(); private: BlackBerryConfiguration(QObject *parent = 0); static BlackBerryConfiguration *m_instance; BlackBerryConfig m_config; - bool setConfig(const QString &ndkPath); + void loadCertificates(); + void loadNdkSettings(); + void saveCertificates(); + void saveNdkSettings(); + bool refresh(); + bool setNdkPath(const QString &ndkPath); QtSupport::BaseQtVersion* createQtVersion(); ProjectExplorer::GccToolChain* createGccToolChain(); ProjectExplorer::Kit* createKit(QnxArchitecture arch, QtSupport::BaseQtVersion* qtVersion, ProjectExplorer::GccToolChain* tc); diff --git a/src/plugins/qnx/blackberrycreatecertificatedialog.cpp b/src/plugins/qnx/blackberrycreatecertificatedialog.cpp new file mode 100644 index 00000000000..883ef267a72 --- /dev/null +++ b/src/plugins/qnx/blackberrycreatecertificatedialog.cpp @@ -0,0 +1,208 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrycreatecertificatedialog.h" +#include "blackberrycertificate.h" +#include "ui_blackberrycreatecertificatedialog.h" + +#include +#include +#include +#include + +namespace Qnx { +namespace Internal { + +BlackBerryCreateCertificateDialog::BlackBerryCreateCertificateDialog( + QWidget *parent, Qt::WindowFlags f) : + QDialog(parent, f), + m_ui(new Ui_BlackBerryCreateCertificateDialog), + m_certificate(0) +{ + m_ui->setupUi(this); + m_ui->progressBar->hide(); + m_ui->certPath->setExpectedKind(Utils::PathChooser::Any); + m_ui->certPath->setPromptDialogTitle(tr("Create certificate")); + m_ui->certPath->setPromptDialogFilter(tr("PKCS 12 archives (*.p12)")); + m_ui->status->clear(); + + m_cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel); + Q_ASSERT(m_cancelButton); + + m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); + m_okButton->setEnabled(false); + + connect(m_cancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + connect(m_okButton, SIGNAL(clicked()), + this, SLOT(createCertificate())); + connect(m_ui->certPath, SIGNAL(changed(QString)), + this, SLOT(validate())); + connect(m_ui->certPath, SIGNAL(editingFinished()), + this, SLOT(appendExtension())); + connect(m_ui->author, SIGNAL(textChanged(QString)), + this, SLOT(validate())); + connect(m_ui->password, SIGNAL(textChanged(QString)), + this, SLOT(validate())); + connect(m_ui->password2, SIGNAL(textChanged(QString)), + this, SLOT(validate())); + connect(m_ui->showPassword, SIGNAL(stateChanged(int)), + this, SLOT(checkBoxChanged(int))); +} + +QString BlackBerryCreateCertificateDialog::author() const +{ + return m_ui->author->text(); +} + +QString BlackBerryCreateCertificateDialog::certPath() const +{ + return m_ui->certPath->path(); +} + +QString BlackBerryCreateCertificateDialog::keystorePassword() const +{ + return m_ui->password->text(); +} + +BlackBerryCertificate * BlackBerryCreateCertificateDialog::certificate() const +{ + return m_certificate; +} + +void BlackBerryCreateCertificateDialog::validate() +{ + if (!m_ui->certPath->isValid() + || m_ui->author->text().isEmpty() + || m_ui->password->text().isEmpty() + || m_ui->password2->text().isEmpty()) { + m_ui->status->clear(); + m_okButton->setEnabled(false); + return; + } + + QFileInfo fileInfo(m_ui->certPath->path()); + + if (!fileInfo.dir().exists()) { + m_ui->status->setText(tr("Base directory does not exist")); + m_okButton->setEnabled(false); + return; + } + + if (m_ui->password->text() != m_ui->password2->text()) { + m_ui->status->setText(tr("The entered passwords do not match")); + m_okButton->setEnabled(false); + return; + } + + m_ui->status->clear(); + m_okButton->setEnabled(true); +} + +void BlackBerryCreateCertificateDialog::createCertificate() +{ + setBusy(true); + + QFile file(m_ui->certPath->path()); + + if (file.exists()) { + const int result = QMessageBox::question(this, tr("Are you sure?"), + tr("The file '%1' will be overwritten. Do you want to proceed?") + .arg(file.fileName()), QMessageBox::Yes | QMessageBox::No); + + if (result & QMessageBox::Yes) { + file.remove(); + } else { + setBusy(false); + return; + } + } + + m_certificate = new BlackBerryCertificate(certPath(), + author(), keystorePassword()); + + connect(m_certificate, SIGNAL(finished(int)), this, SLOT(certificateCreated(int))); + m_certificate->store(); +} + +void BlackBerryCreateCertificateDialog::appendExtension() +{ + QString path = m_ui->certPath->path(); + + if (!path.endsWith(QLatin1String(".p12"))) { + path += QLatin1String(".p12"); + m_ui->certPath->setPath(path); + } +} + +void BlackBerryCreateCertificateDialog::checkBoxChanged(int state) +{ + if (state == Qt::Checked) { + m_ui->password->setEchoMode(QLineEdit::Normal); + m_ui->password2->setEchoMode(QLineEdit::Normal); + } else { + m_ui->password->setEchoMode(QLineEdit::Password); + m_ui->password2->setEchoMode(QLineEdit::Password); + } +} + +void BlackBerryCreateCertificateDialog::certificateCreated(int status) +{ + if (status == BlackBerryCertificate::Success) { + accept(); + } else { + m_certificate->deleteLater(); + m_certificate = 0; + QMessageBox::critical(this, tr("Error"), + tr("An unknown error happened while creating the certificate")); + reject(); + } +} + +void BlackBerryCreateCertificateDialog::setBusy(bool busy) +{ + m_okButton->setEnabled(!busy); + m_cancelButton->setEnabled(!busy); + m_ui->certPath->setEnabled(!busy); + m_ui->author->setEnabled(!busy); + m_ui->password->setEnabled(!busy); + m_ui->password2->setEnabled(!busy); + m_ui->showPassword->setEnabled(!busy); + m_ui->progressBar->setVisible(busy); + + if (busy) + m_ui->status->setText(tr("Please be patient...")); + else + m_ui->status->clear(); +} + +} +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrycreatecertificatedialog.h b/src/plugins/qnx/blackberrycreatecertificatedialog.h new file mode 100644 index 00000000000..19a7734e640 --- /dev/null +++ b/src/plugins/qnx/blackberrycreatecertificatedialog.h @@ -0,0 +1,82 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYCREATECERTIFICATEDIALOG_H +#define QNX_INTERNAL_BLACKBERRYCREATECERTIFICATEDIALOG_H + +#include + +QT_BEGIN_NAMESPACE +class QPushButton; +QT_END_NAMESPACE + +namespace Qnx { +namespace Internal { + +class Ui_BlackBerryCreateCertificateDialog; +class BlackBerryCertificate; + +class BlackBerryCreateCertificateDialog : public QDialog +{ +Q_OBJECT + +public: + explicit BlackBerryCreateCertificateDialog(QWidget *parent = 0, + Qt::WindowFlags f = 0); + + QString author() const; + QString certPath() const; + QString keystorePassword() const; + + BlackBerryCertificate *certificate() const; + +private slots: + void validate(); + void createCertificate(); + void appendExtension(); + void checkBoxChanged(int state); + void certificateCreated(int status); + +private: + void setBusy(bool busy); + + Ui_BlackBerryCreateCertificateDialog *m_ui; + + BlackBerryCertificate *m_certificate; + + QPushButton *m_cancelButton; + QPushButton *m_okButton; +}; + +} +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYCREATECERTIFICATEDIALOG_H diff --git a/src/plugins/qnx/blackberrycreatecertificatedialog.ui b/src/plugins/qnx/blackberrycreatecertificatedialog.ui new file mode 100644 index 00000000000..1948d2d058e --- /dev/null +++ b/src/plugins/qnx/blackberrycreatecertificatedialog.ui @@ -0,0 +1,133 @@ + + + Qnx::Internal::BlackBerryCreateCertificateDialog + + + + 0 + 0 + 495 + 191 + + + + Create certificate + + + + + + + + Path: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Author: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Password: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QLineEdit::Password + + + + + + + Confirm password: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QLineEdit::Password + + + + + + + Show password + + + + + + + + 75 + true + + + + Status + + + Qt::AlignCenter + + + + + + + + + 0 + + + -1 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
+ + +
diff --git a/src/plugins/qnx/blackberrycsjregistrar.cpp b/src/plugins/qnx/blackberrycsjregistrar.cpp new file mode 100644 index 00000000000..7643b145e9b --- /dev/null +++ b/src/plugins/qnx/blackberrycsjregistrar.cpp @@ -0,0 +1,115 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrycsjregistrar.h" +#include "blackberryconfiguration.h" + +#include + +#include +#include +#include + +namespace Qnx { +namespace Internal { + +BlackBerryCsjRegistrar::BlackBerryCsjRegistrar(QObject *parent) : + QObject(parent), + m_process(new QProcess(this)) +{ + connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), + this, SLOT(processFinished())); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(processError(QProcess::ProcessError))); +} + +void BlackBerryCsjRegistrar::tryRegister(const QStringList &csjFiles, + const QString &csjPin, const QString &cskPassword) +{ + if (m_process->state() != QProcess::NotRunning) + return; + + QString command = BlackBerryConfiguration::instance() + .qnxEnv().value(QLatin1String("QNX_HOST")) + + (QLatin1String("/usr/bin/blackberry-signer")); + + if (Utils::HostOsInfo::isWindowsHost()) + command += QLatin1String(".bat"); + + QStringList arguments; + + arguments << QLatin1String("-register") + << QLatin1String("-cskpass") + << cskPassword + << QLatin1String("-csjpin") + << csjPin + << csjFiles; + + m_process->start(command, arguments); +} + +void BlackBerryCsjRegistrar::processFinished() +{ + QByteArray result = m_process->readAllStandardOutput(); + + if (result.contains("Successfully registered with server.")) + emit finished(RegisterSuccess, QString()); + else + emit finished(Error, QLatin1String(result)); +} + +void BlackBerryCsjRegistrar::processError(QProcess::ProcessError error) +{ + QString errorMessage; + + switch (error) { + case QProcess::FailedToStart: + errorMessage = tr("Failed to start blackberry-signer process"); + break; + case QProcess::Timedout: + errorMessage = tr("Process timed out"); + case QProcess::Crashed: + errorMessage = tr("Child process has crashed"); + break; + case QProcess::WriteError: + case QProcess::ReadError: + errorMessage = tr("Process I/O error"); + break; + case QProcess::UnknownError: + errorMessage = tr("Unknown process error"); + break; + } + + emit finished(Error, errorMessage); +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrycsjregistrar.h b/src/plugins/qnx/blackberrycsjregistrar.h new file mode 100644 index 00000000000..28bba48d4a7 --- /dev/null +++ b/src/plugins/qnx/blackberrycsjregistrar.h @@ -0,0 +1,71 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYCSJREGISTRAR_H +#define QNX_INTERNAL_BLACKBERRYCSJREGISTRAR_H + +#include +#include +#include + +namespace Qnx { +namespace Internal { + +class BlackBerryCsjRegistrar : public QObject +{ +Q_OBJECT + +public: + enum RegisterStatus + { + RegisterSuccess, + Error + }; + + BlackBerryCsjRegistrar(QObject *parent = 0); + + void tryRegister(const QStringList &csjFiles, const QString &csjPin, const QString &cskPassword); + +signals: + void finished(int status, const QString &errorString); + +private slots: + void processFinished(); + void processError(QProcess::ProcessError error); + +private: + QProcess *m_process; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYCSJREGISTRAR_H diff --git a/src/plugins/qnx/blackberryimportcertificatedialog.cpp b/src/plugins/qnx/blackberryimportcertificatedialog.cpp new file mode 100644 index 00000000000..f362475ca62 --- /dev/null +++ b/src/plugins/qnx/blackberryimportcertificatedialog.cpp @@ -0,0 +1,142 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberryimportcertificatedialog.h" +#include "blackberrycertificate.h" +#include "ui_blackberryimportcertificatedialog.h" + +#include +#include + +#include + +namespace Qnx { +namespace Internal { + +BlackBerryImportCertificateDialog::BlackBerryImportCertificateDialog( + QWidget *parent, Qt::WindowFlags f) : + QDialog(parent, f), + m_ui(new Ui_BlackBerryImportCertificateDialog), + m_certificate(0) +{ + m_ui->setupUi(this); + m_ui->certPath->setExpectedKind(Utils::PathChooser::File); + m_ui->certPath->setPromptDialogTitle(tr("Import Certificate")); + m_ui->certPath->setPromptDialogFilter(tr("PKCS 12 Archives (*.p12)")); + + m_cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel); + + m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); + m_okButton->setEnabled(false); + + connect(m_cancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + connect(m_okButton, SIGNAL(clicked()), + this, SLOT(importCertificate())); + connect(m_ui->certPath, SIGNAL(changed(QString)), + this, SLOT(validate())); + connect(m_ui->certPass, SIGNAL(textChanged(QString)), + this, SLOT(validate())); +} + +QString BlackBerryImportCertificateDialog::author() const +{ + return m_author; +} + +QString BlackBerryImportCertificateDialog::certPath() const +{ + return m_ui->certPath->path(); +} + +QString BlackBerryImportCertificateDialog::keystorePassword() const +{ + return m_ui->certPass->text(); +} + +BlackBerryCertificate * BlackBerryImportCertificateDialog::certificate() const +{ + return m_certificate; +} + +void BlackBerryImportCertificateDialog::importCertificate() +{ + setBusy(true); + + m_certificate = new BlackBerryCertificate(certPath(), + QString(), keystorePassword()); + + connect(m_certificate, SIGNAL(finished(int)), this, SLOT(certificateLoaded(int))); + + m_certificate->load(); +} + +void BlackBerryImportCertificateDialog::validate() +{ + if (!m_ui->certPath->isValid() || m_ui->certPass->text().isEmpty()) { + m_okButton->setEnabled(false); + return; + } + + m_okButton->setEnabled(true); +} + +void BlackBerryImportCertificateDialog::certificateLoaded(int status) +{ + if (status != BlackBerryCertificate::Success) { + setBusy(false); + + m_certificate->deleteLater(); + m_certificate = 0; + + if (status == BlackBerryCertificate::WrongPassword) { + QMessageBox::information(this, tr("Error"), + tr("Invalid keystore password")); + } else { + QMessageBox::information(this, tr("Error"), + tr("An unknown error has happened")); + } + } else { + m_author = m_certificate->author(); + accept(); + } +} + +void BlackBerryImportCertificateDialog::setBusy(bool busy) +{ + m_ui->certPath->setEnabled(!busy); + m_ui->certPass->setEnabled(!busy); + m_okButton->setEnabled(!busy); + m_cancelButton->setEnabled(!busy); +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberryimportcertificatedialog.h b/src/plugins/qnx/blackberryimportcertificatedialog.h new file mode 100644 index 00000000000..438801e11dc --- /dev/null +++ b/src/plugins/qnx/blackberryimportcertificatedialog.h @@ -0,0 +1,82 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYIMPORTCERTIFICATEDIALOG_H +#define QNX_INTERNAL_BLACKBERRYIMPORTCERTIFICATEDIALOG_H + +#include + +QT_BEGIN_NAMESPACE +class QPushButton; +QT_END_NAMESPACE + +namespace Qnx { +namespace Internal { + +class Ui_BlackBerryImportCertificateDialog; +class BlackBerryCertificate; + +class BlackBerryImportCertificateDialog : public QDialog +{ +Q_OBJECT + +public: + explicit BlackBerryImportCertificateDialog(QWidget *parent = 0, + Qt::WindowFlags f = 0); + + QString author() const; + QString certPath() const; + QString keystorePassword() const; + + BlackBerryCertificate *certificate() const; + +private slots: + void importCertificate(); + void validate(); + void certificateLoaded(int); + +private: + void setBusy(bool busy); + + Ui_BlackBerryImportCertificateDialog *m_ui; + + BlackBerryCertificate *m_certificate; + + QString m_author; + + QPushButton *m_cancelButton; + QPushButton *m_okButton; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYIMPORTCERTIFICATEDIALOG_H diff --git a/src/plugins/qnx/blackberryimportcertificatedialog.ui b/src/plugins/qnx/blackberryimportcertificatedialog.ui new file mode 100644 index 00000000000..fd486bf4d11 --- /dev/null +++ b/src/plugins/qnx/blackberryimportcertificatedialog.ui @@ -0,0 +1,70 @@ + + + Qnx::Internal::BlackBerryImportCertificateDialog + + + + 0 + 0 + 412 + 88 + + + + Import certificate + + + + + + + + Path: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Password: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QLineEdit::Password + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
+ + +
diff --git a/src/plugins/qnx/blackberrykeyspage.cpp b/src/plugins/qnx/blackberrykeyspage.cpp new file mode 100644 index 00000000000..2a1140dff0c --- /dev/null +++ b/src/plugins/qnx/blackberrykeyspage.cpp @@ -0,0 +1,70 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrykeyspage.h" +#include "blackberrykeyswidget.h" +#include "qnxconstants.h" + +#include + +#include + +namespace Qnx { +namespace Internal { + +BlackBerryKeysPage::BlackBerryKeysPage(QObject *parent) : + Core::IOptionsPage(parent), + m_widget(0) +{ + setId(Core::Id(Constants::QNX_BB_SIGNING_ID)); + setDisplayName(tr("Keys")); + setCategory(Constants::QNX_BB_CATEGORY); + setDisplayCategory(QCoreApplication::translate("BlackBerry", + Constants::QNX_BB_CATEGORY_TR)); +} + +QWidget *BlackBerryKeysPage::createPage(QWidget *parent) +{ + m_widget = new BlackBerryKeysWidget(parent); + return m_widget; +} + +void BlackBerryKeysPage::apply() +{ + m_widget->apply(); +} + +void BlackBerryKeysPage::finish() +{ +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberrykeyspage.h b/src/plugins/qnx/blackberrykeyspage.h new file mode 100644 index 00000000000..04027ee8cf3 --- /dev/null +++ b/src/plugins/qnx/blackberrykeyspage.h @@ -0,0 +1,58 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef BLACKBERRYSIGNINGPAGE_H +#define BLACKBERRYSIGNINGPAGE_H + +#include + +namespace Qnx { +namespace Internal { + +class BlackBerryKeysWidget; + +class BlackBerryKeysPage : public Core::IOptionsPage +{ + Q_OBJECT +public: + explicit BlackBerryKeysPage(QObject *parent = 0); + QWidget *createPage(QWidget *parent); + void apply(); + void finish(); + +private: + BlackBerryKeysWidget *m_widget; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // BLACKBERRYSIGNINGPAGE_H diff --git a/src/plugins/qnx/blackberrykeyswidget.cpp b/src/plugins/qnx/blackberrykeyswidget.cpp new file mode 100644 index 00000000000..1d7c4684433 --- /dev/null +++ b/src/plugins/qnx/blackberrykeyswidget.cpp @@ -0,0 +1,209 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberrykeyswidget.h" +#include "blackberryregisterkeydialog.h" +#include "blackberryconfiguration.h" +#include "blackberrycertificatemodel.h" +#include "blackberryimportcertificatedialog.h" +#include "blackberrycreatecertificatedialog.h" +#include "blackberrycertificate.h" +#include "ui_blackberrykeyswidget.h" + +#include +#include +#include +#include + +namespace Qnx { +namespace Internal { + +BlackBerryKeysWidget::BlackBerryKeysWidget(QWidget *parent) : + QWidget(parent), + m_ui(new Ui_BlackBerryKeysWidget), + m_model(new BlackBerryCertificateModel(this)) +{ + m_ui->setupUi(this); + m_ui->certificatesView->setModel(m_model); + m_ui->certificatesView->resizeColumnsToContents(); + + QHeaderView *headerView = m_ui->certificatesView->horizontalHeader(); + headerView->setResizeMode(QHeaderView::Stretch); + headerView->setResizeMode(2, QHeaderView::Fixed); + + QItemSelectionModel *selectionModel = m_ui->certificatesView->selectionModel(); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(handleSelectionChanged(QItemSelection,QItemSelection))); + + updateRegisterSection(); + + connect(m_ui->registerButton, SIGNAL(clicked()), this, SLOT(registerKey())); + connect(m_ui->unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterKey())); + connect(m_ui->createCertificate, SIGNAL(clicked()), this, SLOT(createCertificate())); + connect(m_ui->importCertificate, SIGNAL(clicked()), this, SLOT(importCertificate())); + connect(m_ui->deleteCertificate, SIGNAL(clicked()), this, SLOT(deleteCertificate())); +} + +void BlackBerryKeysWidget::apply() +{ + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + + configuration.syncCertificates(m_model->certificates(), m_model->activeCertificate()); +} + +void BlackBerryKeysWidget::registerKey() +{ + BlackBerryRegisterKeyDialog dialog; + + const int result = dialog.exec(); + + if (result != QDialog::Accepted) + return; + + BlackBerryCertificate *cert = dialog.certificate(); + + if (cert) { + if (!m_model->insertCertificate(cert)) + QMessageBox::information(this, tr("Error"), tr("Could not insert default certificate")); + } + + updateRegisterSection(); +} + +void BlackBerryKeysWidget::unregisterKey() +{ + const QMessageBox::StandardButton answer = + QMessageBox::question(this, tr("Unregister Key"), + tr("Do you really want to unregister your key? This action cannot be undone!"), + QMessageBox::Yes | QMessageBox::No); + + if (answer & QMessageBox::No) + return; + + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + + QFile f(configuration.barsignerCskPath()); + f.remove(); + + f.setFileName(configuration.barsignerDbPath()); + f.remove(); + + updateRegisterSection(); +} + +void BlackBerryKeysWidget::createCertificate() +{ + BlackBerryCreateCertificateDialog dialog; + + const int result = dialog.exec(); + + if (result == QDialog::Rejected) + return; + + BlackBerryCertificate *cert = dialog.certificate(); + + if (cert) { + if (!m_model->insertCertificate(cert)) + QMessageBox::information(this, tr("Error"), tr("Error storing certificate")); + } +} + +void BlackBerryKeysWidget::importCertificate() +{ + BlackBerryImportCertificateDialog dialog; + + const int result = dialog.exec(); + + if (result == QDialog::Rejected) + return; + + BlackBerryCertificate *cert = dialog.certificate(); + + if (cert) { + if (!m_model->insertCertificate(cert)) + QMessageBox::information(this, tr("Error"), tr("This certificate already exists")); + } +} + +void BlackBerryKeysWidget::deleteCertificate() +{ + const int result = QMessageBox::question(this, tr("Delete certificate"), + tr("Are you sure you want to delete this certificate?"), + QMessageBox::Yes | QMessageBox::No); + + if (result & QMessageBox::No) + return; + + m_model->removeRow(m_ui->certificatesView->selectionModel()->currentIndex().row()); +} + +void BlackBerryKeysWidget::handleSelectionChanged(const QItemSelection &selected, + const QItemSelection &deselected) +{ + Q_UNUSED(deselected); + + m_ui->deleteCertificate->setEnabled(!selected.indexes().isEmpty()); +} + +void BlackBerryKeysWidget::updateRegisterSection() +{ + if (hasRegisteredKey()) { + m_ui->registerButton->hide(); + m_ui->unregisterButton->show(); + m_ui->registeredLabel->setText(tr("Registered: Yes")); + } else { + m_ui->registerButton->show(); + m_ui->unregisterButton->hide(); + m_ui->registeredLabel->setText(tr("Registered: No")); + } +} + +bool BlackBerryKeysWidget::hasRegisteredKey() const +{ + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + + QFileInfo cskFile(configuration.barsignerCskPath()); + + if (!cskFile.exists()) + return false; + + QFileInfo dbFile(configuration.barsignerDbPath()); + + if (!dbFile.exists()) + return false; + + return true; +} + + +} // namespace Internal +} // namespace Qnx + diff --git a/src/plugins/qnx/blackberrykeyswidget.h b/src/plugins/qnx/blackberrykeyswidget.h new file mode 100644 index 00000000000..a6bc7f5ba70 --- /dev/null +++ b/src/plugins/qnx/blackberrykeyswidget.h @@ -0,0 +1,84 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef BLACKBERRYKEYSWIDGET_H_H +#define BLACKBERRYKEYSWIDGET_H_H + +#include "blackberryconfiguration.h" + +#include +#include + +QT_BEGIN_NAMESPACE +class QItemSelection; +QT_END_NAMESPACE + +namespace Qnx { +namespace Internal { + +class BlackBerryCertificateModel; +class Ui_BlackBerryKeysWidget; + +class BlackBerryKeysWidget : public QWidget +{ + Q_OBJECT +public: + explicit BlackBerryKeysWidget(QWidget *parent = 0); + + void apply(); + +private slots: + void registerKey(); + void unregisterKey(); + void createCertificate(); + void importCertificate(); + void deleteCertificate(); + void handleSelectionChanged( + const QItemSelection &selected, + const QItemSelection &deselected); + +private: + void updateRegisterSection(); + + bool hasRegisteredKey() const; + + QString dataDir() const; + QString cskFilePath() const; + QString dbFilePath() const; + + Ui_BlackBerryKeysWidget *m_ui; + BlackBerryCertificateModel *m_model; +}; + +} // namespace Internal +} // namespeace Qnx + +#endif // BLACKBERRYKEYSWIDGET_H_H diff --git a/src/plugins/qnx/blackberrykeyswidget.ui b/src/plugins/qnx/blackberrykeyswidget.ui new file mode 100644 index 00000000000..f0acadbdd13 --- /dev/null +++ b/src/plugins/qnx/blackberrykeyswidget.ui @@ -0,0 +1,120 @@ + + + Qnx::Internal::BlackBerryKeysWidget + + + + 0 + 0 + 959 + 390 + + + + Form + + + + + + RIM Signing Authority + + + + + + Qt::Horizontal + + + + 658 + 20 + + + + + + + + Registered: Yes + + + + + + + Register + + + + + + + Unregister + + + + + + + + + + Developer Certificate + + + + + + Qt::Vertical + + + + 20 + 189 + + + + + + + + QAbstractItemView::SelectRows + + + false + + + + + + + Create + + + + + + + Import + + + + + + + false + + + Delete + + + + + + + + + + + diff --git a/src/plugins/qnx/blackberryndksettingswidget.cpp b/src/plugins/qnx/blackberryndksettingswidget.cpp index 4d716f08880..9ed7df20c64 100644 --- a/src/plugins/qnx/blackberryndksettingswidget.cpp +++ b/src/plugins/qnx/blackberryndksettingswidget.cpp @@ -62,7 +62,7 @@ void BlackBerryNDKSettingsWidget::checkSdkPath() { if (!m_ui->sdkPath->path().isEmpty() && QnxUtils::isValidNdkPath(m_ui->sdkPath->path())) - m_bbConfig->setupConfiguration(m_ui->sdkPath->path()); + m_bbConfig->setupNdkConfiguration(m_ui->sdkPath->path()); } void BlackBerryNDKSettingsWidget::updateInfoTable() @@ -114,7 +114,7 @@ void BlackBerryNDKSettingsWidget::cleanConfiguration() QMessageBox::Yes | QMessageBox::No); if (button == QMessageBox::Yes) - m_bbConfig->cleanConfiguration(); + m_bbConfig->cleanNdkConfiguration(); } void BlackBerryNDKSettingsWidget::initInfoTable() diff --git a/src/plugins/qnx/blackberryregisterkeydialog.cpp b/src/plugins/qnx/blackberryregisterkeydialog.cpp new file mode 100644 index 00000000000..18379bf5a19 --- /dev/null +++ b/src/plugins/qnx/blackberryregisterkeydialog.cpp @@ -0,0 +1,352 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "blackberryregisterkeydialog.h" +#include "blackberrycsjregistrar.h" +#include "blackberryconfiguration.h" +#include "blackberrycertificate.h" +#include "ui_blackberryregisterkeydialog.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#if defined(Q_OS_WIN) +#include +#endif + +namespace Qnx { +namespace Internal { + +BlackBerryRegisterKeyDialog::BlackBerryRegisterKeyDialog(QWidget *parent, + Qt::WindowFlags f) : + QDialog(parent, f), + m_ui(new Ui_BlackBerryRegisterKeyDialog), + m_registrar(new BlackBerryCsjRegistrar(this)), + m_certificate(0) +{ + m_ui->setupUi(this); + m_ui->statusLabel->clear(); + + setupCsjPathChooser(m_ui->pbdtPath); + setupCsjPathChooser(m_ui->rdkPath); + + m_cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel); + + m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); + + setBusy(false); + + m_okButton->setEnabled(false); + + QFileInfo authorP12(BlackBerryConfiguration::instance().defaultKeystorePath()); + + if (authorP12.exists()) { + m_ui->genCert->setEnabled(false); + m_ui->genCert->setChecked(false); + m_ui->keystorePassword->setEnabled(false); + m_ui->keystorePassword2->setEnabled(false); + } else { + m_ui->genCert->setEnabled(true); + m_ui->genCert->setChecked(true); + m_ui->keystorePassword->setEnabled(true); + m_ui->keystorePassword2->setEnabled(true); + } + + + connect(m_cancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + connect(m_okButton, SIGNAL(clicked()), + this, SLOT(createKey())); + connect(m_ui->pbdtPath, SIGNAL(changed(QString)), + this, SLOT(csjAutoComplete(QString))); + connect(m_ui->rdkPath, SIGNAL(changed(QString)), + this, SLOT(csjAutoComplete(QString))); + connect(m_ui->showPins, SIGNAL(stateChanged(int)), + this, SLOT(pinCheckBoxChanged(int))); + connect(m_registrar, SIGNAL(finished(int,QString)), + this, SLOT(registrarFinished(int,QString))); + connect(m_ui->genCert, SIGNAL(stateChanged(int)), + this, SLOT(certCheckBoxChanged(int))); + connect(m_ui->pbdtPath, SIGNAL(changed(QString)), this, SLOT(validate())); + connect(m_ui->rdkPath, SIGNAL(changed(QString)), this, SLOT(validate())); + connect(m_ui->csjPin, SIGNAL(textChanged(QString)), this, SLOT(validate())); + connect(m_ui->cskPin, SIGNAL(textChanged(QString)), this, SLOT(validate())); + connect(m_ui->cskPin2, SIGNAL(textChanged(QString)), this, SLOT(validate())); + connect(m_ui->keystorePassword, SIGNAL(textChanged(QString)), this, SLOT(validate())); + connect(m_ui->keystorePassword2, SIGNAL(textChanged(QString)), this, SLOT(validate())); +} + +void BlackBerryRegisterKeyDialog::csjAutoComplete(const QString &path) +{ + Utils::PathChooser *chooser = 0; + QString file = path; + + if (file.contains(QLatin1String("PBDT"))) { + file.replace(QLatin1String("PBDT"), QLatin1String("RDK")); + chooser = m_ui->rdkPath; + } else if (file.contains(QLatin1String("RDK"))) { + file.replace(QLatin1String("RDK"), QLatin1String("PBDT")); + chooser = m_ui->pbdtPath; + } + + if (!chooser) + return; + + QFileInfo fileInfo(file); + + if (fileInfo.exists()) + chooser->setPath(file); +} + +void BlackBerryRegisterKeyDialog::validate() +{ + if (!m_ui->pbdtPath->isValid() + || !m_ui->rdkPath->isValid() + || m_ui->csjPin->text().isEmpty() + || m_ui->cskPin->text().isEmpty() + || m_ui->cskPin2->text().isEmpty()) { + m_okButton->setEnabled(false); + m_ui->statusLabel->clear(); + return; + } + + if (m_ui->cskPin->text() != m_ui->cskPin2->text()) { + m_okButton->setEnabled(false); + m_ui->statusLabel->setText(tr("CSK PINs do not match")); + return; + } + + if (m_ui->genCert->isChecked()) { + if (m_ui->keystorePassword->text().isEmpty() + || m_ui->keystorePassword2->text().isEmpty()) { + m_okButton->setEnabled(false); + m_ui->statusLabel->clear(); + return; + } + + if (m_ui->keystorePassword->text() + != m_ui->keystorePassword2->text()) { + m_ui->statusLabel->setText(tr("Keystore password does not match")); + m_okButton->setEnabled(false); + return; + } + } + + m_ui->statusLabel->clear(); + m_okButton->setEnabled(true); +} + +void BlackBerryRegisterKeyDialog::pinCheckBoxChanged(int state) +{ + if (state == Qt::Checked) { + m_ui->csjPin->setEchoMode(QLineEdit::Normal); + m_ui->cskPin->setEchoMode(QLineEdit::Normal); + m_ui->cskPin2->setEchoMode(QLineEdit::Normal); + m_ui->keystorePassword->setEchoMode(QLineEdit::Normal); + m_ui->keystorePassword2->setEchoMode(QLineEdit::Normal); + } else { + m_ui->csjPin->setEchoMode(QLineEdit::Password); + m_ui->cskPin->setEchoMode(QLineEdit::Password); + m_ui->cskPin2->setEchoMode(QLineEdit::Password); + m_ui->keystorePassword->setEchoMode(QLineEdit::Password); + m_ui->keystorePassword2->setEchoMode(QLineEdit::Password); + } +} + +void BlackBerryRegisterKeyDialog::certCheckBoxChanged(int state) +{ + m_ui->keystorePassword->setEnabled(state == Qt::Checked); + m_ui->keystorePassword2->setEnabled(state == Qt::Checked); + + validate(); +} + +void BlackBerryRegisterKeyDialog::createKey() +{ + setBusy(true); + + QStringList csjFiles; + csjFiles << rdkPath() << pbdtPath(); + + m_registrar->tryRegister(csjFiles, csjPin(), cskPin()); +} + +void BlackBerryRegisterKeyDialog::registrarFinished(int status, + const QString &errorString) +{ + if (status == BlackBerryCsjRegistrar::Error) { + QMessageBox::critical(this, tr("Error"), errorString); + cleanup(); + setBusy(false); + return; + } + + if (m_ui->genCert->isChecked()) + generateDeveloperCertificate(); + else + accept(); +} + +void BlackBerryRegisterKeyDialog::certificateCreated(int status) +{ + if (status == BlackBerryCertificate::Error) { + QMessageBox::critical(this, tr("Error"), tr("Error creating developer certificate")); + cleanup(); + m_certificate->deleteLater(); + m_certificate = 0; + setBusy(false); + } else { + accept(); + } +} + +QString BlackBerryRegisterKeyDialog::pbdtPath() const +{ + return m_ui->pbdtPath->path(); +} + +QString BlackBerryRegisterKeyDialog::rdkPath() const +{ + return m_ui->rdkPath->path(); +} + +QString BlackBerryRegisterKeyDialog::csjPin() const +{ + return m_ui->csjPin->text(); +} + +QString BlackBerryRegisterKeyDialog::cskPin() const +{ + return m_ui->cskPin->text(); +} + +QString BlackBerryRegisterKeyDialog::keystorePassword() const +{ + return m_ui->keystorePassword->text(); +} + +QString BlackBerryRegisterKeyDialog::keystorePath() const +{ + if (m_ui->genCert->isChecked()) { + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + return configuration.defaultKeystorePath(); + } + + return QString(); +} + +BlackBerryCertificate * BlackBerryRegisterKeyDialog::certificate() const +{ + return m_certificate; +} + +void BlackBerryRegisterKeyDialog::generateDeveloperCertificate() +{ + m_certificate = new BlackBerryCertificate(keystorePath(), + getCsjAuthor(rdkPath()), keystorePassword()); + + connect(m_certificate, SIGNAL(finished(int)), this, SLOT(certificateCreated(int))); + + m_certificate->store(); +} + +void BlackBerryRegisterKeyDialog::cleanup() const +{ + BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance(); + + QFile f(configuration.barsignerCskPath()); + f.remove(); + + f.setFileName(configuration.barsignerDbPath()); + f.remove(); + + if (m_ui->genCert->isChecked()) { + f.setFileName(configuration.defaultKeystorePath()); + f.remove(); + } +} + +void BlackBerryRegisterKeyDialog::setBusy(bool busy) +{ + m_ui->progressBar->setVisible(busy); + m_okButton->setEnabled(!busy); + m_cancelButton->setEnabled(!busy); + m_ui->rdkPath->setEnabled(!busy); + m_ui->pbdtPath->setEnabled(!busy); + m_ui->csjPin->setEnabled(!busy); + m_ui->cskPin->setEnabled(!busy); + m_ui->cskPin2->setEnabled(!busy); + m_ui->keystorePassword->setEnabled(!busy); + m_ui->keystorePassword2->setEnabled(!busy); + m_ui->showPins->setEnabled(!busy); + +} + +QString BlackBerryRegisterKeyDialog::getCsjAuthor(const QString &fileName) const +{ + QFile file(fileName); + + QString author = QLatin1String("Unknown Author"); + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return author; + + QTextStream stream(&file); + + while (!stream.atEnd()) { + QString line = stream.readLine(); + + if (line.startsWith(QLatin1String("Company="))) { + author = line.remove(QLatin1String("Company=")).trimmed(); + break; + } + } + + file.close(); + + return author; +} +void BlackBerryRegisterKeyDialog::setupCsjPathChooser(Utils::PathChooser *chooser) +{ + chooser->setExpectedKind(Utils::PathChooser::File); + chooser->setPromptDialogTitle(tr("Browse CSJ file")); + chooser->setPromptDialogFilter(tr("CSJ files (*.csj)")); +} + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/blackberryregisterkeydialog.h b/src/plugins/qnx/blackberryregisterkeydialog.h new file mode 100644 index 00000000000..e88398746d9 --- /dev/null +++ b/src/plugins/qnx/blackberryregisterkeydialog.h @@ -0,0 +1,99 @@ +/************************************************************************** +** +** Copyright (C) 2011 - 2013 Research In Motion +** +** Contact: Research In Motion (blackberry-qt@qnx.com) +** Contact: KDAB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QNX_INTERNAL_BLACKBERRYREGISTERKEYDIALOG_H +#define QNX_INTERNAL_BLACKBERRYREGISTERKEYDIALOG_H + +#include + +QT_BEGIN_NAMESPACE +class QPushButton; +QT_END_NAMESPACE + +namespace Utils { +class PathChooser; +} + +namespace Qnx { +namespace Internal { + +class Ui_BlackBerryRegisterKeyDialog; +class BlackBerryCsjRegistrar; +class BlackBerryCertificate; + +class BlackBerryRegisterKeyDialog : public QDialog +{ +Q_OBJECT + +public: + explicit BlackBerryRegisterKeyDialog(QWidget *parent = 0, + Qt::WindowFlags f = 0); + + QString pbdtPath() const; + QString rdkPath() const; + QString csjPin() const; + QString cskPin() const; + QString keystorePassword() const; + QString keystorePath() const; + + BlackBerryCertificate *certificate() const; + +private slots: + void csjAutoComplete(const QString &path); + void validate(); + void createKey(); + void pinCheckBoxChanged(int state); + void certCheckBoxChanged(int state); + void registrarFinished(int status, const QString &errorString); + void certificateCreated(int status); + +private: + void setupCsjPathChooser(Utils::PathChooser *chooser); + void generateDeveloperCertificate(); + void cleanup() const; + void setBusy(bool busy); + + QString getCsjAuthor(const QString &fileName) const; + + Ui_BlackBerryRegisterKeyDialog *m_ui; + + BlackBerryCsjRegistrar *m_registrar; + + BlackBerryCertificate *m_certificate; + + QPushButton *m_okButton; + QPushButton *m_cancelButton; +}; + +} // namespace Internal +} // namespace Qnx + +#endif // QNX_INTERNAL_BLACKBERRYREGISTERKEYDIALOG_H diff --git a/src/plugins/qnx/blackberryregisterkeydialog.ui b/src/plugins/qnx/blackberryregisterkeydialog.ui new file mode 100644 index 00000000000..fcb58990980 --- /dev/null +++ b/src/plugins/qnx/blackberryregisterkeydialog.ui @@ -0,0 +1,354 @@ + + + Qnx::Internal::BlackBerryRegisterKeyDialog + + + + 0 + 0 + 583 + 339 + + + + Create key + + + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + + true + + + QFrame::WinPanel + + + <html><head/><body><p><span style=" font-weight:600;">Obtaining keys</span></p><p>You will need to order a pair of CSJ files from RIM, by <a href="https://www.blackberry.com/SignedKeys/codesigning.html"><span style=" text-decoration: underline; color:#004f69;">visiting this page.</span></a></p></body></html> + + + Qt::RichText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + false + + + true + + + Qt::TextBrowserInteraction + + + + + + + Qt::Vertical + + + + 20 + 4 + + + + + + + + + + PBDT CSJ file: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + RDK CSJ file: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + CSJ pin: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + CSK pin: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Confirm CSK pin: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Keystore password: + + + + + + + Confirm password: + + + + + + + false + + + Generate developer certificate automatically + + + true + + + + + + + Show + + + + + + + QLineEdit::Password + + + + + + + QLineEdit::Password + + + + + + + + + + 10 + + + QLineEdit::Password + + + This is the pin you entered when you requested the CSJ files. + + + + + + + QLineEdit::Password + + + + + + + + + + QLineEdit::Password + + + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Status + + + Qt::AlignCenter + + + false + + + + + + + 0 + + + -1 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
+ + csjPin + cskPin + cskPin2 + genCert + keystorePassword + keystorePassword2 + showPins + buttonBox + + + +
diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro index 96930922d62..fbc201a7e41 100644 --- a/src/plugins/qnx/qnx.pro +++ b/src/plugins/qnx/qnx.pro @@ -60,7 +60,15 @@ SOURCES += qnxplugin.cpp \ bardescriptoreditorwidget.cpp \ bardescriptordocument.cpp \ bardescriptordocumentnodehandlers.cpp \ - bardescriptorpermissionsmodel.cpp + bardescriptorpermissionsmodel.cpp \ + blackberrykeyswidget.cpp \ + blackberrykeyspage.cpp \ + blackberrycsjregistrar.cpp \ + blackberrycertificate.cpp \ + blackberrycertificatemodel.cpp \ + blackberryregisterkeydialog.cpp \ + blackberryimportcertificatedialog.cpp \ + blackberrycreatecertificatedialog.cpp HEADERS += qnxplugin.h\ qnxconstants.h \ @@ -117,7 +125,15 @@ HEADERS += qnxplugin.h\ bardescriptoreditorwidget.h \ bardescriptordocument.h \ bardescriptordocumentnodehandlers.h \ - bardescriptorpermissionsmodel.h + bardescriptorpermissionsmodel.h \ + blackberrykeyswidget.h \ + blackberrykeyspage.h \ + blackberrycsjregistrar.h \ + blackberrycertificate.h \ + blackberrycertificatemodel.h \ + blackberryregisterkeydialog.h \ + blackberryimportcertificatedialog.h \ + blackberrycreatecertificatedialog.h FORMS += \ blackberrydeviceconfigurationwizardsetuppage.ui \ @@ -127,7 +143,11 @@ FORMS += \ blackberrydeviceconfigurationwidget.ui \ qnxbaseqtconfigwidget.ui \ blackberryndksettingswidget.ui \ - bardescriptoreditorwidget.ui + bardescriptoreditorwidget.ui \ + blackberrykeyswidget.ui \ + blackberryregisterkeydialog.ui \ + blackberryimportcertificatedialog.ui \ + blackberrycreatecertificatedialog.ui DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII diff --git a/src/plugins/qnx/qnx.qbs b/src/plugins/qnx/qnx.qbs index b08da75bb7d..6f2eda72543 100644 --- a/src/plugins/qnx/qnx.qbs +++ b/src/plugins/qnx/qnx.qbs @@ -97,6 +97,28 @@ QtcPlugin { "blackberryndksettingspage.h", "blackberryconfiguration.cpp", "blackberryconfiguration.h", + "blackberryregistrar.cpp", + "blackberryregistrar.h", + "blackberrycertificate.cpp", + "blackberrycertificate.h", + "blackberrykeyspage.cpp", + "blackberrykeyspage.h", + "blackberrykeyswidget.cpp", + "blackberrykeyswidget.h", + "blackberrykeyswidget.ui", + "blackberrycertificatemodel.cpp", + "blackberrycertificatemodel.h", + "blackberryregisterkeydialog.cpp", + "blackberryregisterkeydialog.h", + "blackberryregisterkeydialog.ui", + "blackberryimportcertificatedialog.cpp", + "blackberryimportcertificatedialog.h", + "blackberryimportcertificatedialog.ui", + "blackberrycreatecertificatedialog.cpp", + "blackberrycreatecertificatedialog.h", + "blackberrycreatecertificatedialog.ui", + "blackberrywizardextension.cpp", + "blackberrywizardextension.h", "pathchooserdelegate.cpp", "pathchooserdelegate.h", "qnx.qrc", diff --git a/src/plugins/qnx/qnxconstants.h b/src/plugins/qnx/qnxconstants.h index bbf31e3d6e6..54c4dba4d5e 100644 --- a/src/plugins/qnx/qnxconstants.h +++ b/src/plugins/qnx/qnxconstants.h @@ -93,11 +93,16 @@ const char QNX_BB_CATEGORY[] = "XF.BlackBerry"; const char QNX_BB_CATEGORY_TR[] = QT_TRANSLATE_NOOP("BlackBerry", "BlackBerry"); const char QNX_BB_CATEGORY_ICON[] = ":/qnx/images/target.png"; const char QNX_BB_NDK_SETTINGS_ID[] = "ZZ.BlackBerry NDK Configuration"; +const char QNX_BB_SIGNING_ID[] = "ZZ.BlackBerry Signing Infrastructure Configuration"; const char QNX_BAR_DESCRIPTOR_MIME_TYPE[] = "application/vnd.rim.qnx.bar_descriptor"; const char QNX_BAR_DESCRIPTOR_EDITOR_ID[] = "Qnx.BarDescriptorEditor"; const char QNX_TASK_CATEGORY_BARDESCRIPTOR[] = "Task.Category.BarDescriptor"; + +const char QNX_KEY_AUTHOR[] = "author"; +const char QNX_KEY_PATH[] = "path"; +const char QNX_KEY_ACTIVE[] = "active"; } // namespace Constants } // namespace Qnx diff --git a/src/plugins/qnx/qnxplugin.cpp b/src/plugins/qnx/qnxplugin.cpp index 35b6155103f..e329e3b7c05 100644 --- a/src/plugins/qnx/qnxplugin.cpp +++ b/src/plugins/qnx/qnxplugin.cpp @@ -48,6 +48,7 @@ #include "blackberryndksettingspage.h" #include "bardescriptoreditorfactory.h" #include "bardescriptormagicmatcher.h" +#include "blackberrykeyspage.h" #include #include @@ -78,6 +79,7 @@ bool QNXPlugin::initialize(const QStringList &arguments, QString *errorString) addAutoReleasedObject(new BlackBerryRunConfigurationFactory); addAutoReleasedObject(new BlackBerryRunControlFactory); addAutoReleasedObject(new BlackBerryNDKSettingsPage); + addAutoReleasedObject(new BlackBerryKeysPage); // Handles QNX addAutoReleasedObject(new QnxQtVersionFactory);