mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Automatic updates for ca-bundle.crt CA certificates bundle.
- checking updates every 5 days from homepage qupzilla.com
This commit is contained in:
parent
2b82d486d0
commit
3a2ceeab31
@ -3,5 +3,6 @@
|
||||
<file>data/browsedata.db</file>
|
||||
<file>data/profiles.ini</file>
|
||||
<file>data/ca-bundle.crt</file>
|
||||
<file>data/bundle_version</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
1
src/data/data/bundle_version
Normal file
1
src/data/data/bundle_version
Normal file
@ -0,0 +1 @@
|
||||
1
|
101
src/network/cabundleupdater.cpp
Normal file
101
src/network/cabundleupdater.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "cabundleupdater.h"
|
||||
#include "mainapplication.h"
|
||||
#include "networkmanager.h"
|
||||
#include "qupzilla.h"
|
||||
#include "globalfunctions.h"
|
||||
|
||||
CaBundleUpdater::CaBundleUpdater(NetworkManager* manager, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_manager(manager)
|
||||
, m_progress(Start)
|
||||
, m_latestBundleVersion(0)
|
||||
{
|
||||
m_bundleVersionFileName = mApp->PROFILEDIR + "certificates/bundle_version";
|
||||
m_bundleFileName = mApp->PROFILEDIR + "certificates/ca-bundle.crt";
|
||||
m_lastUpdateFileName = mApp->PROFILEDIR + "certificates/last_update";
|
||||
|
||||
QTimer::singleShot(30 * 1000, this, SLOT(start()));
|
||||
}
|
||||
|
||||
void CaBundleUpdater::start()
|
||||
{
|
||||
QFile updateFile(m_lastUpdateFileName);
|
||||
bool updateNow = false;
|
||||
|
||||
if (updateFile.exists()) {
|
||||
if (!updateFile.open(QFile::ReadOnly)) {
|
||||
qWarning() << "CaBundleUpdater::start cannot open file for reading" << m_lastUpdateFileName;
|
||||
}
|
||||
else {
|
||||
QDateTime updateTime = QDateTime::fromString(updateFile.readAll());
|
||||
updateNow = updateTime.addDays(5) < QDateTime::currentDateTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
updateNow = true;
|
||||
}
|
||||
|
||||
if (updateNow) {
|
||||
m_progress = CheckLastUpdate;
|
||||
|
||||
m_reply = m_manager->get(QNetworkRequest(QupZilla::WWWADDRESS + "/certs/bundle_version"));
|
||||
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
||||
}
|
||||
}
|
||||
|
||||
void CaBundleUpdater::replyFinished()
|
||||
{
|
||||
if (m_progress == CheckLastUpdate) {
|
||||
QByteArray response = m_reply->readAll().trimmed();
|
||||
m_reply->close();
|
||||
m_reply->deleteLater();
|
||||
|
||||
if (m_reply->error() != QNetworkReply::NoError || response.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_latestBundleVersion = response.toInt();
|
||||
int currentBundleVersion = qz_readAllFileContents(m_bundleVersionFileName).trimmed().toInt();
|
||||
|
||||
if (m_latestBundleVersion == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_latestBundleVersion > currentBundleVersion) {
|
||||
m_progress = LoadBundle;
|
||||
m_reply = m_manager->get(QNetworkRequest(QupZilla::WWWADDRESS + "/certs/ca-bundle.crt"));
|
||||
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
||||
}
|
||||
|
||||
QFile file(m_lastUpdateFileName);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_lastUpdateFileName;
|
||||
}
|
||||
|
||||
file.write(QDateTime::currentDateTime().toString().toUtf8());
|
||||
}
|
||||
else if (m_progress == LoadBundle) {
|
||||
QByteArray response = m_reply->readAll();
|
||||
m_reply->close();
|
||||
m_reply->deleteLater();
|
||||
|
||||
if (m_reply->error() != QNetworkReply::NoError || response.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(m_bundleVersionFileName);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_bundleVersionFileName;
|
||||
}
|
||||
|
||||
file.write(QByteArray::number(m_latestBundleVersion));
|
||||
file.close();
|
||||
|
||||
file.setFileName(m_bundleFileName);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_bundleFileName;
|
||||
}
|
||||
|
||||
file.write(response);
|
||||
}
|
||||
}
|
39
src/network/cabundleupdater.h
Normal file
39
src/network/cabundleupdater.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef CABUNDLEUPDATER_H
|
||||
#define CABUNDLEUPDATER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QFile>
|
||||
#include <QDateTime>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class NetworkManager;
|
||||
class CaBundleUpdater : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CaBundleUpdater(NetworkManager* manager, QObject* parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void start();
|
||||
void replyFinished();
|
||||
|
||||
private:
|
||||
enum Progress { Start, CheckLastUpdate, LoadBundle };
|
||||
|
||||
NetworkManager* m_manager;
|
||||
Progress m_progress;
|
||||
QNetworkReply* m_reply;
|
||||
|
||||
QString m_bundleVersionFileName;
|
||||
QString m_bundleFileName;
|
||||
QString m_lastUpdateFileName;
|
||||
|
||||
int m_latestBundleVersion;
|
||||
};
|
||||
|
||||
#endif // CABUNDLEUPDATER_H
|
@ -29,6 +29,7 @@
|
||||
#include "certificateinfowidget.h"
|
||||
#include "globalfunctions.h"
|
||||
#include "acceptlanguage.h"
|
||||
#include "cabundleupdater.h"
|
||||
|
||||
QString fileNameForCert(const QSslCertificate &cert)
|
||||
{
|
||||
@ -83,6 +84,7 @@ void NetworkManager::loadSettings()
|
||||
|
||||
QString certDir = mApp->PROFILEDIR + "certificates";
|
||||
QString bundlePath = certDir + "/ca-bundle.crt";
|
||||
QString bundleVersionPath = certDir + "/bundle_version";
|
||||
|
||||
if (!QDir(certDir).exists()) {
|
||||
QDir dir(mApp->PROFILEDIR);
|
||||
@ -92,6 +94,9 @@ void NetworkManager::loadSettings()
|
||||
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));
|
||||
@ -450,4 +455,6 @@ void NetworkManager::loadCertificates()
|
||||
#endif
|
||||
|
||||
QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts);
|
||||
|
||||
new CaBundleUpdater(this, this);
|
||||
}
|
||||
|
@ -184,7 +184,8 @@ SOURCES += main.cpp\
|
||||
navigation/siteicon.cpp \
|
||||
navigation/goicon.cpp \
|
||||
rss/rssicon.cpp \
|
||||
navigation/downicon.cpp
|
||||
navigation/downicon.cpp \
|
||||
network/cabundleupdater.cpp
|
||||
|
||||
HEADERS += \
|
||||
3rdparty/qtwin.h \
|
||||
@ -307,7 +308,8 @@ HEADERS += \
|
||||
navigation/siteicon.h \
|
||||
navigation/goicon.h \
|
||||
rss/rssicon.h \
|
||||
navigation/downicon.h
|
||||
navigation/downicon.h \
|
||||
network/cabundleupdater.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
@ -127,7 +127,7 @@ void WebPage::watchedFileChanged(const QString &file)
|
||||
}
|
||||
}
|
||||
|
||||
void WebPage::printFrame(QWebFrame *frame)
|
||||
void WebPage::printFrame(QWebFrame* frame)
|
||||
{
|
||||
p_QupZilla->printPage(frame);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user