diff --git a/README.md b/README.md index c9b00d7..a4f9b39 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Generování licence pro SD kartu ## Docker +/bin/bash - docker-compose up, spustí kontejner - otevření terminálu konterjneru, docker exec -it sd_gen-sd_gen-1 /bin/bash diff --git a/include/plcLicence.h b/include/plcLicence.h index a38300d..45c1808 100644 --- a/include/plcLicence.h +++ b/include/plcLicence.h @@ -46,7 +46,7 @@ typedef uint32_t DWORD; // DWORD = unsigned 32 bit value typedef uint16_t WORD; // WORD = unsigned 16 bit value typedef uint8_t BYTE; // BYTE = unsigned 8 bit value typedef uint32_t UDINT; -typedef unsigned long DATE; +typedef uint32_t DATE; typedef uint8_t USINT; typedef int32_t DINT; typedef uint16_t UINT; @@ -213,8 +213,8 @@ class PlcLicence private: string cidString = ""; - string csdString = ""; char *cid; // CID + string csdString = ""; char *csd; // CSD string stationName; // name of station string distributor; // name of switch diff --git a/include/utils.h b/include/utils.h index afbd507..239b49b 100644 --- a/include/utils.h +++ b/include/utils.h @@ -27,7 +27,7 @@ typedef uint32_t DWORD; #endif #ifndef DATE -typedef unsigned long DATE; +typedef uint32_t DATE; #endif using namespace std; diff --git a/src/CreateLicence.cpp b/src/CreateLicence.cpp index b612214..6eef2d9 100644 --- a/src/CreateLicence.cpp +++ b/src/CreateLicence.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -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) { diff --git a/src/PlcLicence.cpp b/src/PlcLicence.cpp index 9e383a9..a5e4d74 100644 --- a/src/PlcLicence.cpp +++ b/src/PlcLicence.cpp @@ -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] = {}; diff --git a/src/utils.cpp b/src/utils.cpp index b202eeb..60194d8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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 aes256_cbc_encrypt(const std::vector &plaintext, const std::vector &key, const std::vector &iv) { std::vector ciphertext;