Commit bb45c9b0b14a9f7268c25e97fb052ca37ca8ea0d
1 parent
ec33ae2c
Exists in
master
Pequenas alterações
Showing
8 changed files
with
79 additions
and
87 deletions
Show diff stats
cacic-teste/cacic-teste.pro
... | ... | @@ -12,9 +12,9 @@ CONFIG -= app_bundle |
12 | 12 | CONFIG += c++11 |
13 | 13 | TEMPLATE = app |
14 | 14 | win32 { |
15 | -LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | |
15 | + LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | |
16 | 16 | } else { |
17 | -LIBS += -L/usr/lib -lcryptopp | |
17 | + LIBS += -L/usr/lib -lcryptopp | |
18 | 18 | } |
19 | 19 | |
20 | 20 | SOURCES += \ |
... | ... | @@ -27,3 +27,5 @@ HEADERS += \ |
27 | 27 | ../src/ccacic.h \ |
28 | 28 | ../src/cacic_computer.h \ |
29 | 29 | ../src/cacic_comm.h |
30 | + | |
31 | +INCLUDEPATH += ../src | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -70,29 +70,32 @@ void CTestCacic::testDeleteFolder() |
70 | 70 | } |
71 | 71 | |
72 | 72 | void CTestCacic::testEnCrypt(){ |
73 | - QString key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
74 | - QString IV = "0123456789123456"; //iv nunca se repete para a mesma senha. | |
75 | - QString input = "aqui vai a url que sera encriptada"; | |
73 | + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
74 | + std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. | |
75 | + std::string input = "aqui vai a url que sera encriptada"; | |
76 | 76 | QVERIFY(OCacic.enCrypt(input, key, IV) == "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="); |
77 | 77 | } |
78 | 78 | |
79 | 79 | void CTestCacic::testDeCrypt(){ |
80 | - QString key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
81 | - QString IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. | |
82 | - QString input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; | |
80 | + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
81 | + std::string IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. | |
82 | + std::string input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; | |
83 | 83 | QVERIFY(OCacic.deCrypt(input, key, IV) == "aqui vai a url que sera encriptada"); |
84 | 84 | |
85 | 85 | } |
86 | 86 | |
87 | 87 | void CTestCacic::testInterfaceDeRede(){ |
88 | 88 | // qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); |
89 | - QVERIFY(!OCacicComp.getNetworkInterface().empty()); | |
89 | + QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); | |
90 | 90 | } |
91 | 91 | |
92 | 92 | void CTestCacic::testpegarOS(){ |
93 | 93 | QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); |
94 | 94 | } |
95 | 95 | |
96 | -//void CTestCacic::testJson(){ | |
97 | -// OCacic.readJson(); | |
98 | -//} | |
96 | +void CTestCacic::testSslConnection() | |
97 | +{ | |
98 | + OSslComm.start("127.0.0.1", 8888); | |
99 | + QVERIFY(false); | |
100 | +} | |
101 | + | ... | ... |
cacic-teste/testcacic.h
1 | 1 | #ifndef TESTINSTALLCACIC_H |
2 | 2 | #define TESTINSTALLCACIC_H |
3 | -#include "../src/CACIC_comm.h" | |
4 | -#include "../src/ccacic.h" | |
5 | -#include "../src/cacic_computer.h" | |
3 | + | |
4 | +#include <cacic_comm.h> | |
5 | +#include <ccacic.h> | |
6 | +#include <cacic_computer.h> | |
6 | 7 | #include <QtTest/QtTest> |
7 | 8 | #include <QDebug> |
8 | 9 | #include <QList> |
9 | 10 | #include <QProcess> |
10 | 11 | #include <QStringList> |
11 | 12 | #include <iostream> |
12 | -#include <QHostAddress> | |
13 | +#include <csslcomm.h> | |
13 | 14 | |
14 | 15 | class CTestCacic : public QObject |
15 | 16 | { |
... | ... | @@ -23,6 +24,7 @@ private: |
23 | 24 | CACIC_Computer OCacicComp; |
24 | 25 | QString testPath; |
25 | 26 | QString testIniPath; |
27 | + CSslComm OSslComm; | |
26 | 28 | |
27 | 29 | signals: |
28 | 30 | |
... | ... | @@ -40,7 +42,7 @@ private slots: |
40 | 42 | void testDeleteFile(); |
41 | 43 | void testInterfaceDeRede(); |
42 | 44 | void testpegarOS(); |
43 | -// void testJson(); | |
45 | + void testSslConnection(); | |
44 | 46 | }; |
45 | 47 | |
46 | 48 | #endif // TESTINSTALLCACIC_H | ... | ... |
src/CACIC_comm.h
... | ... | @@ -99,7 +99,7 @@ public: |
99 | 99 | |
100 | 100 | QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); |
101 | 101 | if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){ |
102 | - // qDebug() << "Status:" << codigoStatus.toInt() << reason; | |
102 | + qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason; | |
103 | 103 | return true; |
104 | 104 | }else{ |
105 | 105 | reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); | ... | ... |
src/cacic_computer.cpp
1 | 1 | #include "cacic_computer.h" |
2 | 2 | |
3 | -CACIC_Computer::CACIC_Computer(QObject *parent) : | |
4 | - QObject(parent) | |
3 | +CACIC_Computer::CACIC_Computer() | |
5 | 4 | { |
6 | 5 | os = pegarOS(); |
7 | 6 | networkInterface = networkInterfacesRunning(); |
8 | 7 | } |
9 | 8 | |
9 | +/*NetworkInterfacesRunning | |
10 | + * @return: QList<QList<std::string>>. | |
11 | + * Retorna todas as interfaces com seus IP's, nome e MAC. | |
12 | + * Cada uma é salva em uma lista que também será salva em | |
13 | + * outra lista que conterá todas as interfaces. | |
14 | + * | |
15 | + */ | |
10 | 16 | QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
11 | 17 | QNetworkInterface interface; |
12 | 18 | QList<std::string> lista; |
13 | 19 | QList<QList<std::string>> todasInterfaces; |
14 | 20 | |
15 | 21 | foreach (QNetworkInterface in, interface.allInterfaces()) { |
16 | - if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) & | |
17 | - !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) & | |
22 | + if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && | |
23 | + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && | |
18 | 24 | (bool)(in.flags() & QNetworkInterface::IsRunning)){ |
25 | +// qDebug() << in.humanReadableName() << "\n"; | |
19 | 26 | lista.append(in.humanReadableName().toStdString()); |
27 | +// qDebug() << in.hardwareAddress() << "\n"; | |
20 | 28 | lista.append(in.hardwareAddress().toStdString()); |
21 | 29 | foreach (QNetworkAddressEntry ae, in.addressEntries()){ |
22 | 30 | if (ae.ip().scopeId() == ""){ |
... | ... | @@ -24,6 +32,7 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
24 | 32 | } else { |
25 | 33 | lista.append(ae.ip().toString().toStdString()); |
26 | 34 | } |
35 | +// qDebug() << ae.ip().toString() << "\n"; | |
27 | 36 | } |
28 | 37 | todasInterfaces.append(lista); |
29 | 38 | lista.clear(); |
... | ... | @@ -32,11 +41,21 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
32 | 41 | return todasInterfaces; |
33 | 42 | } |
34 | 43 | |
44 | +/*pegarOS | |
45 | + * @return: std::string; | |
46 | + * retorna uma string o qual dirá qual so é. | |
47 | + * | |
48 | + */ | |
35 | 49 | std::string CACIC_Computer::pegarOS(){ |
36 | 50 | QString text; |
37 | 51 | QStringList environment = QProcess::systemEnvironment(); |
38 | 52 | foreach (text, environment) { |
39 | 53 | if (text.contains("OS=", Qt::CaseInsensitive)){ |
54 | + if ((QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8) && | |
55 | + (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8_1)) | |
56 | +// qDebug () << "win 8"; | |
57 | + else if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8_1) | |
58 | +// qDebug() << "win 8.1"; | |
40 | 59 | return text.mid(text.indexOf("=")+1).toStdString(); |
41 | 60 | } |
42 | 61 | //implementar o if pra quando for linux. |
... | ... | @@ -57,5 +76,3 @@ QList<QList<std::string>> CACIC_Computer::getNetworkInterface() const |
57 | 76 | return networkInterface; |
58 | 77 | } |
59 | 78 | |
60 | - | |
61 | - | ... | ... |
src/cacic_computer.h
... | ... | @@ -6,12 +6,12 @@ |
6 | 6 | #include <QtSerialPort/QtSerialPort> |
7 | 7 | #include <QtSerialPort/QSerialPortInfo> |
8 | 8 | #include <QtNetwork/QtNetwork> |
9 | +#include <QSysInfo> | |
9 | 10 | |
10 | -class CACIC_Computer : public QObject | |
11 | +class CACIC_Computer | |
11 | 12 | { |
12 | - Q_OBJECT | |
13 | 13 | public: |
14 | - explicit CACIC_Computer(QObject *parent = 0); | |
14 | + CACIC_Computer(); | |
15 | 15 | |
16 | 16 | std::string pegarOS(); |
17 | 17 | std::string getOs() const; |
... | ... | @@ -19,14 +19,11 @@ public: |
19 | 19 | QList<QList<std::string>> networkInterfacesRunning(); |
20 | 20 | |
21 | 21 | private: |
22 | - QList<QList<std::string>> networkInterface; | |
22 | + QList<QList<std::string>> networkInterface; | |
23 | 23 | std::string os; |
24 | 24 | |
25 | -signals: | |
26 | - | |
27 | -public slots: | |
28 | - | |
29 | - | |
30 | 25 | }; |
31 | 26 | |
27 | +Q_DECLARE_METATYPE(CACIC_Computer) | |
28 | +Q_DECLARE_METATYPE(CACIC_Computer*) | |
32 | 29 | #endif // CACIC_COMPUTER_H | ... | ... |
src/ccacic.cpp
... | ... | @@ -66,7 +66,8 @@ QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagTyp |
66 | 66 | tag = tagType.mid(0,1) + tag + tagType.mid(1); |
67 | 67 | tagSize = tag.size(); |
68 | 68 | return fullString.mid(fullString.indexOf(tag) + tagSize, |
69 | - fullString.indexOf(tagFim) - (fullString.indexOf(tag) + tagSize)).trimmed(); | |
69 | + fullString.indexOf(tagFim) - | |
70 | + (fullString.indexOf(tag) + tagSize)).trimmed(); | |
70 | 71 | } |
71 | 72 | /*createFolder |
72 | 73 | * @parameter QString path: caminho onde será criado o diretório, sendo criado toda a árvore se necessário. |
... | ... | @@ -103,18 +104,18 @@ bool CCacic::deleteFile(QString path) |
103 | 104 | } |
104 | 105 | |
105 | 106 | /*enCrypt |
106 | - * @parameter QString str_in: string que será encriptada (url). | |
107 | - * QString key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | |
107 | + * @parameter std::string str_in: string que será encriptada (url). | |
108 | + * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | |
108 | 109 | * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty |
109 | - * QString iv: IV (Vetor de Inicialização) deve ser aleatório. | |
110 | + * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. | |
110 | 111 | * (http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) |
111 | 112 | * exemplo de iv: 0123456789123456 |
112 | 113 | * @return std:string: retorna a string encriptada convertida em base64. |
113 | 114 | * */ |
114 | -QString CCacic::enCrypt(QString str_in, QString key, QString iv) { | |
115 | +std::string CCacic::enCrypt(std::string str_in, std::string key, std::string iv) { | |
115 | 116 | std::string str_out; |
116 | - CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.toStdString().c_str(), key.length(), (byte*)iv.toStdString().c_str()); | |
117 | - CryptoPP::StringSource encryptor(str_in.toStdString(), true, | |
117 | + CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | |
118 | + CryptoPP::StringSource encryptor(str_in, true, | |
118 | 119 | new CryptoPP::StreamTransformationFilter(encryption, |
119 | 120 | new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), |
120 | 121 | false // do not append a newline |
... | ... | @@ -122,59 +123,32 @@ QString CCacic::enCrypt(QString str_in, QString key, QString iv) { |
122 | 123 | ) |
123 | 124 | ); |
124 | 125 | //qDebug(QString::fromStdString(str_out).toLocal8Bit()); |
125 | - return QString::fromStdString(str_out).toLocal8Bit(); | |
126 | + return str_out; | |
126 | 127 | } |
127 | 128 | |
128 | 129 | /*deCrypt |
129 | - * @parameter QString str_in: string encriptada convertida em base64. | |
130 | - * QString key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | |
130 | + * @parameter std::string str_in: string encriptada convertida em base64. | |
131 | + * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | |
131 | 132 | * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty |
132 | - * QString iv: IV (Vetor de Inicialização) deve ser aleatório. | |
133 | + * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. | |
133 | 134 | * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. |
134 | 135 | * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) |
135 | 136 | * *exemplo de iv: 0123456789123456 |
136 | 137 | * @return QString: retorna a string desencriptada convertida em base64. |
137 | 138 | * */ |
138 | -QString CCacic::deCrypt(QString str_in, QString key, QString iv) { | |
139 | +std::string CCacic::deCrypt(std::string str_in, std::string key, std::string iv) { | |
139 | 140 | std::string str_out; |
140 | - CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.toStdString().c_str(), key.length(), (byte*)iv.toStdString().c_str()); | |
141 | + CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | |
141 | 142 | |
142 | - CryptoPP::StringSource decryptor(str_in.toStdString(), true, | |
143 | - new CryptoPP::Base64Decoder( | |
144 | - new CryptoPP::StreamTransformationFilter(decryption, | |
145 | - new CryptoPP::StringSink(str_out) | |
146 | - ) | |
147 | - ) | |
148 | - ); | |
149 | - return QString::fromStdString(str_out).toLocal8Bit(); | |
143 | + CryptoPP::StringSource decryptor(str_in, true, | |
144 | + new CryptoPP::Base64Decoder( | |
145 | + new CryptoPP::StreamTransformationFilter(decryption, | |
146 | + new CryptoPP::StringSink(str_out)) | |
147 | + ) | |
148 | + ); | |
149 | + return str_out; | |
150 | 150 | } |
151 | 151 | |
152 | -//void CCacic::readJson() | |
153 | -//{ | |
154 | -// QString val; | |
155 | -// QFile file; | |
156 | -// file.setFileName("e:/Lightbase/teste.json"); | |
157 | -// file.open(QIODevice::ReadOnly | QIODevice::Text); | |
158 | -// val = file.readAll(); | |
159 | -// file.close(); | |
160 | -// qWarning() << val; | |
161 | -// QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); | |
162 | -// QJsonObject sett2 = d.object(); | |
163 | -// QJsonValue value = sett2.value(QString("appName")); | |
164 | -// qWarning() << value; | |
165 | -// QJsonObject item = value.toObject(); | |
166 | -// qWarning() << tr("QJsonObject of description: ") << item; | |
167 | - | |
168 | -// /* incase of string value get value and convert into string*/ | |
169 | -// qWarning() << tr("QJsonObject[appName] of description: ") << item["description"]; | |
170 | -// QJsonValue subobj = item["description"]; | |
171 | -// qWarning() << subobj.toString(); | |
172 | - | |
173 | -// /* incase of array get array and convert into string*/ | |
174 | -// qWarning() << tr("QJsonObject[appName] of value: ") << item["imp"]; | |
175 | -// QJsonArray test = item["imp"].toArray(); | |
176 | -// qWarning() << test[1].toString(); | |
177 | -//} | |
178 | 152 | |
179 | 153 | /*Getters/Setters |
180 | 154 | * Begin: | ... | ... |
src/ccacic.h
1 | 1 | #ifndef CCACIC_H |
2 | 2 | #define CCACIC_H |
3 | + | |
3 | 4 | #include <QCoreApplication> |
4 | 5 | #include <QObject> |
5 | 6 | #include <QFile> |
... | ... | @@ -12,11 +13,8 @@ |
12 | 13 | #include "crypto++/include/md5.h" |
13 | 14 | #include <QSettings> |
14 | 15 | #include <QDir> |
15 | -#include <QJsonObject> | |
16 | -#include <QJsonParseError> | |
17 | -#include <QJsonArray> | |
18 | 16 | #include <QDebug> |
19 | - | |
17 | +//#include <jvson.h> | |
20 | 18 | class CCacic : public QObject |
21 | 19 | { |
22 | 20 | Q_OBJECT |
... | ... | @@ -25,12 +23,11 @@ public: |
25 | 23 | QString getValueFromFile(QString sectionName, QString keyName, QString filePath); |
26 | 24 | void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath); |
27 | 25 | QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]"); |
28 | - QString enCrypt(QString str_in, QString key, QString iv); | |
29 | - QString deCrypt(QString str_in, QString key, QString iv); | |
26 | + std::string enCrypt(std::string str_in, std::string key, std::string iv); | |
27 | + std::string deCrypt(std::string str_in, std::string key, std::string iv); | |
30 | 28 | bool createFolder(QString path); |
31 | 29 | bool deleteFolder(QString path); |
32 | 30 | bool deleteFile(QString path); |
33 | -// void readJson(); | |
34 | 31 | |
35 | 32 | //Geters/seters: |
36 | 33 | ... | ... |