Commit 237ed6cf80f9e8456ca9a8de55ef52ccfa0dc485

Authored by Eric Menezes Noronha
1 parent 644f8b7b
Exists in master

Conexão ssl e alguns refinamentos.

README.md
... ... @@ -6,4 +6,7 @@ Instalando no Windows:
6 6 *Caso dê problemas durante a compilação e for solicitado o "this->" antes de alguns métodos, deve ser corrigido em cada arquivo.
7 7 *Depois disso basta seguir esse tutorial: https://sites.google.com/site/ievgensychov/cryptopp
8 8  
  9 +- OpenSSL (https://www.openssl.org/)
  10 +*Encontrado para windows em https://www.openssl.org/related/binaries.html;
  11 +
9 12 Módulo agente do software Cacic
... ...
cacic-teste/cacic-teste.pro
... ... @@ -20,16 +20,14 @@ win32 {
20 20 SOURCES += \
21 21 testcacic.cpp \
22 22 ../src/ccacic.cpp \
23   - ../src/cacic_computer.cpp \
24   - ../src/sslclient.cpp
  23 + ../src/cacic_computer.cpp
25 24  
26 25  
27 26 HEADERS += \
28 27 testcacic.h \
29 28 ../src/ccacic.h \
30 29 ../src/cacic_computer.h \
31   - ../src/cacic_comm.h \
32   - ../src/sslclient.h
  30 + ../src/cacic_comm.h
33 31  
34 32 INCLUDEPATH += ../src \
35 33 ../src/crypto++/include/
... ...
cacic-teste/testcacic.cpp
... ... @@ -97,11 +97,11 @@ void CTestCacic::testInterfaceDeRede(){
97 97 }
98 98  
99 99 void CTestCacic::testpegarOS(){
100   - QVERIFY(OCacicComp.getOs() != "0");
  100 + QVERIFY(OCacicComp.getOs() != 0);
101 101 }
102 102  
103 103 void CTestCacic::testPegarUsu(){
104   - QVERIFY(OCacicComp.getUser() != "0");
  104 + QVERIFY(OCacicComp.getUser() != "0");
105 105 }
106 106  
107 107 void CTestCacic::testLogin(){
... ... @@ -116,8 +116,9 @@ void CTestCacic::testSslConnection()
116 116 QVariantMap login;
117 117 login["user"] = "cacic";
118 118 login["password"] = "cacic";
119   - QJsonObject json = OCacicComm.comm("/ws/get/test", QJsonObject::fromVariantMap(login), true);
120   - QJsonValue jsonvalue = json["key"];
  119 + OCacicComm.setUrlSsl("https://teste.cacic.cc");
  120 + QJsonObject json = OCacicComm.comm("", QJsonObject::fromVariantMap(login), true);
  121 + QJsonValue jsonvalue = json["reply"];
121 122 // qDebug() << jsonvalue.toVariant().toString();
122 123 QVERIFY(!jsonvalue.isNull());
123 124 }
... ...
src/cacic_comm.h
... ... @@ -12,14 +12,13 @@
12 12 #include <QUrlQuery>
13 13 #include <QJsonObject>
14 14 #include <QJsonDocument>
15   -#include <sslclient.h>
16   -
17 15  
18 16 class CacicComm {
19 17  
20 18 private:
21 19 QUrlQuery params;
22 20 QString urlGerente;
  21 + QString urlSsl;
23 22 // FIXME: Get from configuration
24 23 QString usuario = "user";
25 24 QString password = "123456";
... ... @@ -57,11 +56,15 @@ public:
57 56 QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false)
58 57 {
59 58 QByteArray data;
60   - QUrl url = urlGerente + route;
61   - QNetworkRequest req(url);
62   - req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
63   - if (isSsl)
  59 + QNetworkRequest req;
  60 + QUrl url;
  61 + if (isSsl){
  62 + url = urlSsl + route;
64 63 req.setSslConfiguration(QSslConfiguration::defaultConfiguration());
  64 + } else
  65 + url = urlGerente + route;
  66 + req.setUrl(url);
  67 + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
65 68 if (json.empty())
66 69 {
67 70 //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois)
... ... @@ -83,6 +86,10 @@ public:
83 86 // a requisição HTTP
84 87  
85 88 QNetworkReply *reply = mgr.post(req, data);
  89 + if (!reply->sslConfiguration().isNull()){
  90 +// qDebug() << "Eh ssl";
  91 + reply->ignoreSslErrors();
  92 + }
86 93 eventLoop.exec(); // sai do looping chamando o "finished()".
87 94 QVariantMap replyValue;
88 95 //grava o código de retorno
... ... @@ -92,7 +99,6 @@ public:
92 99 //se não houver erro, grava o retorno;
93 100 QString strReply = (QString)reply->readAll();
94 101 replyValue["reply"] = strReply;
95   - //parse json
96 102 // qDebug() << "Response:" << strReply;
97 103  
98 104 delete reply;
... ... @@ -153,15 +159,12 @@ public:
153 159  
154 160 }
155 161  
156   - bool sslConnection(QString host, int port) {
157   - //cria dados para conexão
158   - SslClient client;
159   - client.setHost(host);
160   - client.setPort(port);
161   -
162   - return client.start();
163   - //cria conexão e retorna json
  162 + void setUrlSsl(QString value){
  163 + this->urlSsl = value;
  164 + }
164 165  
  166 + QString getUrlSsl (){
  167 + return this->urlSsl;
165 168 }
166 169  
167 170 signals:
... ...
src/cacic_computer.cpp
... ... @@ -51,6 +51,7 @@ QList&lt;QList&lt;std::string&gt;&gt; CACIC_Computer::networkInterfacesRunning(){
51 51 * 160 = Windows 8
52 52 * 176 = Windows 8.1
53 53 * 200 = Linux
  54 + * 0 = unkown
54 55 */
55 56 int CACIC_Computer::pegarOS(){
56 57 #if defined (Q_OS_WIN)
... ... @@ -71,9 +72,10 @@ std::string CACIC_Computer::pegarUsu(){
71 72 QString text;
72 73 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
73 74 foreach (text, environment) {
74   - if (text.contains("USER=", Qt::CaseInsensitive)
75   - || text.contains("USERNAME=", Qt::CaseInsensitive) ){
  75 + if (text.contains("USER=" , Qt::CaseInsensitive) ||
  76 + text.contains("USERNAME=", Qt::CaseInsensitive) ){
76 77 QStringList split = text.split("=");
  78 +// qDebug() << split[1];
77 79 return split[1].toStdString();
78 80 }
79 81 }
... ...
src/ccacic.h
... ... @@ -4,13 +4,13 @@
4 4 #include <QCoreApplication>
5 5 #include <QObject>
6 6 #include <QFile>
7   -#include "crypto++/include/aes.h"
8   -#include "crypto++/include/base64.h"
9   -#include "crypto++/include/modes.h"
10   -#include "crypto++/include/filters.h"
11   -#include "crypto++/include/hex.h"
12   -#include "crypto++/include/sha.h"
13   -#include "crypto++/include/md5.h"
  7 +#include <aes.h>
  8 +#include <base64.h>
  9 +#include <modes.h>
  10 +#include <filters.h>
  11 +#include <hex.h>
  12 +#include <sha.h>
  13 +#include <md5.h>
14 14 #include <QSettings>
15 15 #include <QDir>
16 16 #include <QDebug>
... ...
src/sslclient.cpp
... ... @@ -1,5 +0,0 @@
1   -#include "sslclient.h"
2   -
3   -SslClient::SslClient()
4   -{
5   -}
src/sslclient.h
... ... @@ -1,10 +0,0 @@
1   -#ifndef SSLCLIENT_H
2   -#define SSLCLIENT_H
3   -
4   -class SslClient
5   -{
6   -public:
7   - SslClient();
8   -};
9   -
10   -#endif // SSLCLIENT_H