diff --git a/Makefile b/Makefile index be33279..0dfe1f8 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ CXX = g++ # define any compile-time flags # CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w -CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto -w +CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto # define library paths in addition to /usr/lib # if I wanted to include libraries not in /usr/lib I'd specify diff --git a/src/LicenceELC11.cpp b/_old/LicenceELC11.cpp similarity index 100% rename from src/LicenceELC11.cpp rename to _old/LicenceELC11.cpp diff --git a/src/LicenceELC31.cpp b/_old/LicenceELC31.cpp similarity index 100% rename from src/LicenceELC31.cpp rename to _old/LicenceELC31.cpp diff --git a/include/licenceELC11.h b/_old/licenceELC11.h similarity index 100% rename from include/licenceELC11.h rename to _old/licenceELC11.h diff --git a/src/licenceELC21.cpp b/_old/licenceELC21.cpp similarity index 100% rename from src/licenceELC21.cpp rename to _old/licenceELC21.cpp diff --git a/include/licenceELC21.h b/_old/licenceELC21.h similarity index 100% rename from include/licenceELC21.h rename to _old/licenceELC21.h diff --git a/include/licenceELC31.h b/_old/licenceELC31.h similarity index 100% rename from include/licenceELC31.h rename to _old/licenceELC31.h diff --git a/docker/Dockerfile b/docker/Dockerfile index 6c1b444..272475f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,6 +11,12 @@ RUN chmod 755 /app/start.sh COPY ./startok.sh /app/ RUN chmod 755 /app/startok.sh +COPY ./lread.sh /app/ +RUN chmod 755 /app/lread.sh + +COPY ./lgen.sh /app/ +RUN chmod 755 /app/lgen.sh + COPY ./Makefile /app/ ENTRYPOINT ["tail"] diff --git a/docker/lgen.sh b/docker/lgen.sh new file mode 100644 index 0000000..5539a32 --- /dev/null +++ b/docker/lgen.sh @@ -0,0 +1,7 @@ +#!/bin/bash +chmod 777 output/generate + +#./output/generate -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml + +cd output +./generate -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml \ No newline at end of file diff --git a/docker/lread.sh b/docker/lread.sh new file mode 100644 index 0000000..4a9e6ae --- /dev/null +++ b/docker/lread.sh @@ -0,0 +1,7 @@ +#!/bin/bash +chmod 777 output/read + +#./output/read -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml + +cd output +./read -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml \ No newline at end of file diff --git a/docker/start.sh b/docker/start.sh index fa8d308..be6f26b 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,7 +1,7 @@ #!/bin/bash chmod 777 output/licenceGenerator -#./output/licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=400e00325b59000076b27f800a404013 -outputType=file -configFileName=licData.xml -licenceFileName=ezlic_eovosv0_vaxvcpalxjx.lic -licenceVersion=1 -licenceType=EOV_OSV +#./output/licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml cd output -./licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=400e00325b59000076b27f800a404013 -outputType=file -configFileName=licData.xml -licenceFileName=ezlic_eovosv0_vaxvcpalxjx.lic -licenceVersion=1 -licenceType=EOV_OSV \ No newline at end of file +./licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml \ No newline at end of file diff --git a/include/common/licenceCommon.h b/include/common/licenceCommon.h index 5b323a8..2bd2d2a 100644 --- a/include/common/licenceCommon.h +++ b/include/common/licenceCommon.h @@ -47,15 +47,6 @@ enum class GeneralError ItemsCountMismatch = 61 }; -// unordered_map mapGeneralErrors = { -// {GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu."}, -// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."}, -// {GeneralError::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."}, -// {GeneralError::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."}, -// {GeneralError::LicenceMismatch, "Nesouhlasí licence."}, -// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."} -// }; - enum class ELCType { ELC1 = 1, @@ -120,14 +111,19 @@ struct LicenceIdentification uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů uint8_t licenceIndex = 0; uint8_t revision; - uint8_t licCompatibility = 1; // identikator hlavního ELC - + uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC uint16_t licItemsCount = 0; - string cid_cds_path = ""; string licenceFilePath = ""; }; +/// @brief obecná struktura pro reader +struct LicenceInfoGeneral +{ + int reqDataPointsCount = 0; + unordered_map licences = {}; +}; + /// @brief obecná struktura polozky licence, defaultní kompatibilita struct LicenceItem { @@ -135,103 +131,54 @@ struct LicenceItem int dataPointsCount = 0; }; -/// @brief struktura polozky licence, kompatibilita 1 -struct LicenceItemCompatibility1 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - -/// @brief struktura polozky licence, kompatibilita 2 -struct LicenceItemCompatibility2 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - -/// @brief struktura polozky licence, kompatibilita 3 -struct LicenceItemCompatibility3 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - - -struct LicenceItem11 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - -struct LicenceItem21 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - -struct LicenceItem31 -{ - int protocolId = -1; - int dataPointsCount = 0; -}; - -/// @brief základní struktura, seznam polozek licencí -struct LicenceInfo -{ - int reqDataPointsCount = 0; - unordered_map licences = {}; -}; - -/// @brief základní struktura, seznam polozek licencí, kompatibilita 1 -struct LicenceInfoCompatibility1 -{ - int reqDataPointsCount = 0; - unordered_map licences = {}; -}; - -/// @brief základní struktura, seznam polozek licencí, kompatibilita 2 -struct LicenceInfoCompatibility2 -{ - int reqDataPointsCount = 0; - unordered_map licences = {}; -}; - -/// @brief základní struktura, seznam polozek licencí, kompatibilita 3 -struct LicenceInfoCompatibility3 -{ - int reqDataPointsCount = 0; - unordered_map licences = {}; -}; - -struct LicenceInfo1 +/* struktury pro ELC 1 */ +//defaultní struktura pro ELC 1 +struct LicenceELC1Info { bool isValid {false}; }; -struct LicenceInfo11 +//struktura ELC1, kompatibilita 1 +struct LicenceELC1Info_1 { - int reqDataPointsCount = 0; unordered_map licences = {}; }; -struct LicenceInfo21 +//defaultni struktura polozky licence ELC 1 +struct LicenceELC1Item +{ + int protocolId = -1; + int dataPointsCount = 0; +}; + + +/* struktury pro ELC 2 */ +//defaultní struktura pro ELC 2 +struct LicenceELC2Info { - int reqDataPointsCount = 0; unordered_map licences = {}; }; -struct LicenceInfo31 +struct LicenceELC2Info_1 { - int reqDataPointsCount = 0; unordered_map licences = {}; }; -struct LicenceInfoGeneral +//defaultni struktura polozky ELC 2 +struct LicenceELC2Item { - int reqDataPointsCount = 0; - unordered_map licences = {}; + int protocolId = -1; + int dataPointsCount = 0; }; +//struktura polozky ELC 2, +struct LicenceELC2Item_1 +{ + int protocolId = -1; + int dataPointsCount = 0; +}; + + class LicenceException : public std::exception { public: diff --git a/include/common/utils.h b/include/common/utils.h index 86aba2c..eb03acc 100644 --- a/include/common/utils.h +++ b/include/common/utils.h @@ -1,6 +1,3 @@ -//#define LINUX 1 -#define WINDOWS 1 - #ifndef UTILS_H_ #define UTILS_H_ @@ -12,6 +9,7 @@ #include #include // dirname #include +#include typedef uint8_t BYTE; typedef uint16_t WORD; diff --git a/include/generator/licenceGenerator.h b/include/generator/licenceGenerator.h index ccdb530..f30675a 100644 --- a/include/generator/licenceGenerator.h +++ b/include/generator/licenceGenerator.h @@ -7,19 +7,20 @@ #include #include "pugixml.hpp" #include "licenceCommon.h" -#include "licenceELC11.h" -#include "licenceELC21.h" -#include "licenceELC31.h" +// #include "licenceELC11.h" +// #include "licenceELC21.h" +// #include "licenceELC31.h" #include "licGenELC1.h" #include "licGenELC2.h" #include "licGenELC3.h" using namespace std; - + class LicenceGenerator { +public: struct LicData { string station = ""; @@ -32,31 +33,27 @@ class LicenceGenerator pugi::xml_document *doc; }; -public: + LicData licData; int elcSwitchType; string operationErrors = ""; pugi::xml_document doc; bool argumentsCorrect = false; ErrorMessage error; - LicenceELC11 *licence11; - LicenceELC21 *licence21; - LicenceELC31 *licence31; + // LicenceELC11 *licence11; + // LicenceELC21 *licence21; + // LicenceELC31 *licence31; Mapping mapping; - LicenceGenerator(); ~LicenceGenerator(); LicenceGenerator(string uid, string cid, string csd, string dataFileName); - + void createLicenceFile(); - LicenceInfoGeneral licenceInfo; - private: LicenceIdentification licIdentification; - LicData licData; string configFileName = ""; void *licence = nullptr; @@ -66,7 +63,6 @@ private: void createLicenceELC1(); void createLicenceELC2(); void createLicenceELC3(); - }; #endif \ No newline at end of file diff --git a/include/generator/pugixml.hpp b/include/generator/pugixml.hpp index 9f7c3fb..1980cb8 100644 --- a/include/generator/pugixml.hpp +++ b/include/generator/pugixml.hpp @@ -944,13 +944,17 @@ namespace pugi char _memory[192]; // Non-copyable semantics - xml_document(const xml_document&); - xml_document& operator=(const xml_document&); + // xml_document(const xml_document&); + // xml_document& operator=(const xml_document&); void create(); void destroy(); public: + + xml_document(const xml_document&); + xml_document& operator=(const xml_document&); + // Default constructor, makes empty document xml_document(); diff --git a/include/reader/licReaderELC1.h b/include/reader/licReaderELC1.h index 8e4e67a..5f43c28 100644 --- a/include/reader/licReaderELC1.h +++ b/include/reader/licReaderELC1.h @@ -14,7 +14,7 @@ namespace Reader { public: - LicenceInfo21 licenceInfo; + LicenceELC1Info licenceInfo; Licence1(); ~Licence1(); diff --git a/include/reader/licReaderELC2.h b/include/reader/licReaderELC2.h index d073999..237a41a 100644 --- a/include/reader/licReaderELC2.h +++ b/include/reader/licReaderELC2.h @@ -13,15 +13,13 @@ namespace Reader class Licence2 : public LicenceELC2 { public: - LicenceInfo21 licenceInfo; + LicenceELC2Info licenceInfo; - Licence2(); ~Licence2(); Licence2(LicenceIdentification &licIdentification); bool readLicence(LicenceInfoGeneral *licences); - int getDataPointsCount(int protocolId); bool getLicenceInfo(void *ptr); bool getLicenceItemInfo(int protocolId, void *returnItemStructure); void getLicenceItems(); diff --git a/output/cid b/output/cid index 53e2b16..9a70e3e 100644 --- a/output/cid +++ b/output/cid @@ -1,4 +1,4 @@ -0353445355313647801b1a9f6600c747 +9f54495344434954615ad803c50171bf 6   . x4   .. nt$6 & manfid 6  cid "6  fwrev 6 Jm  csd ,6 gEd$ subsystem 46 % diff --git a/output/csd b/output/csd index 7dee550..609cf45 100644 --- a/output/csd +++ b/output/csd @@ -1,2 +1,2 @@ -400e00325b59000076b27f800a404013 +400e00325b5900003be77f800a400043 \ No newline at end of file diff --git a/output/ezlic_eovosv0_jjacdgpdxpb.lic b/output/ezlic_eovosv0_jjacdgpdxpb.lic new file mode 100644 index 0000000..9942ae6 Binary files /dev/null and b/output/ezlic_eovosv0_jjacdgpdxpb.lic differ diff --git a/output/ezlic_eovosv0_wqxcyjpdxji.lic b/output/ezlic_eovosv0_wqxcyjpdxji.lic new file mode 100644 index 0000000..c67a8bd Binary files /dev/null and b/output/ezlic_eovosv0_wqxcyjpdxji.lic differ diff --git a/output/generate b/output/generate new file mode 100644 index 0000000..4b2a8cb Binary files /dev/null and b/output/generate differ diff --git a/output/cis b/output/lcis/cid similarity index 100% rename from output/cis rename to output/lcis/cid diff --git a/output/lcis/cis b/output/lcis/cis new file mode 100644 index 0000000..53e2b16 --- /dev/null +++ b/output/lcis/cis @@ -0,0 +1,5 @@ +0353445355313647801b1a9f6600c747 +6   . x4   .. nt$6 & manfid 6 +  cid "6  fwrev 6 Jm  csd ,6 gEd$ +subsystem 46 % +driver (6 -  ocr -6 ? power *6 4L  type 6 1M  date #6 rTP hwrev )6 nyR  dsr '6 ` serial 6 NNm erase_size 6 6m block 6 n uevent 6 o  ssr 6 q  scr &6 &y oemid !6 y ( preferred_erase_size %6   name \ No newline at end of file diff --git a/output/lcis/csd b/output/lcis/csd new file mode 100644 index 0000000..7dee550 --- /dev/null +++ b/output/lcis/csd @@ -0,0 +1,2 @@ +400e00325b59000076b27f800a404013 + \ No newline at end of file diff --git a/output/lcis/ezlic_eovosv0_wqxcyjpdxji.lic b/output/lcis/ezlic_eovosv0_wqxcyjpdxji.lic new file mode 100644 index 0000000..c67a8bd Binary files /dev/null and b/output/lcis/ezlic_eovosv0_wqxcyjpdxji.lic differ diff --git a/output/lcis/licData.xml b/output/lcis/licData.xml new file mode 100644 index 0000000..55876f9 --- /dev/null +++ b/output/lcis/licData.xml @@ -0,0 +1,37 @@ + + +EOV_OSV +WAGO +Licence pro EOV_OSV +eov.ceskatrebova.ddts.cz +eov2 +Projekt XXX stanice YYY + + + Položka licence 1 + 111 + 100 + + + Položka licence 2 + 222 + 200 + + + Položka licence 3 + 333 + 300 + + + Položka licence 4 + 555 + 666 + + + Položka licence 5 + 666 + 9998 + + + + \ No newline at end of file diff --git a/output/_orig_ezlic_eovosv0_cbheemcjsii.lic b/output/lcis/temp/_orig_ezlic_eovosv0_cbheemcjsii.lic similarity index 100% rename from output/_orig_ezlic_eovosv0_cbheemcjsii.lic rename to output/lcis/temp/_orig_ezlic_eovosv0_cbheemcjsii.lic diff --git a/output/ezlic_eovosv0_cbheemcjsii.lic b/output/lcis/temp/ezlic_eovosv0_cbheemcjsii.lic similarity index 100% rename from output/ezlic_eovosv0_cbheemcjsii.lic rename to output/lcis/temp/ezlic_eovosv0_cbheemcjsii.lic diff --git a/output/ezlic_eovosv0_vdyeygcjeca.lic b/output/lcis/temp/ezlic_eovosv0_vdyeygcjeca.lic similarity index 100% rename from output/ezlic_eovosv0_vdyeygcjeca.lic rename to output/lcis/temp/ezlic_eovosv0_vdyeygcjeca.lic diff --git a/output/lcis/temp/ezlic_eovosv0_xjxvxgalxab.lic b/output/lcis/temp/ezlic_eovosv0_xjxvxgalxab.lic new file mode 100644 index 0000000..4e1b4f2 Binary files /dev/null and b/output/lcis/temp/ezlic_eovosv0_xjxvxgalxab.lic differ diff --git a/output/licData.xml b/output/licData.xml index d41f290..870d8ac 100644 --- a/output/licData.xml +++ b/output/licData.xml @@ -1,36 +1,26 @@ - + EOV_OSV WAGO Licence pro EOV_OSV -eov.ceskatrebova.ddts.cz -eov2 +odb.zaluzi.drt.cz +POZ8 Projekt XXX stanice YYY Položka licence 1 111 - 100 + 7454 Položka licence 2 222 - 200 + 6477 Položka licence 3 333 - 300 - - - Položka licence 3 - 444 - 1600 - - - Položka licence 4 - 555 - 666 + 7844 diff --git a/output/licenceGenerator b/output/licenceGenerator index 43a8115..bba4edc 100644 Binary files a/output/licenceGenerator and b/output/licenceGenerator differ diff --git a/output/read b/output/read new file mode 100644 index 0000000..9d8828d Binary files /dev/null and b/output/read differ diff --git a/src/CreateLicence.cpp b/src/CreateLicence.cpp index 3976ac3..4ce2ca9 100644 --- a/src/CreateLicence.cpp +++ b/src/CreateLicence.cpp @@ -1,3 +1,6 @@ +#define LINUX 1 +//#define WINDOWS 1 + #include #include "licenceGenerator.h" @@ -5,7 +8,7 @@ /// @param argc /// @param argv parametry pro generování licence /// @return -int main5(int argc, char *argv[]) +int main6(int argc, char *argv[]) { unordered_map arguments = getArguments(argc, argv); try diff --git a/src/ReadLicence.cpp b/src/ReadLicence.cpp index 3136c8f..74c4a0f 100644 --- a/src/ReadLicence.cpp +++ b/src/ReadLicence.cpp @@ -1,3 +1,6 @@ +#define LINUX 1 +// #define WINDOWS 1 + #include #include "licenceReader.h" @@ -13,15 +16,16 @@ int main() initStructure.licenceType = (int)LicenceType::EOS_EOV; initStructure.licenceVersion = 1; initStructure.licenceIndex = 0; - initStructure.compatibility = 1; - initStructure.licenceFilePath = ""; - initStructure.cid_csd_filePath = ""; + initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru + // initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní. + // pro ELC 1 LicenceELC1Info s výstupem isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; } + initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontorlu licence // verze původní ELC 1 LicenceReader licenceReaderELC1{}; - if (licenceReaderELC1.initread(1, initStructure)) //iniciacni nacteni + if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni { - LicenceInfo1 info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false + LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false if (licenceReaderELC1.getLicenceInfo(&info)) { if (info.isValid) @@ -39,11 +43,24 @@ int main() // verze ELC 2 pro jeden protokol LicenceReader licenceReaderELC2{}; - - if (licenceReaderELC2.initread(2, initStructure)) //iniciacni nacteni + + if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni { - LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) - int protocolId = 444; + // v případě kompatibility 0, či nezadané výstup nativně je defaultní. + // v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility. Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1 + LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) + // if () + int protocolId = 333; + + // if (initStructure.compatibility == 1) //ukazka kompatibilita + // { + // LicenceELC2Item_1 info; //jiná struktura, zbytek stejný + // if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info)) + // { + // cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl; + // } + //........... + // } if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info)) { @@ -60,15 +77,17 @@ int main() LicenceReader licenceReaderCompleteELC2{}; // verze ELC 2 kompletní načtení - if (licenceReaderCompleteELC2.init(2, initStructure)) //iniciacni nacteni + if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni { - LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) + LicenceELC2Info 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"; + 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) { @@ -91,3 +110,6 @@ int main() // system("pause"); return SUCCES; } + +// cid: 0353445355313647801b1a9f6600c747 csd: 400e00325b59000076b27f800a404013 +// https://sprava.app.elzel.cz/device/417 cid: 9f54495344434954615ad803c50171bf csd: 400e00325b5900003be77f800a400043 \ No newline at end of file diff --git a/src/common/SDCard.o b/src/common/SDCard.o index cf5508e..4a65c6c 100644 Binary files a/src/common/SDCard.o and b/src/common/SDCard.o differ diff --git a/src/common/licenceELC1.o b/src/common/licenceELC1.o index 6fb918a..0b9ce0c 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 e385bae..008171b 100644 Binary files a/src/common/licenceELC2.o and b/src/common/licenceELC2.o differ diff --git a/src/common/utils.cpp b/src/common/utils.cpp index 7885cdf..28181da 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -3,7 +3,6 @@ #include /* core library */ #include "utils.h" - using namespace std; const std::string base64_chars = @@ -26,7 +25,7 @@ void getCharsFromString(string &source, char *charArray, size_t length) void getCharsFromString(string source, char *charArray) { - size_t length = source.length(); + size_t length = source.length(); for (size_t i = 0; i < length; i++) { charArray[i] = source[i]; @@ -117,8 +116,8 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke int ciphertext_len; /* Create and initialise the context */ - if (!(ctx = EVP_CIPHER_CTX_new())) return -1; - + if (!(ctx = EVP_CIPHER_CTX_new())) + return -1; /* * Initialise the encryption operation. IMPORTANT - ensure you use a key @@ -180,7 +179,7 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char * * EVP_DecryptUpdate can be called multiple times if necessary. */ if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) - return -1; + return -1; plaintext_len = len; /* @@ -188,7 +187,7 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char * * this stage. */ if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) - return -1; + return -1; plaintext_len += len; @@ -316,17 +315,17 @@ string getCompletePath(string fileName) #ifdef WINDOWS return fileName; #else -//warning TODO filesystem -char path[PATH_MAX+1] = {}; - ssize_t length = readlink("/proc/self/exe", path, PATH_MAX); - path[length] = '\0'; - string result = string(dirname(path)) + "/" + fileName; - return result; - //return std::string( result, (count > 0) ? count : 0 ); - // std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0])); - // std::filesystem::path fullPathOther = exePath.parent_path() / fileName; - // std::string fullPathStrOther = fullPathOther.string(); - // return fullPathStrOther; + + char path[PATH_MAX + 1] = {}; + ssize_t length = readlink("/proc/self/exe", path, PATH_MAX); + path[length] = '\0'; + string result = string(dirname(path)) + "/" + fileName; + return result; + // return std::string( result, (count > 0) ? count : 0 ); + // std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0])); + // std::filesystem::path fullPathOther = exePath.parent_path() / fileName; + // std::string fullPathStrOther = fullPathOther.string(); + // return fullPathStrOther; #endif } @@ -390,7 +389,7 @@ std::vector joinVectors(const std::vector &vector1 bool readFile(string fileName, vector &output) { std::ifstream file(fileName, std::ios::in | std::ios::binary); - + if (file.is_open() != 1) { return false; diff --git a/src/common/utils.o b/src/common/utils.o index 1d5497e..ef95f8a 100644 Binary files a/src/common/utils.o and b/src/common/utils.o differ diff --git a/src/generator/LicenceGenerator.d b/src/generator/LicenceGenerator.d index f4e9767..e83f4d9 100644 --- a/src/generator/LicenceGenerator.d +++ b/src/generator/LicenceGenerator.d @@ -1,9 +1,8 @@ src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \ include/generator/licenceGenerator.h include/generator/pugixml.hpp \ include/generator/pugiconfig.hpp include/common/licenceCommon.h \ - include/licenceELC11.h include/common/SDCard.h include/licenceELC21.h \ - include/common/utils.h include/generator/pugixml.hpp \ - include/licenceELC31.h include/generator/licGenELC1.h \ + include/generator/licGenELC1.h include/common/utils.h \ include/common/licenceELC1.h include/common/licenceCommon.h \ - include/common/SDCard.h include/generator/licGenELC2.h \ - include/common/licenceELC2.h include/generator/licGenELC3.h + include/common/SDCard.h include/common/SDCard.h \ + include/generator/licGenELC2.h include/common/licenceELC2.h \ + include/generator/licGenELC3.h include/generator/pugixml.hpp diff --git a/src/generator/LicenceGenerator.o b/src/generator/LicenceGenerator.o index c1ad612..ef0d9a9 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 7d8014f..41a10e6 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 ed0c2cb..a13bec4 100644 Binary files a/src/generator/licGenELC2.o and b/src/generator/licGenELC2.o differ diff --git a/src/generator/licGenELC3.o b/src/generator/licGenELC3.o index 7d3e288..ba95669 100644 Binary files a/src/generator/licGenELC3.o and b/src/generator/licGenELC3.o differ diff --git a/src/generator/pugixml.o b/src/generator/pugixml.o index a9643b0..12d8d7d 100644 Binary files a/src/generator/pugixml.o and b/src/generator/pugixml.o differ diff --git a/src/reader/LicenceReader.cpp b/src/reader/LicenceReader.cpp index 5fdc5c8..c86ab44 100644 --- a/src/reader/LicenceReader.cpp +++ b/src/reader/LicenceReader.cpp @@ -13,118 +13,10 @@ LicenceReader::LicenceReader() { } -// LicenceReader::LicenceReader(string uid, string cid, string csd, string dataFileName) -// { -// try -// { -// if (dataFileName.empty()) -// throw std::runtime_error("Missing dataFileName par."); - -// if (uid.empty() == false) -// { -// this->licData.uid = uid; -// } -// else -// { -// if (cid.empty()) -// throw std::runtime_error("Missing CID par."); -// if (csd.empty()) -// throw std::runtime_error("Missing CSD par."); -// } -// } -// catch (const std::exception &e) -// { -// this->argumentsCorrect = false; -// std::cerr << "error: " << e.what() << endl; -// return; -// } - -// this->configFileName = dataFileName; -// this->licData.cid = cid; -// this->licData.csd = csd; - -// this->argumentsCorrect = true; - -// if (processInputConfiguration() == false) -// { -// cerr << "Chyba: " << error.message << endl; -// } -// } - -// LicenceReader::LicenceReader(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility) -// { -// this->licIdentification.licElcType = (ELCType)elcType; -// this->licIdentification.licLicenceType = (LicenceType)licenceType; -// this->licIdentification.licenceVersion = licenceVersion; -// this->licIdentification.licenceIndex = licenceIndex; -// this->licIdentification.licCompatibility = compatibility; -// } - -/// @brief inicializace generátoru a načtení licenčních bodů do obecné struktury +/// @brief provede pouze inicialazaci čtecí třídy /// @param elcType -/// @param licenceType -/// @param licenceVersion -/// @param licenceIndex -/// @param compatibility +/// @param initStructure /// @return -bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO -{ - try - { - elcSwitchType = elcType * 10 + licCompatibility; - - if (init(elcType, initStructure)) - { - switch (elcSwitchType) - { - case 11: - { // old eoseov - 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: - { - Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); - this->licence2 = &licenceELC2; - licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath; - licenceELC2.licenceFilePath = initStructure.licenceFilePath; - this->licence2->readLicence(&this->licenceInfo); - break; - } - case 31: - { - // LicenceELC31 licence = LicenceELC31(this->licIdentification); - break; - } - } - } - else - return false; - } - catch (const LicenceException &ex) - { - error.code = ex.getErrorCode(); - error.message = ex.getErrorMessage(); - return false; - } - - return true; // TODO testy -} - bool LicenceReader::init(int elcType, InitStructure &initStructure) { try @@ -151,7 +43,73 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure) elcSwitchType = elcType * 10 + licCompatibility; - return true; + return true; +} + +/// @brief provede inicializaci čtecí třídy a zároveň načte licenční body do obecné struktury +/// @param elcType +/// @param licenceType +/// @param licenceVersion +/// @param licenceIndex +/// @param compatibility +/// @return +bool LicenceReader::initread(int elcType, InitStructure &initStructure) +{ + try + { + elcSwitchType = elcType * 10 + initStructure.compatibility; + + if (init(elcType, initStructure)) + { + switch (this->licIdentification.licElcType) + { + case ELCType::ELC1: + { // old eoseov + 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 ELCType::ELC2: + { + Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); + this->licence2 = &licenceELC2; + licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath; + licenceELC2.licenceFilePath = initStructure.licenceFilePath; + this->licence2->readLicence(&this->licenceInfo); + break; + } + case ELCType::ELC3: + { + break; + } + default: + throw LicenceException((int)GeneralError::ELCNotImplemented, "Toto ELC není implementováno"); + } + } + else + return false; + } + catch (const LicenceException &ex) + { + error.code = ex.getErrorCode(); + error.message = ex.getErrorMessage(); + return false; + } + + return true; // TODO testy } /// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury @@ -162,28 +120,51 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure { try { - switch (elcSwitchType) + switch (this->licIdentification.licElcType) { - case 11: + case ELCType::ELC1: { - 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)) - resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId); + if (!this->licIdentification.licCompatibility) // defaultní kompatibilita + { + LicenceELC1Info *resultPtr = static_cast(returnItemStructure); + if (this->licenceInfo.licences.count(1)) // stare eov má natvrdo "id" 1. + resultPtr->isValid = true; + else + resultPtr->isValid = false; + } else - resultPtr->dataPointsCount = 0; + { + LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována."); + } break; } - case 31: + case ELCType::ELC2: + { + if (!this->licIdentification.licCompatibility) // defaultní kompatibilita + { + LicenceELC2Item *resultPtr = static_cast(returnItemStructure); + resultPtr->protocolId = protocolId; // protocolId; + if (this->licenceInfo.licences.count(protocolId)) + resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId); + else + resultPtr->dataPointsCount = 0; + } + else + { + switch (this->licIdentification.licCompatibility) + { + case 1: + // kod pro kompatibilitu 1 + break; + default: + LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována."); + break; + } + } + break; + } + case ELCType::ELC3: { - // LicenceELC31 licence = LicenceELC31(this->licIdentification); break; } default: @@ -211,66 +192,61 @@ bool LicenceReader::getLicenceInfo(void *returnStructure) { try { - switch (elcSwitchType) + switch (this->licIdentification.licElcType) { - case 11: - { // old eoseov - - LicenceInfo1 *resultPtr = static_cast(returnStructure); - - if (this->licenceInfo.licences.count(1)) + case ELCType::ELC1: + { // old eoseov + if (!this->licIdentification.licCompatibility) // defaultní kompatibilita { - resultPtr->isValid = true; + LicenceELC1Info *resultPtr = static_cast(returnStructure); + + if (this->licenceInfo.licences.count(1)) // starý EOS má natvrdo "id" 1 + { + resultPtr->isValid = true; + } + else + { + resultPtr->isValid = false; + } } else { - resultPtr->isValid = false; + switch (this->licIdentification.licCompatibility) + { + case 1: + // kod pro kompatibilitu 1 + break; + default: + LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována."); + break; + } } - return true; break; } - case 21: + case ELCType::ELC2: { - - 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; - // } + if (!this->licIdentification.licCompatibility) // defaultní kompatibilita + { + Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); + licenceELC2.readLicence(&this->licenceInfo); + licenceELC2.getLicenceInfo(returnStructure); + } + else + { + switch (this->licIdentification.licCompatibility) + { + case 1: + // kod pro kompatibilitu 1 + break; + default: + LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována."); + break; + } + } break; } - case 31: + case ELCType::ELC3: { - // 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; } } @@ -281,6 +257,7 @@ bool LicenceReader::getLicenceInfo(void *returnStructure) error.message = ex.getErrorMessage(); return false; } + return true; } LicenceReader::~LicenceReader() diff --git a/src/reader/LicenceReader.o b/src/reader/LicenceReader.o index 1bd4c51..27a7056 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 52210e5..52ecad6 100644 --- a/src/reader/licReaderELC1.cpp +++ b/src/reader/licReaderELC1.cpp @@ -10,6 +10,9 @@ namespace Reader { } + /// @brief načte seznam licenčních bodů do obecné struktury + /// @param licences + /// @return bool Licence1::readLicence(LicenceInfoGeneral *licences) { sdCard = SDCard(this->cid_cdsPath); @@ -20,11 +23,6 @@ namespace Reader 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; @@ -34,12 +32,12 @@ namespace Reader FILE *licenceFile; char ch; - licenceFile = fopen(licFileNameToRead, "rb"); // read mode + licenceFile = fopen(licFileNameToRead, "rb"); 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_END); + const int size = ftell(licenceFile); fseek(licenceFile, 0, SEEK_SET); if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath); @@ -75,7 +73,7 @@ namespace Reader 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); @@ -85,7 +83,6 @@ namespace Reader } 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) @@ -101,7 +98,7 @@ namespace Reader } else { - throw LicenceException((int)GeneralError::LicenceSizeCardMismatch, "Size card info mismatch"); + throw LicenceException((int)GeneralError::ItemsCountMismatch, "ItemsCountMismatch"); } } } diff --git a/src/reader/licReaderELC1.o b/src/reader/licReaderELC1.o index c800943..bf94c02 100644 Binary files a/src/reader/licReaderELC1.o and b/src/reader/licReaderELC1.o differ diff --git a/src/reader/licReaderELC2.cpp b/src/reader/licReaderELC2.cpp index d01de19..4df790b 100644 --- a/src/reader/licReaderELC2.cpp +++ b/src/reader/licReaderELC2.cpp @@ -3,15 +3,15 @@ namespace Reader { - Licence2::Licence2(){} + Licence2::Licence2() {} - Licence2::~Licence2(){} + Licence2::~Licence2() {} Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification) { } - /// @brief načte licence do obecné struktury ELC2 + /// @brief načte seznam licenčních bodů do obecné struktury /// @param licences /// @return bool Licence2::readLicence(LicenceInfoGeneral *licences) @@ -90,23 +90,23 @@ namespace Reader } bool Licence2::getLicenceInfo(void *returnStructure) -{ - if (returnStructure != nullptr) { - LicenceInfo21 *resultPtr = static_cast(returnStructure); - for (auto item : this->licBody.privateContent.dataItems) + if (returnStructure != nullptr) { - resultPtr->licences.insert(pair(item.protoId, item.licCount)); + LicenceELC2Info *resultPtr = static_cast(returnStructure); + for (auto item : this->licBody.privateContent.dataItems) + { + resultPtr->licences.insert(pair(item.protoId, item.licCount)); + } + } + else + { + errorMessage.code = 1; + errorMessage.message = "Error: Null pointer!"; + return false; } - } - else - { - errorMessage.code = 1; - errorMessage.message = "Error: Null pointer!"; - return false; - } - return true; -} + return true; + } } \ No newline at end of file diff --git a/src/reader/licReaderELC2.o b/src/reader/licReaderELC2.o index f26ea20..b09d02b 100644 Binary files a/src/reader/licReaderELC2.o and b/src/reader/licReaderELC2.o differ diff --git a/src/reader/licReaderELC3.o b/src/reader/licReaderELC3.o index c02dcff..7e2c3ab 100644 Binary files a/src/reader/licReaderELC3.o and b/src/reader/licReaderELC3.o differ