#pragma once #include "auth/big_num.hpp" #include #include #include namespace wowee { namespace auth { // SRP6a implementation for World of Warcraft authentication // Based on the original wowee JavaScript implementation class SRP { public: SRP(); ~SRP() = default; // Initialize with username and password void initialize(const std::string& username, const std::string& password); // Initialize with username and pre-computed auth hash (SHA1(UPPER(user):UPPER(pass))) void initializeWithHash(const std::string& username, const std::vector& authHash); // Feed server challenge data (B, g, N, salt) void feed(const std::vector& B, const std::vector& g, const std::vector& N, const std::vector& salt); // Some SRP implementations use k = H(N|g) instead of the WoW-specific k=3. // Default is false (k=3). void setUseHashedK(bool enabled) { useHashedK_ = enabled; } // Controls how SHA1 outputs are interpreted when converted to big integers (x, u, optionally k). // Many SRP implementations treat hash outputs as big-endian integers. // Default is false (treat hash outputs as little-endian integers). void setHashBigEndian(bool enabled) { hashBigEndian_ = enabled; } // Get client public ephemeral (A) - send to server std::vector getA() const; // Get client proof (M1) - send to server std::vector getM1() const; // Verify server proof (M2) bool verifyServerProof(const std::vector& serverM2) const; // Get session key (K) - used for encryption std::vector getSessionKey() const; private: // WoW-specific SRP multiplier (k = 3) static constexpr uint32_t K_VALUE = 3; // Helper methods std::vector computeAuthHash(const std::string& username, const std::string& password) const; void computeClientEphemeral(); void computeSessionKey(); void computeProofs(const std::string& username); // SRP values BigNum g; // Generator BigNum N; // Prime modulus BigNum k; // Multiplier (3 for WoW) BigNum s; // Salt BigNum a; // Client private ephemeral BigNum A; // Client public ephemeral BigNum B; // Server public ephemeral BigNum x; // Salted password hash BigNum u; // Scrambling parameter BigNum S; // Shared session key (raw) // Derived values std::vector K; // Interleaved session key (40 bytes) std::vector M1; // Client proof (20 bytes) std::vector M2; // Expected server proof (20 bytes) // Stored credentials std::string stored_username; std::string stored_password; std::vector stored_auth_hash; // Pre-computed SHA1(UPPER(user):UPPER(pass)) bool initialized = false; bool useHashedK_ = false; bool hashBigEndian_ = false; }; } // namespace auth } // namespace wowee