oddělení generatoru od readeru
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -83,7 +83,8 @@
|
||||
"numbers": "cpp",
|
||||
"span": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"variant": "cpp"
|
||||
"variant": "cpp",
|
||||
"climits": "cpp"
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve"
|
||||
}
|
||||
6
Makefile
6
Makefile
@@ -8,7 +8,7 @@ CXX = g++
|
||||
|
||||
# define any compile-time flags
|
||||
# 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
|
||||
# if I wanted to include libraries not in /usr/lib I'd specify
|
||||
@@ -19,10 +19,10 @@ LFLAGS =
|
||||
OUTPUT := output
|
||||
|
||||
# define source directory
|
||||
SRC := src
|
||||
SRC := src src/common src/reader src/generator
|
||||
|
||||
# define include directory
|
||||
INCLUDE := include
|
||||
INCLUDE := include include/common include/reader include/generator
|
||||
|
||||
# define lib directory
|
||||
LIB := lib
|
||||
|
||||
@@ -23,8 +23,6 @@ const string cidFilePath = "";
|
||||
class SDCard
|
||||
{
|
||||
|
||||
|
||||
|
||||
struct SDCardData
|
||||
{
|
||||
uint8_t isCorrectLoad = 0; // SD karta je korektne nactena //bool vs byte ?
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef LICENCE_COMMON_H_
|
||||
#define LICENCE_COMMON_H_
|
||||
|
||||
//---------------- společná hlavička pro všechny licence ----------------
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "pugixml.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -15,6 +18,11 @@ 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,
|
||||
@@ -27,7 +35,9 @@ enum class GeneralError
|
||||
ELCMismatch = 8,
|
||||
CRCMismatch = 9,
|
||||
EncryptError = 10,
|
||||
DecryptError = 11
|
||||
DecryptError = 11,
|
||||
ParamMissing = 12,
|
||||
IvanlidParam = 13
|
||||
};
|
||||
|
||||
enum class ELCType
|
||||
@@ -91,7 +101,7 @@ struct LicenceIdentification
|
||||
string licTypeName = "";
|
||||
PlcType licPlcType;
|
||||
|
||||
uint8_t licenceVersion = 1; // verze licence, určitě kodování, pojmenování souborů
|
||||
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
|
||||
@@ -100,19 +110,24 @@ struct LicenceIdentification
|
||||
|
||||
string cid_cds_path = "";
|
||||
string licenceFilePath = "";
|
||||
|
||||
};
|
||||
|
||||
struct LicData
|
||||
// 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 LicenceItem
|
||||
{
|
||||
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;
|
||||
int protocolId = -1;
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
struct LicenceItem11
|
||||
@@ -133,29 +148,35 @@ struct LicenceItem31
|
||||
int dataPointsCount = 0;
|
||||
};
|
||||
|
||||
struct LicenceInfo
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo11
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo21
|
||||
{
|
||||
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 LicenceInfo31
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfoGeneral
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
struct LicenceInfoGeneral
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
};
|
||||
|
||||
class LicenceException : public std::exception
|
||||
{
|
||||
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 getLicenceName();
|
||||
string cid_cdsPath = "";
|
||||
string licenceFilePath = "";
|
||||
|
||||
|
||||
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)[]);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -27,7 +27,7 @@ struct DateAndTime {
|
||||
|
||||
void generatePause();
|
||||
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);
|
||||
WORD getCurrentDateAsCODESYSDate();
|
||||
DWORD getCurrentDateAsCODESYSDateDword();
|
||||
9
include/generator/licGenELC1.h
Normal file
9
include/generator/licGenELC1.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ELC1_GENERATOR__H
|
||||
#define ELC1_GENERATOR__H
|
||||
|
||||
namespace Generator
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
9
include/generator/licGenELC2.h
Normal file
9
include/generator/licGenELC2.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ELC2_GENERATOR__H
|
||||
#define ELC2_GENERATOR__H
|
||||
|
||||
namespace Generator
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -11,16 +11,33 @@
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include "pugixml.hpp"
|
||||
#include "licenceCommon.h"
|
||||
#include "licenceELC11.h"
|
||||
#include "licenceELC21.h"
|
||||
#include "licenceELC31.h"
|
||||
|
||||
#include "licGenELC1.h"
|
||||
#include "licGenELC2.h"
|
||||
#include "licGenELC3.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
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:
|
||||
int elcSwitchType;
|
||||
string operationErrors = "";
|
||||
@@ -34,17 +51,15 @@ public:
|
||||
LicenceGenerator();
|
||||
~LicenceGenerator();
|
||||
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
|
||||
LicenceGenerator(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
|
||||
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;
|
||||
@@ -58,9 +73,6 @@ private:
|
||||
void createLicenceELC2();
|
||||
void createLicenceELC3();
|
||||
|
||||
void readLicenceELC1();
|
||||
void readLicenceELC2();
|
||||
void readLicenceELC3();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
#include "licenceCommon.h"
|
||||
#include "pugixml.hpp"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -12,22 +13,33 @@ using namespace std;
|
||||
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;
|
||||
LicenceInfo21 licenceInfo;
|
||||
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
string cid_cdsPath = ""; //"c:\\_projects\\LicenceGenerator\\output\\"; ///sys/block/mmcblk0/device/
|
||||
string licenceFilePath = ""; //"c:\\_projects\\LicenceGenerator\\output\\";
|
||||
|
||||
LicenceELC21();
|
||||
~LicenceELC21();
|
||||
LicenceELC21(LicenceIdentification & licIdentification, LicData & icData);
|
||||
LicenceELC21(LicenceIdentification & licIdentification);
|
||||
LicenceELC21(LicData & icData);
|
||||
LicenceELC21(LicenceIdentification &licIdentification, LicData &licData);
|
||||
LicenceELC21(LicenceIdentification &licIdentification);
|
||||
LicenceELC21(LicData &licData);
|
||||
bool createLicence();
|
||||
bool readLicence(LicenceInfoGeneral * licences);
|
||||
bool readLicence(LicenceInfoGeneral *licences);
|
||||
int getDataPointsCount(int protocolId);
|
||||
bool getLicenceInfo(void * ptr);
|
||||
bool getLicenceInfo(void *ptr);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
|
||||
enum class Error21
|
||||
@@ -51,28 +63,28 @@ public:
|
||||
|
||||
struct LicenceId
|
||||
{
|
||||
char licIdent[5] = { 'E', 'L', 'C', '0','_'};
|
||||
char licIdent[5] = {'E', 'L', 'C', '0', '_'};
|
||||
};
|
||||
|
||||
//struct __attribute__((__packed__)) LicencePublicHeader
|
||||
// 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
|
||||
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] = {};
|
||||
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
|
||||
@@ -84,7 +96,7 @@ public:
|
||||
int crc = 0;
|
||||
};
|
||||
|
||||
struct PrivateContent //privátní šifrovaná část
|
||||
struct PrivateContent // privátní šifrovaná část
|
||||
{
|
||||
LicenceIdentDataHeader licenceIdentHeader;
|
||||
vector<licDataItem> dataItems;
|
||||
@@ -95,12 +107,11 @@ public:
|
||||
{
|
||||
LicenceId licId;
|
||||
LicenceIdentDataHeader licenceIdentHeader;
|
||||
string publicHeader = ""; //JSON
|
||||
string publicHeader = ""; // JSON
|
||||
PrivateContent privateContent;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
int licItemCount = 0;
|
||||
LicenceBody licBody;
|
||||
LicenceIdentification lIdentification;
|
||||
@@ -110,11 +121,10 @@ public:
|
||||
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);
|
||||
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
|
||||
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
|
||||
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
|
||||
string getLicenceName();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,11 +6,24 @@
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "licenceCommon.h"
|
||||
#include "pugixml.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class LicenceELC31
|
||||
{
|
||||
struct LicData
|
||||
{
|
||||
string station = "";
|
||||
string distributor = "";
|
||||
string licenceName = "";
|
||||
string projectDescription = "";
|
||||
string cid = ""; // CID z SD karty
|
||||
string csd = ""; // CSD z SD karty
|
||||
string uid = ""; // jedinečný identifikátor z jiného systému
|
||||
pugi::xml_document *doc;
|
||||
};
|
||||
|
||||
LicData lData;
|
||||
bool processInputConfiguration();
|
||||
LicenceIdentification lIdentification;
|
||||
|
||||
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
|
||||
34
include/reader/licReaderELC2.h
Normal file
34
include/reader/licReaderELC2.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#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);
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#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_
|
||||
|
||||
#include "utils.h"
|
||||
// #include "licenceCommon.h"
|
||||
#include "licenceELC11.h"
|
||||
#include "licenceELC21.h"
|
||||
#include "licenceELC31.h"
|
||||
|
||||
#include "licReaderELC1.h"
|
||||
#include "licReaderELC2.h"
|
||||
#include "licReaderELC3.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Reader;
|
||||
|
||||
|
||||
struct InitStructure
|
||||
{
|
||||
@@ -28,18 +32,13 @@ public:
|
||||
bool argumentsCorrect = false;
|
||||
ErrorMessage error;
|
||||
LicenceELC11 *licence11;
|
||||
LicenceELC21 *licence21;
|
||||
LicenceELC31 *licence31;
|
||||
Licence2 *licence2;
|
||||
|
||||
LicenceReader();
|
||||
~LicenceReader();
|
||||
bool init(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
bool init(int elcType, InitStructure &initStructure);
|
||||
bool initread(int elcType, int licenceType, int licenceVersion, int licenceIndex, int compatibility);
|
||||
bool initread(int elcType, InitStructure &initStructure);
|
||||
|
||||
void readLicenceFile();
|
||||
|
||||
bool getLicenceInfo(void *returnStructure);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
|
||||
@@ -47,14 +46,9 @@ public:
|
||||
|
||||
private:
|
||||
LicenceIdentification licIdentification;
|
||||
LicData licData;
|
||||
string configFileName = "";
|
||||
|
||||
void *licence = nullptr;
|
||||
|
||||
void readLicenceELC1();
|
||||
void readLicenceELC2();
|
||||
void readLicenceELC3();
|
||||
};
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@@ -1,28 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include "utils.h"
|
||||
#include "licenceGenerator.h"
|
||||
#include "licenceReader.h"
|
||||
#include "licenceCommon.h"
|
||||
|
||||
/// @brief hlavní funkce
|
||||
/// @param argc
|
||||
/// @param argv parametry pro generování licence
|
||||
/// @return
|
||||
int main5(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
// try
|
||||
// {
|
||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
// LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]);
|
||||
// generatorOld.createLicenceFile();
|
||||
// return SUCCES;
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// cerr << "Obecná chyba\n";
|
||||
// }
|
||||
try
|
||||
{
|
||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]);
|
||||
generatorOld.createLicenceFile();
|
||||
return SUCCES;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "Obecná chyba\n";
|
||||
}
|
||||
|
||||
// system("pause");
|
||||
system("pause");
|
||||
return SUCCES;
|
||||
}
|
||||
|
||||
@@ -484,148 +484,6 @@ bool LicenceELC11::createEosEovLicence()
|
||||
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)
|
||||
{
|
||||
sdCard = SDCard(this->cid_cdsPath);
|
||||
@@ -745,22 +603,4 @@ bool LicenceELC11::readLicence(LicenceInfoGeneral *licences)
|
||||
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() {}
|
||||
|
||||
@@ -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 "utils.h"
|
||||
#include "licenceGenerator.h"
|
||||
#include "licenceReader.h"
|
||||
#include "licenceCommon.h"
|
||||
|
||||
|
||||
/// @brief hlavní funkce
|
||||
/// @param argc
|
||||
/// @param argv parametry pro generování licence
|
||||
/// @return
|
||||
int main()
|
||||
int mainno()
|
||||
{
|
||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
// try
|
||||
@@ -29,7 +28,8 @@ int main()
|
||||
|
||||
try
|
||||
{
|
||||
int protocolId = 222;
|
||||
|
||||
int protocolId = 444;
|
||||
|
||||
LicenceReader licenceReader1 {};
|
||||
|
||||
@@ -50,17 +50,15 @@ int main()
|
||||
|
||||
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;
|
||||
cout << "Všechny licenční body: " << endl;
|
||||
for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; }
|
||||
}
|
||||
else
|
||||
cerr << "Došlo k chybě: " << licenceReader1.error.message;
|
||||
else cout << "Došlo k chybě: " << licenceReader1.error.message;
|
||||
}
|
||||
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";
|
||||
@@ -77,16 +75,16 @@ int main()
|
||||
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||
}
|
||||
else
|
||||
cerr << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "Obecná chyba\n";
|
||||
cout << "Obecná chyba\n";
|
||||
}
|
||||
|
||||
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.
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.
143
src/generator/LicenceGenerator.cpp
Normal file
143
src/generator/LicenceGenerator.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#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"
|
||||
Mapping mapping;
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
LicenceGenerator::~LicenceGenerator()
|
||||
{
|
||||
}
|
||||
7
src/generator/LicenceGenerator.d
Normal file
7
src/generator/LicenceGenerator.d
Normal file
@@ -0,0 +1,7 @@
|
||||
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/generator/licGenELC2.h include/generator/licGenELC3.h
|
||||
BIN
src/generator/LicenceGenerator.o
Normal file
BIN
src/generator/LicenceGenerator.o
Normal file
Binary file not shown.
6
src/generator/licGenELC1.cpp
Normal file
6
src/generator/licGenELC1.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "licGenELC1.h"
|
||||
|
||||
namespace Generator
|
||||
{
|
||||
|
||||
}
|
||||
2
src/generator/licGenELC1.d
Normal file
2
src/generator/licGenELC1.d
Normal file
@@ -0,0 +1,2 @@
|
||||
src/generator/licGenELC1.o: src/generator/licGenELC1.cpp \
|
||||
include/generator/licGenELC1.h
|
||||
BIN
src/generator/licGenELC1.o
Normal file
BIN
src/generator/licGenELC1.o
Normal file
Binary file not shown.
6
src/generator/licGenELC2.cpp
Normal file
6
src/generator/licGenELC2.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "licGenELC2.h"
|
||||
|
||||
namespace Generator
|
||||
{
|
||||
|
||||
}
|
||||
2
src/generator/licGenELC2.d
Normal file
2
src/generator/licGenELC2.d
Normal file
@@ -0,0 +1,2 @@
|
||||
src/generator/licGenELC2.o: src/generator/licGenELC2.cpp \
|
||||
include/generator/licGenELC2.h
|
||||
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,6 +1,8 @@
|
||||
#include "licenceELC21.h"
|
||||
#include "utils.h"
|
||||
#include "SDCard.h"
|
||||
#include "pugixml.hpp"
|
||||
|
||||
|
||||
LicenceELC21::LicenceELC21()
|
||||
{
|
||||
@@ -27,8 +29,8 @@ bool LicenceELC21::createLicence()
|
||||
getHeader();
|
||||
|
||||
sdCard = SDCard(lData.cid, lData.csd);
|
||||
if (sdCard.isLoaded == false)
|
||||
cerr << "SD card read error." << endl;
|
||||
if (sdCard.isLoaded == false) throw LicenceException((int)Error21::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||
|
||||
this->licBody.licenceIdentHeader.cardSize = sdCard.cardData.cardSize;
|
||||
this->licBody.licenceIdentHeader.serialNumber = sdCard.cardData.serialNumber;
|
||||
this->licBody.licenceIdentHeader.licItemCount = this->licBody.privateContent.dataItems.size();
|
||||
@@ -107,8 +109,7 @@ bool LicenceELC21::createLicence()
|
||||
// Check if the file is open
|
||||
if (!outputFile.is_open())
|
||||
{
|
||||
std::cerr << "Error opening file: " << licfileName << std::endl;
|
||||
return false;
|
||||
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));
|
||||
@@ -129,7 +130,6 @@ bool LicenceELC21::readLicence(LicenceInfoGeneral * licences)
|
||||
|
||||
string licFileName = getLicenceName();
|
||||
string licFilePath = this->licenceFilePath+licFileName;
|
||||
cout << licFilePath;
|
||||
|
||||
vector<char> content;
|
||||
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.
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.
118
src/reader/licReaderELC2.cpp
Normal file
118
src/reader/licReaderELC2.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#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("9f544930303030300000000b47015423", "400e00325b5900003a0d7f800a40008d");
|
||||
sdCard = SDCard(this->cid_cdsPath);
|
||||
if (sdCard.isLoaded == false)
|
||||
throw LicenceException((int)Error::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||
|
||||
string licFileName = getLicenceName();
|
||||
string licFilePath = this->licenceFilePath + licFileName;
|
||||
|
||||
vector<char> content;
|
||||
if (readFile(licFilePath, content) == false)
|
||||
{
|
||||
throw LicenceException((int)GeneralError::FileOpenError, "Chyba otevření souboru licence: " + licFilePath);
|
||||
}
|
||||
|
||||
this->licBody.licId.licIdent[0] = content[0];
|
||||
this->licBody.licId.licIdent[1] = content[1];
|
||||
this->licBody.licId.licIdent[2] = content[2];
|
||||
this->licBody.licId.licIdent[3] = content[3];
|
||||
this->licBody.licId.licIdent[4] = content[4];
|
||||
|
||||
this->licBody.licenceIdentHeader.licenceType = content[5];
|
||||
this->licBody.licenceIdentHeader.licenceTypeVersion = content[6];
|
||||
this->licBody.licenceIdentHeader.licenceIndex = content[7];
|
||||
this->licBody.licenceIdentHeader.compatibilityVersion = content[8];
|
||||
this->licBody.licenceIdentHeader.licItemCount = content[9];
|
||||
this->licBody.licenceIdentHeader.publicHeaderLength = bytesToWord(content[10], content[11]);
|
||||
this->licBody.licenceIdentHeader.cardSize = bytesToWord(content[12], content[13]);
|
||||
this->licBody.licenceIdentHeader.serialNumber = bytesToDword(content[14], content[15], content[16], content[17]);
|
||||
|
||||
//~~~uint16_t crcPublic = bytesToWord(content[18 + licBody.licenceIdentHeader.publicHeaderLength], content[19 + licBody.licenceIdentHeader.publicHeaderLength]);
|
||||
|
||||
int elcVersion = (int)licBody.licId.licIdent[3] - 48;
|
||||
|
||||
if (elcVersion != (int)this->lIdentification.licElcType)
|
||||
{
|
||||
throw LicenceException((int)GeneralError::ELCMismatch, "Nesouhlasí ELC.");
|
||||
}
|
||||
|
||||
vector<unsigned char> encryptedPart(content.begin() + licBody.licenceIdentHeader.publicHeaderLength + 20, content.begin() + content.size());
|
||||
|
||||
vector<unsigned char> privateContentDecrypted;
|
||||
privateContentDecrypted = decryptPrivateContent(encryptedPart);
|
||||
|
||||
LicenceBody licBodyDecrypted;
|
||||
licBodyDecrypted.licenceIdentHeader.licenceType = privateContentDecrypted[0];
|
||||
licBodyDecrypted.licenceIdentHeader.licenceTypeVersion = privateContentDecrypted[1];
|
||||
licBodyDecrypted.licenceIdentHeader.licenceIndex = privateContentDecrypted[2];
|
||||
licBodyDecrypted.licenceIdentHeader.compatibilityVersion = privateContentDecrypted[3];
|
||||
licBodyDecrypted.licenceIdentHeader.licItemCount = privateContentDecrypted[4];
|
||||
licBodyDecrypted.licenceIdentHeader.publicHeaderLength = bytesToWord(privateContentDecrypted[5], privateContentDecrypted[6]);
|
||||
licBodyDecrypted.licenceIdentHeader.cardSize = bytesToWord(privateContentDecrypted[7], privateContentDecrypted[8]);
|
||||
licBodyDecrypted.licenceIdentHeader.serialNumber = bytesToDword(privateContentDecrypted[9], privateContentDecrypted[10], privateContentDecrypted[11], privateContentDecrypted[12]);
|
||||
|
||||
//~~~CRC
|
||||
|
||||
if (licBodyDecrypted.licenceIdentHeader.licItemCount != this->licBody.licenceIdentHeader.licItemCount)
|
||||
{
|
||||
throw LicenceException((int)LicenceELC2::Error::ItemsCountMismatch, mapErrors.at(Error::ItemsCountMismatch));
|
||||
}
|
||||
|
||||
int index = 13;
|
||||
for (int i = 0; i < this->licBody.licenceIdentHeader.licItemCount; i++)
|
||||
{
|
||||
licDataItem item;
|
||||
item.protoId = bytesToWord(privateContentDecrypted[index], privateContentDecrypted[index + 1]);
|
||||
item.licCount = bytesToWord(privateContentDecrypted[index + 2], privateContentDecrypted[index + 3]);
|
||||
index += sizeof(licDataItem);
|
||||
this->licBody.privateContent.dataItems.push_back(item);
|
||||
this->licenceInfo.licences.insert(pair<int, int>(item.protoId, item.licCount));
|
||||
licences->licences.insert(pair<int, int>(item.protoId, item.licCount));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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