From bb45c9b0b14a9f7268c25e97fb052ca37ca8ea0d Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Tue, 5 Aug 2014 14:14:13 -0300 Subject: [PATCH] Pequenas alterações --- cacic-teste/cacic-teste.pro | 6 ++++-- cacic-teste/testcacic.cpp | 23 +++++++++++++---------- cacic-teste/testcacic.h | 12 +++++++----- src/CACIC_comm.h | 2 +- src/cacic_computer.cpp | 29 +++++++++++++++++++++++------ src/cacic_computer.h | 15 ++++++--------- src/ccacic.cpp | 68 +++++++++++++++++++++----------------------------------------------- src/ccacic.h | 11 ++++------- 8 files changed, 79 insertions(+), 87 deletions(-) diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index 1ce5c40..f9ce92b 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -12,9 +12,9 @@ CONFIG -= app_bundle CONFIG += c++11 TEMPLATE = app win32 { -LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp + LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp } else { -LIBS += -L/usr/lib -lcryptopp + LIBS += -L/usr/lib -lcryptopp } SOURCES += \ @@ -27,3 +27,5 @@ HEADERS += \ ../src/ccacic.h \ ../src/cacic_computer.h \ ../src/cacic_comm.h + +INCLUDEPATH += ../src diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 11a1520..f75fa15 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -70,29 +70,32 @@ void CTestCacic::testDeleteFolder() } void CTestCacic::testEnCrypt(){ - QString key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) - QString IV = "0123456789123456"; //iv nunca se repete para a mesma senha. - QString input = "aqui vai a url que sera encriptada"; + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) + std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. + std::string input = "aqui vai a url que sera encriptada"; QVERIFY(OCacic.enCrypt(input, key, IV) == "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="); } void CTestCacic::testDeCrypt(){ - QString key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) - QString IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. - QString input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) + std::string IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. + std::string input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; QVERIFY(OCacic.deCrypt(input, key, IV) == "aqui vai a url que sera encriptada"); } void CTestCacic::testInterfaceDeRede(){ // qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); - QVERIFY(!OCacicComp.getNetworkInterface().empty()); + QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); } void CTestCacic::testpegarOS(){ QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); } -//void CTestCacic::testJson(){ -// OCacic.readJson(); -//} +void CTestCacic::testSslConnection() +{ + OSslComm.start("127.0.0.1", 8888); + QVERIFY(false); +} + diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index dd4e55a..ca0664a 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -1,15 +1,16 @@ #ifndef TESTINSTALLCACIC_H #define TESTINSTALLCACIC_H -#include "../src/CACIC_comm.h" -#include "../src/ccacic.h" -#include "../src/cacic_computer.h" + +#include +#include +#include #include #include #include #include #include #include -#include +#include class CTestCacic : public QObject { @@ -23,6 +24,7 @@ private: CACIC_Computer OCacicComp; QString testPath; QString testIniPath; + CSslComm OSslComm; signals: @@ -40,7 +42,7 @@ private slots: void testDeleteFile(); void testInterfaceDeRede(); void testpegarOS(); -// void testJson(); + void testSslConnection(); }; #endif // TESTINSTALLCACIC_H diff --git a/src/CACIC_comm.h b/src/CACIC_comm.h index 6b440dd..2e12d5d 100644 --- a/src/CACIC_comm.h +++ b/src/CACIC_comm.h @@ -99,7 +99,7 @@ public: QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){ - // qDebug() << "Status:" << codigoStatus.toInt() << reason; + qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason; return true; }else{ reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); diff --git a/src/cacic_computer.cpp b/src/cacic_computer.cpp index 02e4997..5e056f3 100644 --- a/src/cacic_computer.cpp +++ b/src/cacic_computer.cpp @@ -1,22 +1,30 @@ #include "cacic_computer.h" -CACIC_Computer::CACIC_Computer(QObject *parent) : - QObject(parent) +CACIC_Computer::CACIC_Computer() { os = pegarOS(); networkInterface = networkInterfacesRunning(); } +/*NetworkInterfacesRunning + * @return: QList>. + * Retorna todas as interfaces com seus IP's, nome e MAC. + * Cada uma é salva em uma lista que também será salva em + * outra lista que conterá todas as interfaces. + * + */ QList> CACIC_Computer::networkInterfacesRunning(){ QNetworkInterface interface; QList lista; QList> todasInterfaces; foreach (QNetworkInterface in, interface.allInterfaces()) { - if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) & - !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) & + if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && (bool)(in.flags() & QNetworkInterface::IsRunning)){ +// qDebug() << in.humanReadableName() << "\n"; lista.append(in.humanReadableName().toStdString()); +// qDebug() << in.hardwareAddress() << "\n"; lista.append(in.hardwareAddress().toStdString()); foreach (QNetworkAddressEntry ae, in.addressEntries()){ if (ae.ip().scopeId() == ""){ @@ -24,6 +32,7 @@ QList> CACIC_Computer::networkInterfacesRunning(){ } else { lista.append(ae.ip().toString().toStdString()); } +// qDebug() << ae.ip().toString() << "\n"; } todasInterfaces.append(lista); lista.clear(); @@ -32,11 +41,21 @@ QList> CACIC_Computer::networkInterfacesRunning(){ return todasInterfaces; } +/*pegarOS + * @return: std::string; + * retorna uma string o qual dirá qual so é. + * + */ std::string CACIC_Computer::pegarOS(){ QString text; QStringList environment = QProcess::systemEnvironment(); foreach (text, environment) { if (text.contains("OS=", Qt::CaseInsensitive)){ + if ((QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8) && + (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8_1)) +// qDebug () << "win 8"; + else if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8_1) +// qDebug() << "win 8.1"; return text.mid(text.indexOf("=")+1).toStdString(); } //implementar o if pra quando for linux. @@ -57,5 +76,3 @@ QList> CACIC_Computer::getNetworkInterface() const return networkInterface; } - - diff --git a/src/cacic_computer.h b/src/cacic_computer.h index 0097b59..0851af0 100644 --- a/src/cacic_computer.h +++ b/src/cacic_computer.h @@ -6,12 +6,12 @@ #include #include #include +#include -class CACIC_Computer : public QObject +class CACIC_Computer { - Q_OBJECT public: - explicit CACIC_Computer(QObject *parent = 0); + CACIC_Computer(); std::string pegarOS(); std::string getOs() const; @@ -19,14 +19,11 @@ public: QList> networkInterfacesRunning(); private: - QList> networkInterface; + QList> networkInterface; std::string os; -signals: - -public slots: - - }; +Q_DECLARE_METATYPE(CACIC_Computer) +Q_DECLARE_METATYPE(CACIC_Computer*) #endif // CACIC_COMPUTER_H diff --git a/src/ccacic.cpp b/src/ccacic.cpp index 343fed0..b3ec8cd 100644 --- a/src/ccacic.cpp +++ b/src/ccacic.cpp @@ -66,7 +66,8 @@ QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagTyp tag = tagType.mid(0,1) + tag + tagType.mid(1); tagSize = tag.size(); return fullString.mid(fullString.indexOf(tag) + tagSize, - fullString.indexOf(tagFim) - (fullString.indexOf(tag) + tagSize)).trimmed(); + fullString.indexOf(tagFim) - + (fullString.indexOf(tag) + tagSize)).trimmed(); } /*createFolder * @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) } /*enCrypt - * @parameter QString str_in: string que será encriptada (url). - * QString key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits + * @parameter std::string str_in: string que será encriptada (url). + * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty - * QString iv: IV (Vetor de Inicialização) deve ser aleatório. + * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. * (http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) * exemplo de iv: 0123456789123456 * @return std:string: retorna a string encriptada convertida em base64. * */ -QString CCacic::enCrypt(QString str_in, QString key, QString iv) { +std::string CCacic::enCrypt(std::string str_in, std::string key, std::string iv) { std::string str_out; - CryptoPP::CFB_Mode::Encryption encryption((byte*)key.toStdString().c_str(), key.length(), (byte*)iv.toStdString().c_str()); - CryptoPP::StringSource encryptor(str_in.toStdString(), true, + CryptoPP::CFB_Mode::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); + CryptoPP::StringSource encryptor(str_in, true, new CryptoPP::StreamTransformationFilter(encryption, new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), false // do not append a newline @@ -122,59 +123,32 @@ QString CCacic::enCrypt(QString str_in, QString key, QString iv) { ) ); //qDebug(QString::fromStdString(str_out).toLocal8Bit()); - return QString::fromStdString(str_out).toLocal8Bit(); + return str_out; } /*deCrypt - * @parameter QString str_in: string encriptada convertida em base64. - * QString key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits + * @parameter std::string str_in: string encriptada convertida em base64. + * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty - * QString iv: IV (Vetor de Inicialização) deve ser aleatório. + * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) * *exemplo de iv: 0123456789123456 * @return QString: retorna a string desencriptada convertida em base64. * */ -QString CCacic::deCrypt(QString str_in, QString key, QString iv) { +std::string CCacic::deCrypt(std::string str_in, std::string key, std::string iv) { std::string str_out; - CryptoPP::CFB_Mode::Decryption decryption((byte*)key.toStdString().c_str(), key.length(), (byte*)iv.toStdString().c_str()); + CryptoPP::CFB_Mode::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); - CryptoPP::StringSource decryptor(str_in.toStdString(), true, - new CryptoPP::Base64Decoder( - new CryptoPP::StreamTransformationFilter(decryption, - new CryptoPP::StringSink(str_out) - ) - ) - ); - return QString::fromStdString(str_out).toLocal8Bit(); + CryptoPP::StringSource decryptor(str_in, true, + new CryptoPP::Base64Decoder( + new CryptoPP::StreamTransformationFilter(decryption, + new CryptoPP::StringSink(str_out)) + ) + ); + return str_out; } -//void CCacic::readJson() -//{ -// QString val; -// QFile file; -// file.setFileName("e:/Lightbase/teste.json"); -// file.open(QIODevice::ReadOnly | QIODevice::Text); -// val = file.readAll(); -// file.close(); -// qWarning() << val; -// QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); -// QJsonObject sett2 = d.object(); -// QJsonValue value = sett2.value(QString("appName")); -// qWarning() << value; -// QJsonObject item = value.toObject(); -// qWarning() << tr("QJsonObject of description: ") << item; - -// /* incase of string value get value and convert into string*/ -// qWarning() << tr("QJsonObject[appName] of description: ") << item["description"]; -// QJsonValue subobj = item["description"]; -// qWarning() << subobj.toString(); - -// /* incase of array get array and convert into string*/ -// qWarning() << tr("QJsonObject[appName] of value: ") << item["imp"]; -// QJsonArray test = item["imp"].toArray(); -// qWarning() << test[1].toString(); -//} /*Getters/Setters * Begin: diff --git a/src/ccacic.h b/src/ccacic.h index ef5027c..b54c0c1 100644 --- a/src/ccacic.h +++ b/src/ccacic.h @@ -1,5 +1,6 @@ #ifndef CCACIC_H #define CCACIC_H + #include #include #include @@ -12,11 +13,8 @@ #include "crypto++/include/md5.h" #include #include -#include -#include -#include #include - +//#include class CCacic : public QObject { Q_OBJECT @@ -25,12 +23,11 @@ public: QString getValueFromFile(QString sectionName, QString keyName, QString filePath); void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath); QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]"); - QString enCrypt(QString str_in, QString key, QString iv); - QString deCrypt(QString str_in, QString key, QString iv); + std::string enCrypt(std::string str_in, std::string key, std::string iv); + std::string deCrypt(std::string str_in, std::string key, std::string iv); bool createFolder(QString path); bool deleteFolder(QString path); bool deleteFile(QString path); -// void readJson(); //Geters/seters: -- libgit2 0.21.2