From 237ed6cf80f9e8456ca9a8de55ef52ccfa0dc485 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Mon, 11 Aug 2014 17:18:59 -0300 Subject: [PATCH] Conexão ssl e alguns refinamentos. --- README.md | 3 +++ cacic-teste/cacic-teste.pro | 6 ++---- cacic-teste/testcacic.cpp | 9 +++++---- src/cacic_comm.h | 33 ++++++++++++++++++--------------- src/cacic_computer.cpp | 6 ++++-- src/ccacic.h | 14 +++++++------- src/sslclient.cpp | 5 ----- src/sslclient.h | 10 ---------- 8 files changed, 39 insertions(+), 47 deletions(-) delete mode 100644 src/sslclient.cpp delete mode 100644 src/sslclient.h diff --git a/README.md b/README.md index 51bbb9e..2b0ed0e 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,7 @@ Instalando no Windows: *Caso dê problemas durante a compilação e for solicitado o "this->" antes de alguns métodos, deve ser corrigido em cada arquivo. *Depois disso basta seguir esse tutorial: https://sites.google.com/site/ievgensychov/cryptopp +- OpenSSL (https://www.openssl.org/) +*Encontrado para windows em https://www.openssl.org/related/binaries.html; + Módulo agente do software Cacic diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index 8ded4a7..dead633 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -20,16 +20,14 @@ win32 { SOURCES += \ testcacic.cpp \ ../src/ccacic.cpp \ - ../src/cacic_computer.cpp \ - ../src/sslclient.cpp + ../src/cacic_computer.cpp HEADERS += \ testcacic.h \ ../src/ccacic.h \ ../src/cacic_computer.h \ - ../src/cacic_comm.h \ - ../src/sslclient.h + ../src/cacic_comm.h INCLUDEPATH += ../src \ ../src/crypto++/include/ diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 92f1ec3..b45c873 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -97,11 +97,11 @@ void CTestCacic::testInterfaceDeRede(){ } void CTestCacic::testpegarOS(){ - QVERIFY(OCacicComp.getOs() != "0"); + QVERIFY(OCacicComp.getOs() != 0); } void CTestCacic::testPegarUsu(){ - QVERIFY(OCacicComp.getUser() != "0"); + QVERIFY(OCacicComp.getUser() != "0"); } void CTestCacic::testLogin(){ @@ -116,8 +116,9 @@ void CTestCacic::testSslConnection() QVariantMap login; login["user"] = "cacic"; login["password"] = "cacic"; - QJsonObject json = OCacicComm.comm("/ws/get/test", QJsonObject::fromVariantMap(login), true); - QJsonValue jsonvalue = json["key"]; + OCacicComm.setUrlSsl("https://teste.cacic.cc"); + QJsonObject json = OCacicComm.comm("", QJsonObject::fromVariantMap(login), true); + QJsonValue jsonvalue = json["reply"]; // qDebug() << jsonvalue.toVariant().toString(); QVERIFY(!jsonvalue.isNull()); } diff --git a/src/cacic_comm.h b/src/cacic_comm.h index b1c3830..2376a2e 100644 --- a/src/cacic_comm.h +++ b/src/cacic_comm.h @@ -12,14 +12,13 @@ #include #include #include -#include - class CacicComm { private: QUrlQuery params; QString urlGerente; + QString urlSsl; // FIXME: Get from configuration QString usuario = "user"; QString password = "123456"; @@ -57,11 +56,15 @@ public: QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) { QByteArray data; - QUrl url = urlGerente + route; - QNetworkRequest req(url); - req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); - if (isSsl) + QNetworkRequest req; + QUrl url; + if (isSsl){ + url = urlSsl + route; req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); + } else + url = urlGerente + route; + req.setUrl(url); + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); if (json.empty()) { //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) @@ -83,6 +86,10 @@ public: // a requisição HTTP QNetworkReply *reply = mgr.post(req, data); + if (!reply->sslConfiguration().isNull()){ +// qDebug() << "Eh ssl"; + reply->ignoreSslErrors(); + } eventLoop.exec(); // sai do looping chamando o "finished()". QVariantMap replyValue; //grava o código de retorno @@ -92,7 +99,6 @@ public: //se não houver erro, grava o retorno; QString strReply = (QString)reply->readAll(); replyValue["reply"] = strReply; - //parse json // qDebug() << "Response:" << strReply; delete reply; @@ -153,15 +159,12 @@ public: } - bool sslConnection(QString host, int port) { - //cria dados para conexão - SslClient client; - client.setHost(host); - client.setPort(port); - - return client.start(); - //cria conexão e retorna json + void setUrlSsl(QString value){ + this->urlSsl = value; + } + QString getUrlSsl (){ + return this->urlSsl; } signals: diff --git a/src/cacic_computer.cpp b/src/cacic_computer.cpp index 06d27e3..d749ceb 100644 --- a/src/cacic_computer.cpp +++ b/src/cacic_computer.cpp @@ -51,6 +51,7 @@ QList> CACIC_Computer::networkInterfacesRunning(){ * 160 = Windows 8 * 176 = Windows 8.1 * 200 = Linux + * 0 = unkown */ int CACIC_Computer::pegarOS(){ #if defined (Q_OS_WIN) @@ -71,9 +72,10 @@ std::string CACIC_Computer::pegarUsu(){ QString text; QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); foreach (text, environment) { - if (text.contains("USER=", Qt::CaseInsensitive) - || text.contains("USERNAME=", Qt::CaseInsensitive) ){ + if (text.contains("USER=" , Qt::CaseInsensitive) || + text.contains("USERNAME=", Qt::CaseInsensitive) ){ QStringList split = text.split("="); +// qDebug() << split[1]; return split[1].toStdString(); } } diff --git a/src/ccacic.h b/src/ccacic.h index b54c0c1..88c5d97 100644 --- a/src/ccacic.h +++ b/src/ccacic.h @@ -4,13 +4,13 @@ #include #include #include -#include "crypto++/include/aes.h" -#include "crypto++/include/base64.h" -#include "crypto++/include/modes.h" -#include "crypto++/include/filters.h" -#include "crypto++/include/hex.h" -#include "crypto++/include/sha.h" -#include "crypto++/include/md5.h" +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/src/sslclient.cpp b/src/sslclient.cpp deleted file mode 100644 index 7bb6d48..0000000 --- a/src/sslclient.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "sslclient.h" - -SslClient::SslClient() -{ -} diff --git a/src/sslclient.h b/src/sslclient.h deleted file mode 100644 index b98d39b..0000000 --- a/src/sslclient.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SSLCLIENT_H -#define SSLCLIENT_H - -class SslClient -{ -public: - SslClient(); -}; - -#endif // SSLCLIENT_H -- libgit2 0.21.2