mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Cleanups
This commit is contained in:
parent
b24303c00b
commit
abe13dd22d
@ -200,706 +200,3 @@ void NetworkManager::proxyAuthentication(const QString &proxyHost, QAuthenticato
|
||||
auth->setUser(user->text());
|
||||
auth->setPassword(pass->text());
|
||||
}
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
|
||||
#include "browserwindow.h"
|
||||
#include "autofill.h"
|
||||
#include "networkmanagerproxy.h"
|
||||
#include "mainapplication.h"
|
||||
#include "webpage.h"
|
||||
#include "tabbedwebview.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "networkproxyfactory.h"
|
||||
#include "certificateinfowidget.h"
|
||||
#include "qztools.h"
|
||||
#include "qzsettings.h"
|
||||
#include "acceptlanguage.h"
|
||||
#include "cabundleupdater.h"
|
||||
#include "settings.h"
|
||||
#include "datapaths.h"
|
||||
#include "passwordmanager.h"
|
||||
#include "schemehandlers/adblockschemehandler.h"
|
||||
#include "schemehandlers/fileschemehandler.h"
|
||||
#include "schemehandlers/ftpschemehandler.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QNetworkDiskCache>
|
||||
#include <QSslCipher>
|
||||
#include <QSslSocket>
|
||||
#include <QSslConfiguration>
|
||||
#include <QDateTime>
|
||||
#include <QMessageBox>
|
||||
#include <QAuthenticator>
|
||||
#include <QDirIterator>
|
||||
|
||||
static QString fileNameForCert(const QSslCertificate &cert)
|
||||
{
|
||||
QString certFileName = CertificateInfoWidget::certificateItemText(cert);
|
||||
certFileName.remove(QLatin1Char(' '));
|
||||
certFileName.append(QLatin1String(".crt"));
|
||||
certFileName = QzTools::filterCharsFromFilename(certFileName);
|
||||
|
||||
while (certFileName.startsWith(QLatin1Char('.'))) {
|
||||
certFileName = certFileName.mid(1);
|
||||
}
|
||||
|
||||
return certFileName;
|
||||
}
|
||||
|
||||
NetworkManager::NetworkManager(QObject* parent)
|
||||
: NetworkManagerProxy(parent)
|
||||
, m_adblockManager(0)
|
||||
, m_ignoreAllWarnings(false)
|
||||
, m_disableWeakCiphers(true)
|
||||
{
|
||||
connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslError(QNetworkReply*,QList<QSslError>)));
|
||||
connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(setSSLConfiguration(QNetworkReply*)));
|
||||
|
||||
m_schemeHandlers["qupzilla"] = new QupZillaSchemeHandler();
|
||||
m_schemeHandlers["abp"] = new AdBlockSchemeHandler();
|
||||
m_schemeHandlers["file"] = new FileSchemeHandler();
|
||||
m_schemeHandlers["ftp"] = new FtpSchemeHandler();
|
||||
|
||||
m_proxyFactory = new NetworkProxyFactory();
|
||||
setProxyFactory(m_proxyFactory);
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void NetworkManager::loadSettings()
|
||||
{
|
||||
Settings settings;
|
||||
|
||||
if (settings.value("Web-Browser-Settings/AllowLocalCache", true).toBool() && !mApp->isPrivate()) {
|
||||
QNetworkDiskCache* cache = mApp->networkCache();
|
||||
cache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
|
||||
setCache(cache);
|
||||
}
|
||||
|
||||
settings.beginGroup("Web-Browser-Settings");
|
||||
m_doNotTrack = settings.value("DoNotTrack", false).toBool();
|
||||
m_sendReferer = settings.value("SendReferer", true).toBool();
|
||||
settings.endGroup();
|
||||
|
||||
m_acceptLanguage = AcceptLanguage::generateHeader(settings.value("Language/acceptLanguage", AcceptLanguage::defaultLanguage()).toStringList());
|
||||
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
|
||||
QString certDir = DataPaths::currentProfilePath() + "/certificates";
|
||||
QString bundlePath = certDir + "/ca-bundle.crt";
|
||||
QString bundleVersionPath = certDir + "/bundle_version";
|
||||
|
||||
if (!QDir(certDir).exists()) {
|
||||
QDir dir;
|
||||
dir.mkdir(certDir);
|
||||
}
|
||||
|
||||
if (!QFile::exists(bundlePath)) {
|
||||
QFile(":data/ca-bundle.crt").copy(bundlePath);
|
||||
QFile(bundlePath).setPermissions(QFile::ReadUser | QFile::WriteUser);
|
||||
|
||||
QFile(":data/bundle_version").copy(bundleVersionPath);
|
||||
QFile(bundleVersionPath).setPermissions(QFile::ReadUser | QFile::WriteUser);
|
||||
}
|
||||
|
||||
QSslSocket::setDefaultCaCertificates(QSslCertificate::fromPath(bundlePath));
|
||||
#else
|
||||
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates());
|
||||
#endif
|
||||
|
||||
loadCertificates();
|
||||
|
||||
m_proxyFactory->loadSettings();
|
||||
}
|
||||
|
||||
void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
|
||||
{
|
||||
if (!reply->sslConfiguration().isNull()) {
|
||||
QSslCertificate cert = reply->sslConfiguration().peerCertificate();
|
||||
if (!QzTools::isCertificateValid(cert) || reply->property("downReply").toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (webPage->url().host() == reply->url().host()) {
|
||||
webPage->setSSLCertificate(cert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkManager::disableWeakCiphers(bool disable)
|
||||
{
|
||||
if (disable) {
|
||||
QStringList blacklist;
|
||||
blacklist << QSL("SRP-AES-256-CBC-SHA") // open to MitM
|
||||
<< QSL("SRP-AES-128-CBC-SHA"); // open to MitM
|
||||
|
||||
// Disable blacklisted ciphers and ciphers with less than 128b key
|
||||
QList<QSslCipher> acceptedCiphers;
|
||||
foreach (const QSslCipher &c, QSslSocket::defaultCiphers()) {
|
||||
if (!blacklist.contains(c.name()) && c.usedBits() >= 128)
|
||||
acceptedCiphers.append(c);
|
||||
}
|
||||
QSslSocket::setDefaultCiphers(acceptedCiphers);
|
||||
}
|
||||
else {
|
||||
QSslSocket::setDefaultCiphers(QSslSocket::supportedCiphers());
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint qHash(const QSslCertificate &cert)
|
||||
{
|
||||
return qHash(cert.toPem());
|
||||
}
|
||||
|
||||
void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
|
||||
{
|
||||
if (m_ignoreAllWarnings || reply->property("downReply").toBool()) {
|
||||
reply->ignoreSslErrors(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QHash<QSslCertificate, QStringList> errorHash;
|
||||
foreach (const QSslError &error, errors) {
|
||||
// Weird behavior on Windows
|
||||
if (error.error() == QSslError::NoError) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QSslCertificate cert = error.certificate();
|
||||
|
||||
if (errorHash.contains(cert)) {
|
||||
errorHash[cert].append(error.errorString());
|
||||
}
|
||||
else {
|
||||
errorHash.insert(cert, QStringList(error.errorString()));
|
||||
}
|
||||
}
|
||||
|
||||
// User already rejected those certs on this page
|
||||
if (webPage->containsRejectedCerts(errorHash.keys())) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString title = tr("SSL Certificate Error!");
|
||||
QString text1 = tr("The page you are trying to access has the following errors in the SSL certificate:");
|
||||
|
||||
QString certs;
|
||||
|
||||
QHash<QSslCertificate, QStringList>::const_iterator i = errorHash.constBegin();
|
||||
while (i != errorHash.constEnd()) {
|
||||
const QSslCertificate cert = i.key();
|
||||
const QStringList errors = i.value();
|
||||
|
||||
if (m_localCerts.contains(cert) || m_tempAllowedCerts.contains(cert) || errors.isEmpty()) {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
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>";
|
||||
|
||||
certs += "<ul>";
|
||||
foreach (const QString &error, errors) {
|
||||
certs += "<li>";
|
||||
certs += tr("<b>Error: </b>") + error;
|
||||
certs += "</li>";
|
||||
}
|
||||
certs += "</ul>";
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
QString text2 = tr("Would you like to make an exception for this certificate?");
|
||||
QString message = QString("<b>%1</b><p>%2</p>%3<p>%4</p>").arg(title, text1, certs, text2);
|
||||
|
||||
if (!certs.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
reply->ignoreSslErrors(errors);
|
||||
}
|
||||
|
||||
void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
||||
{
|
||||
QDialog* dialog = new QDialog();
|
||||
dialog->setWindowTitle(tr("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);
|
||||
QCheckBox* save = new QCheckBox(dialog);
|
||||
save->setText(tr("Save username and password for 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. "
|
||||
"The site says: \"%2\"").arg(reply->url().host(), QzTools::escape(auth->realm())));
|
||||
formLa->addRow(label);
|
||||
|
||||
formLa->addRow(userLab, user);
|
||||
formLa->addRow(passLab, pass);
|
||||
formLa->addRow(save);
|
||||
|
||||
formLa->addWidget(box);
|
||||
bool shouldUpdateEntry = false;
|
||||
|
||||
AutoFill* fill = mApp->autoFill();
|
||||
QString storedUser;
|
||||
QString storedPassword;
|
||||
if (fill->isStored(reply->url())) {
|
||||
const QVector<PasswordEntry> &data = fill->getFormData(reply->url());
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
save->setChecked(true);
|
||||
shouldUpdateEntry = true;
|
||||
storedUser = data.first().username;
|
||||
storedPassword = data.first().password;
|
||||
user->setText(storedUser);
|
||||
pass->setText(storedPassword);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to set the originating WebTab as a current tab
|
||||
QWebEngineFrame* frame = qobject_cast<QWebEngineFrame*>(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
|
||||
if (mApp->isPrivate()) {
|
||||
save->setVisible(false);
|
||||
}
|
||||
|
||||
if (dialog->exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
auth->setUser(user->text());
|
||||
auth->setPassword(pass->text());
|
||||
|
||||
if (save->isChecked()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
dialog->setWindowTitle(tr("FTP 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: "));
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
||||
{
|
||||
if (op == PostOperation && outgoingData) {
|
||||
QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024);
|
||||
mApp->autoFill()->post(request, outgoingDataByteArray);
|
||||
}
|
||||
|
||||
QNetworkRequest req = request;
|
||||
QNetworkReply* reply = 0;
|
||||
|
||||
if (qzSettings->workOffline) {
|
||||
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
|
||||
}
|
||||
|
||||
// SchemeHandlers
|
||||
if (m_schemeHandlers.contains(req.url().scheme())) {
|
||||
reply = m_schemeHandlers[req.url().scheme()]->createRequest(op, req, outgoingData);
|
||||
if (reply) {
|
||||
if (req.url().scheme() == "ftp") {
|
||||
QVariant v = req.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
||||
if (webPage) {
|
||||
connect(reply, SIGNAL(downloadRequest(QNetworkRequest)),
|
||||
webPage, SLOT(downloadRequested(QNetworkRequest)));
|
||||
}
|
||||
connect(reply, SIGNAL(ftpAuthenticationRequierd(QUrl,QAuthenticator*)),
|
||||
this, SLOT(ftpAuthentication(QUrl,QAuthenticator*)));
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
|
||||
// Plugins
|
||||
reply = mApp->plugins()->createRequest(op, request, outgoingData);
|
||||
if (reply) {
|
||||
return reply;
|
||||
}
|
||||
|
||||
// Indicates whether the load action was triggered by user (eg. opening new tab, clicking on link, ...)
|
||||
bool userLoadAction = req.rawHeader("X-QupZilla-UserLoadAction") == QByteArray("1");
|
||||
|
||||
if (userLoadAction) {
|
||||
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"));
|
||||
}
|
||||
|
||||
if (m_doNotTrack) {
|
||||
req.setRawHeader("DNT", QByteArray("1"));
|
||||
}
|
||||
|
||||
if (!m_sendReferer) {
|
||||
req.setRawHeader("Referer", QByteArray());
|
||||
}
|
||||
|
||||
req.setRawHeader("Accept-Language", m_acceptLanguage);
|
||||
|
||||
// #830: Disabling HttpPipeling fixes issue with loading HTML5 videos on YouTube
|
||||
//req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
||||
|
||||
// Adblock
|
||||
if (!userLoadAction && op == QNetworkAccessManager::GetOperation) {
|
||||
if (!m_adblockManager) {
|
||||
m_adblockManager = AdBlockManager::instance();
|
||||
}
|
||||
reply = m_adblockManager->block(req);
|
||||
if (reply) {
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
|
||||
return QNetworkAccessManager::createRequest(op, req, outgoingData);
|
||||
}
|
||||
|
||||
void NetworkManager::removeLocalCertificate(const QSslCertificate &cert)
|
||||
{
|
||||
m_localCerts.removeOne(cert);
|
||||
|
||||
QList<QSslCertificate> certs = QSslSocket::defaultCaCertificates();
|
||||
certs.removeOne(cert);
|
||||
QSslSocket::setDefaultCaCertificates(certs);
|
||||
|
||||
// Delete cert file from profile
|
||||
bool deleted = false;
|
||||
QDirIterator it(DataPaths::currentProfilePath() + "/certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
const QString filePath = it.next();
|
||||
const QList<QSslCertificate> &certs = QSslCertificate::fromPath(filePath);
|
||||
if (certs.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QSslCertificate cert_ = certs.at(0);
|
||||
if (cert == cert_) {
|
||||
QFile file(filePath);
|
||||
if (!file.remove()) {
|
||||
qWarning() << "NetworkManager::removeLocalCertificate cannot remove file" << filePath;
|
||||
}
|
||||
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!deleted) {
|
||||
qWarning() << "NetworkManager::removeLocalCertificate cannot remove certificate";
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkManager::addLocalCertificate(const QSslCertificate &cert)
|
||||
{
|
||||
// if (!cert.isValid()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
m_localCerts.append(cert);
|
||||
QSslSocket::addDefaultCaCertificate(cert);
|
||||
|
||||
QDir dir(DataPaths::currentProfilePath());
|
||||
if (!dir.exists("certificates")) {
|
||||
dir.mkdir("certificates");
|
||||
}
|
||||
|
||||
QString certFileName = fileNameForCert(cert);
|
||||
QString fileName = QzTools::ensureUniqueFilename(DataPaths::currentProfilePath() + "/certificates/" + certFileName);
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
file.write(cert.toPem());
|
||||
file.close();
|
||||
}
|
||||
else {
|
||||
qWarning() << "NetworkManager::addLocalCertificate cannot write to file: " << fileName;
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkManager::isIgnoringAllWarnings() const
|
||||
{
|
||||
return m_ignoreAllWarnings;
|
||||
}
|
||||
|
||||
void NetworkManager::setIgnoreAllWarnings(bool state)
|
||||
{
|
||||
m_ignoreAllWarnings = state;
|
||||
Settings().setValue("SSL-Configuration/IgnoreAllSSLWarnings", m_ignoreAllWarnings);
|
||||
}
|
||||
|
||||
bool NetworkManager::isDisablingWeakCiphers() const
|
||||
{
|
||||
return m_disableWeakCiphers;
|
||||
}
|
||||
|
||||
void NetworkManager::setDisableWeakCiphers(bool state)
|
||||
{
|
||||
m_disableWeakCiphers = state;
|
||||
disableWeakCiphers(m_disableWeakCiphers);
|
||||
Settings().setValue("SSL-Configuration/DisableWeakCiphers", m_disableWeakCiphers);
|
||||
}
|
||||
|
||||
NetworkProxyFactory* NetworkManager::proxyFactory() const
|
||||
{
|
||||
return m_proxyFactory;
|
||||
}
|
||||
|
||||
bool NetworkManager::registerSchemeHandler(const QString &scheme, SchemeHandler* handler)
|
||||
{
|
||||
if (m_schemeHandlers.contains(scheme)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_schemeHandlers[scheme] = handler;
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void NetworkManager::saveSettings()
|
||||
{
|
||||
Settings settings;
|
||||
settings.beginGroup("SSL-Configuration");
|
||||
settings.setValue("CACertPaths", m_certPaths);
|
||||
settings.setValue("IgnoreAllSSLWarnings", m_ignoreAllWarnings);
|
||||
settings.setValue("DisableWeakCiphers", m_disableWeakCiphers);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("Web-Browser-Settings");
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void NetworkManager::loadCertificates()
|
||||
{
|
||||
Settings settings;
|
||||
settings.beginGroup("SSL-Configuration");
|
||||
m_certPaths = settings.value("CACertPaths", QStringList()).toStringList();
|
||||
m_ignoreAllWarnings = settings.value("IgnoreAllSSLWarnings", false).toBool();
|
||||
m_disableWeakCiphers = settings.value("DisableWeakCiphers", true).toBool();
|
||||
settings.endGroup();
|
||||
|
||||
disableWeakCiphers(m_disableWeakCiphers);
|
||||
|
||||
// CA Certificates
|
||||
m_caCerts = QSslSocket::defaultCaCertificates();
|
||||
|
||||
foreach (const QString &path, m_certPaths) {
|
||||
#ifdef Q_OS_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
|
||||
QDirIterator it(path, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString filePath = it.next();
|
||||
if (!filePath.endsWith(QLatin1String(".crt"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_caCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem);
|
||||
}
|
||||
}
|
||||
#else
|
||||
m_caCerts += QSslCertificate::fromPath(path + "/*.crt", QSsl::Pem, QRegExp::Wildcard);
|
||||
#endif
|
||||
}
|
||||
// Local Certificates
|
||||
#ifdef Q_OS_WIN
|
||||
QDirIterator it_(DataPaths::currentProfilePath() + "/certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
||||
while (it_.hasNext()) {
|
||||
QString filePath = it_.next();
|
||||
if (!filePath.endsWith(QLatin1String(".crt"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_localCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem);
|
||||
}
|
||||
}
|
||||
#else
|
||||
m_localCerts = QSslCertificate::fromPath(DataPaths::currentProfilePath() + "/certificates/*.crt", QSsl::Pem, QRegExp::Wildcard);
|
||||
#endif
|
||||
|
||||
QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts);
|
||||
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
|
||||
new CaBundleUpdater(this, this);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -459,191 +459,6 @@ void WebPage::cleanBlockedObjects()
|
||||
runJavaScript(Scripts::setCss(elementHiding));
|
||||
}
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
bool WebPage::supportsExtension(Extension extension) const
|
||||
{
|
||||
Q_UNUSED(extension)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output)
|
||||
{
|
||||
if (extension == ChooseMultipleFilesExtension) {
|
||||
const QWebEnginePage::ChooseMultipleFilesExtensionOption* exOption = static_cast<const QWebEnginePage::ChooseMultipleFilesExtensionOption*>(option);
|
||||
QWebEnginePage::ChooseMultipleFilesExtensionReturn* exReturn = static_cast<QWebEnginePage::ChooseMultipleFilesExtensionReturn*>(output);
|
||||
|
||||
if (!exOption || !exReturn) {
|
||||
return QWebEnginePage::extension(extension, option, output);
|
||||
}
|
||||
|
||||
QString suggestedFileName;
|
||||
if (!exOption->suggestedFileNames.isEmpty()) {
|
||||
suggestedFileName = exOption->suggestedFileNames.at(0);
|
||||
}
|
||||
|
||||
exReturn->fileNames = QzTools::getOpenFileNames("WebPage-UploadFiles", 0, tr("Select files to upload..."), suggestedFileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
const ErrorPageExtensionOption* exOption = static_cast<const QWebEnginePage::ErrorPageExtensionOption*>(option);
|
||||
ErrorPageExtensionReturn* exReturn = static_cast<QWebEnginePage::ErrorPageExtensionReturn*>(output);
|
||||
|
||||
if (!exOption || !exReturn) {
|
||||
return QWebEnginePage::extension(extension, option, output);
|
||||
}
|
||||
|
||||
WebPage* erPage = qobject_cast<WebPage*>(exOption->frame->page());
|
||||
|
||||
if (!erPage) {
|
||||
return QWebEnginePage::extension(extension, option, output);
|
||||
}
|
||||
|
||||
QString errorString;
|
||||
if (exOption->domain == QWebEnginePage::QtNetwork) {
|
||||
switch (exOption->error) {
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
errorString = tr("Server refused the connection");
|
||||
break;
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
errorString = tr("Server closed the connection");
|
||||
break;
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
// If a one-word host was not find, search for the text instead
|
||||
// It needs to be async to correctly refresh loading state
|
||||
if (!exOption->url.host().isEmpty() && !exOption->url.host().contains(QL1C('.'))) {
|
||||
const QString text = QzTools::fromPunycode(exOption->url.host().toUtf8());
|
||||
QMetaObject::invokeMethod(this, "doWebSearch", Qt::QueuedConnection, Q_ARG(QString, text));
|
||||
return false;
|
||||
}
|
||||
errorString = tr("Server not found");
|
||||
break;
|
||||
case QNetworkReply::TimeoutError:
|
||||
errorString = tr("Connection timed out");
|
||||
break;
|
||||
case QNetworkReply::SslHandshakeFailedError:
|
||||
errorString = tr("Untrusted connection");
|
||||
break;
|
||||
case QNetworkReply::TemporaryNetworkFailureError:
|
||||
errorString = tr("Temporary network failure");
|
||||
break;
|
||||
case QNetworkReply::ProxyConnectionRefusedError:
|
||||
errorString = tr("Proxy connection refused");
|
||||
break;
|
||||
case QNetworkReply::ProxyNotFoundError:
|
||||
errorString = tr("Proxy server not found");
|
||||
break;
|
||||
case QNetworkReply::ProxyTimeoutError:
|
||||
errorString = tr("Proxy connection timed out");
|
||||
break;
|
||||
case QNetworkReply::ProxyAuthenticationRequiredError:
|
||||
errorString = tr("Proxy authentication required");
|
||||
break;
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
errorString = tr("Content not found");
|
||||
break;
|
||||
case QNetworkReply::UnknownNetworkError:
|
||||
errorString = exOption->errorString.isEmpty() ? tr("Unknown network error") : exOption->errorString;
|
||||
break;
|
||||
case QNetworkReply::ProtocolUnknownError: {
|
||||
// Sometimes exOption->url returns just "?" instead of actual url
|
||||
const QUrl unknownProtocolUrl = (exOption->url.toString() == QLatin1String("?")) ? erPage->mainFrame()->requestedUrl() : exOption->url;
|
||||
handleUnknownProtocol(unknownProtocolUrl);
|
||||
return false;
|
||||
}
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
if (exOption->errorString.startsWith(QLatin1String("AdBlock"))) {
|
||||
if (exOption->frame != erPage->mainFrame()) {
|
||||
// Content in <iframe>
|
||||
QWebElement docElement = erPage->mainFrame()->documentElement();
|
||||
|
||||
QWebElementCollection elements;
|
||||
elements.append(docElement.findAll(QSL("iframe")));
|
||||
|
||||
foreach (QWebElement element, elements) {
|
||||
const QString src = element.attribute(QSL("src"));
|
||||
if (!src.isEmpty() && exOption->url.toString().contains(src)) {
|
||||
element.setStyleProperty(QSL("display"), QSL("none"));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// The whole page is blocked
|
||||
QString rule = exOption->errorString;
|
||||
rule.remove(QLatin1String("AdBlock: "));
|
||||
|
||||
QString errString = QzTools::readAllFileContents(":/html/adblockPage.html");
|
||||
errString.replace(QLatin1String("%TITLE%"), tr("AdBlocked Content"));
|
||||
errString.replace(QLatin1String("%IMAGE%"), QLatin1String("qrc:html/adblock_big.png"));
|
||||
errString.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:html/adblock_big.png"));
|
||||
|
||||
errString.replace(QLatin1String("%RULE%"), tr("Blocked by <i>%1</i>").arg(rule));
|
||||
errString = QzTools::applyDirectionToPage(errString);
|
||||
|
||||
exReturn->baseUrl = exOption->url;
|
||||
exReturn->content = QString(errString + "<span id=\"qupzilla-error-page\"></span>").toUtf8();
|
||||
|
||||
if (PopupWebPage* popupPage = qobject_cast<PopupWebPage*>(exOption->frame->page())) {
|
||||
WebView* view = qobject_cast<WebView*>(popupPage->view());
|
||||
if (view) {
|
||||
// Closing blocked popup
|
||||
popupPage->mainWindow()->adBlockIcon()->popupBlocked(rule, exOption->url);
|
||||
view->closeView();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
errorString = tr("Content Access Denied");
|
||||
break;
|
||||
default:
|
||||
if (exOption->errorString != QLatin1String("QupZilla:No Error")) {
|
||||
qDebug() << "Content error: " << exOption->errorString << exOption->error;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (exOption->domain == QWebEnginePage::Http) {
|
||||
// 200 status code = OK
|
||||
// It shouldn't be reported as an error, but sometimes it is ...
|
||||
if (exOption->error == 200) {
|
||||
return false;
|
||||
}
|
||||
errorString = tr("Error code %1").arg(exOption->error);
|
||||
}
|
||||
else if (exOption->domain == QWebEnginePage::WebKit) {
|
||||
return false; // Downloads
|
||||
}
|
||||
|
||||
const QUrl loadedUrl = exOption->url;
|
||||
exReturn->baseUrl = loadedUrl;
|
||||
|
||||
QFile file(":/html/errorPage.html");
|
||||
file.open(QFile::ReadOnly);
|
||||
QString errString = file.readAll();
|
||||
errString.replace(QLatin1String("%TITLE%"), tr("Failed loading page"));
|
||||
|
||||
errString.replace(QLatin1String("%IMAGE%"), QzTools::pixmapToByteArray(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
|
||||
errString.replace(QLatin1String("%FAVICON%"), QzTools::pixmapToByteArray(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning).pixmap(16, 16)));
|
||||
errString.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
|
||||
|
||||
QString heading2 = loadedUrl.host().isEmpty() ? tr("QupZilla can't load page.") : tr("QupZilla can't load page from %1.").arg(loadedUrl.host());
|
||||
|
||||
errString.replace(QLatin1String("%HEADING%"), errorString);
|
||||
errString.replace(QLatin1String("%HEADING2%"), heading2);
|
||||
errString.replace(QLatin1String("%LI-1%"), tr("Check the address for typing errors such as <b>ww.</b>example.com instead of <b>www.</b>example.com"));
|
||||
errString.replace(QLatin1String("%LI-2%"), tr("If you are unable to load any pages, check your computer's network connection."));
|
||||
errString.replace(QLatin1String("%LI-3%"), tr("If your computer or network is protected by a firewall or proxy, make sure that QupZilla is permitted to access the Web."));
|
||||
errString.replace(QLatin1String("%TRY-AGAIN%"), tr("Try Again"));
|
||||
errString = QzTools::applyDirectionToPage(errString);
|
||||
|
||||
exReturn->content = QString(errString + "<span id=\"qupzilla-error-page\"></span>").toUtf8();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result)
|
||||
{
|
||||
Q_UNUSED(securityOrigin)
|
||||
|
@ -96,11 +96,6 @@ private:
|
||||
QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE;
|
||||
QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
bool supportsExtension(Extension extension) const;
|
||||
bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0);
|
||||
#endif
|
||||
|
||||
void handleUnknownProtocol(const QUrl &url);
|
||||
void desktopServicesOpen(const QUrl &url);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user