2011-03-03 18:29:20 +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-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"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "autofillmodel.h"
|
|
|
|
#include "networkmanagerproxy.h"
|
|
|
|
#include "mainapplication.h"
|
2011-03-22 21:36:15 +01:00
|
|
|
#include "webpage.h"
|
2011-03-27 21:59:40 +02:00
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "adblockmanager.h"
|
|
|
|
#include "adblocknetwork.h"
|
2011-04-26 19:47:12 +02:00
|
|
|
#include "networkproxyfactory.h"
|
2011-09-18 15:35:44 +02:00
|
|
|
#include "qupzillaschemehandler.h"
|
2011-10-12 22:28:41 +02:00
|
|
|
#include "certificateinfowidget.h"
|
|
|
|
#include "globalfunctions.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"
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2011-12-04 16:54:57 +01:00
|
|
|
QString fileNameForCert(const QSslCertificate &cert)
|
|
|
|
{
|
|
|
|
QString certFileName = CertificateInfoWidget::certificateItemText(cert);
|
|
|
|
certFileName.remove(" ");
|
|
|
|
certFileName.append(".crt");
|
|
|
|
certFileName = qz_filterCharsFromFilename(certFileName);
|
|
|
|
return certFileName;
|
|
|
|
}
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent)
|
2011-11-28 19:17:48 +01:00
|
|
|
: NetworkManagerProxy(parent)
|
2011-09-18 15:35:44 +02:00
|
|
|
, m_adblockNetwork(0)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_qupzillaSchemeHandler(new QupZillaSchemeHandler)
|
|
|
|
, m_ignoreAllWarnings(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +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
|
|
|
|
2011-04-26 19:47:12 +02:00
|
|
|
m_proxyFactory = new NetworkProxyFactory();
|
|
|
|
setProxyFactory(m_proxyFactory);
|
2011-03-02 16:57:41 +01:00
|
|
|
loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkManager::loadSettings()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
|
|
|
|
|
|
|
if (settings.value("AllowLocalCache", true).toBool()) {
|
2011-03-23 22:36:03 +01:00
|
|
|
m_diskCache = mApp->networkCache();
|
2011-11-06 17:01:23 +01:00
|
|
|
m_diskCache->setCacheDirectory(mApp->getActiveProfilPath() + "/networkcache");
|
|
|
|
m_diskCache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
|
2011-03-02 16:57:41 +01:00
|
|
|
setCache(m_diskCache);
|
|
|
|
}
|
2011-04-05 20:56:55 +02:00
|
|
|
m_doNotTrack = settings.value("DoNotTrack", false).toBool();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
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
|
|
|
|
2011-10-17 13:43:51 +02:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
// From doc:
|
|
|
|
// QSslSocket::VerifyNone ... The connection will still be encrypted, and your socket
|
|
|
|
// will still send its local certificate to the peer if it's requested.
|
|
|
|
|
2011-03-22 21:36:15 +01:00
|
|
|
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
|
2011-10-17 13:43:51 +02:00
|
|
|
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
2011-03-22 21:36:15 +01:00
|
|
|
QSslConfiguration::setDefaultConfiguration(config);
|
2011-10-17 13:43:51 +02:00
|
|
|
#endif
|
2011-03-22 21:36:15 +01:00
|
|
|
|
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));
|
|
|
|
|
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();
|
2011-11-09 16:58:25 +01:00
|
|
|
if (!cert.isValid() || 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-01-21 20:27:45 +01:00
|
|
|
if (!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
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-03-04 15:15:21 +01:00
|
|
|
if (m_ignoreAllWarnings) {
|
|
|
|
reply->ignoreSslErrors(errors);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-12 09:54:36 +02:00
|
|
|
|
2011-11-08 15:20:53 +01:00
|
|
|
if (reply->property("downReply").toBool()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-27 14:30:16 +01:00
|
|
|
int errorsIgnored = 0;
|
|
|
|
foreach(QSslError error, errors) {
|
|
|
|
if (m_ignoredCerts.contains(error.certificate())) {
|
|
|
|
++errorsIgnored;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errorsIgnored == errors.count()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-12 09:54:36 +02: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*>());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!webPage) {
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QSslError error, errors) {
|
|
|
|
if (m_localCerts.contains(error.certificate())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (error.error() == QSslError::NoError) { //Weird behavior on Windows
|
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
|
|
|
|
|
|
|
QSslCertificate cert = error.certificate();
|
2011-11-27 14:30:16 +01:00
|
|
|
certs.append("<ul><li>");
|
|
|
|
certs.append(tr("<b>Organization: </b>") + CertificateInfoWidget::clearCertSpecialSymbols(cert.subjectInfo(QSslCertificate::Organization)));
|
|
|
|
certs.append("</li><li>");
|
|
|
|
certs.append(tr("<b>Domain Name: </b>") + CertificateInfoWidget::clearCertSpecialSymbols(cert.subjectInfo(QSslCertificate::CommonName)));
|
|
|
|
certs.append("</li><li>");
|
|
|
|
certs.append(tr("<b>Expiration Date: </b>") + cert.expiryDate().toString("hh:mm:ss dddd d. MMMM yyyy"));
|
|
|
|
certs.append("</li><li>");
|
|
|
|
certs.append(tr("<b>Error: </b>") + error.errorString());
|
|
|
|
certs.append("</li></ul>");
|
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()) {
|
2012-01-21 20:27:45 +01:00
|
|
|
if (QMessageBox::critical(webPage->view(), tr("SSL Certificate Error!"), message,
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) {
|
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
|
|
|
|
2011-11-27 14:30:16 +01:00
|
|
|
foreach(QSslError error, errors) {
|
|
|
|
if (!m_localCerts.contains(error.certificate())) {
|
|
|
|
addLocalCertificate(error.certificate());
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
QDialog* dialog = new QDialog(p_QupZilla);
|
|
|
|
dialog->setWindowTitle(tr("Authorization 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);
|
|
|
|
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. "
|
2011-11-05 18:36:53 +01:00
|
|
|
"The site says: \"%2\"").arg(reply->url().toEncoded(), Qt::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);
|
2011-03-04 13:59:07 +01:00
|
|
|
AutoFillModel* fill = mApp->autoFill();
|
2011-03-02 16:57:41 +01:00
|
|
|
if (fill->isStored(reply->url())) {
|
|
|
|
save->setChecked(true);
|
|
|
|
user->setText(fill->getUsername(reply->url()));
|
|
|
|
pass->setText(fill->getPassword(reply->url()));
|
|
|
|
}
|
|
|
|
emit wantsFocus(reply->url());
|
|
|
|
|
|
|
|
//Do not save when private browsing is enabled
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!dialog->exec() == QDialog::Accepted) {
|
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
|
|
|
auth->setUser(user->text());
|
|
|
|
auth->setPassword(pass->text());
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (save->isChecked()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
fill->addEntry(reply->url(), user->text(), pass->text());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator* auth)
|
2011-04-26 19:47:12 +02:00
|
|
|
{
|
|
|
|
QDialog* dialog = new QDialog(p_QupZilla);
|
|
|
|
dialog->setWindowTitle(tr("Proxy authorization 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()));
|
|
|
|
|
|
|
|
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->addWidget(box);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!dialog->exec() == QDialog::Accepted) {
|
2011-04-26 19:47:12 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-26 19:47:12 +02:00
|
|
|
auth->setUser(user->text());
|
|
|
|
auth->setPassword(pass->text());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_doNotTrack) {
|
2011-04-05 20:56:55 +02:00
|
|
|
req.setRawHeader("DNT", "1");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-19 13:15:01 +01:00
|
|
|
|
2011-10-18 17:39:51 +02:00
|
|
|
req.setRawHeader("Accept-Language", m_acceptLanguage);
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
//SchemeHandlers
|
2011-11-06 17:01:23 +01:00
|
|
|
if (req.url().scheme() == "qupzilla") {
|
2011-09-18 15:35:44 +02:00
|
|
|
reply = m_qupzillaSchemeHandler->createRequest(op, req, outgoingData);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (reply) {
|
2011-09-18 15:35:44 +02:00
|
|
|
return reply;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) {
|
2011-09-18 15:35:44 +02:00
|
|
|
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
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) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_adblockNetwork) {
|
2011-03-29 20:30:05 +02:00
|
|
|
m_adblockNetwork = AdBlockManager::instance()->network();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
reply = m_adblockNetwork->block(req);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (reply) {
|
2011-03-29 20:30:05 +02:00
|
|
|
return reply;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-29 20:30:05 +02:00
|
|
|
}
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
|
2011-03-02 16:57:41 +01:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
QList<QSslCertificate> certs = QSslSocket::defaultCaCertificates();
|
|
|
|
certs.removeOne(cert);
|
|
|
|
QSslSocket::setDefaultCaCertificates(certs);
|
|
|
|
|
|
|
|
//Delete cert file from profile
|
2011-12-04 16:54:57 +01:00
|
|
|
bool deleted = false;
|
|
|
|
QString certFileName = fileNameForCert(cert);
|
2011-10-12 22:28:41 +02:00
|
|
|
int startIndex = 0;
|
|
|
|
QDirIterator it(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!filePath.contains(certFileName)) {
|
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
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
QFile file(filePath);
|
2011-12-04 16:54:57 +01:00
|
|
|
if (!file.remove()) {
|
|
|
|
qWarning() << "NetworkManager::removeLocalCertificate cannot remove file" << filePath;
|
|
|
|
}
|
|
|
|
deleted = true;
|
2011-10-12 22:28:41 +02:00
|
|
|
break;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-12-04 16:54:57 +01:00
|
|
|
|
|
|
|
if (!deleted) {
|
|
|
|
qWarning() << "NetworkManager::removeLocalCertificate cannot find file" << certFileName;
|
|
|
|
}
|
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
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
QDir dir(mApp->getActiveProfilPath());
|
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);
|
2011-11-27 19:57:04 +01:00
|
|
|
QString fileName = qz_ensureUniqueFilename(mApp->getActiveProfilPath() + "certificates/" + certFileName);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkManager::saveCertificates()
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-10-12 22:28:41 +02:00
|
|
|
//CA Certificates
|
|
|
|
m_caCerts = QSslSocket::defaultCaCertificates();
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QString path, m_certPaths) {
|
2011-10-12 22:28:41 +02:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
// 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
|
|
|
|
int startIndex = 0;
|
|
|
|
QDirIterator it(path, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!filePath.endsWith(".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
|
|
|
|
}
|
|
|
|
//Local Certificates
|
|
|
|
#ifdef Q_WS_WIN
|
2011-11-06 17:01:23 +01:00
|
|
|
int startIndex = 0;
|
|
|
|
QDirIterator it_(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
|
|
|
while (it_.hasNext()) {
|
|
|
|
QString filePath = startIndex == 0 ? it_.next() : it_.next().mid(startIndex);
|
|
|
|
if (!filePath.endsWith(".crt")) {
|
|
|
|
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
|
2011-11-06 17:01:23 +01:00
|
|
|
m_localCerts += QSslCertificate::fromPath(mApp->getActiveProfilPath() + "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
|
|
|
|
|
|
|
new CaBundleUpdater(this, this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-15 17:50:09 +01:00
|
|
|
|
|
|
|
void NetworkManager::disconnectObjects()
|
|
|
|
{
|
|
|
|
disconnect(this);
|
|
|
|
}
|