This commit is contained in:
2023-08-17 14:32:33 +02:00
parent c07db22aba
commit bf75988495
6 changed files with 28 additions and 22 deletions

View File

@@ -1,4 +1,3 @@
#include <stdio.h>
#include <map>
#include <cstring>
@@ -109,27 +108,11 @@ int main(int argc, char *argv[])
const int csdLength = argumentsString["-csd"].length();
char csdArg[32] = {};
getCharsFromString(argumentsString["-csd"], csdArg, csdLength);
//cout << "csd delka pred: " << strlen(csdArg) << "\n";
//cout << "csd delka po: " << strlen(csdArg) << "\n";
//cout << "csd:" << csdArg << "\n";
const int cidLength = argumentsString["-cid"].length();
char cidArg[32] = {};
getCharsFromString(argumentsString["-cid"], cidArg, cidLength);
//cout << "cid delka pred: " << strlen(cidArg) << "\n";
//for (int i=0;i<32;i++) cidArg[i]=argumentsString["-cid"][i];
//cout << "cid delka po: " << strlen(cidArg) << "\n";
//cout << "cid delka sizeof po: " << sizeof(cidArg) << "\n";
//cout << "cid:" << cidArg;
// char cidTest = getCharArray(argumentsString["-cid"]);
// PlcLicence plcWriteLicence = PlcLicence(argumentsString);
// PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, stationName, switchName, licenceType, binaryType, nullptr);
// PlcLicence plcWriteLicence = PlcLicence(arguments["-cid"], arguments["-csd"], stationName, switchName, licenceType, binaryType, nullptr);
PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, argumentsString["-outputType"], argumentsString["-configFileName"]);
if (plcWriteLicence.CreateLicence() == false)
{

View File

@@ -6,6 +6,7 @@
#define CID_LENGTH 32
#define CSD_LENGTH 32
const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/";
const std::string cEzLic_p78ou3_licencfilepath_f21 = "/mnt/mmc/ez_sys/licence/";
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
@@ -607,6 +608,16 @@ bool PlcLicence::CreateLicence()
LicenceSourceData licSourceData;
// cout << "size of WORD:" << sizeof(WORD) << endl;
// cout << "size of DWORD:" << sizeof(DWORD) << endl;
// cout << "size of DATE:" << sizeof(DATE) << endl;
// cout << "size of BYTE:" << sizeof(BYTE) << endl;
// cout << "size of int:" << sizeof(int) << endl;
// cout << "size of char:" << sizeof(char) << endl;
// cout << "size of float:" << sizeof(float) << endl;
// cout << "Size of dataToFile: " << sizeof(dataToFile) << endl;
// return true;
if (plcData.licenceType == "EOV" || plcData.licenceType == to_string((int)LicenceType::LicenceEov))
{
licSourceData.licType = 0x1AA2; // 6818 ... proč ?
@@ -657,7 +668,7 @@ bool PlcLicence::CreateLicence()
dataToFile.header.licVersion = 10;
dataToFile.header.licType = licIdent.licIDType;
dataToFile.header.licDate = getLicDate();
dataToFile.header.licDate = getLicDate(); //1692230400; //getLicDate(); //1692144000;// getLicDate();
mainLicDescription += dataToFile.header.licDescription1;
mainLicDescription += " [";
mainLicDescription += dataToFile.header.licDescription2;
@@ -715,6 +726,8 @@ bool PlcLicence::CreateLicence()
unsigned char bdataMainToFileELC1[dataMainLength] = {};
memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength);
unsigned char bdataToFile[dataToFileLength] = {};
memcpy(bdataToFile, &dataToFile, dataToFileLength);
unsigned char totalEncryptedArray[totalEncryptedLength] = {};

View File

@@ -24,6 +24,7 @@
using namespace std;
const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -385,6 +386,7 @@ DateAndTime getCurrentDateTimeAsCODESYSDateTime()
return codesysDateTime;
}
DATE getLicDate()
{
time_t ttime = time(0);
@@ -393,10 +395,17 @@ DATE getLicDate()
int minutesSeconds = 60 * local_time->tm_min;
int seconds = 1 * local_time->tm_sec;
int totalSeconds = hoursSeconds + minutesSeconds + seconds;
DATE dateOnly = ttime - totalSeconds + 7200; // 7200 + vteřina za dvě hodiny pro srování
#ifdef WINDOWS
DATE dateOnly = ttime - totalSeconds + 7200;// (pro windows); // 7200 + vteřina za dvě hodiny pro srování
#else
DATE dateOnly = ttime - totalSeconds;
#endif
return dateOnly;
}
std::vector<unsigned char> aes256_cbc_encrypt(const std::vector<unsigned char> &plaintext, const std::vector<unsigned char> &key, const std::vector<unsigned char> &iv)
{
std::vector<unsigned char> ciphertext;