Compare commits

...

21 Commits

Author SHA1 Message Date
a5139db75a uprava 2024-10-03 11:57:02 +02:00
e21828d63f oprava directiv 2024-10-03 11:47:51 +02:00
4dcd40aadf oprava #define direktiv 2024-10-03 11:44:03 +02:00
a4e66ddaaf Tag 2024-06-24 08:46:25 +02:00
122f5cb92b Publikační verze 1 2024-06-24 08:43:36 +02:00
e157f5cc39 readme 2024-06-05 08:10:34 +02:00
b3178445c3 verzování 2024-06-04 12:48:42 +02:00
d827ccf34f ELC 3 2024-05-16 11:42:46 +02:00
d03261b873 ELC 3 2024-05-16 09:25:25 +02:00
ca93b3369f ELC 3 2024-05-14 14:51:30 +02:00
63d8178b4b upravy 2024-04-15 09:32:46 +02:00
e4b7cb5fb7 piřdání cesty k informaci o licenci 2024-04-15 09:24:32 +02:00
70e1fd9c4d Git čistka 2024-04-12 12:20:27 +02:00
671a764b04 Oddělení informace o licenci 2024-04-12 12:15:37 +02:00
2b7a68e64a upravy, čištení 2024-04-12 10:26:31 +02:00
3b1ee6038e Upravy a opravování kryptování 2024-04-11 14:31:24 +02:00
ead3ba6e3e upravy opravy 2024-04-10 08:03:43 +02:00
79cc4998bc Upravy popisků 2024-04-03 09:38:01 +02:00
2175852bc0 testování filip 2024-03-28 14:17:49 +01:00
22a97056f9 Upravy z testování Filip 2024-03-12 09:46:24 +01:00
2bfc662b51 ELC2 CRC check, čištění 2024-02-07 13:36:25 +01:00
114 changed files with 2108 additions and 2466 deletions

View File

@@ -8,7 +8,7 @@ CXX = g++
# define any compile-time flags # define any compile-time flags
# CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w # CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w
CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto -std=c++11
# define library paths in addition to /usr/lib # define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify # if I wanted to include libraries not in /usr/lib I'd specify
@@ -16,10 +16,10 @@ CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto
LFLAGS = LFLAGS =
# define output directory # define output directory
OUTPUT := output OUTPUT:= output
# define source directory # define source directory
SRC := src src/common src/reader src/generator SRC := src src/common src/reader src/generator
# define include directory # define include directory
INCLUDE := include include/common include/reader include/generator INCLUDE := include include/common include/reader include/generator

View File

@@ -2,11 +2,18 @@
Generování licence pro SD kartu Generování licence pro SD kartu
## version 1.1
- oprava #define direktiv pro celý kod (zapínání debugu, detailního výpisu a kompletního zakomentování kodu)
## version 1.0
- startovací publikační verze. Implementováno generování a čtení ELC1, ELC2 i ELC3
## Docker ## Docker
/bin/bash /bin/bash
- docker-compose up, spustí kontejner - docker-compose up, spustí kontejner
- otevření terminálu konterjneru, docker exec -it sd_gen-sd_gen-1 /bin/bash - otevření terminálu kontejneru, docker exec -it sd_gen-sd_gen-1 /bin/bash
./generate.sh - vytvoření spustitelného souboru
./start.sh - spuštění spustistelného souboru
./generate.sh
./start.sh

View File

@@ -1,607 +0,0 @@
#include <cstring>
#include <fstream>
#include <filesystem>
#include "licenceELC11.h"
#include "utils.h"
#include "pugixml.hpp"
#define CID_LENGTH 32
#define CSD_LENGTH 32
const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/";
const std::string cEzLic_p78ou3_licencfilepath_f21 = "/mnt/mmc/ez_sys/licence/";
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
const string cEzLic_p78ou3_licencfilepath_f10 = "/root/ez_sys/licence/";
const WORD maxDataToFile = 10000; // velikost datoveho bufferu pro ulozeni dat licence
const BYTE licMaxCount = 100;
const DWORD cEzLic_p78ou3_CheckLicNumber_ERR = 0xFFFFFFFF; // 16#FFFFFFFF; // chybna identifikace licence
const DWORD cEzLic_p78ou3_CheckLicNumber_EOV1 = 3781234965; // cislo pro overeni licence EOV, OSV verze 1
const BYTE cEzLic_p78ou3_CheckLicNumberId_ERR = 0; // id licence pro neidentifikovanou licenci
const BYTE cEzLic_p78ou3_CheckLicNumberId_EOV1 = 1; // id licence pro EOV, OSV verze 1
const BYTE cEzLic_p78ou3_MaxCheckLicNumberId = cEzLic_p78ou3_CheckLicNumberId_EOV1; // pocet identifikatoru licenci
const DWORD cEzLic_p78ou3_CheckLicNumber[] = {cEzLic_p78ou3_CheckLicNumber_ERR, cEzLic_p78ou3_CheckLicNumber_EOV1};
const WORD cEzLic_p78ou3_LicPrefixType_ELC1 = 1; // prefix typ1 = pouze zasifrovani dat
const WORD cEzLic_p78ou3_HeaderType_10 = 10; // hlavicka kriptovane casti verze 1.0
const WORD cEzLic_p78ou3_DataType_10 = 10; // data licence verze 1.0
const WORD cEzLic_p78ou3_SubType_10_10 = 0x0A0A; // subtype - verze hlavicky + verze data -> cEzLic_p78ou3_HeaderType_XX * 256 + cEzLic_p78ou3_DataType_XX
// ID aplikace
const WORD cEzLic_p78ou3_IDType_DDTS = 1; // aplikace DDTS
const WORD cEzLic_p78ou3_IDType_EOVOSV = 2; // aplikace EOV-OSV
const WORD cEzLic_p78ou3_IDType_DRT = 3; // aplikace DRT
// std::string cEzLic_p78ou3_IDTypeStrData11[] = {"neznamo", "DDTS", "EOV-OSV", "DRT"};
const BYTE cnibblescount11 = 32;
std::string cSDMonthStr11[] = {"-", "I.", "II.", "III.", "IV.", "V.", "VI.", "VII.", "VIII.", "IX.", "X.", "XI.", "XII.", "-", "-", "-"};
BYTE cHexNibble_to_No11[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 0, 0, 0, 0, 0, 0,
10, 11, 12, 13, 14, 15,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
10, 11, 12, 13, 14, 15,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const string eoseovLicenceType = "EOV_OSV";
LicenceELC11::LicenceELC11()
{
}
LicenceELC11::LicenceELC11(LicenceIdentification &licIdentification)
: lIdentification(licIdentification)
{
}
LicenceELC11::LicenceELC11(string cisArg, string csdArg, string binaryType, string dataFileName)
{
for (unsigned int i = 0; i < cisArg.length(); i++)
this->cid[i] = cisArg[i];
for (unsigned int i = 0; i < csdArg.length(); i++)
this->csd[i] = csdArg[i];
this->stationName = "";
this->distributor = "";
this->licType = 2;
processConfigFile(dataFileName);
if (binaryType == "base64")
this->binaryGeneration = BinaryGenerationType::Base64Cout;
else
this->binaryGeneration = BinaryGenerationType::File;
}
/// @brief process config file
/// @param dataFileName
void LicenceELC11::processConfigFile(string &dataFileName)
{
string fullFile = getCompletePath(dataFileName);
const int fileNameLength = fullFile.length();
char fileName[fileNameLength] = {};
getCharsFromString(fullFile, fileName, fileNameLength);
pugi::xml_document doc;
#ifdef WINDOWS
pugi::xml_parse_result result = doc.load_file("licData.xml");
#else
pugi::xml_parse_result result = doc.load_file(fileName);
#endif
if (result)
{
const char *dataRootName = doc.child("data") ? "data" : "licence"; // kompatibilita s verzí, která měla ještě root "data"
this->stationName = doc.child(dataRootName).child("station").child_value();
this->distributor = doc.child(dataRootName).child("distributor").child_value();
this->dataLicenceType = doc.child(dataRootName).child("licenceType").child_value();
this->dataLicenceVersion = doc.child(dataRootName).child("licenceType").attribute("version").value();
this->dataGenerationType = this->dataLicenceVersion;
this->dataCryptoVersion = this->dataLicenceVersion;
}
else
{
throw LicenceException((int)51, "Chyba při čtení xml");
}
}
/// @brief reads data from CID a CSD
void LicenceELC11::getSDData()
{
for (int i = 0; i < CID_LENGTH; i++)
this->sdData.CID_nibble[i] = (BYTE)cid[i];
for (int i = 0; i < cnibblescount / 2; i++)
{
this->sdData.CID[i] = cHexNibble_to_No11[this->sdData.CID_nibble[2 * i]] << 4 | cHexNibble_to_No11[this->sdData.CID_nibble[2 * i + 1]];
}
this->sdData.manufacturerID = this->sdData.CID[0];
this->sdData.oemID[0] = this->sdData.CID[1];
this->sdData.oemID[1] = this->sdData.CID[2];
this->sdData.name[0] = this->sdData.CID[3];
this->sdData.name[1] = this->sdData.CID[4];
this->sdData.name[2] = this->sdData.CID[5];
this->sdData.name[3] = this->sdData.CID[6];
this->sdData.name[4] = this->sdData.CID[7];
this->sdData.productRevision_hw = cHexNibble_to_No11[this->sdData.CID[16]];
this->sdData.productRevision_sw = cHexNibble_to_No11[this->sdData.CID[17]];
if (this->sdData.productRevision_sw < 10)
this->sdData.productRevision = (float)this->sdData.productRevision_hw + ((float)this->sdData.productRevision_sw * 0.1);
else
this->sdData.productRevision = (float)this->sdData.productRevision_hw + ((float)this->sdData.productRevision_sw * 0.01);
this->sdData.serialNumber = this->sdData.CID[9] << 24 | this->sdData.CID[10] << 16 | this->sdData.CID[11] << 8 | this->sdData.CID[12];
this->sdData.manufacturerDate_year = cHexNibble_to_No11[this->sdData.CID_nibble[27]] * 10 + cHexNibble_to_No11[this->sdData.CID_nibble[28]] + 2000;
this->sdData.manufacturerDate_month = cHexNibble_to_No11[this->sdData.CID_nibble[29]];
string date = cSDMonthStr11[this->sdData.manufacturerDate_month] + std::to_string(this->sdData.manufacturerDate_year);
for (unsigned i = 0; i < date.length(); i++)
this->sdData.manufacturerDate[i] = date[i];
// CSD
for (unsigned int i = 0; i < CSD_LENGTH; i++)
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
for (unsigned int i = 0; i < cnibblescount / 2; i++)
{
//
this->sdData.CSD[i] = cHexNibble_to_No11[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No11[this->sdData.CSD_nibble[2 * i + 1]];
}
if (this->sdData.CSD_nibble[0] == 0x34)
{
this->sdData.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9];
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
if (this->sdData.cardSize > 17200) // TODO result.cardSize
{
}
}
BYTE sdCrc = 0;
for (int i = 0; i <= 14; i++)
{
BYTE sdChar = this->sdData.CID[i];
for (int j = 0; j <= 7; j++)
{
sdCrc = sdCrc << 1;
if ((sdChar ^ sdCrc) & 0x80)
sdCrc = sdCrc ^ 0x09;
sdChar = sdChar << 1;
}
sdCrc = sdCrc & 0x7F;
}
this->sdData.CRCOK = ((sdCrc << 1) | 1) == this->sdData.CID[15];
}
/// @brief inits keys and vectors for encrypting
void LicenceELC11::initCrypto()
{
if (this->licType == cEzLic_p78ou3_IDType_EOVOSV)
{
this->cryptData.aesInitVector[0] = this->sdData.CID[10];
this->cryptData.aesInitVector[1] = this->sdData.CID[12];
this->cryptData.aesInitVector[2] = this->sdData.CID[11];
this->cryptData.aesInitVector[3] = this->sdData.CID[9];
this->cryptData.aesInitVector[4] = this->sdData.CID_nibble[22] - 15;
this->cryptData.aesInitVector[5] = this->sdData.CID_nibble[24] - 15;
this->cryptData.aesInitVector[6] = this->sdData.CID_nibble[25] - 15;
this->cryptData.aesInitVector[7] = this->sdData.CID_nibble[21] - 15;
memcpy(&this->cryptData.aesInitVector[8], &this->cryptData.aesInitVector[0], 8);
this->cryptData.aesKey[0] = this->sdData.CID[12];
this->cryptData.aesKey[1] = this->sdData.CID_nibble[23] - 15;
this->cryptData.aesKey[2] = this->sdData.CID_nibble[25] - 15;
this->cryptData.aesKey[3] = this->sdData.CID[11];
this->cryptData.aesKey[4] = this->sdData.CID[9];
this->cryptData.aesKey[5] = this->sdData.CID_nibble[21] - 15;
this->cryptData.aesKey[6] = 97 + this->sdData.CID[9] % 25;
this->cryptData.aesKey[7] = this->sdData.CID_nibble[22] - 15;
memcpy(&this->cryptData.aesKey[8], &this->cryptData.aesKey[0], 8);
memcpy(&this->cryptData.aesKey[16], &this->cryptData.aesKey[6], 8);
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
}
}
string LicenceELC11::getLicenceName()
{
string result = "";
char prefixChar = 97;
int licIndex = lIdentification.licenceIndex;
// natvrdo, stará ELC
result = "ezlic_eovosv" + to_string(licIndex) + "_";
result += prefixChar + (this->sdCard.cardData.CID[12] % 25);
result += prefixChar + (this->sdCard.cardData.CID[10] % 25);
result += prefixChar + (this->sdCard.cardData.CID_nibble[22] % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[23] * 2) % 25);
result += prefixChar + (this->sdCard.cardData.CID_nibble[24] % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[25] * 3) % 25);
result += prefixChar + (this->sdCard.cardData.CID[9] % 25);
result += prefixChar + (this->sdCard.cardData.CID[11] % 25);
result += prefixChar + (this->sdCard.cardData.CID[2] % 25);
result += prefixChar + (this->sdCard.cardData.CID[1] % 25);
result += prefixChar + (this->sdCard.cardData.CID[3] % 25);
result += ".lic";
return result;
}
/// @brief get proper licencename
/// @param licPostfix
/// @return
string LicenceELC11::getLicenceName(BYTE licPostfix)
{
string result = "";
char prefixChar = 97;
if (licPostfix > 9) // chyba
{
}
if (licType == PlcLicenceType::LicenceOther)
{
result = "ezlic_";
result += prefixChar + (this->sdData.CID[12] % 25);
result += prefixChar + (this->sdData.CID[10] % 25);
result += prefixChar + (this->sdData.CID_nibble[22] % 25);
result += prefixChar + ((this->sdData.CID_nibble[23] * 2) % 25);
result += prefixChar + (this->sdData.CID_nibble[24] % 25);
result += prefixChar + ((this->sdData.CID_nibble[25] * 3) % 25);
result += prefixChar + (this->sdData.CID[9] % 25);
result += prefixChar + (this->sdData.CID[11] % 25);
result += prefixChar + (this->sdData.CID[2] % 25);
result += prefixChar + (this->sdData.CID[1] % 25);
result += prefixChar + (this->sdData.CID[3] % 25);
result += ".lic";
}
else
{
result = "ezlic_eovosv" + to_string(licPostfix) + "_";
result += prefixChar + (this->sdData.CID[12] % 25);
result += prefixChar + (this->sdData.CID[10] % 25);
result += prefixChar + (this->sdData.CID_nibble[22] % 25);
result += prefixChar + ((this->sdData.CID_nibble[23] * 2) % 25);
result += prefixChar + (this->sdData.CID_nibble[24] % 25);
result += prefixChar + ((this->sdData.CID_nibble[25] * 3) % 25);
result += prefixChar + (this->sdData.CID[9] % 25);
result += prefixChar + (this->sdData.CID[11] % 25);
result += prefixChar + (this->sdData.CID[2] % 25);
result += prefixChar + (this->sdData.CID[1] % 25);
result += prefixChar + (this->sdData.CID[3] % 25);
result += ".lic";
}
return result;
}
bool LicenceELC11::createLicence()
{
if (this->dataLicenceType == eoseovLicenceType)
{
return createEosEovLicence();
}
else
{
return false;
}
}
bool LicenceELC11::createEosEovLicence()
{
getSDData();
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; // 6818 ... proč ?
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 cEzLic_p78ou3_IDType_DDTS:
mainLicDescription = "ddts ";
break;
case 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 LicenceELC11::readLicence(LicenceInfoGeneral *licences)
{
sdCard = SDCard(this->cid_cdsPath);
if (sdCard.isLoaded == false) throw LicenceException((int)51, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
for (unsigned int i = 0; i < sdCard.cidString.length(); i++)
this->cid[i] = sdCard.cidString[i]; // nutné pro původní algoritmus
for (unsigned int i = 0; i < sdCard.csdString.length(); i++)
this->csd[i] = sdCard.csdString[i]; // nutné pro původní algoritmus
string licFileName = getLicenceName();
string licFilePath = this->licenceFilePath + licFileName;
FILE *licenceFile;
char ch;
const int fileNameLength = licFilePath.length();
char fileNameCh[fileNameLength] = {};
for (int i = 0; i < fileNameLength; i++)
fileNameCh[i] = licFilePath[i];
licenceFile = fopen(fileNameCh, "rb"); // read mode
if (licenceFile == nullptr)
throw LicenceException((int)Error11::LicenceReadError, "Licence read error: " + licFilePath);
fseek(licenceFile, 0, SEEK_END); // seek to end of file
const int size = ftell(licenceFile); // get current file pointer
fseek(licenceFile, 0, SEEK_SET);
if (size <= 0)
throw LicenceException((int)Error11::LicenceReadError, "Licence read error: " + licFilePath);
int count = 0;
unsigned char licenceContent[size];
for (int i = 0; i < size; i++)
{
ch = fgetc(licenceFile);
licenceContent[i] = ch;
count++;
}
fclose(licenceFile);
//getSDData();?
LicenceDataMainELC licenceHeader{};
LicenceData licEncryptedData{};
// memset(&licenceHeader, 0, sizeof(LicenceDataMainELC));
memcpy(&licenceHeader, licenceContent, sizeof(LicenceDataMainELC));
const int sizeOfEncryptedData = size - sizeof(LicenceDataMainELC);
unsigned char encryptedData[sizeOfEncryptedData] = {};
for (int i = 0; i < sizeOfEncryptedData; i++)
encryptedData[i] = licenceContent[i + sizeof(LicenceDataMainELC)];
BYTE prefixType = (int)licenceContent[3] - 0x30;
if (prefixType == PrefixType::ELC1)
{
if (licenceHeader.licHeader.sizeData > 0)
{
if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10)
{
initCrypto();
// CryptData cryptData = initCrypto(sdData, licIdent.licIDType);
unsigned char decrypted[2000] = {};
int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted);
if (sizeof(licEncryptedData) != decrypted_len)
{
throw LicenceException((int)Error11::LicenceSizeMismatch, "License size mismatch ");
}
else
{
// memset(&licEncryptedData, 0, sizeof(licEncryptedData));
memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData));
if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10)
{
if (licEncryptedData.header.licType == cEzLic_p78ou3_IDType_EOVOSV)
{
if (licEncryptedData.header.licCount > 0)
{
for (int i = 0; i < licMaxCount; i++)
{
licences->licences.insert(pair<int, int>(licEncryptedData.items[i].protoId, licEncryptedData.items[i].licCount));
}
}
else
{
throw LicenceException((int)Error11::LicenceSizeCardMismatch, "Size card info mismatch");
}
}
}
else
{
throw LicenceException((int)Error11::LicenceMismatch, "Licence mismatch");
}
}
}
}
else
{
throw LicenceException((int)Error11::LicenceMismatch, "Licence mismatch");
}
}
else
{
throw LicenceException((int)Error11::LicenceReadError, "Licence error");
}
return true;
}
LicenceELC11::~LicenceELC11() {}

View File

@@ -1,36 +0,0 @@
#include "licenceELC31.h"
#include "utils.h"
LicenceELC31::LicenceELC31()
{
}
LicenceELC31::LicenceELC31(LicData &licData)
{
lData = licData;
processInputConfiguration();
}
LicenceELC31::LicenceELC31(LicenceIdentification &licIdentification) : lIdentification(licIdentification)
{
}
bool LicenceELC31::processInputConfiguration()
{
return true;
}
int LicenceELC31::getDataPointsCount(int protocolId)
{
return protocolId;
}
void LicenceELC31::createLicence()
{
}
void LicenceELC31::readLicence()
{
}
LicenceELC31::~LicenceELC31() { }

View File

@@ -1,281 +0,0 @@
#ifndef PLC_LICENCE11_H
#define PLC_LICENCE11_H
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <wchar.h>
#include <time.h>
#include <map>
#include <stdint.h>
#include "licenceCommon.h"
#include "SDCard.h"
using namespace std;
#define MAX_LICENCE_COUNT 100
enum InputLicenceType
{
EOSEOV = 1
};
enum BinaryGenerationType
{
Base64Cout = 1,
File = 2
};
enum PlcLicenceType
{
LicenceOther = 0,
LicenceEov = 1
};
enum LidIdType
{
Ddts = 1,
EovOsv = 2
};
enum PrefixType
{
ELC1 = 1
};
typedef uint32_t DWORD;
typedef uint16_t WORD;
typedef uint8_t BYTE;
typedef uint32_t UDINT;
typedef uint32_t DATE;
typedef uint8_t USINT;
typedef int32_t DINT;
typedef uint16_t UINT;
typedef int16_t INT;
/// @brief identifikace licence
typedef struct LicenceIdent
{
WORD licPrefixType = 0; // WORD; typ licencniho souboru - pro kazdy prefig je jiny typ souboru a jiny zpusob zpracovani dat [sifrovani, podpis, komprese, ...]
WORD licHeaderType = 0; //: WORD; typ hlavicky kriptovane casti licencniho souboru
WORD licDataType = 0; //: WORD; typ licence - pro kazdou hlavicku jsou samostatne typy licenci - mohou byt i shodne s typem jine hlavicky
WORD licSubType = 0; //: WORD; slouceny typ hlavicku a typ licence => typ hlavicky * 256 + typ licence
WORD licIDType = 0; //: WORD; id aplikace, pro kterou je licence urcena => 1 = ddts, 2 = eov-osv
BYTE licPostfix = 0; //: BYTE; rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
} LicenceIdent;
/// @brief struktura pro přípravu dat na generování
typedef struct LicenceSourceData
{
BYTE startGen; // na nabeznou hranu se vygeneruje licence
BYTE loadSD; //: BOOL; na nabeznou hranu se nacte SD karta
// zadavane hodnoty
BYTE licType_id; // vybrany typ licence
char licDescription1[40] = {}; //: STRING(39); jmeno stanice
char licDescription2[20] = {}; //: STRING(19); jmeno rozvadece
BYTE licPostfix; // rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
BYTE enInit; //: BOOL; inicializace (promazani) adresare pro licence
// interne generovane hodnoty
WORD licType; //: WORD; hlavicka licence
BYTE licIdOk; //: BOOL; korektne zvoleny typ licence
string licPostfixIdent; //[2]; //: STRING(2); vygenerovany postfix z cisla pro rozliseni postfixu v souborech a textech
} LicenceSourceData;
/// @brief struktura obsahující dodatečné informace k licenci
typedef struct PlcData
{
string plcType = "";
string licenceType = ""; // typ
string licenceVersion = "1";
string licenceName = ""; // název
string station = ""; // stanice
string distributor = ""; // rozvadec
} PlcData;
/*
MID (Manufacturer ID): 8 bits - Identifies the manufacturer of the SD card.
OID (OEM/Application ID): 16 bits - Identifies the OEM and application-specific information.
PNM (Product Name): 40 bits - A string representing the product name of the SD card.
PRV (Product Revision): 8 bits - The product revision/version.
PSN (Product Serial Number): 32 bits - A unique serial number assigned to the SD card during manufacturing.
MDT (Manufacturing Date): 12 bits - Represents the manufacturing date of the SD card.
CRC (CRC7 Checksum): 7 bits - A cyclic redundancy check for error detection.
unused: 4 bits - Reserved for future use.
*/
/// @brief struktura pro načtení CIS a CSD dat
typedef struct SDData
{
BYTE isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
BYTE CID_nibble[32] = {0}; // surova data CID ze souboru
BYTE CID[16] = {0}; // prekodovane CID informace
BYTE manufacturerID = 0; // ID vyrobce 1B -> Byte 15
char oemID[2] = {}; // ID aplikace/oem 2B -> Byte 13-14 // oemID: !!STRING(3);
char name[5] = {}; // jmeno produktu 5B -> Byte 8-12 !!STRING(6);
BYTE productRevision_hw = 0;
BYTE productRevision_sw = 0;
float productRevision = 0; // revize produktu 1B [bcd sh] -> Byte 7, bity 0-3 = revize HW, bity 4-7 = revize SW
DWORD serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
WORD manufacturerDate_year = 0;
BYTE manufacturerDate_month = 0;
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
BYTE CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1
BYTE CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
BYTE CSD[16] = {}; //: ARRAY [0..15] OF BYTE; // prekodovane CSD informace
UDINT cardSize = 0; //: UDINT; // velikost SD karty
BYTE cardGSize = 0; // prepocitana velikost na GB
} CidData;
// nekodovana cast licence
/// @brief nekryptovaná hlavička licence
typedef struct LicenceDataMainHeaderELC
{
BYTE licType = 0;
; // typ licence => duplicitni polozka s hlavickou kodovane casti licence - pouze pro ucely dekodovani dat
BYTE dummy1 = 0;
WORD licSubType = 0; // horni byte = typ hlavicky kodovane casti, spodni byte = typ dat polozkove casti => duplicitni casti s id a hlavickou kodovane casti - pouze pro ucely dekodovani
char description[80] = {}; // viditelny popis licincniho souboru
UDINT sizeData = 0; // velikost kodovane casti licence v Bytech
} LicenceDataMainHeaderELC;
// hlavní struktura licence
typedef struct LicenceDataMainELC
{
// prefix MUSI zustat jako prvni prvek struktury a MUSI byt typu DWORD
DWORD prefix = 0; // urcuje strukturu dat citelne casti licencniho souboru [teto struktury] + zpusob sifrovani, dig, podpis, kompresi... dat
LicenceDataMainHeaderELC licHeader {}; // nekodovana cast licence
} LicenceDataMain;
// polozkova cast licence verze 1.0
typedef struct LicenceDataItem
{
WORD protoId = 0; // id protokolu pro ktery je licence
WORD licCount = 0; // pocet datovych bodu licence
DWORD data1 = 0; // doplnkove nahodne cislo, slouzi pro overeni licence v runtime
} LicenceDataItem;
// identifikace kodovane casti licence - !!! MUSI yustat pro vsechny verze STEJNA !!!
typedef struct LicenceDataId
{
WORD version = 0; // verze hlavicky
WORD rez = 0;
UDINT cardSize = 0;
} LicenceDataId;
typedef struct LicenceDataHeader
{
BYTE licType = 0; // typ licence => 0...neznamy (chyba), 1...DDTS, 2...EOV-OSV
BYTE licReserve = 0; // rezerva
WORD licVersion = 0; //: WORD; verze polozkove casti licence
DATE licDate = 0; // datum vygenerovani licence
char licDescription1[40] = {}; // licDescription1: STRING(39); stanice, pro kterou byla licence generovana
char licDescription2[20] = {}; // STRING(19); rozvadec, pro ktery byla licence generovana
USINT licCount = 0; // aktivni pocet dat polozkove casti licence
BYTE licDummy = 0; // rezerva
WORD licReservew = 0; // rezerva
} LicenceDataHeader;
// kodovana cast licence verze 1.1 s polozkovou casi licence verze 1.0
typedef struct LicenceData
{
LicenceDataId id {}; // id !!! MUSI zustat na PRVNIM miste struktury
LicenceDataHeader header{} ;
LicenceDataItem items[MAX_LICENCE_COUNT] = {}; // polozkova cast licence
WORD dummy = 0; // pro zarovnani struktur - jinak nebude fungovat vypocet a kontrola CRC !!!
WORD crc = 0; // kontrolni kod - !!! MUSI zustat na konci struktury
} LicenceData;
typedef struct LicenceRetData
{
BYTE retCode = 0; // navratovy kod funkce pro nacteni SD
DINT subCode = 0; // doplnkova informace chyby
std::string text = ""; // textovy popis navratove hodnoty
bool isDone = false; // operace korektne dokoncena
} LicenceRetData;
typedef struct CryptData
{
bool initDone = false;
DWORD cryptDataAddress = 0; // adresa na data, ktera se maji cryptovat
UINT cryptDataSize = 0; // velikostdat, ktera semaji cryptovat
BYTE aesInitVector[15] = {0}; //] : ARRAY [0..14] OF BYTE;// AES 128 bit IV
BYTE aesKey[32] = {0}; // : ARRAY [0..31] OF BYTE; // AES 256 bit key
DINT aesRetVal = 0; // navratova hodnota AES
DWORD retDataAddress = 0; // adresa na ulozeni cryptovana dat
UINT retDataSize = 0; // velikost cryptovanych dat
LicenceData *licenseData;
} CryptData;
/// @brief licence class
class LicenceELC11
{
enum class Error11
{
SDCardReadError = 50,
LicenceReadError = 51,
LicenceSizeMismatch = 52,
LicenceSizeCardMismatch = 53,
LicenceMismatch = 54,
ItemsCountMismatch = 61
};
// unordered_map<Error11, string> map11Errors = {
// {Error11::SDCardReadError, "Nepodařilo se načíst SD kartu."},
// {Error11::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
// };
private:
SDCard sdCard;
string cidString = "";
char cid[32] = {};
string csdString = "";
char csd[32] = {}; // CSD
string stationName; // name of station
string distributor; // name of switch
const char *dataFileName; // name of xml containing data (if not taken from commandline)
WORD licType = 2; // type of licence
BinaryGenerationType binaryGeneration = BinaryGenerationType::Base64Cout; //typ generování binárního souboru
string dataLicenceType = ""; //type of licence from xmlFile;
string dataLicenceVersion = ""; //version type of licence from xmlFile;
string dataCryptoVersion = ""; //version of crypting from xmlFile
string dataGenerationType = ""; //version of dataGeneration from xmlFile
string dataLicenceDataFileName = ""; //name of licence file to read
CryptData cryptData; // structure for encryp
CidData sdData; // data loaded from SD card
void processConfigFile(string &dataFileName); //process data from config file
void getSDData(); // reads SD card
string getLicenceName(BYTE licPostfix); // get proper licencename
string getLicenceName();
void initCrypto();
bool createEosEovLicence(); // create licence for EOV_OSV
bool readEosEovLicence(string dataFileName);
LicenceIdentification lIdentification;
public:
string operationErrors = "";
ErrorMessage errorMessage;
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
LicenceELC11();
~LicenceELC11();
LicenceELC11(string cid, string csd, string binaryType, string dataFileName);
LicenceELC11(LicenceIdentification & licIdentification);
bool createLicence(); // creates licence
bool readLicence(LicenceInfoGeneral * licences);
};
#endif

View File

@@ -1,585 +0,0 @@
#include "licenceELC21.h"
#include "utils.h"
#include "SDCard.h"
#include "pugixml.hpp"
LicenceELC21::LicenceELC21()
{
}
LicenceELC21::LicenceELC21(LicenceIdentification &licIdentification, LicData &licData)
: lIdentification(licIdentification), lData(licData)
{
}
LicenceELC21::LicenceELC21(LicenceIdentification &licIdentification): lIdentification(licIdentification)
{
}
LicenceELC21::LicenceELC21(LicData &licData): lData(licData)
{
if (processInputConfiguration() == false) throw LicenceException((int)Error21::LicenceReadError, "Chyba při čtení licence");
}
bool LicenceELC21::createLicence()
{
getLicenceItems();
getHeader();
sdCard = SDCard(lData.cid, lData.csd);
if (sdCard.isLoaded == false) throw LicenceException((int)Error21::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
vector<unsigned char> publicContent;
vector<unsigned char> privateContent;
vector<unsigned char> privateContentEncrypted;
publicContent.push_back(this->licBody.licId.licIdent[0]);
publicContent.push_back(this->licBody.licId.licIdent[1]);
publicContent.push_back(this->licBody.licId.licIdent[2]);
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
publicContent.push_back(this->licBody.licId.licIdent[4]);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
publicContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
publicContent.push_back(this->licBody.privateContent.dataItems.size());
publicContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
appendStringToVector(this->licBody.publicHeader, publicContent);
uint16_t crcPublic = calculateCRC16(publicContent);
#ifdef DEB
cout << "CRC pubblic: " << crcPublic << endl;
#endif
publicContent.push_back(crcPublic & 0xFF);
publicContent.push_back((crcPublic >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
privateContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
privateContent.push_back(this->licBody.privateContent.dataItems.size());
privateContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
{
privateContent.push_back(dataItem.protoId & 0xFF);
privateContent.push_back((dataItem.protoId >> 8) & 0xFF);
privateContent.push_back(dataItem.licCount & 0xFF);
privateContent.push_back((dataItem.licCount >> 8) & 0xFF);
for (unsigned int i = 0; i < sizeof(dataItem.dummy); i++)
privateContent.push_back(i);
}
vector<unsigned char> completeVector = joinVectors(publicContent, privateContent);
licBody.privateContent.crc = calculateCRC16(completeVector);
uint16_t crcComplete = calculateCRC16(completeVector);
privateContent.push_back(crcComplete & 0xFF);
privateContent.push_back((crcComplete >> 8) & 0xFF);
privateContentEncrypted = cryptPrivateContent(privateContent);
string licfileName = getLicenceName();
std::ofstream outputFile(licfileName, std::ios::out | std::ios::binary);
// Check if the file is open
if (!outputFile.is_open())
{
throw LicenceException((int)GeneralError::FileOpenError, "Chyba při zakládání souboru licence: " + cid_cdsPath);
}
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
std::copy(privateContentEncrypted.cbegin(), privateContentEncrypted.cend(), std::ostream_iterator<unsigned char>(outputFile));
outputFile.close();
cout << licfileName;
return true;
}
bool LicenceELC21::readLicence(LicenceInfoGeneral * licences)
{
// sdCard = SDCard("9f544930303030300000000b47015423", "400e00325b5900003a0d7f800a40008d");
sdCard = SDCard(this->cid_cdsPath);
if (sdCard.isLoaded == false) throw LicenceException((int)Error21::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
string licFileName = getLicenceName();
string licFilePath = this->licenceFilePath+licFileName;
vector<char> content;
if (readFile(licFilePath, content) == false)
{
throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath);
}
this->licBody.licId.licIdent[0] = content[0];
this->licBody.licId.licIdent[1] = content[1];
this->licBody.licId.licIdent[2] = content[2];
this->licBody.licId.licIdent[3] = content[3];
this->licBody.licId.licIdent[4] = content[4];
this->licBody.licenceIdentHeader.licenceType = content[5];
this->licBody.licenceIdentHeader.licenceTypeVersion = content[6];
this->licBody.licenceIdentHeader.licenceIndex = content[7];
this->licBody.licenceIdentHeader.compatibilityVersion = content[8];
this->licBody.licenceIdentHeader.licItemCount = content[9];
this->licBody.licenceIdentHeader.publicHeaderLength = bytesToWord(content[10], content[11]);
this->licBody.licenceIdentHeader.cardSize = bytesToWord(content[12], content[13]);
this->licBody.licenceIdentHeader.serialNumber = bytesToDword(content[14], content[15], content[16], content[17]);
//~~~uint16_t crcPublic = bytesToWord(content[18 + licBody.licenceIdentHeader.publicHeaderLength], content[19 + licBody.licenceIdentHeader.publicHeaderLength]);
int elcVersion = (int)licBody.licId.licIdent[3] - 48;
if (elcVersion != (int)this->lIdentification.licElcType)
{
throw LicenceException((int)GeneralError::ELCMismatch, "Nesouhlasí ELC.");
}
vector<unsigned char> encryptedPart(content.begin() + licBody.licenceIdentHeader.publicHeaderLength + 20, content.begin() + content.size());
vector<unsigned char> privateContentDecrypted;
privateContentDecrypted = decryptPrivateContent(encryptedPart);
LicenceBody licBodyDecrypted;
licBodyDecrypted.licenceIdentHeader.licenceType = privateContentDecrypted[0];
licBodyDecrypted.licenceIdentHeader.licenceTypeVersion = privateContentDecrypted[1];
licBodyDecrypted.licenceIdentHeader.licenceIndex = privateContentDecrypted[2];
licBodyDecrypted.licenceIdentHeader.compatibilityVersion = privateContentDecrypted[3];
licBodyDecrypted.licenceIdentHeader.licItemCount = privateContentDecrypted[4];
licBodyDecrypted.licenceIdentHeader.publicHeaderLength = bytesToWord(privateContentDecrypted[5], privateContentDecrypted[6]);
licBodyDecrypted.licenceIdentHeader.cardSize = bytesToWord(privateContentDecrypted[7], privateContentDecrypted[8]);
licBodyDecrypted.licenceIdentHeader.serialNumber = bytesToDword(privateContentDecrypted[9], privateContentDecrypted[10], privateContentDecrypted[11], privateContentDecrypted[12]);
//~~~CRC
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
{
throw LicenceException((int)Error21::ItemsCountMismatch, map21Errors.at(Error21::ItemsCountMismatch));
}
int index = 13;
for (int i = 0; i < this->licBody.licenceIdentHeader.licItemCount; i++)
{
licDataItem item;
item.protoId = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
item.licCount = bytesToWord(privateContentDecrypted[index + 2], privateContentDecrypted[index + 3]);
index += sizeof(licDataItem);
this->licBody.privateContent.dataItems.push_back(item);
this->licenceInfo.licences.insert(pair<int, int>(item.protoId, item.licCount));
licences->licences.insert(pair<int, int>(item.protoId, item.licCount));
}
return true;
}
string LicenceELC21::getVersion(int middleVersion)
{
string result = "";
result.append(to_string(generatorVersion));
result.append(".");
result.append(to_string(middleVersion));
result.append(".");
string tempLicenceCount = "3"; // TODO
result.append(tempLicenceCount);
return result;
}
bool LicenceELC21::processInputConfiguration()
{
const char *dataRootName = "licence";
Mapping mapping;
string licType = lData.doc->child(dataRootName).child("licenceType").child_value();
if (!licType.empty())
{
this->lIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
this->lIdentification.licTypeName = licType;
}
else
{
errorMessage.code = (int)Error21::LicenceMismatch;
errorMessage.message = "ERROR MISSING licenceType";
return false;
}
this->lIdentification.licenceVersion = atoi(&lData.doc->child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]);
this->lIdentification.revision = lData.doc->child(dataRootName).attribute("revision").value()[0];
this->lIdentification.licenceIndex = atoi(&lData.doc->child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->lIdentification.licElcType = (ELCType)atoi(&lData.doc->child(dataRootName).attribute("elc").value()[0]);
this->lIdentification.licCompatibility = atoi(&lData.doc->child(dataRootName).attribute("compatibility").value()[0]);
string plcType = lData.doc->child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{
this->lIdentification.licPlcType = mapping.licMapPlcType[plcType];
}
this->lData.station = &lData.doc->child(dataRootName).child("station").child_value()[0];
this->lData.distributor = &lData.doc->child(dataRootName).child("distributor").child_value()[0];
this->lData.projectDescription = &lData.doc->child(dataRootName).child("project").child_value()[0];
licBody.licenceIdentHeader.cardSize = 0;
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
licBody.licenceIdentHeader.licenceType = this->lIdentification.licenceVersion;
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
licBody.licenceIdentHeader.serialNumber = 0;
return true;
}
void LicenceELC21::getLicenceItems()
{
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : lData.doc->child("licence").child("items"))
{
licDataItem item;
item.protoId = atoi(licItemNode.child("protoId").child_value());
item.licCount = atoi(licItemNode.child("dataPointsCount").child_value());
this->licBody.privateContent.dataItems.push_back(item);
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{
nodeIndex++;
if (nodeIndex == 1)
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
}
else
{
licBody.publicHeader.append("}");
}
}
}
void LicenceELC21::getHeader()
{
PublicHeader publicHeader;
publicHeader.version = getVersion(7);
publicHeader.projectDescription = lData.projectDescription;
publicHeader.date = getDate();
publicHeader.licenceType = lIdentification.licTypeName;
publicHeader.licenceType += to_string(lIdentification.licenceIndex);
licBody.publicHeader = "";
licBody.publicHeader.append("{\"version\":");
licBody.publicHeader.append(publicHeader.version);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"project\":\"");
licBody.publicHeader.append(publicHeader.projectDescription);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"date\":\"");
licBody.publicHeader.append(publicHeader.date);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"note\":\"poznámka\",");
licBody.publicHeader.append("\"licenceType\":\"");
licBody.publicHeader.append(publicHeader.licenceType);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"items\":[");
lIdentification.licItemsCount = std::distance(lData.doc->child("licence").child("items").begin(), lData.doc->child("licence").child("items").end());
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : lData.doc->child("licence").child("items"))
{
licBody.publicHeader.append("{");
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{
nodeIndex++;
if (nodeIndex == 1)
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
}
else
{
licBody.publicHeader.append("}");
}
}
licBody.publicHeader.append("]");
licBody.publicHeader.append("}");
}
vector<unsigned char> LicenceELC21::cryptPrivateContent(const std::vector<unsigned char> &content)
{
BYTE initVector[15] = {};
BYTE aesKey[32] = {};
LicenceELC21::initVector(initVector, aesKey);
unsigned char encrypted[10000] = {};
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í.");
std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
return result;
}
vector<unsigned char> LicenceELC21::decryptPrivateContent(const std::vector<unsigned char> &content)
{
BYTE initVector[15] = {0};
BYTE aesKey[32] = {0};
LicenceELC21::initVector(initVector, aesKey);
const unsigned char *encryptedData = content.data();
unsigned char decrypted[10000] = {};
int decrypted_len = decrypt(encryptedData, content.size(), aesKey, initVector, decrypted);
if (decrypted_len <= 0) throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování.");
std::vector<unsigned char> result(decrypted, decrypted + decrypted_len);
return result;
}
void LicenceELC21::initVector(BYTE (&iVector)[], BYTE (&key)[])
{
struct Vector15
{
int vec[15];
};
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};
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));
int lVersion = lIdentification.licenceVersion;
iVector[0] = vectors.at(lVersion).vec[0];
iVector[1] = vectors.at(lVersion).vec[1];
iVector[2] = vectors.at(lVersion).vec[2];
iVector[3] = vectors.at(lVersion).vec[3];
iVector[4] = vectors.at(lVersion).vec[4];
iVector[5] = vectors.at(lVersion).vec[5];
iVector[6] = vectors.at(lVersion).vec[6];
iVector[7] = vectors.at(lVersion).vec[7];
memcpy(&iVector[8], &iVector[0], 8);
key[0] = keys.at(lVersion).key[0];
key[1] = keys.at(lVersion).key[1];
key[2] = keys.at(lVersion).key[2];
key[3] = keys.at(lVersion).key[3];
key[4] = keys.at(lVersion).key[4];
key[5] = keys.at(lVersion).key[5];
key[6] = keys.at(lVersion).key[6];
key[7] = keys.at(lVersion).key[7];
memcpy(&key[8], &key[0], 8);
memcpy(&key[16], &key[6], 8);
memcpy(&key[24], &key[12], 8);
}
/// @brief get proper licencename
/// @param licPostfix
/// @return
string LicenceELC21::getLicenceName()
{
string result = "";
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"));
baseString.insert(std::pair<int, string>((int)LicenceType::DRT, "ezlic_drt"));
struct Index
{
int index[11];
};
std::unordered_map<int, Index> indexes;
Index indexes1 = {7, 16, 20, 23, 18, 4, 9, 11, 6, 9, 13};
Index indexes2 = {12, 10, 22, 23, 24, 25, 9, 11, 2, 1, 3}; // puvodní indexy
Index indexes3 = {8, 13, 11, 9, 7, 11, 10, 13, 5, 20, 19};
indexes.insert(std::pair<int, Index>(1, indexes1));
indexes.insert(std::pair<int, Index>(2, indexes2));
indexes.insert(std::pair<int, Index>(3, indexes3));
result = baseString.at(licType) + to_string(lIdentification.licenceIndex) + "_";
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[0]] + (lIdentification.licenceIndex * 11)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[1]] + (lIdentification.licenceIndex * 39)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[2]] + (lIdentification.licenceIndex * 1)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[3]] * 2) % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[4]] + (lIdentification.licenceIndex * 5)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID_nibble[indexes.at(lVersion).index[5]] * 3) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[6]] + (lIdentification.licenceIndex * 52)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[7]] + (lIdentification.licenceIndex * 34)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[8]] + (lIdentification.licenceIndex * 21)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[9]] + (lIdentification.licenceIndex * 47)) % 25);
result += prefixChar + ((this->sdCard.cardData.CID[indexes.at(lVersion).index[10]] + (lIdentification.licenceIndex * 7)) % 25);
result += ".lic";
return result;
}
int LicenceELC21::getDataPointsCount(int protocolId)
{
if (this->readLicence(nullptr) == false)
{
}
for (auto item : this->licBody.privateContent.dataItems)
{
if (item.protoId == protocolId)
return item.licCount;
}
return 0;
}
bool LicenceELC21::getLicenceItemInfo(int protocolId, void *returnItemStructure)
{
if (returnItemStructure != nullptr)
{
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure);
resultPtr->protocolId = protocolId; // protocolId;
if (this->licenceInfo.licences.count(protocolId)) resultPtr->dataPointsCount=this->licenceInfo.licences.at(protocolId);
else resultPtr->dataPointsCount = 0;
}
else
{
errorMessage.code = 1;
errorMessage.message = "Error: Null pointer!";
return false;
}
return true;
}
bool LicenceELC21::getLicenceInfo(void *returnStructure)
{
if (returnStructure != nullptr)
{
LicenceInfo21 *resultPtr = static_cast<LicenceInfo21 *>(returnStructure);
for (auto item : this->licBody.privateContent.dataItems)
{
resultPtr->licences.insert(pair<int, int>(item.protoId, item.licCount));
}
}
else
{
errorMessage.code = 1;
errorMessage.message = "Error: Null pointer!";
return false;
}
return true;
}
LicenceELC21::~LicenceELC21() {}

View File

@@ -1,130 +0,0 @@
#ifndef PLC_LICENCE21_H
#define PLC_LICENCE21_H
#include "utils.h"
#include <stdint.h>
#include <unordered_map>
#include "licenceCommon.h"
#include "pugixml.hpp"
#include "SDCard.h"
using namespace std;
class LicenceELC21
{
struct LicData
{
string station = "";
string distributor = "";
string licenceName = "";
string projectDescription = "";
string cid = ""; // CID z SD karty
string csd = ""; // CSD z SD karty
string uid = ""; // jedinečný identifikátor z jiného systému
pugi::xml_document *doc;
};
public:
ErrorMessage errorMessage;
LicenceInfo21 licenceInfo;
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
LicenceELC21();
~LicenceELC21();
LicenceELC21(LicenceIdentification &licIdentification, LicData &licData);
LicenceELC21(LicenceIdentification &licIdentification);
LicenceELC21(LicData &licData);
bool createLicence();
bool readLicence(LicenceInfoGeneral *licences);
int getDataPointsCount(int protocolId);
bool getLicenceInfo(void *ptr);
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
enum class Error21
{
SDCardReadError = 50,
LicenceReadError = 51,
LicenceSizeMismatch = 52,
LicenceSizeCardMismatch = 53,
LicenceMismatch = 54,
ItemsCountMismatch = 61
};
unordered_map<Error21, string> map21Errors = {
{Error21::SDCardReadError, "Nepodařilo se načíst SD kartu."},
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
{Error21::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
{Error21::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
{Error21::LicenceMismatch, "Nesouhlasí licence."},
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
};
struct LicenceId
{
char licIdent[5] = {'E', 'L', 'C', '0', '_'};
};
// struct __attribute__((__packed__)) LicencePublicHeader
struct LicenceIdentDataHeader
{
BYTE licenceType = 0; // EOSEOV, DRT ...
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
BYTE licenceIndex = 0; // puvodní post fix, identifikátor pro více licencí
BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent
BYTE licItemCount = 0; // počet licenčních bodů
WORD publicHeaderLength = 0; // délka veřejné hlavičy
WORD cardSize = 0; // velikost SD karty
DWORD serialNumber = 0; // seriove cislo karty
};
///
struct licDataItem
{
WORD protoId = 0; // id protokolu pro ktery je licence
WORD licCount = 0; // pocet datovych bodu licence
char dummy[64] = {}; // dummy pro větší velikost licence v případě méně licenčních bodů
};
struct PublicHeader
{
string version = "";
string projectDescription = "";
string date = "";
string licenceType = "";
int crc = 0;
};
struct PrivateContent // privátní šifrovaná část
{
LicenceIdentDataHeader licenceIdentHeader;
vector<licDataItem> dataItems;
WORD crc = 0;
};
struct LicenceBody
{
LicenceId licId;
LicenceIdentDataHeader licenceIdentHeader;
string publicHeader = ""; // JSON
PrivateContent privateContent;
};
private:
int licItemCount = 0;
LicenceBody licBody;
LicenceIdentification lIdentification;
LicData lData;
SDCard sdCard;
void getHeader();
string getVersion(int middleVersion);
void getLicenceItems();
bool processInputConfiguration();
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)[]);
string getLicenceName();
};
#endif

View File

@@ -1,43 +0,0 @@
#ifndef PLC_LICENCE31_H
#define PLC_LICENCE31_H
#include <stdint.h>
#include <iostream>
#include <vector>
#include "utils.h"
#include "licenceCommon.h"
#include "pugixml.hpp"
using namespace std;
class LicenceELC31
{
struct LicData
{
string station = "";
string distributor = "";
string licenceName = "";
string projectDescription = "";
string cid = ""; // CID z SD karty
string csd = ""; // CSD z SD karty
string uid = ""; // jedinečný identifikátor z jiného systému
pugi::xml_document *doc;
};
LicData lData;
bool processInputConfiguration();
LicenceIdentification lIdentification;
public:
LicenceELC31();
~LicenceELC31();
LicenceELC31(LicData & licData);
LicenceELC31(LicenceIdentification & licIdentification);
void createLicence();
void readLicence();
int getDataPointsCount(int protocolId);
};
#endif

View File

@@ -1 +0,0 @@
licenceGenerator.exe -cid=9f544930303030300000000b47015423 -csd=400e00325b5900003a0d7f800a40008d -outputType=base64 -configFileName=licData.xml

View File

@@ -1 +0,0 @@
licenceGenerator.exe -cid=9f544930303030300000000b47015423 -csd=400e00325b5900003a0d7f800a40008d -outputType=file -configFileName=licData.xml

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<data version="1">
<plcType>WAGO</plcType>
<licenceType version="1">EOV_OSV</licenceType>
<licenceName>Licence pro EOV_OSV</licenceName>
<station>ceskatrebova</station>
<distributor>RO1</distributor>
</data>

Binary file not shown.

View File

@@ -11,6 +11,9 @@ RUN chmod 755 /app/start.sh
COPY ./startok.sh /app/ COPY ./startok.sh /app/
RUN chmod 755 /app/startok.sh RUN chmod 755 /app/startok.sh
COPY ./startuid.sh /app/
RUN chmod 755 /app/startuid.sh
COPY ./lread.sh /app/ COPY ./lread.sh /app/
RUN chmod 755 /app/lread.sh RUN chmod 755 /app/lread.sh

View File

@@ -8,7 +8,7 @@ CXX = g++
# define any compile-time flags # define any compile-time flags
# CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto # CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto
CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto -std=c++11 CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto -w -std=c++11
# define library paths in addition to /usr/lib # define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify # if I wanted to include libraries not in /usr/lib I'd specify

View File

@@ -1,5 +1,2 @@
#!/bin/bash #!/bin/bash
rm src/CreateLicence.o
rm src/PlcLicence.o
rm src/utils.o
make make

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
chmod 777 output/licenceGenerator chmod 777 output/licenceGenerator
#./output/licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml #./output/licenceGenerator -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml
cd output cd output
./licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml ./licenceGenerator -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml

7
docker/startELC12.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
chmod 777 output/licenceGenerator
#./output/licenceGenerator -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml
cd output
./licenceGenerator -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml

7
docker/startuid.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
chmod 777 output/licenceGenerator
#./output/licenceGenerator -uid=a3395d1b898b4fdbbd563f9c75b3e885 -outputType=file -configFileName=licData.xml
cd output
./licenceGenerator -uid=a3395d1b898b4fdbbd563f9c75b3e885 -outputType=file -configFileName=licData.xml

BIN
ezlic_drt0_jjacdgpdxpb.lic Normal file

Binary file not shown.

View File

@@ -1,6 +1,9 @@
#ifndef SDCARD_H_ #ifndef SDCARD_H_
#define SDCARD_H_ #define SDCARD_H_
#include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#define CID_LENGTH 32 #define CID_LENGTH 32
#define CSD_LENGTH 32 #define CSD_LENGTH 32
@@ -20,9 +23,18 @@ const BYTE cnibblescount = 32;
const string cidFilePath = ""; const string cidFilePath = "";
struct SDCardInfo
{
uint32_t cardSize{};
uint32_t serialNumber{};
string date = "";
string oemID = "";
string name = "";
bool isLoaded = false;
};
class SDCard class SDCard
{ {
struct SDCardData struct SDCardData
{ {
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ? uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
@@ -37,6 +49,7 @@ class SDCard
uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6 uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
uint16_t manufacturerDate_year = 0; uint16_t manufacturerDate_year = 0;
uint8_t manufacturerDate_month = 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 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 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 uint8_t CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
@@ -46,25 +59,23 @@ class SDCard
bool crcCorrect = false; bool crcCorrect = false;
}; };
bool readSDCard(); bool readSDCard();
bool getCIDFromFile(); bool getCIDFromFile();
bool getCSDFromFile(); bool getCSDFromFile();
public: public:
SDCardData cardData; SDCardData cardData;
bool isLoaded = false; bool isLoaded = false;
char cid[32] = {}; char cid[32] = {};
char csd[32] = {}; char csd[32] = {};
string filePath = ""; string filePath = "";
string cidString = ""; //pro předání pro starý generátor string cidString = ""; // pro předání pro starý generátor
string csdString = ""; //pro předání pro starý generátor string csdString = ""; // pro předání pro starý generátor
SDCard(); SDCard();
SDCard(string cid, string csd); SDCard(string cid, string csd);
SDCard(const string filesPath); SDCard(const string filesPath);
}; };
#endif
#endif #endif

View File

@@ -0,0 +1,7 @@
#ifndef LICCONNECTOR_H_INCLUDED
#define LICCONNECTOR_H_INCLUDED
#include "lic_config.h"
//#include "../../_src/_main/Ez_automaincfg.h"
#endif // LICCONNECTOR_H_INCLUDED

View File

@@ -0,0 +1,7 @@
#ifndef LIC_CONFIG_H_INCLUDED
#define LIC_CONFIG_H_INCLUDED
//#define EZ_LIC_DEBUG //zapíná debug pro windows. Pro produkci je potřeba nechat zakomentované
//#define EZ_LIC_DEBUG_SHOW_DETAILS //zapíná detailní výpis při čtení licene. Pro produkci je potřeba nechat zakomentované
#endif

View File

@@ -1,19 +1,27 @@
#ifndef LICENCE_COMMON_H_ #ifndef LICENCE_COMMON_H_
#define LICENCE_COMMON_H_ #define LICENCE_COMMON_H_
#include "licConnector.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#define CRC = 1
//---------------- společná hlavička pro všechny licence ---------------- //---------------- společná hlavička pro všechny licence ----------------
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <map>
#include <unordered_map> #include <unordered_map>
#include <map>
#include <stdint.h> #include <stdint.h>
using namespace std; using namespace std;
#define XML_VERSION 1 #define XML_VERSION 1
#define SOFTWARE_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 cidSize = 32;
const int csdSize = 32; const int csdSize = 32;
@@ -44,14 +52,16 @@ enum class GeneralError
LicenceSizeMismatch = 52, LicenceSizeMismatch = 52,
LicenceSizeCardMismatch = 53, LicenceSizeCardMismatch = 53,
LicenceMismatch = 54, LicenceMismatch = 54,
LicenceCRCMismatch = 54,
UIDReadError = 55,
ItemsCountMismatch = 61 ItemsCountMismatch = 61
}; };
enum class ELCType enum class ELCType
{ {
ELC1 = 1, ELC1 = 1, // starý původní licenční soubor zalozený na CID a CSD
ELC2 = 2, ELC2 = 2, // modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů
ELC3 = 3 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 enum class ELCSubType
{ {
@@ -88,11 +98,15 @@ enum class FileNameGenerationType
DEFAULT = 1 DEFAULT = 1
}; };
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 struct Mapping
{ {
std::map<string, LicenceType> licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}}; unordered_map<string, LicenceType> licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}};
std::map<string, EncryptionType> licMapEncryption = {{"CID_AES256", EncryptionType::CID_AES256}, {"FIX_AES256", EncryptionType::FIX_AES256}}; unordered_map<string, EncryptionType> licMapEncryption = {{"CID_AES256", EncryptionType::CID_AES256}, {"FIX_AES256", EncryptionType::FIX_AES256}};
std::map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}}; unordered_map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}};
}; };
struct ErrorMessage struct ErrorMessage
@@ -103,13 +117,12 @@ struct ErrorMessage
struct LicenceIdentification struct LicenceIdentification
{ {
ELCType licElcType = ELCType::ELC2; ELCType licElcType = ELCType::ELC2; // hlavní typ licenčního souboru
LicenceType licLicenceType; LicenceType licLicenceType;
string licTypeName = ""; string licTypeName = "";
PlcType licPlcType; PlcType licPlcType;
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
uint8_t licenceIndex = 0; uint8_t licenceIndex = 0; // index licenčního souboru v případě, ze jich je víc
uint8_t revision; uint8_t revision;
uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC
uint16_t licItemsCount = 0; uint16_t licItemsCount = 0;
@@ -120,64 +133,82 @@ struct LicenceIdentification
/// @brief obecná struktura pro reader /// @brief obecná struktura pro reader
struct LicenceInfoGeneral struct LicenceInfoGeneral
{ {
int reqDataPointsCount = 0; map<DWORD, DWORD> licences = {};
unordered_map<int, int> licences = {};
}; };
/// @brief obecná struktura polozky licence, defaultní kompatibilita /// @brief obecná struktura polozky licence, defaultní kompatibilita
struct LicenceItem struct LicenceItem
{ {
int protocolId = -1; DWORD protocolId{};
int dataPointsCount = 0; DWORD dataPointsCount{};
}; };
/* struktury pro ELC 1 */ /* struktury pro ELC 1 */
//defaultní struktura pro ELC 1 // defaultní struktura pro ELC 1
struct LicenceELC1Info struct LicenceELC1Info
{ {
bool isValid {false}; bool isValid{false};
}; };
//struktura ELC1, kompatibilita 1 // struktura ELC1, kompatibilita 1
struct LicenceELC1Info_1 struct LicenceELC1Info_1
{ {
unordered_map<int, int> licences = {}; unordered_map<int, int> licences = {};
}; };
//defaultni struktura polozky licence ELC 1 // defaultni struktura polozky licence ELC 1
struct LicenceELC1Item struct LicenceELC1Item
{ {
int protocolId = -1; int protocolId = -1;
int dataPointsCount = 0; int dataPointsCount = 0;
}; };
/* struktury pro ELC 2 */ /* struktury pro ELC 2 */
//defaultní struktura pro ELC 2 // defaultní struktura pro ELC 2
struct LicenceELC2Info struct LicenceELC2Info
{ {
unordered_map<int, int> licences = {}; map<DWORD, DWORD> licences = {};
}; };
struct LicenceELC2Info_1 /* struktury pro ELC 3 */
// defaultní struktura pro ELC 3
struct LicenceELC3Info
{ {
unordered_map<int, int> licences = {}; map<DWORD, DWORD> licences = {};
}; };
//defaultni struktura polozky ELC 2 // struct LicenceELC2Info_1
// {
// map<int, int> licences = {};
// };
// defaultni struktura polozky ELC 2
struct LicenceELC2Item struct LicenceELC2Item
{ {
int protocolId = -1; DWORD protocolId{};
int dataPointsCount = 0; DWORD dataPointsCount{};
}; };
//struktura polozky ELC 2, // struktura polozky ELC 2 pro další kompatibility
struct LicenceELC2Item_1 struct LicenceELC2Item_1
{ {
int protocolId = -1; DWORD protocolId{};
int dataPointsCount = 0; DWORD dataPointsCount{};
}; };
// defaultni struktura polozky ELC 3
struct LicenceELC3Item
{
DWORD protocolId{};
DWORD dataPointsCount{};
};
// struktura polozky ELC 3 pro další kompatibility,
struct LicenceELC3Item_1
{
DWORD protocolId{};
DWORD dataPointsCount{};
};
class LicenceException : public std::exception class LicenceException : public std::exception
{ {
@@ -206,3 +237,5 @@ private:
}; };
#endif #endif
#endif

View File

@@ -1,8 +1,9 @@
#ifndef PLC_LICENCE1_COMMON_H #ifndef PLC_LICENCE1_COMMON_H
#define PLC_LICENCE1_COMMON_H #define PLC_LICENCE1_COMMON_H
#include <stdint.h> #include "utils.h"
#include <unordered_map> #ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <vector> #include <vector>
#include "licenceCommon.h" #include "licenceCommon.h"
#include "SDCard.h" #include "SDCard.h"
@@ -264,4 +265,5 @@ public:
}; };
#endif
#endif #endif

View File

@@ -1,8 +1,9 @@
#ifndef PLC_LICENCE2_COMMON_H #ifndef PLC_LICENCE2_COMMON_H
#define PLC_LICENCE2_COMMON_H #define PLC_LICENCE2_COMMON_H
#include <stdint.h> #include "utils.h"
#include <unordered_map> #ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <vector> #include <vector>
#include "licenceCommon.h" #include "licenceCommon.h"
#include "SDCard.h" #include "SDCard.h"
@@ -14,33 +15,15 @@ public:
LicenceELC2(); LicenceELC2();
LicenceELC2(LicenceIdentification &licIdentification); LicenceELC2(LicenceIdentification &licIdentification);
~LicenceELC2(); ~LicenceELC2();
string cid_cdsPath = ""; string cid_cdsPath = "";
string licenceFilePath = ""; string licenceFilePath = "";
string licFileName = "";
Mapping mapping; Mapping mapping;
ErrorMessage errorMessage; ErrorMessage errorMessage;
// enum class Error
// {
// SDCardReadError = 50,
// LicenceReadError = 51,
// LicenceSizeMismatch = 52,
// LicenceSizeCardMismatch = 53,
// LicenceMismatch = 54,
// ItemsCountMismatch = 61
// };
// unordered_map<Error, string> mapErrors = {
// {Error::SDCardReadError, "Nepodařilo se načíst SD kartu."},
// {Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
// {Error::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
// {Error::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
// {Error::LicenceMismatch, "Nesouhlasí licence."},
// {Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
// };
struct LicenceId struct LicenceId
{ {
char licIdent[5] = {'E', 'L', 'C', '0', '_'}; char licIdent[5] = {'E', 'L', 'C', '0', '_'};
@@ -49,22 +32,20 @@ public:
// struct __attribute__((__packed__)) LicencePublicHeader // struct __attribute__((__packed__)) LicencePublicHeader
struct LicenceIdentDataHeader struct LicenceIdentDataHeader
{ {
BYTE licenceType = 0; // EOSEOV, DRT ... BYTE licenceType{}; // EOSEOV, DRT ...
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
BYTE licenceIndex = 0; // 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 compatibilityVersion = 1; // udava verzi komplet PrivateContent
BYTE licItemCount = 0; // počet licenčních bodů BYTE licItemCount{}; // počet protokolů v linenci
WORD publicHeaderLength = 0; // délka veřejné hlavičy WORD publicHeaderLength{}; // délka veřejné hlavičy
WORD cardSize = 0; // velikost SD karty WORD cardSize{}; // velikost SD karty
DWORD serialNumber = 0; // seriove cislo karty DWORD serialNumber = {}; // seriove cislo karty
}; };
///
struct licDataItem struct licDataItem
{ {
WORD protoId = 0; // id protokolu pro ktery je licence DWORD protoId{}; // id protokolu pro ktery je licence
WORD licCount = 0; // pocet datovych bodu licence DWORD licCount{}; // pocet datovych bodu licence
char dummy[64] = {}; // dummy pro větší velikost licence v případě méně licenčních bodů
}; };
struct PublicHeader struct PublicHeader
@@ -73,35 +54,35 @@ public:
string projectDescription = ""; string projectDescription = "";
string date = ""; string date = "";
string licenceType = ""; string licenceType = "";
int crc = 0;
}; };
struct PrivateContent // privátní šifrovaná část struct PrivateContent // privátní šifrovaná část
{ {
LicenceIdentDataHeader licenceIdentHeader; LicenceIdentDataHeader licenceIdentHeader{};
vector<licDataItem> dataItems; vector<licDataItem> dataItems{};
WORD crc = 0; WORD crc{};
}; };
struct LicenceBody struct LicenceBody
{ {
LicenceId licId; LicenceId licId{};
LicenceIdentDataHeader licenceIdentHeader; LicenceIdentDataHeader licenceIdentHeader{};
string publicHeader = ""; // JSON string publicHeader = ""; // JSON
PrivateContent privateContent; PrivateContent privateContent{};
}; };
LicenceBody licBody; SDCard sdCard{};
SDCard sdCard;
LicenceIdentification lIdentification; protected:
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content); vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
vector<unsigned char> decryptPrivateContent(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(); string getLicenceName();
LicenceBody licBody{};
LicenceIdentification lIdentification{};
private: private:
}; };
#endif
#endif #endif

View File

@@ -0,0 +1,90 @@
#ifndef PLC_LICENCE3_COMMON_H
#define PLC_LICENCE3_COMMON_H
#include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#define UID_LENGTH 32
#include <vector>
#include "licenceCommon.h"
/// @brief společná třída pro pro reader i generator licence typu ELC2
class LicenceELC3
{
public:
LicenceELC3();
LicenceELC3(LicenceIdentification &licIdentification);
~LicenceELC3();
string licenceFilePath = "";
string licFileName = "";
string uid = "";
BYTE uidb[UID_LENGTH] = {};
string uid_path = ""; ///etc/machine-id
Mapping mapping;
ErrorMessage errorMessage;
struct LicenceId
{
char licIdent[5] = {'E', 'L', 'C', '0', '_'};
};
// struct __attribute__((__packed__)) LicencePublicHeader
struct LicenceIdentDataHeader
{
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 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
};
struct licDataItem
{
DWORD protoId{}; // id protokolu pro ktery je licence
DWORD licCount{}; // pocet datovych bodu licence
};
struct PublicHeader
{
string version = "";
string projectDescription = "";
string date = "";
string licenceType = "";
};
struct PrivateContent // privátní šifrovaná část
{
LicenceIdentDataHeader licenceIdentHeader{};
vector<licDataItem> dataItems{};
WORD crc{};
};
struct LicenceBody
{
LicenceId licId{};
LicenceIdentDataHeader licenceIdentHeader{};
string publicHeader = ""; // JSON
PrivateContent privateContent{};
};
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);
string getLicenceName();
LicenceBody licBody{};
LicenceIdentification lIdentification{};
private:
};
#endif
#endif

View File

@@ -1,14 +1,15 @@
#ifndef UTILS_H_ #ifndef UTILS_H_
#define UTILS_H_ #define UTILS_H_
#include "licConnector.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <chrono> #include <chrono>
#include <format> #include <libgen.h>
#include <libgen.h> // dirname
#include <climits>
#include <unistd.h> #include <unistd.h>
typedef uint8_t BYTE; typedef uint8_t BYTE;
@@ -42,12 +43,15 @@ void getCharsFromString(string& source, char *charArray, size_t length);
string getCompletePath(string fileName); string getCompletePath(string fileName);
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector); void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
uint16_t calculateCRC16(std::vector<unsigned char>& charVector); uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
uint16_t calculateCRC16(std::vector<char> &charVector);
uint16_t calculateCRC16(std::vector<unsigned char> &charVector, int removeCount);
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4); uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
uint32_t bytesToWord(uint8_t byte1, uint8_t byte2); uint32_t bytesToWord(uint8_t byte1, uint8_t byte2);
vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, const std::vector<unsigned char>& vector2); vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, const std::vector<unsigned char>& vector2);
bool readFile(string fileName, vector<char> &output); bool readFile(string fileName, vector<char> &output);
#endif #endif
#endif
@@ -67,6 +71,5 @@ bool readFile(string fileName, vector<char> &output);

View File

@@ -25,13 +25,15 @@ namespace Generator
pugi::xml_document *xmlDoc; pugi::xml_document *xmlDoc;
string projectDescription = ""; string projectDescription = "";
bool createLicence(); bool createLicence();
private:
void getHeader(); void getHeader();
string getVersion(int middleVersion); string getVersion(int middleVersion);
bool processInputConfiguration(); bool processInputConfiguration();
void getLicenceItems(); void getLicenceItems();
}; };
} }

View File

@@ -1,9 +1,38 @@
#ifndef ELC3_GENERATOR__H #ifndef ELC3_GENERATOR_H
#define ELC3_GENERATOR__H #define ELC3_GENERATOR_H
#include "utils.h"
#include "licenceCommon.h"
#include "licenceELC3.h"
#include "pugixml.hpp"
using namespace std;
namespace Generator namespace Generator
{ {
class Licence3 : public LicenceELC3
{
public:
Licence3();
Licence3(string uuid, pugi::xml_document * xmlDoc);
~Licence3();
string cid = "";
string csd = "";
pugi::xml_document *xmlDoc;
string projectDescription = "";
bool createLicence();
private:
void getHeader();
string getVersion(int middleVersion);
bool processInputConfiguration();
void getLicenceItems();
};
} }
#endif #endif

View File

@@ -1,15 +1,15 @@
#include "licenceCommon.h"
#ifndef LICENCE_GENERATOR_H_ #ifndef LICENCE_GENERATOR_H_
#define LICENCE_GENERATOR_H_ #define LICENCE_GENERATOR_H_
#define DEFAULT_LICENCE_POINTS_COUNT = 4294967295 //počet licenčních bodů pro některé protokoly např: pt_Ez_buffer a pt_Ez_webs
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include "pugixml.hpp" #include "pugixml.hpp"
#include "licenceCommon.h"
// #include "licenceELC11.h"
// #include "licenceELC21.h"
// #include "licenceELC31.h"
#include "licGenELC1.h" #include "licGenELC1.h"
#include "licGenELC2.h" #include "licGenELC2.h"
@@ -33,16 +33,17 @@ public:
pugi::xml_document *doc; pugi::xml_document *doc;
}; };
LicData licData; LicData licData {};
int elcSwitchType; int elcSwitchType {};
string operationErrors = ""; string operationErrors = "";
pugi::xml_document doc; pugi::xml_document doc {} ;
bool argumentsCorrect = false; bool argumentsCorrect = false;
ErrorMessage error; ErrorMessage error {};
// LicenceELC11 *licence11; // LicenceELC11 *licence11;
// LicenceELC21 *licence21; // LicenceELC21 *licence21;
// LicenceELC31 *licence31; // LicenceELC31 *licence31;
Mapping mapping; Mapping mapping {};
SDCard sdCard {};
LicenceGenerator(); LicenceGenerator();
~LicenceGenerator(); ~LicenceGenerator();
@@ -50,7 +51,7 @@ public:
void createLicenceFile(); void createLicenceFile();
LicenceInfoGeneral licenceInfo; LicenceInfoGeneral licenceInfoGeneral {};
private: private:
LicenceIdentification licIdentification; LicenceIdentification licIdentification;

View File

@@ -2,6 +2,8 @@
#define ELC1_READER__H #define ELC1_READER__H
#include "utils.h" #include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licenceCommon.h" #include "licenceCommon.h"
#include "licenceELC1.h" #include "licenceELC1.h"
#include "SDCard.h" #include "SDCard.h"
@@ -28,4 +30,5 @@ namespace Reader
}; };
} }
#endif
#endif #endif

View File

@@ -2,6 +2,8 @@
#define ELC2_READER_H #define ELC2_READER_H
#include "utils.h" #include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licenceCommon.h" #include "licenceCommon.h"
#include "licenceELC2.h" #include "licenceELC2.h"
#include "SDCard.h" #include "SDCard.h"
@@ -21,10 +23,10 @@ namespace Reader
bool readLicence(LicenceInfoGeneral *licences); bool readLicence(LicenceInfoGeneral *licences);
bool getLicenceInfo(void *ptr); bool getLicenceInfo(void *ptr);
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
void getLicenceItems(); void getLicenceItems();
}; };
} }
#endif
#endif #endif

View File

@@ -1,9 +1,32 @@
#ifndef ELC3_READER__H #ifndef ELC3_READER__H
#define ELC3_READER__H #define ELC3_READER__H
#include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licenceCommon.h"
#include "licenceELC3.h"
namespace Reader namespace Reader
{ {
class Licence3 : public LicenceELC3
{
public:
LicenceELC3Info licenceInfo;
Licence3();
~Licence3();
Licence3(LicenceIdentification &licIdentification);
bool readLicence(LicenceInfoGeneral *licences);
bool getLicenceInfo(void *ptr);
void getLicenceItems();
private:
bool getUID();
};
} }
#endif
#endif #endif

View File

@@ -2,7 +2,9 @@
#define LICENCE_READER_H_ #define LICENCE_READER_H_
#include "utils.h" #include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "SDCard.h"
#include "licReaderELC1.h" #include "licReaderELC1.h"
#include "licReaderELC2.h" #include "licReaderELC2.h"
#include "licReaderELC3.h" #include "licReaderELC3.h"
@@ -19,6 +21,14 @@ struct InitStructure
int compatibility = 0; int compatibility = 0;
string licenceFilePath = ""; string licenceFilePath = "";
string cid_csd_filePath = ""; string cid_csd_filePath = "";
string uid_filePath = "";
};
/// @brief struktura pro informaci o licenci
struct LicenceInfo
{
string licenceFileName = ""; //samotný název licenčního souboru
string licenceFilePath = ""; //název licenčního souboru včetně cesty
}; };
class LicenceReader class LicenceReader
@@ -29,24 +39,25 @@ public:
string operationErrors = ""; string operationErrors = "";
bool argumentsCorrect = false; bool argumentsCorrect = false;
ErrorMessage error; ErrorMessage error;
Licence2 *licence2; SDCardInfo sdCardInfo {};
Licence1 *licence1; LicenceInfo licInfo {};
LicenceReader(); LicenceReader();
~LicenceReader(); ~LicenceReader();
bool init(int elcType, InitStructure &initStructure); bool init(int elcType, InitStructure &initStructure);
bool initread(int elcType, InitStructure &initStructure); bool initread(int elcType, InitStructure &initStructure);
bool getLicenceInfo(void *returnStructure); bool getLicenceInfo(void *returnStructure); //vrací informace o všech licenčních bodech základě předané návratové struktury
bool getLicenceItemInfo(int protocolId, void *returnItemStructure); bool getLicenceItemInfo(int protocolId, void *returnItemStructure); //vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
LicenceInfoGeneral licenceInfo;
private: private:
LicenceIdentification licIdentification; Licence3 *licence3 {}; //interní struktura pro zpracování licence ELC2
Licence2 *licence2 {}; //interní struktura pro zpracování licence ELC2
Licence1 *licence1 {}; //interní struktura pro zpracování licence ELC1
LicenceIdentification licIdentification {};
string configFileName = ""; string configFileName = "";
void *licence = nullptr; LicenceInfoGeneral licencesInfo {}; //pole licencí
}; };
#endif
#endif #endif

View File

@@ -1,32 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<licence elc="1" xmlVersion="1" revision="1" compatibility="1"> <licence elc="1" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType> <licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>WAGO</plcType> <plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName> <licenceName>Licence pro EOV_OSV</licenceName>
<station>start.cz</station> <station>zst.ceskatrebova.ddts.cz</station>
<distributor>teco</distributor> <distributor>ROV21</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>
</licence> </licence>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<data version="1">
<plcType>WAGO</plcType>
<licenceType version="1">EOV_OSV</licenceType>
<licenceName>Licence pro EOV_OSV</licenceName>
<station>start.cz</station>
<distributor>teco</distributor>
</data>

View File

@@ -1 +1 @@
licenceGenerator.exe -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml licenceGenerator.exe -uid=a3395d1b898b4fdbbd563f9c75b3e885.a433 -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml

1
output/createnewELC2.bat Normal file
View File

@@ -0,0 +1 @@
licenceGenerator.exe -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,27 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<licence elc="2" xmlVersion="1" revision="1" compatibility="1"> <licence elc="3" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType> <licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>WAGO</plcType> <plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName> <licenceName>Licence pro EOV_OSV</licenceName>
<station>odb.zaluzi.drt.cz</station> <project>Licence ELC3</project>
<distributor>POZ8</distributor> <items>
<project>Projekt XXX stanice YYY</project> <item>
<items> <name>pt_Ez_interHW</name>
<item> <protoId>0</protoId>
<name>Položka licence 1</name> <dataPointsCount>3</dataPointsCount>
<protoId>111</protoId> </item>
<dataPointsCount>7454</dataPointsCount> <item>
</item> <name>pt_Ez_buffer</name>
<item> <protoId>1</protoId>
<name>Položka licence 2</name> <dataPointsCount>4294967295</dataPointsCount>
<protoId>222</protoId> </item>
<dataPointsCount>6477</dataPointsCount> <item>
</item> <name>pt_Ez_webs</name>
<item> <protoId>2</protoId>
<name>Položka licence 3</name> <dataPointsCount>4294967295</dataPointsCount>
<protoId>333</protoId> </item>
<dataPointsCount>7844</dataPointsCount> <item>
</item> <name>pt_Ez_iec104c</name>
</items> <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> </licence>

39
output/licDataActual3.xml Normal file
View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="3" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">DRT</licenceType>
<plcType>wago</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<project>Licence ELC3</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>

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>

39
output/licDataRDT2.xml Normal file
View File

@@ -0,0 +1,39 @@
<?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 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>

Binary file not shown.

1
output/machine-id Normal file
View File

@@ -0,0 +1 @@
a3395d1b898b4fdbbd563f9c75b3e885

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,6 @@
#define LINUX 1 #include "reader/licenceReader.h"
//#define WINDOWS 1
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <stdio.h> #include <stdio.h>
#include "licenceGenerator.h" #include "licenceGenerator.h"
@@ -8,7 +9,7 @@
/// @param argc /// @param argc
/// @param argv parametry pro generování licence /// @param argv parametry pro generování licence
/// @return /// @return
int main6(int argc, char *argv[]) int main8(int argc, char *argv[])
{ {
unordered_map<string, string> arguments = getArguments(argc, argv); unordered_map<string, string> arguments = getArguments(argc, argv);
try try
@@ -16,6 +17,48 @@ int main6(int argc, char *argv[])
unordered_map<string, string> arguments = getArguments(argc, argv); unordered_map<string, string> arguments = getArguments(argc, argv);
LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]); LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]);
generatorOld.createLicenceFile(); generatorOld.createLicenceFile();
//system("pause");
#ifdef READ
InitStructure initStructure = {};
initStructure.licenceType = (int)LicenceType::DRT;
initStructure.licenceVersion = 1;
initStructure.licenceIndex = 0;
initStructure.licenceFilePath = ""; //c://_projects//sd_gen//output//"; // cesta k licenčnímu souboru
initStructure.compatibility = 1;
// initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
// 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
initStructure.uid_filePath = ""; // cesta k souboru machine-id. (/etc/machine-id), takze by mělo být /etc/. machine-id si doplním
//---------------------------------------- ELC3 ----------------------------------------------------------
// verze ELC 3 pro jeden protokol. Oproti ELC2 je potřeba přidat cestu k uid/machine-id v initStructure
LicenceReader licenceReaderELC3{};
if (licenceReaderELC3.initread(3, initStructure)) // iniciacni nacteni
{
LicenceELC3Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
// if ()
int protocolId = 7;
// ukazka dat SD karty
cout << "název licenčního souboru: " << licenceReaderELC3.licInfo.licenceFileName << "\n";
cout << "cesta k licenčnímu souboru: " << licenceReaderELC3.licInfo.licenceFilePath << "\n";
if (licenceReaderELC3.getLicenceItemInfo(protocolId, &info))
{
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
}
else
cout << "Tento protokol nemá body";
}
else
{
cout << "CHYBA: " << licenceReaderELC3.error.message;
}
//---------------------------------------- ELC3 ----------------------------------------------------------
system("pause");
return SUCCES;
#endif
return SUCCES; return SUCCES;
} }
catch (const LicenceException &ex) catch (const LicenceException &ex)
@@ -32,3 +75,5 @@ int main6(int argc, char *argv[])
system("pause"); system("pause");
return SUCCES; return SUCCES;
} }
#endif

View File

@@ -1,27 +1,30 @@
#define LINUX 1
// #define WINDOWS 1
#include <stdio.h>
#include "licenceReader.h" #include "licenceReader.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
/// @brief hlavní funkce /// @brief hlavní funkce
/// @param argc /// @param argc
/// @param argv parametry pro generování licence /// @param argv parametry pro generování licence
/// @return /// @return
int main() int main()
{ {
// buffer,850client,104client, 104server, web
// kouknout na unikatní klíc pro linux (native uid, i openssl neco má)
try try
{ {
InitStructure initStructure;
initStructure.licenceType = (int)LicenceType::EOS_EOV; InitStructure initStructure = {};
initStructure.licenceType = (int)LicenceType::DRT;
initStructure.licenceVersion = 1; initStructure.licenceVersion = 1;
initStructure.licenceIndex = 0; initStructure.licenceIndex = 0;
initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru initStructure.licenceFilePath = ""; //c://_projects//sd_gen//output//"; // cesta k licenčnímu souboru
// initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní. // initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
// pro ELC 1 LicenceELC1Info s výstupem isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; } // 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 kontorlu licence initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence
initStructure.uid_filePath = ""; // cesta k souboru machine-id. (/etc/machine-id), takze by mělo být /etc/.
// verze původní ELC 1 //verze původní ELC 1, zatím zůstává staré řešení
LicenceReader licenceReaderELC1{}; LicenceReader licenceReaderELC1{};
if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
{ {
@@ -43,16 +46,27 @@ int main()
// verze ELC 2 pro jeden protokol // verze ELC 2 pro jeden protokol
LicenceReader licenceReaderELC2{}; LicenceReader licenceReaderELC2{};
if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni
{ {
// v případě kompatibility 0, či nezadané výstup nativně je defaultní. // v případě kompatibility 0, či nezadané výstup nativně je defaultní.
// v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility. Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1 // v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility.
// Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
// if () // if ()
int protocolId = 333; int protocolId = 4;
// ukazka 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";
// if (initStructure.compatibility == 1) //ukazka kompatibilita cout << "název licenčního souboru: " << licenceReaderELC2.licInfo.licenceFileName << "\n";
cout << "cesta k licenčnímu souboru: " << licenceReaderELC2.licInfo.licenceFilePath << "\n";
// if (initStructure.compatibility == 1) //ukazka kompatibilita 1
// { // {
// LicenceELC2Item_1 info; //jiná struktura, zbytek stejný // LicenceELC2Item_1 info; //jiná struktura, zbytek stejný
// if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info)) // if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
@@ -67,20 +81,46 @@ int main()
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl; cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
} }
else else
cout << "CHYBA: " << licenceReaderELC2.error.message; cout << "Tento protokol nemá body";
} }
else else
{ {
cout << "CHYBA: " << licenceReaderELC2.error.message; cout << "CHYBA: " << licenceReaderELC2.error.message;
} }
LicenceReader licenceReaderCompleteELC2{}; //---------------------------------------- ELC3 ----------------------------------------------------------
//verze ELC 3 pro jeden protokol. Oproti ELC2 je potřeba přidat cestu k uid/machine-id v initStructure
LicenceReader licenceReaderELC3{};
if (licenceReaderELC3.initread(3, initStructure)) // iniciacni nacteni
{
LicenceELC3Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo1, LicenceInfo2, LicenceInfo3)
// if ()
int protocolId = 7;
if (licenceReaderELC3.getLicenceItemInfo(protocolId, &info))
{
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
}
else
cout << "Tento protokol nemá body";
}
else
{
cout << "CHYBA: " << licenceReaderELC3.error.message;
}
//---------------------------------------- ELC3 ----------------------------------------------------------
// verze ELC 2 kompletní načtení // verze ELC 2 kompletní načtení
/*
LicenceReader licenceReaderCompleteELC2{};
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
{ {
LicenceELC2Info info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) LicenceELC2Info info;
int protocolId = 333; int protocolId = 2;
if (licenceReaderCompleteELC2.getLicenceInfo(&info)) if (licenceReaderCompleteELC2.getLicenceInfo(&info))
{ {
@@ -88,11 +128,12 @@ int main()
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n"; cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
else else
cout << "Pro tento protokol nejsou definovay licencni body\n"; cout << "Pro tento protokol nejsou definovay licencni body\n";
cout << "Vypis vsech licencnich bodu: " << endl; cout << "Vypis vsech licencnich bodu: " << endl;
for (const auto &pair : info.licences) // for (const auto &pair : info.licences)
{ // {
std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; // std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
} // }
} }
else else
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message; cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
@@ -101,15 +142,141 @@ int main()
{ {
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message; cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
} }
*/
} }
catch (...) catch (...)
{ {
cout << "Obecna chyba\n"; cout << "Obecna chyba\n";
} }
// system("pause"); system("pause");
return SUCCES; return SUCCES;
// verze původní ELC 1, zatím zůstává staré řešení
// LicenceReader licenceReaderELC1{};
// if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
// {
// LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
// if (licenceReaderELC1.getLicenceInfo(&info))
// {
// if (info.isValid)
// cout << "Platna licence ELC1 \n";
// else
// cout << "Neplatna licence ELC1\n";
// }
// else
// cout << "CHYBA: " << licenceReaderELC1.error.message;
// }
// else
// {
// cout << "CHYBA: " << licenceReaderELC1.error.message;
// }
// return SUCCES;
} }
// cid: 0353445355313647801b1a9f6600c747 csd: 400e00325b59000076b27f800a404013 // buffer,web, 850client,104client, 104server,
// https://sprava.app.elzel.cz/device/417 cid: 9f54495344434954615ad803c50171bf csd: 400e00325b5900003be77f800a400043 //
/*
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
pt_Ez_buffer, // 1 - datovy Buffer
pt_Ez_webs, // 2 - Ez www conectivity server
pt_Ez_dblogc, // 3 - Ez database log client
pt_Ez_sysinfoc, // 4 - Systemove informace systemu
pt_Ez_iec104c, // 5 - IEC-104 client
pt_Ez_iec104s, // 6 - IEC-104 server
pt_Ez_iec61850c, // 7 - IEC-61850 client
pt_Ez_iec61850s, // 8 - IEC-61850 server
pt_Ez_mdbipc, // 9 - Modbus IP client
pt_Ez_mdbips, // 10 - Modbus IP server
pt_Ez_mdbrtum, // 11 - Modbus RTU master
pt_Ez_mdbrtul, // 12 - Modbus RTU slave
pt_Ez_mdbasciim, // 13 - Modbus ASCII master
pt_Ez_mdbasciil, // 14 - Modbus ASCII slave
pt_Ez_gsmm, // 15 - GSM master
pt_Ez_gsml, // 16 - GSM slave
pt_Ez_iec101m, // 17 - IEC-101 master
pt_Ez_iec101l, // 18 - IEC-101 slave
pt_Ez_iec103m, // 19 - IEC-103 master
pt_Ext_snmpc, // 20 - SNMP client
pt_Ext_snmps, // 21 - SNMP server
pt_Ez_siadc09c, // 22 - ANSI/SIA DC-09 client
pt_Ez_honeywellgxyc, // 23 - Honeywell Galaxy smart client
pt_Ez_contactidm, // 24 - Ademco Contact ID - SIA DC-05 master
pt_Ez_litesm, // 25 - EPS Lites master
pt_Ez_epsnetmpcc, // 26 - Tecomat Epsnet MPC client
pt_Ez_epsnetmpcs, // 27 - Tecomat Epsnet MPC server
pt_Ez_epsnetmpcm, // 28 - Tecomat Epsnet MPC master
pt_Ez_epsnetmpcl, // 29 - Tecomat Epsnet MPC slave
pt_Ez_epsnetplc, // 30 - Tecomat Epsnet PLC
pt_Ez_amitdbnetipc, // 31 - AMiT DB-Net/IP client
pt_Ez_amitdbnetm, // 32 - AMiT DB-Net master
pt_Ez_fatekm, // 33 - Fatek master
pt_Ez_canm, // 34 - CAN master
pt_Ez_iec6205621m, // 35 - IEC 62056.21 master
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ů):
#define EZ_HW_TECOMAT 1
#define EZ_HW_WAGO 2
#define EZ_HW_NATIVE_LINUX 3
#define EZ_HW_NATIVE_LINUX_DOCKER 4
#define EZ_HW_ARM64_LINUX 5
#define EZ_HW_ARM64_LINUX_DOCKER 6
Pro ostatní je uveden skutečný požadovaný počet licenčních bodů pro daný protokol.
U protokolů pt_Ez_buffer a pt_Ez_webs nastavovat defaultně EZ_PROTO_INFINITE = 4294967295
*/
/*
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
pt_Ez_buffer, // 1 - datovy Buffer
pt_Ez_webs, // 2 - Ez www conectivity server
pt_Ez_dblogc, // 3 - Ez database log client
pt_Ez_mdbipc, // 4 - Modbus IP client
pt_Ez_mdbips, // 5 - Modbus IP server
pt_Ext_snmpc, // 6 - SNMP client
pt_Ext_snmps, // 7 - SNMP server
pt_Ez_iec104s, // 8 - IEC-104 server
pt_Ez_iec104c, // 9 - IEC-104 client
pt_Ez_sysinfoc, // 10 - Systemove informace systemu
pt_Ez_siadc09c, // 11 - ANSI/SIA DC-09 client
pt_Ez_honeywellgxyc, // 12 - Honeywell Galaxy smart client
pt_Ez_iec61850s, // 13 - IEC-61850 server
pt_Ez_iec61850c, // 14 - IEC-61850 client
pt_Ez_mdbrtum, // 15 - Modbus RTU master
pt_Ez_mdbrtul, // 16 - Modbus RTU slave
pt_Ez_mdbasciim, // 17 - Modbus ASCII master
pt_Ez_mdbasciil, // 18 - Modbus ASCII slave
pt_Ez_epsnetmpcc, // 19 - Tecomat Epsnet MPC client
pt_Ez_epsnetmpcs, // 20 - Tecomat Epsnet MPC server
pt_Ez_epsnetmpcl, // 21 - Tecomat Epsnet MPC slave
pt_Ez_epsnetmpcm, // 22 - Tecomat Epsnet MPC master
pt_Ez_epsnetplc, // 23 - Tecomat Epsnet PLC
pt_Ez_litesm, // 24 - EPS Lites master
pt_Ez_contactidm, // 25 - Ademco Contact ID - SIA DC-05 master
pt_Ez_amitdbnetipc, // 26 - AMiT DB-Net/IP client
pt_Ez_amitdbnetm, // 27 - AMiT DB-Net master
pt_Ez_fatekm, // 28 - Fatek master
pt_Ez_canm, // 29 - CAN master
pt_Ez_iec6205621m, // 30 - IEC 62056.21 master
pt_Ez_mbusm, // 31 - MBus master
pt_Ez_gsmm, // 32 - GSM master
pt_Ez_gsml, // 33 - GSM slave
pt_Ez_iec101m, // 34 - IEC-101 master
pt_Ez_iec101l, // 35 - IEC-101 slave
pt_Ez_iec103m, // 36 - IEC-103 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)
*/
#endif

View File

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

View File

@@ -1,5 +1,5 @@
#include "utils.h"
#include "SDCard.h" #include "SDCard.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
SDCard::SDCard() SDCard::SDCard()
{ {
@@ -72,6 +72,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.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 // CSD
for (int i = 0; i < CSD_LENGTH; i++) for (int i = 0; i < CSD_LENGTH; i++)
this->cardData.CSD_nibble[i] = (BYTE)csd[i]; this->cardData.CSD_nibble[i] = (BYTE)csd[i];
@@ -141,3 +146,5 @@ bool SDCard::getCSDFromFile()
return true; return true;
} }
#endif

View File

@@ -1,2 +1,3 @@
src/common/SDCard.o: src/common/SDCard.cpp include/common/utils.h \ src/common/SDCard.o: src/common/SDCard.cpp include/common/SDCard.h \
include/common/SDCard.h include/common/utils.h include/common/licConnector.h \
include/common/lic_config.h

Binary file not shown.

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,5 +1,5 @@
#include "licenceELC1.h" #include "licenceELC1.h"
#include "utils.h" #ifndef EZ_APPLICATION_LICENCE_DISABLE
#define CID_LENGTH 32 #define CID_LENGTH 32
#define CSD_LENGTH 32 #define CSD_LENGTH 32
@@ -216,3 +216,5 @@ string LicenceELC1::getLicenceName(BYTE licPostfix)
} }
return result; return result;
} }
#endif

View File

@@ -1,3 +1,4 @@
src/common/licenceELC1.o: src/common/licenceELC1.cpp \ src/common/licenceELC1.o: src/common/licenceELC1.cpp \
include/common/licenceELC1.h include/common/licenceCommon.h \ include/common/licenceELC1.h include/common/utils.h \
include/common/SDCard.h include/common/utils.h include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h include/common/SDCard.h

Binary file not shown.

View File

@@ -1,15 +1,15 @@
#include "licenceELC2.h" #include "licenceELC2.h"
#include "utils.h" #ifndef EZ_APPLICATION_LICENCE_DISABLE
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 /// @param licPostfix
/// @return /// @return
string LicenceELC2::getLicenceName() string LicenceELC2::getLicenceName()
@@ -61,8 +61,10 @@ string LicenceELC2::getLicenceName()
vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigned char> &content) vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigned char> &content)
{ {
BYTE initVector[15] = {}; // BYTE initVector[15] = {}; old funkční s 15, předěláme to do 16 pro test
BYTE aesKey[32] = {}; // BYTE aesKey[32] = {};
BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0};
BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0};
LicenceELC2::initVector(initVector, aesKey); LicenceELC2::initVector(initVector, aesKey);
@@ -70,7 +72,8 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
const unsigned char *plainTextArray = content.data(); const unsigned char *plainTextArray = content.data();
int finalEncryptedLength = encrypt(plainTextArray, content.size(), aesKey, initVector, encrypted); 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); std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
@@ -79,69 +82,78 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
vector<unsigned char> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &content) vector<unsigned char> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &content)
{ {
BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0};
BYTE initVector[15] = {0}; BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0};
BYTE aesKey[32] = {0};
LicenceELC2::initVector(initVector, aesKey); LicenceELC2::initVector(initVector, aesKey);
const unsigned char *encryptedData = content.data(); const unsigned char *encryptedData = content.data();
unsigned char decrypted[10000] = {}; 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); 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++)
{
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 = {5, 1, 3, this->sdCard.cardData.CID[9], 4, 12, 13, 17, 9, this->sdCard.cardData.CID_nibble[24]-15, 2, 23, 17, 13, 4, 3};
CryptInitVector vec3 = {2, 7, 1, this->sdCard.cardData.CID[6], 8, 13, 16, 6, 4, this->sdCard.cardData.CID_nibble[20]-15, 8, 7, 2, 14, 15, 21};
struct Vector15 std::unordered_map<int, CryptInitVector> vectors;
{ vectors.insert(std::pair<int, CryptInitVector>(1, vec1));
int vec[15]; vectors.insert(std::pair<int, CryptInitVector>(2, vec2));
}; vectors.insert(std::pair<int, CryptInitVector>(3, vec3));
Vector15 vec1 = {this->sdCard.cardData.CID[10], CryptAesKey key1 = {this->sdCard.cardData.CID[12],
this->sdCard.cardData.CID[12], this->sdCard.cardData.CID[23] - 15,
this->sdCard.cardData.CID[11], this->sdCard.cardData.CID[25] - 15,
this->sdCard.cardData.CID[9], this->sdCard.cardData.CID[11],
this->sdCard.cardData.CID_nibble[22] - 15, this->sdCard.cardData.CID[9],
this->sdCard.cardData.CID_nibble[24] - 15, this->sdCard.cardData.CID_nibble[21],
this->sdCard.cardData.CID_nibble[25] - 15, this->sdCard.cardData.CID[9] % 25,
this->sdCard.cardData.CID_nibble[21] - 15, this->sdCard.cardData.CID_nibble[22] - 15,
9, 10, 11, 12, 13, 14, 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};
Vector15 vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //TODO přidat smysluplnější indexy 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};
Vector15 vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 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; std::unordered_map<int, CryptAesKey> keys;
vectors.insert(std::pair<int, Vector15>(1, vec1)); keys.insert(std::pair<int, CryptAesKey>(1, key1));
vectors.insert(std::pair<int, Vector15>(2, vec2)); keys.insert(std::pair<int, CryptAesKey>(2, key2));
vectors.insert(std::pair<int, Vector15>(3, vec3)); keys.insert(std::pair<int, CryptAesKey>(3, key3));
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));
int lVersion = lIdentification.licenceVersion; int lVersion = lIdentification.licenceVersion;
@@ -169,4 +181,4 @@ void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[])
memcpy(&key[24], &key[12], 8); memcpy(&key[24], &key[12], 8);
} }
#endif

View File

@@ -1,3 +1,4 @@
src/common/licenceELC2.o: src/common/licenceELC2.cpp \ src/common/licenceELC2.o: src/common/licenceELC2.cpp \
include/common/licenceELC2.h include/common/licenceCommon.h \ include/common/licenceELC2.h include/common/utils.h \
include/common/SDCard.h include/common/utils.h include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h include/common/SDCard.h

Binary file not shown.

177
src/common/licenceELC3.cpp Normal file
View File

@@ -0,0 +1,177 @@
#include "licenceELC3.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
LicenceELC3::LicenceELC3() {}
LicenceELC3::~LicenceELC3() {}
LicenceELC3::LicenceELC3(LicenceIdentification &licIdentification) : lIdentification(licIdentification)
{
}
/// @brief get proper licencename
/// @param licPostfix
/// @return
string LicenceELC3::getLicenceName()
{
BYTE uidb[UID_LENGTH] = {};
for (unsigned int i = 0; i < this->uid.length(); i++) uidb[i] = uid[i];
string result = "";
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"));
baseString.insert(std::pair<int, string>((int)LicenceType::DRT, "ezlic_drt"));
struct Index
{
int index[11];
};
std::unordered_map<int, Index> indexes;
Index indexes1 = {7, 16, 20, 23, 18, 4, 9, 11, 6, 9, 13};
Index indexes2 = {12, 10, 22, 23, 24, 25, 9, 11, 2, 1, 3}; // puvodní indexy
Index indexes3 = {8, 13, 11, 9, 7, 11, 10, 13, 5, 20, 19};
indexes.insert(std::pair<int, Index>(1, indexes1));
indexes.insert(std::pair<int, Index>(2, indexes2));
indexes.insert(std::pair<int, Index>(3, indexes3));
result = baseString.at(licType) + to_string(lIdentification.licenceIndex) + "_";
result += prefixChar + ((uidb[indexes.at(lVersion).index[0]] + (lIdentification.licenceIndex * 11)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[1]] + (lIdentification.licenceIndex * 39)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[2]] + (lIdentification.licenceIndex * 1)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[3]] * 2) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[4]] + (lIdentification.licenceIndex * 5)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[5]] * 3) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[6]] + (lIdentification.licenceIndex * 52)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[7]] + (lIdentification.licenceIndex * 34)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[8]] + (lIdentification.licenceIndex * 21)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[9]] + (lIdentification.licenceIndex * 47)) % 25);
result += prefixChar + ((uidb[indexes.at(lVersion).index[10]] + (lIdentification.licenceIndex * 7)) % 25);
result += ".lic";
return result;
}
vector<unsigned char> LicenceELC3::cryptPrivateContent(const std::vector<unsigned char> &content)
{
BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0};
BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0};
LicenceELC3::initVector(initVector, aesKey);
unsigned char encrypted[10000] = {};
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í.");
std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
return result;
}
vector<unsigned char> LicenceELC3::decryptPrivateContent(const std::vector<unsigned char> &content)
{
BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0};
BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0};
LicenceELC3::initVector(initVector, aesKey);
const unsigned char *encryptedData = content.data();
unsigned char decrypted[10000] = {};
int decrypted_len = decrypt(encryptedData, content.size(), aesKey, initVector, decrypted);
if (decrypted_len <= 0)
throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování.");
vector<unsigned char> res{};
for (int i = 0; i < decrypted_len; i++)
{
res.push_back(decrypted[i]);
}
return res;
}
void LicenceELC3::initVector(BYTE *iVector, BYTE *key)
{
BYTE uidb[UID_LENGTH] = {};
for (unsigned int i = 0; i < this->uid.length(); i++) uidb[i] = uid[i];
CryptInitVector vec1 = {uidb[10],
uidb[12],
uidb[11],
uidb[9],
uidb[22]-6,
uidb[24]-4,
uidb[25]-13,
uidb[21]-9,
9, 10, 11, 12, 13, 14, 15, 16};
CryptInitVector vec2 = {5, 1, 3, uidb[9], 4, 12, 13, 17, 9, uidb[24]-15, 2, 23, 17, 13, 4, 3};
CryptInitVector vec3 = {2, 7, 1, uidb[6], 8, 13, 16, 6, 4, uidb[20]-15, 8, 7, 2, 14, 15, 21};
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));
CryptAesKey key1 = {uidb[12],
uidb[23] - 15,
uidb[25] - 15,
uidb[11],
uidb[9],
uidb[21],
uidb[9] % 25,
uidb[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, 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;
iVector[0] = vectors.at(lVersion).vec[0];
iVector[1] = vectors.at(lVersion).vec[1];
iVector[2] = vectors.at(lVersion).vec[2];
iVector[3] = vectors.at(lVersion).vec[3];
iVector[4] = vectors.at(lVersion).vec[4];
iVector[5] = vectors.at(lVersion).vec[5];
iVector[6] = vectors.at(lVersion).vec[6];
iVector[7] = vectors.at(lVersion).vec[7];
memcpy(&iVector[8], &iVector[0], 8);
key[0] = keys.at(lVersion).key[0];
key[1] = keys.at(lVersion).key[1];
key[2] = keys.at(lVersion).key[2];
key[3] = keys.at(lVersion).key[3];
key[4] = keys.at(lVersion).key[4];
key[5] = keys.at(lVersion).key[5];
key[6] = keys.at(lVersion).key[6];
key[7] = keys.at(lVersion).key[7];
memcpy(&key[8], &key[0], 8);
memcpy(&key[16], &key[6], 8);
memcpy(&key[24], &key[12], 8);
}
#endif

4
src/common/licenceELC3.d Normal file
View File

@@ -0,0 +1,4 @@
src/common/licenceELC3.o: src/common/licenceELC3.cpp \
include/common/licenceELC3.h include/common/utils.h \
include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h

BIN
src/common/licenceELC3.o Normal file

Binary file not shown.

View File

@@ -1,7 +1,10 @@
#include "utils.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include <openssl/conf.h> #include <openssl/conf.h>
#include <openssl/ssl.h> /* core library */ #include <openssl/ssl.h> /* core library */
#include "utils.h"
using namespace std;
using namespace std; using namespace std;
@@ -89,8 +92,8 @@ DATE getLicDate()
int seconds = 1 * local_time->tm_sec; int seconds = 1 * local_time->tm_sec;
int totalSeconds = hoursSeconds + minutesSeconds + seconds; int totalSeconds = hoursSeconds + minutesSeconds + seconds;
#ifdef WINDOWS #ifdef EZ_LIC_DEBUG
DATE dateOnly = ttime - totalSeconds + 7200; // (pro windows); // 7200 + vteřina za dvě hodiny pro srování DATE dateOnly = ttime - totalSeconds + 7200; // (pro win); // 7200 + vteřina za dvě hodiny pro srování
#else #else
DATE dateOnly = ttime - totalSeconds; DATE dateOnly = ttime - totalSeconds;
#endif #endif
@@ -127,14 +130,20 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
* is 128 bits * is 128 bits
*/ */
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
/* /*
* Provide the message to be encrypted, and obtain the encrypted output. * Provide the message to be encrypted, and obtain the encrypted output.
* EVP_EncryptUpdate can be called multiple times if necessary * EVP_EncryptUpdate can be called multiple times if necessary
*/ */
if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)) if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
ciphertext_len = len; ciphertext_len = len;
/* /*
@@ -142,7 +151,10 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
* this stage. * this stage.
*/ */
if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
ciphertext_len += len; ciphertext_len += len;
/* Clean up */ /* Clean up */
@@ -162,7 +174,10 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
/* Create and initialise the context */ /* Create and initialise the context */
if (!(ctx = EVP_CIPHER_CTX_new())) if (!(ctx = EVP_CIPHER_CTX_new()))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
/* /*
* Initialise the decryption operation. IMPORTANT - ensure you use a key * Initialise the decryption operation. IMPORTANT - ensure you use a key
@@ -172,14 +187,20 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
* is 128 bits * is 128 bits
*/ */
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
/* /*
* Provide the message to be decrypted, and obtain the plaintext output. * Provide the message to be decrypted, and obtain the plaintext output.
* EVP_DecryptUpdate can be called multiple times if necessary. * EVP_DecryptUpdate can be called multiple times if necessary.
*/ */
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
plaintext_len = len; plaintext_len = len;
/* /*
@@ -187,7 +208,10 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
* this stage. * this stage.
*/ */
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
{
EVP_CIPHER_CTX_free(ctx);
return -1; return -1;
}
plaintext_len += len; plaintext_len += len;
@@ -312,10 +336,9 @@ unordered_map<string, string> getArguments(int argc, char *argv[])
string getCompletePath(string fileName) string getCompletePath(string fileName)
{ {
#ifdef WINDOWS #ifdef EZ_LIC_DEBUG
return fileName; return fileName;
#else #else
char path[PATH_MAX + 1] = {}; char path[PATH_MAX + 1] = {};
ssize_t length = readlink("/proc/self/exe", path, PATH_MAX); ssize_t length = readlink("/proc/self/exe", path, PATH_MAX);
path[length] = '\0'; path[length] = '\0';
@@ -338,6 +361,33 @@ void appendStringToVector(const std::string &str, std::vector<unsigned char> &ch
} }
} }
uint16_t calculateCRC16(std::vector<char> &charVector)
{
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
uint16_t crc = 0xFFFF; // Initial value
size_t length = charVector.size();
for (size_t i = 0; i < length; i++)
{
crc ^= charVector[i]; // XOR with the current data byte
for (int j = 0; j < 8; j++)
{
if (crc & 0x0001)
{
crc = (crc >> 1) ^ polynomial;
}
else
{
crc = crc >> 1;
}
}
}
return crc;
}
uint16_t calculateCRC16(std::vector<unsigned char> &charVector) uint16_t calculateCRC16(std::vector<unsigned char> &charVector)
{ {
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
@@ -365,6 +415,34 @@ uint16_t calculateCRC16(std::vector<unsigned char> &charVector)
return crc; return crc;
} }
uint16_t calculateCRC16(std::vector<unsigned char> &charVector, int removeCount)
{
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
uint16_t crc = 0xFFFF; // Initial value
size_t length = charVector.size();
length = length - removeCount;
for (size_t i = 0; i < length; i++)
{
crc ^= charVector[i]; // XOR with the current data byte
for (int j = 0; j < 8; j++)
{
if (crc & 0x0001)
{
crc = (crc >> 1) ^ polynomial;
}
else
{
crc = crc >> 1;
}
}
}
return crc;
}
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4) uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
{ {
return static_cast<uint32_t>(byte1) | return static_cast<uint32_t>(byte1) |
@@ -389,7 +467,7 @@ std::vector<unsigned char> joinVectors(const std::vector<unsigned char> &vector1
bool readFile(string fileName, vector<char> &output) bool readFile(string fileName, vector<char> &output)
{ {
std::ifstream file(fileName, std::ios::in | std::ios::binary); std::ifstream file(fileName, std::ios::in | std::ios::binary);
if (file.is_open() != 1) if (file.is_open() != 1)
{ {
return false; return false;
@@ -406,3 +484,5 @@ bool readFile(string fileName, vector<char> &output)
return true; return true;
} }
#endif

View File

@@ -1,11 +1,13 @@
src/common/utils.o: src/common/utils.cpp include/openssl/conf.h \ src/common/utils.o: src/common/utils.cpp include/common/utils.h \
include/openssl/macros.h include/openssl/opensslconf.h \ include/common/licConnector.h include/common/lic_config.h \
include/openssl/configuration.h include/openssl/opensslv.h \ include/openssl/conf.h include/openssl/macros.h \
include/openssl/bio.h include/openssl/e_os2.h include/openssl/crypto.h \ include/openssl/opensslconf.h include/openssl/configuration.h \
include/openssl/safestack.h include/openssl/stack.h \ include/openssl/opensslv.h include/openssl/bio.h include/openssl/e_os2.h \
include/openssl/types.h include/openssl/cryptoerr.h \ include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/symhacks.h include/openssl/cryptoerr_legacy.h \ include/openssl/stack.h include/openssl/types.h \
include/openssl/core.h include/openssl/bioerr.h include/openssl/lhash.h \ include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/openssl/bioerr.h include/openssl/lhash.h \
include/openssl/conferr.h include/openssl/conftypes.h \ include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/ssl.h include/openssl/comp.h include/openssl/comperr.h \ include/openssl/ssl.h include/openssl/comp.h include/openssl/comperr.h \
include/openssl/x509.h include/openssl/buffer.h \ include/openssl/x509.h include/openssl/buffer.h \
@@ -24,5 +26,4 @@ src/common/utils.o: src/common/utils.cpp include/openssl/conf.h \
include/openssl/asyncerr.h include/openssl/ct.h include/openssl/cterr.h \ include/openssl/asyncerr.h include/openssl/ct.h include/openssl/cterr.h \
include/openssl/sslerr.h include/openssl/sslerr_legacy.h \ include/openssl/sslerr.h include/openssl/sslerr_legacy.h \
include/openssl/prov_ssl.h include/openssl/ssl2.h include/openssl/ssl3.h \ include/openssl/prov_ssl.h include/openssl/ssl2.h include/openssl/ssl3.h \
include/openssl/tls1.h include/openssl/dtls1.h include/openssl/srtp.h \ include/openssl/tls1.h include/openssl/dtls1.h include/openssl/srtp.h
include/common/utils.h

Binary file not shown.

View File

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

Binary file not shown.

View File

@@ -13,16 +13,20 @@ LicenceGenerator::LicenceGenerator()
LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string dataFileName) LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string dataFileName)
{ {
if (dataFileName.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: dataFileName"); if (dataFileName.empty())
throw LicenceException((int)GeneralError::ParamMissing, "Missing par: dataFileName");
if (uid.empty() == false) if (uid.empty() == false)
{ {
if (uid.length() < 32) throw LicenceException((int)GeneralError::IvanlidParam, "UID incorrect size");
this->licData.uid = uid; this->licData.uid = uid;
} }
else else
{ {
if (cid.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CID"); if (cid.empty())
if (csd.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CSD"); throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CID");
if (csd.empty())
throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CSD");
} }
this->configFileName = dataFileName; this->configFileName = dataFileName;
@@ -36,56 +40,55 @@ LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string da
bool LicenceGenerator::processInputConfiguration() bool LicenceGenerator::processInputConfiguration()
{ {
string fullFile = getCompletePath(this->configFileName); string fullFile = getCompletePath(this->configFileName);
const int fileNameLength = fullFile.length(); const int fileNameLength = fullFile.length();
char fileName[fileNameLength] = {}; char fileName[fileNameLength] = {};
getCharsFromString(fullFile, fileName, fileNameLength); getCharsFromString(fullFile, fileName, fileNameLength);
#ifdef WINDOWS #ifdef EZ_LIC_DEBUG
pugi::xml_parse_result result = doc.load_file("licData.xml"); pugi::xml_parse_result result = doc.load_file("licData.xml");
#else #else
pugi::xml_parse_result result = doc.load_file(fileName); pugi::xml_parse_result result = doc.load_file(fileName);
#endif #endif
if (result) if (result)
{
const char *dataRootName = doc.child("data") ? "data" : "licence"; // kompatibilita s verzí, která měla ještě root "data"
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
{ {
const char *dataRootName = doc.child("data") ? "data" : "licence"; // kompatibilita s verzí, která měla ještě root "data" throw LicenceException((int)GeneralError::IvanlidParam, "Invalid param: XML VERSION");
}
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION) this->licData.doc = &doc;
{
throw LicenceException((int)GeneralError::IvanlidParam, "Invalid param: XML VERSION");
}
this->licData.doc = &doc; string licType = doc.child(dataRootName).child("licenceType").child_value();
if (!licType.empty())
string licType = doc.child(dataRootName).child("licenceType").child_value(); {
if (!licType.empty()) this->licIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
{
this->licIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
}
else
{
throw LicenceException((int)GeneralError::ParamMissing, "ERROR MISSING licenceType");
}
this->licIdentification.licenceVersion = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]);
this->licIdentification.revision = doc.child(dataRootName).attribute("revision").value()[0];
this->licIdentification.licenceIndex = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->licIdentification.licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]);
this->licIdentification.licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").value()[0]);
string plcType = doc.child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{
this->licIdentification.licPlcType = mapping.licMapPlcType[plcType];
}
} }
else else
{ {
throw LicenceException((int)GeneralError::FileOpenError, "Unable to open the config file."); throw LicenceException((int)GeneralError::ParamMissing, "ERROR MISSING licenceType");
} }
this->licIdentification.licenceVersion = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]);
this->licIdentification.revision = doc.child(dataRootName).attribute("revision").value()[0];
this->licIdentification.licenceIndex = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->licIdentification.licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]);
this->licIdentification.licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").value()[0]);
string plcType = doc.child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{
this->licIdentification.licPlcType = mapping.licMapPlcType[plcType];
}
}
else
{
throw LicenceException((int)GeneralError::FileOpenError, "Unable to open the config file: " + fullFile + "\n");
}
return true; return true;
} }
@@ -118,15 +121,14 @@ void LicenceGenerator::createLicenceELC2()
switch (this->licIdentification.licCompatibility) switch (this->licIdentification.licCompatibility)
{ {
case 1: case 1:
Generator::Licence2 licence = Generator::Licence2(licData.cid,licData.csd,licData.doc); {
licence.createLicence(); Generator::Licence2 licence = Generator::Licence2(licData.cid, licData.csd, licData.doc);
/*
licence.createLicence(); licence.createLicence();
// LicenceELC21 licence = LicenceELC21(this->licData);
// licence.createLicence();
*/
break; break;
} }
default:
throw LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Compatibility not implemented.");
}
} }
void LicenceGenerator::createLicenceELC3() void LicenceGenerator::createLicenceELC3()
@@ -134,10 +136,14 @@ void LicenceGenerator::createLicenceELC3()
switch (this->licIdentification.licCompatibility) switch (this->licIdentification.licCompatibility)
{ {
case 1: case 1:
//LicenceELC31 licence = LicenceELC31(this->licData); {
//licence.createLicence(); Generator::Licence3 licence = Generator::Licence3(licData.uid, licData.doc);
licence.createLicence();
break; break;
} }
default:
throw LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Compatibility not implemented.");
}
} }
LicenceGenerator::~LicenceGenerator() LicenceGenerator::~LicenceGenerator()

View File

@@ -1,8 +1,10 @@
src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \ src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \
include/generator/licenceGenerator.h include/generator/pugixml.hpp \ include/generator/licenceGenerator.h include/common/licenceCommon.h \
include/generator/pugiconfig.hpp include/common/licenceCommon.h \ include/common/licConnector.h include/common/lic_config.h \
include/generator/pugixml.hpp include/generator/pugiconfig.hpp \
include/generator/licGenELC1.h include/common/utils.h \ include/generator/licGenELC1.h include/common/utils.h \
include/common/licenceELC1.h include/common/licenceCommon.h \ include/common/licenceELC1.h include/common/utils.h \
include/common/SDCard.h include/common/SDCard.h \ include/common/licenceCommon.h include/common/SDCard.h \
include/generator/licGenELC2.h include/common/licenceELC2.h \ include/common/SDCard.h include/generator/licGenELC2.h \
include/generator/licGenELC3.h include/generator/pugixml.hpp include/common/licenceELC2.h include/generator/licGenELC3.h \
include/common/licenceELC3.h include/generator/pugixml.hpp

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

@@ -34,7 +34,7 @@ namespace Generator
getCharsFromString(fullFile, fileName, fileNameLength); getCharsFromString(fullFile, fileName, fileNameLength);
pugi::xml_document doc; pugi::xml_document doc;
#ifdef WINDOWS #ifdef EZ_LIC_DEBUG
pugi::xml_parse_result result = doc.load_file("licData.xml"); pugi::xml_parse_result result = doc.load_file("licData.xml");
#else #else
pugi::xml_parse_result result = doc.load_file(fileName); pugi::xml_parse_result result = doc.load_file(fileName);
@@ -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() bool Licence1::createLicence()
{ {
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
@@ -374,7 +186,7 @@ namespace Generator
if (binaryGeneration == BinaryGenerationType::File) if (binaryGeneration == BinaryGenerationType::File)
{ {
#ifdef WINDOWS #ifdef EZ_LIC_DEBUG
char licFileNameToSave[licenseFileName.length()] = {}; char licFileNameToSave[licenseFileName.length()] = {};
getCharsFromString(licenseFileName, licFileNameToSave, licenseFileName.length()); getCharsFromString(licenseFileName, licFileNameToSave, licenseFileName.length());

View File

@@ -1,6 +1,7 @@
src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \ src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \
include/generator/licGenELC1.h include/common/utils.h \ include/generator/licGenELC1.h include/common/utils.h \
include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h include/common/licenceELC1.h \ include/common/licenceCommon.h include/common/licenceELC1.h \
include/common/licenceCommon.h include/common/SDCard.h \ include/common/utils.h include/common/licenceCommon.h \
include/common/SDCard.h include/generator/pugixml.hpp \ include/common/SDCard.h include/common/SDCard.h \
include/generator/pugiconfig.hpp include/generator/pugixml.hpp include/generator/pugiconfig.hpp

Binary file not shown.

View File

@@ -1,3 +1,5 @@
#include "licGenELC2.h" #include "licGenELC2.h"
namespace Generator namespace Generator
@@ -6,22 +8,22 @@ namespace Generator
{ {
} }
Licence2::~Licence2(){} Licence2::~Licence2() {}
Licence2::Licence2(string cid, string csd, pugi::xml_document *xmlDoc)
Licence2::Licence2(string cid, string csd, pugi::xml_document * xmlDoc)
{ {
this->cid = cid; this->cid = cid;
this->csd = csd; this->csd = csd;
this->xmlDoc = xmlDoc; this->xmlDoc = xmlDoc;
if (processInputConfiguration() == false) throw LicenceException((int)GeneralError::LicenceReadError, "Chyba při čtení licence"); if (processInputConfiguration() == false)
throw LicenceException((int)GeneralError::LicenceReadError, "Chyba při čtení licence");
} }
void Licence2::getHeader() void Licence2::getHeader()
{ {
PublicHeader publicHeader; PublicHeader publicHeader;
publicHeader.version = getVersion(7); publicHeader.version = getVersion(lIdentification.revision);
publicHeader.projectDescription = projectDescription; publicHeader.projectDescription = projectDescription;
publicHeader.date = getDate(); publicHeader.date = getDate();
publicHeader.licenceType = lIdentification.licTypeName; publicHeader.licenceType = lIdentification.licTypeName;
@@ -90,195 +92,223 @@ namespace Generator
} }
string Licence2::getVersion(int middleVersion) string Licence2::getVersion(int middleVersion)
{
string result = "";
result.append(to_string(generatorVersion));
result.append(".");
result.append(to_string(middleVersion));
result.append(".");
string tempLicenceCount = "3"; // TODO
result.append(tempLicenceCount);
return result;
}
bool Licence2::processInputConfiguration()
{
const char *dataRootName = "licence";
string licType = xmlDoc->child(dataRootName).child("licenceType").child_value();
if (!licType.empty())
{ {
this->lIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV; string result = "";
this->lIdentification.licTypeName = licType; result.append(to_string(generatorVersion));
} result.append(".");
else result.append(to_string(middleVersion));
{ result.append(".");
errorMessage.code = (int)GeneralError::LicenceMismatch; string tempLicenceCount = "1";
errorMessage.message = "ERROR MISSING licenceType"; result.append(tempLicenceCount);
return false; return result;
} }
this->lIdentification.licenceVersion = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]); bool Licence2::processInputConfiguration()
this->lIdentification.revision = xmlDoc->child(dataRootName).attribute("revision").value()[0];
this->lIdentification.licenceIndex = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->lIdentification.licElcType = (ELCType)atoi(&xmlDoc->child(dataRootName).attribute("elc").value()[0]);
this->lIdentification.licCompatibility = atoi(&xmlDoc->child(dataRootName).attribute("compatibility").value()[0]);
string plcType = xmlDoc->child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{ {
this->lIdentification.licPlcType = mapping.licMapPlcType[plcType]; const char *dataRootName = "licence";
}
this->projectDescription = &xmlDoc->child(dataRootName).child("project").child_value()[0]; string licType = xmlDoc->child(dataRootName).child("licenceType").child_value();
if (!licType.empty())
licBody.licenceIdentHeader.cardSize = 0;
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
licBody.licenceIdentHeader.licenceType = this->lIdentification.licenceVersion;
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
licBody.licenceIdentHeader.serialNumber = 0;
return true;
}
void Licence2::getLicenceItems()
{
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : xmlDoc->child("licence").child("items"))
{
licDataItem item;
item.protoId = atoi(licItemNode.child("protoId").child_value());
item.licCount = atoi(licItemNode.child("dataPointsCount").child_value());
this->licBody.privateContent.dataItems.push_back(item);
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{ {
nodeIndex++; this->lIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
if (nodeIndex == 1) this->lIdentification.licTypeName = licType;
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
} }
else else
{ {
licBody.publicHeader.append("}"); errorMessage.code = (int)GeneralError::LicenceMismatch;
errorMessage.message = "ERROR MISSING licenceType";
return false;
}
this->lIdentification.licenceVersion = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]);
this->lIdentification.revision = atoi(&xmlDoc->child(dataRootName).attribute("revision").value()[0]);
this->lIdentification.licenceIndex = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->lIdentification.licElcType = (ELCType)atoi(&xmlDoc->child(dataRootName).attribute("elc").value()[0]);
this->lIdentification.licCompatibility = atoi(&xmlDoc->child(dataRootName).attribute("compatibility").value()[0]);
string plcType = xmlDoc->child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{
this->lIdentification.licPlcType = mapping.licMapPlcType[plcType];
}
this->projectDescription = &xmlDoc->child(dataRootName).child("project").child_value()[0];
licBody.licenceIdentHeader.cardSize={};
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
licBody.licenceIdentHeader.licenceType = (BYTE)this->lIdentification.licLicenceType;
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
licBody.licenceIdentHeader.serialNumber={};
return true;
}
void Licence2::getLicenceItems()
{
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : xmlDoc->child("licence").child("items"))
{
licDataItem item;
item.protoId = atoi(licItemNode.child("protoId").child_value());
item.licCount = atoi(licItemNode.child("dataPointsCount").child_value());
this->licBody.privateContent.dataItems.push_back(item);
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{
nodeIndex++;
if (nodeIndex == 1)
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
}
else
{
licBody.publicHeader.append("}");
}
} }
} }
}
bool Licence2::createLicence() bool Licence2::createLicence()
{
getLicenceItems();
getHeader();
sdCard = SDCard(this->cid, this->csd);
if (sdCard.isLoaded == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
vector<unsigned char> publicContent;
vector<unsigned char> privateContent;
vector<unsigned char> privateContentEncrypted;
publicContent.push_back(this->licBody.licId.licIdent[0]);
publicContent.push_back(this->licBody.licId.licIdent[1]);
publicContent.push_back(this->licBody.licId.licIdent[2]);
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
publicContent.push_back(this->licBody.licId.licIdent[4]);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
publicContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
publicContent.push_back(this->licBody.privateContent.dataItems.size());
publicContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
appendStringToVector(this->licBody.publicHeader, publicContent);
uint16_t crcPublic = calculateCRC16(publicContent);
publicContent.push_back(crcPublic & 0xFF);
publicContent.push_back((crcPublic >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
privateContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
privateContent.push_back(this->licBody.privateContent.dataItems.size());
privateContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
{ {
privateContent.push_back(dataItem.protoId & 0xFF); getLicenceItems();
privateContent.push_back((dataItem.protoId >> 8) & 0xFF); getHeader();
privateContent.push_back(dataItem.licCount & 0xFF);
privateContent.push_back((dataItem.licCount >> 8) & 0xFF); sdCard = SDCard(this->cid, this->csd);
for (unsigned int i = 0; i < sizeof(dataItem.dummy); i++) if (sdCard.isLoaded == false)
privateContent.push_back(i); throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
vector<unsigned char> publicContent {};
vector<unsigned char> privateContent {};
vector<unsigned char> privateContentEncrypted {};
publicContent.push_back(this->licBody.licId.licIdent[0]);
publicContent.push_back(this->licBody.licId.licIdent[1]);
publicContent.push_back(this->licBody.licId.licIdent[2]);
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
publicContent.push_back(this->licBody.licId.licIdent[4]);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
publicContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
publicContent.push_back(this->licBody.privateContent.dataItems.size());
publicContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
publicContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
appendStringToVector(this->licBody.publicHeader, publicContent);
#ifdef CRCCHECK
cout << "CRC public size: " << publicContent.size() << "\n";
cout << "CRC gen public: " << calculateCRC16(publicContent) << "\n";
#endif
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
privateContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
privateContent.push_back(this->licBody.privateContent.dataItems.size());
privateContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.cardSize & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.cardSize >> 8) & 0xFF);
privateContent.push_back(this->licBody.licenceIdentHeader.serialNumber & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 8) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 16) & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.serialNumber >> 24) & 0xFF);
privateContent.push_back(1);
privateContent.push_back(1);
privateContent.push_back(1);
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
{
privateContent.push_back(dataItem.protoId & 0xFF);
privateContent.push_back((dataItem.protoId >> 8) & 0xFF);
privateContent.push_back((dataItem.protoId >> 16) & 0xFF);
privateContent.push_back((dataItem.protoId >> 24) & 0xFF);
privateContent.push_back(dataItem.licCount & 0xFF);
privateContent.push_back((dataItem.licCount >> 8) & 0xFF);
privateContent.push_back((dataItem.licCount >> 16) & 0xFF);
privateContent.push_back((dataItem.licCount >> 24) & 0xFF);
}
#ifdef CRCCHECK
cout << "CRC private size: " << privateContent.size() << "\n";
cout << "CRC gen private: " << calculateCRC16(privateContent) << "\n";
#endif
vector<unsigned char> completeVector = joinVectors(publicContent, privateContent);
uint16_t crcComplete = calculateCRC16(completeVector);
#ifdef CRCCHECK
cout << "CRC complete size: " << completeVector.size() << "\n";
cout << "CRC gen complete: " << crcComplete << "\n";
#endif
privateContent.push_back(crcComplete & 0xFF);
privateContent.push_back((crcComplete >> 8) & 0xFF);
// cout << "crc complete: " << crcComplete << "\n";
// cout << "privateContent length: " << privateContent.size() << "\n";
// for (auto x : privateContent) cout << (int)x << "-";
// cout << "\n";
privateContentEncrypted = cryptPrivateContent(privateContent);
// cout << "privateContentEncrypted length: " << privateContentEncrypted.size() << "\n";
// for (auto x : privateContentEncrypted) cout << (int)x << "-";
// cout << "\n";
string licfileName = getLicenceName();
std::ofstream outputFile(licfileName, std::ios::out | std::ios::binary);
// Check if the file is open
if (!outputFile.is_open())
{
throw LicenceException((int)GeneralError::FileOpenError, "Chyba při zakládání souboru licence: " + cid_cdsPath);
}
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
std::copy(privateContentEncrypted.cbegin(), privateContentEncrypted.cend(), std::ostream_iterator<unsigned char>(outputFile));
outputFile.close();
cout << licfileName;
return true;
} }
vector<unsigned char> completeVector = joinVectors(publicContent, privateContent);
licBody.privateContent.crc = calculateCRC16(completeVector);
uint16_t crcComplete = calculateCRC16(completeVector);
privateContent.push_back(crcComplete & 0xFF);
privateContent.push_back((crcComplete >> 8) & 0xFF);
privateContentEncrypted = cryptPrivateContent(privateContent);
string licfileName = getLicenceName();
std::ofstream outputFile(licfileName, std::ios::out | std::ios::binary);
// Check if the file is open
if (!outputFile.is_open())
{
throw LicenceException((int)GeneralError::FileOpenError, "Chyba při zakládání souboru licence: " + cid_cdsPath);
}
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
std::copy(privateContentEncrypted.cbegin(), privateContentEncrypted.cend(), std::ostream_iterator<unsigned char>(outputFile));
outputFile.close();
cout << licfileName;
return true;
}
} }

View File

@@ -1,6 +1,7 @@
src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \ src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \
include/generator/licGenELC2.h include/common/utils.h \ include/generator/licGenELC2.h include/common/utils.h \
include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h include/common/licenceELC2.h \ include/common/licenceCommon.h include/common/licenceELC2.h \
include/common/licenceCommon.h include/common/SDCard.h \ include/common/utils.h include/common/licenceCommon.h \
include/common/SDCard.h include/generator/pugixml.hpp \ include/common/SDCard.h include/common/SDCard.h \
include/generator/pugiconfig.hpp include/generator/pugixml.hpp include/generator/pugiconfig.hpp

Binary file not shown.

View File

@@ -2,7 +2,287 @@
namespace Generator namespace Generator
{ {
Licence3::Licence3()
{
}
Licence3::~Licence3() {}
Licence3::Licence3(string uid, pugi::xml_document *xmlDoc)
{
this->uid = uid;
this->xmlDoc = xmlDoc;
if (processInputConfiguration() == false)
throw LicenceException((int)GeneralError::LicenceReadError, "Chyba při čtení licence");
}
void Licence3::getHeader()
{
PublicHeader publicHeader;
publicHeader.version = getVersion(lIdentification.revision);
publicHeader.projectDescription = projectDescription;
publicHeader.date = getDate();
publicHeader.licenceType = lIdentification.licTypeName;
publicHeader.licenceType += to_string(lIdentification.licenceIndex);
licBody.publicHeader = "";
licBody.publicHeader.append("{\"version\":");
licBody.publicHeader.append(publicHeader.version);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"project\":\"");
licBody.publicHeader.append(publicHeader.projectDescription);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"date\":\"");
licBody.publicHeader.append(publicHeader.date);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"note\":\"poznámka\",");
licBody.publicHeader.append("\"licenceType\":\"");
licBody.publicHeader.append(publicHeader.licenceType);
licBody.publicHeader.append("\",");
licBody.publicHeader.append("\"items\":[");
lIdentification.licItemsCount = std::distance(xmlDoc->child("licence").child("items").begin(), xmlDoc->child("licence").child("items").end());
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : xmlDoc->child("licence").child("items"))
{
licBody.publicHeader.append("{");
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{
nodeIndex++;
if (nodeIndex == 1)
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
}
else
{
licBody.publicHeader.append("}");
}
}
licBody.publicHeader.append("]");
licBody.publicHeader.append("}");
}
string Licence3::getVersion(int middleVersion)
{
string result = "";
result.append(to_string(generatorVersion));
result.append(".");
result.append(to_string(middleVersion));
result.append(".");
string tempLicenceCount = "1";
result.append(tempLicenceCount);
return result;
}
bool Licence3::processInputConfiguration()
{
const char *dataRootName = "licence";
string licType = xmlDoc->child(dataRootName).child("licenceType").child_value();
if (!licType.empty())
{
this->lIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
this->lIdentification.licTypeName = licType;
}
else
{
errorMessage.code = (int)GeneralError::LicenceMismatch;
errorMessage.message = "ERROR MISSING licenceType";
return false;
}
this->lIdentification.licenceVersion = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]);
this->lIdentification.revision = atoi(&xmlDoc->child(dataRootName).attribute("revision").value()[0]);
this->lIdentification.licenceIndex = atoi(&xmlDoc->child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]);
this->lIdentification.licElcType = (ELCType)atoi(&xmlDoc->child(dataRootName).attribute("elc").value()[0]);
this->lIdentification.licCompatibility = atoi(&xmlDoc->child(dataRootName).attribute("compatibility").value()[0]);
string plcType = xmlDoc->child(dataRootName).child("plcType").child_value();
if (!plcType.empty())
{
this->lIdentification.licPlcType = mapping.licMapPlcType[plcType];
}
this->projectDescription = &xmlDoc->child(dataRootName).child("project").child_value()[0];
licBody.licenceIdentHeader.compatibilityVersion = this->lIdentification.licCompatibility;
licBody.licenceIdentHeader.licenceIndex = this->lIdentification.licenceIndex;
licBody.licenceIdentHeader.licenceType = (BYTE)this->lIdentification.licLicenceType;
licBody.licenceIdentHeader.licenceTypeVersion = this->lIdentification.licenceVersion;
return true;
}
void Licence3::getLicenceItems()
{
int nodeIndex = 0;
int itemIndex = 0;
for (pugi::xml_node licItemNode : xmlDoc->child("licence").child("items"))
{
licDataItem item;
item.protoId = atoi(licItemNode.child("protoId").child_value());
item.licCount = atoi(licItemNode.child("dataPointsCount").child_value());
this->licBody.privateContent.dataItems.push_back(item);
nodeIndex = 0;
itemIndex++;
for (pugi::xml_node child : licItemNode.children())
{
nodeIndex++;
if (nodeIndex == 1)
{
licBody.publicHeader.append("\"name\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\",");
continue;
}
if (nodeIndex == 3)
{
licBody.publicHeader.append("\"dataPointsCount\":\"");
licBody.publicHeader.append(child.child_value());
licBody.publicHeader.append("\"");
}
}
if (itemIndex != lIdentification.licItemsCount)
{
licBody.publicHeader.append("},");
}
else
{
licBody.publicHeader.append("}");
}
}
}
bool Licence3::createLicence()
{
getLicenceItems();
getHeader();
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
this->licBody.licenceIdentHeader.publicHeaderLength = this->licBody.publicHeader.length();
vector<unsigned char> publicContent{};
vector<unsigned char> privateContent{};
vector<unsigned char> privateContentEncrypted{};
publicContent.push_back(this->licBody.licId.licIdent[0]);
publicContent.push_back(this->licBody.licId.licIdent[1]);
publicContent.push_back(this->licBody.licId.licIdent[2]);
publicContent.push_back(((char)48 + (int)this->lIdentification.licElcType));
publicContent.push_back(this->licBody.licId.licIdent[4]);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceType);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
publicContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
publicContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
publicContent.push_back(this->licBody.privateContent.dataItems.size());
publicContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
publicContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
appendStringToVector(this->licBody.publicHeader, publicContent);
#ifdef EZ_LIC_DEBUG_SHOW_DETAILS
cout << "CRC public size: " << publicContent.size() << "\n";
cout << "CRC gen public: " << calculateCRC16(publicContent) << "\n";
#endif
privateContent.push_back(this->licBody.licenceIdentHeader.licenceType);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceTypeVersion);
privateContent.push_back(this->licBody.licenceIdentHeader.licenceIndex);
privateContent.push_back(this->licBody.licenceIdentHeader.compatibilityVersion);
privateContent.push_back(this->licBody.privateContent.dataItems.size());
privateContent.push_back(this->licBody.licenceIdentHeader.publicHeaderLength & 0xFF);
privateContent.push_back((this->licBody.licenceIdentHeader.publicHeaderLength >> 8) & 0xFF);
privateContent.push_back(1);
privateContent.push_back(1);
privateContent.push_back(1);
for (licDataItem dataItem : this->licBody.privateContent.dataItems)
{
privateContent.push_back(dataItem.protoId & 0xFF);
privateContent.push_back((dataItem.protoId >> 8) & 0xFF);
privateContent.push_back((dataItem.protoId >> 16) & 0xFF);
privateContent.push_back((dataItem.protoId >> 24) & 0xFF);
privateContent.push_back(dataItem.licCount & 0xFF);
privateContent.push_back((dataItem.licCount >> 8) & 0xFF);
privateContent.push_back((dataItem.licCount >> 16) & 0xFF);
privateContent.push_back((dataItem.licCount >> 24) & 0xFF);
}
#ifdef EZ_LIC_DEBUG_SHOW_DETAILS
cout << "CRC private size: " << privateContent.size() << "\n";
cout << "CRC gen private: " << calculateCRC16(privateContent) << "\n";
#endif
vector<unsigned char> completeVector = joinVectors(publicContent, privateContent);
uint16_t crcComplete = calculateCRC16(completeVector);
#ifdef EZ_LIC_DEBUG_SHOW_DETAILS
cout << "CRC complete size: " << completeVector.size() << "\n";
cout << "CRC gen complete: " << crcComplete << "\n";
#endif
privateContent.push_back(crcComplete & 0xFF);
privateContent.push_back((crcComplete >> 8) & 0xFF);
// cout << "crc complete: " << crcComplete << "\n";
// cout << "privateContent length: " << privateContent.size() << "\n";
// for (auto x : privateContent) cout << (int)x << "-";
// cout << "\n";
privateContentEncrypted = cryptPrivateContent(privateContent);
// cout << "privateContentEncrypted length: " << privateContentEncrypted.size() << "\n";
// for (auto x : privateContentEncrypted) cout << (int)x << "-";
// cout << "\n";
string licfileName = getLicenceName();
std::ofstream outputFile(licfileName, std::ios::out | std::ios::binary);
// Check if the file is open
if (!outputFile.is_open())
{
throw LicenceException((int)GeneralError::FileOpenError, "Chyba při zakládání souboru licence: " + uid_path);
}
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
std::copy(privateContentEncrypted.cbegin(), privateContentEncrypted.cend(), std::ostream_iterator<unsigned char>(outputFile));
outputFile.close();
cout << licfileName;
return true;
}
} }

View File

@@ -1,2 +1,6 @@
src/generator/licGenELC3.o: src/generator/licGenELC3.cpp \ src/generator/licGenELC3.o: src/generator/licGenELC3.cpp \
include/generator/licGenELC3.h include/generator/licGenELC3.h include/common/utils.h \
include/common/licConnector.h include/common/lic_config.h \
include/common/licenceCommon.h include/common/licenceELC3.h \
include/common/utils.h include/common/licenceCommon.h \
include/generator/pugixml.hpp include/generator/pugiconfig.hpp

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,5 @@
#include <licenceReader.h> #include <licenceReader.h>
#ifndef EZ_APPLICATION_LICENCE_DISABLE
ELCType licElcType = ELCType::ELC2; ELCType licElcType = ELCType::ELC2;
LicenceType licLicenceType; LicenceType licLicenceType;
@@ -64,7 +65,7 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
switch (this->licIdentification.licElcType) switch (this->licIdentification.licElcType)
{ {
case ELCType::ELC1: case ELCType::ELC1:
{ // old eoseov {
Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification); Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification);
this->licence1 = &licenceELC1; this->licence1 = &licenceELC1;
licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath; licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath;
@@ -72,7 +73,7 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
try try
{ {
this->licence1->readLicence(&this->licenceInfo); this->licence1->readLicence(&this->licencesInfo);
} }
catch (const LicenceException &ex) catch (const LicenceException &ex)
{ {
@@ -88,11 +89,31 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
this->licence2 = &licenceELC2; this->licence2 = &licenceELC2;
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath; licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
licenceELC2.licenceFilePath = initStructure.licenceFilePath; licenceELC2.licenceFilePath = initStructure.licenceFilePath;
this->licence2->readLicence(&this->licenceInfo); this->licence2->readLicence(&this->licencesInfo);
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->licInfo.licenceFileName = this->licence2->licFileName;
this->licInfo.licenceFilePath = this->licence2->licenceFilePath;
//this->licenceInfo.
//this->sdCardInfo.licenceFileName = this->licence2->licFileName;
break; break;
} }
case ELCType::ELC3: case ELCType::ELC3:
{ {
Reader::Licence3 licenceELC3 = Reader::Licence3(this->licIdentification);
this->licence3 = &licenceELC3;
this->licence3->uid_path = initStructure.uid_filePath;
licenceELC3.licenceFilePath = initStructure.licenceFilePath;
this->licence3->readLicence(&this->licencesInfo);
this->licInfo.licenceFileName = this->licence3->licFileName;
break; break;
} }
default: default:
@@ -113,6 +134,7 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure)
} }
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury /// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
/// vrací false při chybě nebo v případě, ze pro daný protokol není dostatečný počet licenčních bodů
/// @param protocolId /// @param protocolId
/// @param returnItemStructure /// @param returnItemStructure
/// @return /// @return
@@ -127,7 +149,7 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{ {
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnItemStructure); LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnItemStructure);
if (this->licenceInfo.licences.count(1)) // stare eov má natvrdo "id" 1. if (this->licencesInfo.licences.count(1)) // stare eov má natvrdo "id" 1.
resultPtr->isValid = true; resultPtr->isValid = true;
else else
resultPtr->isValid = false; resultPtr->isValid = false;
@@ -140,22 +162,29 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
} }
case ELCType::ELC2: case ELCType::ELC2:
{ {
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita if (!this->licIdentification.licCompatibility || licIdentification.licCompatibility == 1) // defaultní kompatibilita
{ {
LicenceELC2Item *resultPtr = static_cast<LicenceELC2Item *>(returnItemStructure); LicenceELC2Item *resultPtr = static_cast<LicenceELC2Item *>(returnItemStructure);
resultPtr->protocolId = protocolId; // protocolId; resultPtr->protocolId = protocolId;
if (this->licenceInfo.licences.count(protocolId)) if (this->licencesInfo.licences.count(protocolId))
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId); resultPtr->dataPointsCount = this->licencesInfo.licences.at(protocolId);
else else
{
resultPtr->dataPointsCount = 0; resultPtr->dataPointsCount = 0;
error.code = 0;
error.message = "Protokol: " + to_string(protocolId) + " nemá licenční body";
return false;
}
} }
else else
{ {
switch (this->licIdentification.licCompatibility) switch (this->licIdentification.licCompatibility)
{ {
case 1: case 1:
{
// kod pro kompatibilitu 1 // kod pro kompatibilitu 1
break; break;
}
default: default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována."); LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break; break;
@@ -165,6 +194,35 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
} }
case ELCType::ELC3: case ELCType::ELC3:
{ {
cout << "komp: " << this->licIdentification.licCompatibility << "\n";
if (!this->licIdentification.licCompatibility || licIdentification.licCompatibility == 1) // defaultní kompatibilita
{
LicenceELC3Item *resultPtr = static_cast<LicenceELC3Item *>(returnItemStructure);
resultPtr->protocolId = protocolId;
if (this->licencesInfo.licences.count(protocolId))
resultPtr->dataPointsCount = this->licencesInfo.licences.at(protocolId);
else
{
resultPtr->dataPointsCount = 0;
error.code = 0;
error.message = "Protokol: " + to_string(protocolId) + " nemá licenční body";
return false;
}
}
else
{
switch (this->licIdentification.licCompatibility)
{
case 1:
{
// kod pro kompatibilitu 1
break;
}
default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break;
}
}
break; break;
} }
default: default:
@@ -200,7 +258,7 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
{ {
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnStructure); LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnStructure);
if (this->licenceInfo.licences.count(1)) // starý EOS má natvrdo "id" 1 if (this->licencesInfo.licences.count(1)) // starý EOS má natvrdo "id" 1
{ {
resultPtr->isValid = true; resultPtr->isValid = true;
} }
@@ -228,7 +286,7 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{ {
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
licenceELC2.readLicence(&this->licenceInfo); licenceELC2.readLicence(&this->licencesInfo);
licenceELC2.getLicenceInfo(returnStructure); licenceELC2.getLicenceInfo(returnStructure);
} }
else else
@@ -263,3 +321,5 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
LicenceReader::~LicenceReader() LicenceReader::~LicenceReader()
{ {
} }
#endif

View File

@@ -1,7 +1,9 @@
src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \ src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \
include/reader/licenceReader.h include/common/utils.h \ include/reader/licenceReader.h include/common/utils.h \
include/common/licConnector.h include/common/lic_config.h \
include/common/SDCard.h include/common/utils.h \
include/reader/licReaderELC1.h include/common/licenceCommon.h \ include/reader/licReaderELC1.h include/common/licenceCommon.h \
include/common/licenceELC1.h include/common/licenceCommon.h \ include/common/licenceELC1.h include/common/licenceCommon.h \
include/common/SDCard.h include/common/SDCard.h \ include/common/SDCard.h include/reader/licReaderELC2.h \
include/reader/licReaderELC2.h include/common/licenceELC2.h \ include/common/licenceELC2.h include/reader/licReaderELC3.h \
include/reader/licReaderELC3.h include/common/licenceELC3.h

Some files were not shown because too many files have changed in this diff Show More