Upravy a opravování kryptování
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#ifndef EZ_APPLICATION_LICENCE_DISABLE
|
||||
|
||||
#include "utils.h"
|
||||
#include "SDCard.h"
|
||||
|
||||
@@ -72,6 +74,11 @@ bool SDCard::readSDCard()
|
||||
|
||||
this->cardData.serialNumber = this->cardData.CID[9] << 24 | this->cardData.CID[10] << 16 | this->cardData.CID[11] << 8 | this->cardData.CID[12];
|
||||
|
||||
this->cardData.manufacturerDate_year = cHexNibbleToNo[this->cardData.CID_nibble[27]] * 10 + cHexNibbleToNo[this->cardData.CID_nibble[28]] + 2000;
|
||||
this->cardData.manufacturerDate_month = cHexNibbleToNo[this->cardData.CID_nibble[29]];
|
||||
this->cardData.date = to_string(this->cardData.manufacturerDate_month) + "/" + to_string(this->cardData.manufacturerDate_year);
|
||||
//string date = cSDMonthStr1[this->sdData.manufacturerDate_month] + std::to_string(this->sdData.manufacturerDate_year);
|
||||
|
||||
// CSD
|
||||
for (int i = 0; i < CSD_LENGTH; i++)
|
||||
this->cardData.CSD_nibble[i] = (BYTE)csd[i];
|
||||
@@ -141,3 +148,5 @@ bool SDCard::getCSDFromFile()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
5
src/common/cid
Normal file
5
src/common/cid
Normal file
@@ -0,0 +1,5 @@
|
||||
9f54495344434954615ad803c50171bf
|
||||
6 . x4 <20><><EFBFBD> .. nt$6 &<26> manfid 6 <20><><EFBFBD>
|
||||
cid "6 <10> fwrev 6 Jm<4A> csd ,6 gEd$
|
||||
subsystem 46 <20><><EFBFBD>%
|
||||
driver (6 <20><><EFBFBD>- ocr -6 <20><><EFBFBD>? power *6 <>4L type 6 <20>1M date #6 <20>rTP hwrev )6 n<>yR dsr '6 <20>` serial 6 NN<4E>m erase_size <20>6 <20>6<EFBFBD>m block 6 <20><><EFBFBD>n uevent 6 <18><>o ssr 6 <1E>q scr &6 &<26><>y oemid !6 <20><><EFBFBD>y ( preferred_erase_size %6 <20><><EFBFBD> name
|
||||
2
src/common/csd
Normal file
2
src/common/csd
Normal file
@@ -0,0 +1,2 @@
|
||||
400e00325b5900003be77f800a400043
|
||||
|
||||
BIN
src/common/ezlic_drt0_jjacdgpdxpb.lic
Normal file
BIN
src/common/ezlic_drt0_jjacdgpdxpb.lic
Normal file
Binary file not shown.
@@ -1,3 +1,6 @@
|
||||
#ifndef EZ_APPLICATION_LICENCE_DISABLE
|
||||
|
||||
|
||||
#include "licenceELC1.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -216,3 +219,5 @@ string LicenceELC1::getLicenceName(BYTE licPostfix)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifndef EZ_APPLICATION_LICENCE_DISABLE
|
||||
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/ssl.h> /* core library */
|
||||
@@ -127,14 +128,20 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
|
||||
* is 128 bits
|
||||
*/
|
||||
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Provide the message to be encrypted, and obtain the encrypted output.
|
||||
* EVP_EncryptUpdate can be called multiple times if necessary
|
||||
*/
|
||||
if (1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
ciphertext_len = len;
|
||||
|
||||
/*
|
||||
@@ -142,7 +149,10 @@ int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *ke
|
||||
* this stage.
|
||||
*/
|
||||
if (1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
ciphertext_len += len;
|
||||
|
||||
/* Clean up */
|
||||
@@ -472,3 +482,5 @@ bool readFile(string fileName, vector<char> &output)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user