oddeleni a lazeni ELC1
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -178,52 +179,57 @@ struct LicenceItem31
|
|||||||
struct LicenceInfo
|
struct LicenceInfo
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||||
struct LicenceInfoCompatibility1
|
struct LicenceInfoCompatibility1
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 2
|
||||||
struct LicenceInfoCompatibility2
|
struct LicenceInfoCompatibility2
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
|
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
|
||||||
struct LicenceInfoCompatibility3
|
struct LicenceInfoCompatibility3
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LicenceInfo1
|
||||||
|
{
|
||||||
|
bool isValid {false};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceInfo11
|
struct LicenceInfo11
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceInfo21
|
struct LicenceInfo21
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceInfo31
|
struct LicenceInfo31
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LicenceInfoGeneral
|
struct LicenceInfoGeneral
|
||||||
{
|
{
|
||||||
int reqDataPointsCount = 0;
|
int reqDataPointsCount = 0;
|
||||||
map<int, int> licences = {};
|
unordered_map<int, int> licences = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class LicenceException : public std::exception
|
class LicenceException : public std::exception
|
||||||
|
|||||||
@@ -40,11 +40,8 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
|||||||
string convertToString(char* a, int size);
|
string convertToString(char* a, int size);
|
||||||
string base64_encode_ai(const std::string &input);
|
string base64_encode_ai(const std::string &input);
|
||||||
unordered_map<string, string> getArguments(int argc, char *argv[]);
|
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);
|
void getCharsFromString(string& source, char *charArray, size_t length);
|
||||||
string getCompletePath(string fileName);
|
string getCompletePath(string fileName);
|
||||||
char* getFileContent(string fileName);
|
|
||||||
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
|
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
|
||||||
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
|
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
|
||||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
||||||
|
|||||||
@@ -1,9 +1,31 @@
|
|||||||
#ifndef ELC1_READER__H
|
#ifndef ELC1_READER__H
|
||||||
#define ELC1_READER__H
|
#define ELC1_READER__H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "licenceCommon.h"
|
||||||
|
#include "licenceELC1.h"
|
||||||
|
#include "SDCard.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace Reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
class Licence1 : public LicenceELC1
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
LicenceInfo21 licenceInfo;
|
||||||
|
|
||||||
|
Licence1();
|
||||||
|
~Licence1();
|
||||||
|
Licence1(LicenceIdentification &licIdentification);
|
||||||
|
|
||||||
|
bool readLicence(LicenceInfoGeneral *licences);
|
||||||
|
bool getLicenceInfo(void *ptr);
|
||||||
|
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||||
|
void getLicenceItems();
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
#define LICENCE_READER_H_
|
#define LICENCE_READER_H_
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "licenceELC11.h"
|
|
||||||
#include "licenceELC31.h"
|
|
||||||
|
|
||||||
#include "licReaderELC1.h"
|
#include "licReaderELC1.h"
|
||||||
#include "licReaderELC2.h"
|
#include "licReaderELC2.h"
|
||||||
@@ -31,9 +29,9 @@ public:
|
|||||||
string operationErrors = "";
|
string operationErrors = "";
|
||||||
bool argumentsCorrect = false;
|
bool argumentsCorrect = false;
|
||||||
ErrorMessage error;
|
ErrorMessage error;
|
||||||
LicenceELC11 *licence11;
|
|
||||||
LicenceELC31 *licence31;
|
|
||||||
Licence2 *licence2;
|
Licence2 *licence2;
|
||||||
|
Licence1 *licence1;
|
||||||
|
|
||||||
|
|
||||||
LicenceReader();
|
LicenceReader();
|
||||||
~LicenceReader();
|
~LicenceReader();
|
||||||
|
|||||||
Binary file not shown.
@@ -5,7 +5,7 @@
|
|||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv parametry pro generování licence
|
/// @param argv parametry pro generování licence
|
||||||
/// @return
|
/// @return
|
||||||
int main(int argc, char *argv[])
|
int main5(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -213,6 +213,7 @@ void LicenceELC11::initCrypto()
|
|||||||
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
|
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string LicenceELC11::getLicenceName()
|
string LicenceELC11::getLicenceName()
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
|
|||||||
@@ -1,38 +1,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "utils.h"
|
|
||||||
#include "licenceReader.h"
|
#include "licenceReader.h"
|
||||||
|
|
||||||
|
|
||||||
/// @brief hlavní funkce
|
/// @brief hlavní funkce
|
||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv parametry pro generování licence
|
/// @param argv parametry pro generování licence
|
||||||
/// @return
|
/// @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
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
int protocolId = 444;
|
|
||||||
|
|
||||||
LicenceReader licenceReader1 {};
|
|
||||||
|
|
||||||
InitStructure initStructure;
|
InitStructure initStructure;
|
||||||
initStructure.licenceType = (int)LicenceType::EOS_EOV;
|
initStructure.licenceType = (int)LicenceType::EOS_EOV;
|
||||||
initStructure.licenceVersion = 1;
|
initStructure.licenceVersion = 1;
|
||||||
@@ -41,52 +17,77 @@ int main5()
|
|||||||
initStructure.licenceFilePath = "";
|
initStructure.licenceFilePath = "";
|
||||||
initStructure.cid_csd_filePath = "";
|
initStructure.cid_csd_filePath = "";
|
||||||
|
|
||||||
cout << "-- verze #1: init a iterace" << "\n";
|
// verze původní ELC 1
|
||||||
|
LicenceReader licenceReaderELC1{};
|
||||||
//verze #1: načtení kompletní licence a zobrazení
|
if (licenceReaderELC1.initread(1, initStructure)) //iniciacni nacteni
|
||||||
if (licenceReader1.init(2, initStructure))
|
|
||||||
{
|
{
|
||||||
LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
LicenceInfo1 info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
|
||||||
|
if (licenceReaderELC1.getLicenceInfo(&info))
|
||||||
if (licenceReader1.getLicenceInfo(&info))
|
|
||||||
{
|
{
|
||||||
if (info.licences.count(protocolId) > 0) cout << "Počet z vectoru pro : " << protocolId << ": " << info.licences.at(protocolId) << endl;
|
if (info.isValid)
|
||||||
cout << "Všechny licenční body: " << endl;
|
cout << "Platna licence ELC1 \n";
|
||||||
for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; }
|
else
|
||||||
|
cout << "Neplatna licence ELC1\n";
|
||||||
}
|
}
|
||||||
else cout << "Došlo k chybě: " << licenceReader1.error.message;
|
else
|
||||||
|
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Došlo k chybě: " << licenceReader1.error.message;
|
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "\n" << "-- verze #2: init a iterace" << "\n";
|
// verze ELC 2 pro jeden protokol
|
||||||
//verze #2 : iterace pro kazdý bod zvlášť
|
LicenceReader licenceReaderELC2{};
|
||||||
|
|
||||||
LicenceReader licenceReader2 {};
|
if (licenceReaderELC2.initread(2, initStructure)) //iniciacni nacteni
|
||||||
|
|
||||||
if (licenceReader2.initread(2, initStructure))
|
|
||||||
{
|
{
|
||||||
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||||
|
int protocolId = 444;
|
||||||
|
|
||||||
if (licenceReader2.getLicenceItemInfo(protocolId, &info))
|
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
||||||
{
|
{
|
||||||
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
LicenceReader licenceReaderCompleteELC2{};
|
||||||
|
|
||||||
|
// verze ELC 2 kompletní načtení
|
||||||
|
if (licenceReaderCompleteELC2.init(2, initStructure)) //iniciacni nacteni
|
||||||
|
{
|
||||||
|
LicenceInfo21 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 (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
cout << "Obecná chyba\n";
|
cout << "Obecna chyba\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
system("pause");
|
// system("pause");
|
||||||
return SUCCES;
|
return SUCCES;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,20 +8,24 @@ SDCard::SDCard()
|
|||||||
SDCard::SDCard(const string cds_cid_Path)
|
SDCard::SDCard(const string cds_cid_Path)
|
||||||
{
|
{
|
||||||
this->filePath = cds_cid_Path;
|
this->filePath = cds_cid_Path;
|
||||||
if (getCIDFromFile() == false) return;
|
if (getCIDFromFile() == false)
|
||||||
if (getCSDFromFile() == false) return;
|
return;
|
||||||
|
if (getCSDFromFile() == false)
|
||||||
|
return;
|
||||||
this->isLoaded = SDCard::readSDCard();
|
this->isLoaded = SDCard::readSDCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDCard::SDCard(string cid, string csd)
|
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 < cid.length(); i++)
|
||||||
for (unsigned int i = 0; i < csd.length(); i++) this->csd[i] = csd[i];
|
this->cid[i] = cid[i];
|
||||||
|
for (unsigned int i = 0; i < csd.length(); i++)
|
||||||
|
this->csd[i] = csd[i];
|
||||||
|
|
||||||
this->isLoaded = SDCard::readSDCard();
|
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,
|
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.CRCOK = ((sdCrc << 1) | 1) == this->cardData.CID[15];
|
||||||
this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1);
|
this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1);
|
||||||
return this->cardData.crcCorrect;
|
return this->cardData.crcCorrect;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDCard::getCIDFromFile()
|
bool SDCard::getCIDFromFile()
|
||||||
@@ -109,11 +112,14 @@ bool SDCard::getCIDFromFile()
|
|||||||
{
|
{
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -125,11 +131,13 @@ bool SDCard::getCSDFromFile()
|
|||||||
{
|
{
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -58,8 +58,7 @@ LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentifica
|
|||||||
|
|
||||||
bool LicenceELC1::getSDData()
|
bool LicenceELC1::getSDData()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < CID_LENGTH; i++)
|
for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
||||||
this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
|
||||||
|
|
||||||
for (int i = 0; i < cnibblescount / 2; i++)
|
for (int i = 0; i < cnibblescount / 2; i++)
|
||||||
{
|
{
|
||||||
@@ -91,12 +90,10 @@ bool LicenceELC1::getSDData()
|
|||||||
this->sdData.manufacturerDate[i] = date[i];
|
this->sdData.manufacturerDate[i] = date[i];
|
||||||
|
|
||||||
// CSD
|
// CSD
|
||||||
for (unsigned int i = 0; i < CSD_LENGTH; i++)
|
for (unsigned int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
||||||
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < cnibblescount / 2; 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]];
|
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.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9];
|
||||||
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
|
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
|
||||||
|
|
||||||
if (this->sdData.cardSize > 17200) // TODO result.cardSize
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BYTE sdCrc = 0;
|
BYTE sdCrc = 0;
|
||||||
@@ -189,10 +182,6 @@ string LicenceELC1::getLicenceName(BYTE licPostfix)
|
|||||||
string result = "";
|
string result = "";
|
||||||
char prefixChar = 97;
|
char prefixChar = 97;
|
||||||
|
|
||||||
if (licPostfix > 9) // chyba
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (licType == PlcLicenceType::LicenceOther)
|
if (licType == PlcLicenceType::LicenceOther)
|
||||||
{
|
{
|
||||||
result = "ezlic_";
|
result = "ezlic_";
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -60,7 +60,7 @@ LicenceReader::LicenceReader()
|
|||||||
// this->licIdentification.licCompatibility = compatibility;
|
// this->licIdentification.licCompatibility = compatibility;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/// @brief inicializace generátoru a načtení licenčních bodů
|
/// @brief inicializace generátoru a načtení licenčních bodů do obecné struktury
|
||||||
/// @param elcType
|
/// @param elcType
|
||||||
/// @param licenceType
|
/// @param licenceType
|
||||||
/// @param licenceVersion
|
/// @param licenceVersion
|
||||||
@@ -79,11 +79,21 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
|
|||||||
{
|
{
|
||||||
case 11:
|
case 11:
|
||||||
{ // old eoseov
|
{ // old eoseov
|
||||||
LicenceELC11 licence = LicenceELC11(this->licIdentification);
|
Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification);
|
||||||
this->licence11 = &licence;
|
this->licence1 = &licenceELC1;
|
||||||
licence.cid_cdsPath = initStructure.cid_csd_filePath;
|
licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||||
licence.licenceFilePath = initStructure.licenceFilePath;
|
licenceELC1.licenceFilePath = initStructure.licenceFilePath;
|
||||||
this->licence11->readLicence(&this->licenceInfo);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this->licence1->readLicence(&this->licenceInfo);
|
||||||
|
}
|
||||||
|
catch (const LicenceException &ex)
|
||||||
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 21:
|
case 21:
|
||||||
@@ -93,12 +103,11 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
|
|||||||
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||||
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
||||||
this->licence2->readLicence(&this->licenceInfo);
|
this->licence2->readLicence(&this->licenceInfo);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 31:
|
case 31:
|
||||||
{
|
{
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,9 +151,13 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure)
|
|||||||
|
|
||||||
elcSwitchType = elcType * 10 + licCompatibility;
|
elcSwitchType = elcType * 10 + licCompatibility;
|
||||||
|
|
||||||
return true; // TODO testy
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @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)
|
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -152,18 +165,14 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
|||||||
switch (elcSwitchType)
|
switch (elcSwitchType)
|
||||||
{
|
{
|
||||||
case 11:
|
case 11:
|
||||||
{ // old eoseov
|
{
|
||||||
LicenceItem11 *resultPtr = static_cast<LicenceItem11 *>(returnItemStructure);
|
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnItemStructure);
|
||||||
resultPtr->protocolId = protocolId;
|
if (this->licenceInfo.licences.count(1)) resultPtr->isValid = true; //stare eov melo natvrdo "id" 1.
|
||||||
if (this->licenceInfo.licences.count(protocolId))
|
else resultPtr->isValid = false;
|
||||||
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
|
||||||
else
|
|
||||||
resultPtr->dataPointsCount = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 21:
|
case 21:
|
||||||
{
|
{
|
||||||
|
|
||||||
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure);
|
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure);
|
||||||
resultPtr->protocolId = protocolId; // protocolId;
|
resultPtr->protocolId = protocolId; // protocolId;
|
||||||
if (this->licenceInfo.licences.count(protocolId))
|
if (this->licenceInfo.licences.count(protocolId))
|
||||||
@@ -174,7 +183,7 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
|||||||
}
|
}
|
||||||
case 31:
|
case 31:
|
||||||
{
|
{
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -195,30 +204,44 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
|||||||
return true;
|
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)
|
bool LicenceReader::getLicenceInfo(void *returnStructure)
|
||||||
{
|
{
|
||||||
// const type_info& ti1 = typeid(returnStructure);
|
try
|
||||||
// cout << "TTTYP: " << ti1.name() << endl;
|
{
|
||||||
switch (elcSwitchType)
|
switch (elcSwitchType)
|
||||||
{
|
{
|
||||||
case 11:
|
case 11:
|
||||||
{ // old eoseov
|
{ // old eoseov
|
||||||
|
|
||||||
|
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnStructure);
|
||||||
|
|
||||||
|
if (this->licenceInfo.licences.count(1))
|
||||||
|
{
|
||||||
|
resultPtr->isValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultPtr->isValid = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 21:
|
case 21:
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
||||||
licenceELC2.readLicence(&this->licenceInfo);
|
licenceELC2.readLicence(&this->licenceInfo);
|
||||||
return licenceELC2.getLicenceInfo(returnStructure);
|
return licenceELC2.getLicenceInfo(returnStructure);
|
||||||
}
|
|
||||||
catch (const LicenceException &ex)
|
// catch (const LicenceException &ex)
|
||||||
{
|
// {
|
||||||
error.code = ex.getErrorCode();
|
// error.code = ex.getErrorCode();
|
||||||
error.message = ex.getErrorMessage();
|
// error.message = ex.getErrorMessage();
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
// LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
||||||
// try
|
// try
|
||||||
@@ -236,7 +259,7 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
|
|||||||
}
|
}
|
||||||
case 31:
|
case 31:
|
||||||
{
|
{
|
||||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||||
// try
|
// try
|
||||||
// {
|
// {
|
||||||
// licence.readLicence();
|
// licence.readLicence();
|
||||||
@@ -251,10 +274,13 @@ bool LicenceReader::getLicenceInfo(void *returnStructure)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
error.code = -1;
|
catch (const LicenceException &ex)
|
||||||
error.message = "Nepodařilo se identifikovat licenci";
|
{
|
||||||
|
error.code = ex.getErrorCode();
|
||||||
|
error.message = ex.getErrorMessage();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LicenceReader::~LicenceReader()
|
LicenceReader::~LicenceReader()
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \
|
src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \
|
||||||
include/reader/licenceReader.h include/common/utils.h \
|
include/reader/licenceReader.h include/common/utils.h \
|
||||||
include/licenceELC11.h include/common/licenceCommon.h \
|
include/reader/licReaderELC1.h include/common/licenceCommon.h \
|
||||||
include/common/SDCard.h include/licenceELC31.h \
|
include/common/licenceELC1.h include/common/licenceCommon.h \
|
||||||
include/generator/pugixml.hpp include/generator/pugiconfig.hpp \
|
include/common/SDCard.h include/common/SDCard.h \
|
||||||
include/reader/licReaderELC1.h include/reader/licReaderELC2.h \
|
include/reader/licReaderELC2.h include/common/licenceELC2.h \
|
||||||
include/common/licenceELC2.h include/common/licenceCommon.h \
|
include/reader/licReaderELC3.h
|
||||||
include/common/SDCard.h include/reader/licReaderELC3.h
|
|
||||||
|
|||||||
Binary file not shown.
@@ -2,5 +2,126 @@
|
|||||||
|
|
||||||
namespace Reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
Licence1::Licence1() {}
|
||||||
|
|
||||||
|
Licence1::~Licence1() {}
|
||||||
|
|
||||||
|
Licence1::Licence1(LicenceIdentification &licIdentification) : LicenceELC1(licIdentification)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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 licFilePath = this->licenceFilePath + licFileName;
|
||||||
|
|
||||||
|
char licFileNameToRead[licFilePath.length()+1] = {};
|
||||||
|
getCharsFromString(licFilePath, licFileNameToRead, licFilePath.length());
|
||||||
|
|
||||||
|
FILE *licenceFile;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
licenceFile = fopen(licFileNameToRead, "rb"); // read mode
|
||||||
|
|
||||||
|
if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath);
|
||||||
|
|
||||||
|
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 (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();
|
||||||
|
// CryptData cryptData = initCrypto(sdData, licIdent.licIDType);
|
||||||
|
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
|
||||||
|
{
|
||||||
|
// memset(&licEncryptedData, 0, sizeof(licEncryptedData));
|
||||||
|
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::LicenceSizeCardMismatch, "Size card info mismatch");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
src/reader/licReaderELC1.o: src/reader/licReaderELC1.cpp \
|
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.
Binary file not shown.
Reference in New Issue
Block a user