Upravy a opravování kryptování

This commit is contained in:
2024-04-11 14:31:24 +02:00
parent ead3ba6e3e
commit 3b1ee6038e
47 changed files with 414 additions and 422 deletions

View File

@@ -10,4 +10,4 @@ services:
- ./lib:/app/lib
- ./output:/app/output
- ./src:/app/src
/bin

BIN
ezlic_drt0_jjacdgpdxpb.lic Normal file

Binary file not shown.

View File

@@ -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

View File

@@ -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<string, LicenceType> 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<int, int> 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<DWORD, DWORD> licences = {};
@@ -166,21 +173,20 @@ struct LicenceELC2Info
// map<int, int> 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

View File

@@ -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

View File

@@ -1,7 +1,8 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef PLC_LICENCE2_COMMON_H
#define PLC_LICENCE2_COMMON_H
#include <vector>
#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<licDataItem> dataItems {};
WORD crc {};
LicenceIdentDataHeader licenceIdentHeader{};
vector<licDataItem> 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<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
void initVector(BYTE *iVector, BYTE *key);
string getLicenceName();
LicenceBody licBody{};
LicenceIdentification lIdentification{};
private:
};
#endif
#endif

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef UTILS_H_
#define UTILS_H_
@@ -48,7 +50,7 @@ vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, con
bool readFile(string fileName, vector<char> &output);
#endif
#endif

View File

@@ -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();
};
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,32 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="1" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>WAGO</plcType>
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<station>start.cz</station>
<distributor>teco</distributor>
<project>Projekt XXX stanice YYY</project>
<items>
<item>
<name>Položka licence 1</name>
<protoId>666</protoId>
<dataPointsCount>100</dataPointsCount>
</item>
<item>
<name>Položka licence 2</name>
<protoId>777</protoId>
<dataPointsCount>200</dataPointsCount>
</item>
<item>
<name>Položka licence 3</name>
<protoId>888</protoId>
<dataPointsCount>300</dataPointsCount>
</item>
<item>
<name>Položka licence 3</name>
<protoId>999</protoId>
<dataPointsCount>1600</dataPointsCount>
</item>
</items>
<project>Zdenda Test CRC1</project>
<items>
<item>
<name>pt_Ez_buffer</name>
<protoId>1</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>555</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec61850c</name>
<protoId>14</protoId>
<dataPointsCount>222</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104c</name>
<protoId>9</protoId>
<dataPointsCount>333</dataPointsCount>
</item>
<item>
<name>pt_Ez_interHW</name>
<protoId>0</protoId>
<dataPointsCount>3</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104s</name>
<protoId>8</protoId>
<dataPointsCount>444</dataPointsCount>
</item>
<item>
<name>TEST</name>
<protoId>20</protoId>
<dataPointsCount>4444</dataPointsCount>
</item>
</items>
</licence>

44
licDataTest.xml Normal file
View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<project>Zdenda Test CRC1</project>
<items>
<item>
<name>pt_Ez_interHW</name>
<protoId>2</protoId>
<dataPointsCount>22</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec61850c</name>
<protoId>7</protoId>
<dataPointsCount>77</dataPointsCount>
</item>
<item>
<name>pt_Ez_buffer</name>
<protoId>1</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_mdbrtum</name>
<protoId>15</protoId>
<dataPointsCount>150</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104c</name>
<protoId>5</protoId>
<dataPointsCount>55</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104s</name>
<protoId>6</protoId>
<dataPointsCount>66</dataPointsCount>
</item>
<item>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
</items>
</licence>

Binary file not shown.

Binary file not shown.

View File

@@ -3,17 +3,12 @@
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<project>Zdenda Test CRC1</project>
<project>Zdenda Test CRC4</project>
<items>
<item>
<name>pt_Ez_interHW</name>
<protoId>2</protoId>
<dataPointsCount>22</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec61850c</name>
<protoId>7</protoId>
<dataPointsCount>77</dataPointsCount>
<protoId>0</protoId>
<dataPointsCount>3</dataPointsCount>
</item>
<item>
<name>pt_Ez_buffer</name>
@@ -21,9 +16,9 @@
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_mdbrtum</name>
<protoId>15</protoId>
<dataPointsCount>150</dataPointsCount>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104c</name>
@@ -36,9 +31,9 @@
<dataPointsCount>66</dataPointsCount>
</item>
<item>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>4294967295</dataPointsCount>
<name>pt_Ez_iec61850c</name>
<protoId>7</protoId>
<dataPointsCount>77</dataPointsCount>
</item>
</items>
</licence>

39
output/licDataELC1.xml Normal file
View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="1" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<project>Zdenda Test CRC4</project>
<items>
<item>
<name>pt_Ez_interHW</name>
<protoId>0</protoId>
<dataPointsCount>3</dataPointsCount>
</item>
<item>
<name>pt_Ez_buffer</name>
<protoId>1</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104c</name>
<protoId>5</protoId>
<dataPointsCount>55</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104s</name>
<protoId>6</protoId>
<dataPointsCount>66</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec61850c</name>
<protoId>7</protoId>
<dataPointsCount>77</dataPointsCount>
</item>
</items>
</licence>

View File

@@ -3,9 +3,14 @@
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<project>Zdenda Test CRC1</project>
<project>Zdenda Test CRC4</project>
<items>
<item>
<name>pt_Ez_interHW</name>
<protoId>0</protoId>
<dataPointsCount>3</dataPointsCount>
</item>
<item>
<name>pt_Ez_buffer</name>
<protoId>1</protoId>
<dataPointsCount>4294967295</dataPointsCount>
@@ -13,33 +18,22 @@
<item>
<name>pt_Ez_webs</name>
<protoId>2</protoId>
<dataPointsCount>555</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec61850c</name>
<protoId>14</protoId>
<dataPointsCount>222</dataPointsCount>
<dataPointsCount>4294967295</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104c</name>
<protoId>9</protoId>
<dataPointsCount>333</dataPointsCount>
</item>
<item>
<name>pt_Ez_interHW</name>
<protoId>0</protoId>
<dataPointsCount>3</dataPointsCount>
<protoId>5</protoId>
<dataPointsCount>55</dataPointsCount>
</item>
<item>
<name>pt_Ez_iec104s</name>
<protoId>8</protoId>
<dataPointsCount>444</dataPointsCount>
<protoId>6</protoId>
<dataPointsCount>66</dataPointsCount>
</item>
<item>
<name>TEST</name>
<protoId>20</protoId>
<dataPointsCount>4444</dataPointsCount>
<name>pt_Ez_iec61850c</name>
<protoId>7</protoId>
<dataPointsCount>77</dataPointsCount>
</item>
</items>
</licence>

Binary file not shown.

Binary file not shown.

View File

@@ -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<string, string> arguments = getArguments(argc, argv);
try
@@ -32,3 +33,5 @@ int main6(int argc, char *argv[])
system("pause");
return SUCCES;
}
#endif

View File

@@ -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<string> gTokens;
// std::vector<string> 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

View File

@@ -1,4 +1,4 @@
9f5449534443495461457815de0164a9
9f54495344434954615ad803c50171bf
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%

View File

@@ -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

5
src/common/cid Normal file
View File

@@ -0,0 +1,5 @@
9f54495344434954615ad803c50171bf
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%
driver (6 <20><><EFBFBD>-  ocr -6 <20><><EFBFBD>? power *6 <>4L  type 6 <20>1M  date #6 <20>rTP hwrev )6 n<>yR  dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o  ssr 6 <1E>q  scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD>  name

2
src/common/csd Normal file
View File

@@ -0,0 +1,2 @@
400e00325b5900003be77f800a400043

Binary file not shown.

View File

@@ -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

View File

@@ -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<int, string> baseString;
baseString.insert(std::pair<int, string>((int)LicenceType::EOS_EOV, "ezlic_eovosv"));
baseString.insert(std::pair<int, string>((int)LicenceType::DDTS, "ezlic_ddts"));
@@ -70,7 +73,8 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
const unsigned char *plainTextArray = content.data();
int finalEncryptedLength = encrypt(plainTextArray, content.size(), aesKey, initVector, encrypted);
if (finalEncryptedLength <= 0) throw LicenceException((int)GeneralError::EncryptError, "Chyba při kryptování.");
if (finalEncryptedLength <= 0)
throw LicenceException((int)GeneralError::EncryptError, "Chyba při kryptování.");
std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
@@ -79,69 +83,79 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
vector<unsigned char> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &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<unsigned char> result(decrypted, decrypted + decrypted_len);
vector<unsigned char> 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<unsigned char> 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<int, CryptInitVector> vectors;
vectors.insert(std::pair<int, CryptInitVector>(1, vec1));
vectors.insert(std::pair<int, CryptInitVector>(2, vec2));
vectors.insert(std::pair<int, CryptInitVector>(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<int, Vector15> vectors;
vectors.insert(std::pair<int, Vector15>(1, vec1));
vectors.insert(std::pair<int, Vector15>(2, vec2));
vectors.insert(std::pair<int, Vector15>(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<int, Key32> keys;
keys.insert(std::pair<int, Key32>(1, key1));
keys.insert(std::pair<int, Key32>(2, key2));
keys.insert(std::pair<int, Key32>(3, key3));
std::unordered_map<int, CryptAesKey> keys;
keys.insert(std::pair<int, CryptAesKey>(1, key1));
keys.insert(std::pair<int, CryptAesKey>(2, key2));
keys.insert(std::pair<int, CryptAesKey>(3, key3));
int lVersion = lIdentification.licenceVersion;
@@ -169,4 +183,4 @@ void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[])
memcpy(&key[24], &key[12], 8);
}
#endif

View File

@@ -1,3 +1,4 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <openssl/conf.h>
#include <openssl/ssl.h> /* 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<char> &output)
return true;
}
#endif

View File

@@ -1,2 +1,2 @@
400e00325b5900003a0d7f800a40008d
400e00325b5900003be77f800a400043

Binary file not shown.

5
src/generator/cid Normal file
View File

@@ -0,0 +1,5 @@
9f54495344434954615ad803c50171bf
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%
driver (6 <20><><EFBFBD>-  ocr -6 <20><><EFBFBD>? power *6 <>4L  type 6 <20>1M  date #6 <20>rTP hwrev )6 n<>yR  dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o  ssr 6 <1E>q  scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD>  name

2
src/generator/csd Normal file
View File

@@ -0,0 +1,2 @@
400e00325b5900003be77f800a400043

View File

@@ -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<const char *>(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<signed char>(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);

View File

@@ -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";

View File

@@ -1,3 +1,6 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <licenceReader.h>
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

5
src/reader/cid Normal file
View File

@@ -0,0 +1,5 @@
9f54495344434954615ad803c50171bf
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%
driver (6 <20><><EFBFBD>-  ocr -6 <20><><EFBFBD>? power *6 <>4L  type 6 <20>1M  date #6 <20>rTP hwrev )6 n<>yR  dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o  ssr 6 <1E>q  scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD>  name

2
src/reader/csd Normal file
View File

@@ -0,0 +1,2 @@
400e00325b5900003be77f800a400043

Binary file not shown.

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licReaderELC1.h"
namespace Reader
@@ -121,4 +123,6 @@ namespace Reader
return true;
}
}
}
#endif

View File

@@ -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<char> 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<unsigned char> privateContentDecrypted {};
//vector<unsigned char> 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;
}
}
}
#endif

View File

@@ -1,7 +1,11 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licReaderELC3.h"
namespace Reader
{
}
#endif