From f4675165ea4d7cf72b0905b6ef36385708b20220 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 27 Mar 2018 10:38:00 +0300 Subject: [PATCH] Add environment variable to allow insecure connections (self-signed certs) NHEKO_ALLOW_INSECURE_CONNECTIONS=1 ./nheko fixes #260 --- include/MatrixClient.h | 9 +++++---- src/MatrixClient.cc | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 0e15dc2..62ac208 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -102,7 +102,7 @@ public slots: void setServer(const QString &server) { - server_ = QUrl(QString("https://%1").arg(server)); + server_ = QUrl(QString("%1://%2").arg(serverProtocol_).arg(server)); }; void setAccessToken(const QString &token) { token_ = token; }; void setNextBatchToken(const QString &next_batch) { next_batch_ = next_batch; }; @@ -193,9 +193,10 @@ private: // Increasing transaction ID. int txn_id_; - // Token to be used for the next sync. + //! Token to be used for the next sync. QString next_batch_; - - // filter to be send as filter-param for (initial) /sync requests + //! http or https (default). + QString serverProtocol_; + //! Filter to be send as filter-param for (initial) /sync requests. QString filter_; }; diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 09dd0e2..e7d04eb 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -36,11 +37,26 @@ MatrixClient::MatrixClient(QString server, QObject *parent) : QNetworkAccessManager(parent) , clientApiUrl_{"/_matrix/client/r0"} , mediaApiUrl_{"/_matrix/media/r0"} - , server_{"https://" + server} + , serverProtocol_{"https"} { QSettings settings; txn_id_ = settings.value("client/transaction_id", 1).toInt(); + auto env = QProcessEnvironment::systemEnvironment(); + + auto allowInsecureConnections = env.value("NHEKO_ALLOW_INSECURE_CONNECTIONS", "0"); + + if (allowInsecureConnections == "1") { + qWarning() << "Insecure connections are allowed: SSL errors will be ignored"; + connect( + this, + &QNetworkAccessManager::sslErrors, + this, + [](QNetworkReply *reply, const QList &) { reply->ignoreSslErrors(); }); + } + + setServer(server); + QJsonObject default_filter{ { "room",