Commit 237ed6cf80f9e8456ca9a8de55ef52ccfa0dc485
1 parent
644f8b7b
Exists in
master
Conexão ssl e alguns refinamentos.
Showing
8 changed files
with
39 additions
and
47 deletions
Show diff stats
README.md
@@ -6,4 +6,7 @@ Instalando no Windows: | @@ -6,4 +6,7 @@ Instalando no Windows: | ||
6 | *Caso dê problemas durante a compilação e for solicitado o "this->" antes de alguns métodos, deve ser corrigido em cada arquivo. | 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 | *Depois disso basta seguir esse tutorial: https://sites.google.com/site/ievgensychov/cryptopp | 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 | Módulo agente do software Cacic | 12 | Módulo agente do software Cacic |
cacic-teste/cacic-teste.pro
@@ -20,16 +20,14 @@ win32 { | @@ -20,16 +20,14 @@ win32 { | ||
20 | SOURCES += \ | 20 | SOURCES += \ |
21 | testcacic.cpp \ | 21 | testcacic.cpp \ |
22 | ../src/ccacic.cpp \ | 22 | ../src/ccacic.cpp \ |
23 | - ../src/cacic_computer.cpp \ | ||
24 | - ../src/sslclient.cpp | 23 | + ../src/cacic_computer.cpp |
25 | 24 | ||
26 | 25 | ||
27 | HEADERS += \ | 26 | HEADERS += \ |
28 | testcacic.h \ | 27 | testcacic.h \ |
29 | ../src/ccacic.h \ | 28 | ../src/ccacic.h \ |
30 | ../src/cacic_computer.h \ | 29 | ../src/cacic_computer.h \ |
31 | - ../src/cacic_comm.h \ | ||
32 | - ../src/sslclient.h | 30 | + ../src/cacic_comm.h |
33 | 31 | ||
34 | INCLUDEPATH += ../src \ | 32 | INCLUDEPATH += ../src \ |
35 | ../src/crypto++/include/ | 33 | ../src/crypto++/include/ |
cacic-teste/testcacic.cpp
@@ -97,11 +97,11 @@ void CTestCacic::testInterfaceDeRede(){ | @@ -97,11 +97,11 @@ void CTestCacic::testInterfaceDeRede(){ | ||
97 | } | 97 | } |
98 | 98 | ||
99 | void CTestCacic::testpegarOS(){ | 99 | void CTestCacic::testpegarOS(){ |
100 | - QVERIFY(OCacicComp.getOs() != "0"); | 100 | + QVERIFY(OCacicComp.getOs() != 0); |
101 | } | 101 | } |
102 | 102 | ||
103 | void CTestCacic::testPegarUsu(){ | 103 | void CTestCacic::testPegarUsu(){ |
104 | - QVERIFY(OCacicComp.getUser() != "0"); | 104 | + QVERIFY(OCacicComp.getUser() != "0"); |
105 | } | 105 | } |
106 | 106 | ||
107 | void CTestCacic::testLogin(){ | 107 | void CTestCacic::testLogin(){ |
@@ -116,8 +116,9 @@ void CTestCacic::testSslConnection() | @@ -116,8 +116,9 @@ void CTestCacic::testSslConnection() | ||
116 | QVariantMap login; | 116 | QVariantMap login; |
117 | login["user"] = "cacic"; | 117 | login["user"] = "cacic"; |
118 | login["password"] = "cacic"; | 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 | // qDebug() << jsonvalue.toVariant().toString(); | 122 | // qDebug() << jsonvalue.toVariant().toString(); |
122 | QVERIFY(!jsonvalue.isNull()); | 123 | QVERIFY(!jsonvalue.isNull()); |
123 | } | 124 | } |
src/cacic_comm.h
@@ -12,14 +12,13 @@ | @@ -12,14 +12,13 @@ | ||
12 | #include <QUrlQuery> | 12 | #include <QUrlQuery> |
13 | #include <QJsonObject> | 13 | #include <QJsonObject> |
14 | #include <QJsonDocument> | 14 | #include <QJsonDocument> |
15 | -#include <sslclient.h> | ||
16 | - | ||
17 | 15 | ||
18 | class CacicComm { | 16 | class CacicComm { |
19 | 17 | ||
20 | private: | 18 | private: |
21 | QUrlQuery params; | 19 | QUrlQuery params; |
22 | QString urlGerente; | 20 | QString urlGerente; |
21 | + QString urlSsl; | ||
23 | // FIXME: Get from configuration | 22 | // FIXME: Get from configuration |
24 | QString usuario = "user"; | 23 | QString usuario = "user"; |
25 | QString password = "123456"; | 24 | QString password = "123456"; |
@@ -57,11 +56,15 @@ public: | @@ -57,11 +56,15 @@ public: | ||
57 | QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) | 56 | QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) |
58 | { | 57 | { |
59 | QByteArray data; | 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 | req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); | 63 | req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); |
64 | + } else | ||
65 | + url = urlGerente + route; | ||
66 | + req.setUrl(url); | ||
67 | + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); | ||
65 | if (json.empty()) | 68 | if (json.empty()) |
66 | { | 69 | { |
67 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) | 70 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) |
@@ -83,6 +86,10 @@ public: | @@ -83,6 +86,10 @@ public: | ||
83 | // a requisição HTTP | 86 | // a requisição HTTP |
84 | 87 | ||
85 | QNetworkReply *reply = mgr.post(req, data); | 88 | QNetworkReply *reply = mgr.post(req, data); |
89 | + if (!reply->sslConfiguration().isNull()){ | ||
90 | +// qDebug() << "Eh ssl"; | ||
91 | + reply->ignoreSslErrors(); | ||
92 | + } | ||
86 | eventLoop.exec(); // sai do looping chamando o "finished()". | 93 | eventLoop.exec(); // sai do looping chamando o "finished()". |
87 | QVariantMap replyValue; | 94 | QVariantMap replyValue; |
88 | //grava o código de retorno | 95 | //grava o código de retorno |
@@ -92,7 +99,6 @@ public: | @@ -92,7 +99,6 @@ public: | ||
92 | //se não houver erro, grava o retorno; | 99 | //se não houver erro, grava o retorno; |
93 | QString strReply = (QString)reply->readAll(); | 100 | QString strReply = (QString)reply->readAll(); |
94 | replyValue["reply"] = strReply; | 101 | replyValue["reply"] = strReply; |
95 | - //parse json | ||
96 | // qDebug() << "Response:" << strReply; | 102 | // qDebug() << "Response:" << strReply; |
97 | 103 | ||
98 | delete reply; | 104 | delete reply; |
@@ -153,15 +159,12 @@ public: | @@ -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 | signals: | 170 | signals: |
src/cacic_computer.cpp
@@ -51,6 +51,7 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ | @@ -51,6 +51,7 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ | ||
51 | * 160 = Windows 8 | 51 | * 160 = Windows 8 |
52 | * 176 = Windows 8.1 | 52 | * 176 = Windows 8.1 |
53 | * 200 = Linux | 53 | * 200 = Linux |
54 | + * 0 = unkown | ||
54 | */ | 55 | */ |
55 | int CACIC_Computer::pegarOS(){ | 56 | int CACIC_Computer::pegarOS(){ |
56 | #if defined (Q_OS_WIN) | 57 | #if defined (Q_OS_WIN) |
@@ -71,9 +72,10 @@ std::string CACIC_Computer::pegarUsu(){ | @@ -71,9 +72,10 @@ std::string CACIC_Computer::pegarUsu(){ | ||
71 | QString text; | 72 | QString text; |
72 | QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | 73 | QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); |
73 | foreach (text, environment) { | 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 | QStringList split = text.split("="); | 77 | QStringList split = text.split("="); |
78 | +// qDebug() << split[1]; | ||
77 | return split[1].toStdString(); | 79 | return split[1].toStdString(); |
78 | } | 80 | } |
79 | } | 81 | } |
src/ccacic.h
@@ -4,13 +4,13 @@ | @@ -4,13 +4,13 @@ | ||
4 | #include <QCoreApplication> | 4 | #include <QCoreApplication> |
5 | #include <QObject> | 5 | #include <QObject> |
6 | #include <QFile> | 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 | #include <QSettings> | 14 | #include <QSettings> |
15 | #include <QDir> | 15 | #include <QDir> |
16 | #include <QDebug> | 16 | #include <QDebug> |
src/sslclient.cpp