Commit 9f0583f8 authored by Rafael Roquetto's avatar Rafael Roquetto

BlackBerry NDK 10.2 signing support

Change-Id: I7bd6649dd20b0b204b7a4f4bcbcee6bc45fa0272
Reviewed-by: Nicolas Arnaud-Cormos's avatarNicolas Arnaud-Cormos <nicolas@kdab.com>
parent 9654df9f
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
......@@ -50,6 +50,7 @@ BlackBerryCertificate::BlackBerryCertificate(const QString &fileName,
m_storePass(storePass),
m_process(new QProcess(this))
{
m_process->setProcessChannelMode(QProcess::MergedChannels);
}
void BlackBerryCertificate::load()
......@@ -142,10 +143,12 @@ void BlackBerryCertificate::loadFinished()
while (!processOutput.atEnd()) {
QString chunk = processOutput.readLine();
if (chunk.contains(
QLatin1String("Error: Failed to decrypt keystore, invalid password"))) {
if (chunk.contains(QLatin1String("invalid password"))) {
status = WrongPassword;
break;
} else if (chunk.contains(QLatin1String("must be at least 6 characters"))) {
status = PasswordTooSmall;
break;
} else if (chunk.startsWith(QLatin1String("Owner:"))) {
chunk.remove(QLatin1String("Owner:"));
m_author = chunk.remove(QLatin1String("CN=")).trimmed();
......
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
......@@ -51,6 +51,7 @@ public:
Success,
Busy,
WrongPassword,
PasswordTooSmall,
InvalidOutputFormat,
Error
};
......
/**************************************************************************
**
** 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 "blackberryconfigurationmanager.h"
#include <coreplugin/icore.h>
#include <QSettings>
#include <QStringList>
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++) {
m_certificates.removeAt(row);
//XXX shall we also delete from disk?
}
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<BlackBerryCertificate*> 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()
{
BlackBerryConfigurationManager &configManager = BlackBerryConfigurationManager::instance();
m_certificates = configManager.certificates();
m_activeCertificate = configManager.activeCertificate();
}
} // namespace Internal
} // namespace Qnx
/**************************************************************************
**
** 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 BLACKBERRYCERTIFICATEMODEL_H
#define BLACKBERRYCERTIFICATEMODEL_H
#include <QAbstractTableModel>
#include <QList>
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<BlackBerryCertificate*> certificates() const;
private slots:
void load();
private:
enum Columns {
CertPath,
CertAuthor,
CertActive,
ColumnCount
};
QList<BlackBerryCertificate*> m_certificates;
BlackBerryCertificate *m_activeCertificate;
};
} // namespace Internal
} // namespace Qnx
#endif // BLACKBERRYCERTIFICATEMODEL_H
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
......@@ -71,33 +71,6 @@ BlackBerryConfigurationManager::BlackBerryConfigurationManager(QObject *parent)
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
}
void BlackBerryConfigurationManager::loadCertificates()
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->beginGroup(CertificateGroup);
foreach (const 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_activeCertificate = cert;
m_certificates << cert;
settings->endGroup();
}
settings->endGroup();
settings->endGroup();
}
void BlackBerryConfigurationManager::loadManualConfigurations()
{
QSettings *settings = Core::ICore::settings();
......@@ -173,29 +146,6 @@ QStringList BlackBerryConfigurationManager::activeConfigurationNdkEnvPaths()
return actives;
}
void BlackBerryConfigurationManager::saveCertificates()
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->beginGroup(CertificateGroup);
settings->remove(QString());
foreach (const BlackBerryCertificate *cert, m_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_activeCertificate)
settings->setValue(QLatin1String(Qnx::Constants::QNX_KEY_ACTIVE), true);
settings->endGroup();
}
settings->endGroup();
settings->endGroup();
}
void BlackBerryConfigurationManager::saveManualConfigurations()
{
if (manualConfigurations().isEmpty())
......@@ -331,52 +281,6 @@ BlackBerryConfiguration *BlackBerryConfigurationManager::configurationFromEnvFil
return 0;
}
void BlackBerryConfigurationManager::syncCertificates(QList<BlackBerryCertificate*> certificates,
BlackBerryCertificate *activeCertificate)
{
m_activeCertificate = activeCertificate;
foreach (BlackBerryCertificate *cert, certificates) {
if (!certificates.contains(cert))
removeCertificate(cert);
}
foreach (BlackBerryCertificate *cert, certificates)
addCertificate(cert);
}
void BlackBerryConfigurationManager::addCertificate(BlackBerryCertificate *certificate)
{
if (m_certificates.contains(certificate))
return;
if (m_certificates.isEmpty())
m_activeCertificate = certificate;
certificate->setParent(this);
m_certificates << certificate;
}
void BlackBerryConfigurationManager::removeCertificate(BlackBerryCertificate *certificate)
{
if (m_activeCertificate == certificate)
m_activeCertificate = 0;
m_certificates.removeAll(certificate);
delete certificate;
}
QList<BlackBerryCertificate*> BlackBerryConfigurationManager::certificates() const
{
return m_certificates;
}
BlackBerryCertificate * BlackBerryConfigurationManager::activeCertificate()
{
return m_activeCertificate;
}
// Returns a valid qnxEnv map from a valid configuration;
// Needed by other classes to get blackberry process path (keys registration, debug token...)
QMultiMap<QString, QString> BlackBerryConfigurationManager::defaultQnxEnv()
......@@ -394,7 +298,6 @@ void BlackBerryConfigurationManager::loadSettings()
clearInvalidConfigurations();
loadAutoDetectedConfigurations();
loadManualConfigurations();
loadCertificates();
emit settingsLoaded();
}
......@@ -423,7 +326,6 @@ void BlackBerryConfigurationManager::saveSettings()
{
saveActiveConfigurationNdkEnvPath();
saveManualConfigurations();
saveCertificates();
}
BlackBerryConfigurationManager &BlackBerryConfigurationManager::instance()
......@@ -444,6 +346,11 @@ QString BlackBerryConfigurationManager::barsignerCskPath() const
return QnxUtils::dataDirPath() + QLatin1String("/barsigner.csk");
}
QString BlackBerryConfigurationManager::idTokenPath() const
{
return QnxUtils::dataDirPath() + QLatin1String("/bbidtoken.csk");
}
QString BlackBerryConfigurationManager::barsignerDbPath() const
{
return QnxUtils::dataDirPath() + QLatin1String("/barsigner.db");
......
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
......@@ -42,7 +42,6 @@ namespace Qnx {
namespace Internal {
class BlackBerryConfiguration;
class BlackBerryCertificate;
class BlackBerryConfigurationManager : public QObject
{
......@@ -58,17 +57,11 @@ public:
BlackBerryConfiguration *configurationFromEnvFile(const Utils::FileName &envFile) const;
QString barsignerCskPath() const;
QString idTokenPath() const;
QString barsignerDbPath() const;
QString defaultKeystorePath() const;
QString defaultDebugTokenPath() const;
void clearConfigurationSettings(BlackBerryConfiguration *config);
void syncCertificates(QList<BlackBerryCertificate*> certificates,
BlackBerryCertificate *activeCertificate);
void addCertificate(BlackBerryCertificate *certificate);
void removeCertificate(BlackBerryCertificate *certificate);
QList<BlackBerryCertificate*> certificates() const;
BlackBerryCertificate *activeCertificate();
QMultiMap<QString, QString> defaultQnxEnv();
......@@ -84,13 +77,8 @@ private:
static BlackBerryConfigurationManager *m_instance;
QList<BlackBerryConfiguration*> m_configs;
QList<BlackBerryCertificate*> m_certificates;
BlackBerryCertificate *m_activeCertificate;
void loadCertificates();
void loadManualConfigurations();
void loadAutoDetectedConfigurations();
void saveCertificates();
void saveManualConfigurations();
void saveActiveConfigurationNdkEnvPath();
void clearInvalidConfigurations();
......
<
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
......@@ -31,6 +31,7 @@
#include "blackberrycreatecertificatedialog.h"
#include "blackberrycertificate.h"
#include "blackberryconfigurationmanager.h"
#include "ui_blackberrycreatecertificatedialog.h"
#include <QPushButton>
......@@ -49,9 +50,6 @@ BlackBerryCreateCertificateDialog::BlackBerryCreateCertificateDialog(
{
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);
......@@ -64,10 +62,6 @@ BlackBerryCreateCertificateDialog::BlackBerryCreateCertificateDialog(
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)),
......@@ -85,7 +79,7 @@ QString BlackBerryCreateCertificateDialog::author() const
QString BlackBerryCreateCertificateDialog::certPath() const
{
return m_ui->certPath->path();
return BlackBerryConfigurationManager::instance().defaultKeystorePath();
}
QString BlackBerryCreateCertificateDialog::keystorePassword() const
......@@ -100,8 +94,7 @@ BlackBerryCertificate * BlackBerryCreateCertificateDialog::certificate() const
void BlackBerryCreateCertificateDialog::validate()
{
if (!m_ui->certPath->isValid()
|| m_ui->author->text().isEmpty()
if (m_ui->author->text().isEmpty()
|| m_ui->password->text().isEmpty()
|| m_ui->password2->text().isEmpty()) {
m_ui->status->clear();
......@@ -109,7 +102,7 @@ void BlackBerryCreateCertificateDialog::validate()
return;
}
QFileInfo fileInfo(m_ui->certPath->path());
QFileInfo fileInfo(certPath());
if (!fileInfo.dir().exists()) {
m_ui->status->setText(tr("Base directory does not exist."));
......@@ -123,6 +116,12 @@ void BlackBerryCreateCertificateDialog::validate()
return;
}
if (m_ui->password->text().size() < 6) {
m_ui->status->setText(tr("Password must be at least 6 characters long."));
m_okButton->setEnabled(false);
return;
}