summaryrefslogtreecommitdiff
path: root/Network/NetworkAccessManager.hpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2020-05-11 22:17:58 +0200
committerChristoph Berg <myon@debian.org>2020-05-11 22:17:58 +0200
commit32a41b1abe1a4aab0892c9c2051be6ba5b379f1e (patch)
treec6e107c1ee4d70610e43a7912e57c720334a08c7 /Network/NetworkAccessManager.hpp
parent08299e8b2bf50ba90daf570f57def529dd29d6e7 (diff)
New upstream version 2.2.0~rc1+repackupstream/2.2.0_rc1+repack
Diffstat (limited to 'Network/NetworkAccessManager.hpp')
-rw-r--r--Network/NetworkAccessManager.hpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/Network/NetworkAccessManager.hpp b/Network/NetworkAccessManager.hpp
new file mode 100644
index 00000000..1d1b79bc
--- /dev/null
+++ b/Network/NetworkAccessManager.hpp
@@ -0,0 +1,76 @@
+#ifndef NETWORK_ACCESS_MANAGER_HPP__
+#define NETWORK_ACCESS_MANAGER_HPP__
+
+#include <QNetworkAccessManager>
+#include <QList>
+#include <QSslError>
+#include <QNetworkReply>
+#include <QString>
+
+#include "widgets/MessageBox.hpp"
+
+class QNetworkRequest;
+class QIODevice;
+class QWidget;
+
+// sub-class QNAM to keep a list of accepted SSL errors and allow
+// them in future replies
+class NetworkAccessManager
+ : public QNetworkAccessManager
+{
+public:
+ NetworkAccessManager (QWidget * parent)
+ : QNetworkAccessManager (parent)
+ {
+ // handle SSL errors that have not been cached as allowed
+ // exceptions and offer them to the user to add to the ignored
+ // exception cache
+ connect (this, &QNetworkAccessManager::sslErrors, [this, &parent] (QNetworkReply * reply, QList<QSslError> const& errors) {
+ QString message;
+ QList<QSslError> new_errors;
+ for (auto const& error: errors)
+ {
+ if (!allowed_ssl_errors_.contains (error))
+ {
+ new_errors << error;
+ message += '\n' + reply->request ().url ().toDisplayString () + ": "
+ + error.errorString ();
+ }
+ }
+ if (new_errors.size ())
+ {
+ QString certs;
+ for (auto const& cert : reply->sslConfiguration ().peerCertificateChain ())
+ {
+ certs += cert.toText () + '\n';
+ }
+ if (MessageBox::Ignore == MessageBox::query_message (parent, tr ("Network SSL Errors"), message, certs, MessageBox::Abort | MessageBox::Ignore))
+ {
+ // accumulate new SSL error exceptions that have been allowed
+ allowed_ssl_errors_.append (new_errors);
+ reply->ignoreSslErrors (allowed_ssl_errors_);
+ }
+ }
+ else
+ {
+ // no new exceptions so silently ignore the ones already allowed
+ reply->ignoreSslErrors (allowed_ssl_errors_);
+ }
+ });
+ }
+
+protected:
+ QNetworkReply * createRequest (Operation operation, QNetworkRequest const& request, QIODevice * outgoing_data = nullptr) override
+ {
+ auto reply = QNetworkAccessManager::createRequest (operation, request, outgoing_data);
+ // errors are usually certificate specific so passing all cached
+ // exceptions here is ok
+ reply->ignoreSslErrors (allowed_ssl_errors_);
+ return reply;
+ }
+
+private:
+ QList<QSslError> allowed_ssl_errors_;
+};
+
+#endif