Compare commits

...

2 Commits

Author SHA1 Message Date
37d02abd3f oddělení, čištění, kontrola ELC1 2024-02-05 15:04:22 +01:00
5229f16c9d oddeleni a lazeni ELC1 2024-02-01 15:07:33 +01:00
60 changed files with 601 additions and 436 deletions

View File

@@ -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 -w
CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify

View File

@@ -213,6 +213,7 @@ void LicenceELC11::initCrypto()
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
}
}
string LicenceELC11::getLicenceName()
{
string result = "";

View File

@@ -11,6 +11,12 @@ RUN chmod 755 /app/start.sh
COPY ./startok.sh /app/
RUN chmod 755 /app/startok.sh
COPY ./lread.sh /app/
RUN chmod 755 /app/lread.sh
COPY ./lgen.sh /app/
RUN chmod 755 /app/lgen.sh
COPY ./Makefile /app/
ENTRYPOINT ["tail"]

7
docker/lgen.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
chmod 777 output/generate
#./output/generate -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml
cd output
./generate -cid=9f54495344434954615ad803c50171bf -csd=400e00325b5900003be77f800a400043 -outputType=file -configFileName=licData.xml

7
docker/lread.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
chmod 777 output/read
#./output/read -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml
cd output
./read -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml

View File

@@ -1,7 +1,7 @@
#!/bin/bash
chmod 777 output/licenceGenerator
#./output/licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=400e00325b59000076b27f800a404013 -outputType=file -configFileName=licData.xml -licenceFileName=ezlic_eovosv0_vaxvcpalxjx.lic -licenceVersion=1 -licenceType=EOV_OSV
#./output/licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml
cd output
./licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=400e00325b59000076b27f800a404013 -outputType=file -configFileName=licData.xml -licenceFileName=ezlic_eovosv0_vaxvcpalxjx.lic -licenceVersion=1 -licenceType=EOV_OSV
./licenceGenerator -cid=0353445355313647801b1a9f6600c747 -csd=0353445355313647801b1a9f6600c747 -outputType=file -configFileName=licData.xml

View File

@@ -6,6 +6,7 @@
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <stdint.h>
using namespace std;
@@ -46,15 +47,6 @@ enum class GeneralError
ItemsCountMismatch = 61
};
// unordered_map<GeneralError, string> mapGeneralErrors = {
// {GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu."},
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
// {GeneralError::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
// {GeneralError::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
// {GeneralError::LicenceMismatch, "Nesouhlasí licence."},
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
// };
enum class ELCType
{
ELC1 = 1,
@@ -119,14 +111,19 @@ struct LicenceIdentification
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
uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC
uint16_t licItemsCount = 0;
string cid_cds_path = "";
string licenceFilePath = "";
};
/// @brief obecná struktura pro reader
struct LicenceInfoGeneral
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief obecná struktura polozky licence, defaultní kompatibilita
struct LicenceItem
{
@@ -134,97 +131,53 @@ struct LicenceItem
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 1
struct LicenceItemCompatibility1
/* struktury pro ELC 1 */
//defaultní struktura pro ELC 1
struct LicenceELC1Info
{
int protocolId = -1;
int dataPointsCount = 0;
bool isValid {false};
};
/// @brief struktura polozky licence, kompatibilita 2
struct LicenceItemCompatibility2
//struktura ELC1, kompatibilita 1
struct LicenceELC1Info_1
{
int protocolId = -1;
int dataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief struktura polozky licence, kompatibilita 3
struct LicenceItemCompatibility3
//defaultni struktura polozky licence ELC 1
struct LicenceELC1Item
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem11
/* struktury pro ELC 2 */
//defaultní struktura pro ELC 2
struct LicenceELC2Info
{
unordered_map<int, int> licences = {};
};
struct LicenceELC2Info_1
{
unordered_map<int, int> licences = {};
};
//defaultni struktura polozky ELC 2
struct LicenceELC2Item
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem21
//struktura polozky ELC 2,
struct LicenceELC2Item_1
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem31
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief základní struktura, seznam polozek licencí
struct LicenceInfo
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
struct LicenceInfoCompatibility1
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
struct LicenceInfoCompatibility2
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
struct LicenceInfoCompatibility3
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
struct LicenceInfo11
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
struct LicenceInfo21
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
struct LicenceInfo31
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
struct LicenceInfoGeneral
{
int reqDataPointsCount = 0;
map<int, int> licences = {};
};
class LicenceException : public std::exception
{

View File

@@ -1,6 +1,3 @@
//#define LINUX 1
#define WINDOWS 1
#ifndef UTILS_H_
#define UTILS_H_
@@ -12,6 +9,7 @@
#include <format>
#include <libgen.h> // dirname
#include <climits>
#include <unistd.h>
typedef uint8_t BYTE;
typedef uint16_t WORD;
@@ -40,11 +38,8 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
string convertToString(char* a, int size);
string base64_encode_ai(const std::string &input);
unordered_map<string, string> getArguments(int argc, char *argv[]);
char* getCharArray(string source);
void getCharsFromString1(string source, char *charArray);
void getCharsFromString(string& source, char *charArray, size_t length);
string getCompletePath(string fileName);
char* getFileContent(string fileName);
void appendStringToVector(const std::string& str, 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);

View File

@@ -7,19 +7,20 @@
#include <stdint.h>
#include "pugixml.hpp"
#include "licenceCommon.h"
#include "licenceELC11.h"
#include "licenceELC21.h"
#include "licenceELC31.h"
// #include "licenceELC11.h"
// #include "licenceELC21.h"
// #include "licenceELC31.h"
#include "licGenELC1.h"
#include "licGenELC2.h"
#include "licGenELC3.h"
using namespace std;
class LicenceGenerator
{
public:
struct LicData
{
string station = "";
@@ -32,31 +33,27 @@ class LicenceGenerator
pugi::xml_document *doc;
};
public:
LicData licData;
int elcSwitchType;
string operationErrors = "";
pugi::xml_document doc;
bool argumentsCorrect = false;
ErrorMessage error;
LicenceELC11 *licence11;
LicenceELC21 *licence21;
LicenceELC31 *licence31;
// LicenceELC11 *licence11;
// LicenceELC21 *licence21;
// LicenceELC31 *licence31;
Mapping mapping;
LicenceGenerator();
~LicenceGenerator();
LicenceGenerator(string uid, string cid, string csd, string dataFileName);
void createLicenceFile();
LicenceInfoGeneral licenceInfo;
private:
LicenceIdentification licIdentification;
LicData licData;
string configFileName = "";
void *licence = nullptr;
@@ -66,7 +63,6 @@ private:
void createLicenceELC1();
void createLicenceELC2();
void createLicenceELC3();
};
#endif

View File

@@ -944,13 +944,17 @@ namespace pugi
char _memory[192];
// Non-copyable semantics
xml_document(const xml_document&);
xml_document& operator=(const xml_document&);
// xml_document(const xml_document&);
// xml_document& operator=(const xml_document&);
void create();
void destroy();
public:
xml_document(const xml_document&);
xml_document& operator=(const xml_document&);
// Default constructor, makes empty document
xml_document();

View File

@@ -1,9 +1,31 @@
#ifndef ELC1_READER__H
#define ELC1_READER__H
#include "utils.h"
#include "licenceCommon.h"
#include "licenceELC1.h"
#include "SDCard.h"
using namespace std;
namespace Reader
{
class Licence1 : public LicenceELC1
{
public:
LicenceELC1Info licenceInfo;
Licence1();
~Licence1();
Licence1(LicenceIdentification &licIdentification);
bool readLicence(LicenceInfoGeneral *licences);
bool getLicenceInfo(void *ptr);
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
void getLicenceItems();
};
}
#endif

View File

@@ -13,15 +13,13 @@ namespace Reader
class Licence2 : public LicenceELC2
{
public:
LicenceInfo21 licenceInfo;
LicenceELC2Info licenceInfo;
Licence2();
~Licence2();
Licence2(LicenceIdentification &licIdentification);
bool readLicence(LicenceInfoGeneral *licences);
int getDataPointsCount(int protocolId);
bool getLicenceInfo(void *ptr);
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
void getLicenceItems();

View File

@@ -2,8 +2,6 @@
#define LICENCE_READER_H_
#include "utils.h"
#include "licenceELC11.h"
#include "licenceELC31.h"
#include "licReaderELC1.h"
#include "licReaderELC2.h"
@@ -31,9 +29,9 @@ public:
string operationErrors = "";
bool argumentsCorrect = false;
ErrorMessage error;
LicenceELC11 *licence11;
LicenceELC31 *licence31;
Licence2 *licence2;
Licence1 *licence1;
LicenceReader();
~LicenceReader();

View File

@@ -1,4 +1,4 @@
0353445355313647801b1a9f6600c747
9f54495344434954615ad803c50171bf
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%

View File

@@ -1,2 +1,2 @@
400e00325b59000076b27f800a404013
400e00325b5900003be77f800a400043

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
output/generate Normal file

Binary file not shown.

5
output/lcis/cis Normal file
View File

@@ -0,0 +1,5 @@
0353445355313647801b1a9f6600c747
6   . x4 <20><><EFBFBD>  .. nt$6 &<26> manfid 6 <20><><EFBFBD>
 cid "6 <10> fwrev 6 Jm<4A>  csd ,6 gEd$
subsystem 46 <20><><EFBFBD>%
driver (6 <20><><EFBFBD>-  ocr -6 <20><><EFBFBD>? power *6 <>4L  type 6 <20>1M  date #6 <20>rTP hwrev )6 n<>yR  dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o  ssr 6 <1E>q  scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD>  name

2
output/lcis/csd Normal file
View File

@@ -0,0 +1,2 @@
400e00325b59000076b27f800a404013

Binary file not shown.

37
output/lcis/licData.xml Normal file
View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>WAGO</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<station>eov.ceskatrebova.ddts.cz</station>
<distributor>eov2</distributor>
<project>Projekt XXX stanice YYY</project>
<items>
<item>
<name>Položka licence 1</name>
<protoId>111</protoId>
<dataPointsCount>100</dataPointsCount>
</item>
<item>
<name>Položka licence 2</name>
<protoId>222</protoId>
<dataPointsCount>200</dataPointsCount>
</item>
<item>
<name>Položka licence 3</name>
<protoId>333</protoId>
<dataPointsCount>300</dataPointsCount>
</item>
<item>
<name>Položka licence 4</name>
<protoId>555</protoId>
<dataPointsCount>666</dataPointsCount>
</item>
<item>
<name>Položka licence 5</name>
<protoId>666</protoId>
<dataPointsCount>9998</dataPointsCount>
</item>
</items>
</licence>

Binary file not shown.

Binary file not shown.

View File

@@ -1,36 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<licence elc="1" xmlVersion="1" revision="1" compatibility="1">
<licence elc="2" xmlVersion="1" revision="1" compatibility="1">
<licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>WAGO</plcType>
<licenceName>Licence pro EOV_OSV</licenceName>
<station>eov.ceskatrebova.ddts.cz</station>
<distributor>eov2</distributor>
<station>odb.zaluzi.drt.cz</station>
<distributor>POZ8</distributor>
<project>Projekt XXX stanice YYY</project>
<items>
<item>
<name>Položka licence 1</name>
<protoId>111</protoId>
<dataPointsCount>100</dataPointsCount>
<dataPointsCount>7454</dataPointsCount>
</item>
<item>
<name>Položka licence 2</name>
<protoId>222</protoId>
<dataPointsCount>200</dataPointsCount>
<dataPointsCount>6477</dataPointsCount>
</item>
<item>
<name>Položka licence 3</name>
<protoId>333</protoId>
<dataPointsCount>300</dataPointsCount>
</item>
<item>
<name>Položka licence 3</name>
<protoId>444</protoId>
<dataPointsCount>1600</dataPointsCount>
</item>
<item>
<name>Položka licence 4</name>
<protoId>555</protoId>
<dataPointsCount>666</dataPointsCount>
<dataPointsCount>7844</dataPointsCount>
</item>
</items>

Binary file not shown.

BIN
output/read Normal file

Binary file not shown.

View File

@@ -1,3 +1,6 @@
#define LINUX 1
//#define WINDOWS 1
#include <stdio.h>
#include "licenceGenerator.h"
@@ -5,7 +8,7 @@
/// @param argc
/// @param argv parametry pro generování licence
/// @return
int main(int argc, char *argv[])
int main6(int argc, char *argv[])
{
unordered_map<string, string> arguments = getArguments(argc, argv);
try

View File

@@ -1,92 +1,115 @@
#include <stdio.h>
#include "utils.h"
#include "licenceReader.h"
#define LINUX 1
// #define WINDOWS 1
#include <stdio.h>
#include "licenceReader.h"
/// @brief hlavní funkce
/// @param argc
/// @param argv parametry pro generování licence
/// @return
int main5()
int main()
{
// 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();
// system("pause");
// return SUCCES;
// }
// catch (...)
// {
// cerr << "Obecná chyba\n";
// }
// system("pause");
// return SUCCES;
try
{
int protocolId = 444;
LicenceReader licenceReader1 {};
InitStructure initStructure;
initStructure.licenceType = (int)LicenceType::EOS_EOV;
initStructure.licenceVersion = 1;
initStructure.licenceIndex = 0;
initStructure.compatibility = 1;
initStructure.licenceFilePath = "";
initStructure.cid_csd_filePath = "";
initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru
// initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
// pro ELC 1 LicenceELC1Info s výstupem isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; }
initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontorlu licence
cout << "-- verze #1: init a iterace" << "\n";
//verze #1: načtení kompletní licence a zobrazení
if (licenceReader1.init(2, initStructure))
// verze původní ELC 1
LicenceReader licenceReaderELC1{};
if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
{
LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
if (licenceReader1.getLicenceInfo(&info))
LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
if (licenceReaderELC1.getLicenceInfo(&info))
{
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 cout << "Došlo k chybě: " << licenceReader1.error.message;
}
else
{
cout << "Došlo k chybě: " << licenceReader1.error.message;
}
cout << "\n" << "-- verze #2: init a iterace" << "\n";
//verze #2 : iterace pro kazdý bod zvlášť
LicenceReader licenceReader2 {};
if (licenceReader2.initread(2, initStructure))
{
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
if (licenceReader2.getLicenceItemInfo(protocolId, &info))
{
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
if (info.isValid)
cout << "Platna licence ELC1 \n";
else
cout << "Neplatna licence ELC1\n";
}
else
cout << "Došlo k chybě: " << licenceReader2.error.message;
cout << "CHYBA: " << licenceReaderELC1.error.message;
}
else
{
cout << "Došlo k chybě: " << licenceReader2.error.message;
cout << "CHYBA: " << licenceReaderELC1.error.message;
}
// verze ELC 2 pro jeden protokol
LicenceReader licenceReaderELC2{};
if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni
{
// v případě kompatibility 0, či nezadané výstup nativně je defaultní.
// v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility. Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
// if ()
int protocolId = 333;
// if (initStructure.compatibility == 1) //ukazka kompatibilita
// {
// LicenceELC2Item_1 info; //jiná struktura, zbytek stejný
// if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
// {
// cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
// }
//...........
// }
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
{
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
}
else
cout << "CHYBA: " << licenceReaderELC2.error.message;
}
else
{
cout << "CHYBA: " << licenceReaderELC2.error.message;
}
LicenceReader licenceReaderCompleteELC2{};
// verze ELC 2 kompletní načtení
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
{
LicenceELC2Info info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
int protocolId = 333;
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
{
if (info.licences.count(protocolId) > 0)
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
else
cout << "Pro tento protokol nejsou definovay licencni body\n";
cout << "Vypis vsech licencnich bodu: " << endl;
for (const auto &pair : info.licences)
{
std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
}
}
else
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
}
else
{
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
}
}
catch (...)
{
cout << "Obecná chyba\n";
cout << "Obecna chyba\n";
}
system("pause");
// system("pause");
return SUCCES;
}
// cid: 0353445355313647801b1a9f6600c747 csd: 400e00325b59000076b27f800a404013
// https://sprava.app.elzel.cz/device/417 cid: 9f54495344434954615ad803c50171bf csd: 400e00325b5900003be77f800a400043

View File

@@ -8,20 +8,24 @@ SDCard::SDCard()
SDCard::SDCard(const string cds_cid_Path)
{
this->filePath = cds_cid_Path;
if (getCIDFromFile() == false) return;
if (getCSDFromFile() == false) return;
if (getCIDFromFile() == false)
return;
if (getCSDFromFile() == false)
return;
this->isLoaded = SDCard::readSDCard();
}
SDCard::SDCard(string cid, string csd)
{
for (unsigned int i = 0; i < cid.length(); i++) this->cid[i] = cid[i];
for (unsigned int i = 0; i < csd.length(); i++) this->csd[i] = csd[i];
for (unsigned int i = 0; i < cid.length(); i++)
this->cid[i] = cid[i];
for (unsigned int i = 0; i < csd.length(); i++)
this->csd[i] = csd[i];
this->isLoaded = SDCard::readSDCard();
}
bool SDCard:: readSDCard()
bool SDCard::readSDCard()
{
BYTE cHexNibbleToNo[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -99,7 +103,6 @@ bool SDCard:: readSDCard()
this->cardData.CRCOK = ((sdCrc << 1) | 1) == this->cardData.CID[15];
this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1);
return this->cardData.crcCorrect;
}
bool SDCard::getCIDFromFile()
@@ -109,11 +112,14 @@ bool SDCard::getCIDFromFile()
{
return false;
}
if (content.size() >= 32)
if (content.size() >= CID_LENGTH)
{
for (int i = 0; i<32;i++) this->cid[i] = content[i];
for (int i = 0; i < 32; i++)
this->cid[i] = content[i];
}
else return false;
else
return false;
return true;
}
@@ -125,11 +131,13 @@ bool SDCard::getCSDFromFile()
{
return false;
}
if (content.size() >= 32)
if (content.size() >= CSD_LENGTH)
{
for (int i = 0; i<32;i++) this->csd[i] = content[i];
for (int i = 0; i < 32; i++)
this->csd[i] = content[i];
}
else return false;
else
return false;
return true;
}

Binary file not shown.

View File

@@ -58,8 +58,7 @@ LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentifica
bool LicenceELC1::getSDData()
{
for (int i = 0; i < CID_LENGTH; i++)
this->sdData.CID_nibble[i] = (BYTE)cid[i];
for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
for (int i = 0; i < cnibblescount / 2; i++)
{
@@ -91,12 +90,10 @@ bool LicenceELC1::getSDData()
this->sdData.manufacturerDate[i] = date[i];
// CSD
for (unsigned int i = 0; i < CSD_LENGTH; i++)
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
for (unsigned int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
for (unsigned int i = 0; i < cnibblescount / 2; i++)
{
//
this->sdData.CSD[i] = cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i + 1]];
}
@@ -104,10 +101,6 @@ bool LicenceELC1::getSDData()
{
this->sdData.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9];
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
if (this->sdData.cardSize > 17200) // TODO result.cardSize
{
}
}
BYTE sdCrc = 0;
@@ -189,10 +182,6 @@ string LicenceELC1::getLicenceName(BYTE licPostfix)
string result = "";
char prefixChar = 97;
if (licPostfix > 9) // chyba
{
}
if (licType == PlcLicenceType::LicenceOther)
{
result = "ezlic_";

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,6 @@
#include <openssl/ssl.h> /* core library */
#include "utils.h"
using namespace std;
const std::string base64_chars =
@@ -26,7 +25,7 @@ void getCharsFromString(string &source, char *charArray, size_t length)
void getCharsFromString(string source, char *charArray)
{
size_t length = source.length();
size_t length = source.length();
for (size_t i = 0; i < length; i++)
{
charArray[i] = source[i];
@@ -117,8 +116,8 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
int ciphertext_len;
/* Create and initialise the context */
if (!(ctx = EVP_CIPHER_CTX_new())) return -1;
if (!(ctx = EVP_CIPHER_CTX_new()))
return -1;
/*
* Initialise the encryption operation. IMPORTANT - ensure you use a key
@@ -180,7 +179,7 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
* EVP_DecryptUpdate can be called multiple times if necessary.
*/
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
return -1;
return -1;
plaintext_len = len;
/*
@@ -188,7 +187,7 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
* this stage.
*/
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
return -1;
return -1;
plaintext_len += len;
@@ -316,17 +315,17 @@ string getCompletePath(string fileName)
#ifdef WINDOWS
return fileName;
#else
//warning TODO filesystem
char path[PATH_MAX+1] = {};
ssize_t length = readlink("/proc/self/exe", path, PATH_MAX);
path[length] = '\0';
string result = string(dirname(path)) + "/" + fileName;
return result;
//return std::string( result, (count > 0) ? count : 0 );
// std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0]));
// std::filesystem::path fullPathOther = exePath.parent_path() / fileName;
// std::string fullPathStrOther = fullPathOther.string();
// return fullPathStrOther;
char path[PATH_MAX + 1] = {};
ssize_t length = readlink("/proc/self/exe", path, PATH_MAX);
path[length] = '\0';
string result = string(dirname(path)) + "/" + fileName;
return result;
// return std::string( result, (count > 0) ? count : 0 );
// std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0]));
// std::filesystem::path fullPathOther = exePath.parent_path() / fileName;
// std::string fullPathStrOther = fullPathOther.string();
// return fullPathStrOther;
#endif
}
@@ -390,7 +389,7 @@ std::vector<unsigned char> joinVectors(const std::vector<unsigned char> &vector1
bool readFile(string fileName, vector<char> &output)
{
std::ifstream file(fileName, std::ios::in | std::ios::binary);
if (file.is_open() != 1)
{
return false;

Binary file not shown.

View File

@@ -1,9 +1,8 @@
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/licGenELC1.h include/common/utils.h \
include/common/licenceELC1.h include/common/licenceCommon.h \
include/common/SDCard.h include/generator/licGenELC2.h \
include/common/licenceELC2.h include/generator/licGenELC3.h
include/common/SDCard.h include/common/SDCard.h \
include/generator/licGenELC2.h include/common/licenceELC2.h \
include/generator/licGenELC3.h include/generator/pugixml.hpp

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -13,109 +13,10 @@ 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ů
/// @brief provede pouze inicialazaci čtecí třídy
/// @param elcType
/// @param licenceType
/// @param licenceVersion
/// @param licenceIndex
/// @param compatibility
/// @param initStructure
/// @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
@@ -142,39 +43,128 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure)
elcSwitchType = elcType * 10 + licCompatibility;
return true;
}
/// @brief provede inicializaci čtecí třídy a zároveň načte licenční body do obecné struktury
/// @param elcType
/// @param licenceType
/// @param licenceVersion
/// @param licenceIndex
/// @param compatibility
/// @return
bool LicenceReader::initread(int elcType, InitStructure &initStructure)
{
try
{
elcSwitchType = elcType * 10 + initStructure.compatibility;
if (init(elcType, initStructure))
{
switch (this->licIdentification.licElcType)
{
case ELCType::ELC1:
{ // old eoseov
Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification);
this->licence1 = &licenceELC1;
licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath;
licenceELC1.licenceFilePath = initStructure.licenceFilePath;
try
{
this->licence1->readLicence(&this->licenceInfo);
}
catch (const LicenceException &ex)
{
error.code = ex.getErrorCode();
error.message = ex.getErrorMessage();
return false;
}
break;
}
case ELCType::ELC2:
{
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 ELCType::ELC3:
{
break;
}
default:
throw LicenceException((int)GeneralError::ELCNotImplemented, "Toto ELC není implementováno");
}
}
else
return false;
}
catch (const LicenceException &ex)
{
error.code = ex.getErrorCode();
error.message = ex.getErrorMessage();
return false;
}
return true; // TODO testy
}
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
/// @param protocolId
/// @param returnItemStructure
/// @return
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
{
try
{
switch (elcSwitchType)
switch (this->licIdentification.licElcType)
{
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);
case ELCType::ELC1:
{
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnItemStructure);
if (this->licenceInfo.licences.count(1)) // stare eov má natvrdo "id" 1.
resultPtr->isValid = true;
else
resultPtr->isValid = false;
}
else
resultPtr->dataPointsCount = 0;
{
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
}
break;
}
case 21:
case ELCType::ELC2:
{
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure);
resultPtr->protocolId = protocolId; // protocolId;
if (this->licenceInfo.licences.count(protocolId))
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{
LicenceELC2Item *resultPtr = static_cast<LicenceELC2Item *>(returnItemStructure);
resultPtr->protocolId = protocolId; // protocolId;
if (this->licenceInfo.licences.count(protocolId))
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
else
resultPtr->dataPointsCount = 0;
}
else
resultPtr->dataPointsCount = 0;
{
switch (this->licIdentification.licCompatibility)
{
case 1:
// kod pro kompatibilitu 1
break;
default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break;
}
}
break;
}
case 31:
case ELCType::ELC3:
{
LicenceELC31 licence = LicenceELC31(this->licIdentification);
break;
}
default:
@@ -195,66 +185,79 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
return true;
}
/// @brief vrací informace o všech licenčních bodech základě předané návratové struktury
/// @param returnStructure
/// @return
bool LicenceReader::getLicenceInfo(void *returnStructure)
{
// const type_info& ti1 = typeid(returnStructure);
// cout << "TTTYP: " << ti1.name() << endl;
switch (elcSwitchType)
try
{
case 11:
{ // old eoseov
break;
}
case 21:
{
try
switch (this->licIdentification.licElcType)
{
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
licenceELC2.readLicence(&this->licenceInfo);
return licenceELC2.getLicenceInfo(returnStructure);
case ELCType::ELC1:
{ // old eoseov
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{
LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnStructure);
if (this->licenceInfo.licences.count(1)) // starý EOS má natvrdo "id" 1
{
resultPtr->isValid = true;
}
else
{
resultPtr->isValid = false;
}
}
else
{
switch (this->licIdentification.licCompatibility)
{
case 1:
// kod pro kompatibilitu 1
break;
default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break;
}
}
break;
}
catch (const LicenceException &ex)
case ELCType::ELC2:
{
error.code = ex.getErrorCode();
error.message = ex.getErrorMessage();
return false;
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
{
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
licenceELC2.readLicence(&this->licenceInfo);
licenceELC2.getLicenceInfo(returnStructure);
}
else
{
switch (this->licIdentification.licCompatibility)
{
case 1:
// kod pro kompatibilitu 1
break;
default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break;
}
}
break;
}
case ELCType::ELC3:
{
break;
}
}
// 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:
catch (const LicenceException &ex)
{
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 = ex.getErrorCode();
error.message = ex.getErrorMessage();
return false;
}
}
error.code = -1;
error.message = "Nepodařilo se identifikovat licenci";
return false;
return true;
}
LicenceReader::~LicenceReader()

View File

@@ -1,8 +1,7 @@
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
include/reader/licReaderELC1.h include/common/licenceCommon.h \
include/common/licenceELC1.h include/common/licenceCommon.h \
include/common/SDCard.h include/common/SDCard.h \
include/reader/licReaderELC2.h include/common/licenceELC2.h \
include/reader/licReaderELC3.h

Binary file not shown.

View File

@@ -2,5 +2,123 @@
namespace Reader
{
Licence1::Licence1() {}
Licence1::~Licence1() {}
Licence1::Licence1(LicenceIdentification &licIdentification) : LicenceELC1(licIdentification)
{
}
/// @brief načte seznam licenčních bodů do obecné struktury
/// @param licences
/// @return
bool Licence1::readLicence(LicenceInfoGeneral *licences)
{
sdCard = SDCard(this->cid_cdsPath);
if (sdCard.isLoaded == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
for (unsigned int i = 0; i < CID_LENGTH;i++) this->cid[i] = sdCard.cid[i];
for (unsigned int i = 0; i < CSD_LENGTH;i++) this->csd[i] = sdCard.csd[i];
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
string licFileName = getLicenceName(0);
string licFilePath = this->licenceFilePath + licFileName;
char licFileNameToRead[licFilePath.length()+1] = {};
getCharsFromString(licFilePath, licFileNameToRead, licFilePath.length());
FILE *licenceFile;
char ch;
licenceFile = fopen(licFileNameToRead, "rb");
if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath);
fseek(licenceFile, 0, SEEK_END);
const int size = ftell(licenceFile);
fseek(licenceFile, 0, SEEK_SET);
if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath);
int count = 0;
unsigned char licenceContent[size];
for (int i = 0; i < size; i++)
{
ch = fgetc(licenceFile);
licenceContent[i] = ch;
count++;
}
fclose(licenceFile);
LicenceDataMainELC licenceHeader{};
LicenceData licEncryptedData{};
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)
{
throw LicenceException((int)GeneralError::LicenceSizeMismatch, "License size mismatch ");
}
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.header.licCount > 0)
{
for (int i = 0; i < licMaxCount; i++)
{
licences->licences.insert(pair<int, int>(licEncryptedData.items[i].protoId, licEncryptedData.items[i].licCount));
}
}
else
{
throw LicenceException((int)GeneralError::ItemsCountMismatch, "ItemsCountMismatch");
}
}
}
else
{
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
}
}
}
}
else
{
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
}
}
else
{
throw LicenceException((int)GeneralError::LicenceReadError, "Licence error");
}
return true;
}
}

View File

@@ -1,2 +1,5 @@
src/reader/licReaderELC1.o: src/reader/licReaderELC1.cpp \
include/reader/licReaderELC1.h
include/reader/licReaderELC1.h include/common/utils.h \
include/common/licenceCommon.h include/common/licenceELC1.h \
include/common/licenceCommon.h include/common/SDCard.h \
include/common/SDCard.h

Binary file not shown.

View File

@@ -3,15 +3,15 @@
namespace Reader
{
Licence2::Licence2(){}
Licence2::Licence2() {}
Licence2::~Licence2(){}
Licence2::~Licence2() {}
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification)
{
}
/// @brief načte licence do obecné struktury ELC2
/// @brief načte seznam licenčních bodů do obecné struktury
/// @param licences
/// @return
bool Licence2::readLicence(LicenceInfoGeneral *licences)
@@ -90,23 +90,23 @@ namespace Reader
}
bool Licence2::getLicenceInfo(void *returnStructure)
{
if (returnStructure != nullptr)
{
LicenceInfo21 *resultPtr = static_cast<LicenceInfo21 *>(returnStructure);
for (auto item : this->licBody.privateContent.dataItems)
if (returnStructure != nullptr)
{
resultPtr->licences.insert(pair<int, int>(item.protoId, item.licCount));
LicenceELC2Info *resultPtr = static_cast<LicenceELC2Info *>(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;
}
}
else
{
errorMessage.code = 1;
errorMessage.message = "Error: Null pointer!";
return false;
}
return true;
}
return true;
}
}

Binary file not shown.

Binary file not shown.