iw4x-client/src/Components/Modules/Auth.hpp

63 lines
1.4 KiB
C++
Raw Normal View History

2016-02-21 13:57:56 -05:00
namespace Components
{
class Auth : public Component
{
public:
Auth();
~Auth();
const char* GetName() { return "Auth"; };
2016-04-11 07:32:11 -04:00
bool UnitTest();
2016-02-21 13:57:56 -05:00
2016-02-22 17:35:53 -05:00
static void StoreKey();
static void LoadKey(bool force = false);
static unsigned int GetKeyHash();
static uint32_t GetSecurityLevel();
2016-02-22 20:03:05 -05:00
static void IncreaseSecurityLevel(uint32_t level, std::string command = "");
2016-02-22 17:35:53 -05:00
static uint32_t GetZeroBits(Utils::Cryptography::Token token, std::string publicKey);
2016-04-11 07:32:11 -04:00
static void IncrementToken(Utils::Cryptography::Token& token, Utils::Cryptography::Token& computeToken, std::string publicKey, uint32_t zeroBits, bool* cancel = nullptr, uint64_t* count = nullptr);
2016-02-22 17:35:53 -05:00
2016-02-21 13:57:56 -05:00
private:
enum AuthState
{
STATE_UNKNOWN,
STATE_NEGOTIATING,
STATE_VALID,
STATE_INVALID,
};
struct AuthInfo
{
2016-04-11 07:32:11 -04:00
Utils::Cryptography::ECC::Key publicKey;
2016-02-21 13:57:56 -05:00
std::string challenge;
AuthState state;
int time;
};
2016-02-22 20:03:05 -05:00
struct TokenIncrementing
{
bool cancel;
bool generating;
2016-06-02 09:11:31 -04:00
std::thread thread;
2016-02-22 20:03:05 -05:00
uint32_t targetLevel;
int startTime;
std::string command;
2016-02-23 07:39:38 -05:00
uint64_t hashes;
2016-02-22 20:03:05 -05:00
};
2016-02-21 13:57:56 -05:00
static AuthInfo ClientAuthInfo[18];
2016-02-22 20:03:05 -05:00
static TokenIncrementing TokenContainer;
2016-02-21 13:57:56 -05:00
2016-02-22 17:35:53 -05:00
static Utils::Cryptography::Token GuidToken;
2016-04-11 07:32:11 -04:00
static Utils::Cryptography::Token ComputeToken;
static Utils::Cryptography::ECC::Key GuidKey;
2016-02-22 17:35:53 -05:00
2016-02-21 13:57:56 -05:00
static void Frame();
static void RegisterClient(int clientNum);
static void RegisterClientStub();
};
}