Oddělení ELC1 generatoru a readeru
This commit is contained in:
@@ -37,9 +37,24 @@ enum class GeneralError
|
|||||||
EncryptError = 10,
|
EncryptError = 10,
|
||||||
DecryptError = 11,
|
DecryptError = 11,
|
||||||
ParamMissing = 12,
|
ParamMissing = 12,
|
||||||
IvanlidParam = 13
|
IvanlidParam = 13,
|
||||||
|
SDCardReadError = 50,
|
||||||
|
LicenceReadError = 51,
|
||||||
|
LicenceSizeMismatch = 52,
|
||||||
|
LicenceSizeCardMismatch = 53,
|
||||||
|
LicenceMismatch = 54,
|
||||||
|
ItemsCountMismatch = 61
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// unordered_map<GeneralError, string> mapGeneralErrors = {
|
||||||
|
// {GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||||
|
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||||
|
// {GeneralError::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
||||||
|
// {GeneralError::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
||||||
|
// {GeneralError::LicenceMismatch, "Nesouhlasí licence."},
|
||||||
|
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
|
||||||
|
// };
|
||||||
|
|
||||||
enum class ELCType
|
enum class ELCType
|
||||||
{
|
{
|
||||||
ELC1 = 1,
|
ELC1 = 1,
|
||||||
@@ -112,24 +127,35 @@ struct LicenceIdentification
|
|||||||
string licenceFilePath = "";
|
string licenceFilePath = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct LicData
|
/// @brief obecná struktura polozky licence, defaultní kompatibilita
|
||||||
// {
|
|
||||||
// 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;
|
|
||||||
// };
|
|
||||||
|
|
||||||
struct LicenceItem
|
struct LicenceItem
|
||||||
{
|
{
|
||||||
int protocolId = -1;
|
int protocolId = -1;
|
||||||
int dataPointsCount = 0;
|
int dataPointsCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 1
|
||||||
|
struct LicenceItemCompatibility1
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 2
|
||||||
|
struct LicenceItemCompatibility2
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 3
|
||||||
|
struct LicenceItemCompatibility3
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct LicenceItem11
|
struct LicenceItem11
|
||||||
{
|
{
|
||||||
int protocolId = -1;
|
int protocolId = -1;
|
||||||
@@ -148,12 +174,34 @@ struct LicenceItem31
|
|||||||
int dataPointsCount = 0;
|
int dataPointsCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief základní struktura, seznam polozek licencí
|
||||||
struct LicenceInfo
|
struct LicenceInfo
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||||
|
struct LicenceInfoCompatibility1
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||||
|
struct LicenceInfoCompatibility2
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
|
||||||
|
struct LicenceInfoCompatibility3
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
struct LicenceInfo11
|
struct LicenceInfo11
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
|
|||||||
267
include/common/licenceELC1.h
Normal file
267
include/common/licenceELC1.h
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
#ifndef PLC_LICENCE1_COMMON_H
|
||||||
|
#define PLC_LICENCE1_COMMON_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
|
||||||
|
/// @brief společná třída pro reader a generátor ELC1
|
||||||
|
class LicenceELC1
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LicenceELC1();
|
||||||
|
LicenceELC1(LicenceIdentification &licIdentification);
|
||||||
|
~LicenceELC1();
|
||||||
|
|
||||||
|
bool getSDData(); // reads SD card
|
||||||
|
string getLicenceName(BYTE licPostfix); // get proper licencename
|
||||||
|
string getLicenceName();
|
||||||
|
void initCrypto();
|
||||||
|
LicenceIdentification lIdentification;
|
||||||
|
|
||||||
|
string cid_cdsPath = "";
|
||||||
|
string licenceFilePath = "";
|
||||||
|
|
||||||
|
Mapping mapping;
|
||||||
|
|
||||||
|
ErrorMessage errorMessage;
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
const BYTE licMaxCount = 100;
|
||||||
|
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
|
||||||
|
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[2] = {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 BYTE cnibblescount11 = 32;
|
||||||
|
|
||||||
|
CryptData cryptData; // structure for encryp
|
||||||
|
CidData sdData; // data loaded from SD card
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -15,32 +15,31 @@ public:
|
|||||||
LicenceELC2(LicenceIdentification &licIdentification);
|
LicenceELC2(LicenceIdentification &licIdentification);
|
||||||
~LicenceELC2();
|
~LicenceELC2();
|
||||||
|
|
||||||
string getLicenceName();
|
|
||||||
string cid_cdsPath = "";
|
string cid_cdsPath = "";
|
||||||
string licenceFilePath = "";
|
string licenceFilePath = "";
|
||||||
|
|
||||||
|
Mapping mapping;
|
||||||
|
|
||||||
ErrorMessage errorMessage;
|
ErrorMessage errorMessage;
|
||||||
|
|
||||||
|
|
||||||
enum class Error
|
// enum class Error
|
||||||
{
|
// {
|
||||||
SDCardReadError = 50,
|
// SDCardReadError = 50,
|
||||||
LicenceReadError = 51,
|
// LicenceReadError = 51,
|
||||||
LicenceSizeMismatch = 52,
|
// LicenceSizeMismatch = 52,
|
||||||
LicenceSizeCardMismatch = 53,
|
// LicenceSizeCardMismatch = 53,
|
||||||
LicenceMismatch = 54,
|
// LicenceMismatch = 54,
|
||||||
ItemsCountMismatch = 61
|
// ItemsCountMismatch = 61
|
||||||
};
|
// };
|
||||||
|
|
||||||
unordered_map<Error, string> mapErrors = {
|
// unordered_map<Error, string> mapErrors = {
|
||||||
{Error::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
// {Error::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||||
{Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
// {Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||||
{Error::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
// {Error::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
||||||
{Error::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
// {Error::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
||||||
{Error::LicenceMismatch, "Nesouhlasí licence."},
|
// {Error::LicenceMismatch, "Nesouhlasí licence."},
|
||||||
{Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
// {Error::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||||
};
|
// };
|
||||||
|
|
||||||
struct LicenceId
|
struct LicenceId
|
||||||
{
|
{
|
||||||
@@ -98,6 +97,7 @@ public:
|
|||||||
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();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
|||||||
string convertToString(char* a, int size);
|
string convertToString(char* a, int size);
|
||||||
string base64_encode_ai(const std::string &input);
|
string base64_encode_ai(const std::string &input);
|
||||||
unordered_map<string, string> getArguments(int argc, char *argv[]);
|
unordered_map<string, string> getArguments(int argc, char *argv[]);
|
||||||
unordered_map<string, const char*> mapArguments(int argc, char *argv[]);
|
|
||||||
char* getCharArray(string source);
|
char* getCharArray(string source);
|
||||||
void getCharsFromString1(string source, char *charArray);
|
void getCharsFromString1(string source, char *charArray);
|
||||||
void getCharsFromString(string& source, char *charArray, size_t length);
|
void getCharsFromString(string& source, char *charArray, size_t length);
|
||||||
|
|||||||
@@ -1,9 +1,38 @@
|
|||||||
#ifndef ELC1_GENERATOR__H
|
#ifndef ELC1_GENERATOR__H
|
||||||
#define ELC1_GENERATOR__H
|
#define ELC1_GENERATOR__H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "licenceELC1.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
namespace Generator
|
namespace Generator
|
||||||
{
|
{
|
||||||
|
class Licence1 : public LicenceELC1
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Licence1();
|
||||||
|
Licence1(string cid, string csd, string dataFileName);
|
||||||
|
~Licence1();
|
||||||
|
|
||||||
|
pugi::xml_document *xmlDoc;
|
||||||
|
string projectDescription = "";
|
||||||
|
string stationName; // name of station
|
||||||
|
string distributor;
|
||||||
|
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
|
||||||
|
|
||||||
|
void processConfigFile(string &dataFileName); // process data from config file
|
||||||
|
bool createLicence(); // create licence for EOV_OSV
|
||||||
|
LicenceIdentification lIdentification;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,9 +1,38 @@
|
|||||||
#ifndef ELC2_GENERATOR__H
|
#ifndef ELC2_GENERATOR_H
|
||||||
#define ELC2_GENERATOR__H
|
#define ELC2_GENERATOR_H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "licenceELC2.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace Generator
|
namespace Generator
|
||||||
{
|
{
|
||||||
|
class Licence2 : public LicenceELC2
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
Licence2();
|
||||||
|
Licence2(string cid, string csd, pugi::xml_document * xmlDoc);
|
||||||
|
~Licence2();
|
||||||
|
|
||||||
|
string cid = "";
|
||||||
|
string csd = "";
|
||||||
|
pugi::xml_document *xmlDoc;
|
||||||
|
string projectDescription = "";
|
||||||
|
|
||||||
|
|
||||||
|
bool createLicence();
|
||||||
|
void getHeader();
|
||||||
|
string getVersion(int middleVersion);
|
||||||
|
bool processInputConfiguration();
|
||||||
|
void getLicenceItems();
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3,13 +3,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <wchar.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <map>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "pugixml.hpp"
|
#include "pugixml.hpp"
|
||||||
#include "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
@@ -47,6 +41,8 @@ public:
|
|||||||
LicenceELC11 *licence11;
|
LicenceELC11 *licence11;
|
||||||
LicenceELC21 *licence21;
|
LicenceELC21 *licence21;
|
||||||
LicenceELC31 *licence31;
|
LicenceELC31 *licence31;
|
||||||
|
Mapping mapping;
|
||||||
|
|
||||||
|
|
||||||
LicenceGenerator();
|
LicenceGenerator();
|
||||||
~LicenceGenerator();
|
~LicenceGenerator();
|
||||||
@@ -54,8 +50,6 @@ public:
|
|||||||
|
|
||||||
void createLicenceFile();
|
void createLicenceFile();
|
||||||
|
|
||||||
int getDataPointsCount(int protocolId);
|
|
||||||
|
|
||||||
|
|
||||||
LicenceInfoGeneral licenceInfo;
|
LicenceInfoGeneral licenceInfo;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ELC2_READER__H
|
#ifndef ELC2_READER_H
|
||||||
#define ELC2_READER__H
|
#define ELC2_READER_H
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
@@ -20,14 +20,12 @@ namespace Reader
|
|||||||
~Licence2();
|
~Licence2();
|
||||||
Licence2(LicenceIdentification &licIdentification);
|
Licence2(LicenceIdentification &licIdentification);
|
||||||
|
|
||||||
|
|
||||||
bool readLicence(LicenceInfoGeneral *licences);
|
bool readLicence(LicenceInfoGeneral *licences);
|
||||||
|
|
||||||
int getDataPointsCount(int protocolId);
|
int getDataPointsCount(int protocolId);
|
||||||
bool getLicenceInfo(void *ptr);
|
bool getLicenceInfo(void *ptr);
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||||
|
void getLicenceItems();
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
output/_orig_ezlic_eovosv0_cbheemcjsii.lic
Normal file
BIN
output/_orig_ezlic_eovosv0_cbheemcjsii.lic
Normal file
Binary file not shown.
BIN
output/ezlic_eovosv0_cbheemcjsii.lic
Normal file
BIN
output/ezlic_eovosv0_cbheemcjsii.lic
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
<?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="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>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<name>Položka licence 4</name>
|
<name>Položka licence 4</name>
|
||||||
<protoId>555</protoId>
|
<protoId>555</protoId>
|
||||||
<dataPointsCount>1999</dataPointsCount>
|
<dataPointsCount>666</dataPointsCount>
|
||||||
</item>
|
</item>
|
||||||
</items>
|
</items>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "licenceGenerator.h"
|
#include "licenceGenerator.h"
|
||||||
#include "licenceReader.h"
|
|
||||||
|
|
||||||
/// @brief hlavní funkce
|
/// @brief hlavní funkce
|
||||||
/// @param argc
|
/// @param argc
|
||||||
@@ -16,9 +15,15 @@ int main(int argc, char *argv[])
|
|||||||
generatorOld.createLicenceFile();
|
generatorOld.createLicenceFile();
|
||||||
return SUCCES;
|
return SUCCES;
|
||||||
}
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
cout << "error: " << ex.getErrorMessage();
|
||||||
|
system("pause");
|
||||||
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
cerr << "Obecná chyba\n";
|
cerr << "Obecná chyba\n";
|
||||||
|
system("pause");
|
||||||
}
|
}
|
||||||
|
|
||||||
system("pause");
|
system("pause");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv parametry pro generování licence
|
/// @param argv parametry pro generování licence
|
||||||
/// @return
|
/// @return
|
||||||
int mainno()
|
int main5()
|
||||||
{
|
{
|
||||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||||
// try
|
// try
|
||||||
|
|||||||
Binary file not shown.
37
src/common/licData.xml
Normal file
37
src/common/licData.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
|
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
||||||
|
<plcType>WAGO</plcType>
|
||||||
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
|
<station>eov.ceskatrebova.ddts.cz</station>
|
||||||
|
<distributor>eov2</distributor>
|
||||||
|
<project>Projekt XXX stanice YYY</project>
|
||||||
|
<items>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 1</name>
|
||||||
|
<protoId>111</protoId>
|
||||||
|
<dataPointsCount>100</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 2</name>
|
||||||
|
<protoId>222</protoId>
|
||||||
|
<dataPointsCount>200</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>333</protoId>
|
||||||
|
<dataPointsCount>300</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>444</protoId>
|
||||||
|
<dataPointsCount>1600</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 4</name>
|
||||||
|
<protoId>555</protoId>
|
||||||
|
<dataPointsCount>1999</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
</items>
|
||||||
|
|
||||||
|
</licence>
|
||||||
229
src/common/licenceELC1.cpp
Normal file
229
src/common/licenceELC1.cpp
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
#include "licenceELC1.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#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 cnibblescount1 = 32;
|
||||||
|
std::string cSDMonthStr1[] = {"-", "I.", "II.", "III.", "IV.", "V.", "VI.", "VII.", "VIII.", "IX.", "X.", "XI.", "XII.", "-", "-", "-"};
|
||||||
|
BYTE cHexNibble_to_No1[] = {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";
|
||||||
|
|
||||||
|
LicenceELC1::LicenceELC1() {}
|
||||||
|
|
||||||
|
LicenceELC1::~LicenceELC1() {}
|
||||||
|
|
||||||
|
LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentification(licIdentification)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LicenceELC1::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_No1[this->sdData.CID_nibble[2 * i]] << 4 | cHexNibble_to_No1[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_No1[this->sdData.CID[16]];
|
||||||
|
this->sdData.productRevision_sw = cHexNibble_to_No1[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_No1[this->sdData.CID_nibble[27]] * 10 + cHexNibble_to_No1[this->sdData.CID_nibble[28]] + 2000;
|
||||||
|
this->sdData.manufacturerDate_month = cHexNibble_to_No1[this->sdData.CID_nibble[29]];
|
||||||
|
string date = cSDMonthStr1[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_No1[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No1[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];
|
||||||
|
|
||||||
|
return (int)this->sdData.CID[15] == (int)((sdCrc << 1) | 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LicenceELC1::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 LicenceELC1::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 LicenceELC1::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;
|
||||||
|
}
|
||||||
3
src/common/licenceELC1.d
Normal file
3
src/common/licenceELC1.d
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
src/common/licenceELC1.o: src/common/licenceELC1.cpp \
|
||||||
|
include/common/licenceELC1.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/common/utils.h
|
||||||
BIN
src/common/licenceELC1.o
Normal file
BIN
src/common/licenceELC1.o
Normal file
Binary file not shown.
Binary file not shown.
@@ -47,11 +47,9 @@ bool LicenceGenerator::processInputConfiguration()
|
|||||||
#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"
|
const char *dataRootName = doc.child("data") ? "data" : "licence"; // kompatibilita s verzí, která měla ještě root "data"
|
||||||
Mapping mapping;
|
|
||||||
|
|
||||||
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
|
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
|
||||||
{
|
{
|
||||||
@@ -87,7 +85,6 @@ bool LicenceGenerator::processInputConfiguration()
|
|||||||
{
|
{
|
||||||
throw LicenceException((int)GeneralError::FileOpenError, "Unable to open the config file.");
|
throw LicenceException((int)GeneralError::FileOpenError, "Unable to open the config file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -112,8 +109,8 @@ void LicenceGenerator::createLicenceFile()
|
|||||||
|
|
||||||
void LicenceGenerator::createLicenceELC1() // přejmenvat na ELC1
|
void LicenceGenerator::createLicenceELC1() // přejmenvat na ELC1
|
||||||
{
|
{
|
||||||
LicenceELC11 plcWriteLicence = LicenceELC11(this->licData.cid, this->licData.csd, "file", this->configFileName);
|
Generator::Licence1 licence = Generator::Licence1(this->licData.cid, this->licData.csd, this->configFileName);
|
||||||
plcWriteLicence.createLicence();
|
licence.createLicence();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicenceGenerator::createLicenceELC2()
|
void LicenceGenerator::createLicenceELC2()
|
||||||
@@ -121,8 +118,13 @@ 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();
|
||||||
|
/*
|
||||||
|
licence.createLicence();
|
||||||
// LicenceELC21 licence = LicenceELC21(this->licData);
|
// LicenceELC21 licence = LicenceELC21(this->licData);
|
||||||
// licence.createLicence();
|
// licence.createLicence();
|
||||||
|
*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \
|
|||||||
include/licenceELC11.h include/common/SDCard.h include/licenceELC21.h \
|
include/licenceELC11.h include/common/SDCard.h include/licenceELC21.h \
|
||||||
include/common/utils.h include/generator/pugixml.hpp \
|
include/common/utils.h include/generator/pugixml.hpp \
|
||||||
include/licenceELC31.h include/generator/licGenELC1.h \
|
include/licenceELC31.h include/generator/licGenELC1.h \
|
||||||
include/generator/licGenELC2.h include/generator/licGenELC3.h
|
include/common/licenceELC1.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/generator/licGenELC2.h \
|
||||||
|
include/common/licenceELC2.h include/generator/licGenELC3.h
|
||||||
|
|||||||
Binary file not shown.
37
src/generator/licData.xml
Normal file
37
src/generator/licData.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
|
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
||||||
|
<plcType>WAGO</plcType>
|
||||||
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
|
<station>eov.ceskatrebova.ddts.cz</station>
|
||||||
|
<distributor>eov2</distributor>
|
||||||
|
<project>Projekt XXX stanice YYY</project>
|
||||||
|
<items>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 1</name>
|
||||||
|
<protoId>111</protoId>
|
||||||
|
<dataPointsCount>100</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 2</name>
|
||||||
|
<protoId>222</protoId>
|
||||||
|
<dataPointsCount>200</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>333</protoId>
|
||||||
|
<dataPointsCount>300</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>444</protoId>
|
||||||
|
<dataPointsCount>1600</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 4</name>
|
||||||
|
<protoId>555</protoId>
|
||||||
|
<dataPointsCount>1999</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
</items>
|
||||||
|
|
||||||
|
</licence>
|
||||||
@@ -1,6 +1,428 @@
|
|||||||
#include "licGenELC1.h"
|
#include "licGenELC1.h"
|
||||||
|
#define CID_LENGTH 32
|
||||||
|
#define CSD_LENGTH 32
|
||||||
|
|
||||||
namespace Generator
|
namespace Generator
|
||||||
{
|
{
|
||||||
|
Licence1::Licence1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Licence1::~Licence1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Licence1::Licence1(string cisArg, string csdArg, 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);
|
||||||
|
|
||||||
|
this->binaryGeneration = BinaryGenerationType::File;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Licence1::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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool Licence1::createLicenceOld()
|
||||||
|
// {
|
||||||
|
// if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||||
|
// initCrypto();
|
||||||
|
|
||||||
|
// // promenne pro praci se soubory a adresari
|
||||||
|
// LicenceDataMainELC dataMainToFileELC1{}; //: tEz_LicenceDataMainELC1; hlavicka urcena pro zapis do souboru - typ ELC1
|
||||||
|
// LicenceData dataToFile{}; // tEz_LicenceData_10_10; // data urcena pro sifrovani a zapis do soubotu - verze => hlavicka: 1.0, data: 1.0
|
||||||
|
|
||||||
|
// // pomocne promenne
|
||||||
|
// string licencePostfix; //: STRING; pomocna promenna pro kontrolu postfixu
|
||||||
|
// string mainLicDescription; //: STRING(79); globalni pojmenovani licence v nesifrovane casti licence
|
||||||
|
|
||||||
|
// USINT generation = 2; //: USINT; verze SW pro licenceřř
|
||||||
|
|
||||||
|
// PlcData plcData;
|
||||||
|
// plcData.licenceName = "Licence";
|
||||||
|
// plcData.licenceType = "1";
|
||||||
|
// plcData.station = stationName;
|
||||||
|
// plcData.distributor = distributor;
|
||||||
|
|
||||||
|
// LicenceSourceData licSourceData;
|
||||||
|
|
||||||
|
// if (plcData.licenceType == "EOV" || plcData.licenceType == to_string((int)PlcLicenceType::LicenceEov))
|
||||||
|
// {
|
||||||
|
// licSourceData.licType = 0x1AA2;
|
||||||
|
// licSourceData.licPostfix = 0;
|
||||||
|
// getCharsFromString(plcData.station, licSourceData.licDescription1);
|
||||||
|
// getCharsFromString(plcData.station, dataToFile.header.licDescription1);
|
||||||
|
// getCharsFromString(plcData.distributor, licSourceData.licDescription2);
|
||||||
|
// getCharsFromString(plcData.distributor, dataToFile.header.licDescription2);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// LicenceIdent licIdent{};
|
||||||
|
// licIdent.licPrefixType = licSourceData.licType >> 12;
|
||||||
|
// licIdent.licHeaderType = licSourceData.licType >> 8 & 0x000F;
|
||||||
|
// licIdent.licDataType = licSourceData.licType >> 4 & 0x000F;
|
||||||
|
// licIdent.licSubType = licIdent.licHeaderType << 8 | licIdent.licHeaderType;
|
||||||
|
// licIdent.licIDType = licSourceData.licType & 0x000F;
|
||||||
|
|
||||||
|
// if (licSourceData.licPostfix > 9)
|
||||||
|
// licSourceData.licPostfix = 0;
|
||||||
|
// licencePostfix = to_string(licSourceData.licPostfix);
|
||||||
|
|
||||||
|
// string licenseFileName = getLicenceName(0);
|
||||||
|
// licSourceData.licPostfixIdent = right(licencePostfix, 1);
|
||||||
|
|
||||||
|
// if (licIdent.licHeaderType == cEzLic_p78ou3_HeaderType_10)
|
||||||
|
// {
|
||||||
|
// if (licIdent.licDataType == cEzLic_p78ou3_DataType_10)
|
||||||
|
// {
|
||||||
|
// dataToFile.id.version = 10;
|
||||||
|
// dataToFile.id.cardSize = this->sdData.cardSize;
|
||||||
|
|
||||||
|
// switch (licIdent.licIDType)
|
||||||
|
// {
|
||||||
|
// case 1://cEzLic_p78ou3_IDType_DDTS:
|
||||||
|
// mainLicDescription = "ddts ";
|
||||||
|
// break;
|
||||||
|
// case 2: //cEzLic_p78ou3_IDType_EOVOSV:
|
||||||
|
// mainLicDescription = "eov, osv ";
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// mainLicDescription = "neznama app ";
|
||||||
|
// }
|
||||||
|
|
||||||
|
// mainLicDescription += licSourceData.licPostfixIdent;
|
||||||
|
// mainLicDescription += " => ";
|
||||||
|
|
||||||
|
// dataToFile.header.licVersion = 10;
|
||||||
|
// dataToFile.header.licType = licIdent.licIDType;
|
||||||
|
// dataToFile.header.licDate = getLicDate(); // 1692230400; //getLicDate(); //1692144000;// getLicDate();
|
||||||
|
// mainLicDescription += dataToFile.header.licDescription1;
|
||||||
|
// mainLicDescription += " [";
|
||||||
|
// mainLicDescription += dataToFile.header.licDescription2;
|
||||||
|
// mainLicDescription += "]";
|
||||||
|
|
||||||
|
// if (licIdent.licIDType == cEzLic_p78ou3_IDType_EOVOSV)
|
||||||
|
// {
|
||||||
|
// if (generation == 1) // stará verze
|
||||||
|
// {
|
||||||
|
// dataToFile.header.licCount = 1;
|
||||||
|
// dataToFile.items[0].licCount = 65535;
|
||||||
|
// dataToFile.items[0].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1;
|
||||||
|
// dataToFile.items[0].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// dataToFile.header.licCount = 1;
|
||||||
|
// dataToFile.items[1].licCount = 65535; // 65535;
|
||||||
|
// dataToFile.items[1].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1;
|
||||||
|
// dataToFile.items[1].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// unsigned char encrypted[10000] = {};
|
||||||
|
// const int s = sizeof(dataToFile);
|
||||||
|
// unsigned char byteArray[s] = {};
|
||||||
|
// memcpy(byteArray, &dataToFile, sizeof(dataToFile));
|
||||||
|
|
||||||
|
// dataToFile.crc = calculateCRC16(byteArray, s - sizeof(dataToFile.crc)); // 47535 | 884:38382
|
||||||
|
|
||||||
|
// memcpy(byteArray, &dataToFile, sizeof(dataToFile));
|
||||||
|
|
||||||
|
// int finalEncryptedLength = encrypt(byteArray, sizeof(dataToFile), this->cryptData.aesKey, this->cryptData.aesInitVector, encrypted);
|
||||||
|
|
||||||
|
// if (licIdent.licPrefixType == cEzLic_p78ou3_LicPrefixType_ELC1) // typ1 = pouze zasifrovani dat
|
||||||
|
// {
|
||||||
|
// dataMainToFileELC1.prefix = 0x31434C45;
|
||||||
|
// getCharsFromString(mainLicDescription, dataMainToFileELC1.licHeader.description);
|
||||||
|
// dataMainToFileELC1.licHeader.sizeData = finalEncryptedLength; // sizeof(dataToFile); // 884;
|
||||||
|
// dataMainToFileELC1.licHeader.licType = licIdent.licIDType;
|
||||||
|
// dataMainToFileELC1.licHeader.licSubType = licIdent.licHeaderType << 8 | licIdent.licDataType;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const int dataMainLength = sizeof(dataMainToFileELC1);
|
||||||
|
// const int dataToFileLength = sizeof(dataToFile);
|
||||||
|
// const int totalEncryptedLength = dataMainLength + finalEncryptedLength;
|
||||||
|
|
||||||
|
// unsigned char bdataMainToFileELC1[dataMainLength] = {};
|
||||||
|
// memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength);
|
||||||
|
|
||||||
|
// unsigned char bdataToFile[dataToFileLength] = {};
|
||||||
|
// memcpy(bdataToFile, &dataToFile, dataToFileLength);
|
||||||
|
// unsigned char totalEncryptedArray[totalEncryptedLength] = {};
|
||||||
|
|
||||||
|
// for (int i = 0; i < dataMainLength; i++)
|
||||||
|
// totalEncryptedArray[i] = bdataMainToFileELC1[i];
|
||||||
|
// for (int i = 0; i < finalEncryptedLength; i++)
|
||||||
|
// totalEncryptedArray[i + dataMainLength] = encrypted[i];
|
||||||
|
|
||||||
|
// string fullFile = getCompletePath(licenseFileName);
|
||||||
|
|
||||||
|
// if (binaryGeneration == BinaryGenerationType::File)
|
||||||
|
// {
|
||||||
|
// #ifdef WINDOWS
|
||||||
|
|
||||||
|
// char licFileNameToSave[licenseFileName.length()] = {};
|
||||||
|
// getCharsFromString(licenseFileName, licFileNameToSave, licenseFileName.length());
|
||||||
|
|
||||||
|
// FILE *fileLicence = fopen(licFileNameToSave, "wb");
|
||||||
|
// if (fileLicence)
|
||||||
|
// {
|
||||||
|
// fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence);
|
||||||
|
// // printf("License binary saved.\n");
|
||||||
|
// fclose(fileLicence);
|
||||||
|
// cout << licenseFileName << endl;
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// #else
|
||||||
|
// std::ofstream outputFile(fullFile);
|
||||||
|
// if (outputFile.is_open())
|
||||||
|
// {
|
||||||
|
// outputFile.write(reinterpret_cast<const char *>(totalEncryptedArray), totalEncryptedLength);
|
||||||
|
// outputFile.close();
|
||||||
|
// std::cout << licenseFileName;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// std::cerr << "Unable to open licence file." << std::endl;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// #endif
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// int totalFileSize = sizeof(totalEncryptedArray);
|
||||||
|
// // cout << "data:text/plain;base64,";
|
||||||
|
// cout << "data:application/octet-stream;base64,";
|
||||||
|
|
||||||
|
// char encryptedChars[totalFileSize];
|
||||||
|
|
||||||
|
// for (int i = 0; i < totalFileSize; i++)
|
||||||
|
// encryptedChars[i] = static_cast<signed char>(totalEncryptedArray[i]);
|
||||||
|
|
||||||
|
// string strToBase = convertToString(encryptedChars, totalFileSize);
|
||||||
|
// string base64Coded = base64_encode_ai(strToBase);
|
||||||
|
// cout << base64Coded << endl;
|
||||||
|
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
bool Licence1::createLicence()
|
||||||
|
{
|
||||||
|
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||||
|
initCrypto();
|
||||||
|
|
||||||
|
// promenne pro praci se soubory a adresari
|
||||||
|
LicenceDataMainELC dataMainToFileELC1{};
|
||||||
|
LicenceData dataToFile{};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
licencePostfix = to_string(licSourceData.licPostfix);
|
||||||
|
|
||||||
|
string licenseFileName = getLicenceName(0);
|
||||||
|
licSourceData.licPostfixIdent = right(licencePostfix, 1);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,6 @@
|
|||||||
src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \
|
src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \
|
||||||
include/generator/licGenELC1.h
|
include/generator/licGenELC1.h include/common/utils.h \
|
||||||
|
include/common/licenceCommon.h include/common/licenceELC1.h \
|
||||||
|
include/common/licenceCommon.h include/common/SDCard.h \
|
||||||
|
include/common/SDCard.h include/generator/pugixml.hpp \
|
||||||
|
include/generator/pugiconfig.hpp
|
||||||
|
|||||||
Binary file not shown.
@@ -2,5 +2,283 @@
|
|||||||
|
|
||||||
namespace Generator
|
namespace Generator
|
||||||
{
|
{
|
||||||
|
Licence2::Licence2()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Licence2::~Licence2(){}
|
||||||
|
|
||||||
|
|
||||||
|
Licence2::Licence2(string cid, string csd, pugi::xml_document * xmlDoc)
|
||||||
|
{
|
||||||
|
this->cid = cid;
|
||||||
|
this->csd = csd;
|
||||||
|
|
||||||
|
this->xmlDoc = xmlDoc;
|
||||||
|
if (processInputConfiguration() == false) throw LicenceException((int)GeneralError::LicenceReadError, "Chyba při čtení licence");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Licence2::getHeader()
|
||||||
|
{
|
||||||
|
PublicHeader publicHeader;
|
||||||
|
publicHeader.version = getVersion(7);
|
||||||
|
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 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;
|
||||||
|
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 = 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 = 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++;
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \
|
src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \
|
||||||
include/generator/licGenELC2.h
|
include/generator/licGenELC2.h include/common/utils.h \
|
||||||
|
include/common/licenceCommon.h include/common/licenceELC2.h \
|
||||||
|
include/common/licenceCommon.h include/common/SDCard.h \
|
||||||
|
include/common/SDCard.h include/generator/pugixml.hpp \
|
||||||
|
include/generator/pugiconfig.hpp
|
||||||
|
|||||||
Binary file not shown.
@@ -1,8 +1,37 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<data version="1">
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
<plcType>WAGO</plcType>
|
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
||||||
<licenceType version="1">EOV_OSV</licenceType>
|
<plcType>WAGO</plcType>
|
||||||
<licenceName>Licence pro EOV_OSV</licenceName>
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
<station>ceskatrebova</station>
|
<station>eov.ceskatrebova.ddts.cz</station>
|
||||||
<distributor>RO1</distributor>
|
<distributor>eov2</distributor>
|
||||||
</data>
|
<project>Projekt XXX stanice YYY</project>
|
||||||
|
<items>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 1</name>
|
||||||
|
<protoId>111</protoId>
|
||||||
|
<dataPointsCount>100</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 2</name>
|
||||||
|
<protoId>222</protoId>
|
||||||
|
<dataPointsCount>200</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>333</protoId>
|
||||||
|
<dataPointsCount>300</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>444</protoId>
|
||||||
|
<dataPointsCount>1600</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 4</name>
|
||||||
|
<protoId>555</protoId>
|
||||||
|
<dataPointsCount>1999</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
</items>
|
||||||
|
|
||||||
|
</licence>
|
||||||
Binary file not shown.
37
src/reader/licData.xml
Normal file
37
src/reader/licData.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
|
||||||
|
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
||||||
|
<plcType>WAGO</plcType>
|
||||||
|
<licenceName>Licence pro EOV_OSV</licenceName>
|
||||||
|
<station>eov.ceskatrebova.ddts.cz</station>
|
||||||
|
<distributor>eov2</distributor>
|
||||||
|
<project>Projekt XXX stanice YYY</project>
|
||||||
|
<items>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 1</name>
|
||||||
|
<protoId>111</protoId>
|
||||||
|
<dataPointsCount>100</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 2</name>
|
||||||
|
<protoId>222</protoId>
|
||||||
|
<dataPointsCount>200</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>333</protoId>
|
||||||
|
<dataPointsCount>300</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 3</name>
|
||||||
|
<protoId>444</protoId>
|
||||||
|
<dataPointsCount>1600</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<name>Položka licence 4</name>
|
||||||
|
<protoId>555</protoId>
|
||||||
|
<dataPointsCount>1999</dataPointsCount>
|
||||||
|
</item>
|
||||||
|
</items>
|
||||||
|
|
||||||
|
</licence>
|
||||||
@@ -3,13 +3,9 @@
|
|||||||
namespace Reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
Licence2::Licence2()
|
Licence2::Licence2(){}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Licence2::~Licence2()
|
Licence2::~Licence2(){}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification)
|
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification)
|
||||||
{
|
{
|
||||||
@@ -20,11 +16,9 @@ namespace Reader
|
|||||||
/// @return
|
/// @return
|
||||||
bool Licence2::readLicence(LicenceInfoGeneral *licences)
|
bool Licence2::readLicence(LicenceInfoGeneral *licences)
|
||||||
{
|
{
|
||||||
|
|
||||||
// sdCard = SDCard("9f544930303030300000000b47015423", "400e00325b5900003a0d7f800a40008d");
|
|
||||||
sdCard = SDCard(this->cid_cdsPath);
|
sdCard = SDCard(this->cid_cdsPath);
|
||||||
if (sdCard.isLoaded == false)
|
if (sdCard.isLoaded == false)
|
||||||
throw LicenceException((int)Error::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
throw LicenceException((int)GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu., cesta: " + cid_cdsPath);
|
||||||
|
|
||||||
string licFileName = getLicenceName();
|
string licFileName = getLicenceName();
|
||||||
string licFilePath = this->licenceFilePath + licFileName;
|
string licFilePath = this->licenceFilePath + licFileName;
|
||||||
@@ -78,7 +72,7 @@ namespace Reader
|
|||||||
|
|
||||||
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
||||||
{
|
{
|
||||||
throw LicenceException((int)LicenceELC2::Error::ItemsCountMismatch, mapErrors.at(Error::ItemsCountMismatch));
|
throw LicenceException((int)GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 13;
|
int index = 13;
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user