Compare commits
2 Commits
36a799057c
...
c0b36e9068
| Author | SHA1 | Date | |
|---|---|---|---|
| c0b36e9068 | |||
| a7fc519138 |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -83,7 +83,8 @@
|
|||||||
"numbers": "cpp",
|
"numbers": "cpp",
|
||||||
"span": "cpp",
|
"span": "cpp",
|
||||||
"cinttypes": "cpp",
|
"cinttypes": "cpp",
|
||||||
"variant": "cpp"
|
"variant": "cpp",
|
||||||
|
"climits": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve"
|
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve"
|
||||||
}
|
}
|
||||||
6
Makefile
6
Makefile
@@ -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 -w
|
||||||
|
|
||||||
# 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
|
||||||
@@ -19,10 +19,10 @@ LFLAGS =
|
|||||||
OUTPUT := output
|
OUTPUT := output
|
||||||
|
|
||||||
# define source directory
|
# define source directory
|
||||||
SRC := src
|
SRC := src src/common src/reader src/generator
|
||||||
|
|
||||||
# define include directory
|
# define include directory
|
||||||
INCLUDE := include
|
INCLUDE := include include/common include/reader include/generator
|
||||||
|
|
||||||
# define lib directory
|
# define lib directory
|
||||||
LIB := lib
|
LIB := lib
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ const string cidFilePath = "";
|
|||||||
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 ?
|
||||||
255
include/common/licenceCommon.h
Normal file
255
include/common/licenceCommon.h
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
#ifndef LICENCE_COMMON_H_
|
||||||
|
#define LICENCE_COMMON_H_
|
||||||
|
|
||||||
|
//---------------- společná hlavička pro všechny licence ----------------
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define XML_VERSION 1
|
||||||
|
#define SOFTWARE_VERSION 1
|
||||||
|
#define SUCCES 0;
|
||||||
|
|
||||||
|
const int cidSize = 32;
|
||||||
|
const int csdSize = 32;
|
||||||
|
const int generatorVersion = 1;
|
||||||
|
|
||||||
|
typedef uint8_t BYTE;
|
||||||
|
typedef uint16_t WORD;
|
||||||
|
typedef uint32_t DWORD;
|
||||||
|
typedef uint32_t DATE;
|
||||||
|
|
||||||
|
enum class GeneralError
|
||||||
|
{
|
||||||
|
GeneralError = 1,
|
||||||
|
FileOpenError = 2,
|
||||||
|
FileReadError = 3,
|
||||||
|
FileWriteError = 4,
|
||||||
|
ELCNotImplemented = 5,
|
||||||
|
LicenceTypeNotImplemented = 6,
|
||||||
|
CompatibilityTypeNotImplemented = 7,
|
||||||
|
ELCMismatch = 8,
|
||||||
|
CRCMismatch = 9,
|
||||||
|
EncryptError = 10,
|
||||||
|
DecryptError = 11,
|
||||||
|
ParamMissing = 12,
|
||||||
|
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
|
||||||
|
{
|
||||||
|
ELC1 = 1,
|
||||||
|
ELC2 = 2,
|
||||||
|
ELC3 = 3
|
||||||
|
};
|
||||||
|
enum class ELCSubType
|
||||||
|
{
|
||||||
|
DEFAULT = 1
|
||||||
|
}; // subtype = dataVersion
|
||||||
|
enum class LicenceType
|
||||||
|
{
|
||||||
|
EOS_EOV,
|
||||||
|
DDTS,
|
||||||
|
DRT
|
||||||
|
}; //
|
||||||
|
enum class HeaderType
|
||||||
|
{
|
||||||
|
DEFAULT = 0
|
||||||
|
}; ////subtype = version
|
||||||
|
|
||||||
|
enum class EncryptionType
|
||||||
|
{
|
||||||
|
CID_AES256 = 10,
|
||||||
|
FIX_AES256 = 20
|
||||||
|
};
|
||||||
|
enum class BinaryType
|
||||||
|
{
|
||||||
|
FILE = 1,
|
||||||
|
BASE64 = 2
|
||||||
|
};
|
||||||
|
enum class PlcType
|
||||||
|
{
|
||||||
|
WAGO = 1,
|
||||||
|
TECO = 2
|
||||||
|
};
|
||||||
|
enum class FileNameGenerationType
|
||||||
|
{
|
||||||
|
DEFAULT = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Mapping
|
||||||
|
{
|
||||||
|
std::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}};
|
||||||
|
std::map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ErrorMessage
|
||||||
|
{
|
||||||
|
int code = 0;
|
||||||
|
string message = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceIdentification
|
||||||
|
{
|
||||||
|
ELCType licElcType = ELCType::ELC2;
|
||||||
|
LicenceType licLicenceType;
|
||||||
|
string licTypeName = "";
|
||||||
|
PlcType licPlcType;
|
||||||
|
|
||||||
|
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
|
||||||
|
uint8_t licenceIndex = 0;
|
||||||
|
uint8_t revision;
|
||||||
|
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
||||||
|
|
||||||
|
uint16_t licItemsCount = 0;
|
||||||
|
|
||||||
|
string cid_cds_path = "";
|
||||||
|
string licenceFilePath = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief obecná struktura polozky licence, defaultní kompatibilita
|
||||||
|
struct LicenceItem
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 1
|
||||||
|
struct LicenceItemCompatibility1
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 2
|
||||||
|
struct LicenceItemCompatibility2
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief struktura polozky licence, kompatibilita 3
|
||||||
|
struct LicenceItemCompatibility3
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct LicenceItem11
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceItem21
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceItem31
|
||||||
|
{
|
||||||
|
int protocolId = -1;
|
||||||
|
int dataPointsCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief základní struktura, seznam polozek licencí
|
||||||
|
struct LicenceInfo
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceInfo21
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceInfo31
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceInfoGeneral
|
||||||
|
{
|
||||||
|
int reqDataPointsCount = 0;
|
||||||
|
map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class LicenceException : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LicenceException(int errorCode, const std::string &errorMessage)
|
||||||
|
: errorCode_(errorCode), errorMessage_(errorMessage) {}
|
||||||
|
|
||||||
|
const char *what() const noexcept override
|
||||||
|
{
|
||||||
|
return errorMessage_.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getErrorCode() const
|
||||||
|
{
|
||||||
|
return errorCode_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &getErrorMessage() const
|
||||||
|
{
|
||||||
|
return errorMessage_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int errorCode_;
|
||||||
|
std::string errorMessage_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
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
|
||||||
107
include/common/licenceELC2.h
Normal file
107
include/common/licenceELC2.h
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#ifndef PLC_LICENCE2_COMMON_H
|
||||||
|
#define PLC_LICENCE2_COMMON_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
|
||||||
|
/// @brief společná třída pro pro reader i generator licence typu ELC2
|
||||||
|
class LicenceELC2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LicenceELC2();
|
||||||
|
LicenceELC2(LicenceIdentification &licIdentification);
|
||||||
|
~LicenceELC2();
|
||||||
|
|
||||||
|
string cid_cdsPath = "";
|
||||||
|
string licenceFilePath = "";
|
||||||
|
|
||||||
|
Mapping mapping;
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
LicenceBody licBody;
|
||||||
|
SDCard sdCard;
|
||||||
|
LicenceIdentification lIdentification;
|
||||||
|
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();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -27,7 +27,7 @@ struct DateAndTime {
|
|||||||
|
|
||||||
void generatePause();
|
void generatePause();
|
||||||
std::string right(const std::string& sourceString, size_t numChars);
|
std::string right(const std::string& sourceString, size_t numChars);
|
||||||
void getCharsFromString(string source, char *charArray);
|
void getCharsFromString(const string source, char *charArray);
|
||||||
uint16_t calculateCRC16(const uint8_t* data, size_t length);
|
uint16_t calculateCRC16(const uint8_t* data, size_t length);
|
||||||
WORD getCurrentDateAsCODESYSDate();
|
WORD getCurrentDateAsCODESYSDate();
|
||||||
DWORD getCurrentDateAsCODESYSDateDword();
|
DWORD getCurrentDateAsCODESYSDateDword();
|
||||||
@@ -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);
|
||||||
38
include/generator/licGenELC1.h
Normal file
38
include/generator/licGenELC1.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef ELC1_GENERATOR__H
|
||||||
|
#define ELC1_GENERATOR__H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "licenceELC1.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
|
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
|
||||||
38
include/generator/licGenELC2.h
Normal file
38
include/generator/licGenELC2.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef 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
|
||||||
|
{
|
||||||
|
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
|
||||||
9
include/generator/licGenELC3.h
Normal file
9
include/generator/licGenELC3.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef ELC3_GENERATOR__H
|
||||||
|
#define ELC3_GENERATOR__H
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,24 +3,35 @@
|
|||||||
|
|
||||||
#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 "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
#include "licenceELC11.h"
|
#include "licenceELC11.h"
|
||||||
#include "licenceELC21.h"
|
#include "licenceELC21.h"
|
||||||
#include "licenceELC31.h"
|
#include "licenceELC31.h"
|
||||||
|
|
||||||
|
#include "licGenELC1.h"
|
||||||
|
#include "licGenELC2.h"
|
||||||
|
#include "licGenELC3.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class LicenceGenerator
|
class LicenceGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
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:
|
public:
|
||||||
int elcSwitchType;
|
int elcSwitchType;
|
||||||
string operationErrors = "";
|
string operationErrors = "";
|
||||||
@@ -30,21 +41,19 @@ public:
|
|||||||
LicenceELC11 *licence11;
|
LicenceELC11 *licence11;
|
||||||
LicenceELC21 *licence21;
|
LicenceELC21 *licence21;
|
||||||
LicenceELC31 *licence31;
|
LicenceELC31 *licence31;
|
||||||
|
Mapping mapping;
|
||||||
|
|
||||||
|
|
||||||
LicenceGenerator();
|
LicenceGenerator();
|
||||||
~LicenceGenerator();
|
~LicenceGenerator();
|
||||||
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
|
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
|
||||||
LicenceGenerator(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
|
||||||
|
|
||||||
void createLicenceFile();
|
void createLicenceFile();
|
||||||
void readLicenceFile();
|
|
||||||
|
|
||||||
int getDataPointsCount(int protocolId);
|
|
||||||
bool getLicenceInfo(int protocolId, void *returnStructure);
|
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
|
||||||
|
|
||||||
LicenceInfoGeneral licenceInfo;
|
LicenceInfoGeneral licenceInfo;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LicenceIdentification licIdentification;
|
LicenceIdentification licIdentification;
|
||||||
LicData licData;
|
LicData licData;
|
||||||
@@ -58,9 +67,6 @@ private:
|
|||||||
void createLicenceELC2();
|
void createLicenceELC2();
|
||||||
void createLicenceELC3();
|
void createLicenceELC3();
|
||||||
|
|
||||||
void readLicenceELC1();
|
|
||||||
void readLicenceELC2();
|
|
||||||
void readLicenceELC3();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
#ifndef LICENCE_COMMON_H_
|
|
||||||
#define LICENCE_COMMON_H_
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <map>
|
|
||||||
#include "pugixml.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#define XML_VERSION 1
|
|
||||||
#define SOFTWARE_VERSION 1
|
|
||||||
#define SUCCES 0;
|
|
||||||
|
|
||||||
const int cidSize = 32;
|
|
||||||
const int csdSize = 32;
|
|
||||||
const int generatorVersion = 1;
|
|
||||||
|
|
||||||
enum class GeneralError
|
|
||||||
{
|
|
||||||
GeneralError = 1,
|
|
||||||
FileOpenError = 2,
|
|
||||||
FileReadError = 3,
|
|
||||||
FileWriteError = 4,
|
|
||||||
ELCNotImplemented = 5,
|
|
||||||
LicenceTypeNotImplemented = 6,
|
|
||||||
CompatibilityTypeNotImplemented = 7,
|
|
||||||
ELCMismatch = 8,
|
|
||||||
CRCMismatch = 9,
|
|
||||||
EncryptError = 10,
|
|
||||||
DecryptError = 11
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ELCType
|
|
||||||
{
|
|
||||||
ELC1 = 1,
|
|
||||||
ELC2 = 2,
|
|
||||||
ELC3 = 3
|
|
||||||
};
|
|
||||||
enum class ELCSubType
|
|
||||||
{
|
|
||||||
DEFAULT = 1
|
|
||||||
}; // subtype = dataVersion
|
|
||||||
enum class LicenceType
|
|
||||||
{
|
|
||||||
EOS_EOV,
|
|
||||||
DDTS,
|
|
||||||
DRT
|
|
||||||
}; //
|
|
||||||
enum class HeaderType
|
|
||||||
{
|
|
||||||
DEFAULT = 0
|
|
||||||
}; ////subtype = version
|
|
||||||
|
|
||||||
enum class EncryptionType
|
|
||||||
{
|
|
||||||
CID_AES256 = 10,
|
|
||||||
FIX_AES256 = 20
|
|
||||||
};
|
|
||||||
enum class BinaryType
|
|
||||||
{
|
|
||||||
FILE = 1,
|
|
||||||
BASE64 = 2
|
|
||||||
};
|
|
||||||
enum class PlcType
|
|
||||||
{
|
|
||||||
WAGO = 1,
|
|
||||||
TECO = 2
|
|
||||||
};
|
|
||||||
enum class FileNameGenerationType
|
|
||||||
{
|
|
||||||
DEFAULT = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mapping
|
|
||||||
{
|
|
||||||
std::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}};
|
|
||||||
std::map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ErrorMessage
|
|
||||||
{
|
|
||||||
int code = 0;
|
|
||||||
string message = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceIdentification
|
|
||||||
{
|
|
||||||
ELCType licElcType = ELCType::ELC2;
|
|
||||||
LicenceType licLicenceType;
|
|
||||||
string licTypeName = "";
|
|
||||||
PlcType licPlcType;
|
|
||||||
|
|
||||||
uint8_t licenceVersion = 1; // verze licence, určitě kodování, pojmenování souborů
|
|
||||||
uint8_t licenceIndex = 0;
|
|
||||||
uint8_t revision;
|
|
||||||
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
|
||||||
|
|
||||||
uint16_t licItemsCount = 0;
|
|
||||||
|
|
||||||
string cid_cds_path = "";
|
|
||||||
string licenceFilePath = "";
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceItem11
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceItem21
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceItem31
|
|
||||||
{
|
|
||||||
int protocolId = -1;
|
|
||||||
int dataPointsCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceInfo11
|
|
||||||
{
|
|
||||||
int reqDataPointsCount = 0;
|
|
||||||
map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceInfo21
|
|
||||||
{
|
|
||||||
int reqDataPointsCount = 0;
|
|
||||||
map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceInfo31
|
|
||||||
{
|
|
||||||
int reqDataPointsCount = 0;
|
|
||||||
map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LicenceInfoGeneral
|
|
||||||
{
|
|
||||||
int reqDataPointsCount = 0;
|
|
||||||
map<int, int> licences = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
class LicenceException : public std::exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LicenceException(int errorCode, const std::string &errorMessage)
|
|
||||||
: errorCode_(errorCode), errorMessage_(errorMessage) {}
|
|
||||||
|
|
||||||
const char *what() const noexcept override
|
|
||||||
{
|
|
||||||
return errorMessage_.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
int getErrorCode() const
|
|
||||||
{
|
|
||||||
return errorCode_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string &getErrorMessage() const
|
|
||||||
{
|
|
||||||
return errorMessage_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int errorCode_;
|
|
||||||
std::string errorMessage_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
#include "SDCard.h"
|
#include "SDCard.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -12,8 +13,19 @@ using namespace std;
|
|||||||
class LicenceELC21
|
class LicenceELC21
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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;
|
ErrorMessage errorMessage;
|
||||||
LicenceInfo21 licenceInfo;
|
LicenceInfo21 licenceInfo;
|
||||||
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||||
@@ -21,9 +33,9 @@ public:
|
|||||||
|
|
||||||
LicenceELC21();
|
LicenceELC21();
|
||||||
~LicenceELC21();
|
~LicenceELC21();
|
||||||
LicenceELC21(LicenceIdentification & licIdentification, LicData & icData);
|
LicenceELC21(LicenceIdentification &licIdentification, LicData &licData);
|
||||||
LicenceELC21(LicenceIdentification &licIdentification);
|
LicenceELC21(LicenceIdentification &licIdentification);
|
||||||
LicenceELC21(LicData & icData);
|
LicenceELC21(LicData &licData);
|
||||||
bool createLicence();
|
bool createLicence();
|
||||||
bool readLicence(LicenceInfoGeneral *licences);
|
bool readLicence(LicenceInfoGeneral *licences);
|
||||||
int getDataPointsCount(int protocolId);
|
int getDataPointsCount(int protocolId);
|
||||||
@@ -72,7 +84,7 @@ public:
|
|||||||
{
|
{
|
||||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
WORD protoId = 0; // id protokolu pro ktery je licence
|
||||||
WORD licCount = 0; // pocet datovych bodu licence
|
WORD licCount = 0; // pocet datovych bodu licence
|
||||||
char dummy[64] = {};
|
char dummy[64] = {}; // dummy pro větší velikost licence v případě méně licenčních bodů
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PublicHeader
|
struct PublicHeader
|
||||||
@@ -100,7 +112,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int licItemCount = 0;
|
int licItemCount = 0;
|
||||||
LicenceBody licBody;
|
LicenceBody licBody;
|
||||||
LicenceIdentification lIdentification;
|
LicenceIdentification lIdentification;
|
||||||
@@ -114,7 +125,6 @@ public:
|
|||||||
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();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,11 +6,24 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "licenceCommon.h"
|
#include "licenceCommon.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class LicenceELC31
|
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;
|
LicData lData;
|
||||||
bool processInputConfiguration();
|
bool processInputConfiguration();
|
||||||
LicenceIdentification lIdentification;
|
LicenceIdentification lIdentification;
|
||||||
|
|||||||
9
include/reader/licReaderELC1.h
Normal file
9
include/reader/licReaderELC1.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef ELC1_READER__H
|
||||||
|
#define ELC1_READER__H
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
32
include/reader/licReaderELC2.h
Normal file
32
include/reader/licReaderELC2.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef ELC2_READER_H
|
||||||
|
#define ELC2_READER_H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "licenceELC2.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
class Licence2 : public LicenceELC2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LicenceInfo21 licenceInfo;
|
||||||
|
|
||||||
|
|
||||||
|
Licence2();
|
||||||
|
~Licence2();
|
||||||
|
Licence2(LicenceIdentification &licIdentification);
|
||||||
|
|
||||||
|
bool readLicence(LicenceInfoGeneral *licences);
|
||||||
|
int getDataPointsCount(int protocolId);
|
||||||
|
bool getLicenceInfo(void *ptr);
|
||||||
|
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||||
|
void getLicenceItems();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
9
include/reader/licReaderELC3.h
Normal file
9
include/reader/licReaderELC3.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef ELC3_READER__H
|
||||||
|
#define ELC3_READER__H
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,12 +2,16 @@
|
|||||||
#define LICENCE_READER_H_
|
#define LICENCE_READER_H_
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
// #include "licenceCommon.h"
|
|
||||||
#include "licenceELC11.h"
|
#include "licenceELC11.h"
|
||||||
#include "licenceELC21.h"
|
|
||||||
#include "licenceELC31.h"
|
#include "licenceELC31.h"
|
||||||
|
|
||||||
|
#include "licReaderELC1.h"
|
||||||
|
#include "licReaderELC2.h"
|
||||||
|
#include "licReaderELC3.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Reader;
|
||||||
|
|
||||||
|
|
||||||
struct InitStructure
|
struct InitStructure
|
||||||
{
|
{
|
||||||
@@ -28,18 +32,13 @@ public:
|
|||||||
bool argumentsCorrect = false;
|
bool argumentsCorrect = false;
|
||||||
ErrorMessage error;
|
ErrorMessage error;
|
||||||
LicenceELC11 *licence11;
|
LicenceELC11 *licence11;
|
||||||
LicenceELC21 *licence21;
|
|
||||||
LicenceELC31 *licence31;
|
LicenceELC31 *licence31;
|
||||||
|
Licence2 *licence2;
|
||||||
|
|
||||||
LicenceReader();
|
LicenceReader();
|
||||||
~LicenceReader();
|
~LicenceReader();
|
||||||
bool init(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
|
||||||
bool init(int elcType, InitStructure &initStructure);
|
bool init(int elcType, InitStructure &initStructure);
|
||||||
bool initread(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
|
||||||
bool initread(int elcType, InitStructure &initStructure);
|
bool initread(int elcType, InitStructure &initStructure);
|
||||||
|
|
||||||
void readLicenceFile();
|
|
||||||
|
|
||||||
bool getLicenceInfo(void *returnStructure);
|
bool getLicenceInfo(void *returnStructure);
|
||||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||||
|
|
||||||
@@ -47,14 +46,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
LicenceIdentification licIdentification;
|
LicenceIdentification licIdentification;
|
||||||
LicData licData;
|
|
||||||
string configFileName = "";
|
string configFileName = "";
|
||||||
|
|
||||||
void *licence = nullptr;
|
void *licence = nullptr;
|
||||||
|
|
||||||
void readLicenceELC1();
|
|
||||||
void readLicenceELC2();
|
|
||||||
void readLicenceELC3();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
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>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,28 +1,31 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "utils.h"
|
|
||||||
#include "licenceGenerator.h"
|
#include "licenceGenerator.h"
|
||||||
#include "licenceReader.h"
|
|
||||||
#include "licenceCommon.h"
|
|
||||||
|
|
||||||
/// @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 main5(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// 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();
|
||||||
// return SUCCES;
|
return SUCCES;
|
||||||
// }
|
}
|
||||||
// catch (...)
|
catch (const LicenceException &ex)
|
||||||
// {
|
{
|
||||||
// cerr << "Obecná chyba\n";
|
cout << "error: " << ex.getErrorMessage();
|
||||||
// }
|
system("pause");
|
||||||
|
}
|
||||||
// system("pause");
|
catch (...)
|
||||||
|
{
|
||||||
|
cerr << "Obecná chyba\n";
|
||||||
|
system("pause");
|
||||||
|
}
|
||||||
|
|
||||||
|
system("pause");
|
||||||
return SUCCES;
|
return SUCCES;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -484,148 +484,6 @@ bool LicenceELC11::createEosEovLicence()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LicenceELC11::readEosEovLicence(string dataFileName)
|
|
||||||
{
|
|
||||||
BYTE licPostfix = 0;
|
|
||||||
FILE *licenceFile;
|
|
||||||
char ch;
|
|
||||||
|
|
||||||
const int fileNameLength = dataFileName.length();
|
|
||||||
char fileNameCh[fileNameLength] = {};
|
|
||||||
for (unsigned int i = 0; i < dataFileName.length(); i++)
|
|
||||||
fileNameCh[i] = dataFileName[i];
|
|
||||||
|
|
||||||
cout << dataFileName << endl;
|
|
||||||
|
|
||||||
licenceFile = fopen(fileNameCh, "rb"); // read mode
|
|
||||||
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 (licenceFile == nullptr)
|
|
||||||
{
|
|
||||||
perror("Error while opening the file.\n");
|
|
||||||
operationErrors = "Error while opening the file.\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
unsigned char licenceContent[size];
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
ch = fgetc(licenceFile);
|
|
||||||
licenceContent[i] = ch;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(licenceFile);
|
|
||||||
getSDData();
|
|
||||||
|
|
||||||
string licFileName = getLicenceName(licPostfix);
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
unsigned char decrypted[2000] = {};
|
|
||||||
int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted);
|
|
||||||
|
|
||||||
if (sizeof(licEncryptedData) != decrypted_len)
|
|
||||||
{
|
|
||||||
operationErrors = "License size mismatch";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
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.id.cardSize != sdData.cardSize)
|
|
||||||
{
|
|
||||||
operationErrors = "Size card mismatch";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (licEncryptedData.header.licCount > 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (licType == PlcLicenceType::LicenceOther)
|
|
||||||
{
|
|
||||||
// původní stará
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// maxLic := MIN(EzLlic_5rq4_DataFromFile_10_10.header.licCount, cEzLic_p78ou3_licMaxCount); ?
|
|
||||||
int maxLic = min(licEncryptedData.header.licCount, licMaxCount);
|
|
||||||
for (int i = 1; i < maxLic; i++)
|
|
||||||
{
|
|
||||||
if (licEncryptedData.items[i].protoId > 0 || licEncryptedData.items[i].licCount > 0 || licEncryptedData.items[i].data1 > 0)
|
|
||||||
{
|
|
||||||
// EzLlic_5rq4_CheckData.LicId[EzLlic_5rq4_DataFromFile_10_10.items[licId].protoId] := licId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
operationErrors = "Licence items mismatch";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
operationErrors = "Size card info mismatch";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
operationErrors = "Licence mismatch";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
operationErrors = "Licence error";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
operationErrors = "Licence error";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Licence readed: " << size << endl
|
|
||||||
<< ", data: " << licenceHeader.licHeader.description << endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceELC11::readLicence(LicenceInfoGeneral *licences)
|
bool LicenceELC11::readLicence(LicenceInfoGeneral *licences)
|
||||||
{
|
{
|
||||||
sdCard = SDCard(this->cid_cdsPath);
|
sdCard = SDCard(this->cid_cdsPath);
|
||||||
@@ -745,22 +603,4 @@ bool LicenceELC11::readLicence(LicenceInfoGeneral *licences)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool LicenceELC11::readLicence(string dataFileName, string licenceType, string licenceVersion, string cidArg, string csdArg)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// for (unsigned int i = 0; i < cidArg.length(); i++)
|
|
||||||
// this->cid[i] = cidArg[i];
|
|
||||||
// for (unsigned int i = 0; i < csdArg.length(); i++)
|
|
||||||
// this->csd[i] = csdArg[i];
|
|
||||||
// this->dataLicenceType = licenceType;
|
|
||||||
// this->dataLicenceVersion = licenceVersion;
|
|
||||||
|
|
||||||
// if (this->dataLicenceType == eoseovLicenceType)
|
|
||||||
// {
|
|
||||||
// return readEosEovLicence(dataFileName);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
LicenceELC11::~LicenceELC11() {}
|
LicenceELC11::~LicenceELC11() {}
|
||||||
|
|||||||
@@ -1,195 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <licenceGenerator.h>
|
|
||||||
#include "utils.h"
|
|
||||||
#include "pugixml.hpp"
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
LicenceGenerator::LicenceGenerator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string dataFileName)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (dataFileName.empty())
|
|
||||||
throw std::runtime_error("Missing dataFileName par.");
|
|
||||||
|
|
||||||
if (uid.empty() == false)
|
|
||||||
{
|
|
||||||
this->licData.uid = uid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cid.empty())
|
|
||||||
throw std::runtime_error("Missing CID par.");
|
|
||||||
if (csd.empty())
|
|
||||||
throw std::runtime_error("Missing CSD par.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
this->argumentsCorrect = false;
|
|
||||||
std::cerr << "error: " << e.what() << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->configFileName = dataFileName;
|
|
||||||
this->licData.cid = cid;
|
|
||||||
this->licData.csd = csd;
|
|
||||||
|
|
||||||
this->argumentsCorrect = true;
|
|
||||||
|
|
||||||
if (processInputConfiguration() == false)
|
|
||||||
{
|
|
||||||
cerr << "Chyba: " << error.message << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceGenerator::processInputConfiguration()
|
|
||||||
{
|
|
||||||
string fullFile = getCompletePath(this->configFileName);
|
|
||||||
const int fileNameLength = fullFile.length();
|
|
||||||
char fileName[fileNameLength] = {};
|
|
||||||
getCharsFromString(fullFile, fileName, fileNameLength);
|
|
||||||
|
|
||||||
#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"
|
|
||||||
Mapping mapping;
|
|
||||||
|
|
||||||
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
|
|
||||||
{
|
|
||||||
error.code = -1;
|
|
||||||
error.message = "Invalid XML VERSION";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->licData.doc = &doc;
|
|
||||||
|
|
||||||
string licType = doc.child(dataRootName).child("licenceType").child_value();
|
|
||||||
if (!licType.empty())
|
|
||||||
{
|
|
||||||
this->licIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << endl
|
|
||||||
<< " ERROR MISSING licenceType " << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
|
||||||
|
|
||||||
//licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]);
|
|
||||||
//licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").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
|
|
||||||
{
|
|
||||||
std::cerr << "Unable to open the config file." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::createLicenceFile()
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
createLicenceELC1();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC2:
|
|
||||||
createLicenceELC2();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC3:
|
|
||||||
createLicenceELC3();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::readLicenceFile()
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
readLicenceELC1();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC2:
|
|
||||||
readLicenceELC2();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC3:
|
|
||||||
readLicenceELC3();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::createLicenceELC1() // přejmenvat na ELC1
|
|
||||||
{
|
|
||||||
LicenceELC11 plcWriteLicence = LicenceELC11(this->licData.cid, this->licData.csd, "file", this->configFileName);
|
|
||||||
plcWriteLicence.createLicence();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::createLicenceELC2()
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licCompatibility)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licData);
|
|
||||||
licence.createLicence();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::createLicenceELC3()
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licCompatibility)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
LicenceELC31 licence = LicenceELC31(this->licData);
|
|
||||||
licence.createLicence();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::readLicenceELC1()
|
|
||||||
{
|
|
||||||
cout << "reading ELC1" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::readLicenceELC2()
|
|
||||||
{
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceGenerator::readLicenceELC3()
|
|
||||||
{
|
|
||||||
cout << "reading ELC3" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceGenerator::~LicenceGenerator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,454 +0,0 @@
|
|||||||
#include <licenceReader.h>
|
|
||||||
|
|
||||||
ELCType licElcType = ELCType::ELC2;
|
|
||||||
LicenceType licLicenceType;
|
|
||||||
PlcType licPlcType;
|
|
||||||
|
|
||||||
uint8_t licenceVersion = 1; // verze licence, určitě kodování, pojmenování souborů
|
|
||||||
uint8_t licenceIndex = 0;
|
|
||||||
uint8_t revision;
|
|
||||||
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
|
||||||
|
|
||||||
LicenceReader::LicenceReader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// LicenceReader::LicenceReader(string uid, string cid, string csd, string dataFileName)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (dataFileName.empty())
|
|
||||||
// throw std::runtime_error("Missing dataFileName par.");
|
|
||||||
|
|
||||||
// if (uid.empty() == false)
|
|
||||||
// {
|
|
||||||
// this->licData.uid = uid;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (cid.empty())
|
|
||||||
// throw std::runtime_error("Missing CID par.");
|
|
||||||
// if (csd.empty())
|
|
||||||
// throw std::runtime_error("Missing CSD par.");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (const std::exception &e)
|
|
||||||
// {
|
|
||||||
// this->argumentsCorrect = false;
|
|
||||||
// std::cerr << "error: " << e.what() << endl;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this->configFileName = dataFileName;
|
|
||||||
// this->licData.cid = cid;
|
|
||||||
// this->licData.csd = csd;
|
|
||||||
|
|
||||||
// this->argumentsCorrect = true;
|
|
||||||
|
|
||||||
// if (processInputConfiguration() == false)
|
|
||||||
// {
|
|
||||||
// cerr << "Chyba: " << error.message << endl;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// LicenceReader::LicenceReader(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility)
|
|
||||||
// {
|
|
||||||
// this->licIdentification.licElcType = (ELCType)elcType;
|
|
||||||
// this->licIdentification.licLicenceType = (LicenceType)licenceType;
|
|
||||||
// this->licIdentification.licenceVersion = licenceVersion;
|
|
||||||
// this->licIdentification.licenceIndex = licenceIndex;
|
|
||||||
// this->licIdentification.licCompatibility = compatibility;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// @brief inicializace generátoru a načtení licenčních bodů
|
|
||||||
/// @param elcType
|
|
||||||
/// @param licenceType
|
|
||||||
/// @param licenceVersion
|
|
||||||
/// @param licenceIndex
|
|
||||||
/// @param compatibility
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::initread(int elcType, InitStructure &initStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
if (init(elcType, initStructure))
|
|
||||||
{
|
|
||||||
switch (elcSwitchType)
|
|
||||||
{
|
|
||||||
case 11:
|
|
||||||
{ // old eoseov
|
|
||||||
LicenceELC11 licence = LicenceELC11(this->licIdentification);
|
|
||||||
this->licence11 = &licence;
|
|
||||||
licence.cid_cdsPath = initStructure.cid_csd_filePath;
|
|
||||||
licence.licenceFilePath = initStructure.licenceFilePath;;
|
|
||||||
this->licence11->readLicence(&this->licenceInfo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 21:
|
|
||||||
{
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
|
||||||
this->licence21 = &licence;
|
|
||||||
licence.cid_cdsPath = initStructure.cid_csd_filePath;
|
|
||||||
licence.licenceFilePath = initStructure.licenceFilePath;;
|
|
||||||
this->licence21->readLicence(&this->licenceInfo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 31:
|
|
||||||
{
|
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // TODO testy
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceReader::initread(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
if (init(elcType, licenceType, licenceVersion, licenceIndex, compatibility))
|
|
||||||
{
|
|
||||||
switch (elcSwitchType)
|
|
||||||
{
|
|
||||||
case 11:
|
|
||||||
{ // old eoseov
|
|
||||||
LicenceELC11 licence = LicenceELC11(this->licIdentification);
|
|
||||||
licence.readLicence(&this->licenceInfo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 21:
|
|
||||||
{
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
|
||||||
this->licence21 = &licence;
|
|
||||||
this->licence21->readLicence(&this->licenceInfo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 31:
|
|
||||||
{
|
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // TODO testy
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief inicicialize generátoro, pouze vstupní kontrola
|
|
||||||
/// @param elcType
|
|
||||||
/// @param licenceType
|
|
||||||
/// @param licenceVersion
|
|
||||||
/// @param licenceIndex
|
|
||||||
/// @param compatibility
|
|
||||||
/// @return
|
|
||||||
bool LicenceReader::init(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (elcType > 3)
|
|
||||||
{
|
|
||||||
error.code = (int)GeneralError::ELCNotImplemented;
|
|
||||||
error.message = "ELC není implementováno.";
|
|
||||||
throw LicenceException((int)GeneralError::ELCNotImplemented, error.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->licIdentification.licElcType = (ELCType)elcType;
|
|
||||||
this->licIdentification.licLicenceType = (LicenceType)licenceType;
|
|
||||||
this->licIdentification.licenceVersion = licenceVersion;
|
|
||||||
this->licIdentification.licenceIndex = licenceIndex;
|
|
||||||
this->licIdentification.licCompatibility = compatibility;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
return true; // TODO testy
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceReader::init(int elcType, InitStructure &initStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (elcType > 3)
|
|
||||||
{
|
|
||||||
error.code = (int)GeneralError::ELCNotImplemented;
|
|
||||||
error.message = "ELC není implementováno.";
|
|
||||||
throw LicenceException((int)GeneralError::ELCNotImplemented, error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->licIdentification.licElcType = (ELCType)elcType;
|
|
||||||
this->licIdentification.licLicenceType = (LicenceType)initStructure.licenceType;
|
|
||||||
this->licIdentification.licenceVersion = licenceVersion;
|
|
||||||
this->licIdentification.licenceIndex = licenceIndex;
|
|
||||||
this->licIdentification.licCompatibility = initStructure.compatibility;
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
return true; // TODO testy
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool LicenceReader::init(InitStructure &initStructure)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (initStructure.elcType > 3)
|
|
||||||
// {
|
|
||||||
// error.code = (int)GeneralError::ELCNotImplemented;
|
|
||||||
// error.message = "ELC není implementováno.";
|
|
||||||
// throw LicenceException((int)GeneralError::ELCNotImplemented, error.message);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this->licIdentification.licElcType = (ELCType)initStructure.elcType;
|
|
||||||
// this->licIdentification.licLicenceType = (LicenceType)initStructure.licenceType;
|
|
||||||
// this->licIdentification.licenceVersion = licenceVersion;
|
|
||||||
// this->licIdentification.licenceIndex = licenceIndex;
|
|
||||||
// this->licIdentification.licCompatibility = initStructure.compatibility;
|
|
||||||
// }
|
|
||||||
// catch (const LicenceException &ex)
|
|
||||||
// {
|
|
||||||
// error.code = ex.getErrorCode();
|
|
||||||
// error.message = ex.getErrorMessage();
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// elcSwitchType = initStructure.elcType * 10 + licCompatibility;
|
|
||||||
|
|
||||||
// return true; // TODO testy
|
|
||||||
// }
|
|
||||||
|
|
||||||
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
switch (elcSwitchType)
|
|
||||||
{
|
|
||||||
case 11:
|
|
||||||
{ // old eoseov
|
|
||||||
LicenceItem11 *resultPtr = static_cast<LicenceItem11 *>(returnItemStructure);
|
|
||||||
resultPtr->protocolId = protocolId;
|
|
||||||
if (this->licenceInfo.licences.count(protocolId))
|
|
||||||
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
|
||||||
else
|
|
||||||
resultPtr->dataPointsCount = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 21:
|
|
||||||
{
|
|
||||||
|
|
||||||
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;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 31:
|
|
||||||
{
|
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
error.code = -1;
|
|
||||||
error.message = "Nepodařilo se identifikovat licenci";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LicenceReader::getLicenceInfo(void *returnStructure)
|
|
||||||
{
|
|
||||||
// const type_info& ti1 = typeid(returnStructure);
|
|
||||||
// cout << "TTTYP: " << ti1.name() << endl;
|
|
||||||
switch (elcSwitchType)
|
|
||||||
{
|
|
||||||
case 11:
|
|
||||||
{ // old eoseov
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 21:
|
|
||||||
{
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
licence.readLicence(&this->licenceInfo);
|
|
||||||
return licence.getLicenceInfo(returnStructure);
|
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
|
||||||
{
|
|
||||||
error.code = ex.getErrorCode();
|
|
||||||
error.message = ex.getErrorMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 31:
|
|
||||||
{
|
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// licence.readLicence();
|
|
||||||
// return licence.getLicenceInfo(returnStructure);
|
|
||||||
// }
|
|
||||||
// catch (const LicenceException &ex)
|
|
||||||
// {
|
|
||||||
// error.code = ex.getErrorCode();
|
|
||||||
// error.message = ex.getErrorMessage();
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error.code = -1;
|
|
||||||
error.message = "Nepodařilo se identifikovat licenci";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool LicenceReader::processInputConfiguration()
|
|
||||||
// {
|
|
||||||
// string fullFile = getCompletePath(this->configFileName);
|
|
||||||
// const size_t fileNameLength = fullFile.length();
|
|
||||||
// char fileName[fileNameLength] = {};
|
|
||||||
// getCharsFromString(fullFile, fileName, fileNameLength);
|
|
||||||
|
|
||||||
// #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"
|
|
||||||
// Mapping mapping;
|
|
||||||
|
|
||||||
// if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
|
|
||||||
// {
|
|
||||||
// error.code = -1;
|
|
||||||
// error.message = "Invalid XML VERSION";
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this->licData.doc = &doc;
|
|
||||||
|
|
||||||
// string licType = doc.child(dataRootName).child("licenceType").child_value();
|
|
||||||
// if (!licType.empty())
|
|
||||||
// {
|
|
||||||
// this->licIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// cerr << endl
|
|
||||||
// << " ERROR MISSING licenceType " << endl;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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]);
|
|
||||||
|
|
||||||
// licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]);
|
|
||||||
// licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").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
|
|
||||||
// {
|
|
||||||
// std::cerr << "Unable to open the config file." << std::endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void LicenceReader::readLicenceFile()
|
|
||||||
{
|
|
||||||
switch (this->licIdentification.licElcType)
|
|
||||||
{
|
|
||||||
case ELCType::ELC1:
|
|
||||||
readLicenceELC1();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC2:
|
|
||||||
readLicenceELC2();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELCType::ELC3:
|
|
||||||
readLicenceELC3();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceReader::readLicenceELC1()
|
|
||||||
{
|
|
||||||
cout << "reading ELC1" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceReader::readLicenceELC2()
|
|
||||||
{
|
|
||||||
LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LicenceReader::readLicenceELC3()
|
|
||||||
{
|
|
||||||
cout << "reading ELC3" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceReader::~LicenceReader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "licenceGenerator.h"
|
|
||||||
#include "licenceReader.h"
|
#include "licenceReader.h"
|
||||||
#include "licenceCommon.h"
|
|
||||||
|
|
||||||
/// @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 main5()
|
||||||
{
|
{
|
||||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||||
// try
|
// try
|
||||||
@@ -29,7 +28,8 @@ int main()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int protocolId = 222;
|
|
||||||
|
int protocolId = 444;
|
||||||
|
|
||||||
LicenceReader licenceReader1 {};
|
LicenceReader licenceReader1 {};
|
||||||
|
|
||||||
@@ -50,17 +50,15 @@ int main()
|
|||||||
|
|
||||||
if (licenceReader1.getLicenceInfo(&info))
|
if (licenceReader1.getLicenceInfo(&info))
|
||||||
{
|
{
|
||||||
std::cout << "Počet licenčních bodů pro : " << protocolId << ": " << info.reqDataPointsCount << std::endl;
|
|
||||||
if (info.licences.count(protocolId) > 0) cout << "Počet z vectoru pro : " << protocolId << ": " << info.licences.at(protocolId) << endl;
|
if (info.licences.count(protocolId) > 0) cout << "Počet z vectoru pro : " << protocolId << ": " << info.licences.at(protocolId) << endl;
|
||||||
cout << "Všechny licenční body: " << endl;
|
cout << "Všechny licenční body: " << endl;
|
||||||
for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; }
|
for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; }
|
||||||
}
|
}
|
||||||
else
|
else cout << "Došlo k chybě: " << licenceReader1.error.message;
|
||||||
cerr << "Došlo k chybě: " << licenceReader1.error.message;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Došlo k chybě: " << licenceReader1.error.message;
|
cout << "Došlo k chybě: " << licenceReader1.error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "\n" << "-- verze #2: init a iterace" << "\n";
|
cout << "\n" << "-- verze #2: init a iterace" << "\n";
|
||||||
@@ -77,16 +75,16 @@ int main()
|
|||||||
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cerr << "Došlo k chybě: " << licenceReader2.error.message;
|
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Došlo k chybě: " << licenceReader2.error.message;
|
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
cerr << "Obecná chyba\n";
|
cout << "Obecná chyba\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
system("pause");
|
system("pause");
|
||||||
|
|||||||
2
src/common/SDCard.d
Normal file
2
src/common/SDCard.d
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
src/common/SDCard.o: src/common/SDCard.cpp include/common/utils.h \
|
||||||
|
include/common/SDCard.h
|
||||||
BIN
src/common/SDCard.o
Normal file
BIN
src/common/SDCard.o
Normal file
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.
172
src/common/licenceELC2.cpp
Normal file
172
src/common/licenceELC2.cpp
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#include "licenceELC2.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
LicenceELC2::LicenceELC2(){}
|
||||||
|
|
||||||
|
LicenceELC2::~LicenceELC2(){}
|
||||||
|
|
||||||
|
LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification): lIdentification(licIdentification)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// @brief get proper licencename
|
||||||
|
/// @param licPostfix
|
||||||
|
/// @return
|
||||||
|
string LicenceELC2::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigned char> &content)
|
||||||
|
{
|
||||||
|
|
||||||
|
BYTE initVector[15] = {};
|
||||||
|
BYTE aesKey[32] = {};
|
||||||
|
|
||||||
|
LicenceELC2::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> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &content)
|
||||||
|
{
|
||||||
|
|
||||||
|
BYTE initVector[15] = {0};
|
||||||
|
BYTE aesKey[32] = {0};
|
||||||
|
|
||||||
|
LicenceELC2::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 LicenceELC2::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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
3
src/common/licenceELC2.d
Normal file
3
src/common/licenceELC2.d
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
src/common/licenceELC2.o: src/common/licenceELC2.cpp \
|
||||||
|
include/common/licenceELC2.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/common/utils.h
|
||||||
BIN
src/common/licenceELC2.o
Normal file
BIN
src/common/licenceELC2.o
Normal file
Binary file not shown.
28
src/common/utils.d
Normal file
28
src/common/utils.d
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
src/common/utils.o: src/common/utils.cpp include/openssl/conf.h \
|
||||||
|
include/openssl/macros.h include/openssl/opensslconf.h \
|
||||||
|
include/openssl/configuration.h include/openssl/opensslv.h \
|
||||||
|
include/openssl/bio.h include/openssl/e_os2.h include/openssl/crypto.h \
|
||||||
|
include/openssl/safestack.h include/openssl/stack.h \
|
||||||
|
include/openssl/types.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/ssl.h include/openssl/comp.h include/openssl/comperr.h \
|
||||||
|
include/openssl/x509.h include/openssl/buffer.h \
|
||||||
|
include/openssl/buffererr.h include/openssl/evp.h \
|
||||||
|
include/openssl/core_dispatch.h include/openssl/evperr.h \
|
||||||
|
include/openssl/params.h include/openssl/bn.h include/openssl/bnerr.h \
|
||||||
|
include/openssl/objects.h include/openssl/obj_mac.h \
|
||||||
|
include/openssl/asn1.h include/openssl/asn1err.h \
|
||||||
|
include/openssl/objectserr.h include/openssl/ec.h \
|
||||||
|
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
|
||||||
|
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
|
||||||
|
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
|
||||||
|
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
|
||||||
|
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/pem.h \
|
||||||
|
include/openssl/pemerr.h include/openssl/hmac.h include/openssl/async.h \
|
||||||
|
include/openssl/asyncerr.h include/openssl/ct.h include/openssl/cterr.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/tls1.h include/openssl/dtls1.h include/openssl/srtp.h \
|
||||||
|
include/common/utils.h
|
||||||
BIN
src/common/utils.o
Normal file
BIN
src/common/utils.o
Normal file
Binary file not shown.
145
src/generator/LicenceGenerator.cpp
Normal file
145
src/generator/LicenceGenerator.cpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <licenceGenerator.h>
|
||||||
|
#include "utils.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
LicenceGenerator::LicenceGenerator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string dataFileName)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (dataFileName.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: dataFileName");
|
||||||
|
|
||||||
|
if (uid.empty() == false)
|
||||||
|
{
|
||||||
|
this->licData.uid = uid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cid.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CID");
|
||||||
|
if (csd.empty()) throw LicenceException((int)GeneralError::ParamMissing, "Missing par: CSD");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->configFileName = dataFileName;
|
||||||
|
this->licData.cid = cid;
|
||||||
|
this->licData.csd = csd;
|
||||||
|
|
||||||
|
this->argumentsCorrect = true;
|
||||||
|
|
||||||
|
processInputConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LicenceGenerator::processInputConfiguration()
|
||||||
|
{
|
||||||
|
|
||||||
|
string fullFile = getCompletePath(this->configFileName);
|
||||||
|
const int fileNameLength = fullFile.length();
|
||||||
|
char fileName[fileNameLength] = {};
|
||||||
|
getCharsFromString(fullFile, fileName, fileNameLength);
|
||||||
|
|
||||||
|
#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"
|
||||||
|
|
||||||
|
if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION)
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
throw LicenceException((int)GeneralError::FileOpenError, "Unable to open the config file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LicenceGenerator::createLicenceFile()
|
||||||
|
{
|
||||||
|
switch (this->licIdentification.licElcType)
|
||||||
|
{
|
||||||
|
case ELCType::ELC1:
|
||||||
|
createLicenceELC1();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ELCType::ELC2:
|
||||||
|
createLicenceELC2();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ELCType::ELC3:
|
||||||
|
createLicenceELC3();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LicenceGenerator::createLicenceELC1() // přejmenvat na ELC1
|
||||||
|
{
|
||||||
|
Generator::Licence1 licence = Generator::Licence1(this->licData.cid, this->licData.csd, this->configFileName);
|
||||||
|
licence.createLicence();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LicenceGenerator::createLicenceELC2()
|
||||||
|
{
|
||||||
|
switch (this->licIdentification.licCompatibility)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
Generator::Licence2 licence = Generator::Licence2(licData.cid,licData.csd,licData.doc);
|
||||||
|
licence.createLicence();
|
||||||
|
/*
|
||||||
|
licence.createLicence();
|
||||||
|
// LicenceELC21 licence = LicenceELC21(this->licData);
|
||||||
|
// licence.createLicence();
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LicenceGenerator::createLicenceELC3()
|
||||||
|
{
|
||||||
|
switch (this->licIdentification.licCompatibility)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
//LicenceELC31 licence = LicenceELC31(this->licData);
|
||||||
|
//licence.createLicence();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LicenceGenerator::~LicenceGenerator()
|
||||||
|
{
|
||||||
|
}
|
||||||
9
src/generator/LicenceGenerator.d
Normal file
9
src/generator/LicenceGenerator.d
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \
|
||||||
|
include/generator/licenceGenerator.h include/generator/pugixml.hpp \
|
||||||
|
include/generator/pugiconfig.hpp include/common/licenceCommon.h \
|
||||||
|
include/licenceELC11.h include/common/SDCard.h include/licenceELC21.h \
|
||||||
|
include/common/utils.h include/generator/pugixml.hpp \
|
||||||
|
include/licenceELC31.h include/generator/licGenELC1.h \
|
||||||
|
include/common/licenceELC1.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/generator/licGenELC2.h \
|
||||||
|
include/common/licenceELC2.h include/generator/licGenELC3.h
|
||||||
BIN
src/generator/LicenceGenerator.o
Normal file
BIN
src/generator/LicenceGenerator.o
Normal file
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>
|
||||||
428
src/generator/licGenELC1.cpp
Normal file
428
src/generator/licGenELC1.cpp
Normal file
@@ -0,0 +1,428 @@
|
|||||||
|
#include "licGenELC1.h"
|
||||||
|
#define CID_LENGTH 32
|
||||||
|
#define CSD_LENGTH 32
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
6
src/generator/licGenELC1.d
Normal file
6
src/generator/licGenELC1.d
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \
|
||||||
|
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
|
||||||
BIN
src/generator/licGenELC1.o
Normal file
BIN
src/generator/licGenELC1.o
Normal file
Binary file not shown.
284
src/generator/licGenELC2.cpp
Normal file
284
src/generator/licGenELC2.cpp
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
#include "licGenELC2.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
6
src/generator/licGenELC2.d
Normal file
6
src/generator/licGenELC2.d
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \
|
||||||
|
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
|
||||||
BIN
src/generator/licGenELC2.o
Normal file
BIN
src/generator/licGenELC2.o
Normal file
Binary file not shown.
8
src/generator/licGenELC3.cpp
Normal file
8
src/generator/licGenELC3.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "licGenELC3.h"
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
2
src/generator/licGenELC3.d
Normal file
2
src/generator/licGenELC3.d
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
src/generator/licGenELC3.o: src/generator/licGenELC3.cpp \
|
||||||
|
include/generator/licGenELC3.h
|
||||||
BIN
src/generator/licGenELC3.o
Normal file
BIN
src/generator/licGenELC3.o
Normal file
Binary file not shown.
2
src/generator/pugixml.d
Normal file
2
src/generator/pugixml.d
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
src/generator/pugixml.o: src/generator/pugixml.cpp \
|
||||||
|
include/generator/pugixml.hpp include/generator/pugiconfig.hpp
|
||||||
BIN
src/generator/pugixml.o
Normal file
BIN
src/generator/pugixml.o
Normal file
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">
|
||||||
|
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
|
||||||
<plcType>WAGO</plcType>
|
<plcType>WAGO</plcType>
|
||||||
<licenceType version="1">EOV_OSV</licenceType>
|
|
||||||
<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>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "licenceELC21.h"
|
#include "licenceELC21.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "SDCard.h"
|
#include "SDCard.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
|
|
||||||
LicenceELC21::LicenceELC21()
|
LicenceELC21::LicenceELC21()
|
||||||
{
|
{
|
||||||
@@ -27,8 +29,8 @@ bool LicenceELC21::createLicence()
|
|||||||
getHeader();
|
getHeader();
|
||||||
|
|
||||||
sdCard = SDCard(lData.cid, lData.csd);
|
sdCard = SDCard(lData.cid, lData.csd);
|
||||||
if (sdCard.isLoaded == false)
|
if (sdCard.isLoaded == false) throw LicenceException((int)Error21::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||||
cerr << "SD card read error." << endl;
|
|
||||||
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
|
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
|
||||||
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
|
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
|
||||||
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
|
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
|
||||||
@@ -107,8 +109,7 @@ bool LicenceELC21::createLicence()
|
|||||||
// Check if the file is open
|
// Check if the file is open
|
||||||
if (!outputFile.is_open())
|
if (!outputFile.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Error opening file: " << licfileName << std::endl;
|
throw LicenceException((int)GeneralError::FileOpenError, "Chyba při zakládání souboru licence: " + cid_cdsPath);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
|
std::copy(publicContent.cbegin(), publicContent.cend(), std::ostream_iterator<unsigned char>(outputFile));
|
||||||
@@ -129,7 +130,6 @@ bool LicenceELC21::readLicence(LicenceInfoGeneral * licences)
|
|||||||
|
|
||||||
string licFileName = getLicenceName();
|
string licFileName = getLicenceName();
|
||||||
string licFilePath = this->licenceFilePath+licFileName;
|
string licFilePath = this->licenceFilePath+licFileName;
|
||||||
cout << licFilePath;
|
|
||||||
|
|
||||||
vector<char> content;
|
vector<char> content;
|
||||||
if (readFile(licFilePath, content) == false)
|
if (readFile(licFilePath, content) == false)
|
||||||
|
|||||||
262
src/reader/LicenceReader.cpp
Normal file
262
src/reader/LicenceReader.cpp
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
#include <licenceReader.h>
|
||||||
|
|
||||||
|
ELCType licElcType = ELCType::ELC2;
|
||||||
|
LicenceType licLicenceType;
|
||||||
|
PlcType licPlcType;
|
||||||
|
|
||||||
|
uint8_t licenceVersion = 1; // verze licence, určitě kodování, pojmenování souborů
|
||||||
|
uint8_t licenceIndex = 0;
|
||||||
|
uint8_t revision;
|
||||||
|
uint8_t licCompatibility = 1; // identikator hlavního ELC
|
||||||
|
|
||||||
|
LicenceReader::LicenceReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// LicenceReader::LicenceReader(string uid, string cid, string csd, string dataFileName)
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (dataFileName.empty())
|
||||||
|
// throw std::runtime_error("Missing dataFileName par.");
|
||||||
|
|
||||||
|
// if (uid.empty() == false)
|
||||||
|
// {
|
||||||
|
// this->licData.uid = uid;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// if (cid.empty())
|
||||||
|
// throw std::runtime_error("Missing CID par.");
|
||||||
|
// if (csd.empty())
|
||||||
|
// throw std::runtime_error("Missing CSD par.");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// catch (const std::exception &e)
|
||||||
|
// {
|
||||||
|
// this->argumentsCorrect = false;
|
||||||
|
// std::cerr << "error: " << e.what() << endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// this->configFileName = dataFileName;
|
||||||
|
// this->licData.cid = cid;
|
||||||
|
// this->licData.csd = csd;
|
||||||
|
|
||||||
|
// this->argumentsCorrect = true;
|
||||||
|
|
||||||
|
// if (processInputConfiguration() == false)
|
||||||
|
// {
|
||||||
|
// cerr << "Chyba: " << error.message << endl;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// LicenceReader::LicenceReader(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility)
|
||||||
|
// {
|
||||||
|
// this->licIdentification.licElcType = (ELCType)elcType;
|
||||||
|
// this->licIdentification.licLicenceType = (LicenceType)licenceType;
|
||||||
|
// this->licIdentification.licenceVersion = licenceVersion;
|
||||||
|
// this->licIdentification.licenceIndex = licenceIndex;
|
||||||
|
// this->licIdentification.licCompatibility = compatibility;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// @brief inicializace generátoru a načtení licenčních bodů
|
||||||
|
/// @param elcType
|
||||||
|
/// @param licenceType
|
||||||
|
/// @param licenceVersion
|
||||||
|
/// @param licenceIndex
|
||||||
|
/// @param compatibility
|
||||||
|
/// @return
|
||||||
|
bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
elcSwitchType = elcType * 10 + licCompatibility;
|
||||||
|
|
||||||
|
if (init(elcType, initStructure))
|
||||||
|
{
|
||||||
|
switch (elcSwitchType)
|
||||||
|
{
|
||||||
|
case 11:
|
||||||
|
{ // old eoseov
|
||||||
|
LicenceELC11 licence = LicenceELC11(this->licIdentification);
|
||||||
|
this->licence11 = &licence;
|
||||||
|
licence.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||||
|
licence.licenceFilePath = initStructure.licenceFilePath;
|
||||||
|
this->licence11->readLicence(&this->licenceInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 21:
|
||||||
|
{
|
||||||
|
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
||||||
|
this->licence2 = &licenceELC2;
|
||||||
|
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||||
|
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
||||||
|
this->licence2->readLicence(&this->licenceInfo);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 31:
|
||||||
|
{
|
||||||
|
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; // TODO testy
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LicenceReader::init(int elcType, InitStructure &initStructure)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (elcType > 3)
|
||||||
|
{
|
||||||
|
error.code = (int)GeneralError::ELCNotImplemented;
|
||||||
|
error.message = "ELC není implementováno.";
|
||||||
|
throw LicenceException((int)GeneralError::ELCNotImplemented, error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->licIdentification.licElcType = (ELCType)elcType;
|
||||||
|
this->licIdentification.licLicenceType = (LicenceType)initStructure.licenceType;
|
||||||
|
this->licIdentification.licenceVersion = licenceVersion;
|
||||||
|
this->licIdentification.licenceIndex = licenceIndex;
|
||||||
|
this->licIdentification.licCompatibility = initStructure.compatibility;
|
||||||
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
elcSwitchType = elcType * 10 + licCompatibility;
|
||||||
|
|
||||||
|
return true; // TODO testy
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (elcSwitchType)
|
||||||
|
{
|
||||||
|
case 11:
|
||||||
|
{ // old eoseov
|
||||||
|
LicenceItem11 *resultPtr = static_cast<LicenceItem11 *>(returnItemStructure);
|
||||||
|
resultPtr->protocolId = protocolId;
|
||||||
|
if (this->licenceInfo.licences.count(protocolId))
|
||||||
|
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
||||||
|
else
|
||||||
|
resultPtr->dataPointsCount = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 21:
|
||||||
|
{
|
||||||
|
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 31:
|
||||||
|
{
|
||||||
|
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
error.code = -1;
|
||||||
|
error.message = "Nepodařilo se identifikovat licenci";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LicenceReader::getLicenceInfo(void *returnStructure)
|
||||||
|
{
|
||||||
|
// const type_info& ti1 = typeid(returnStructure);
|
||||||
|
// cout << "TTTYP: " << ti1.name() << endl;
|
||||||
|
switch (elcSwitchType)
|
||||||
|
{
|
||||||
|
case 11:
|
||||||
|
{ // old eoseov
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 21:
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
||||||
|
licenceELC2.readLicence(&this->licenceInfo);
|
||||||
|
return licenceELC2.getLicenceInfo(returnStructure);
|
||||||
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// licence.readLicence(&this->licenceInfo);
|
||||||
|
// return licence.getLicenceInfo(returnStructure);
|
||||||
|
// }
|
||||||
|
// catch (const LicenceException &ex)
|
||||||
|
// {
|
||||||
|
// error.code = ex.getErrorCode();
|
||||||
|
// error.message = ex.getErrorMessage();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 31:
|
||||||
|
{
|
||||||
|
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// licence.readLicence();
|
||||||
|
// return licence.getLicenceInfo(returnStructure);
|
||||||
|
// }
|
||||||
|
// catch (const LicenceException &ex)
|
||||||
|
// {
|
||||||
|
// error.code = ex.getErrorCode();
|
||||||
|
// error.message = ex.getErrorMessage();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error.code = -1;
|
||||||
|
error.message = "Nepodařilo se identifikovat licenci";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LicenceReader::~LicenceReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
8
src/reader/LicenceReader.d
Normal file
8
src/reader/LicenceReader.d
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \
|
||||||
|
include/reader/licenceReader.h include/common/utils.h \
|
||||||
|
include/licenceELC11.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/licenceELC31.h \
|
||||||
|
include/generator/pugixml.hpp include/generator/pugiconfig.hpp \
|
||||||
|
include/reader/licReaderELC1.h include/reader/licReaderELC2.h \
|
||||||
|
include/common/licenceELC2.h include/common/licenceCommon.h \
|
||||||
|
include/common/SDCard.h include/reader/licReaderELC3.h
|
||||||
BIN
src/reader/LicenceReader.o
Normal file
BIN
src/reader/LicenceReader.o
Normal file
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>
|
||||||
6
src/reader/licReaderELC1.cpp
Normal file
6
src/reader/licReaderELC1.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "licReaderELC1.h"
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
2
src/reader/licReaderELC1.d
Normal file
2
src/reader/licReaderELC1.d
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
src/reader/licReaderELC1.o: src/reader/licReaderELC1.cpp \
|
||||||
|
include/reader/licReaderELC1.h
|
||||||
BIN
src/reader/licReaderELC1.o
Normal file
BIN
src/reader/licReaderELC1.o
Normal file
Binary file not shown.
112
src/reader/licReaderELC2.cpp
Normal file
112
src/reader/licReaderELC2.cpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#include "licReaderELC2.h"
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
|
||||||
|
Licence2::Licence2(){}
|
||||||
|
|
||||||
|
Licence2::~Licence2(){}
|
||||||
|
|
||||||
|
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief načte licence do obecné struktury ELC2
|
||||||
|
/// @param licences
|
||||||
|
/// @return
|
||||||
|
bool Licence2::readLicence(LicenceInfoGeneral *licences)
|
||||||
|
{
|
||||||
|
sdCard = SDCard(this->cid_cdsPath);
|
||||||
|
if (sdCard.isLoaded == false)
|
||||||
|
throw LicenceException((int)GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu., 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)GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence.");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Licence2::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
src/reader/licReaderELC2.d
Normal file
5
src/reader/licReaderELC2.d
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
src/reader/licReaderELC2.o: src/reader/licReaderELC2.cpp \
|
||||||
|
include/reader/licReaderELC2.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
|
||||||
BIN
src/reader/licReaderELC2.o
Normal file
BIN
src/reader/licReaderELC2.o
Normal file
Binary file not shown.
7
src/reader/licReaderELC3.cpp
Normal file
7
src/reader/licReaderELC3.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "licReaderELC3.h"
|
||||||
|
|
||||||
|
namespace Reader
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
2
src/reader/licReaderELC3.d
Normal file
2
src/reader/licReaderELC3.d
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
src/reader/licReaderELC3.o: src/reader/licReaderELC3.cpp \
|
||||||
|
include/reader/licReaderELC3.h
|
||||||
BIN
src/reader/licReaderELC3.o
Normal file
BIN
src/reader/licReaderELC3.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user