Upravy a opravování kryptování

This commit is contained in:
2024-04-11 14:31:24 +02:00
parent ead3ba6e3e
commit 3b1ee6038e
47 changed files with 414 additions and 422 deletions

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef SDCARD_H_
#define SDCARD_H_
@@ -25,9 +27,9 @@ struct SDCardInfo
uint32_t cardSize {};
uint32_t serialNumber {};
string date = "";
uint8_t manufacturerID {};
char oemID[2] = {};
char name[5] = {};
string oemID = "";
string name = "";
string licenceFileName = "";
bool isLoaded = false;
};
@@ -47,6 +49,7 @@ class SDCard
uint32_t serialNumber = 0; // seriove cislo karty 4B -> Byte 3-6
uint16_t manufacturerDate_year = 0;
uint8_t manufacturerDate_month = 0;
string date = "";
char manufacturerDate[10] = {}; //: STRING(10); // datum vyroby 2B [bcd -yym] -> Byte 1-2, bity 0-3 = mesic, bity 4-11 = posledni cislice roku or roku 2000, bity 12-15 nepouzito
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
@@ -77,4 +80,5 @@ public:
};
#endif
#endif

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#define CRC = 1
#ifndef LICENCE_COMMON_H_
@@ -15,7 +17,10 @@ using namespace std;
#define XML_VERSION 1
#define SOFTWARE_VERSION 1
#define SUCCES 0;
#define SUCCES 0
#define CRYPT_INIT_VECTOR_SIZE 16
#define CRYPT_INIT_KEY_SIZE 32
const int cidSize = 32;
const int csdSize = 32;
@@ -52,9 +57,9 @@ enum class GeneralError
enum class ELCType
{
ELC1 = 1, //starý původní licenční soubor zalozený na CID a CSD
ELC2 = 2, //modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů
ELC3 = 3 //budoucí softwarový licenční soubor, který není zalozený na existenci CID a CSD, ale na unikátním ID instalace linuxu
ELC1 = 1, // starý původní licenční soubor zalozený na CID a CSD
ELC2 = 2, // modifikovaný starý licenční soubor umoznující modifikace (šifrování, název) dle parametrů
ELC3 = 3 // budoucí softwarový licenční soubor, který není zalozený na existenci CID a CSD, ale na unikátním ID instalace linuxu
};
enum class ELCSubType
{
@@ -91,7 +96,10 @@ enum class FileNameGenerationType
DEFAULT = 1
};
//indexy musí být velká písmena ze základní ASCI tabulky
struct CryptInitVector{ int vec[CRYPT_INIT_VECTOR_SIZE]; };
struct CryptAesKey { int key[CRYPT_INIT_KEY_SIZE]; };
// indexy musí být velká písmena ze základní ASCI tabulky
struct Mapping
{
unordered_map<string, LicenceType> licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}};
@@ -107,12 +115,12 @@ struct ErrorMessage
struct LicenceIdentification
{
ELCType licElcType = ELCType::ELC2; //hlavní typ licenčního souboru
ELCType licElcType = ELCType::ELC2; // hlavní typ licenčního souboru
LicenceType licLicenceType;
string licTypeName = "";
PlcType licPlcType;
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
uint8_t licenceIndex = 0; //index licenčního souboru v případě, ze jich je víc
uint8_t licenceIndex = 0; // index licenčního souboru v případě, ze jich je víc
uint8_t revision;
uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC
uint16_t licItemsCount = 0;
@@ -129,33 +137,32 @@ struct LicenceInfoGeneral
/// @brief obecná struktura polozky licence, defaultní kompatibilita
struct LicenceItem
{
DWORD protocolId {};
DWORD dataPointsCount {};
DWORD protocolId{};
DWORD dataPointsCount{};
};
/* struktury pro ELC 1 */
//defaultní struktura pro ELC 1
// defaultní struktura pro ELC 1
struct LicenceELC1Info
{
bool isValid {false};
bool isValid{false};
};
//struktura ELC1, kompatibilita 1
// struktura ELC1, kompatibilita 1
struct LicenceELC1Info_1
{
unordered_map<int, int> licences = {};
};
//defaultni struktura polozky licence ELC 1
// defaultni struktura polozky licence ELC 1
struct LicenceELC1Item
{
int protocolId = -1;
int dataPointsCount = 0;
};
/* struktury pro ELC 2 */
//defaultní struktura pro ELC 2
// defaultní struktura pro ELC 2
struct LicenceELC2Info
{
map<DWORD, DWORD> licences = {};
@@ -166,21 +173,20 @@ struct LicenceELC2Info
// map<int, int> licences = {};
// };
//defaultni struktura polozky ELC 2
// defaultni struktura polozky ELC 2
struct LicenceELC2Item
{
DWORD protocolId {};
DWORD dataPointsCount {};
DWORD protocolId{};
DWORD dataPointsCount{};
};
//struktura polozky ELC 2,
// struktura polozky ELC 2,
struct LicenceELC2Item_1
{
DWORD protocolId {};
DWORD dataPointsCount {};
DWORD protocolId{};
DWORD dataPointsCount{};
};
class LicenceException : public std::exception
{
public:
@@ -208,3 +214,5 @@ private:
};
#endif
#endif

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef PLC_LICENCE1_COMMON_H
#define PLC_LICENCE1_COMMON_H
@@ -262,4 +264,5 @@ public:
};
#endif
#endif

View File

@@ -1,7 +1,8 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef PLC_LICENCE2_COMMON_H
#define PLC_LICENCE2_COMMON_H
#include <vector>
#include "licenceCommon.h"
#include "SDCard.h"
@@ -13,9 +14,10 @@ public:
LicenceELC2();
LicenceELC2(LicenceIdentification &licIdentification);
~LicenceELC2();
string cid_cdsPath = "";
string licenceFilePath = "";
string licFileName = "";
Mapping mapping;
@@ -29,21 +31,21 @@ public:
// struct __attribute__((__packed__)) LicencePublicHeader
struct LicenceIdentDataHeader
{
BYTE licenceType {}; // EOSEOV, DRT ...
BYTE licenceType{}; // EOSEOV, DRT ...
BYTE licenceTypeVersion = 1; // verze licence, urcuje nuance sifrování a pojmenování souborů
BYTE licenceIndex {}; // puvodní post fix, identifikátor pro více licencí
BYTE licenceIndex{}; // puvodní post fix, identifikátor pro více licencí
BYTE compatibilityVersion = 1; // udava verzi komplet PrivateContent
BYTE licItemCount {}; // počet protokolů v linenci
WORD publicHeaderLength {}; // délka veřejné hlavičy
WORD cardSize {}; // velikost SD karty
DWORD serialNumber = {}; // seriove cislo karty
BYTE licItemCount{}; // počet protokolů v linenci
WORD publicHeaderLength{}; // délka veřejné hlavičy
WORD cardSize{}; // velikost SD karty
DWORD serialNumber = {}; // seriove cislo karty
};
///
struct licDataItem
{
DWORD protoId {}; // id protokolu pro ktery je licence
DWORD licCount {}; // pocet datovych bodu licence
DWORD protoId{}; // id protokolu pro ktery je licence
DWORD licCount{}; // pocet datovych bodu licence
};
struct PublicHeader
@@ -56,30 +58,31 @@ public:
struct PrivateContent // privátní šifrovaná část
{
LicenceIdentDataHeader licenceIdentHeader {};
vector<licDataItem> dataItems {};
WORD crc {};
LicenceIdentDataHeader licenceIdentHeader{};
vector<licDataItem> dataItems{};
WORD crc{};
};
struct LicenceBody
{
LicenceId licId {};
LicenceIdentDataHeader licenceIdentHeader {};
LicenceId licId{};
LicenceIdentDataHeader licenceIdentHeader{};
string publicHeader = ""; // JSON
PrivateContent privateContent {};
PrivateContent privateContent{};
};
LicenceBody licBody {};
SDCard sdCard {};
LicenceIdentification lIdentification {};
SDCard sdCard{};
protected:
vector<unsigned char> cryptPrivateContent(const std::vector<unsigned char> &content);
vector<unsigned char> decryptPrivateContent(const std::vector<unsigned char> &content);
void initVector(BYTE (&iVector)[], BYTE (&key)[]);
void initVector(BYTE *iVector, BYTE *key);
string getLicenceName();
LicenceBody licBody{};
LicenceIdentification lIdentification{};
private:
};
#endif
#endif

View File

@@ -1,3 +1,5 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#ifndef UTILS_H_
#define UTILS_H_
@@ -48,7 +50,7 @@ vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, con
bool readFile(string fileName, vector<char> &output);
#endif
#endif