Commit 0a0debe3 authored by Rafael Roquetto's avatar Rafael Roquetto Committed by hjk

Qnx: Simple BlackBerry debug token management.

This patch enables debug token creation and installation.

Change-Id: I85cbb8ddc413228662cd7967e1805196212a430c
Reviewed-by: default avatarTobias Nätterlund <tobias.naetterlund@kdab.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 2be16feb
/**************************************************************************
**
** 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 "blackberrydebugtokenrequestdialog.h"
#include "blackberrydebugtokenrequester.h"
#include "blackberryconfiguration.h"
#include "blackberrycertificate.h"
#include "ui_blackberrydebugtokenrequestdialog.h"
#include <QPushButton>
#include <QDir>
#include <QMessageBox>
namespace Qnx {
namespace Internal {
BlackBerryDebugTokenRequestDialog::BlackBerryDebugTokenRequestDialog(
QWidget *parent, Qt::WindowFlags f) :
QDialog(parent, f),
m_ui(new Ui_BlackBerryDebugTokenRequestDialog),
m_requester(new BlackBerryDebugTokenRequester)
{
m_ui->setupUi(this);
m_ui->progressBar->hide();
m_ui->status->clear();
m_ui->debugTokenPath->setExpectedKind(Utils::PathChooser::Any);
m_ui->debugTokenPath->setPromptDialogTitle(tr("Request Debug Token"));
m_ui->debugTokenPath->setPromptDialogFilter(tr("BAR Files (*.bar)"));
m_cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel);
m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
m_okButton->setEnabled(false);
populateComboBox();
connect(m_cancelButton, SIGNAL(clicked()),
this, SLOT(reject()));
connect(m_okButton, SIGNAL(clicked()),
this, SLOT(requestDebugToken()));
connect(m_ui->debugTokenPath, SIGNAL(changed(QString)),
this, SLOT(validate()));
connect(m_ui->debugTokenPath, SIGNAL(editingFinished()),
this, SLOT(appendExtension()));
connect(m_ui->keystorePassword, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(m_ui->cskPassword, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(m_ui->devicePin, SIGNAL(textChanged(QString)),
this, SLOT(validate()));
connect(m_ui->showPassword, SIGNAL(stateChanged(int)),
this, SLOT(checkBoxChanged(int)));
connect(m_requester, SIGNAL(finished(int)),
this, SLOT(debugTokenArrived(int)));
}
QString BlackBerryDebugTokenRequestDialog::debugToken() const
{
return m_ui->debugTokenPath->path();
}
void BlackBerryDebugTokenRequestDialog::validate()
{
if (!m_ui->debugTokenPath->isValid()
|| m_ui->keystorePassword->text().isEmpty()
|| m_ui->devicePin->text().isEmpty()
|| m_ui->cskPassword->text().isEmpty()) {
m_okButton->setEnabled(false);
return;
}
QFileInfo fileInfo(m_ui->debugTokenPath->path());
if (!fileInfo.dir().exists()) {
m_ui->status->setText(tr("Base directory does not exist."));
m_okButton->setEnabled(false);
return;
}
m_ui->status->clear();
m_okButton->setEnabled(true);
}
void BlackBerryDebugTokenRequestDialog::requestDebugToken()
{
setBusy(true);
QFile file(m_ui->debugTokenPath->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_requester->requestDebugToken(m_ui->debugTokenPath->path(),
m_ui->cskPassword->text(),
m_ui->keystore->itemText(m_ui->keystore->currentIndex()),
m_ui->keystorePassword->text(), m_ui->devicePin->text());
}
void BlackBerryDebugTokenRequestDialog::appendExtension()
{
QString path = m_ui->debugTokenPath->path();
if (!path.endsWith(QLatin1String(".bar"))) {
path += QLatin1String(".bar");
m_ui->debugTokenPath->setPath(path);
}
}
void BlackBerryDebugTokenRequestDialog::checkBoxChanged(int state)
{
if (state == Qt::Checked) {
m_ui->cskPassword->setEchoMode(QLineEdit::Normal);
m_ui->keystorePassword->setEchoMode(QLineEdit::Normal);
} else {
m_ui->cskPassword->setEchoMode(QLineEdit::Password);
m_ui->keystorePassword->setEchoMode(QLineEdit::Password);
}
}
void BlackBerryDebugTokenRequestDialog::debugTokenArrived(int status)
{
QString errorString = tr("Failed to request debug token: ");
switch (status) {
case BlackBerryDebugTokenRequester::Success:
accept();
return;
case BlackBerryDebugTokenRequester::WrongCskPassword:
errorString += tr("Wrong CSK password.");
break;
case BlackBerryDebugTokenRequester::WrongKeystorePassword:
errorString += tr("Wrong keystore password.");
break;
case BlackBerryDebugTokenRequester::NetworkUnreachable:
errorString += tr("Network unreachable.");
break;
case BlackBerryDebugTokenRequester::IllegalPin:
errorString += tr("Illegal device PIN.");
break;
case BlackBerryDebugTokenRequester::FailedToStartInferiorProcess:
errorString += tr("Failed to start inferior process.");
break;
case BlackBerryDebugTokenRequester::InferiorProcessTimedOut:
errorString += tr("Inferior processes timed out.");
break;
case BlackBerryDebugTokenRequester::InferiorProcessCrashed:
errorString += tr("Inferior process has crashed.");
break;
case BlackBerryDebugTokenRequester::InferiorProcessReadError:
case BlackBerryDebugTokenRequester::InferiorProcessWriteError:
errorString += tr("Failed to communicate with the inferior process.");
break;
case BlackBerryDebugTokenRequester::UnknownError:
errorString += tr("An unknwon error has occurred.");
break;
}
QMessageBox::critical(this, tr("Error"), errorString);
setBusy(false);
}
void BlackBerryDebugTokenRequestDialog::setBusy(bool busy)
{
m_okButton->setEnabled(!busy);
m_cancelButton->setEnabled(!busy);
m_ui->debugTokenPath->setEnabled(!busy);
m_ui->keystore->setEnabled(!busy);
m_ui->keystorePassword->setEnabled(!busy);
m_ui->cskPassword->setEnabled(!busy);
m_ui->showPassword->setEnabled(!busy);
m_ui->devicePin->setEnabled(!busy);
m_ui->progressBar->setVisible(busy);
if (busy)
m_ui->status->setText(tr("Requesting debug token..."));
else
m_ui->status->clear();
}
void BlackBerryDebugTokenRequestDialog::populateComboBox()
{
BlackBerryConfiguration &configuration = BlackBerryConfiguration::instance();
QList<BlackBerryCertificate*> certificates = configuration.certificates();
foreach (const BlackBerryCertificate *certificate, certificates)
m_ui->keystore->addItem(certificate->fileName());
}
}
} // 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 QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTDIALOG_H
#define QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTDIALOG_H
#include <QDialog>
QT_BEGIN_NAMESPACE
class QPushButton;
QT_END_NAMESPACE
namespace Qnx {
namespace Internal {
class Ui_BlackBerryDebugTokenRequestDialog;
class BlackBerryDebugTokenRequester;
class BlackBerryDebugTokenRequestDialog : public QDialog
{
Q_OBJECT
public:
explicit BlackBerryDebugTokenRequestDialog(QWidget *parent = 0,
Qt::WindowFlags f = 0);
QString debugToken() const;
private slots:
void validate();
void requestDebugToken();
void appendExtension();
void checkBoxChanged(int state);
void debugTokenArrived(int status);
private:
void setBusy(bool busy);
void populateComboBox();
Ui_BlackBerryDebugTokenRequestDialog *m_ui;
BlackBerryDebugTokenRequester *m_requester;
QPushButton *m_cancelButton;
QPushButton *m_okButton;
};
}
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BlackBerryDebugTokenRequestDialog</class>
<widget class="QDialog" name="Qnx::Internal::BlackBerryDebugTokenRequestDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>198</height>
</rect>
</property>
<property name="windowTitle">
<string>Request Debug Token</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Debug token path:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::PathChooser" name="debugTokenPath" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Keystore:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="keystore"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Keystore password:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="keystorePassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>CSK password:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="cskPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Device PIN:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="devicePin">
<property name="inputMask">
<string notr="true">HHHHHHHH; </string>
</property>
<property name="maxLength">
<number>8</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="showPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="status">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Status</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
/**************************************************************************
**
** 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 "blackberrydebugtokenrequester.h"
namespace {
static const char PROCESS_NAME[] = "blackberry-debugtokenrequest";
static const char ERR_WRONG_CSK_PASS[] = "The signature on the code signing request didn't verify.";
static const char ERR_WRONG_KEYSTORE_PASS[] = "Failed to decrypt keystore, invalid password";
static const char ERR_ILLEGAL_DEVICE_PIN[] = "Illegal device PIN";
static const char ERR_NETWORK_UNREACHABLE[] = "Network is unreachable";
}
namespace Qnx {
namespace Internal {
BlackBerryDebugTokenRequester::BlackBerryDebugTokenRequester(QObject *parent) :
BlackBerryNdkProcess(QLatin1String(PROCESS_NAME), parent)
{
addErrorStringMapping(QLatin1String(ERR_WRONG_CSK_PASS), WrongCskPassword);
addErrorStringMapping(QLatin1String(ERR_WRONG_KEYSTORE_PASS), WrongKeystorePassword);
addErrorStringMapping(QLatin1String(ERR_WRONG_KEYSTORE_PASS), WrongKeystorePassword);
addErrorStringMapping(QLatin1String(ERR_NETWORK_UNREACHABLE), NetworkUnreachable);
}
void BlackBerryDebugTokenRequester::requestDebugToken(const QString &path,
const QString &cskPassword, const QString &keyStore,
const QString &keyStorePassword, const QString &devicePin)
{
QStringList arguments;
arguments << QLatin1String("-keystore")
<< keyStore
<< QLatin1String("-storepass")
<< keyStorePassword
<< QLatin1String("-cskpass")
<< cskPassword
<< QLatin1String("-devicepin")
<< devicePin
<< path;
start(arguments);
}
} // 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 QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTER_H
#define QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTER_H
#include "blackberryndkprocess.h"
namespace Qnx {
namespace Internal {
class BlackBerryDebugTokenRequester : public BlackBerryNdkProcess
{
Q_OBJECT
public:
enum ReturnStatus
{
WrongCskPassword = UserStatus,
WrongKeystorePassword,
NetworkUnreachable,
IllegalPin
};
explicit BlackBerryDebugTokenRequester(QObject *parent = 0);
void requestDebugToken(const QString &path, const QString &cskPassword,
const QString &keyStore, const QString &keyStorePassword,
const QString &devicePin);
};
}
}
#endif // QNX_INTERNAL_BLACKBERRYDEBUGTOKENREQUESTER_H
/**************************************************************************
**
** 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