2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "networkmanager.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2013-01-24 17:47:50 +01:00
|
|
|
#include "autofill.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "networkmanagerproxy.h"
|
|
|
|
#include "mainapplication.h"
|
2011-03-22 21:36:15 +01:00
|
|
|
#include "webpage.h"
|
2013-02-10 10:38:12 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-27 21:59:40 +02:00
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "adblockmanager.h"
|
2011-04-26 19:47:12 +02:00
|
|
|
#include "networkproxyfactory.h"
|
2011-10-12 22:28:41 +02:00
|
|
|
#include "certificateinfowidget.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2011-10-18 17:39:51 +02:00
|
|
|
#include "acceptlanguage.h"
|
2012-01-07 10:29:38 +01:00
|
|
|
#include "cabundleupdater.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2013-05-14 17:25:55 +02:00
|
|
|
#include "passwordmanager.h"
|
2013-09-19 20:21:46 +02:00
|
|
|
#include "sslerrordialog.h"
|
2012-08-23 11:36:36 +02:00
|
|
|
#include "schemehandlers/adblockschemehandler.h"
|
|
|
|
#include "schemehandlers/qupzillaschemehandler.h"
|
2012-08-23 16:17:56 +02:00
|
|
|
#include "schemehandlers/fileschemehandler.h"
|
2013-01-28 10:52:55 +01:00
|
|
|
#include "schemehandlers/ftpschemehandler.h"
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QNetworkDiskCache>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QSslSocket>
|
|
|
|
#include <QSslConfiguration>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QAuthenticator>
|
|
|
|
#include <QDirIterator>
|
2012-03-02 12:12:00 +01:00
|
|
|
#include <QDebug>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2013-01-22 18:12:21 +01:00
|
|
|
static QString fileNameForCert(const QSslCertificate &cert)
|
2011-12-04 16:54:57 +01:00
|
|
|
{
|
|
|
|
QString certFileName = CertificateInfoWidget::certificateItemText(cert);
|
2012-09-04 12:42:45 +02:00
|
|
|
certFileName.remove(QLatin1Char(' '));
|
|
|
|
certFileName.append(QLatin1String(".crt"));
|
2013-01-22 19:04:22 +01:00
|
|
|
certFileName = QzTools::filterCharsFromFilename(certFileName);
|
2013-01-22 18:12:21 +01:00
|
|
|
|
|
|
|
while (certFileName.startsWith(QLatin1Char('.'))) {
|
|
|
|
certFileName = certFileName.mid(1);
|
|
|
|
}
|
|
|
|
|
2011-12-04 16:54:57 +01:00
|
|
|
return certFileName;
|
|
|
|
}
|
|
|
|
|
2013-02-25 23:25:11 +01:00
|
|
|
NetworkManager::NetworkManager(QObject* parent)
|
2011-11-28 19:17:48 +01:00
|
|
|
: NetworkManagerProxy(parent)
|
2012-06-15 17:03:37 +02:00
|
|
|
, m_adblockManager(0)
|
2011-09-18 15:35:44 +02:00
|
|
|
, m_ignoreAllWarnings(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authentication(QNetworkReply*,QAuthenticator*)));
|
|
|
|
connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthentication(QNetworkProxy,QAuthenticator*)));
|
|
|
|
connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslError(QNetworkReply*,QList<QSslError>)));
|
2011-03-22 21:36:15 +01:00
|
|
|
connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(setSSLConfiguration(QNetworkReply*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-06-15 17:43:19 +02:00
|
|
|
m_schemeHandlers["qupzilla"] = new QupZillaSchemeHandler();
|
2012-06-24 23:46:32 +02:00
|
|
|
m_schemeHandlers["abp"] = new AdBlockSchemeHandler();
|
2012-08-23 16:17:56 +02:00
|
|
|
m_schemeHandlers["file"] = new FileSchemeHandler();
|
2013-01-28 10:52:55 +01:00
|
|
|
m_schemeHandlers["ftp"] = new FtpSchemeHandler();
|
2012-03-15 19:35:37 +01:00
|
|
|
|
2011-04-26 19:47:12 +02:00
|
|
|
m_proxyFactory = new NetworkProxyFactory();
|
|
|
|
setProxyFactory(m_proxyFactory);
|
2014-02-01 20:58:20 +01:00
|
|
|
|
2014-02-14 10:38:43 +01:00
|
|
|
loadSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkManager::loadSettings()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-02-10 14:50:18 +01:00
|
|
|
if (settings.value("Web-Browser-Settings/AllowLocalCache", true).toBool() && !mApp->isPrivateSession()) {
|
2012-06-15 17:43:19 +02:00
|
|
|
QNetworkDiskCache* cache = mApp->networkCache();
|
|
|
|
cache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
|
|
|
|
setCache(cache);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-07-02 01:40:32 +02:00
|
|
|
|
2014-02-13 20:46:15 +01:00
|
|
|
// Force SSLv3 for servers that doesn't understand TLSv1 handshake
|
|
|
|
QStringList sslv3Sites;
|
|
|
|
sslv3Sites << QLatin1String("centrum.sk") << QLatin1String("centrum.cz") << QLatin1String("oneaccount.com") << QLatin1String("hdi.de")
|
2014-02-14 10:53:19 +01:00
|
|
|
<< QLatin1String("live.com") << QLatin1String("i0.cz") << QLatin1String("sermepa.es");
|
2014-02-13 20:46:15 +01:00
|
|
|
|
2013-02-10 14:50:18 +01:00
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
2014-03-02 22:42:10 +01:00
|
|
|
m_doNotTrack = settings.value("DoNotTrack", true).toBool();
|
2012-01-27 23:01:17 +01:00
|
|
|
m_sendReferer = settings.value("SendReferer", true).toBool();
|
2014-02-13 20:46:15 +01:00
|
|
|
m_sslv3Sites = settings.value("SSLv3Sites", sslv3Sites).toStringList();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2014-02-13 20:46:15 +01:00
|
|
|
|
2011-10-18 17:39:51 +02:00
|
|
|
m_acceptLanguage = AcceptLanguage::generateHeader(settings.value("Language/acceptLanguage", AcceptLanguage::defaultLanguage()).toStringList());
|
2011-03-22 21:36:15 +01:00
|
|
|
|
2013-03-05 18:57:04 +01:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
|
2012-01-03 21:02:35 +01:00
|
|
|
QString certDir = mApp->PROFILEDIR + "certificates";
|
|
|
|
QString bundlePath = certDir + "/ca-bundle.crt";
|
2012-01-07 10:29:38 +01:00
|
|
|
QString bundleVersionPath = certDir + "/bundle_version";
|
2012-01-03 21:02:35 +01:00
|
|
|
|
|
|
|
if (!QDir(certDir).exists()) {
|
|
|
|
QDir dir(mApp->PROFILEDIR);
|
|
|
|
dir.mkdir("certificates");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QFile::exists(bundlePath)) {
|
|
|
|
QFile(":data/ca-bundle.crt").copy(bundlePath);
|
|
|
|
QFile(bundlePath).setPermissions(QFile::ReadUser | QFile::WriteUser);
|
2012-01-07 10:29:38 +01:00
|
|
|
|
|
|
|
QFile(":data/bundle_version").copy(bundleVersionPath);
|
|
|
|
QFile(bundleVersionPath).setPermissions(QFile::ReadUser | QFile::WriteUser);
|
2012-01-03 21:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QSslSocket::setDefaultCaCertificates(QSslCertificate::fromPath(bundlePath));
|
2013-02-24 10:52:31 +01:00
|
|
|
#else
|
|
|
|
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates());
|
|
|
|
#endif
|
2012-01-03 21:02:35 +01:00
|
|
|
|
2013-03-15 10:44:05 +01:00
|
|
|
loadCertificates();
|
|
|
|
|
2011-04-26 19:47:12 +02:00
|
|
|
m_proxyFactory->loadSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
|
2011-03-22 21:36:15 +01:00
|
|
|
{
|
2012-01-10 19:10:16 +01:00
|
|
|
if (!reply->sslConfiguration().isNull()) {
|
2011-03-22 21:36:15 +01:00
|
|
|
QSslCertificate cert = reply->sslConfiguration().peerCertificate();
|
2013-01-22 19:04:22 +01:00
|
|
|
if (!QzTools::isCertificateValid(cert) || reply->property("downReply").toBool()) {
|
2011-03-22 21:36:15 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-22 21:36:15 +01:00
|
|
|
|
|
|
|
QNetworkRequest request = reply->request();
|
|
|
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
2012-01-03 21:02:35 +01:00
|
|
|
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
2012-04-02 19:33:05 +02:00
|
|
|
if (!WebPage::isPointerSafeToUse(webPage)) {
|
2011-03-22 21:36:15 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-19 13:15:01 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
if (webPage->url().host() == reply->url().host()) {
|
2011-11-06 17:01:23 +01:00
|
|
|
webPage->setSSLCertificate(cert);
|
|
|
|
}
|
2011-03-22 21:36:15 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-19 13:15:01 +01:00
|
|
|
|
2013-06-30 12:41:01 +02:00
|
|
|
static inline uint qHash(const QSslCertificate &cert)
|
2012-07-03 15:22:42 +02:00
|
|
|
{
|
|
|
|
return qHash(cert.toPem());
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-07-03 15:22:42 +02:00
|
|
|
if (m_ignoreAllWarnings || reply->property("downReply").toBool()) {
|
2011-03-04 15:15:21 +01:00
|
|
|
reply->ignoreSslErrors(errors);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-12 09:54:36 +02:00
|
|
|
|
2012-07-03 15:22:42 +02:00
|
|
|
QNetworkRequest request = reply->request();
|
|
|
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
|
|
|
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
|
|
|
if (!WebPage::isPointerSafeToUse(webPage)) {
|
2011-11-08 15:20:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-03 15:22:42 +02:00
|
|
|
QHash<QSslCertificate, QStringList> errorHash;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QSslError &error, errors) {
|
2012-07-03 15:22:42 +02:00
|
|
|
// Weird behavior on Windows
|
|
|
|
if (error.error() == QSslError::NoError) {
|
|
|
|
continue;
|
2011-11-27 14:30:16 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QSslCertificate cert = error.certificate();
|
2012-07-03 15:22:42 +02:00
|
|
|
|
|
|
|
if (errorHash.contains(cert)) {
|
|
|
|
errorHash[cert].append(error.errorString());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errorHash.insert(cert, QStringList(error.errorString()));
|
|
|
|
}
|
2011-11-27 14:30:16 +01:00
|
|
|
}
|
|
|
|
|
2012-07-03 15:22:42 +02:00
|
|
|
// User already rejected those certs on this page
|
|
|
|
if (webPage->containsRejectedCerts(errorHash.keys())) {
|
2011-06-12 09:54:36 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-06-12 09:54:36 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QString title = tr("SSL Certificate Error!");
|
2011-11-27 16:30:38 +01:00
|
|
|
QString text1 = tr("The page you are trying to access has the following errors in the SSL certificate:");
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-27 14:30:16 +01:00
|
|
|
QString certs;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-07-03 15:22:42 +02:00
|
|
|
QHash<QSslCertificate, QStringList>::const_iterator i = errorHash.constBegin();
|
|
|
|
while (i != errorHash.constEnd()) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QSslCertificate cert = i.key();
|
|
|
|
const QStringList errors = i.value();
|
2012-07-03 15:22:42 +02:00
|
|
|
|
2013-09-19 20:21:46 +02:00
|
|
|
if (m_localCerts.contains(cert) || m_tempAllowedCerts.contains(cert) || errors.isEmpty()) {
|
2012-07-03 15:22:42 +02:00
|
|
|
++i;
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-30 12:01:12 +02:00
|
|
|
certs += "<ul><li>";
|
|
|
|
certs += tr("<b>Organization: </b>") + CertificateInfoWidget::clearCertSpecialSymbols(cert.subjectInfo(QSslCertificate::Organization));
|
|
|
|
certs += "</li><li>";
|
|
|
|
certs += tr("<b>Domain Name: </b>") + CertificateInfoWidget::clearCertSpecialSymbols(cert.subjectInfo(QSslCertificate::CommonName));
|
|
|
|
certs += "</li><li>";
|
|
|
|
certs += tr("<b>Expiration Date: </b>") + cert.expiryDate().toString("hh:mm:ss dddd d. MMMM yyyy");
|
|
|
|
certs += "</li></ul>";
|
2012-07-03 15:22:42 +02:00
|
|
|
|
|
|
|
certs += "<ul>";
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &error, errors) {
|
2012-07-03 15:22:42 +02:00
|
|
|
certs += "<li>";
|
|
|
|
certs += tr("<b>Error: </b>") + error;
|
|
|
|
certs += "</li>";
|
|
|
|
}
|
|
|
|
certs += "</ul>";
|
|
|
|
|
|
|
|
++i;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-27 16:30:38 +01:00
|
|
|
QString text2 = tr("Would you like to make an exception for this certificate?");
|
2011-11-27 15:43:54 +01:00
|
|
|
QString message = QString("<b>%1</b><p>%2</p>%3<p>%4</p>").arg(title, text1, certs, text2);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-27 14:30:16 +01:00
|
|
|
if (!certs.isEmpty()) {
|
2013-09-19 20:21:46 +02:00
|
|
|
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:
|
2012-07-03 15:22:42 +02:00
|
|
|
// To prevent asking user more than once for the same certificate
|
|
|
|
webPage->addRejectedCerts(errorHash.keys());
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
reply->ignoreSslErrors(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
|
|
|
{
|
2013-02-25 23:25:11 +01:00
|
|
|
QDialog* dialog = new QDialog();
|
2013-02-09 19:49:02 +01:00
|
|
|
dialog->setWindowTitle(tr("Authorisation required"));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QFormLayout* formLa = new QFormLayout(dialog);
|
|
|
|
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLabel* userLab = new QLabel(dialog);
|
|
|
|
QLabel* passLab = new QLabel(dialog);
|
|
|
|
userLab->setText(tr("Username: "));
|
|
|
|
passLab->setText(tr("Password: "));
|
|
|
|
|
|
|
|
QLineEdit* user = new QLineEdit(dialog);
|
|
|
|
QLineEdit* pass = new QLineEdit(dialog);
|
|
|
|
QCheckBox* save = new QCheckBox(dialog);
|
|
|
|
save->setText(tr("Save username and password on this site"));
|
|
|
|
pass->setEchoMode(QLineEdit::Password);
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
|
|
|
label->setText(tr("A username and password are being requested by %1. "
|
2013-03-16 15:44:06 +01:00
|
|
|
"The site says: \"%2\"").arg(reply->url().host(), QzTools::escape(auth->realm())));
|
2011-03-02 16:57:41 +01:00
|
|
|
formLa->addRow(label);
|
|
|
|
|
|
|
|
formLa->addRow(userLab, user);
|
|
|
|
formLa->addRow(passLab, pass);
|
|
|
|
formLa->addRow(save);
|
|
|
|
|
|
|
|
formLa->addWidget(box);
|
2013-02-04 12:11:27 +01:00
|
|
|
bool shouldUpdateEntry = false;
|
2013-02-08 13:02:53 +01:00
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
AutoFill* fill = mApp->autoFill();
|
2013-02-04 12:11:27 +01:00
|
|
|
QString storedUser;
|
|
|
|
QString storedPassword;
|
2011-03-02 16:57:41 +01:00
|
|
|
if (fill->isStored(reply->url())) {
|
2013-05-14 17:25:55 +02:00
|
|
|
const QVector<PasswordEntry> &data = fill->getFormData(reply->url());
|
2013-02-08 15:07:56 +01:00
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
if (!data.isEmpty()) {
|
2013-02-08 15:07:56 +01:00
|
|
|
save->setChecked(true);
|
|
|
|
shouldUpdateEntry = true;
|
2013-05-14 17:25:55 +02:00
|
|
|
storedUser = data.first().username;
|
|
|
|
storedPassword = data.first().password;
|
2013-02-08 15:07:56 +01:00
|
|
|
user->setText(storedUser);
|
|
|
|
pass->setText(storedPassword);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-10 10:38:12 +01:00
|
|
|
// Try to set the originating WebTab as a current tab
|
|
|
|
QWebFrame* frame = qobject_cast<QWebFrame*>(reply->request().originatingObject());
|
|
|
|
if (frame) {
|
|
|
|
WebPage* page = qobject_cast<WebPage*>(frame->page());
|
|
|
|
if (page) {
|
|
|
|
TabbedWebView* view = qobject_cast<TabbedWebView*>(page->view());
|
|
|
|
if (view) {
|
|
|
|
view->setAsCurrentTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not save when private browsing is enabled
|
2012-06-26 11:49:39 +02:00
|
|
|
if (mApp->isPrivateSession()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
save->setVisible(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-01 17:01:08 +01:00
|
|
|
if (dialog->exec() != QDialog::Accepted) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-01 17:01:08 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
auth->setUser(user->text());
|
|
|
|
auth->setPassword(pass->text());
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (save->isChecked()) {
|
2013-02-04 12:11:27 +01:00
|
|
|
if (shouldUpdateEntry) {
|
|
|
|
if (storedUser != user->text() || storedPassword != pass->text()) {
|
|
|
|
fill->updateEntry(reply->url(), user->text(), pass->text());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill->addEntry(reply->url(), user->text(), pass->text());
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 10:52:55 +01:00
|
|
|
void NetworkManager::ftpAuthentication(const QUrl &url, QAuthenticator* auth)
|
|
|
|
{
|
|
|
|
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
|
|
|
FtpDownloader* ftp = 0;
|
|
|
|
if (!reply) {
|
|
|
|
ftp = qobject_cast<FtpDownloader*>(sender());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!auth) {
|
|
|
|
auth = FTP_AUTHENTICATOR(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString lastUser = auth->user();
|
|
|
|
QString lastPass = auth->password();
|
|
|
|
|
|
|
|
if (lastUser.isEmpty() && lastPass.isEmpty()) {
|
|
|
|
// The auth is empty but url contains user's info
|
|
|
|
lastUser = url.userName();
|
|
|
|
lastPass = url.password();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog* dialog = new QDialog(mApp->getWindow());
|
2013-02-09 19:49:02 +01:00
|
|
|
dialog->setWindowTitle(tr("FTP authorisation required"));
|
2013-01-28 10:52:55 +01:00
|
|
|
|
|
|
|
QFormLayout* formLa = new QFormLayout(dialog);
|
|
|
|
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLabel* userLab = new QLabel(dialog);
|
|
|
|
QLabel* passLab = new QLabel(dialog);
|
|
|
|
userLab->setText(tr("Username: "));
|
|
|
|
passLab->setText(tr("Password: "));
|
|
|
|
|
|
|
|
QCheckBox* anonymousLogin = new QCheckBox(dialog);
|
|
|
|
QLineEdit* user = new QLineEdit(lastUser, dialog);
|
|
|
|
QLineEdit* pass = new QLineEdit(lastPass, dialog);
|
|
|
|
anonymousLogin->setText(tr("Login anonymously"));
|
|
|
|
connect(anonymousLogin, SIGNAL(toggled(bool)), user, SLOT(setDisabled(bool)));
|
|
|
|
connect(anonymousLogin, SIGNAL(toggled(bool)), pass, SLOT(setDisabled(bool)));
|
|
|
|
anonymousLogin->setChecked(lastUser.isEmpty() && lastPass.isEmpty());
|
|
|
|
pass->setEchoMode(QLineEdit::Password);
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
|
|
|
int port = 21;
|
|
|
|
if (url.port() != -1) {
|
|
|
|
port = url.port();
|
|
|
|
}
|
|
|
|
|
|
|
|
label->setText(tr("A username and password are being requested by %1:%2.")
|
|
|
|
.arg(url.host(), QString::number(port)));
|
|
|
|
|
|
|
|
formLa->addRow(label);
|
|
|
|
|
|
|
|
formLa->addRow(anonymousLogin);
|
|
|
|
formLa->addRow(userLab, user);
|
|
|
|
formLa->addRow(passLab, pass);
|
|
|
|
|
|
|
|
formLa->addWidget(box);
|
|
|
|
|
|
|
|
if (dialog->exec() != QDialog::Accepted) {
|
|
|
|
if (reply) {
|
|
|
|
reply->abort();
|
|
|
|
// is it safe?
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
|
|
|
else if (ftp) {
|
|
|
|
ftp->abort();
|
|
|
|
ftp->close();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!anonymousLogin->isChecked()) {
|
|
|
|
auth->setUser(user->text());
|
|
|
|
auth->setPassword(pass->text());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
auth->setUser(QString());
|
|
|
|
auth->setPassword(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator* auth)
|
2011-04-26 19:47:12 +02:00
|
|
|
{
|
2013-09-10 15:45:51 +02:00
|
|
|
QString userName;
|
|
|
|
QString password;
|
|
|
|
QVector<PasswordEntry> psws = mApp->autoFill()->getFormData(QUrl(proxy.hostName()));
|
2013-09-03 16:39:07 +02:00
|
|
|
|
2013-09-10 15:45:51 +02:00
|
|
|
if (psws.isEmpty()) {
|
2013-09-03 16:39:07 +02:00
|
|
|
QDialog* dialog = new QDialog();
|
|
|
|
dialog->setWindowTitle(tr("Proxy authorisation required"));
|
|
|
|
|
|
|
|
QFormLayout* formLa = new QFormLayout(dialog);
|
|
|
|
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLabel* userLab = new QLabel(dialog);
|
|
|
|
QLabel* passLab = new QLabel(dialog);
|
|
|
|
userLab->setText(tr("Username: "));
|
|
|
|
passLab->setText(tr("Password: "));
|
|
|
|
|
|
|
|
QLineEdit* user = new QLineEdit(dialog);
|
|
|
|
QLineEdit* pass = new QLineEdit(dialog);
|
|
|
|
pass->setEchoMode(QLineEdit::Password);
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
2013-11-09 19:54:39 +01:00
|
|
|
QCheckBox* rememberCheck = new QCheckBox(tr("Remember username and password for this proxy."), dialog);
|
2013-09-03 16:39:07 +02:00
|
|
|
|
|
|
|
label->setText(tr("A username and password are being requested by proxy %1. ").arg(proxy.hostName()));
|
|
|
|
formLa->addRow(label);
|
|
|
|
formLa->addRow(userLab, user);
|
|
|
|
formLa->addRow(passLab, pass);
|
|
|
|
formLa->addRow(rememberCheck);
|
|
|
|
formLa->addWidget(box);
|
|
|
|
|
|
|
|
if (dialog->exec() != QDialog::Accepted) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-26 19:47:12 +02:00
|
|
|
|
2013-09-10 15:45:51 +02:00
|
|
|
if (rememberCheck->isChecked()) {
|
|
|
|
mApp->autoFill()->addEntry(QUrl(proxy.hostName()), user->text(), pass->text());
|
2013-09-03 16:39:07 +02:00
|
|
|
}
|
2011-04-26 19:47:12 +02:00
|
|
|
|
2013-09-03 16:39:07 +02:00
|
|
|
userName = user->text();
|
|
|
|
password = pass->text();
|
|
|
|
}
|
2013-09-10 15:45:51 +02:00
|
|
|
else {
|
2013-09-03 16:39:07 +02:00
|
|
|
userName = psws.at(0).username;
|
|
|
|
password = psws.at(0).password;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-01 17:01:08 +01:00
|
|
|
|
2013-09-03 16:39:07 +02:00
|
|
|
auth->setUser(userName);
|
|
|
|
auth->setPassword(password);
|
2011-04-26 19:47:12 +02:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (op == PostOperation && outgoingData) {
|
2011-11-06 17:01:23 +01:00
|
|
|
QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024);
|
|
|
|
mApp->autoFill()->post(request, outgoingDataByteArray);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkRequest req = request;
|
2011-09-18 15:35:44 +02:00
|
|
|
QNetworkReply* reply = 0;
|
2011-04-26 19:47:12 +02:00
|
|
|
|
2012-07-08 00:15:03 +02:00
|
|
|
// SchemeHandlers
|
2012-03-15 19:35:37 +01:00
|
|
|
if (m_schemeHandlers.contains(req.url().scheme())) {
|
|
|
|
reply = m_schemeHandlers[req.url().scheme()]->createRequest(op, req, outgoingData);
|
|
|
|
if (reply) {
|
2013-01-28 10:52:55 +01:00
|
|
|
if (req.url().scheme() == "ftp") {
|
|
|
|
QVariant v = req.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
|
|
|
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
|
|
|
if (webPage) {
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(reply, SIGNAL(downloadRequest(QNetworkRequest)),
|
|
|
|
webPage, SLOT(downloadRequested(QNetworkRequest)));
|
2013-01-28 10:52:55 +01:00
|
|
|
}
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(reply, SIGNAL(ftpAuthenticationRequierd(QUrl,QAuthenticator*)),
|
|
|
|
this, SLOT(ftpAuthentication(QUrl,QAuthenticator*)));
|
2013-01-28 10:52:55 +01:00
|
|
|
}
|
2012-03-15 19:35:37 +01:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-08 00:15:03 +02:00
|
|
|
// Plugins
|
|
|
|
reply = mApp->plugins()->createRequest(op, request, outgoingData);
|
|
|
|
if (reply) {
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2012-07-13 11:04:14 +02:00
|
|
|
if (req.rawHeader("X-QupZilla-UserLoadAction") == QByteArray("1")) {
|
|
|
|
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray());
|
|
|
|
req.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), QString());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
req.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), req.rawHeader("Referer"));
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_doNotTrack) {
|
2012-03-04 22:30:45 +01:00
|
|
|
req.setRawHeader("DNT", QByteArray("1"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-19 13:15:01 +01:00
|
|
|
|
2012-01-27 23:01:17 +01:00
|
|
|
if (!m_sendReferer) {
|
2012-03-04 21:59:56 +01:00
|
|
|
req.setRawHeader("Referer", QByteArray());
|
2012-01-27 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 17:39:51 +02:00
|
|
|
req.setRawHeader("Accept-Language", m_acceptLanguage);
|
|
|
|
|
2013-03-30 21:52:59 +01:00
|
|
|
// #830: Disabling HttpPipeling fixes issue with loading HTML5 videos on YouTube
|
|
|
|
//req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2011-03-27 21:59:40 +02:00
|
|
|
// Adblock
|
2011-03-29 20:30:05 +02:00
|
|
|
if (op == QNetworkAccessManager::GetOperation) {
|
2012-06-15 17:03:37 +02:00
|
|
|
if (!m_adblockManager) {
|
|
|
|
m_adblockManager = AdBlockManager::instance();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-06-15 17:03:37 +02:00
|
|
|
reply = m_adblockManager->block(req);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (reply) {
|
2011-03-29 20:30:05 +02:00
|
|
|
return reply;
|
2014-02-01 20:58:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force SSLv3 for servers that doesn't understand TLSv1 handshake
|
|
|
|
if (req.url().scheme() == QLatin1String("https")) {
|
|
|
|
foreach (const QString &host, m_sslv3Sites) {
|
2014-02-01 21:07:42 +01:00
|
|
|
if (QzTools::matchDomain(host, req.url().host())) {
|
2014-02-01 20:58:20 +01:00
|
|
|
QSslConfiguration conf = req.sslConfiguration();
|
|
|
|
conf.setProtocol(QSsl::SslV3);
|
|
|
|
req.setSslConfiguration(conf);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-29 20:30:05 +02:00
|
|
|
}
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2013-03-30 21:52:59 +01:00
|
|
|
return QNetworkAccessManager::createRequest(op, req, outgoingData);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
void NetworkManager::removeLocalCertificate(const QSslCertificate &cert)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-10-12 22:28:41 +02:00
|
|
|
m_localCerts.removeOne(cert);
|
2012-07-03 15:22:42 +02:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
QList<QSslCertificate> certs = QSslSocket::defaultCaCertificates();
|
|
|
|
certs.removeOne(cert);
|
|
|
|
QSslSocket::setDefaultCaCertificates(certs);
|
|
|
|
|
2012-07-03 15:22:42 +02:00
|
|
|
// Delete cert file from profile
|
2011-12-04 16:54:57 +01:00
|
|
|
bool deleted = false;
|
2012-04-04 18:48:54 +02:00
|
|
|
QDirIterator it(mApp->currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
2011-10-12 22:28:41 +02:00
|
|
|
while (it.hasNext()) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString filePath = it.next();
|
2012-03-28 16:42:50 +02:00
|
|
|
const QList<QSslCertificate> &certs = QSslCertificate::fromPath(filePath);
|
|
|
|
if (certs.isEmpty()) {
|
2011-10-12 22:28:41 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QSslCertificate cert_ = certs.at(0);
|
2012-03-28 16:42:50 +02:00
|
|
|
if (cert == cert_) {
|
|
|
|
QFile file(filePath);
|
|
|
|
if (!file.remove()) {
|
|
|
|
qWarning() << "NetworkManager::removeLocalCertificate cannot remove file" << filePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleted = true;
|
|
|
|
break;
|
2011-12-04 16:54:57 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-12-04 16:54:57 +01:00
|
|
|
|
|
|
|
if (!deleted) {
|
2012-03-28 19:43:59 +02:00
|
|
|
qWarning() << "NetworkManager::removeLocalCertificate cannot remove certificate";
|
2011-12-04 16:54:57 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
void NetworkManager::addLocalCertificate(const QSslCertificate &cert)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-27 14:30:16 +01:00
|
|
|
// if (!cert.isValid()) {
|
|
|
|
// return;
|
|
|
|
// }
|
2011-10-12 22:28:41 +02:00
|
|
|
|
|
|
|
m_localCerts.append(cert);
|
|
|
|
QSslSocket::addDefaultCaCertificate(cert);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-04 18:48:54 +02:00
|
|
|
QDir dir(mApp->currentProfilePath());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!dir.exists("certificates")) {
|
2011-10-12 22:28:41 +02:00
|
|
|
dir.mkdir("certificates");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-04 16:54:57 +01:00
|
|
|
QString certFileName = fileNameForCert(cert);
|
2013-01-22 19:04:22 +01:00
|
|
|
QString fileName = QzTools::ensureUniqueFilename(mApp->currentProfilePath() + "certificates/" + certFileName);
|
2011-11-27 19:57:04 +01:00
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
QFile file(fileName);
|
|
|
|
if (file.open(QFile::WriteOnly)) {
|
|
|
|
file.write(cert.toPem());
|
|
|
|
file.close();
|
2011-11-27 15:43:54 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
qWarning() << "NetworkManager::addLocalCertificate cannot write to file: " << fileName;
|
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
|
|
|
|
2013-05-22 14:59:42 +02:00
|
|
|
void NetworkManager::setIgnoreAllWarnings(bool state)
|
|
|
|
{
|
|
|
|
m_ignoreAllWarnings = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkManager::isIgnoringAllWarnings()
|
|
|
|
{
|
|
|
|
return m_ignoreAllWarnings;
|
|
|
|
}
|
|
|
|
|
2013-03-29 19:22:55 +01:00
|
|
|
NetworkProxyFactory* NetworkManager::proxyFactory() const
|
|
|
|
{
|
|
|
|
return m_proxyFactory;
|
|
|
|
}
|
|
|
|
|
2012-03-15 19:35:37 +01:00
|
|
|
bool NetworkManager::registerSchemeHandler(const QString &scheme, SchemeHandler* handler)
|
|
|
|
{
|
|
|
|
if (m_schemeHandlers.contains(scheme)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_schemeHandlers[scheme] = handler;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-12 18:05:45 +02:00
|
|
|
bool NetworkManager::unregisterSchemeHandler(const QString &scheme, SchemeHandler* handler)
|
|
|
|
{
|
|
|
|
if (!m_schemeHandlers.contains(scheme) || m_schemeHandlers[scheme] != handler) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_schemeHandlers.remove(scheme) == 1;
|
|
|
|
}
|
|
|
|
|
2014-02-13 20:46:15 +01:00
|
|
|
void NetworkManager::saveSettings()
|
2011-10-12 22:28:41 +02:00
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-10-12 22:28:41 +02:00
|
|
|
settings.beginGroup("SSL-Configuration");
|
|
|
|
settings.setValue("CACertPaths", m_certPaths);
|
|
|
|
settings.setValue("IgnoreAllSSLWarnings", m_ignoreAllWarnings);
|
|
|
|
settings.endGroup();
|
2014-02-13 20:46:15 +01:00
|
|
|
|
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
|
|
|
settings.setValue("SSLv3Sites", m_sslv3Sites);
|
|
|
|
settings.endGroup();
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkManager::loadCertificates()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-10-12 22:28:41 +02:00
|
|
|
settings.beginGroup("SSL-Configuration");
|
|
|
|
m_certPaths = settings.value("CACertPaths", QStringList()).toStringList();
|
|
|
|
m_ignoreAllWarnings = settings.value("IgnoreAllSSLWarnings", false).toBool();
|
|
|
|
settings.endGroup();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-03-15 10:44:05 +01:00
|
|
|
// CA Certificates
|
2011-10-12 22:28:41 +02:00
|
|
|
m_caCerts = QSslSocket::defaultCaCertificates();
|
2013-03-15 10:44:05 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &path, m_certPaths) {
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2011-10-12 22:28:41 +02:00
|
|
|
// Used from Qt 4.7.4 qsslcertificate.cpp and modified because QSslCertificate::fromPath
|
|
|
|
// is kind of a bugged on Windows, it does work only with full path to cert file
|
|
|
|
QDirIterator it(path, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
2012-03-28 16:42:50 +02:00
|
|
|
QString filePath = it.next();
|
2012-09-04 12:42:45 +02:00
|
|
|
if (!filePath.endsWith(QLatin1String(".crt"))) {
|
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
|
|
|
|
|
|
|
QFile file(filePath);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2011-10-12 22:28:41 +02:00
|
|
|
m_caCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
m_caCerts += QSslCertificate::fromPath(path + "/*.crt", QSsl::Pem, QRegExp::Wildcard);
|
|
|
|
#endif
|
|
|
|
}
|
2013-03-15 10:44:05 +01:00
|
|
|
// Local Certificates
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2012-04-05 11:44:01 +02:00
|
|
|
QDirIterator it_(mApp->currentProfilePath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
2011-11-06 17:01:23 +01:00
|
|
|
while (it_.hasNext()) {
|
2012-03-28 16:42:50 +02:00
|
|
|
QString filePath = it_.next();
|
2012-09-04 12:42:45 +02:00
|
|
|
if (!filePath.endsWith(QLatin1String(".crt"))) {
|
2011-11-06 17:01:23 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QFile file(filePath);
|
|
|
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
m_localCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem);
|
2011-10-12 22:28:41 +02:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-12 22:28:41 +02:00
|
|
|
#else
|
2013-03-15 10:44:05 +01:00
|
|
|
m_localCerts = QSslCertificate::fromPath(mApp->currentProfilePath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
|
2011-10-12 22:28:41 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts);
|
2012-01-07 10:29:38 +01:00
|
|
|
|
2013-03-05 18:57:04 +01:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
|
2012-01-07 10:29:38 +01:00
|
|
|
new CaBundleUpdater(this, this);
|
2013-02-24 10:52:31 +01:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-15 17:50:09 +01:00
|
|
|
|
|
|
|
void NetworkManager::disconnectObjects()
|
|
|
|
{
|
|
|
|
disconnect(this);
|
|
|
|
}
|