ELC 2
This commit is contained in:
71
include/SDCard.h
Normal file
71
include/SDCard.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef SDCARD_H_
|
||||
#define SDCARD_H_
|
||||
|
||||
#define CID_LENGTH 32
|
||||
#define CSD_LENGTH 32
|
||||
|
||||
using namespace std;
|
||||
|
||||
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;
|
||||
|
||||
const BYTE cnibblescount = 32;
|
||||
|
||||
const string cidFilePath = "";
|
||||
|
||||
class SDCard
|
||||
{
|
||||
|
||||
|
||||
|
||||
struct SDCardData
|
||||
{
|
||||
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
||||
uint8_t CID_nibble[32] = {0}; // surova data CID ze souboru
|
||||
uint8_t CID[16] = {0}; // prekodovane CID informace
|
||||
uint8_t 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);
|
||||
uint8_t productRevision_hw = 0;
|
||||
uint8_t productRevision_sw = 0;
|
||||
float productRevision = 0; // revize produktu 1B [bcd sh] -> Byte 7, bity 0-3 = revize HW, bity 4-7 = revize SW
|
||||
uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
|
||||
uint16_t manufacturerDate_year = 0;
|
||||
uint8_t 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
|
||||
uint8_t CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1
|
||||
uint8_t CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
|
||||
uint8_t CSD[16] = {}; //: ARRAY [0..15] OF BYTE; // prekodovane CSD informace
|
||||
uint32_t cardSize = 0; //: UDINT; // velikost SD karty
|
||||
uint8_t cardGSize = 0; // prepocitana velikost na GB
|
||||
};
|
||||
|
||||
bool readSDCard();
|
||||
bool getCIDFromFile();
|
||||
bool getCSDFromFile();
|
||||
|
||||
public:
|
||||
|
||||
SDCardData cardData;
|
||||
bool isLoaded = false;
|
||||
char cid[32] = {};
|
||||
char csd[32] = {};
|
||||
string filePath = "";
|
||||
string cidString = ""; //pro předání pro starý generátor
|
||||
string csdString = ""; //pro předání pro starý generátor
|
||||
|
||||
SDCard();
|
||||
SDCard(string cid, string csd);
|
||||
SDCard(const string filesPath);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
194
include/licenceCommon.h
Normal file
194
include/licenceCommon.h
Normal file
@@ -0,0 +1,194 @@
|
||||
#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
|
||||
};
|
||||
|
||||
// map<GeneralError, string> mapGeneralErrors = {
|
||||
// // 1,"test"
|
||||
// // {CommonError::GeneralError, "Obecná chyba."},
|
||||
// // {CommonError::FileReadError, "Chyba čtení souboru."},
|
||||
// // {CommonError::FileReadError, "Chyba zápisu souboru."},
|
||||
// // {CommonError::ELCNotImplemented, "ELC není implementováno."},
|
||||
// // {CommonError::LicenceTypeNotImplemented, "Typ licence není implementován"}
|
||||
// };
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
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:
|
||||
// Constructor with int and string parameters
|
||||
LicenceException(int errorCode, const std::string &errorMessage)
|
||||
: errorCode_(errorCode), errorMessage_(errorMessage) {}
|
||||
|
||||
// Override the what() function to provide a description of the exception
|
||||
const char *what() const noexcept override
|
||||
{
|
||||
return errorMessage_.c_str();
|
||||
}
|
||||
|
||||
// Getter functions for the exception members
|
||||
int getErrorCode() const
|
||||
{
|
||||
return errorCode_;
|
||||
}
|
||||
|
||||
const std::string &getErrorMessage() const
|
||||
{
|
||||
return errorMessage_;
|
||||
}
|
||||
|
||||
private:
|
||||
int errorCode_;
|
||||
std::string errorMessage_;
|
||||
};
|
||||
|
||||
#endif
|
||||
283
include/licenceELC11.h
Normal file
283
include/licenceELC11.h
Normal file
@@ -0,0 +1,283 @@
|
||||
#ifndef PLC_LICENCE11_H
|
||||
#define PLC_LICENCE11_H
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <wchar.h>
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include "licenceCommon.h"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MAX_LICENCE_COUNT 100
|
||||
|
||||
enum InputLicenceType
|
||||
{
|
||||
EOSEOV = 1
|
||||
};
|
||||
|
||||
enum BinaryGenerationType
|
||||
{
|
||||
Base64Cout = 1,
|
||||
File = 2
|
||||
};
|
||||
|
||||
enum PlcLicenceType
|
||||
{
|
||||
LicenceOther = 0,
|
||||
LicenceEov = 1
|
||||
};
|
||||
enum LidIdType
|
||||
{
|
||||
Ddts = 1,
|
||||
EovOsv = 2
|
||||
};
|
||||
enum PrefixType
|
||||
{
|
||||
ELC1 = 1
|
||||
};
|
||||
|
||||
typedef uint32_t DWORD;
|
||||
typedef uint16_t WORD;
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint32_t UDINT;
|
||||
typedef uint32_t DATE;
|
||||
typedef uint8_t USINT;
|
||||
typedef int32_t DINT;
|
||||
typedef uint16_t UINT;
|
||||
typedef int16_t INT;
|
||||
|
||||
/// @brief identifikace licence
|
||||
typedef struct LicenceIdent
|
||||
{
|
||||
WORD licPrefixType = 0; // WORD; typ licencniho souboru - pro kazdy prefig je jiny typ souboru a jiny zpusob zpracovani dat [sifrovani, podpis, komprese, ...]
|
||||
WORD licHeaderType = 0; //: WORD; typ hlavicky kriptovane casti licencniho souboru
|
||||
WORD licDataType = 0; //: WORD; typ licence - pro kazdou hlavicku jsou samostatne typy licenci - mohou byt i shodne s typem jine hlavicky
|
||||
WORD licSubType = 0; //: WORD; slouceny typ hlavicku a typ licence => typ hlavicky * 256 + typ licence
|
||||
WORD licIDType = 0; //: WORD; id aplikace, pro kterou je licence urcena => 1 = ddts, 2 = eov-osv
|
||||
BYTE licPostfix = 0; //: BYTE; rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
|
||||
} LicenceIdent;
|
||||
|
||||
/// @brief struktura pro přípravu dat na generování
|
||||
typedef struct LicenceSourceData
|
||||
{
|
||||
|
||||
BYTE startGen; // na nabeznou hranu se vygeneruje licence
|
||||
BYTE loadSD; //: BOOL; na nabeznou hranu se nacte SD karta
|
||||
// zadavane hodnoty
|
||||
BYTE licType_id; // vybrany typ licence
|
||||
char licDescription1[40] = {}; //: STRING(39); jmeno stanice
|
||||
char licDescription2[20] = {}; //: STRING(19); jmeno rozvadece
|
||||
BYTE licPostfix; // rozliseni licence pro stejny typ - napr. pokud mam 2x SW pro DRT na 2 nezavisle ED
|
||||
BYTE enInit; //: BOOL; inicializace (promazani) adresare pro licence
|
||||
// interne generovane hodnoty
|
||||
WORD licType; //: WORD; hlavicka licence
|
||||
BYTE licIdOk; //: BOOL; korektne zvoleny typ licence
|
||||
string licPostfixIdent; //[2]; //: STRING(2); vygenerovany postfix z cisla pro rozliseni postfixu v souborech a textech
|
||||
} LicenceSourceData;
|
||||
|
||||
/// @brief struktura obsahující dodatečné informace k licenci
|
||||
typedef struct PlcData
|
||||
{
|
||||
string plcType = "";
|
||||
string licenceType = ""; // typ
|
||||
string licenceVersion = "1";
|
||||
string licenceName = ""; // název
|
||||
string station = ""; // stanice
|
||||
string distributor = ""; // rozvadec
|
||||
} PlcData;
|
||||
|
||||
/*
|
||||
MID (Manufacturer ID): 8 bits - Identifies the manufacturer of the SD card.
|
||||
OID (OEM/Application ID): 16 bits - Identifies the OEM and application-specific information.
|
||||
PNM (Product Name): 40 bits - A string representing the product name of the SD card.
|
||||
PRV (Product Revision): 8 bits - The product revision/version.
|
||||
PSN (Product Serial Number): 32 bits - A unique serial number assigned to the SD card during manufacturing.
|
||||
MDT (Manufacturing Date): 12 bits - Represents the manufacturing date of the SD card.
|
||||
CRC (CRC7 Checksum): 7 bits - A cyclic redundancy check for error detection.
|
||||
unused: 4 bits - Reserved for future use.
|
||||
*/
|
||||
|
||||
/// @brief struktura pro načtení CIS a CSD dat
|
||||
typedef struct SDData
|
||||
{
|
||||
BYTE isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
||||
BYTE CID_nibble[32] = {0}; // surova data CID ze souboru
|
||||
BYTE CID[16] = {0}; // prekodovane CID informace
|
||||
BYTE manufacturerID = 0; // ID vyrobce 1B -> Byte 15
|
||||
char oemID[2] = {}; // ID aplikace/oem 2B -> Byte 13-14 // oemID: !!STRING(3);
|
||||
char name[5] = {}; // jmeno produktu 5B -> Byte 8-12 !!STRING(6);
|
||||
BYTE productRevision_hw = 0;
|
||||
BYTE productRevision_sw = 0;
|
||||
float productRevision = 0; // revize produktu 1B [bcd sh] -> Byte 7, bity 0-3 = revize HW, bity 4-7 = revize SW
|
||||
DWORD serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
|
||||
WORD manufacturerDate_year = 0;
|
||||
BYTE manufacturerDate_month = 0;
|
||||
char manufacturerDate[10] = {}; //: STRING(10); // datum vyroby 2B [bcd -yym] -> Byte 1-2, bity 0-3 = mesic, bity 4-11 = posledni cislice roku or roku 2000, bity 12-15 nepouzito
|
||||
BYTE CRCOK = 0; // CRC 1B -> Byte 0, bity 1-7, bit 0 je vzdy = 1
|
||||
BYTE CSD_nibble[32] = {}; //: ARRAY [0..31] OF BYTE; // surova data CSD ze souboru
|
||||
BYTE CSD[16] = {}; //: ARRAY [0..15] OF BYTE; // prekodovane CSD informace
|
||||
UDINT cardSize = 0; //: UDINT; // velikost SD karty
|
||||
BYTE cardGSize = 0; // prepocitana velikost na GB
|
||||
} CidData;
|
||||
|
||||
// nekodovana cast licence
|
||||
|
||||
/// @brief nekryptovaná hlavička licence
|
||||
typedef struct LicenceDataMainHeaderELC
|
||||
{
|
||||
BYTE licType = 0;
|
||||
; // typ licence => duplicitni polozka s hlavickou kodovane casti licence - pouze pro ucely dekodovani dat
|
||||
BYTE dummy1 = 0;
|
||||
WORD licSubType = 0; // horni byte = typ hlavicky kodovane casti, spodni byte = typ dat polozkove casti => duplicitni casti s id a hlavickou kodovane casti - pouze pro ucely dekodovani
|
||||
char description[80] = {}; // viditelny popis licincniho souboru
|
||||
UDINT sizeData = 0; // velikost kodovane casti licence v Bytech
|
||||
} LicenceDataMainHeaderELC;
|
||||
|
||||
// hlavní struktura licence
|
||||
typedef struct LicenceDataMainELC
|
||||
{
|
||||
// prefix MUSI zustat jako prvni prvek struktury a MUSI byt typu DWORD
|
||||
DWORD prefix = 0; // urcuje strukturu dat citelne casti licencniho souboru [teto struktury] + zpusob sifrovani, dig, podpis, kompresi... dat
|
||||
LicenceDataMainHeaderELC licHeader; // nekodovana cast licence
|
||||
} LicenceDataMain;
|
||||
|
||||
// polozkova cast licence verze 1.0
|
||||
typedef struct LicenceDataItem
|
||||
{
|
||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
||||
WORD licCount = 0; // pocet datovych bodu licence
|
||||
DWORD data1 = 0; // doplnkove nahodne cislo, slouzi pro overeni licence v runtime
|
||||
} LicenceDataItem;
|
||||
|
||||
// identifikace kodovane casti licence - !!! MUSI yustat pro vsechny verze STEJNA !!!
|
||||
typedef struct LicenceDataId
|
||||
{
|
||||
WORD version = 0; // verze hlavicky
|
||||
WORD rez = 0;
|
||||
UDINT cardSize = 0;
|
||||
} LicenceDataId;
|
||||
|
||||
typedef struct LicenceDataHeader
|
||||
{
|
||||
BYTE licType = 0; // typ licence => 0...neznamy (chyba), 1...DDTS, 2...EOV-OSV
|
||||
BYTE licReserve = 0; // rezerva
|
||||
WORD licVersion = 0; //: WORD; verze polozkove casti licence
|
||||
DATE licDate = 0; // datum vygenerovani licence
|
||||
char licDescription1[40] = {}; // licDescription1: STRING(39); stanice, pro kterou byla licence generovana
|
||||
char licDescription2[20] = {}; // STRING(19); rozvadec, pro ktery byla licence generovana
|
||||
USINT licCount = 0; // aktivni pocet dat polozkove casti licence
|
||||
BYTE licDummy = 0; // rezerva
|
||||
WORD licReservew = 0; // rezerva
|
||||
} LicenceDataHeader;
|
||||
|
||||
// kodovana cast licence verze 1.1 s polozkovou casi licence verze 1.0
|
||||
typedef struct LicenceData
|
||||
{
|
||||
LicenceDataId id; // id !!! MUSI zustat na PRVNIM miste struktury
|
||||
LicenceDataHeader header;
|
||||
LicenceDataItem items[MAX_LICENCE_COUNT]; // polozkova cast licence
|
||||
WORD dummy = 0; // pro zarovnani struktur - jinak nebude fungovat vypocet a kontrola CRC !!!
|
||||
WORD crc = 0; // kontrolni kod - !!! MUSI zustat na konci struktury
|
||||
} LicenceData;
|
||||
|
||||
typedef struct LicenceRetData
|
||||
{
|
||||
BYTE retCode = 0; // navratovy kod funkce pro nacteni SD
|
||||
DINT subCode = 0; // doplnkova informace chyby
|
||||
std::string text = ""; // textovy popis navratove hodnoty
|
||||
bool isDone = false; // operace korektne dokoncena
|
||||
} LicenceRetData;
|
||||
|
||||
typedef struct CryptData
|
||||
{
|
||||
bool initDone = false;
|
||||
DWORD cryptDataAddress = 0; // adresa na data, ktera se maji cryptovat
|
||||
UINT cryptDataSize = 0; // velikostdat, ktera semaji cryptovat
|
||||
BYTE aesInitVector[15] = {0}; //] : ARRAY [0..14] OF BYTE;// AES 128 bit IV
|
||||
BYTE aesKey[32] = {0}; // : ARRAY [0..31] OF BYTE; // AES 256 bit key
|
||||
DINT aesRetVal = 0; // navratova hodnota AES
|
||||
DWORD retDataAddress = 0; // adresa na ulozeni cryptovana dat
|
||||
UINT retDataSize = 0; // velikost cryptovanych dat
|
||||
LicenceData *licenseData;
|
||||
} CryptData;
|
||||
|
||||
/// @brief licence class
|
||||
class LicenceELC11
|
||||
{
|
||||
|
||||
enum class Error11
|
||||
{
|
||||
SDCardReadError = 50,
|
||||
LicenceReadError = 51,
|
||||
LicenceSizeMismatch = 52,
|
||||
LicenceSizeCardMismatch = 53,
|
||||
LicenceMismatch = 54,
|
||||
ItemsCountMismatch = 61
|
||||
};
|
||||
|
||||
// unordered_map<Error11, string> map11Errors = {
|
||||
// {Error11::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||
// {Error11::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
|
||||
// };
|
||||
|
||||
private:
|
||||
SDCard sdCard;
|
||||
const string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
const string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
|
||||
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
|
||||
|
||||
//InputLicenceType dataLicenceType = InputLicenceType::EOSEOV;
|
||||
|
||||
CryptData cryptData; // structure for encryp
|
||||
CidData sdData; // data loaded from SD card
|
||||
|
||||
void processConfigFile(string &dataFileName); //process data from config file
|
||||
void getSDData(); // reads SD card
|
||||
string getLicenceName(BYTE licPostfix); // get proper licencename
|
||||
string getLicenceName();
|
||||
void initCrypto();
|
||||
bool createEosEovLicence(); // create licence for EOV_OSV
|
||||
bool readEosEovLicence(string dataFileName);
|
||||
LicenceIdentification lIdentification;
|
||||
|
||||
public:
|
||||
|
||||
string operationErrors = "";
|
||||
ErrorMessage errorMessage;
|
||||
|
||||
LicenceELC11();
|
||||
~LicenceELC11();
|
||||
|
||||
LicenceELC11(string cid, string csd, string binaryType, string dataFileName);
|
||||
LicenceELC11(LicenceIdentification & licIdentification);
|
||||
|
||||
bool createLicence(); // creates licence
|
||||
bool readLicence(string dataFileName, string licenceType, string licenceVersion, string cidArg, string csdArg);
|
||||
bool readLicence(LicenceInfoGeneral * licences);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
125
include/licenceELC21.h
Normal file
125
include/licenceELC21.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#ifndef PLC_LICENCE21_H
|
||||
#define PLC_LICENCE21_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "licenceCommon.h"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class LicenceELC21
|
||||
{
|
||||
const string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
const string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
|
||||
|
||||
enum class Error21
|
||||
{
|
||||
SDCardReadError = 50,
|
||||
LicenceReadError = 51,
|
||||
LicenceSizeMismatch = 52,
|
||||
LicenceSizeCardMismatch = 53,
|
||||
LicenceMismatch = 54,
|
||||
ItemsCountMismatch = 61
|
||||
};
|
||||
|
||||
unordered_map<Error21, string> map21Errors = {
|
||||
{Error21::SDCardReadError, "Nepodařilo se načíst SD kartu."},
|
||||
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||
{Error21::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
|
||||
{Error21::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
|
||||
{Error21::LicenceMismatch, "Nesouhlasí licence."},
|
||||
{Error21::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
|
||||
};
|
||||
|
||||
|
||||
struct LicenceId
|
||||
{
|
||||
char licIdent[5] = { 'E', 'L', 'C', '0','_'};
|
||||
};
|
||||
|
||||
//struct __attribute__((__packed__)) LicencePublicHeader
|
||||
|
||||
struct LicenceIdentDataHeader
|
||||
{
|
||||
BYTE licenceType = 0; //EOSEOV, DRT ...
|
||||
BYTE licenceTypeVersion = 1; //verze licence, urcuje nuance sifrování a pojmenování souborů
|
||||
BYTE licenceIndex = 0; //puvodní post fix, identifikátor pro více licencí
|
||||
BYTE compatibilityVersion = 1; //udava verzi komplet PrivateContent
|
||||
BYTE licItemCount = 0; //počet licenčních bodů
|
||||
WORD publicHeaderLength = 0; //délka veřejné hlavičy
|
||||
WORD cardSize = 0; //velikost SD karty
|
||||
DWORD serialNumber = 0;//seriove cislo karty
|
||||
};
|
||||
|
||||
///
|
||||
struct licDataItem
|
||||
{
|
||||
WORD protoId = 0; // id protokolu pro ktery je licence
|
||||
WORD licCount = 0; // pocet datovych bodu licence
|
||||
char dummy[64] = {};
|
||||
};
|
||||
|
||||
struct PublicHeader
|
||||
{
|
||||
string version = "";
|
||||
string projectDescription = "";
|
||||
string date = "";
|
||||
string licenceType = "";
|
||||
int crc = 0;
|
||||
};
|
||||
|
||||
struct PrivateContent //privátní šifrovaná část
|
||||
{
|
||||
LicenceIdentDataHeader licenceIdentHeader;
|
||||
vector<licDataItem> dataItems;
|
||||
WORD crc = 0;
|
||||
};
|
||||
|
||||
struct LicenceBody
|
||||
{
|
||||
LicenceId licId;
|
||||
LicenceIdentDataHeader licenceIdentHeader;
|
||||
string publicHeader = ""; //JSON
|
||||
PrivateContent privateContent;
|
||||
};
|
||||
|
||||
private:
|
||||
int licItemCount = 0;
|
||||
LicenceBody licBody;
|
||||
LicenceIdentification lIdentification;
|
||||
LicData lData;
|
||||
SDCard sdCard;
|
||||
void getHeader();
|
||||
string getVersion(int middleVersion);
|
||||
void getLicenceItems();
|
||||
bool processInputConfiguration();
|
||||
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char>& content);
|
||||
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char>& content);
|
||||
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
|
||||
string getLicenceName();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
ErrorMessage errorMessage;
|
||||
LicenceInfo21 licenceInfo;
|
||||
|
||||
LicenceELC21();
|
||||
~LicenceELC21();
|
||||
LicenceELC21(LicenceIdentification & licIdentification, LicData & icData);
|
||||
LicenceELC21(LicenceIdentification & licIdentification);
|
||||
LicenceELC21(LicData & icData);
|
||||
bool createLicence();
|
||||
bool readLicence(LicenceInfoGeneral * licences);
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(int protocolId, void * ptr);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
29
include/licenceELC31.h
Normal file
29
include/licenceELC31.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef PLC_LICENCE31_H
|
||||
#define PLC_LICENCE31_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "licenceCommon.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class LicenceELC31
|
||||
{
|
||||
LicData lData;
|
||||
bool processInputConfiguration();
|
||||
|
||||
public:
|
||||
LicenceELC31();
|
||||
~LicenceELC31();
|
||||
LicenceELC31(LicData & licData);
|
||||
LicenceELC31(LicenceIdentification & licIdentification);
|
||||
void createLicence();
|
||||
void readLicence();
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(int protocolId, void * ptr);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
84
include/licenceGenerator.h
Normal file
84
include/licenceGenerator.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef LICENCE_GENERATOR_H_
|
||||
#define LICENCE_GENERATOR_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <wchar.h>
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include "licenceCommon.h"
|
||||
#include "licenceELC11.h"
|
||||
#include "licenceELC21.h"
|
||||
#include "licenceELC31.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct InitStructure
|
||||
{
|
||||
int elcType = 0;
|
||||
int licenceType = 0;
|
||||
int licenceVersion = 0;
|
||||
int licenceIndex = 0;
|
||||
int compatibility = 0;
|
||||
string licenceFilePath = "";
|
||||
};
|
||||
|
||||
class LicenceGenerator
|
||||
{
|
||||
|
||||
|
||||
|
||||
public:
|
||||
int elcSwitchType;
|
||||
string operationErrors = "";
|
||||
pugi::xml_document doc;
|
||||
bool argumentsCorrect = false;
|
||||
ErrorMessage error;
|
||||
LicenceELC11 *licence11;
|
||||
LicenceELC21 *licence21;
|
||||
LicenceELC31 *licence31;
|
||||
|
||||
LicenceGenerator();
|
||||
~LicenceGenerator();
|
||||
LicenceGenerator(map<string, string> &arguments);
|
||||
// LicenceGenerator(string cid, string csd, string dataFileName, string binaryType);
|
||||
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
|
||||
LicenceGenerator(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
bool init(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
bool init(InitStructure &initStructure);
|
||||
bool initread(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
bool initread(InitStructure &initStructure);
|
||||
|
||||
void createLicenceFile();
|
||||
void readLicenceFile();
|
||||
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(int protocolId, void *returnStructure);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
|
||||
LicenceInfoGeneral licenceInfo;
|
||||
|
||||
private:
|
||||
LicenceIdentification licIdentification;
|
||||
LicData licData;
|
||||
string configFileName = "";
|
||||
|
||||
void *licence = nullptr;
|
||||
|
||||
bool processInputConfiguration();
|
||||
|
||||
void createLicenceELC1();
|
||||
void createLicenceELC2();
|
||||
void createLicenceELC3();
|
||||
|
||||
void readLicenceELC1();
|
||||
void readLicenceELC2();
|
||||
void readLicenceELC3();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -18,7 +18,7 @@ using namespace std;
|
||||
|
||||
enum InputLicenceType
|
||||
{
|
||||
EOSEOV
|
||||
EOSEOV = 1
|
||||
};
|
||||
|
||||
enum BinaryGenerationType
|
||||
@@ -227,6 +227,7 @@ private:
|
||||
string dataCryptoVersion = ""; //version of crypting from xmlFile
|
||||
string dataGenerationType = ""; //version of dataGeneration from xmlFile
|
||||
string dataLicenceDataFileName = ""; //name of licence file to read
|
||||
//InputLicenceType dataLicenceType = InputLicenceType::EOSEOV;
|
||||
|
||||
CryptData cryptData; // structure for encryp
|
||||
CidData sdData; // data loaded from SD card
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#define LINUX 1
|
||||
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
#include <bitset>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <filesystem>
|
||||
|
||||
#define LINUX 1
|
||||
#include <vector>
|
||||
|
||||
#define PEM_BUFSIZE_TEXT 1024
|
||||
#define BitVal(data, y) ((data >> y) & 1) /** Return Data.Y value **/
|
||||
@@ -16,21 +22,11 @@
|
||||
|
||||
#define PEM_BUFSIZE_TEXT 1024
|
||||
|
||||
#ifndef BYTE
|
||||
|
||||
typedef uint8_t BYTE;
|
||||
#endif
|
||||
|
||||
#ifndef WORD
|
||||
typedef uint16_t WORD;
|
||||
#endif
|
||||
|
||||
#ifndef DWORD
|
||||
typedef uint32_t DWORD;
|
||||
#endif
|
||||
|
||||
#ifndef DATE
|
||||
typedef uint32_t DATE;
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -56,19 +52,37 @@ DateAndTime getCurrentDateTimeAsCODESYSDateTime();
|
||||
uint16_t convertToCODESYSDate(int day, int month, int year);
|
||||
uint16_t convertToCODESYSTime(int hour, int minute);
|
||||
DATE getLicDate();
|
||||
int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext);
|
||||
string getDate();
|
||||
int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext);
|
||||
bool CompareFiles(const char *fileName, const char *fileName1);
|
||||
unsigned short crc16(const unsigned char* data_p, unsigned char length);
|
||||
int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
|
||||
int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
|
||||
string convertToString(char* a, int size);
|
||||
std::string base64_encode_ai(const std::string &input);
|
||||
std::string base64_decode_ai(const std::string &encoded);
|
||||
map<string, string> getArguments(int argc, char *argv[]);
|
||||
map<string, const char*> mapArguments(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);
|
||||
void getCharsFromString1(string source, char *charArray);
|
||||
void getCharsFromString(string& source, char *charArray, int length);
|
||||
string getCompletePath(string fileName);
|
||||
char* getFileContent(string fileName);
|
||||
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
|
||||
void coutVector (std::vector<unsigned char>& charVector);
|
||||
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
|
||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
||||
uint32_t bytesToWord(uint8_t byte1, uint8_t byte2);
|
||||
vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, const std::vector<unsigned char>& vector2);
|
||||
string readFileToString(const std::string& filename, std::size_t sizeS);
|
||||
bool readFile(string fileName, vector<char> &output);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user