diff --git a/include/common/licenceCommon.h b/include/common/licenceCommon.h index 639e9f2..5b323a8 100644 --- a/include/common/licenceCommon.h +++ b/include/common/licenceCommon.h @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace std; @@ -178,52 +179,57 @@ struct LicenceItem31 struct LicenceInfo { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; /// @brief základní struktura, seznam polozek licencí, kompatibilita 1 struct LicenceInfoCompatibility1 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; -/// @brief základní struktura, seznam polozek licencí, kompatibilita 1 +/// @brief základní struktura, seznam polozek licencí, kompatibilita 2 struct LicenceInfoCompatibility2 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; /// @brief základní struktura, seznam polozek licencí, kompatibilita 3 struct LicenceInfoCompatibility3 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; +}; + +struct LicenceInfo1 +{ + bool isValid {false}; }; struct LicenceInfo11 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; struct LicenceInfo21 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; struct LicenceInfo31 { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; struct LicenceInfoGeneral { int reqDataPointsCount = 0; - map licences = {}; + unordered_map licences = {}; }; class LicenceException : public std::exception diff --git a/include/common/utils.h b/include/common/utils.h index 9908c0e..86aba2c 100644 --- a/include/common/utils.h +++ b/include/common/utils.h @@ -40,11 +40,8 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char * string convertToString(char* a, int size); string base64_encode_ai(const std::string &input); unordered_map getArguments(int argc, char *argv[]); -char* getCharArray(string source); -void getCharsFromString1(string source, char *charArray); void getCharsFromString(string& source, char *charArray, size_t length); string getCompletePath(string fileName); -char* getFileContent(string fileName); void appendStringToVector(const std::string& str, std::vector& charVector); uint16_t calculateCRC16(std::vector& charVector); uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4); diff --git a/include/reader/licReaderELC1.h b/include/reader/licReaderELC1.h index f054028..8e4e67a 100644 --- a/include/reader/licReaderELC1.h +++ b/include/reader/licReaderELC1.h @@ -1,9 +1,31 @@ #ifndef ELC1_READER__H #define ELC1_READER__H +#include "utils.h" +#include "licenceCommon.h" +#include "licenceELC1.h" +#include "SDCard.h" + +using namespace std; + namespace Reader { - + class Licence1 : public LicenceELC1 + { + public: + + LicenceInfo21 licenceInfo; + + Licence1(); + ~Licence1(); + Licence1(LicenceIdentification &licIdentification); + + bool readLicence(LicenceInfoGeneral *licences); + bool getLicenceInfo(void *ptr); + bool getLicenceItemInfo(int protocolId, void *returnItemStructure); + void getLicenceItems(); + + }; } #endif \ No newline at end of file diff --git a/include/reader/licenceReader.h b/include/reader/licenceReader.h index ead75d0..334c6ce 100644 --- a/include/reader/licenceReader.h +++ b/include/reader/licenceReader.h @@ -2,8 +2,6 @@ #define LICENCE_READER_H_ #include "utils.h" -#include "licenceELC11.h" -#include "licenceELC31.h" #include "licReaderELC1.h" #include "licReaderELC2.h" @@ -31,9 +29,9 @@ public: string operationErrors = ""; bool argumentsCorrect = false; ErrorMessage error; - LicenceELC11 *licence11; - LicenceELC31 *licence31; Licence2 *licence2; + Licence1 *licence1; + LicenceReader(); ~LicenceReader(); diff --git a/output/ezlic_eovosv0_cbheemcjsii.lic b/output/ezlic_eovosv0_cbheemcjsii.lic index 03a0106..d160b29 100644 Binary files a/output/ezlic_eovosv0_cbheemcjsii.lic and b/output/ezlic_eovosv0_cbheemcjsii.lic differ diff --git a/src/CreateLicence.cpp b/src/CreateLicence.cpp index a949f2f..3976ac3 100644 --- a/src/CreateLicence.cpp +++ b/src/CreateLicence.cpp @@ -5,7 +5,7 @@ /// @param argc /// @param argv parametry pro generování licence /// @return -int main(int argc, char *argv[]) +int main5(int argc, char *argv[]) { unordered_map arguments = getArguments(argc, argv); try diff --git a/src/LicenceELC11.cpp b/src/LicenceELC11.cpp index 7ce7551..81325bb 100644 --- a/src/LicenceELC11.cpp +++ b/src/LicenceELC11.cpp @@ -213,6 +213,7 @@ void LicenceELC11::initCrypto() memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8); } } + string LicenceELC11::getLicenceName() { string result = ""; diff --git a/src/ReadLicence.cpp b/src/ReadLicence.cpp index a1a4f90..3136c8f 100644 --- a/src/ReadLicence.cpp +++ b/src/ReadLicence.cpp @@ -1,38 +1,14 @@ #include -#include "utils.h" #include "licenceReader.h" - /// @brief hlavní funkce /// @param argc /// @param argv parametry pro generování licence /// @return -int main5() +int main() { - // unordered_map arguments = getArguments(argc, argv); - // try - // { - // unordered_map arguments = getArguments(argc, argv); - // LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]); - // generatorOld.createLicenceFile(); - // system("pause"); - // return SUCCES; - // } - // catch (...) - // { - // cerr << "Obecná chyba\n"; - // } - - // system("pause"); - // return SUCCES; - try { - - int protocolId = 444; - - LicenceReader licenceReader1 {}; - InitStructure initStructure; initStructure.licenceType = (int)LicenceType::EOS_EOV; initStructure.licenceVersion = 1; @@ -41,52 +17,77 @@ int main5() initStructure.licenceFilePath = ""; initStructure.cid_csd_filePath = ""; - cout << "-- verze #1: init a iterace" << "\n"; - - //verze #1: načtení kompletní licence a zobrazení - if (licenceReader1.init(2, initStructure)) + // verze původní ELC 1 + LicenceReader licenceReaderELC1{}; + if (licenceReaderELC1.initread(1, initStructure)) //iniciacni nacteni { - LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) - - if (licenceReader1.getLicenceInfo(&info)) + LicenceInfo1 info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false + if (licenceReaderELC1.getLicenceInfo(&info)) { - if (info.licences.count(protocolId) > 0) cout << "Počet z vectoru pro : " << protocolId << ": " << info.licences.at(protocolId) << endl; - cout << "Všechny licenční body: " << endl; - for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; } - } - else cout << "Došlo k chybě: " << licenceReader1.error.message; - } - else - { - cout << "Došlo k chybě: " << licenceReader1.error.message; - } - - cout << "\n" << "-- verze #2: init a iterace" << "\n"; - //verze #2 : iterace pro kazdý bod zvlášť - - LicenceReader licenceReader2 {}; - - if (licenceReader2.initread(2, initStructure)) - { - LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) - - if (licenceReader2.getLicenceItemInfo(protocolId, &info)) - { - std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl; + if (info.isValid) + cout << "Platna licence ELC1 \n"; + else + cout << "Neplatna licence ELC1\n"; } else - cout << "Došlo k chybě: " << licenceReader2.error.message; + cout << "CHYBA: " << licenceReaderELC1.error.message; } else { - cout << "Došlo k chybě: " << licenceReader2.error.message; + cout << "CHYBA: " << licenceReaderELC1.error.message; + } + + // verze ELC 2 pro jeden protokol + LicenceReader licenceReaderELC2{}; + + if (licenceReaderELC2.initread(2, initStructure)) //iniciacni nacteni + { + LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) + int protocolId = 444; + + if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info)) + { + cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl; + } + else + cout << "CHYBA: " << licenceReaderELC2.error.message; + } + else + { + cout << "CHYBA: " << licenceReaderELC2.error.message; + } + + LicenceReader licenceReaderCompleteELC2{}; + + // verze ELC 2 kompletní načtení + if (licenceReaderCompleteELC2.init(2, initStructure)) //iniciacni nacteni + { + LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) + int protocolId = 333; + + if (licenceReaderCompleteELC2.getLicenceInfo(&info)) + { + if (info.licences.count(protocolId) > 0) cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n"; + else cout << "Pro tento protokol nejsou definovay licencni body\n"; + cout << "Vypis vsech licencnich bodu: " << endl; + for (const auto &pair : info.licences) + { + std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; + } + } + else + cout << "CHYBA: " << licenceReaderCompleteELC2.error.message; + } + else + { + cout << "CHYBA: " << licenceReaderCompleteELC2.error.message; } } catch (...) { - cout << "Obecná chyba\n"; + cout << "Obecna chyba\n"; } - system("pause"); + // system("pause"); return SUCCES; } diff --git a/src/common/SDCard.cpp b/src/common/SDCard.cpp index e87eb74..0f313f6 100644 --- a/src/common/SDCard.cpp +++ b/src/common/SDCard.cpp @@ -8,20 +8,24 @@ SDCard::SDCard() SDCard::SDCard(const string cds_cid_Path) { this->filePath = cds_cid_Path; - if (getCIDFromFile() == false) return; - if (getCSDFromFile() == false) return; + if (getCIDFromFile() == false) + return; + if (getCSDFromFile() == false) + return; this->isLoaded = SDCard::readSDCard(); } SDCard::SDCard(string cid, string csd) { - for (unsigned int i = 0; i < cid.length(); i++) this->cid[i] = cid[i]; - for (unsigned int i = 0; i < csd.length(); i++) this->csd[i] = csd[i]; + for (unsigned int i = 0; i < cid.length(); i++) + this->cid[i] = cid[i]; + for (unsigned int i = 0; i < csd.length(); i++) + this->csd[i] = csd[i]; this->isLoaded = SDCard::readSDCard(); } -bool SDCard:: readSDCard() +bool SDCard::readSDCard() { BYTE cHexNibbleToNo[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -99,7 +103,6 @@ bool SDCard:: readSDCard() this->cardData.CRCOK = ((sdCrc << 1) | 1) == this->cardData.CID[15]; this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1); return this->cardData.crcCorrect; - } bool SDCard::getCIDFromFile() @@ -109,11 +112,14 @@ bool SDCard::getCIDFromFile() { return false; } - if (content.size() >= 32) + + if (content.size() >= CID_LENGTH) { - for (int i = 0; i<32;i++) this->cid[i] = content[i]; + for (int i = 0; i < 32; i++) + this->cid[i] = content[i]; } - else return false; + else + return false; return true; } @@ -125,11 +131,13 @@ bool SDCard::getCSDFromFile() { return false; } - if (content.size() >= 32) + if (content.size() >= CSD_LENGTH) { - for (int i = 0; i<32;i++) this->csd[i] = content[i]; + for (int i = 0; i < 32; i++) + this->csd[i] = content[i]; } - else return false; + else + return false; return true; } diff --git a/src/common/SDCard.o b/src/common/SDCard.o index d3d423e..cf5508e 100644 Binary files a/src/common/SDCard.o and b/src/common/SDCard.o differ diff --git a/src/common/licenceELC1.cpp b/src/common/licenceELC1.cpp index 931afe6..8edb22d 100644 --- a/src/common/licenceELC1.cpp +++ b/src/common/licenceELC1.cpp @@ -58,8 +58,7 @@ LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentifica bool LicenceELC1::getSDData() { - for (int i = 0; i < CID_LENGTH; i++) - this->sdData.CID_nibble[i] = (BYTE)cid[i]; + for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i]; for (int i = 0; i < cnibblescount / 2; i++) { @@ -91,12 +90,10 @@ bool LicenceELC1::getSDData() this->sdData.manufacturerDate[i] = date[i]; // CSD - for (unsigned int i = 0; i < CSD_LENGTH; i++) - this->sdData.CSD_nibble[i] = (BYTE)csd[i]; + for (unsigned int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i]; for (unsigned int i = 0; i < cnibblescount / 2; i++) { - // this->sdData.CSD[i] = cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i + 1]]; } @@ -104,10 +101,6 @@ bool LicenceELC1::getSDData() { this->sdData.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9]; this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048; - - if (this->sdData.cardSize > 17200) // TODO result.cardSize - { - } } BYTE sdCrc = 0; @@ -189,10 +182,6 @@ string LicenceELC1::getLicenceName(BYTE licPostfix) string result = ""; char prefixChar = 97; - if (licPostfix > 9) // chyba - { - } - if (licType == PlcLicenceType::LicenceOther) { result = "ezlic_"; diff --git a/src/common/licenceELC1.o b/src/common/licenceELC1.o index f08c9fb..6fb918a 100644 Binary files a/src/common/licenceELC1.o and b/src/common/licenceELC1.o differ diff --git a/src/common/licenceELC2.o b/src/common/licenceELC2.o index 06ffbf2..e385bae 100644 Binary files a/src/common/licenceELC2.o and b/src/common/licenceELC2.o differ diff --git a/src/generator/LicenceGenerator.o b/src/generator/LicenceGenerator.o index 9e8a809..c1ad612 100644 Binary files a/src/generator/LicenceGenerator.o and b/src/generator/LicenceGenerator.o differ diff --git a/src/generator/licGenELC1.o b/src/generator/licGenELC1.o index 024f9dc..7d8014f 100644 Binary files a/src/generator/licGenELC1.o and b/src/generator/licGenELC1.o differ diff --git a/src/generator/licGenELC2.o b/src/generator/licGenELC2.o index 65182a3..ed0c2cb 100644 Binary files a/src/generator/licGenELC2.o and b/src/generator/licGenELC2.o differ diff --git a/src/reader/LicenceReader.cpp b/src/reader/LicenceReader.cpp index 6ba77b9..5fdc5c8 100644 --- a/src/reader/LicenceReader.cpp +++ b/src/reader/LicenceReader.cpp @@ -60,7 +60,7 @@ LicenceReader::LicenceReader() // this->licIdentification.licCompatibility = compatibility; // } -/// @brief inicializace generátoru a načtení licenčních bodů +/// @brief inicializace generátoru a načtení licenčních bodů do obecné struktury /// @param elcType /// @param licenceType /// @param licenceVersion @@ -72,18 +72,28 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO try { elcSwitchType = elcType * 10 + licCompatibility; - + if (init(elcType, initStructure)) { switch (elcSwitchType) { case 11: { // old eoseov - LicenceELC11 licence = LicenceELC11(this->licIdentification); - this->licence11 = &licence; - licence.cid_cdsPath = initStructure.cid_csd_filePath; - licence.licenceFilePath = initStructure.licenceFilePath; - this->licence11->readLicence(&this->licenceInfo); + Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification); + this->licence1 = &licenceELC1; + licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath; + licenceELC1.licenceFilePath = initStructure.licenceFilePath; + + try + { + this->licence1->readLicence(&this->licenceInfo); + } + catch (const LicenceException &ex) + { + error.code = ex.getErrorCode(); + error.message = ex.getErrorMessage(); + return false; + } break; } case 21: @@ -93,12 +103,11 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath; licenceELC2.licenceFilePath = initStructure.licenceFilePath; this->licence2->readLicence(&this->licenceInfo); - break; } case 31: { - LicenceELC31 licence = LicenceELC31(this->licIdentification); + // LicenceELC31 licence = LicenceELC31(this->licIdentification); break; } } @@ -142,9 +151,13 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure) elcSwitchType = elcType * 10 + licCompatibility; - return true; // TODO testy + return true; } +/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury +/// @param protocolId +/// @param returnItemStructure +/// @return bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure) { try @@ -152,18 +165,14 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure switch (elcSwitchType) { case 11: - { // old eoseov - LicenceItem11 *resultPtr = static_cast(returnItemStructure); - resultPtr->protocolId = protocolId; - if (this->licenceInfo.licences.count(protocolId)) - resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId); - else - resultPtr->dataPointsCount = 0; + { + LicenceInfo1 *resultPtr = static_cast(returnItemStructure); + if (this->licenceInfo.licences.count(1)) resultPtr->isValid = true; //stare eov melo natvrdo "id" 1. + else resultPtr->isValid = false; break; } case 21: { - LicenceItem21 *resultPtr = static_cast(returnItemStructure); resultPtr->protocolId = protocolId; // protocolId; if (this->licenceInfo.licences.count(protocolId)) @@ -174,7 +183,7 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure } case 31: { - LicenceELC31 licence = LicenceELC31(this->licIdentification); + // LicenceELC31 licence = LicenceELC31(this->licIdentification); break; } default: @@ -195,66 +204,83 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure return true; } +/// @brief vrací informace o všech licenčních bodech základě předané návratové struktury +/// @param returnStructure +/// @return bool LicenceReader::getLicenceInfo(void *returnStructure) { - // const type_info& ti1 = typeid(returnStructure); - // cout << "TTTYP: " << ti1.name() << endl; - switch (elcSwitchType) + try { - case 11: - { // old eoseov - break; - } - case 21: - { - try + switch (elcSwitchType) { + case 11: + { // old eoseov + + LicenceInfo1 *resultPtr = static_cast(returnStructure); + + if (this->licenceInfo.licences.count(1)) + { + resultPtr->isValid = true; + } + else + { + resultPtr->isValid = false; + } + return true; + break; + } + case 21: + { + Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); licenceELC2.readLicence(&this->licenceInfo); return licenceELC2.getLicenceInfo(returnStructure); + + // catch (const LicenceException &ex) + // { + // error.code = ex.getErrorCode(); + // error.message = ex.getErrorMessage(); + // return false; + // } + + // LicenceELC21 licence = LicenceELC21(this->licIdentification); + // try + // { + // licence.readLicence(&this->licenceInfo); + // return licence.getLicenceInfo(returnStructure); + // } + // catch (const LicenceException &ex) + // { + // error.code = ex.getErrorCode(); + // error.message = ex.getErrorMessage(); + // return false; + // } + break; } - catch (const LicenceException &ex) + case 31: { - error.code = ex.getErrorCode(); - error.message = ex.getErrorMessage(); - return false; + // LicenceELC31 licence = LicenceELC31(this->licIdentification); + // try + // { + // licence.readLicence(); + // return licence.getLicenceInfo(returnStructure); + // } + // catch (const LicenceException &ex) + // { + // error.code = ex.getErrorCode(); + // error.message = ex.getErrorMessage(); + // return false; + // } + break; + } } - - // LicenceELC21 licence = LicenceELC21(this->licIdentification); - // try - // { - // licence.readLicence(&this->licenceInfo); - // return licence.getLicenceInfo(returnStructure); - // } - // catch (const LicenceException &ex) - // { - // error.code = ex.getErrorCode(); - // error.message = ex.getErrorMessage(); - // return false; - // } - break; } - case 31: + catch (const LicenceException &ex) { - LicenceELC31 licence = LicenceELC31(this->licIdentification); - // try - // { - // licence.readLicence(); - // return licence.getLicenceInfo(returnStructure); - // } - // catch (const LicenceException &ex) - // { - // error.code = ex.getErrorCode(); - // error.message = ex.getErrorMessage(); - // return false; - // } - break; + error.code = ex.getErrorCode(); + error.message = ex.getErrorMessage(); + return false; } - } - - error.code = -1; - error.message = "Nepodařilo se identifikovat licenci"; - return false; } LicenceReader::~LicenceReader() diff --git a/src/reader/LicenceReader.d b/src/reader/LicenceReader.d index 3983730..32a9821 100644 --- a/src/reader/LicenceReader.d +++ b/src/reader/LicenceReader.d @@ -1,8 +1,7 @@ src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \ include/reader/licenceReader.h include/common/utils.h \ - include/licenceELC11.h include/common/licenceCommon.h \ - include/common/SDCard.h include/licenceELC31.h \ - include/generator/pugixml.hpp include/generator/pugiconfig.hpp \ - include/reader/licReaderELC1.h include/reader/licReaderELC2.h \ - include/common/licenceELC2.h include/common/licenceCommon.h \ - include/common/SDCard.h include/reader/licReaderELC3.h + include/reader/licReaderELC1.h include/common/licenceCommon.h \ + include/common/licenceELC1.h include/common/licenceCommon.h \ + include/common/SDCard.h include/common/SDCard.h \ + include/reader/licReaderELC2.h include/common/licenceELC2.h \ + include/reader/licReaderELC3.h diff --git a/src/reader/LicenceReader.o b/src/reader/LicenceReader.o index 916576c..1bd4c51 100644 Binary files a/src/reader/LicenceReader.o and b/src/reader/LicenceReader.o differ diff --git a/src/reader/licReaderELC1.cpp b/src/reader/licReaderELC1.cpp index 209047c..52210e5 100644 --- a/src/reader/licReaderELC1.cpp +++ b/src/reader/licReaderELC1.cpp @@ -2,5 +2,126 @@ namespace Reader { + Licence1::Licence1() {} + + Licence1::~Licence1() {} + + Licence1::Licence1(LicenceIdentification &licIdentification) : LicenceELC1(licIdentification) + { + } + + bool Licence1::readLicence(LicenceInfoGeneral *licences) + { + sdCard = SDCard(this->cid_cdsPath); + if (sdCard.isLoaded == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); + for (unsigned int i = 0; i < CID_LENGTH;i++) this->cid[i] = sdCard.cid[i]; + for (unsigned int i = 0; i < CSD_LENGTH;i++) this->csd[i] = sdCard.csd[i]; + + if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); + + for (unsigned int i = 0; i < sdCard.cidString.length(); i++) + this->cid[i] = sdCard.cidString[i]; // nutné pro původní algoritmus + for (unsigned int i = 0; i < sdCard.csdString.length(); i++) + this->csd[i] = sdCard.csdString[i]; // nutné pro původní algoritmus + + string licFileName = getLicenceName(0); + string licFilePath = this->licenceFilePath + licFileName; + + char licFileNameToRead[licFilePath.length()+1] = {}; + getCharsFromString(licFilePath, licFileNameToRead, licFilePath.length()); + + FILE *licenceFile; + char ch; + + licenceFile = fopen(licFileNameToRead, "rb"); // read mode + + if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath); + + fseek(licenceFile, 0, SEEK_END); // seek to end of file + const int size = ftell(licenceFile); // get current file pointer + fseek(licenceFile, 0, SEEK_SET); + + if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath); + + int count = 0; + + unsigned char licenceContent[size]; + + for (int i = 0; i < size; i++) + { + ch = fgetc(licenceFile); + licenceContent[i] = ch; + count++; + } + + fclose(licenceFile); + + LicenceDataMainELC licenceHeader{}; + LicenceData licEncryptedData{}; + + memcpy(&licenceHeader, licenceContent, sizeof(LicenceDataMainELC)); + + const int sizeOfEncryptedData = size - sizeof(LicenceDataMainELC); + unsigned char encryptedData[sizeOfEncryptedData] = {}; + for (int i = 0; i < sizeOfEncryptedData; i++) + encryptedData[i] = licenceContent[i + sizeof(LicenceDataMainELC)]; + + BYTE prefixType = (int)licenceContent[3] - 0x30; + if (prefixType == PrefixType::ELC1) + { + if (licenceHeader.licHeader.sizeData > 0) + { + if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10) + { + initCrypto(); + // CryptData cryptData = initCrypto(sdData, licIdent.licIDType); + unsigned char decrypted[2000] = {}; + int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted); + + if (sizeof(licEncryptedData) != decrypted_len) + { + throw LicenceException((int)GeneralError::LicenceSizeMismatch, "License size mismatch "); + } + else + { + // memset(&licEncryptedData, 0, sizeof(licEncryptedData)); + memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData)); + + if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10) + { + if (licEncryptedData.header.licType == cEzLic_p78ou3_IDType_EOVOSV) + { + if (licEncryptedData.header.licCount > 0) + { + for (int i = 0; i < licMaxCount; i++) + { + licences->licences.insert(pair(licEncryptedData.items[i].protoId, licEncryptedData.items[i].licCount)); + } + } + else + { + throw LicenceException((int)GeneralError::LicenceSizeCardMismatch, "Size card info mismatch"); + } + } + } + else + { + throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch"); + } + } + } + } + else + { + throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch"); + } + } + else + { + throw LicenceException((int)GeneralError::LicenceReadError, "Licence error"); + } + + return true; + } } \ No newline at end of file diff --git a/src/reader/licReaderELC1.d b/src/reader/licReaderELC1.d index eb26f09..c3f292a 100644 --- a/src/reader/licReaderELC1.d +++ b/src/reader/licReaderELC1.d @@ -1,2 +1,5 @@ src/reader/licReaderELC1.o: src/reader/licReaderELC1.cpp \ - include/reader/licReaderELC1.h + include/reader/licReaderELC1.h include/common/utils.h \ + include/common/licenceCommon.h include/common/licenceELC1.h \ + include/common/licenceCommon.h include/common/SDCard.h \ + include/common/SDCard.h diff --git a/src/reader/licReaderELC1.o b/src/reader/licReaderELC1.o index f7d0e7c..c800943 100644 Binary files a/src/reader/licReaderELC1.o and b/src/reader/licReaderELC1.o differ diff --git a/src/reader/licReaderELC2.o b/src/reader/licReaderELC2.o index 266e27d..f26ea20 100644 Binary files a/src/reader/licReaderELC2.o and b/src/reader/licReaderELC2.o differ