2011-03-04 13:59:07 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-03-04 13:59:07 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "sslmanager.h"
|
|
|
|
#include "ui_sslmanager.h"
|
|
|
|
#include "networkmanager.h"
|
|
|
|
#include "mainapplication.h"
|
2011-10-12 22:28:41 +02:00
|
|
|
#include "globalfunctions.h"
|
|
|
|
#include "certificateinfowidget.h"
|
2011-03-04 13:59:07 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QSslSocket>
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
SSLManager::SSLManager(QWidget* parent)
|
2011-10-26 19:23:50 +02:00
|
|
|
: QDialog(parent)
|
2011-10-12 22:28:41 +02:00
|
|
|
, ui(new Ui::SSLManager)
|
2011-03-04 13:59:07 +01:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
ui->setupUi(this);
|
2011-03-20 18:08:31 +01:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
refreshLocalList();
|
|
|
|
refreshCAList();
|
|
|
|
refreshPaths();
|
2011-03-04 15:15:21 +01:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
connect(ui->caList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showCaCertInfo()));
|
|
|
|
connect(ui->caInfoButton, SIGNAL(clicked()), this, SLOT(showCaCertInfo()));
|
2011-03-04 15:15:21 +01:00
|
|
|
connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteCertificate()));
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
connect(ui->localList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showLocalCertInfo()));
|
|
|
|
connect(ui->localInfoButton, SIGNAL(clicked()), this, SLOT(showLocalCertInfo()));
|
2012-04-20 14:49:16 +02:00
|
|
|
connect(ui->addLocalCert, SIGNAL(clicked()), this, SLOT(addLocalCertificate()));
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
connect(ui->addPath, SIGNAL(clicked()), this, SLOT(addPath()));
|
|
|
|
connect(ui->deletePath, SIGNAL(clicked()), this, SLOT(deletePath()));
|
2011-03-04 15:15:21 +01:00
|
|
|
connect(ui->ignoreAll, SIGNAL(clicked(bool)), this, SLOT(ignoreAll(bool)));
|
|
|
|
|
2011-10-21 19:52:58 +02:00
|
|
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->ignoreAll->setChecked(mApp->networkManager()->isIgnoringAllWarnings());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::addPath()
|
|
|
|
{
|
|
|
|
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path..."));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (path.isEmpty()) {
|
2011-10-12 22:28:41 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
ui->pathList->addItem(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::deletePath()
|
|
|
|
{
|
|
|
|
QListWidgetItem* currentItem = ui->pathList->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!currentItem) {
|
2011-10-12 22:28:41 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
delete currentItem;
|
2011-03-04 15:15:21 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
void SSLManager::refreshCAList()
|
2011-03-20 18:08:31 +01:00
|
|
|
{
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->caList->setUpdatesEnabled(false);
|
|
|
|
ui->caList->clear();
|
|
|
|
m_caCerts = QSslSocket::defaultCaCertificates();
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2012-01-24 19:12:31 +01:00
|
|
|
foreach(const QSslCertificate & cert, m_caCerts) {
|
2012-01-28 12:02:37 +01:00
|
|
|
if (m_localCerts.contains(cert)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->caList);
|
2011-11-06 17:01:23 +01:00
|
|
|
item->setText(CertificateInfoWidget::certificateItemText(cert));
|
2012-03-13 17:51:06 +01:00
|
|
|
item->setData(Qt::UserRole + 10, m_caCerts.indexOf(cert));
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->caList->addItem(item);
|
2011-03-20 18:08:31 +01:00
|
|
|
}
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->caList->setCurrentRow(0);
|
|
|
|
ui->caList->setUpdatesEnabled(true);
|
2011-03-20 18:08:31 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
void SSLManager::refreshLocalList()
|
2011-03-04 15:15:21 +01:00
|
|
|
{
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->localList->setUpdatesEnabled(false);
|
|
|
|
ui->localList->clear();
|
|
|
|
m_localCerts = mApp->networkManager()->getLocalCertificates();
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2012-01-24 19:12:31 +01:00
|
|
|
foreach(const QSslCertificate & cert, m_localCerts) {
|
2011-10-12 22:28:41 +02:00
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->localList);
|
2011-11-06 17:01:23 +01:00
|
|
|
item->setText(CertificateInfoWidget::certificateItemText(cert));
|
2012-03-13 17:51:06 +01:00
|
|
|
item->setData(Qt::UserRole + 10, m_localCerts.indexOf(cert));
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->localList->addItem(item);
|
|
|
|
}
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
ui->localList->setCurrentRow(0);
|
|
|
|
ui->localList->setUpdatesEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::refreshPaths()
|
|
|
|
{
|
2012-01-24 19:12:31 +01:00
|
|
|
foreach(const QString & path, mApp->networkManager()->certificatePaths()) {
|
2012-01-23 17:30:34 +01:00
|
|
|
ui->pathList->addItem(path);
|
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::showCaCertInfo()
|
|
|
|
{
|
|
|
|
QListWidgetItem* item = ui->caList->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-04 15:15:21 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-04 15:15:21 +01:00
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
QSslCertificate cert = m_caCerts.at(item->data(Qt::UserRole + 10).toInt());
|
2011-10-12 22:28:41 +02:00
|
|
|
showCertificateInfo(cert);
|
|
|
|
}
|
|
|
|
|
2012-04-20 14:49:16 +02:00
|
|
|
void SSLManager::addLocalCertificate()
|
|
|
|
{
|
|
|
|
const QString &path = QFileDialog::getOpenFileName(this, tr("Import certificate..."), QDir::homePath(), "*.crt");
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QSslCertificate> list = QSslCertificate::fromPath(path);
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mApp->networkManager()->addLocalCertificate(list.at(0));
|
|
|
|
|
|
|
|
refreshLocalList();
|
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
void SSLManager::showLocalCertInfo()
|
|
|
|
{
|
|
|
|
QListWidgetItem* item = ui->localList->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-10-12 22:28:41 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
QSslCertificate cert = m_localCerts.at(item->data(Qt::UserRole + 10).toInt());
|
2011-10-12 22:28:41 +02:00
|
|
|
showCertificateInfo(cert);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::showCertificateInfo(const QSslCertificate &cert)
|
|
|
|
{
|
2011-10-26 19:23:50 +02:00
|
|
|
QDialog* w = new QDialog(this);
|
2011-10-12 22:28:41 +02:00
|
|
|
w->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
w->setWindowTitle(tr("Certificate Informations"));
|
|
|
|
w->setLayout(new QVBoxLayout);
|
|
|
|
CertificateInfoWidget* c = new CertificateInfoWidget(cert);
|
|
|
|
w->layout()->addWidget(c);
|
|
|
|
QDialogButtonBox* b = new QDialogButtonBox(w);
|
|
|
|
b->setStandardButtons(QDialogButtonBox::Close);
|
|
|
|
connect(b, SIGNAL(clicked(QAbstractButton*)), w, SLOT(close()));
|
|
|
|
w->layout()->addWidget(b);
|
|
|
|
w->resize(w->sizeHint());
|
2011-10-26 19:23:50 +02:00
|
|
|
qz_centerWidgetToParent(w, this);
|
2011-10-12 22:28:41 +02:00
|
|
|
w->show();
|
2011-03-04 15:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::deleteCertificate()
|
|
|
|
{
|
2011-10-12 22:28:41 +02:00
|
|
|
QListWidgetItem* item = ui->localList->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-04 15:15:21 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-04 15:15:21 +01:00
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
QSslCertificate cert = m_localCerts.at(item->data(Qt::UserRole + 10).toInt());
|
2011-10-12 22:28:41 +02:00
|
|
|
m_localCerts.removeOne(cert);
|
|
|
|
mApp->networkManager()->removeLocalCertificate(cert);
|
|
|
|
refreshLocalList();
|
2011-03-04 15:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSLManager::ignoreAll(bool state)
|
|
|
|
{
|
2011-10-12 22:28:41 +02:00
|
|
|
mApp->networkManager()->setIgnoreAllWarnings(state);
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void SSLManager::closeEvent(QCloseEvent* e)
|
2011-10-12 22:28:41 +02:00
|
|
|
{
|
|
|
|
QStringList paths;
|
|
|
|
for (int i = 0; i < ui->pathList->count(); i++) {
|
|
|
|
QListWidgetItem* item = ui->pathList->item(i);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item || item->text().isEmpty()) {
|
2011-10-12 22:28:41 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
paths.append(item->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
mApp->networkManager()->setCertificatePaths(paths);
|
|
|
|
|
|
|
|
QWidget::closeEvent(e);
|
2011-03-04 13:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SSLManager::~SSLManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|