From 7a3b48831bfc9c4aa8c39c1e42d5bf5dd73e43c5 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 1 Jan 2019 20:31:51 +1300 Subject: whole buncha fixes & switching to vmp --- csgo-loader/csgo-client/Security/Encryption.cpp | 43 ++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'csgo-loader/csgo-client/Security/Encryption.cpp') diff --git a/csgo-loader/csgo-client/Security/Encryption.cpp b/csgo-loader/csgo-client/Security/Encryption.cpp index 133946a..d361d1c 100644 --- a/csgo-loader/csgo-client/Security/Encryption.cpp +++ b/csgo-loader/csgo-client/Security/Encryption.cpp @@ -563,21 +563,36 @@ namespace Wrapper } // Wrapper for the AES256 encryption algorithm. - void Encryption::Start() { } + void Encryption::Start() + { + // Create cryptographic context. + if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, 0)) + { + if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, CRYPT_NEWKEYSET)) + INFO_ASSERT("Critical failure\nContact an admin with the following code: %08x", GetLastError()); + } + + uint8_t RandomBytes[32]; + uint32_t RandomBytesCount = sizeof RandomBytes; + + // Generate random bytes to use as encryption key. + if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes)) + std::memcpy(m_EncryptionKey, RandomBytes, RandomBytesCount); + + // Release context. + if(m_CryptProvider) + CryptReleaseContext(m_CryptProvider, 0); + } void Encryption::Start(ByteArray &EncryptionKey) { // If an encryption key is provided, initialise the wrapper with // the passed parameter. if(!EncryptionKey.empty()) - { - for(auto &It : EncryptionKey) - m_EncryptionKey.emplace_back(It); - } - else - { + std::memcpy(m_EncryptionKey, EncryptionKey.data(), EncryptionKey.size()); + + if(EncryptionKey.empty()) Start(); - } } ByteArray Encryption::Encrypt(ByteArray &Data) @@ -585,11 +600,7 @@ namespace Wrapper // Encrypt outgoing data. ByteArray Encrypted; - #ifdef DEBUG - Encrypted = Data; - #else - Aes256::encrypt(m_EncryptionKey, Data, Encrypted); - #endif + Aes256::encrypt(GetKey(), Data, Encrypted); return Encrypted; } @@ -599,11 +610,7 @@ namespace Wrapper // Decrypt incoming data. ByteArray Decrypted; - #ifdef DEBUG - Decrypted = Data; - #else - Aes256::decrypt(m_EncryptionKey, Data, Decrypted); - #endif + Aes256::decrypt(GetKey(), Data, Decrypted); return Decrypted; } -- cgit v1.2.3