Compare commits
3 Commits
b7811685e2
...
ed2cf088a6
| Author | SHA1 | Date | |
|---|---|---|---|
| ed2cf088a6 | |||
| eaf88b506a | |||
| b2260178f6 |
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -65,7 +65,10 @@
|
|||||||
"bitset": "cpp",
|
"bitset": "cpp",
|
||||||
"codecvt": "cpp",
|
"codecvt": "cpp",
|
||||||
"xtree": "cpp",
|
"xtree": "cpp",
|
||||||
"map": "cpp"
|
"map": "cpp",
|
||||||
|
"csignal": "cpp",
|
||||||
|
"filesystem": "cpp",
|
||||||
|
"list": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve"
|
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve"
|
||||||
}
|
}
|
||||||
74
include/pugiconfig.hpp
Normal file
74
include/pugiconfig.hpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* pugixml parser - version 1.7
|
||||||
|
* --------------------------------------------------------
|
||||||
|
* Copyright (C) 2006-2015, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||||
|
* Report bugs and download new versions at http://pugixml.org/
|
||||||
|
*
|
||||||
|
* This library is distributed under the MIT License. See notice at the end
|
||||||
|
* of this file.
|
||||||
|
*
|
||||||
|
* This work is based on the pugxml parser, which is:
|
||||||
|
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HEADER_PUGICONFIG_HPP
|
||||||
|
#define HEADER_PUGICONFIG_HPP
|
||||||
|
|
||||||
|
// Uncomment this to enable wchar_t mode
|
||||||
|
// #define PUGIXML_WCHAR_MODE
|
||||||
|
|
||||||
|
// Uncomment this to enable compact mode
|
||||||
|
// #define PUGIXML_COMPACT
|
||||||
|
|
||||||
|
// Uncomment this to disable XPath
|
||||||
|
// #define PUGIXML_NO_XPATH
|
||||||
|
|
||||||
|
// Uncomment this to disable STL
|
||||||
|
// #define PUGIXML_NO_STL
|
||||||
|
|
||||||
|
// Uncomment this to disable exceptions
|
||||||
|
// #define PUGIXML_NO_EXCEPTIONS
|
||||||
|
|
||||||
|
// Set this to control attributes for public classes/functions, i.e.:
|
||||||
|
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
|
||||||
|
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
|
||||||
|
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
|
||||||
|
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
|
||||||
|
|
||||||
|
// Tune these constants to adjust memory-related behavior
|
||||||
|
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
|
||||||
|
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
||||||
|
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
||||||
|
|
||||||
|
// Uncomment this to switch to header-only version
|
||||||
|
// #define PUGIXML_HEADER_ONLY
|
||||||
|
|
||||||
|
// Uncomment this to enable long long support
|
||||||
|
// #define PUGIXML_HAS_LONG_LONG
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2006-2015 Arseny Kapoulkine
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without
|
||||||
|
* restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following
|
||||||
|
* conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
1400
include/pugixml.hpp
Normal file
1400
include/pugixml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,9 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
#define LINUX 1
|
||||||
|
|
||||||
#define PEM_BUFSIZE_TEXT 1024
|
#define PEM_BUFSIZE_TEXT 1024
|
||||||
#define BitVal(data, y) ((data >> y) & 1) /** Return Data.Y value **/
|
#define BitVal(data, y) ((data >> y) & 1) /** Return Data.Y value **/
|
||||||
@@ -66,6 +68,8 @@ map<string, const char*> mapArguments(int argc, char *argv[]);
|
|||||||
char* getCharArray(string source);
|
char* getCharArray(string source);
|
||||||
void getCharsFromString1(string source, char *charArray);
|
void getCharsFromString1(string source, char *charArray);
|
||||||
void getCharsFromString(string& source, char *charArray, int length);
|
void getCharsFromString(string& source, char *charArray, int length);
|
||||||
|
string getCompletePath(string fileName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <map>
|
|
||||||
#include <cstring>
|
|
||||||
#include "plcLicence.h"
|
#include "plcLicence.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <csignal>
|
#include <filesystem>
|
||||||
|
|
||||||
|
|
||||||
#define FILEBUFFER 300
|
#define FILEBUFFER 300
|
||||||
#define TWO_HOURSE_SECONDS 7200
|
#define TWO_HOURSE_SECONDS 7200
|
||||||
|
|
||||||
void signalHandler(int signum)
|
|
||||||
{
|
|
||||||
if (signum == SIGSEGV)
|
|
||||||
{
|
|
||||||
std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl;
|
|
||||||
// You can perform some recovery actions here if needed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief hlavní funkce
|
/// @brief hlavní funkce
|
||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv parametry pro generování licence
|
/// @param argv parametry pro generování licence
|
||||||
@@ -25,86 +15,8 @@ void signalHandler(int signum)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
std::signal(SIGSEGV, signalHandler);
|
|
||||||
|
|
||||||
// a segmentation fault
|
|
||||||
// int* ptr = nullptr;
|
|
||||||
//*ptr = 42; // This will trigger a segmentation fault
|
|
||||||
|
|
||||||
// map<string, const char *> arguments = mapArguments(argc, argv);
|
|
||||||
map<string, string> argumentsString = getArguments(argc, argv);
|
map<string, string> argumentsString = getArguments(argc, argv);
|
||||||
|
|
||||||
// std::cout << "Number of arguments: " << argc << std::endl;
|
|
||||||
// if (argc > 1)
|
|
||||||
// {
|
|
||||||
// for (int i = 1; i < argc; ++i)
|
|
||||||
// {
|
|
||||||
// arguments.insert(make_pair(to_string(i), argv[i]));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// cerr << "Invalid arguments count";
|
|
||||||
|
|
||||||
// for (auto it = argumentsString.begin(); it != argumentsString.end(); ++it)
|
|
||||||
// {
|
|
||||||
// std::cout << "Key: " << it->first << ", Value: " << it->second << std::endl;
|
|
||||||
// std::cout << it->second.length() << std::endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// generatePause();
|
|
||||||
// return 1;
|
|
||||||
|
|
||||||
// for (int i = 0; i < argc; ++i)
|
|
||||||
// {
|
|
||||||
// std::cout << "Argument " << i << ": " << argv[i] << std::endl;
|
|
||||||
// cout << "size: " << strlen(argv[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// generatePause();
|
|
||||||
// return 1;
|
|
||||||
|
|
||||||
// if (argc >= 5)
|
|
||||||
// {
|
|
||||||
// cid = argv[1];
|
|
||||||
// csd = argv[2];
|
|
||||||
// stationName = argv[3];
|
|
||||||
// switchName = argv[4];
|
|
||||||
// licenceType = argv[5];
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// cout << "Par count error" << endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (argc <= 1)
|
|
||||||
// {
|
|
||||||
// cid = "9f544930303030300000000b47015423";
|
|
||||||
// csd = "400e00325b5900003a0d7f800a40008d";
|
|
||||||
// stationName = "ceskatrebova";
|
|
||||||
// switchName = "RO1";
|
|
||||||
// licenceType = "2";
|
|
||||||
// binaryType = "2";
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// cid = argv[1];
|
|
||||||
// csd = argv[2];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// cid = "9f544930303030300000000b47015423";
|
|
||||||
// csd = "400e00325b5900003a0d7f800a40008d";
|
|
||||||
// stationName = "ceskatrebova";
|
|
||||||
// switchName = "RO1";
|
|
||||||
// licenceType = "2";
|
|
||||||
// binaryType = "2";
|
|
||||||
|
|
||||||
// cout << "binaryType: " << binaryType;
|
|
||||||
// cout << "CID:" << argumentsString["-cid"];
|
|
||||||
|
|
||||||
// cout << "final-cids: " << argumentsString["-cid"].length() << endl;
|
|
||||||
// cout << "final-cds: " << argumentsString["-csd"].length() << endl;
|
|
||||||
// cout << "-----------------------------------\n";
|
|
||||||
|
|
||||||
const int csdLength = argumentsString["-csd"].length();
|
const int csdLength = argumentsString["-csd"].length();
|
||||||
char csdArg[32] = {};
|
char csdArg[32] = {};
|
||||||
getCharsFromString(argumentsString["-csd"], csdArg, csdLength);
|
getCharsFromString(argumentsString["-csd"], csdArg, csdLength);
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
#include "plcLicence.h"
|
#include "plcLicence.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "pugixml.hpp"
|
||||||
|
|
||||||
#define CID_LENGTH 32
|
#define CID_LENGTH 32
|
||||||
#define CSD_LENGTH 32
|
#define CSD_LENGTH 32
|
||||||
|
|
||||||
|
|
||||||
const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/";
|
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_f21 = "/mnt/mmc/ez_sys/licence/";
|
||||||
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
|
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
|
||||||
@@ -50,8 +51,6 @@ BYTE cHexNibble_to_No[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
std::string cEzLic_p78ou3_CipherAES = "aes-256-cbc"; // konfigurace kriptovaciho algoritmu
|
std::string cEzLic_p78ou3_CipherAES = "aes-256-cbc"; // konfigurace kriptovaciho algoritmu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PlcLicence::PlcLicence()
|
PlcLicence::PlcLicence()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -60,46 +59,25 @@ PlcLicence::PlcLicence()
|
|||||||
/// @param dataFileName
|
/// @param dataFileName
|
||||||
void PlcLicence::processConfigFile(string &dataFileName)
|
void PlcLicence::processConfigFile(string &dataFileName)
|
||||||
{
|
{
|
||||||
std::string content;
|
string fullFile = getCompletePath(dataFileName);
|
||||||
std::ifstream inputFile(dataFileName);
|
const int fileNameLength = fullFile.length();
|
||||||
if (inputFile.is_open())
|
char fileName[fileNameLength] = {};
|
||||||
|
getCharsFromString(fullFile, fileName, fileNameLength);
|
||||||
|
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result = doc.load_file(fileName);
|
||||||
|
if (result)
|
||||||
{
|
{
|
||||||
content.assign((std::istreambuf_iterator<char>(inputFile)), (std::istreambuf_iterator<char>()));
|
this->stationName = doc.child("data").child("station").child_value();
|
||||||
inputFile.close();
|
this->distributor = doc.child("data").child("distributor").child_value();
|
||||||
//std::cout << "File content:\n" << content << std::endl;
|
;
|
||||||
|
// cout << doc.child("data").child("plcType").attribute("t").value() << endl;
|
||||||
|
// cout << doc.child("data").child("plcType").child_value() << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unable to open the file." << std::endl;
|
std::cerr << "Unable to open the file." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
string station = getXmlContentFromString(content, "station");
|
|
||||||
string distributor = getXmlContentFromString(content, "distributor");
|
|
||||||
|
|
||||||
// cout << station;
|
|
||||||
// cout << distributor;
|
|
||||||
|
|
||||||
this->stationName = station;
|
|
||||||
this->distributor = distributor;
|
|
||||||
|
|
||||||
// char stationCh[station.length()] = {};
|
|
||||||
// getCharsFromString(station, stationCh);
|
|
||||||
|
|
||||||
// char distributorCh[distributor.length()] = {};
|
|
||||||
// getCharsFromString(distributor, distributorCh);
|
|
||||||
|
|
||||||
// this->stationName = stationCh;
|
|
||||||
// this->distributor = distributorCh;
|
|
||||||
|
|
||||||
// cout << this->stationName << "\n";
|
|
||||||
// cout << this->distributor << "\n";
|
|
||||||
|
|
||||||
// this->stationName = "ceskatrebova";
|
|
||||||
// this->distributor = "RO1";
|
|
||||||
|
|
||||||
// cout << this->stationName << "\n";
|
|
||||||
// cout << this->distributor << "\n";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlcLicence::PlcLicence(map<string, string> &arguments)
|
PlcLicence::PlcLicence(map<string, string> &arguments)
|
||||||
@@ -117,21 +95,6 @@ PlcLicence::PlcLicence(map<string, string> &arguments)
|
|||||||
<< "CID 1:" << cid << " delka: " << strlen(cid) << "\n";
|
<< "CID 1:" << cid << " delka: " << strlen(cid) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// this->cid = "9f544930303030300000000b47015423";
|
|
||||||
// this->csd = "400e00325b5900003a0d7f800a40008d";
|
|
||||||
|
|
||||||
cout << "\n"
|
|
||||||
<< "CID 2:"
|
|
||||||
<< " delka: " << strlen(cid) << "\n";
|
|
||||||
|
|
||||||
// if (arguments.count("-csd") > 0)
|
|
||||||
// {
|
|
||||||
// const int csdLength = arguments["-csd"].length();
|
|
||||||
// char csdArg[csdLength] = {};
|
|
||||||
// getCharsFromString(arguments["-csd"], csdArg);
|
|
||||||
// this->csd = csdArg;
|
|
||||||
// }
|
|
||||||
|
|
||||||
this->licType = 2;
|
this->licType = 2;
|
||||||
|
|
||||||
if (arguments.count("-outputType") > 0)
|
if (arguments.count("-outputType") > 0)
|
||||||
@@ -143,7 +106,6 @@ PlcLicence::PlcLicence(map<string, string> &arguments)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlcLicence::PlcLicence(string cid, string csd, char *stationName, char *switchName, char *licenceType, char *binaryType, const char *dataFileName)
|
PlcLicence::PlcLicence(string cid, string csd, char *stationName, char *switchName, char *licenceType, char *binaryType, const char *dataFileName)
|
||||||
@@ -163,16 +125,13 @@ PlcLicence::PlcLicence(string cid, string csd, char *stationName, char *switchNa
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlcLicence::getSDData()
|
void PlcLicence::getSDData()
|
||||||
{
|
{
|
||||||
//int length = strlen(cid); // Get the length of the char array
|
// int length = strlen(cid); // Get the length of the char array
|
||||||
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++)
|
for (int i = 0; i < cnibblescount / 2; i++)
|
||||||
{
|
{
|
||||||
@@ -204,7 +163,8 @@ void PlcLicence::getSDData()
|
|||||||
this->sdData.manufacturerDate[i] = date[i];
|
this->sdData.manufacturerDate[i] = date[i];
|
||||||
|
|
||||||
// CSD
|
// CSD
|
||||||
for (int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
for (int i = 0; i < CSD_LENGTH; i++)
|
||||||
|
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
||||||
|
|
||||||
for (int i = 0; i < cnibblescount / 2; i++)
|
for (int i = 0; i < cnibblescount / 2; i++)
|
||||||
{
|
{
|
||||||
@@ -239,8 +199,6 @@ void PlcLicence::getSDData()
|
|||||||
this->sdData.CRCOK = ((sdCrc << 1) | 1) == this->sdData.CID[15];
|
this->sdData.CRCOK = ((sdCrc << 1) | 1) == this->sdData.CID[15];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PlcLicence::PlcLicence(char *cid, char *csd, string binaryType, string dataFileName)
|
PlcLicence::PlcLicence(char *cid, char *csd, string binaryType, string dataFileName)
|
||||||
{
|
{
|
||||||
this->cid = cid;
|
this->cid = cid;
|
||||||
@@ -277,8 +235,6 @@ PlcLicence::PlcLicence(char *cid, char *csd, char *stationName, char *switchName
|
|||||||
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
this->binaryGeneration = BinaryGenerationType::Base64Cout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PlcLicence::initCrypto()
|
void PlcLicence::initCrypto()
|
||||||
{
|
{
|
||||||
if (this->licType == cEzLic_p78ou3_IDType_EOVOSV)
|
if (this->licType == cEzLic_p78ou3_IDType_EOVOSV)
|
||||||
@@ -307,165 +263,6 @@ void PlcLicence::initCrypto()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *PlcLicence::getLicenceContent()
|
|
||||||
{
|
|
||||||
getSDData();
|
|
||||||
initCrypto();
|
|
||||||
|
|
||||||
// promenne pro praci se soubory a adresari
|
|
||||||
DWORD sdFileHandle;
|
|
||||||
DWORD sdDirHandle;
|
|
||||||
string dirFileName;
|
|
||||||
string dirFilePath; //: STRING;
|
|
||||||
string dirInfo; //: DIRECTORY_INFO; - NAJIT
|
|
||||||
LicenceDataMainELC dataMainToFileELC1; //: tEz_LicenceDataMainELC1; hlavicka urcena pro zapis do souboru - typ ELC1
|
|
||||||
LicenceData dataToFile; // tEz_LicenceData_10_10;// data urcena pro sifrovani a zapis do soubotu - verze => hlavicka: 1.0, data: 1.0
|
|
||||||
|
|
||||||
// pomocne promenne
|
|
||||||
BYTE dataWriteToFile[cEzLic_p78ou3_maxDataToFile]; // OF BYTE; data zapisovana do souboru
|
|
||||||
DWORD retDataCount; //: DWORD; // pocty zapisovanych a ctenych dat - navratova hodnota jednotlivych funkci
|
|
||||||
string licencePostfix; //: STRING; pomocna promenna pro kontrolu postfixu
|
|
||||||
string mainLicDescription; //: STRING(79); globalni pojmenovani licence v nesifrovane casti licence
|
|
||||||
|
|
||||||
UINT freeDataSize; //: UINT; velikost volne citelnych dat v souboru licenci
|
|
||||||
UINT cryptDataSize; //: UINT; velikost volne cryptovanych dat v souboru licenci
|
|
||||||
UINT fullDataSize; //: UINT; celkova velikost souboru licenci
|
|
||||||
|
|
||||||
USINT generation = 2; //: USINT; verze SW pro licence
|
|
||||||
|
|
||||||
PlcData plcData; // = GetPlcData(dataFileName);// "licData.xml");
|
|
||||||
plcData.licenceName = "Licence";
|
|
||||||
plcData.licenceType = "1";
|
|
||||||
plcData.station = stationName; // "Test";
|
|
||||||
plcData.distributor = distributor; //"RO1";
|
|
||||||
|
|
||||||
LicenceSourceData licSourceData;
|
|
||||||
|
|
||||||
if (plcData.licenceType == "EOV" || plcData.licenceType == to_string((int)LicenceType::LicenceEov))
|
|
||||||
{
|
|
||||||
licSourceData.licType = 0x1AA2; // 6818 ... proč ?
|
|
||||||
licSourceData.licPostfix = 0;
|
|
||||||
getCharsFromString(plcData.station, licSourceData.licDescription1);
|
|
||||||
getCharsFromString(plcData.station, dataToFile.header.licDescription1);
|
|
||||||
getCharsFromString(plcData.distributor, licSourceData.licDescription2);
|
|
||||||
getCharsFromString(plcData.distributor, dataToFile.header.licDescription2);
|
|
||||||
}
|
|
||||||
|
|
||||||
LicenceIdent licIdent;
|
|
||||||
licIdent.licPrefixType = licSourceData.licType >> 12;
|
|
||||||
licIdent.licHeaderType = licSourceData.licType >> 8 & 0x000F;
|
|
||||||
licIdent.licDataType = licSourceData.licType >> 4 & 0x000F;
|
|
||||||
licIdent.licSubType = licIdent.licHeaderType << 8 | licIdent.licHeaderType;
|
|
||||||
licIdent.licIDType = licSourceData.licType & 0x000F;
|
|
||||||
|
|
||||||
if (licSourceData.licPostfix > 9)
|
|
||||||
licSourceData.licPostfix = 0;
|
|
||||||
licencePostfix = to_string(licSourceData.licPostfix);
|
|
||||||
|
|
||||||
string licenseFileName = getLicenceName(0);
|
|
||||||
licSourceData.licPostfixIdent = right(licencePostfix, 1);
|
|
||||||
|
|
||||||
int sizeOfData = sizeof(dataToFile);
|
|
||||||
|
|
||||||
if (licIdent.licHeaderType == cEzLic_p78ou3_HeaderType_10)
|
|
||||||
{
|
|
||||||
if (licIdent.licDataType == cEzLic_p78ou3_DataType_10)
|
|
||||||
{
|
|
||||||
dataToFile.id.version = 10;
|
|
||||||
dataToFile.id.cardSize = this->sdData.cardSize;
|
|
||||||
|
|
||||||
switch (licIdent.licIDType)
|
|
||||||
{
|
|
||||||
case cEzLic_p78ou3_IDType_DDTS:
|
|
||||||
mainLicDescription = "ddts ";
|
|
||||||
break;
|
|
||||||
case cEzLic_p78ou3_IDType_EOVOSV:
|
|
||||||
mainLicDescription = "eov, osv ";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mainLicDescription = "neznama app ";
|
|
||||||
}
|
|
||||||
|
|
||||||
mainLicDescription += licSourceData.licPostfixIdent;
|
|
||||||
mainLicDescription += " => ";
|
|
||||||
|
|
||||||
dataToFile.header.licVersion = 10;
|
|
||||||
dataToFile.header.licType = licIdent.licIDType;
|
|
||||||
dataToFile.header.licDate = getLicDate();
|
|
||||||
mainLicDescription += dataToFile.header.licDescription1;
|
|
||||||
mainLicDescription += " [";
|
|
||||||
mainLicDescription += dataToFile.header.licDescription2;
|
|
||||||
mainLicDescription += "]";
|
|
||||||
|
|
||||||
if (licIdent.licIDType == cEzLic_p78ou3_IDType_EOVOSV)
|
|
||||||
{
|
|
||||||
if (generation == 1) // stará verze
|
|
||||||
{
|
|
||||||
dataToFile.header.licCount = 1;
|
|
||||||
dataToFile.items[0].licCount = 65535;
|
|
||||||
dataToFile.items[0].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1;
|
|
||||||
dataToFile.items[0].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dataToFile.header.licCount = 1;
|
|
||||||
dataToFile.items[1].licCount = 65535;
|
|
||||||
dataToFile.items[1].protoId = cEzLic_p78ou3_CheckLicNumberId_EOV1;
|
|
||||||
dataToFile.items[1].data1 = cEzLic_p78ou3_CheckLicNumber_EOV1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char encrypted[10000] = {};
|
|
||||||
const int s = sizeof(dataToFile);
|
|
||||||
unsigned char byteArray[s] = {};
|
|
||||||
memcpy(byteArray, &dataToFile, sizeof(dataToFile));
|
|
||||||
|
|
||||||
dataToFile.crc = calculateCRC16(byteArray, s - sizeof(dataToFile.crc)); // 47535 | 884:38382
|
|
||||||
|
|
||||||
memcpy(byteArray, &dataToFile, sizeof(dataToFile));
|
|
||||||
|
|
||||||
int finalEncryptedLength = encrypt(byteArray, sizeof(dataToFile), this->cryptData.aesKey, this->cryptData.aesInitVector, encrypted);
|
|
||||||
|
|
||||||
if (licIdent.licPrefixType == cEzLic_p78ou3_LicPrefixType_ELC1) // typ1 = pouze zasifrovani dat
|
|
||||||
{
|
|
||||||
freeDataSize = sizeof(dataMainToFileELC1); // melo by byt 92
|
|
||||||
|
|
||||||
if (1) // EzLic_p78ou3_CryptoData.aesRetVal > 0 crypto
|
|
||||||
{
|
|
||||||
dataMainToFileELC1.prefix = 0x31434C45;
|
|
||||||
getCharsFromString(mainLicDescription, dataMainToFileELC1.licHeader.description);
|
|
||||||
dataMainToFileELC1.licHeader.sizeData = finalEncryptedLength; // sizeof(dataToFile); // 884;
|
|
||||||
dataMainToFileELC1.licHeader.licType = licIdent.licIDType;
|
|
||||||
dataMainToFileELC1.licHeader.licSubType = licIdent.licHeaderType << 8 | licIdent.licDataType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const int dataMainLength = sizeof(dataMainToFileELC1);
|
|
||||||
const int dataToFileLength = sizeof(dataToFile);
|
|
||||||
const int dataEncryptedLength = finalEncryptedLength;
|
|
||||||
const int totalLength = dataMainLength + dataToFileLength;
|
|
||||||
const int totalEncryptedLength = dataMainLength + finalEncryptedLength;
|
|
||||||
|
|
||||||
unsigned char bdataMainToFileELC1[dataMainLength] = {};
|
|
||||||
memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength);
|
|
||||||
|
|
||||||
unsigned char bdataToFile[dataToFileLength] = {};
|
|
||||||
memcpy(bdataToFile, &dataToFile, dataToFileLength);
|
|
||||||
|
|
||||||
unsigned char totalEncryptedArray[totalEncryptedLength] = {};
|
|
||||||
|
|
||||||
for (int i = 0; i < dataMainLength; i++)
|
|
||||||
totalEncryptedArray[i] = bdataMainToFileELC1[i];
|
|
||||||
for (int i = 0; i < finalEncryptedLength; i++)
|
|
||||||
totalEncryptedArray[i + dataMainLength] = encrypted[i];
|
|
||||||
|
|
||||||
return totalEncryptedArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
string PlcLicence::getLicenceName(BYTE licPostfix)
|
string PlcLicence::getLicenceName(BYTE licPostfix)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
@@ -668,7 +465,7 @@ bool PlcLicence::CreateLicence()
|
|||||||
|
|
||||||
dataToFile.header.licVersion = 10;
|
dataToFile.header.licVersion = 10;
|
||||||
dataToFile.header.licType = licIdent.licIDType;
|
dataToFile.header.licType = licIdent.licIDType;
|
||||||
dataToFile.header.licDate = getLicDate(); //1692230400; //getLicDate(); //1692144000;// getLicDate();
|
dataToFile.header.licDate = getLicDate(); // 1692230400; //getLicDate(); //1692144000;// getLicDate();
|
||||||
mainLicDescription += dataToFile.header.licDescription1;
|
mainLicDescription += dataToFile.header.licDescription1;
|
||||||
mainLicDescription += " [";
|
mainLicDescription += " [";
|
||||||
mainLicDescription += dataToFile.header.licDescription2;
|
mainLicDescription += dataToFile.header.licDescription2;
|
||||||
@@ -726,8 +523,6 @@ bool PlcLicence::CreateLicence()
|
|||||||
unsigned char bdataMainToFileELC1[dataMainLength] = {};
|
unsigned char bdataMainToFileELC1[dataMainLength] = {};
|
||||||
memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength);
|
memcpy(bdataMainToFileELC1, &dataMainToFileELC1, dataMainLength);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char bdataToFile[dataToFileLength] = {};
|
unsigned char bdataToFile[dataToFileLength] = {};
|
||||||
memcpy(bdataToFile, &dataToFile, dataToFileLength);
|
memcpy(bdataToFile, &dataToFile, dataToFileLength);
|
||||||
unsigned char totalEncryptedArray[totalEncryptedLength] = {};
|
unsigned char totalEncryptedArray[totalEncryptedLength] = {};
|
||||||
@@ -737,27 +532,39 @@ bool PlcLicence::CreateLicence()
|
|||||||
for (int i = 0; i < finalEncryptedLength; i++)
|
for (int i = 0; i < finalEncryptedLength; i++)
|
||||||
totalEncryptedArray[i + dataMainLength] = encrypted[i];
|
totalEncryptedArray[i + dataMainLength] = encrypted[i];
|
||||||
|
|
||||||
// char chFileName[licenseFileName.length()];
|
// for (int i=0;i<totalEncryptedLength;i++) cout << totalEncryptedArray[i];
|
||||||
char licFileNameToSave[licenseFileName.length()] = {};
|
|
||||||
getCharsFromString(licenseFileName, licFileNameToSave);
|
|
||||||
|
|
||||||
int totalFileSize = sizeof(totalEncryptedArray);
|
string fullFile = getCompletePath(licenseFileName);
|
||||||
|
|
||||||
if (binaryGeneration == BinaryGenerationType::File)
|
if (binaryGeneration == BinaryGenerationType::File)
|
||||||
{
|
{
|
||||||
FILE *fileLicence = fopen(licFileNameToSave, "wb");
|
std::ofstream outputFile(fullFile);
|
||||||
if (fileLicence)
|
|
||||||
|
if (outputFile.is_open())
|
||||||
{
|
{
|
||||||
size_t r1 = fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence);
|
outputFile.write(reinterpret_cast<const char *>(totalEncryptedArray), totalEncryptedLength);
|
||||||
//printf("License binary saved.\n");
|
outputFile.close();
|
||||||
fclose(fileLicence);
|
std::cout << licenseFileName << std::endl;
|
||||||
cout << licFileNameToSave << endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//cout << "data:text/plain;base64,";
|
std::cerr << "Unable to open the file." << std::endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// FILE *fileLicence = fopen(licFileNameToSave, "wb");
|
||||||
|
// if (fileLicence)
|
||||||
|
// {
|
||||||
|
// size_t r1 = fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence);
|
||||||
|
// // printf("License binary saved.\n");
|
||||||
|
// fclose(fileLicence);
|
||||||
|
// cout << licenseFileName << endl;
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int totalFileSize = sizeof(totalEncryptedArray);
|
||||||
|
// cout << "data:text/plain;base64,";
|
||||||
cout << "data:application/octet-stream;base64,";
|
cout << "data:application/octet-stream;base64,";
|
||||||
|
|
||||||
char encryptedChars[totalFileSize];
|
char encryptedChars[totalFileSize];
|
||||||
|
|||||||
12444
src/pugixml.cpp
Normal file
12444
src/pugixml.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
const std::string base64_chars =
|
const std::string base64_chars =
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
@@ -73,14 +72,10 @@ void getCharsFromString1(string source, char *charArray)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getCharsFromString(string& source, char *charArray, int length)
|
void getCharsFromString(string &source, char *charArray, int length)
|
||||||
{
|
{
|
||||||
memset(charArray, 0, length);
|
memset(charArray, 0, length);
|
||||||
// charArray[length]; // Character array to store the string
|
for (int i = 0; i < length; i++) { charArray[i] = source[i]; }
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
charArray[i] = source[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getCharsFromString(string source, char *charArray)
|
void getCharsFromString(string source, char *charArray)
|
||||||
@@ -386,7 +381,6 @@ DateAndTime getCurrentDateTimeAsCODESYSDateTime()
|
|||||||
return codesysDateTime;
|
return codesysDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DATE getLicDate()
|
DATE getLicDate()
|
||||||
{
|
{
|
||||||
time_t ttime = time(0);
|
time_t ttime = time(0);
|
||||||
@@ -396,16 +390,15 @@ DATE getLicDate()
|
|||||||
int seconds = 1 * local_time->tm_sec;
|
int seconds = 1 * local_time->tm_sec;
|
||||||
int totalSeconds = hoursSeconds + minutesSeconds + seconds;
|
int totalSeconds = hoursSeconds + minutesSeconds + seconds;
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
DATE dateOnly = ttime - totalSeconds + 7200;// (pro windows); // 7200 + vteřina za dvě hodiny pro srování
|
DATE dateOnly = ttime - totalSeconds + 7200; // (pro windows); // 7200 + vteřina za dvě hodiny pro srování
|
||||||
#else
|
#else
|
||||||
DATE dateOnly = ttime - totalSeconds;
|
DATE dateOnly = ttime - totalSeconds;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return dateOnly;
|
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> 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;
|
std::vector<unsigned char> ciphertext;
|
||||||
@@ -734,9 +727,10 @@ std::string base64_encode_ai(const std::string &input)
|
|||||||
|
|
||||||
map<string, string> getArguments(int argc, char *argv[])
|
map<string, string> getArguments(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char splitChar='=';
|
const char splitChar = '=';
|
||||||
map<string, string> result;
|
map<string, string> result;
|
||||||
if (argc <= 1) return result;
|
if (argc <= 1)
|
||||||
|
return result;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
@@ -745,7 +739,7 @@ map<string, string> getArguments(int argc, char *argv[])
|
|||||||
string argName;
|
string argName;
|
||||||
string argValue;
|
string argValue;
|
||||||
|
|
||||||
for (int j=0;j<argLength;j++)
|
for (int j = 0; j < argLength; j++)
|
||||||
{
|
{
|
||||||
if (argv[i][j] == splitChar)
|
if (argv[i][j] == splitChar)
|
||||||
{
|
{
|
||||||
@@ -768,11 +762,12 @@ map<string, string> getArguments(int argc, char *argv[])
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, const char*> mapArguments(int argc, char *argv[])
|
map<string, const char *> mapArguments(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char splitChar='=';
|
const char splitChar = '=';
|
||||||
map<string, const char*> result;
|
map<string, const char *> result;
|
||||||
if (argc <= 1) return result;
|
if (argc <= 1)
|
||||||
|
return result;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
@@ -780,9 +775,9 @@ map<string, const char*> mapArguments(int argc, char *argv[])
|
|||||||
int argLength = strlen(argv[i]);
|
int argLength = strlen(argv[i]);
|
||||||
string argName;
|
string argName;
|
||||||
string argValue;
|
string argValue;
|
||||||
char* argValueChar;
|
char *argValueChar;
|
||||||
|
|
||||||
for (int j=0;j<argLength;j++)
|
for (int j = 0; j < argLength; j++)
|
||||||
{
|
{
|
||||||
if (argv[i][j] == splitChar)
|
if (argv[i][j] == splitChar)
|
||||||
{
|
{
|
||||||
@@ -800,11 +795,20 @@ map<string, const char*> mapArguments(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//getCharsFromString(argValue, argValueChar);
|
const char *chValue = argValue.c_str();
|
||||||
|
|
||||||
const char * chValue = argValue.c_str();
|
|
||||||
|
|
||||||
result.insert(make_pair(argName, chValue));
|
result.insert(make_pair(argName, chValue));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getCompletePath(string fileName)
|
||||||
|
{
|
||||||
|
//std::filesystem::path executablePath = std::filesystem::canonical(std::filesystem::current_path()); // / std::filesystem::path(argv[0]));
|
||||||
|
std::filesystem::path exePath = std::filesystem::canonical("/proc/self/exe"); // / std::filesystem::path(argv[0]));
|
||||||
|
//std::filesystem::path fullPath = executablePath.parent_path() / "licenceData.xml";
|
||||||
|
std::filesystem::path fullPathOther = exePath.parent_path() / fileName;
|
||||||
|
//std::string fullPathStr = fullPath.string();
|
||||||
|
std::string fullPathStrOther = fullPathOther.string();
|
||||||
|
return fullPathStrOther;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user