Commit 9eae79ae490bf65afba2df2d3af369d8e6b6ec6b

Authored by LightBase Consultoria em Software Publico
2 parents 057ff81b 4ddd7eb4
Exists in master

Merge branch 'master' of https://github.com/lightbase/cacic-agente

gercols/gercols.cpp
@@ -22,6 +22,31 @@ Gercols::Gercols(QObject *parent) @@ -22,6 +22,31 @@ Gercols::Gercols(QObject *parent)
22 oCacic.setJsonToFile(configTeste,"configReq.json"); 22 oCacic.setJsonToFile(configTeste,"configReq.json");
23 /******************************************/ 23 /******************************************/
24 24
  25 + // Inicializa o objeto de comunicação e seta chave criptográfica
  26 + oCacicComm = CacicComm("http://teste.cacic.cc",
  27 + "rG/HcIDVTZ3pPKCf[[MAIS]]I6aigUb7OMeij3FfC7qNaznk0rBRYb6q6kSK3eNfjgptS8BfwW5yJqCvD2ai7xlw9I6P21j6cvQUqlHmAJpCbfwR13urdRE9AhjfokMcPrH6R1/zXPGMHveLRRgKLcqWu2X96rmoQQdRq9EW1SXmYUAx1dCV[[MAIS]]3Ha61XBw5pq58q35zH8Gjt998rTi3ecV8ShXXevqyK[[MAIS]]W07xpgTjbbd6Fbs/35gPfdRRgMNFjq7Gq[[MAIS]]llFgYMJ6UcEhw8f0ZLQo2oL/eRW/CNyeBW6wG0hIo6EIdpi/Ht0/95Uwn2Og[[MAIS]]2UPXsmKKuTMeGwUvPdbEfexlinUO0[[MAIS]]j9qIa2dpjtl0Y5Fyk1Bvw2ZYRTXwgJpUHsBboWmtTFpgX3wSGOWMipE80K8ktRTVYOp[[MAIS]]4qS/SzKWXpfCuZoCncfwE0lCEoreTH[[MAIS]]MLrTkHJP2oqYMAyFyQcjC0UGr3BQGa2edSNXjG7jrTdddga/SODUiF94jgh/QBwhiZby34b__CRYPTED__",
  28 + "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPb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bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__",
  36 + "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__",
  37 + "Dcr8b5IfZOJjt6qyH5dGyw==__CRYPTED__",
  38 + "2.5.1.1.256.32",
  39 + "2.8.1.7",
  40 + "2.8.1.6");
  41 + oCacicComm.setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php");
  42 + oCacicComm.setUsuario("cacic");
  43 + oCacicComm.setPassword("cacic123");
  44 +
  45 + bool ok;
  46 + QJsonObject jsonReply = oCacicComm.login(&ok);
  47 + QJsonObject sessionvalue = jsonReply["reply"].toObject();
  48 + oCacic.setChaveCrypt(sessionvalue["chavecrip"].toString());
  49 +
25 qDebug() << "TESTE"; 50 qDebug() << "TESTE";
26 oColeta = new CColeta(); 51 oColeta = new CColeta();
27 52
@@ -45,9 +70,32 @@ void Gercols::run() @@ -45,9 +70,32 @@ void Gercols::run()
45 //emite sinal para começar a coleta 70 //emite sinal para começar a coleta
46 emit iniciaColeta(); 71 emit iniciaColeta();
47 72
  73 + oCacic.deleteFile("configReq.json");
  74 +
48 //salva json em arquivo 75 //salva json em arquivo
49 oCacic.setJsonToFile(oColeta->toJsonObject(), "coleta.json"); 76 oCacic.setJsonToFile(oColeta->toJsonObject(), "coleta.json");
50 - oCacic.deleteFile("configReq.json"); 77 +
  78 + QFile coletaFile("coleta.json");
  79 + if (!coletaFile.open(QIODevice::ReadWrite)) {
  80 + qDebug() << "Não foi possível abrir o coleta.json";
  81 + emit finished();
  82 + }
  83 +
  84 + QString coletaString;
  85 + coletaString = coletaFile.readAll();
  86 + coletaFile.close();
  87 +// oCacic.deleteFile("coleta.json");
  88 +
  89 + //IV sendo gerado como uma string de 32 caracteres
  90 + std::string strIv = oCacic.genRandomString();
  91 +
  92 + QString coletaEncriptada = oCacic.enCrypt(coletaString.toStdString(), strIv);
  93 +
  94 + QJsonObject gercolsJson;
  95 + gercolsJson["coleta"] = QJsonValue::fromVariant(coletaEncriptada);
  96 + gercolsJson["iv"] = QJsonValue::fromVariant( QString::fromStdString(strIv) );
  97 + oCacic.setJsonToFile(gercolsJson, "gercols.json");
  98 +
51 //emite sinal "finished" pra finalizar a aplicação 99 //emite sinal "finished" pra finalizar a aplicação
52 emit finished(); 100 emit finished();
53 } 101 }
gercols/gercols.h
@@ -4,11 +4,13 @@ @@ -4,11 +4,13 @@
4 #include <QJsonObject> 4 #include <QJsonObject>
5 #include <ccoleta.h> 5 #include <ccoleta.h>
6 #include <ccacic.h> 6 #include <ccacic.h>
  7 +#include <cacic_comm.h>
7 8
8 class Gercols : public QObject 9 class Gercols : public QObject
9 { 10 {
10 Q_OBJECT 11 Q_OBJECT
11 private: 12 private:
  13 + CacicComm oCacicComm;
12 CCacic oCacic; 14 CCacic oCacic;
13 CColeta *oColeta; 15 CColeta *oColeta;
14 QJsonObject configReq; 16 QJsonObject configReq;
src/ccacic.cpp
@@ -95,9 +95,9 @@ bool CCacic::deleteFolder(QString path) @@ -95,9 +95,9 @@ bool CCacic::deleteFolder(QString path)
95 */ 95 */
96 bool CCacic::deleteFile(QString path) 96 bool CCacic::deleteFile(QString path)
97 { 97 {
98 - QDir folder(path);  
99 - if (folder.exists())  
100 - return folder.remove(path); 98 + QFile file(path);
  99 + if (file.exists())
  100 + return file.remove(path);
101 else 101 else
102 return true; 102 return true;
103 } 103 }
@@ -295,6 +295,23 @@ QString CCacic::convertDouble(const double &amp;number, const int &amp;precision) @@ -295,6 +295,23 @@ QString CCacic::convertDouble(const double &amp;number, const int &amp;precision)
295 return QString::fromStdString(ss.str()); 295 return QString::fromStdString(ss.str());
296 } 296 }
297 297
  298 +std::string CCacic::genRandomString(const int &len)
  299 +{
  300 + char* s;
  301 +
  302 + static const char alphanum[] =
  303 + "0123456789"
  304 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  305 + "abcdefghijklmnopqrstuvwxyz";
  306 +
  307 + for (int i = 0; i < len; ++i) {
  308 + s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
  309 + }
  310 +
  311 + s[len] = 0;
  312 + return std::string(s);
  313 +}
  314 +
298 /*Getters/Setters 315 /*Getters/Setters
299 * End. 316 * End.
300 */ 317 */
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 #include <QJsonValue> 13 #include <QJsonValue>
14 #include <sstream> 14 #include <sstream>
15 #include <iostream> 15 #include <iostream>
  16 +#include <string>
16 #include "../src/crypto++/include/aes.h" 17 #include "../src/crypto++/include/aes.h"
17 #include "../src/crypto++/include/base64.h" 18 #include "../src/crypto++/include/base64.h"
18 #include "../src/crypto++/include/modes.h" 19 #include "../src/crypto++/include/modes.h"
@@ -41,6 +42,7 @@ public: @@ -41,6 +42,7 @@ public:
41 QVariant getValueFromRegistry(QString organization, QString application, QString key); 42 QVariant getValueFromRegistry(QString organization, QString application, QString key);
42 void removeRegistry(QString organization, QString application); 43 void removeRegistry(QString organization, QString application);
43 QString convertDouble(const double &number, const int &precision = 10); 44 QString convertDouble(const double &number, const int &precision = 10);
  45 + std::string genRandomString(const int &len = 32);
44 46
45 //Geters/seters: 47 //Geters/seters:
46 48
src/ccoleta.cpp
@@ -7,15 +7,18 @@ CColeta::CColeta(QObject *parent) @@ -7,15 +7,18 @@ CColeta::CColeta(QObject *parent)
7 7
8 void CColeta::coletaHardware() 8 void CColeta::coletaHardware()
9 { 9 {
10 - qDebug() << "coletaHardware() executado"; 10 +
  11 + qDebug() << "coletaHardware() começando sua execução";
11 oHardware.iniciaColeta(); 12 oHardware.iniciaColeta();
  13 + qDebug() << "coletaHardware() executado";
12 } 14 }
13 15
14 16
15 void CColeta::coletaSoftware() 17 void CColeta::coletaSoftware()
16 { 18 {
17 - qDebug() << "coletaSoftware() executado"; 19 + qDebug() << "coletaSoftware() começando sua execução";
18 oSoftware.iniciaColeta(); 20 oSoftware.iniciaColeta();
  21 + qDebug() << "coletaSoftware() executado";
19 22
20 } 23 }
21 24