aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-02-22 13:51:51 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:34:52 +0100
commitc2836e007e2d46c0c20270b99ede5b78d2c7170b (patch)
treee235f5c3e18b0f396592fd6dd787362d9f208ffd /lib
parentea617d31cf3f72f76fd49c0a20f445a78678fe5f (diff)
downloadlibquotient-c2836e007e2d46c0c20270b99ede5b78d2c7170b.tar.gz
libquotient-c2836e007e2d46c0c20270b99ede5b78d2c7170b.zip
ssl
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp5
-rw-r--r--lib/connection.h5
-rw-r--r--lib/connectiondata.cpp6
-rw-r--r--lib/connectiondata.h1
-rw-r--r--lib/networkaccessmanager.cpp17
-rw-r--r--lib/networkaccessmanager.h1
6 files changed, 30 insertions, 5 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 704bc1b4..62427ae1 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -572,6 +572,11 @@ void Connection::sync(int timeout)
});
}
+void Connection::ignoreSslErrors(bool ignore)
+{
+ connectionData()->ignoreSslErrors(ignore);
+}
+
void Connection::syncLoop(int timeout)
{
if (d->syncLoopConnection && d->syncTimeout == timeout) {
diff --git a/lib/connection.h b/lib/connection.h
index 6729b23d..93e22da2 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -476,6 +476,11 @@ public:
setUserFactory(defaultUserFactory<T>());
}
+ /// Ignore ssl errors (usefull for automated testing with local synapse
+ /// instance).
+ /// \internal
+ void ignoreSslErrors(bool ignore);
+
public Q_SLOTS:
/// \brief Set the homeserver base URL and retrieve its login flows
///
diff --git a/lib/connectiondata.cpp b/lib/connectiondata.cpp
index 87ad4577..672feb06 100644
--- a/lib/connectiondata.cpp
+++ b/lib/connectiondata.cpp
@@ -128,6 +128,12 @@ bool ConnectionData::needsToken(const QString& requestName) const
!= d->needToken.cend();
}
+void ConnectionData::ignoreSslErrors(bool ignore) const
+{
+ auto quotientNam = static_cast<NetworkAccessManager>(nam());
+ quotientNam.ignoreSslErrors(ignore);
+}
+
void ConnectionData::setDeviceId(const QString& deviceId)
{
d->deviceId = deviceId;
diff --git a/lib/connectiondata.h b/lib/connectiondata.h
index e16a2dac..203dc9e8 100644
--- a/lib/connectiondata.h
+++ b/lib/connectiondata.h
@@ -29,6 +29,7 @@ public:
bool needsToken(const QString& requestName) const;
QNetworkAccessManager* nam() const;
+ void ignoreSslErrors(bool ignore = true) const;
void setBaseUrl(QUrl baseUrl);
void setToken(QByteArray accessToken);
void setDeviceId(const QString& deviceId);
diff --git a/lib/networkaccessmanager.cpp b/lib/networkaccessmanager.cpp
index 293538ee..d0380cec 100644
--- a/lib/networkaccessmanager.cpp
+++ b/lib/networkaccessmanager.cpp
@@ -40,17 +40,24 @@ public:
NetworkAccessManager::NetworkAccessManager(QObject* parent)
: QNetworkAccessManager(parent), d(std::make_unique<Private>(this))
-{
- connect(this, &QNetworkAccessManager::sslErrors, this, [](QNetworkReply *reply, const QList<QSslError> &errors) {
- reply->ignoreSslErrors();
- });
-}
+{}
QList<QSslError> NetworkAccessManager::ignoredSslErrors() const
{
return d->ignoredSslErrors;
}
+void NetworkAccessManager::ignoreSslErrors(bool ignore) const
+{
+ if (ignore) {
+ connect(this, &QNetworkAccessManager::sslErrors, this, [](QNetworkReply *reply, const QList<QSslError> &errors) {
+ reply->ignoreSslErrors();
+ });
+ } else {
+ disconnect(this, &QNetworkAccessManager::sslErrors, this, nullptr);
+ }
+}
+
void NetworkAccessManager::addIgnoredSslError(const QSslError& error)
{
d->ignoredSslErrors << error;
diff --git a/lib/networkaccessmanager.h b/lib/networkaccessmanager.h
index 87bc12a1..7643302f 100644
--- a/lib/networkaccessmanager.h
+++ b/lib/networkaccessmanager.h
@@ -19,6 +19,7 @@ public:
QList<QSslError> ignoredSslErrors() const;
void addIgnoredSslError(const QSslError& error);
void clearIgnoredSslErrors();
+ void ignoreSslErrors(bool ignore = true) const;
/** Get a pointer to the singleton */
static NetworkAccessManager* instance();