oddělení, čištění, kontrola ELC1

This commit is contained in:
2024-02-05 15:04:22 +01:00
parent 5229f16c9d
commit 37d02abd3f
54 changed files with 368 additions and 374 deletions

View File

@@ -8,7 +8,7 @@ CXX = g++
# define any compile-time flags # define any compile-time flags
# CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w # CXXFLAGS := -std=c++17 -Wall -Wextra -g -lssl -lcrypto -w
CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto -w CXXFLAGS := -Wall -Wextra -g -lssl -lcrypto
# define library paths in addition to /usr/lib # define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify # if I wanted to include libraries not in /usr/lib I'd specify

View File

@@ -11,6 +11,12 @@ RUN chmod 755 /app/start.sh
COPY ./startok.sh /app/ COPY ./startok.sh /app/
RUN chmod 755 /app/startok.sh 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/ COPY ./Makefile /app/
ENTRYPOINT ["tail"] 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 #!/bin/bash
chmod 777 output/licenceGenerator 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 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

@@ -47,15 +47,6 @@ enum class GeneralError
ItemsCountMismatch = 61 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 enum class ELCType
{ {
ELC1 = 1, ELC1 = 1,
@@ -120,14 +111,19 @@ struct LicenceIdentification
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
uint8_t licenceIndex = 0; uint8_t licenceIndex = 0;
uint8_t revision; 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; uint16_t licItemsCount = 0;
string cid_cds_path = ""; string cid_cds_path = "";
string licenceFilePath = ""; string licenceFilePath = "";
}; };
/// @brief obecná struktura pro reader
struct LicenceInfoGeneral
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief obecná struktura polozky licence, defaultní kompatibilita /// @brief obecná struktura polozky licence, defaultní kompatibilita
struct LicenceItem struct LicenceItem
{ {
@@ -135,103 +131,54 @@ struct LicenceItem
int dataPointsCount = 0; int dataPointsCount = 0;
}; };
/// @brief struktura polozky licence, kompatibilita 1 /* struktury pro ELC 1 */
struct LicenceItemCompatibility1 //defaultní struktura pro ELC 1
{ struct LicenceELC1Info
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 2
struct LicenceItemCompatibility2
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 3
struct LicenceItemCompatibility3
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem11
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem21
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem31
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief základní struktura, seznam polozek licencí
struct LicenceInfo
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
struct LicenceInfoCompatibility1
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 2
struct LicenceInfoCompatibility2
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
struct LicenceInfoCompatibility3
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
struct LicenceInfo1
{ {
bool isValid {false}; bool isValid {false};
}; };
struct LicenceInfo11 //struktura ELC1, kompatibilita 1
struct LicenceELC1Info_1
{ {
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {}; unordered_map<int, int> licences = {};
}; };
struct LicenceInfo21 //defaultni struktura polozky licence ELC 1
struct LicenceELC1Item
{
int protocolId = -1;
int dataPointsCount = 0;
};
/* struktury pro ELC 2 */
//defaultní struktura pro ELC 2
struct LicenceELC2Info
{ {
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {}; unordered_map<int, int> licences = {};
}; };
struct LicenceInfo31 struct LicenceELC2Info_1
{ {
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {}; unordered_map<int, int> licences = {};
}; };
struct LicenceInfoGeneral //defaultni struktura polozky ELC 2
struct LicenceELC2Item
{ {
int reqDataPointsCount = 0; int protocolId = -1;
unordered_map<int, int> licences = {}; int dataPointsCount = 0;
}; };
//struktura polozky ELC 2,
struct LicenceELC2Item_1
{
int protocolId = -1;
int dataPointsCount = 0;
};
class LicenceException : public std::exception class LicenceException : public std::exception
{ {
public: public:

View File

@@ -1,6 +1,3 @@
//#define LINUX 1
#define WINDOWS 1
#ifndef UTILS_H_ #ifndef UTILS_H_
#define UTILS_H_ #define UTILS_H_
@@ -12,6 +9,7 @@
#include <format> #include <format>
#include <libgen.h> // dirname #include <libgen.h> // dirname
#include <climits> #include <climits>
#include <unistd.h>
typedef uint8_t BYTE; typedef uint8_t BYTE;
typedef uint16_t WORD; typedef uint16_t WORD;

View File

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

View File

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

View File

@@ -14,7 +14,7 @@ namespace Reader
{ {
public: public:
LicenceInfo21 licenceInfo; LicenceELC1Info licenceInfo;
Licence1(); Licence1();
~Licence1(); ~Licence1();

View File

@@ -13,15 +13,13 @@ namespace Reader
class Licence2 : public LicenceELC2 class Licence2 : public LicenceELC2
{ {
public: public:
LicenceInfo21 licenceInfo; LicenceELC2Info licenceInfo;
Licence2(); Licence2();
~Licence2(); ~Licence2();
Licence2(LicenceIdentification &licIdentification); Licence2(LicenceIdentification &licIdentification);
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); bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
void getLicenceItems(); void getLicenceItems();

View File

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

View File

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

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.

View File

@@ -1,36 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?> <?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> <licenceType licenceVersion="1" licenceIndex="0">EOV_OSV</licenceType>
<plcType>WAGO</plcType> <plcType>WAGO</plcType>
<licenceName>Licence pro EOV_OSV</licenceName> <licenceName>Licence pro EOV_OSV</licenceName>
<station>eov.ceskatrebova.ddts.cz</station> <station>odb.zaluzi.drt.cz</station>
<distributor>eov2</distributor> <distributor>POZ8</distributor>
<project>Projekt XXX stanice YYY</project> <project>Projekt XXX stanice YYY</project>
<items> <items>
<item> <item>
<name>Položka licence 1</name> <name>Položka licence 1</name>
<protoId>111</protoId> <protoId>111</protoId>
<dataPointsCount>100</dataPointsCount> <dataPointsCount>7454</dataPointsCount>
</item> </item>
<item> <item>
<name>Položka licence 2</name> <name>Položka licence 2</name>
<protoId>222</protoId> <protoId>222</protoId>
<dataPointsCount>200</dataPointsCount> <dataPointsCount>6477</dataPointsCount>
</item> </item>
<item> <item>
<name>Položka licence 3</name> <name>Položka licence 3</name>
<protoId>333</protoId> <protoId>333</protoId>
<dataPointsCount>300</dataPointsCount> <dataPointsCount>7844</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>
</item> </item>
</items> </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 <stdio.h>
#include "licenceGenerator.h" #include "licenceGenerator.h"
@@ -5,7 +8,7 @@
/// @param argc /// @param argc
/// @param argv parametry pro generování licence /// @param argv parametry pro generování licence
/// @return /// @return
int main5(int argc, char *argv[]) int main6(int argc, char *argv[])
{ {
unordered_map<string, string> arguments = getArguments(argc, argv); unordered_map<string, string> arguments = getArguments(argc, argv);
try try

View File

@@ -1,3 +1,6 @@
#define LINUX 1
// #define WINDOWS 1
#include <stdio.h> #include <stdio.h>
#include "licenceReader.h" #include "licenceReader.h"
@@ -13,15 +16,16 @@ int main()
initStructure.licenceType = (int)LicenceType::EOS_EOV; initStructure.licenceType = (int)LicenceType::EOS_EOV;
initStructure.licenceVersion = 1; initStructure.licenceVersion = 1;
initStructure.licenceIndex = 0; initStructure.licenceIndex = 0;
initStructure.compatibility = 1; initStructure.licenceFilePath = ""; // cesta k licenčnímu souboru
initStructure.licenceFilePath = ""; // initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
initStructure.cid_csd_filePath = ""; // 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
// verze původní ELC 1 // verze původní ELC 1
LicenceReader licenceReaderELC1{}; LicenceReader licenceReaderELC1{};
if (licenceReaderELC1.initread(1, initStructure)) //iniciacni nacteni if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
{ {
LicenceInfo1 info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
if (licenceReaderELC1.getLicenceInfo(&info)) if (licenceReaderELC1.getLicenceInfo(&info))
{ {
if (info.isValid) if (info.isValid)
@@ -40,10 +44,23 @@ int main()
// verze ELC 2 pro jeden protokol // verze ELC 2 pro jeden protokol
LicenceReader licenceReaderELC2{}; LicenceReader licenceReaderELC2{};
if (licenceReaderELC2.initread(2, initStructure)) //iniciacni nacteni if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni
{ {
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) // v případě kompatibility 0, či nezadané výstup nativně je defaultní.
int protocolId = 444; // 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)) if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
{ {
@@ -60,15 +77,17 @@ int main()
LicenceReader licenceReaderCompleteELC2{}; LicenceReader licenceReaderCompleteELC2{};
// verze ELC 2 kompletní načtení // verze ELC 2 kompletní načtení
if (licenceReaderCompleteELC2.init(2, initStructure)) //iniciacni nacteni if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
{ {
LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31) LicenceELC2Info info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
int protocolId = 333; int protocolId = 333;
if (licenceReaderCompleteELC2.getLicenceInfo(&info)) if (licenceReaderCompleteELC2.getLicenceInfo(&info))
{ {
if (info.licences.count(protocolId) > 0) cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n"; if (info.licences.count(protocolId) > 0)
else cout << "Pro tento protokol nejsou definovay licencni body\n"; 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; cout << "Vypis vsech licencnich bodu: " << endl;
for (const auto &pair : info.licences) for (const auto &pair : info.licences)
{ {
@@ -91,3 +110,6 @@ int main()
// system("pause"); // system("pause");
return SUCCES; return SUCCES;
} }
// cid: 0353445355313647801b1a9f6600c747 csd: 400e00325b59000076b27f800a404013
// https://sprava.app.elzel.cz/device/417 cid: 9f54495344434954615ad803c50171bf csd: 400e00325b5900003be77f800a400043

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,6 @@
#include <openssl/ssl.h> /* core library */ #include <openssl/ssl.h> /* core library */
#include "utils.h" #include "utils.h"
using namespace std; using namespace std;
const std::string base64_chars = const std::string base64_chars =
@@ -117,8 +116,8 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
int ciphertext_len; int ciphertext_len;
/* Create and initialise the context */ /* 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 * 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. * EVP_DecryptUpdate can be called multiple times if necessary.
*/ */
if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) if (1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
return -1; return -1;
plaintext_len = len; plaintext_len = len;
/* /*
@@ -188,7 +187,7 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
* this stage. * this stage.
*/ */
if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) if (1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
return -1; return -1;
plaintext_len += len; plaintext_len += len;
@@ -316,17 +315,17 @@ string getCompletePath(string fileName)
#ifdef WINDOWS #ifdef WINDOWS
return fileName; return fileName;
#else #else
//warning TODO filesystem
char path[PATH_MAX+1] = {}; char path[PATH_MAX + 1] = {};
ssize_t length = readlink("/proc/self/exe", path, PATH_MAX); ssize_t length = readlink("/proc/self/exe", path, PATH_MAX);
path[length] = '\0'; path[length] = '\0';
string result = string(dirname(path)) + "/" + fileName; string result = string(dirname(path)) + "/" + fileName;
return result; return result;
//return std::string( result, (count > 0) ? count : 0 ); // 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 exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0]));
// std::filesystem::path fullPathOther = exePath.parent_path() / fileName; // std::filesystem::path fullPathOther = exePath.parent_path() / fileName;
// std::string fullPathStrOther = fullPathOther.string(); // std::string fullPathStrOther = fullPathOther.string();
// return fullPathStrOther; // return fullPathStrOther;
#endif #endif
} }

Binary file not shown.

View File

@@ -1,9 +1,8 @@
src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \ src/generator/LicenceGenerator.o: src/generator/LicenceGenerator.cpp \
include/generator/licenceGenerator.h include/generator/pugixml.hpp \ include/generator/licenceGenerator.h include/generator/pugixml.hpp \
include/generator/pugiconfig.hpp include/common/licenceCommon.h \ include/generator/pugiconfig.hpp include/common/licenceCommon.h \
include/licenceELC11.h include/common/SDCard.h include/licenceELC21.h \ include/generator/licGenELC1.h include/common/utils.h \
include/common/utils.h include/generator/pugixml.hpp \
include/licenceELC31.h include/generator/licGenELC1.h \
include/common/licenceELC1.h include/common/licenceCommon.h \ include/common/licenceELC1.h include/common/licenceCommon.h \
include/common/SDCard.h include/generator/licGenELC2.h \ include/common/SDCard.h include/common/SDCard.h \
include/common/licenceELC2.h include/generator/licGenELC3.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,118 +13,10 @@ LicenceReader::LicenceReader()
{ {
} }
// LicenceReader::LicenceReader(string uid, string cid, string csd, string dataFileName) /// @brief provede pouze inicialazaci čtecí třídy
// {
// 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ů do obecné struktury
/// @param elcType /// @param elcType
/// @param licenceType /// @param initStructure
/// @param licenceVersion
/// @param licenceIndex
/// @param compatibility
/// @return /// @return
bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
{
try
{
elcSwitchType = elcType * 10 + licCompatibility;
if (init(elcType, initStructure))
{
switch (elcSwitchType)
{
case 11:
{ // 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 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) bool LicenceReader::init(int elcType, InitStructure &initStructure)
{ {
try try
@@ -154,6 +46,72 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure)
return true; 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 /// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
/// @param protocolId /// @param protocolId
/// @param returnItemStructure /// @param returnItemStructure
@@ -162,28 +120,51 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
{ {
try try
{ {
switch (elcSwitchType) switch (this->licIdentification.licElcType)
{ {
case 11: case ELCType::ELC1:
{ {
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnItemStructure); if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
if (this->licenceInfo.licences.count(1)) resultPtr->isValid = true; //stare eov melo natvrdo "id" 1. {
else resultPtr->isValid = false; LicenceELC1Info *resultPtr = static_cast<LicenceELC1Info *>(returnItemStructure);
break; if (this->licenceInfo.licences.count(1)) // stare eov má natvrdo "id" 1.
} resultPtr->isValid = true;
case 21: else
{ resultPtr->isValid = false;
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure); }
resultPtr->protocolId = protocolId; // protocolId;
if (this->licenceInfo.licences.count(protocolId))
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
else else
resultPtr->dataPointsCount = 0; {
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
}
break; break;
} }
case 31: case ELCType::ELC2:
{
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
{
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:
{ {
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
break; break;
} }
default: default:
@@ -211,66 +192,61 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
{ {
try try
{ {
switch (elcSwitchType) switch (this->licIdentification.licElcType)
{ {
case 11: case ELCType::ELC1:
{ // old eoseov { // old eoseov
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnStructure);
if (this->licenceInfo.licences.count(1))
{ {
resultPtr->isValid = true; 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 else
{ {
resultPtr->isValid = false; switch (this->licIdentification.licCompatibility)
{
case 1:
// kod pro kompatibilitu 1
break;
default:
LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
break;
}
} }
return true;
break; break;
} }
case 21: case ELCType::ELC2:
{ {
if (!this->licIdentification.licCompatibility) // defaultní kompatibilita
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification); {
licenceELC2.readLicence(&this->licenceInfo); Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
return licenceELC2.getLicenceInfo(returnStructure); licenceELC2.readLicence(&this->licenceInfo);
licenceELC2.getLicenceInfo(returnStructure);
// catch (const LicenceException &ex) }
// { else
// error.code = ex.getErrorCode(); {
// error.message = ex.getErrorMessage(); switch (this->licIdentification.licCompatibility)
// return false; {
// } case 1:
// kod pro kompatibilitu 1
// LicenceELC21 licence = LicenceELC21(this->licIdentification); break;
// try default:
// { LicenceException((int)GeneralError::CompatibilityTypeNotImplemented, "Kompatibilita není implementována.");
// licence.readLicence(&this->licenceInfo); break;
// return licence.getLicenceInfo(returnStructure); }
// } }
// catch (const LicenceException &ex)
// {
// error.code = ex.getErrorCode();
// error.message = ex.getErrorMessage();
// return false;
// }
break; break;
} }
case 31: case ELCType::ELC3:
{ {
// 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; break;
} }
} }
@@ -281,6 +257,7 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
error.message = ex.getErrorMessage(); error.message = ex.getErrorMessage();
return false; return false;
} }
return true;
} }
LicenceReader::~LicenceReader() LicenceReader::~LicenceReader()

Binary file not shown.

View File

@@ -10,6 +10,9 @@ namespace Reader
{ {
} }
/// @brief načte seznam licenčních bodů do obecné struktury
/// @param licences
/// @return
bool Licence1::readLicence(LicenceInfoGeneral *licences) bool Licence1::readLicence(LicenceInfoGeneral *licences)
{ {
sdCard = SDCard(this->cid_cdsPath); sdCard = SDCard(this->cid_cdsPath);
@@ -20,11 +23,6 @@ namespace Reader
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath); if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
for (unsigned int i = 0; i < sdCard.cidString.length(); i++)
this->cid[i] = sdCard.cidString[i]; // nutné pro původní algoritmus
for (unsigned int i = 0; i < sdCard.csdString.length(); i++)
this->csd[i] = sdCard.csdString[i]; // nutné pro původní algoritmus
string licFileName = getLicenceName(0); string licFileName = getLicenceName(0);
string licFilePath = this->licenceFilePath + licFileName; string licFilePath = this->licenceFilePath + licFileName;
@@ -34,12 +32,12 @@ namespace Reader
FILE *licenceFile; FILE *licenceFile;
char ch; char ch;
licenceFile = fopen(licFileNameToRead, "rb"); // read mode licenceFile = fopen(licFileNameToRead, "rb");
if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath); if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath);
fseek(licenceFile, 0, SEEK_END); // seek to end of file fseek(licenceFile, 0, SEEK_END);
const int size = ftell(licenceFile); // get current file pointer const int size = ftell(licenceFile);
fseek(licenceFile, 0, SEEK_SET); fseek(licenceFile, 0, SEEK_SET);
if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath); if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath);
@@ -75,7 +73,7 @@ namespace Reader
if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10) if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10)
{ {
initCrypto(); initCrypto();
// CryptData cryptData = initCrypto(sdData, licIdent.licIDType);
unsigned char decrypted[2000] = {}; unsigned char decrypted[2000] = {};
int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted); int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted);
@@ -85,7 +83,6 @@ namespace Reader
} }
else else
{ {
// memset(&licEncryptedData, 0, sizeof(licEncryptedData));
memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData)); memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData));
if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10) if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10)
@@ -101,7 +98,7 @@ namespace Reader
} }
else else
{ {
throw LicenceException((int)GeneralError::LicenceSizeCardMismatch, "Size card info mismatch"); throw LicenceException((int)GeneralError::ItemsCountMismatch, "ItemsCountMismatch");
} }
} }
} }

Binary file not shown.

View File

@@ -3,15 +3,15 @@
namespace Reader namespace Reader
{ {
Licence2::Licence2(){} Licence2::Licence2() {}
Licence2::~Licence2(){} Licence2::~Licence2() {}
Licence2::Licence2(LicenceIdentification &licIdentification) : LicenceELC2(licIdentification) 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 /// @param licences
/// @return /// @return
bool Licence2::readLicence(LicenceInfoGeneral *licences) bool Licence2::readLicence(LicenceInfoGeneral *licences)
@@ -90,23 +90,23 @@ namespace Reader
} }
bool Licence2::getLicenceInfo(void *returnStructure) bool Licence2::getLicenceInfo(void *returnStructure)
{
if (returnStructure != nullptr)
{ {
LicenceInfo21 *resultPtr = static_cast<LicenceInfo21 *>(returnStructure); if (returnStructure != nullptr)
for (auto item : this->licBody.privateContent.dataItems)
{ {
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
else {
{ errorMessage.code = 1;
errorMessage.code = 1; errorMessage.message = "Error: Null pointer!";
errorMessage.message = "Error: Null pointer!"; return false;
return false; }
return true;
} }
return true;
}
} }

Binary file not shown.

Binary file not shown.