diff --git a/src/lib/lib.pro b/src/lib/lib.pro index c05f563a4..42c6b3ae0 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -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 \ diff --git a/src/lib/network/networkmanager.cpp b/src/lib/network/networkmanager.cpp index 84b4d0bdc..85fb9771d 100644 --- a/src/lib/network/networkmanager.cpp +++ b/src/lib/network/networkmanager.cpp @@ -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 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 errors) QString message = QString("%1

%2

%3

%4

").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); diff --git a/src/lib/network/networkmanager.h b/src/lib/network/networkmanager.h index 0b31b10fd..4f12853fb 100644 --- a/src/lib/network/networkmanager.h +++ b/src/lib/network/networkmanager.h @@ -76,7 +76,7 @@ private: QStringList m_certPaths; QList m_caCerts; QList m_localCerts; - QList m_ignoredCerts; + QList m_tempAllowedCerts; QHash m_schemeHandlers; QByteArray m_acceptLanguage; diff --git a/src/lib/network/sslerrordialog.cpp b/src/lib/network/sslerrordialog.cpp new file mode 100644 index 000000000..9077f2215 --- /dev/null +++ b/src/lib/network/sslerrordialog.cpp @@ -0,0 +1,70 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2013 David Rosca +* +* 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 . +* ============================================================ */ +#include "sslerrordialog.h" +#include "ui_sslerrordialog.h" +#include "iconprovider.h" + +#include + +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; + } +} diff --git a/src/lib/network/sslerrordialog.h b/src/lib/network/sslerrordialog.h new file mode 100644 index 000000000..6cb00f9d0 --- /dev/null +++ b/src/lib/network/sslerrordialog.h @@ -0,0 +1,54 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2013 David Rosca +* +* 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 . +* ============================================================ */ +#ifndef SSLERRORDIALOG_H +#define SSLERRORDIALOG_H + +#include + +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 diff --git a/src/lib/network/sslerrordialog.ui b/src/lib/network/sslerrordialog.ui new file mode 100644 index 000000000..a0ccaf7eb --- /dev/null +++ b/src/lib/network/sslerrordialog.ui @@ -0,0 +1,87 @@ + + + SslErrorDialog + + + + 0 + 0 + 511 + 72 + + + + SSL Certificate Error! + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::No|QDialogButtonBox::Yes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/translations/empty.ts b/translations/empty.ts index 4421387d7..8f57a2a36 100644 --- a/translations/empty.ts +++ b/translations/empty.ts @@ -2445,92 +2445,91 @@ Please install latest version of QupZilla. NetworkManager - - + SSL Certificate Error! - + The page you are trying to access has the following errors in the SSL certificate: - + <b>Organization: </b> - + <b>Domain Name: </b> - + <b>Expiration Date: </b> - + <b>Error: </b> - + Would you like to make an exception for this certificate? - + Authorisation required - - - + + + Username: - - - + + + Password: - + Save username and password on this site - + A username and password are being requested by %1. The site says: "%2" - + FTP authorisation required - + Login anonymously - + A username and password are being requested by %1:%2. - + Proxy authorisation required - + A username and password are being requested by proxy %1. @@ -5697,6 +5696,19 @@ After adding or removing certificate paths, it is neccessary to restart QupZilla + + SslErrorDialog + + + SSL Certificate Error! + + + + + Only for this session + + + TabBar