2026-02-12 02:09:15 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace game {
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-13 16:53:28 -08:00
|
|
|
* Warden anti-cheat crypto handler.
|
|
|
|
|
* Derives RC4 keys from the 40-byte SRP session key using SHA1Randx,
|
|
|
|
|
* then encrypts/decrypts Warden packet payloads.
|
2026-02-12 02:09:15 -08:00
|
|
|
*/
|
|
|
|
|
class WardenCrypto {
|
|
|
|
|
public:
|
|
|
|
|
WardenCrypto();
|
|
|
|
|
~WardenCrypto();
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-13 16:53:28 -08:00
|
|
|
* Initialize Warden crypto from the 40-byte SRP session key.
|
|
|
|
|
* Derives encrypt (client->server) and decrypt (server->client) RC4 keys
|
|
|
|
|
* using the SHA1Randx / WardenKeyGenerator algorithm.
|
2026-02-12 02:09:15 -08:00
|
|
|
*/
|
2026-02-13 16:53:28 -08:00
|
|
|
bool initFromSessionKey(const std::vector<uint8_t>& sessionKey);
|
2026-02-12 02:09:15 -08:00
|
|
|
|
|
|
|
|
/**
|
2026-02-13 16:53:28 -08:00
|
|
|
* Replace RC4 keys (called after module hash challenge succeeds).
|
|
|
|
|
* @param newEncryptKey 16-byte key for encrypting outgoing packets
|
|
|
|
|
* @param newDecryptKey 16-byte key for decrypting incoming packets
|
2026-02-12 02:09:15 -08:00
|
|
|
*/
|
2026-02-13 16:53:28 -08:00
|
|
|
void replaceKeys(const std::vector<uint8_t>& newEncryptKey,
|
|
|
|
|
const std::vector<uint8_t>& newDecryptKey);
|
|
|
|
|
|
|
|
|
|
/** Decrypt an incoming SMSG_WARDEN_DATA payload. */
|
2026-02-12 02:09:15 -08:00
|
|
|
std::vector<uint8_t> decrypt(const std::vector<uint8_t>& data);
|
|
|
|
|
|
2026-02-13 16:53:28 -08:00
|
|
|
/** Encrypt an outgoing CMSG_WARDEN_DATA payload. */
|
2026-02-12 02:09:15 -08:00
|
|
|
std::vector<uint8_t> encrypt(const std::vector<uint8_t>& data);
|
|
|
|
|
|
|
|
|
|
bool isInitialized() const { return initialized_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool initialized_;
|
|
|
|
|
|
2026-02-13 16:53:28 -08:00
|
|
|
// RC4 state for decrypting incoming packets (server->client)
|
|
|
|
|
std::vector<uint8_t> decryptRC4State_;
|
|
|
|
|
uint8_t decryptRC4_i_;
|
|
|
|
|
uint8_t decryptRC4_j_;
|
2026-02-12 02:09:15 -08:00
|
|
|
|
2026-02-13 16:53:28 -08:00
|
|
|
// RC4 state for encrypting outgoing packets (client->server)
|
|
|
|
|
std::vector<uint8_t> encryptRC4State_;
|
|
|
|
|
uint8_t encryptRC4_i_;
|
|
|
|
|
uint8_t encryptRC4_j_;
|
2026-02-12 02:09:15 -08:00
|
|
|
|
|
|
|
|
void initRC4(const std::vector<uint8_t>& key,
|
|
|
|
|
std::vector<uint8_t>& state,
|
|
|
|
|
uint8_t& i, uint8_t& j);
|
|
|
|
|
|
|
|
|
|
void processRC4(const uint8_t* input, uint8_t* output, size_t length,
|
|
|
|
|
std::vector<uint8_t>& state, uint8_t& i, uint8_t& j);
|
2026-02-13 16:53:28 -08:00
|
|
|
|
2026-02-14 19:20:32 -08:00
|
|
|
public:
|
2026-02-13 16:53:28 -08:00
|
|
|
/**
|
|
|
|
|
* SHA1Randx / WardenKeyGenerator: generates pseudo-random bytes from a seed.
|
2026-02-14 19:20:32 -08:00
|
|
|
* Used to derive the 16-byte encrypt and decrypt keys from a seed.
|
|
|
|
|
* Public so GameHandler can use it for module hash key derivation.
|
2026-02-13 16:53:28 -08:00
|
|
|
*/
|
|
|
|
|
static void sha1RandxGenerate(const std::vector<uint8_t>& seed,
|
|
|
|
|
uint8_t* outputEncryptKey,
|
|
|
|
|
uint8_t* outputDecryptKey);
|
2026-02-12 02:09:15 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace game
|
|
|
|
|
} // namespace wowee
|