Upravy a opravování kryptování

This commit is contained in:
2024-04-11 14:31:24 +02:00
parent ead3ba6e3e
commit 3b1ee6038e
47 changed files with 414 additions and 422 deletions

View File

@@ -1,15 +1,18 @@
#ifndef EZ_APPLICATION_LICENCE_DISABLE
#include "licenceELC2.h"
#include "utils.h"
LicenceELC2::LicenceELC2() {}
LicenceELC2::LicenceELC2(){}
LicenceELC2::~LicenceELC2(){}
LicenceELC2::~LicenceELC2() {}
LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification): lIdentification(licIdentification)
{}
LicenceELC2::LicenceELC2(LicenceIdentification &licIdentification) : lIdentification(licIdentification)
{
}
/// @brief get proper licencename
/// @brief get proper licencename
/// @param licPostfix
/// @return
string LicenceELC2::getLicenceName()
@@ -18,7 +21,7 @@ string LicenceELC2::getLicenceName()
char prefixChar = 97;
int licType = (int)lIdentification.licLicenceType;
int lVersion = lIdentification.licenceVersion;
unordered_map<int, string> baseString;
baseString.insert(std::pair<int, string>((int)LicenceType::EOS_EOV, "ezlic_eovosv"));
baseString.insert(std::pair<int, string>((int)LicenceType::DDTS, "ezlic_ddts"));
@@ -70,7 +73,8 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
const unsigned char *plainTextArray = content.data();
int finalEncryptedLength = encrypt(plainTextArray, content.size(), aesKey, initVector, encrypted);
if (finalEncryptedLength <= 0) throw LicenceException((int)GeneralError::EncryptError, "Chyba při kryptování.");
if (finalEncryptedLength <= 0)
throw LicenceException((int)GeneralError::EncryptError, "Chyba při kryptování.");
std::vector<unsigned char> result(encrypted, encrypted + finalEncryptedLength);
@@ -79,69 +83,79 @@ vector<unsigned char> LicenceELC2::cryptPrivateContent(const std::vector<unsigne
vector<unsigned char> LicenceELC2::decryptPrivateContent(const std::vector<unsigned char> &content)
{
BYTE initVector[15] = {0};
BYTE aesKey[32] = {0};
BYTE initVector[CRYPT_INIT_VECTOR_SIZE] = {0};
BYTE aesKey[CRYPT_INIT_KEY_SIZE] = {0};
LicenceELC2::initVector(initVector, aesKey);
const unsigned char *encryptedData = content.data();
unsigned char decrypted[10000] = {};
// cout << "\n --- zašifrovaná data přímo z decrypt metody:" << content.size() << "--- \n";
// for (int i = 0; i < (int)content.size(); i++)
// {
// cout << (int)encryptedData[i] << "-";
// }
// cout << "---\n\n";
int decrypted_len = decrypt(encryptedData, content.size(), aesKey, initVector, decrypted);
if (decrypted_len <= 0) throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování.");
if (decrypted_len <= 0)
throw LicenceException((int)GeneralError::DecryptError, "Chyba při dekryptování.");
std::vector<unsigned char> result(decrypted, decrypted + decrypted_len);
vector<unsigned char> res{};
for (int i = 0; i < decrypted_len; i++)
{
// if (i==15) res.push_back(1);
res.push_back(decrypted[i]);
}
return result;
// cout << "\n --- dešifrovaná data přímo z decrypt metody:" << content.size() << "--- \n";
// for (int i = 0; i < decrypted_len; i++)
// {
// cout << (int)decrypted[i] << "-";
// }
// cout << "---\n\n";
return res;
// std::vector<unsigned char> result(decrypted, decrypted + decrypted_len);
// return result;
}
void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[])
void LicenceELC2::initVector(BYTE *iVector, BYTE *key)
{
CryptInitVector vec1 = {this->sdCard.cardData.CID[10],
this->sdCard.cardData.CID[12],
this->sdCard.cardData.CID[11],
this->sdCard.cardData.CID[9],
this->sdCard.cardData.CID_nibble[22] - 15,
this->sdCard.cardData.CID_nibble[24] - 15,
this->sdCard.cardData.CID_nibble[25] - 15,
this->sdCard.cardData.CID_nibble[21] - 15,
9, 10, 11, 12, 13, 14, 15, 16};
CryptInitVector vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; // TODO přidat smysluplnější indexy
CryptInitVector vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
struct Vector15
{
int vec[15];
};
std::unordered_map<int, CryptInitVector> vectors;
vectors.insert(std::pair<int, CryptInitVector>(1, vec1));
vectors.insert(std::pair<int, CryptInitVector>(2, vec2));
vectors.insert(std::pair<int, CryptInitVector>(3, vec3));
Vector15 vec1 = {this->sdCard.cardData.CID[10],
this->sdCard.cardData.CID[12],
this->sdCard.cardData.CID[11],
this->sdCard.cardData.CID[9],
this->sdCard.cardData.CID_nibble[22] - 15,
this->sdCard.cardData.CID_nibble[24] - 15,
this->sdCard.cardData.CID_nibble[25] - 15,
this->sdCard.cardData.CID_nibble[21] - 15,
9, 10, 11, 12, 13, 14, 15};
Vector15 vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //TODO přidat smysluplnější indexy
Vector15 vec3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
CryptAesKey key1 = {this->sdCard.cardData.CID[12],
this->sdCard.cardData.CID[23] - 15,
this->sdCard.cardData.CID[25] - 15,
this->sdCard.cardData.CID[11],
this->sdCard.cardData.CID[9],
this->sdCard.cardData.CID_nibble[21],
this->sdCard.cardData.CID[9] % 25,
this->sdCard.cardData.CID_nibble[22] - 15,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
CryptAesKey key2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
CryptAesKey key3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
std::unordered_map<int, Vector15> vectors;
vectors.insert(std::pair<int, Vector15>(1, vec1));
vectors.insert(std::pair<int, Vector15>(2, vec2));
vectors.insert(std::pair<int, Vector15>(3, vec3));
struct Key32
{
int key[32];
};
Key32 key1 = {this->sdCard.cardData.CID[12],
this->sdCard.cardData.CID[23] - 15,
this->sdCard.cardData.CID[25] - 15,
this->sdCard.cardData.CID[11],
this->sdCard.cardData.CID[9],
this->sdCard.cardData.CID_nibble[21],
this->sdCard.cardData.CID[9] % 25,
this->sdCard.cardData.CID_nibble[22] - 15,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
Key32 key2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
Key32 key3 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
std::unordered_map<int, Key32> keys;
keys.insert(std::pair<int, Key32>(1, key1));
keys.insert(std::pair<int, Key32>(2, key2));
keys.insert(std::pair<int, Key32>(3, key3));
std::unordered_map<int, CryptAesKey> keys;
keys.insert(std::pair<int, CryptAesKey>(1, key1));
keys.insert(std::pair<int, CryptAesKey>(2, key2));
keys.insert(std::pair<int, CryptAesKey>(3, key3));
int lVersion = lIdentification.licenceVersion;
@@ -169,4 +183,4 @@ void LicenceELC2::initVector(BYTE (&iVector)[], BYTE (&key)[])
memcpy(&key[24], &key[12], 8);
}
#endif