diff --git a/docker-compose.yml b/docker-compose.yml index 61f7b99..76e5dc4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,4 +10,4 @@ services: - ./lib:/app/lib - ./output:/app/output - ./src:/app/src - \ No newline at end of file + /bin \ No newline at end of file diff --git a/ezlic_drt0_jjacdgpdxpb.lic b/ezlic_drt0_jjacdgpdxpb.lic new file mode 100644 index 0000000..4911881 Binary files /dev/null and b/ezlic_drt0_jjacdgpdxpb.lic differ diff --git a/include/common/SDCard.h b/include/common/SDCard.h index 4baba68..f82eb7f 100644 --- a/include/common/SDCard.h +++ b/include/common/SDCard.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef SDCARD_H_ #define SDCARD_H_ @@ -25,9 +27,9 @@ struct SDCardInfo uint32_t cardSize {}; uint32_t serialNumber {}; string date = ""; -uint8_t manufacturerID {}; -char oemID[2] = {}; -char name[5] = {}; +string oemID = ""; +string name = ""; +string licenceFileName = ""; bool isLoaded = false; }; @@ -47,6 +49,7 @@ class SDCard uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6 uint16_t manufacturerDate_year = 0; uint8_t manufacturerDate_month = 0; + string date = ""; char manufacturerDate[10] = {}; //: STRING(10); // datum vyroby 2B [bcd -yym] -> Byte 1-2, bity 0-3 = mesic, bity 4-11 = posledni cislice roku or roku 2000, bity 12-15 nepouzito uint8_t CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1 uint8_t CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru @@ -77,4 +80,5 @@ public: }; +#endif #endif \ No newline at end of file diff --git a/include/common/licenceCommon.h b/include/common/licenceCommon.h index 03e5de1..6dcd04a 100644 --- a/include/common/licenceCommon.h +++ b/include/common/licenceCommon.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #define CRC = 1 #ifndef LICENCE_COMMON_H_ @@ -15,7 +17,10 @@ using namespace std; #define XML_VERSION 1 #define SOFTWARE_VERSION 1 -#define SUCCES 0; +#define SUCCES 0 +#define CRYPT_INIT_VECTOR_SIZE 16 +#define CRYPT_INIT_KEY_SIZE 32 + const int cidSize = 32; const int csdSize = 32; @@ -52,9 +57,9 @@ enum class GeneralError enum class ELCType { - ELC1 = 1, //starý původní licenční soubor zalozený na CID a CSD - ELC2 = 2, //modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů - ELC3 = 3 //budoucí softwarový licenční soubor, který není zalozený na existenci CID a CSD, ale na unikátním ID instalace linuxu + ELC1 = 1, // starý původní licenční soubor zalozený na CID a CSD + ELC2 = 2, // modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů + ELC3 = 3 // budoucí softwarový licenční soubor, který není zalozený na existenci CID a CSD, ale na unikátním ID instalace linuxu }; enum class ELCSubType { @@ -91,7 +96,10 @@ enum class FileNameGenerationType DEFAULT = 1 }; -//indexy musí být velká písmena ze základní ASCI tabulky +struct CryptInitVector{ int vec[CRYPT_INIT_VECTOR_SIZE]; }; +struct CryptAesKey { int key[CRYPT_INIT_KEY_SIZE]; }; + +// indexy musí být velká písmena ze základní ASCI tabulky struct Mapping { unordered_map licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}}; @@ -107,12 +115,12 @@ struct ErrorMessage struct LicenceIdentification { - ELCType licElcType = ELCType::ELC2; //hlavní typ licenčního souboru + ELCType licElcType = ELCType::ELC2; // hlavní typ licenčního souboru LicenceType licLicenceType; string licTypeName = ""; PlcType licPlcType; uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů - uint8_t licenceIndex = 0; //index licenčního souboru v případě, ze jich je víc + uint8_t licenceIndex = 0; // index licenčního souboru v případě, ze jich je víc uint8_t revision; uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC uint16_t licItemsCount = 0; @@ -129,33 +137,32 @@ struct LicenceInfoGeneral /// @brief obecná struktura polozky licence, defaultní kompatibilita struct LicenceItem { - DWORD protocolId {}; - DWORD dataPointsCount {}; + DWORD protocolId{}; + DWORD dataPointsCount{}; }; /* struktury pro ELC 1 */ -//defaultní struktura pro ELC 1 +// defaultní struktura pro ELC 1 struct LicenceELC1Info { - bool isValid {false}; + bool isValid{false}; }; -//struktura ELC1, kompatibilita 1 +// struktura ELC1, kompatibilita 1 struct LicenceELC1Info_1 { unordered_map licences = {}; }; -//defaultni struktura polozky licence ELC 1 +// defaultni struktura polozky licence ELC 1 struct LicenceELC1Item { int protocolId = -1; int dataPointsCount = 0; }; - /* struktury pro ELC 2 */ -//defaultní struktura pro ELC 2 +// defaultní struktura pro ELC 2 struct LicenceELC2Info { map licences = {}; @@ -166,21 +173,20 @@ struct LicenceELC2Info // map licences = {}; // }; -//defaultni struktura polozky ELC 2 +// defaultni struktura polozky ELC 2 struct LicenceELC2Item { - DWORD protocolId {}; - DWORD dataPointsCount {}; + DWORD protocolId{}; + DWORD dataPointsCount{}; }; -//struktura polozky ELC 2, +// struktura polozky ELC 2, struct LicenceELC2Item_1 { - DWORD protocolId {}; - DWORD dataPointsCount {}; + DWORD protocolId{}; + DWORD dataPointsCount{}; }; - class LicenceException : public std::exception { public: @@ -208,3 +214,5 @@ private: }; #endif + +#endif diff --git a/include/common/licenceELC1.h b/include/common/licenceELC1.h index f355658..4a498f7 100644 --- a/include/common/licenceELC1.h +++ b/include/common/licenceELC1.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef PLC_LICENCE1_COMMON_H #define PLC_LICENCE1_COMMON_H @@ -262,4 +264,5 @@ public: }; +#endif #endif \ No newline at end of file diff --git a/include/common/licenceELC2.h b/include/common/licenceELC2.h index 0400757..b440a10 100644 --- a/include/common/licenceELC2.h +++ b/include/common/licenceELC2.h @@ -1,7 +1,8 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef PLC_LICENCE2_COMMON_H #define PLC_LICENCE2_COMMON_H - #include #include "licenceCommon.h" #include "SDCard.h" @@ -13,9 +14,10 @@ public: LicenceELC2(); LicenceELC2(LicenceIdentification &licIdentification); ~LicenceELC2(); - + string cid_cdsPath = ""; string licenceFilePath = ""; + string licFileName = ""; Mapping mapping; @@ -29,21 +31,21 @@ public: // struct __attribute__((__packed__)) LicencePublicHeader struct LicenceIdentDataHeader { - BYTE licenceType {}; // EOSEOV, DRT ... + BYTE licenceType{}; // EOSEOV, DRT ... BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů - BYTE licenceIndex {}; // puvodní post fix, identifikátor pro více licencí + BYTE licenceIndex{}; // puvodní post fix, identifikátor pro více licencí BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent - BYTE licItemCount {}; // počet protokolů v linenci - WORD publicHeaderLength {}; // délka veřejné hlavičy - WORD cardSize {}; // velikost SD karty - DWORD serialNumber = {}; // seriove cislo karty + BYTE licItemCount{}; // počet protokolů v linenci + WORD publicHeaderLength{}; // délka veřejné hlavičy + WORD cardSize{}; // velikost SD karty + DWORD serialNumber = {}; // seriove cislo karty }; /// struct licDataItem { - DWORD protoId {}; // id protokolu pro ktery je licence - DWORD licCount {}; // pocet datovych bodu licence + DWORD protoId{}; // id protokolu pro ktery je licence + DWORD licCount{}; // pocet datovych bodu licence }; struct PublicHeader @@ -56,30 +58,31 @@ public: struct PrivateContent // privátní šifrovaná část { - LicenceIdentDataHeader licenceIdentHeader {}; - vector dataItems {}; - WORD crc {}; + LicenceIdentDataHeader licenceIdentHeader{}; + vector dataItems{}; + WORD crc{}; }; struct LicenceBody { - LicenceId licId {}; - LicenceIdentDataHeader licenceIdentHeader {}; + LicenceId licId{}; + LicenceIdentDataHeader licenceIdentHeader{}; string publicHeader = ""; // JSON - PrivateContent privateContent {}; + PrivateContent privateContent{}; }; - LicenceBody licBody {}; - SDCard sdCard {}; - LicenceIdentification lIdentification {}; + SDCard sdCard{}; + +protected: vector cryptPrivateContent(const std::vector &content); vector decryptPrivateContent(const std::vector &content); - void initVector(BYTE (&iVector)[], BYTE (&key)[]); + void initVector(BYTE *iVector, BYTE *key); string getLicenceName(); + LicenceBody licBody{}; + LicenceIdentification lIdentification{}; private: - - }; +#endif #endif \ No newline at end of file diff --git a/include/common/utils.h b/include/common/utils.h index 0a29fce..259f0f8 100644 --- a/include/common/utils.h +++ b/include/common/utils.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef UTILS_H_ #define UTILS_H_ @@ -48,7 +50,7 @@ vector joinVectors(const std::vector& vector1, con bool readFile(string fileName, vector &output); #endif - +#endif diff --git a/include/generator/licGenELC2.h b/include/generator/licGenELC2.h index 7151ca3..5738507 100644 --- a/include/generator/licGenELC2.h +++ b/include/generator/licGenELC2.h @@ -25,13 +25,15 @@ namespace Generator pugi::xml_document *xmlDoc; string projectDescription = ""; - bool createLicence(); + + private: void getHeader(); string getVersion(int middleVersion); bool processInputConfiguration(); void getLicenceItems(); + }; } diff --git a/include/reader/licReaderELC1.h b/include/reader/licReaderELC1.h index 5f43c28..b747bd6 100644 --- a/include/reader/licReaderELC1.h +++ b/include/reader/licReaderELC1.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef ELC1_READER__H #define ELC1_READER__H @@ -28,4 +30,5 @@ namespace Reader }; } +#endif #endif \ No newline at end of file diff --git a/include/reader/licReaderELC2.h b/include/reader/licReaderELC2.h index a03ac16..fd0cfcc 100644 --- a/include/reader/licReaderELC2.h +++ b/include/reader/licReaderELC2.h @@ -1,3 +1,4 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE #ifndef ELC2_READER_H #define ELC2_READER_H @@ -26,4 +27,5 @@ namespace Reader }; } +#endif #endif \ No newline at end of file diff --git a/include/reader/licReaderELC3.h b/include/reader/licReaderELC3.h index f8cae3a..352c4ef 100644 --- a/include/reader/licReaderELC3.h +++ b/include/reader/licReaderELC3.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef ELC3_READER__H #define ELC3_READER__H @@ -6,4 +8,5 @@ namespace Reader } +#endif #endif \ No newline at end of file diff --git a/include/reader/licenceReader.h b/include/reader/licenceReader.h index d241267..324b446 100644 --- a/include/reader/licenceReader.h +++ b/include/reader/licenceReader.h @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #ifndef LICENCE_READER_H_ #define LICENCE_READER_H_ @@ -29,7 +31,6 @@ public: string operationErrors = ""; bool argumentsCorrect = false; ErrorMessage error; - SDCardInfo sdCardInfo {}; LicenceReader(); @@ -47,4 +48,5 @@ private: string configFileName = ""; }; +#endif #endif \ No newline at end of file diff --git a/licData.xml b/licData.xml index 9d502a7..88dc0af 100644 --- a/licData.xml +++ b/licData.xml @@ -1,32 +1,45 @@ - -EOV_OSV -WAGO + +DRT +wago Licence pro EOV_OSV -start.cz -teco -Projekt XXX stanice YYY - - - Položka licence 1 - 666 - 100 - - - Položka licence 2 - 777 - 200 - - - Položka licence 3 - 888 - 300 - - - Položka licence 3 - 999 - 1600 - - +Zdenda Test CRC1 + + +pt_Ez_buffer +1 +4294967295 + + +pt_Ez_webs +2 +555 + + +pt_Ez_iec61850c +14 +222 + + +pt_Ez_iec104c +9 +333 + + +pt_Ez_interHW +0 +3 + + +pt_Ez_iec104s +8 +444 + + +TEST +20 +4444 + + \ No newline at end of file diff --git a/licDataTest.xml b/licDataTest.xml new file mode 100644 index 0000000..7fcbeb6 --- /dev/null +++ b/licDataTest.xml @@ -0,0 +1,44 @@ + + +DRT +wago +Licence pro EOV_OSV +Zdenda Test CRC1 + + +pt_Ez_interHW +2 +22 + + +pt_Ez_iec61850c +7 +77 + + +pt_Ez_buffer +1 +4294967295 + + +pt_Ez_mdbrtum +15 +150 + + +pt_Ez_iec104c +5 +55 + + +pt_Ez_iec104s +6 +66 + + +pt_Ez_webs +2 +4294967295 + + + \ No newline at end of file diff --git a/output/ezlic_drt0_jjacdgpdxpb.lic b/output/ezlic_drt0_jjacdgpdxpb.lic index dd671b5..d9a31ab 100644 Binary files a/output/ezlic_drt0_jjacdgpdxpb.lic and b/output/ezlic_drt0_jjacdgpdxpb.lic differ diff --git a/output/ezlic_eovosv0_wqxcyjpdxji.lic b/output/ezlic_eovosv0_wqxcyjpdxji.lic new file mode 100644 index 0000000..98d0dd2 Binary files /dev/null and b/output/ezlic_eovosv0_wqxcyjpdxji.lic differ diff --git a/output/licData.xml b/output/licData.xml index 7fcbeb6..adb5aa9 100644 --- a/output/licData.xml +++ b/output/licData.xml @@ -3,17 +3,12 @@ DRT wago Licence pro EOV_OSV -Zdenda Test CRC1 +Zdenda Test CRC4 pt_Ez_interHW -2 -22 - - -pt_Ez_iec61850c -7 -77 +0 +3 pt_Ez_buffer @@ -21,9 +16,9 @@ 4294967295 -pt_Ez_mdbrtum -15 -150 +pt_Ez_webs +2 +4294967295 pt_Ez_iec104c @@ -36,9 +31,9 @@ 66 -pt_Ez_webs -2 -4294967295 +pt_Ez_iec61850c +7 +77 \ No newline at end of file diff --git a/output/licDataELC1.xml b/output/licDataELC1.xml new file mode 100644 index 0000000..9ca2518 --- /dev/null +++ b/output/licDataELC1.xml @@ -0,0 +1,39 @@ + + +EOV_OSV +wago +Licence pro EOV_OSV +Zdenda Test CRC4 + + +pt_Ez_interHW +0 +3 + + +pt_Ez_buffer +1 +4294967295 + + +pt_Ez_webs +2 +4294967295 + + +pt_Ez_iec104c +5 +55 + + +pt_Ez_iec104s +6 +66 + + +pt_Ez_iec61850c +7 +77 + + + \ No newline at end of file diff --git a/output/licDataOld.xml b/output/licDataRDT2.xml similarity index 65% rename from output/licDataOld.xml rename to output/licDataRDT2.xml index 88dc0af..adb5aa9 100644 --- a/output/licDataOld.xml +++ b/output/licDataRDT2.xml @@ -3,9 +3,14 @@ DRT wago Licence pro EOV_OSV -Zdenda Test CRC1 +Zdenda Test CRC4 +pt_Ez_interHW +0 +3 + + pt_Ez_buffer 1 4294967295 @@ -13,33 +18,22 @@ pt_Ez_webs 2 -555 - - -pt_Ez_iec61850c -14 -222 +4294967295 pt_Ez_iec104c -9 -333 - - -pt_Ez_interHW -0 -3 +5 +55 pt_Ez_iec104s -8 -444 +6 +66 -TEST -20 -4444 +pt_Ez_iec61850c +7 +77 - \ No newline at end of file diff --git a/output/licenceGenerator b/output/licenceGenerator index 18b33d8..69433f9 100644 Binary files a/output/licenceGenerator and b/output/licenceGenerator differ diff --git a/output/temp/ezlic_drt0_jjacdgpdxpb.lic b/output/temp/ezlic_drt0_jjacdgpdxpb.lic deleted file mode 100644 index 6e82450..0000000 Binary files a/output/temp/ezlic_drt0_jjacdgpdxpb.lic and /dev/null differ diff --git a/output/temp/ezlic_eovosv0_wqxcyjpdxji.lic b/output/temp/ezlic_eovosv0_wqxcyjpdxji.lic new file mode 100644 index 0000000..98d0dd2 Binary files /dev/null and b/output/temp/ezlic_eovosv0_wqxcyjpdxji.lic differ diff --git a/output/temp/generate/licenceGenerator b/output/temp/generate/licenceGenerator index 4b8fb02..2bcbe83 100644 Binary files a/output/temp/generate/licenceGenerator and b/output/temp/generate/licenceGenerator differ diff --git a/output/temp/tempBeforeDword/generate/ezlic_eovosv0_wqxcyjpdxji.lic b/output/temp/tempBeforeDword/generate/ezlic_eovosv0_wqxcyjpdxji.lic new file mode 100644 index 0000000..98d0dd2 Binary files /dev/null and b/output/temp/tempBeforeDword/generate/ezlic_eovosv0_wqxcyjpdxji.lic differ diff --git a/src/CreateLicence.cpp b/src/CreateLicence.cpp index 4ce2ca9..4533f1e 100644 --- a/src/CreateLicence.cpp +++ b/src/CreateLicence.cpp @@ -1,3 +1,4 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE #define LINUX 1 //#define WINDOWS 1 @@ -8,7 +9,7 @@ /// @param argc /// @param argv parametry pro generování licence /// @return -int main6(int argc, char *argv[]) +int main8(int argc, char *argv[]) { unordered_map arguments = getArguments(argc, argv); try @@ -32,3 +33,5 @@ int main6(int argc, char *argv[]) system("pause"); return SUCCES; } + +#endif \ No newline at end of file diff --git a/src/ReadLicence.cpp b/src/ReadLicence.cpp index e4679e7..f18116e 100644 --- a/src/ReadLicence.cpp +++ b/src/ReadLicence.cpp @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #define LINUX 1 // #define WINDOWS 1 @@ -10,9 +12,10 @@ int main() { // buffer,850client,104client, 104server, web - // kouknout na unikatní klíc pro linux + // kouknout na unikatní klíc pro linux (native uid, i openssl neco má) try { + InitStructure initStructure = {}; initStructure.licenceType = (int)LicenceType::DRT; initStructure.licenceVersion = 1; @@ -22,7 +25,7 @@ int main() // pro ELC 1 LicenceELC1Info je to isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; } initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence - // verze původní ELC 1 + // // verze původní ELC 1 // LicenceReader licenceReaderELC1{}; // if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni // { @@ -42,7 +45,10 @@ int main() // cout << "CHYBA: " << licenceReaderELC1.error.message; // } - //TODO přidat udaje o SD, kompatibilita, čas, jmeno licenčního souboru + // return SUCCES; + + // TODO přidat udaje o SD, kompatibilita, čas, jmeno licenčního souboru + // pročistit private/public // verze ELC 2 pro jeden protokol LicenceReader licenceReaderELC2{}; @@ -54,11 +60,15 @@ int main() LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) // if () int protocolId = 2; - //ukayka dat SD karty + // ukayka dat SD karty cout << "SD přečteno: " << licenceReaderELC2.sdCardInfo.isLoaded << "\n"; cout << "Card size: " << licenceReaderELC2.sdCardInfo.cardSize << "\n"; cout << "serial: " << licenceReaderELC2.sdCardInfo.serialNumber << "\n"; - + cout << "date: " << licenceReaderELC2.sdCardInfo.date << "\n"; + cout << "name: " << licenceReaderELC2.sdCardInfo.name << "\n"; + cout << "oemID: " << licenceReaderELC2.sdCardInfo.oemID << "\n"; + cout << "licenceFileName: " << licenceReaderELC2.sdCardInfo.licenceFileName << "\n"; + // if (initStructure.compatibility == 1) //ukazka kompatibilita 1 // { // LicenceELC2Item_1 info; //jiná struktura, zbytek stejný @@ -69,7 +79,7 @@ int main() //........... // } - //TODO toto upravit, kdyz nic neexistuje, tak to vrátí false + // TODO toto upravit, kdyz nic neexistuje, tak to vrátí false if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info)) { cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl; @@ -116,36 +126,12 @@ int main() { cout << "Obecna chyba\n"; } - - // } ] } licC hLenght2 cSize2 ser number 4 - //125-93-125-1 - 1 - 0 - 1 - 6 - 163 - 1 - 231 - 59 - 197 -3 - 216 - 90 -1 -0 -0 -0 -255-255-255-255 - // - //125-93-125-1 - 1 - 0 - 1 - 6 - 163 - 1 - 231 - 59 - 197 -3 - 216 - 90 -1 -0 -236 -0 -255-255-255-255 - - - //here ŹVżz5Ž;k+3f‰"Ş•ů[ 125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0 - //125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-236-0-255-255-255-255-0 - string gV = "69-76-67-50-95-1-1-0-1-6-163-1-231-59-197-3-216-90-123-34-118-101-114-115-105-111-110-34-58-49-46-49-46-49-34-44-34-112-114-111-106-101-99-116-34-58-34-90-100-101-110-100-97-32-84-101-115-116-32-67-82-67-49-34-44-34-100-97-116-101-34-58-34-52-46-52-46-50-48-50-52-34-44-34-110-111-116-101-34-58-34-112-111-122-110-195-161-109-107-97-34-44-34-108-105-99-101-110-99-101-84-121-112-101-34-58-34-68-82-84-48-34-44-34-105-116-101-109-115-34-58-91-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-98-117-102-102-101-114-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-54-49-56-53-48-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-55-55-55-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-53-53-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-54-54-54-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-119-101-98-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-110-116-101-114-72-87-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-51-34-125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-7-0-0-0-9-3-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-5-0-0-0-43-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-6-0-0-0-154-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-2-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-0-0-0-0-3-0-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-186-165"; - string bV = "69-76-67-50-95-1-1-0-1-6-163-1-231-59-197-3-216-90-123-34-118-101-114-115-105-111-110-34-58-49-46-49-46-49-34-44-34-112-114-111-106-101-99-116-34-58-34-90-100-101-110-100-97-32-84-101-115-116-32-67-82-67-49-34-44-34-100-97-116-101-34-58-34-52-46-52-46-50-48-50-52-34-44-34-110-111-116-101-34-58-34-112-111-122-110-195-161-109-107-97-34-44-34-108-105-99-101-110-99-101-84-121-112-101-34-58-34-68-82-84-48-34-44-34-105-116-101-109-115-34-58-91-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-98-117-102-102-101-114-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-54-49-56-53-48-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-55-55-55-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-99-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-53-53-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-101-99-49-48-52-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-54-54-54-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-119-101-98-115-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-52-50-57-52-57-54-55-50-57-53-34-125-44-123-34-110-97-109-101-34-58-34-112-116-95-69-122-95-105-110-116-101-114-72-87-34-44-34-100-97-116-97-80-111-105-110-116-115-67-111-117-110-116-34-58-34-51-34-125-93-125-1-1-0-1-6-163-1-231-59-197-3-216-90-1-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-7-0-0-0-9-3-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-5-0-0-0-43-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-6-0-0-0-154-2-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-2-0-0-0-255-255-255-255-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-0-0-0-0-3-0-0-0-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-186-165"; - - // std::vector gTokens; - // std::vector bTokens; - // std::stringstream ssG(gV); - // std::stringstream ssB(bV); - // std::string token; - - // while (getline(ssG, token, '-')) { gTokens.push_back(token); } - // while (getline(ssB, token, '-')) { bTokens.push_back(token); } - - // cout << gTokens.size() << "\n"; - // cout << bTokens.size() << "\n"; - - - cout << (gV == bV) << "\n"; - return SUCCES; } +// buffer,web, 850client,104client, 104server, +// + /* pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW pt_Ez_buffer, // 1 - datovy Buffer @@ -187,7 +173,7 @@ pt_Ez_mbusm, // 36 - MBus master pt_Ez_azddakm, // 37 - AZD DAK master pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP) pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol) - + Pro index 0 (pt_Ez_interHW) jsou možné hodnoty (počet licenčních bodů): @@ -244,3 +230,5 @@ pt_Ez_azddakm, // 37 - AZD DAK master pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP) pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol) */ + +#endif \ No newline at end of file diff --git a/src/cid b/src/cid index 32a9336..9a70e3e 100644 --- a/src/cid +++ b/src/cid @@ -1,4 +1,4 @@ -9f5449534443495461457815de0164a9 +9f54495344434954615ad803c50171bf 6   . x4   .. nt$6 & manfid 6  cid "6  fwrev 6 Jm  csd ,6 gEd$ subsystem 46 % diff --git a/src/common/SDCard.cpp b/src/common/SDCard.cpp index 0f313f6..56f7923 100644 --- a/src/common/SDCard.cpp +++ b/src/common/SDCard.cpp @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #include "utils.h" #include "SDCard.h" @@ -72,6 +74,11 @@ bool SDCard::readSDCard() this->cardData.serialNumber = this->cardData.CID[9] << 24 | this->cardData.CID[10] << 16 | this->cardData.CID[11] << 8 | this->cardData.CID[12]; + this->cardData.manufacturerDate_year = cHexNibbleToNo[this->cardData.CID_nibble[27]] * 10 + cHexNibbleToNo[this->cardData.CID_nibble[28]] + 2000; + this->cardData.manufacturerDate_month = cHexNibbleToNo[this->cardData.CID_nibble[29]]; + this->cardData.date = to_string(this->cardData.manufacturerDate_month) + "/" + to_string(this->cardData.manufacturerDate_year); + //string date = cSDMonthStr1[this->sdData.manufacturerDate_month] + std::to_string(this->sdData.manufacturerDate_year); + // CSD for (int i = 0; i < CSD_LENGTH; i++) this->cardData.CSD_nibble[i] = (BYTE)csd[i]; @@ -141,3 +148,5 @@ bool SDCard::getCSDFromFile() return true; } + +#endif \ No newline at end of file diff --git a/src/common/cid b/src/common/cid new file mode 100644 index 0000000..9a70e3e --- /dev/null +++ b/src/common/cid @@ -0,0 +1,5 @@ +9f54495344434954615ad803c50171bf +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/src/common/csd b/src/common/csd new file mode 100644 index 0000000..609cf45 --- /dev/null +++ b/src/common/csd @@ -0,0 +1,2 @@ +400e00325b5900003be77f800a400043 + \ No newline at end of file diff --git a/src/common/ezlic_drt0_jjacdgpdxpb.lic b/src/common/ezlic_drt0_jjacdgpdxpb.lic new file mode 100644 index 0000000..dd671b5 Binary files /dev/null and b/src/common/ezlic_drt0_jjacdgpdxpb.lic differ diff --git a/src/common/licenceELC1.cpp b/src/common/licenceELC1.cpp index 8edb22d..64d519b 100644 --- a/src/common/licenceELC1.cpp +++ b/src/common/licenceELC1.cpp @@ -1,3 +1,6 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + + #include "licenceELC1.h" #include "utils.h" @@ -216,3 +219,5 @@ string LicenceELC1::getLicenceName(BYTE licPostfix) } return result; } + +#endif \ No newline at end of file diff --git a/src/common/licenceELC2.cpp b/src/common/licenceELC2.cpp index 7377888..7c62aee 100644 --- a/src/common/licenceELC2.cpp +++ b/src/common/licenceELC2.cpp @@ -1,15 +1,18 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + + #include "licenceELC2.h" #include "utils.h" +LicenceELC2::LicenceELC2() {} - LicenceELC2::LicenceELC2(){} - - LicenceELC2::~LicenceELC2(){} +LicenceELC2::~LicenceELC2() {} - LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification): lIdentification(licIdentification) - {} +LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification) : lIdentification(licIdentification) +{ +} - /// @brief get proper licencename +/// @brief get proper licencename /// @param licPostfix /// @return string LicenceELC2::getLicenceName() @@ -18,7 +21,7 @@ string LicenceELC2::getLicenceName() char prefixChar = 97; int licType = (int)lIdentification.licLicenceType; int lVersion = lIdentification.licenceVersion; - + unordered_map baseString; baseString.insert(std::pair((int)LicenceType::EOS_EOV, "ezlic_eovosv")); baseString.insert(std::pair((int)LicenceType::DDTS, "ezlic_ddts")); @@ -70,7 +73,8 @@ vector LicenceELC2::cryptPrivateContent(const std::vector result(encrypted, encrypted + finalEncryptedLength); @@ -79,69 +83,79 @@ vector LicenceELC2::cryptPrivateContent(const std::vector LicenceELC2::decryptPrivateContent(const std::vector &content) { - - BYTE initVector[15] = {0}; - BYTE aesKey[32] = {0}; + BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0}; + BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0}; LicenceELC2::initVector(initVector, aesKey); const unsigned char *encryptedData = content.data(); unsigned char decrypted[10000] = {}; + // cout << "\n --- zašifrovaná data přímo z decrypt metody:" << content.size() << "--- \n"; + // for (int i = 0; i < (int)content.size(); i++) + // { + // cout << (int)encryptedData[i] << "-"; + // } + // cout << "---\n\n"; + int decrypted_len = decrypt(encryptedData, content.size(), aesKey, initVector, decrypted); - if (decrypted_len <= 0) throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování."); + if (decrypted_len <= 0) + throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování."); - std::vector result(decrypted, decrypted + decrypted_len); + vector res{}; + for (int i = 0; i < decrypted_len; i++) + { + // if (i==15) res.push_back(1); + res.push_back(decrypted[i]); + } - return result; + // cout << "\n --- dešifrovaná data přímo z decrypt metody:" << content.size() << "--- \n"; + // for (int i = 0; i < decrypted_len; i++) + // { + // cout << (int)decrypted[i] << "-"; + // } + // cout << "---\n\n"; + + return res; + // std::vector result(decrypted, decrypted + decrypted_len); + // return result; } -void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[]) +void LicenceELC2::initVector(BYTE *iVector, BYTE *key) { + CryptInitVector vec1 = {this->sdCard.cardData.CID[10], + this->sdCard.cardData.CID[12], + this->sdCard.cardData.CID[11], + this->sdCard.cardData.CID[9], + this->sdCard.cardData.CID_nibble[22] - 15, + this->sdCard.cardData.CID_nibble[24] - 15, + this->sdCard.cardData.CID_nibble[25] - 15, + this->sdCard.cardData.CID_nibble[21] - 15, + 9, 10, 11, 12, 13, 14, 15, 16}; + CryptInitVector vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; // TODO přidat smysluplnější indexy + CryptInitVector vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - struct Vector15 - { - int vec[15]; - }; + std::unordered_map vectors; + vectors.insert(std::pair(1, vec1)); + vectors.insert(std::pair(2, vec2)); + vectors.insert(std::pair(3, vec3)); - Vector15 vec1 = {this->sdCard.cardData.CID[10], - this->sdCard.cardData.CID[12], - this->sdCard.cardData.CID[11], - this->sdCard.cardData.CID[9], - this->sdCard.cardData.CID_nibble[22] - 15, - this->sdCard.cardData.CID_nibble[24] - 15, - this->sdCard.cardData.CID_nibble[25] - 15, - this->sdCard.cardData.CID_nibble[21] - 15, - 9, 10, 11, 12, 13, 14, 15}; - Vector15 vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //TODO přidat smysluplnější indexy - Vector15 vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + CryptAesKey key1 = {this->sdCard.cardData.CID[12], + this->sdCard.cardData.CID[23] - 15, + this->sdCard.cardData.CID[25] - 15, + this->sdCard.cardData.CID[11], + this->sdCard.cardData.CID[9], + this->sdCard.cardData.CID_nibble[21], + this->sdCard.cardData.CID[9] % 25, + this->sdCard.cardData.CID_nibble[22] - 15, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + CryptAesKey key2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + CryptAesKey key3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - std::unordered_map vectors; - vectors.insert(std::pair(1, vec1)); - vectors.insert(std::pair(2, vec2)); - vectors.insert(std::pair(3, vec3)); - - struct Key32 - { - int key[32]; - }; - - Key32 key1 = {this->sdCard.cardData.CID[12], - this->sdCard.cardData.CID[23] - 15, - this->sdCard.cardData.CID[25] - 15, - this->sdCard.cardData.CID[11], - this->sdCard.cardData.CID[9], - this->sdCard.cardData.CID_nibble[21], - this->sdCard.cardData.CID[9] % 25, - this->sdCard.cardData.CID_nibble[22] - 15, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - Key32 key2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - Key32 key3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - - std::unordered_map keys; - keys.insert(std::pair(1, key1)); - keys.insert(std::pair(2, key2)); - keys.insert(std::pair(3, key3)); + std::unordered_map keys; + keys.insert(std::pair(1, key1)); + keys.insert(std::pair(2, key2)); + keys.insert(std::pair(3, key3)); int lVersion = lIdentification.licenceVersion; @@ -169,4 +183,4 @@ void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[]) memcpy(&key[24], &key[12], 8); } - +#endif \ No newline at end of file diff --git a/src/common/utils.cpp b/src/common/utils.cpp index d13c66a..37e4df6 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -1,3 +1,4 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE #include #include /* core library */ @@ -127,14 +128,20 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke * is 128 bits */ if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) + { + EVP_CIPHER_CTX_free(ctx); return -1; + } /* * Provide the message to be encrypted, and obtain the encrypted output. * EVP_EncryptUpdate can be called multiple times if necessary */ if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)) + { + EVP_CIPHER_CTX_free(ctx); return -1; + } ciphertext_len = len; /* @@ -142,7 +149,10 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke * this stage. */ if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) + { + EVP_CIPHER_CTX_free(ctx); return -1; + } ciphertext_len += len; /* Clean up */ @@ -472,3 +482,5 @@ bool readFile(string fileName, vector &output) return true; } + +#endif \ No newline at end of file diff --git a/src/csd b/src/csd index 50b4809..609cf45 100644 --- a/src/csd +++ b/src/csd @@ -1,2 +1,2 @@ -400e00325b5900003a0d7f800a40008d +400e00325b5900003be77f800a400043 \ No newline at end of file diff --git a/src/ezlic_drt0_jjacdgpdxpb.lic b/src/ezlic_drt0_jjacdgpdxpb.lic new file mode 100644 index 0000000..dd671b5 Binary files /dev/null and b/src/ezlic_drt0_jjacdgpdxpb.lic differ diff --git a/src/generator/cid b/src/generator/cid new file mode 100644 index 0000000..9a70e3e --- /dev/null +++ b/src/generator/cid @@ -0,0 +1,5 @@ +9f54495344434954615ad803c50171bf +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/src/generator/csd b/src/generator/csd new file mode 100644 index 0000000..609cf45 --- /dev/null +++ b/src/generator/csd @@ -0,0 +1,2 @@ +400e00325b5900003be77f800a400043 + \ No newline at end of file diff --git a/src/generator/licGenELC1.cpp b/src/generator/licGenELC1.cpp index 59b78ce..73e25a3 100644 --- a/src/generator/licGenELC1.cpp +++ b/src/generator/licGenELC1.cpp @@ -57,194 +57,6 @@ namespace Generator } } - // bool Licence1::createLicenceOld() - // { - // if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); - // initCrypto(); - - // // promenne pro praci se soubory a adresari - // LicenceDataMainELC dataMainToFileELC1{}; //: tEz_LicenceDataMainELC1; hlavicka urcena pro zapis do souboru - typ ELC1 - // LicenceData dataToFile{}; // tEz_LicenceData_10_10; // data urcena pro sifrovani a zapis do soubotu - verze => hlavicka: 1.0, data: 1.0 - - // // pomocne promenne - // string licencePostfix; //: STRING; pomocna promenna pro kontrolu postfixu - // string mainLicDescription; //: STRING(79); globalni pojmenovani licence v nesifrovane casti licence - - // USINT generation = 2; //: USINT; verze SW pro licenceřř - - // PlcData plcData; - // plcData.licenceName = "Licence"; - // plcData.licenceType = "1"; - // plcData.station = stationName; - // plcData.distributor = distributor; - - // LicenceSourceData licSourceData; - - // if (plcData.licenceType == "EOV" || plcData.licenceType == to_string((int)PlcLicenceType::LicenceEov)) - // { - // licSourceData.licType = 0x1AA2; - // licSourceData.licPostfix = 0; - // getCharsFromString(plcData.station, licSourceData.licDescription1); - // getCharsFromString(plcData.station, dataToFile.header.licDescription1); - // getCharsFromString(plcData.distributor, licSourceData.licDescription2); - // getCharsFromString(plcData.distributor, dataToFile.header.licDescription2); - // } - - // LicenceIdent licIdent{}; - // licIdent.licPrefixType = licSourceData.licType >> 12; - // licIdent.licHeaderType = licSourceData.licType >> 8 & 0x000F; - // licIdent.licDataType = licSourceData.licType >> 4 & 0x000F; - // licIdent.licSubType = licIdent.licHeaderType << 8 | licIdent.licHeaderType; - // licIdent.licIDType = licSourceData.licType & 0x000F; - - // if (licSourceData.licPostfix > 9) - // licSourceData.licPostfix = 0; - // licencePostfix = to_string(licSourceData.licPostfix); - - // string licenseFileName = getLicenceName(0); - // licSourceData.licPostfixIdent = right(licencePostfix, 1); - - // if (licIdent.licHeaderType == cEzLic_p78ou3_HeaderType_10) - // { - // if (licIdent.licDataType == cEzLic_p78ou3_DataType_10) - // { - // dataToFile.id.version = 10; - // dataToFile.id.cardSize = this->sdData.cardSize; - - // switch (licIdent.licIDType) - // { - // case 1://cEzLic_p78ou3_IDType_DDTS: - // mainLicDescription = "ddts "; - // break; - // case 2: //cEzLic_p78ou3_IDType_EOVOSV: - // mainLicDescription = "eov, osv "; - // break; - // default: - // mainLicDescription = "neznama app "; - // } - - // mainLicDescription += licSourceData.licPostfixIdent; - // mainLicDescription += " => "; - - // dataToFile.header.licVersion = 10; - // dataToFile.header.licType = licIdent.licIDType; - // dataToFile.header.licDate = getLicDate(); // 1692230400; //getLicDate(); //1692144000;// getLicDate(); - // mainLicDescription += dataToFile.header.licDescription1; - // mainLicDescription += " ["; - // mainLicDescription += dataToFile.header.licDescription2; - // mainLicDescription += "]"; - - // if (licIdent.licIDType == cEzLic_p78ou3_IDType_EOVOSV) - // { - // if (generation == 1) // stará verze - // { - // dataToFile.header.licCount = 1; - // dataToFile.items[0].licCount = 65535; - // dataToFile.items[0].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1; - // dataToFile.items[0].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1; - // } - // else - // { - // dataToFile.header.licCount = 1; - // dataToFile.items[1].licCount = 65535; // 65535; - // dataToFile.items[1].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1; - // dataToFile.items[1].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1; - // } - // } - - // unsigned char encrypted[10000] = {}; - // const int s = sizeof(dataToFile); - // unsigned char byteArray[s] = {}; - // memcpy(byteArray, &dataToFile, sizeof(dataToFile)); - - // dataToFile.crc = calculateCRC16(byteArray, s - sizeof(dataToFile.crc)); // 47535 | 884:38382 - - // memcpy(byteArray, &dataToFile, sizeof(dataToFile)); - - // int finalEncryptedLength = encrypt(byteArray, sizeof(dataToFile), this->cryptData.aesKey, this->cryptData.aesInitVector, encrypted); - - // if (licIdent.licPrefixType == cEzLic_p78ou3_LicPrefixType_ELC1) // typ1 = pouze zasifrovani dat - // { - // dataMainToFileELC1.prefix = 0x31434C45; - // getCharsFromString(mainLicDescription, dataMainToFileELC1.licHeader.description); - // dataMainToFileELC1.licHeader.sizeData = finalEncryptedLength; // sizeof(dataToFile); // 884; - // dataMainToFileELC1.licHeader.licType = licIdent.licIDType; - // dataMainToFileELC1.licHeader.licSubType = licIdent.licHeaderType << 8 | licIdent.licDataType; - // } - - // const int dataMainLength = sizeof(dataMainToFileELC1); - // const int dataToFileLength = sizeof(dataToFile); - // const int totalEncryptedLength = dataMainLength + finalEncryptedLength; - - // unsigned char bdataMainToFileELC1[dataMainLength] = {}; - // memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength); - - // unsigned char bdataToFile[dataToFileLength] = {}; - // memcpy(bdataToFile, &dataToFile, dataToFileLength); - // unsigned char totalEncryptedArray[totalEncryptedLength] = {}; - - // for (int i = 0; i < dataMainLength; i++) - // totalEncryptedArray[i] = bdataMainToFileELC1[i]; - // for (int i = 0; i < finalEncryptedLength; i++) - // totalEncryptedArray[i + dataMainLength] = encrypted[i]; - - // string fullFile = getCompletePath(licenseFileName); - - // if (binaryGeneration == BinaryGenerationType::File) - // { - // #ifdef WINDOWS - - // char licFileNameToSave[licenseFileName.length()] = {}; - // getCharsFromString(licenseFileName, licFileNameToSave, licenseFileName.length()); - - // FILE *fileLicence = fopen(licFileNameToSave, "wb"); - // if (fileLicence) - // { - // fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence); - // // printf("License binary saved.\n"); - // fclose(fileLicence); - // cout << licenseFileName << endl; - // return true; - // } - - // #else - // std::ofstream outputFile(fullFile); - // if (outputFile.is_open()) - // { - // outputFile.write(reinterpret_cast(totalEncryptedArray), totalEncryptedLength); - // outputFile.close(); - // std::cout << licenseFileName; - // } - // else - // { - // std::cerr << "Unable to open licence file." << std::endl; - // } - // return true; - // #endif - // } - // else - // { - // int totalFileSize = sizeof(totalEncryptedArray); - // // cout << "data:text/plain;base64,"; - // cout << "data:application/octet-stream;base64,"; - - // char encryptedChars[totalFileSize]; - - // for (int i = 0; i < totalFileSize; i++) - // encryptedChars[i] = static_cast(totalEncryptedArray[i]); - - // string strToBase = convertToString(encryptedChars, totalFileSize); - // string base64Coded = base64_encode_ai(strToBase); - // cout << base64Coded << endl; - - // return true; - // } - // } - // } - - // return false; - // } - bool Licence1::createLicence() { if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); diff --git a/src/generator/licGenELC2.cpp b/src/generator/licGenELC2.cpp index 6f450c0..da1842b 100644 --- a/src/generator/licGenELC2.cpp +++ b/src/generator/licGenELC2.cpp @@ -25,7 +25,7 @@ namespace Generator PublicHeader publicHeader; publicHeader.version = getVersion(lIdentification.revision); publicHeader.projectDescription = projectDescription; - publicHeader.date = "4.4.2024"; //getDate(); + publicHeader.date = getDate(); publicHeader.licenceType = lIdentification.licTypeName; publicHeader.licenceType += to_string(lIdentification.licenceIndex); @@ -98,7 +98,7 @@ namespace Generator result.append("."); result.append(to_string(middleVersion)); result.append("."); - string tempLicenceCount = "1"; // TODO + string tempLicenceCount = "1"; result.append(tempLicenceCount); return result; } @@ -252,16 +252,9 @@ namespace Generator privateContent.push_back(1); privateContent.push_back(1); privateContent.push_back(1); - - - - // cout << "basic private: \n"; - // for (const auto x : privateContent) cout << (int)x << "-"; - // cout << "\n"; for (licDataItem dataItem : this->licBody.privateContent.dataItems) { - cout << "proto: " << dataItem.protoId << "---"; privateContent.push_back(dataItem.protoId & 0xFF); privateContent.push_back((dataItem.protoId >> 8) & 0xFF); privateContent.push_back((dataItem.protoId >> 16) & 0xFF); @@ -270,14 +263,8 @@ namespace Generator privateContent.push_back((dataItem.licCount >> 8) & 0xFF); privateContent.push_back((dataItem.licCount >> 16) & 0xFF); privateContent.push_back((dataItem.licCount >> 24) & 0xFF); - for (const auto x : privateContent) cout << (int)x << "-"; - cout << "\n"; - //for (unsigned int i = 0; i < sizeof(dataItem.dummy); i++) privateContent.push_back(i); } - cout << "\n final private \n"; - - #ifdef CRCCHECK cout << "CRC private size: " << privateContent.size() << "\n"; cout << "CRC gen private: " << calculateCRC16(privateContent) << "\n"; diff --git a/src/reader/LicenceReader.cpp b/src/reader/LicenceReader.cpp index 364d4e5..82dd000 100644 --- a/src/reader/LicenceReader.cpp +++ b/src/reader/LicenceReader.cpp @@ -1,3 +1,6 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + + #include ELCType licElcType = ELCType::ELC2; @@ -93,6 +96,10 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) this->sdCardInfo.isLoaded = true; this->sdCardInfo.serialNumber = this->licence2->sdCard.cardData.serialNumber; this->sdCardInfo.cardSize = this->licence2->sdCard.cardData.cardSize; + this->sdCardInfo.date = this->licence2->sdCard.cardData.date; + this->sdCardInfo.name = this->licence2->sdCard.cardData.name; + this->sdCardInfo.oemID = this->licence2->sdCard.cardData.oemID; + this->sdCardInfo.licenceFileName = this->licence2->licFileName; break; } @@ -274,3 +281,5 @@ bool LicenceReader::getLicenceInfo(void *returnStructure) LicenceReader::~LicenceReader() { } + +#endif \ No newline at end of file diff --git a/src/reader/cid b/src/reader/cid new file mode 100644 index 0000000..9a70e3e --- /dev/null +++ b/src/reader/cid @@ -0,0 +1,5 @@ +9f54495344434954615ad803c50171bf +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/src/reader/csd b/src/reader/csd new file mode 100644 index 0000000..609cf45 --- /dev/null +++ b/src/reader/csd @@ -0,0 +1,2 @@ +400e00325b5900003be77f800a400043 + \ No newline at end of file diff --git a/src/reader/ezlic_drt0_jjacdgpdxpb.lic b/src/reader/ezlic_drt0_jjacdgpdxpb.lic new file mode 100644 index 0000000..dd671b5 Binary files /dev/null and b/src/reader/ezlic_drt0_jjacdgpdxpb.lic differ diff --git a/src/reader/licReaderELC1.cpp b/src/reader/licReaderELC1.cpp index 52ecad6..62c923d 100644 --- a/src/reader/licReaderELC1.cpp +++ b/src/reader/licReaderELC1.cpp @@ -1,3 +1,5 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #include "licReaderELC1.h" namespace Reader @@ -121,4 +123,6 @@ namespace Reader return true; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/reader/licReaderELC2.cpp b/src/reader/licReaderELC2.cpp index 7985c5f..a93c571 100644 --- a/src/reader/licReaderELC2.cpp +++ b/src/reader/licReaderELC2.cpp @@ -1,5 +1,8 @@ + +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #include "licReaderELC2.h" -#define SHOW 1 +#define SHOW6 1 namespace Reader { @@ -24,12 +27,20 @@ namespace Reader string licFileName = getLicenceName(); string licFilePath = this->licenceFilePath + licFileName; + this->licFileName = licFileName; + vector content {}; if (readFile(licFilePath, content) == false) { throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath); } + #ifdef SHOW + cout << "Celý vstup zašifrovaný: \n"; + for (const auto &x : content) cout << (int)x << "-"; + cout << "\n"; + #endif + this->licBody.licId.licIdent[0] = content[0]; this->licBody.licId.licIdent[1] = content[1]; this->licBody.licId.licIdent[2] = content[2]; @@ -72,11 +83,12 @@ namespace Reader } vector privateContentDecrypted {}; - //vector privateContentDecrypted1 {}; privateContentDecrypted = decryptPrivateContent(encryptedPart); - + #ifdef SHOW + cout << "private encryptedsize: " << encryptedPart.size() << "\n"; + cout << "private decryptedsize: " << privateContentDecrypted.size() << "\n"; cout << "private decrypted: \n"; for (const auto &x : privateContentDecrypted) cout << (int)x << "-"; cout << "\n"; @@ -87,10 +99,6 @@ namespace Reader cout << "CRC read private: " << calculateCRC16(privateContentDecrypted) << "\n"; #endif - // cout << "privateContentDecrypted content length: " << privateContentDecrypted.size() << "\n"; - // for (auto x : privateContentDecrypted) cout << (int)x << "-"; - // cout << "\n"; - LicenceBody licBodyDecrypted; licBodyDecrypted.licenceIdentHeader.licenceType = privateContentDecrypted[0]; licBodyDecrypted.licenceIdentHeader.licenceTypeVersion = privateContentDecrypted[1]; @@ -138,7 +146,6 @@ namespace Reader cout << "vectorsize: " << completeVector.size() << "\n"; cout << "public vector size: " << publicPart.size() << "\n"; cout << "private vector size: " << privateContentDecrypted.size() << "\n"; - for (const auto &pair : this->licenceInfo.licences) { cout << "--<" << pair.first << ", " << pair.second << ">--" << endl; @@ -146,8 +153,6 @@ namespace Reader #endif if (crcCalculated != crcComplete) throw LicenceException((int)GeneralError::LicenceCRCMismatch, "Nesouhlasí CRC."); - else cout << "\n-------------------- KONECNE ---------------------\n"; - return true; } @@ -172,4 +177,6 @@ namespace Reader return true; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/reader/licReaderELC3.cpp b/src/reader/licReaderELC3.cpp index 6c0e341..5411c1f 100644 --- a/src/reader/licReaderELC3.cpp +++ b/src/reader/licReaderELC3.cpp @@ -1,7 +1,11 @@ +#ifndef EZ_APPLICATION_LICENCE_DISABLE + #include "licReaderELC3.h" namespace Reader { } +#endif +