From c82337d693a78f7bb353a4f98cecd21e74dd9456 Mon Sep 17 00:00:00 2001 From: dorian Date: Sat, 9 Mar 2019 23:26:58 +0100 Subject: [PATCH] implemented ssl(https) for user data transfer (finally :D) --- headers/serverconn.h | 3 ++- sources/serverconn.cpp | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/headers/serverconn.h b/headers/serverconn.h index 1978a89..cf12edd 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -54,15 +54,16 @@ private: QString password; QNetworkAccessManager *networkManager; QNetworkAccessManager *refreshNetworkManager; + QNetworkReply *networkReply; QTimer *checkConnTimer; int authErrorCount; ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); + QList apiVersion = {0,2,1}; private slots: - void setState(QString state); public: diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index f919715..0b67754 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -59,7 +59,7 @@ int ServerConn::login(QString username, QString password, bool permanent) pdata.addQueryItem("password", password); // send the request - ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); + ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); if(ret.status_code == 200){ // if not 200 was returned -> user data was correct @@ -124,7 +124,7 @@ int ServerConn::checkConn() pdata.addQueryItem("password", this->password); // send the request - ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); + ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); if(ret.status_code == 401){ // if the stats code is 401 -> userdata is incorrect @@ -155,7 +155,7 @@ int ServerConn::getEvents(QString day) pdata.addQueryItem("day", day); // send the request - ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); + ReturnData_t ret = this->senddata(QUrl("https://www.fanny-leicht.de/j34/templates/g5_helium/intern/events.php"), pdata); if(ret.status_code != 200){ // if the request didn't result in a success, clear the old events, as they are probaply incorrect and return the error code @@ -369,11 +369,16 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + QSslConfiguration config = QSslConfiguration::defaultConfiguration(); + config.setProtocol(QSsl::TlsV1_2); + request.setSslConfiguration(config); + //send a POST request with the given url and data to the server - QNetworkReply* reply; + + QNetworkReply *reply; reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); - + connect(reply, &QNetworkReply::sslErrors, this, [=](){ reply->ignoreSslErrors(); }); // loop to wait until the request has finished before processing the data QEventLoop loop; // timer to cancel the request after 3 seconds @@ -397,9 +402,8 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) //get the full text response ret.text = QString::fromUtf8(reply->readAll()); - if(reply->isOpen()){ - delete reply; - } + // delete the reply object + delete reply; //return the data return(ret);