1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[SslErrorDialog] Add option to accept certificate permanently.

Closes #939
This commit is contained in:
nowrep 2013-09-19 20:21:46 +02:00
parent f527a837db
commit ee8a00ea50
7 changed files with 278 additions and 35 deletions

View File

@ -246,7 +246,8 @@ SOURCES += \
autofill/passwordbackends/databasepasswordbackend.cpp \
autofill/passwordbackends/passwordbackend.cpp \
tools/aesinterface.cpp \
autofill/passwordbackends/databaseencryptedpasswordbackend.cpp
autofill/passwordbackends/databaseencryptedpasswordbackend.cpp \
network/sslerrordialog.cpp
HEADERS += \
@ -429,7 +430,8 @@ HEADERS += \
autofill/passwordbackends/passwordbackend.h \
autofill/passwordbackends/databasepasswordbackend.h \
tools/aesinterface.h \
autofill/passwordbackends/databaseencryptedpasswordbackend.h
autofill/passwordbackends/databaseencryptedpasswordbackend.h \
network/sslerrordialog.h
FORMS += \
preferences/autofillmanager.ui \
@ -479,7 +481,8 @@ FORMS += \
tools/html5permissions/html5permissionsnotification.ui \
tools/html5permissions/html5permissionsdialog.ui \
autofill/autofillwidget.ui \
autofill/passwordbackends/masterpassworddialog.ui
autofill/passwordbackends/masterpassworddialog.ui \
network/sslerrordialog.ui
RESOURCES += \
data/icons.qrc \

View File

@ -31,6 +31,7 @@
#include "cabundleupdater.h"
#include "settings.h"
#include "passwordmanager.h"
#include "sslerrordialog.h"
#include "schemehandlers/adblockschemehandler.h"
#include "schemehandlers/qupzillaschemehandler.h"
#include "schemehandlers/fileschemehandler.h"
@ -212,7 +213,7 @@ void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
const QSslCertificate &cert = i.key();
const QStringList &errors = i.value();
if (m_localCerts.contains(cert) || errors.isEmpty()) {
if (m_localCerts.contains(cert) || m_tempAllowedCerts.contains(cert) || errors.isEmpty()) {
++i;
continue;
}
@ -240,18 +241,34 @@ void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
QString message = QString("<b>%1</b><p>%2</p>%3<p>%4</p>").arg(title, text1, certs, text2);
if (!certs.isEmpty()) {
QMessageBox::StandardButton button = QMessageBox::critical(webPage->view(), tr("SSL Certificate Error!"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::No) {
SslErrorDialog dialog(webPage->view());
dialog.setText(message);
dialog.exec();
switch (dialog.result()) {
case SslErrorDialog::Yes:
foreach (const QSslCertificate &cert, errorHash.keys()) {
if (!m_localCerts.contains(cert)) {
addLocalCertificate(cert);
}
}
break;
case SslErrorDialog::OnlyForThisSession:
foreach (const QSslCertificate &cert, errorHash.keys()) {
if (!m_tempAllowedCerts.contains(cert)) {
m_tempAllowedCerts.append(cert);
}
}
break;
default:
// To prevent asking user more than once for the same certificate
webPage->addRejectedCerts(errorHash.keys());
return;
}
foreach (const QSslCertificate &cert, errorHash.keys()) {
if (!m_localCerts.contains(cert)) {
addLocalCertificate(cert);
}
}
}
reply->ignoreSslErrors(errors);

View File

@ -76,7 +76,7 @@ private:
QStringList m_certPaths;
QList<QSslCertificate> m_caCerts;
QList<QSslCertificate> m_localCerts;
QList<QSslCertificate> m_ignoredCerts;
QList<QSslCertificate> m_tempAllowedCerts;
QHash<QString, SchemeHandler*> m_schemeHandlers;
QByteArray m_acceptLanguage;

View File

@ -0,0 +1,70 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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 "sslerrordialog.h"
#include "ui_sslerrordialog.h"
#include "iconprovider.h"
#include <QPushButton>
SslErrorDialog::SslErrorDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::SslErrorDialog)
, m_result(No)
{
ui->setupUi(this);
ui->icon->setPixmap(qIconProvider->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(52));
ui->buttonBox->addButton(tr("Only for this session"), QDialogButtonBox::ApplyRole);
ui->buttonBox->button(QDialogButtonBox::No)->setFocus();
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
}
SslErrorDialog::~SslErrorDialog()
{
delete ui;
}
void SslErrorDialog::setText(const QString &text)
{
ui->text->setText(text);
}
SslErrorDialog::Result SslErrorDialog::result()
{
return m_result;
}
void SslErrorDialog::buttonClicked(QAbstractButton* button)
{
switch (ui->buttonBox->buttonRole(button)) {
case QDialogButtonBox::YesRole:
m_result = Yes;
accept();
break;
case QDialogButtonBox::ApplyRole:
m_result = OnlyForThisSession;
accept();
break;
default:
m_result = No;
reject();
break;
}
}

View File

@ -0,0 +1,54 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef SSLERRORDIALOG_H
#define SSLERRORDIALOG_H
#include <QDialog>
namespace Ui
{
class SslErrorDialog;
}
class QAbstractButton;
#include "qz_namespace.h"
class QT_QUPZILLA_EXPORT SslErrorDialog : public QDialog
{
Q_OBJECT
public:
enum Result { Yes, No, OnlyForThisSession };
explicit SslErrorDialog(QWidget* parent = 0);
~SslErrorDialog();
void setText(const QString &text);
Result result();
private slots:
void buttonClicked(QAbstractButton* button);
private:
Ui::SslErrorDialog* ui;
Result m_result;
};
#endif // SSLERRORDIALOG_H

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SslErrorDialog</class>
<widget class="QDialog" name="SslErrorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>511</width>
<height>72</height>
</rect>
</property>
<property name="windowTitle">
<string>SSL Certificate Error!</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="icon">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="text">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::No|QDialogButtonBox::Yes</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -2445,92 +2445,91 @@ Please install latest version of QupZilla.</source>
<context>
<name>NetworkManager</name>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="205"/>
<location filename="../src/lib/network/networkmanager.cpp" line="243"/>
<location filename="../src/lib/network/networkmanager.cpp" line="206"/>
<source>SSL Certificate Error!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="206"/>
<location filename="../src/lib/network/networkmanager.cpp" line="207"/>
<source>The page you are trying to access has the following errors in the SSL certificate:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="221"/>
<location filename="../src/lib/network/networkmanager.cpp" line="222"/>
<source>&lt;b&gt;Organization: &lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="223"/>
<location filename="../src/lib/network/networkmanager.cpp" line="224"/>
<source>&lt;b&gt;Domain Name: &lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="225"/>
<location filename="../src/lib/network/networkmanager.cpp" line="226"/>
<source>&lt;b&gt;Expiration Date: &lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="231"/>
<location filename="../src/lib/network/networkmanager.cpp" line="232"/>
<source>&lt;b&gt;Error: &lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="239"/>
<location filename="../src/lib/network/networkmanager.cpp" line="240"/>
<source>Would you like to make an exception for this certificate?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="263"/>
<location filename="../src/lib/network/networkmanager.cpp" line="280"/>
<source>Authorisation required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="270"/>
<location filename="../src/lib/network/networkmanager.cpp" line="377"/>
<location filename="../src/lib/network/networkmanager.cpp" line="449"/>
<location filename="../src/lib/network/networkmanager.cpp" line="287"/>
<location filename="../src/lib/network/networkmanager.cpp" line="394"/>
<location filename="../src/lib/network/networkmanager.cpp" line="466"/>
<source>Username: </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="271"/>
<location filename="../src/lib/network/networkmanager.cpp" line="378"/>
<location filename="../src/lib/network/networkmanager.cpp" line="450"/>
<location filename="../src/lib/network/networkmanager.cpp" line="288"/>
<location filename="../src/lib/network/networkmanager.cpp" line="395"/>
<location filename="../src/lib/network/networkmanager.cpp" line="467"/>
<source>Password: </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="276"/>
<location filename="../src/lib/network/networkmanager.cpp" line="293"/>
<source>Save username and password on this site</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="285"/>
<location filename="../src/lib/network/networkmanager.cpp" line="302"/>
<source>A username and password are being requested by %1. The site says: &quot;%2&quot;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="370"/>
<location filename="../src/lib/network/networkmanager.cpp" line="387"/>
<source>FTP authorisation required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="383"/>
<location filename="../src/lib/network/networkmanager.cpp" line="400"/>
<source>Login anonymously</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="400"/>
<location filename="../src/lib/network/networkmanager.cpp" line="417"/>
<source>A username and password are being requested by %1:%2.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="442"/>
<location filename="../src/lib/network/networkmanager.cpp" line="459"/>
<source>Proxy authorisation required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/networkmanager.cpp" line="464"/>
<location filename="../src/lib/network/networkmanager.cpp" line="481"/>
<source>A username and password are being requested by proxy %1. </source>
<translation type="unfinished"></translation>
</message>
@ -5697,6 +5696,19 @@ After adding or removing certificate paths, it is neccessary to restart QupZilla
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SslErrorDialog</name>
<message>
<location filename="../src/lib/network/sslerrordialog.ui" line="14"/>
<source>SSL Certificate Error!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/lib/network/sslerrordialog.cpp" line="31"/>
<source>Only for this session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>TabBar</name>
<message>