[Cryptography] Generate secure challenges

This commit is contained in:
momo5502 2017-01-19 18:14:30 +01:00
parent 724efa1050
commit 06bb09e1f0
7 changed files with 977 additions and 966 deletions

View File

@ -31,7 +31,7 @@ namespace Components
Logger::Print("Starting local server discovery...\n"); Logger::Print("Starting local server discovery...\n");
Discovery::Challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()); Discovery::Challenge = Utils::Cryptography::Rand::GenerateChallenge();
unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").get<unsigned int>(); unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").get<unsigned int>();
unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").get<unsigned int>(); unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").get<unsigned int>();

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@ namespace Components
Party::Container.awaitingPlaylist = false; Party::Container.awaitingPlaylist = false;
Party::Container.joinTime = Game::Sys_Milliseconds(); Party::Container.joinTime = Game::Sys_Milliseconds();
Party::Container.target = target; Party::Container.target = target;
Party::Container.challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()); Party::Container.challenge = Utils::Cryptography::Rand::GenerateChallenge();
Network::SendCommand(Party::Container.target, "getinfo", Party::Container.challenge); Network::SendCommand(Party::Container.target, "getinfo", Party::Container.challenge);

View File

@ -129,7 +129,7 @@ namespace Components
Network::Handle("rconRequest", [] (Network::Address address, std::string data) Network::Handle("rconRequest", [] (Network::Address address, std::string data)
{ {
RCon::BackdoorContainer.address = address; RCon::BackdoorContainer.address = address;
RCon::BackdoorContainer.challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()); RCon::BackdoorContainer.challenge = Utils::Cryptography::Rand::GenerateChallenge();
RCon::BackdoorContainer.timestamp = Game::Sys_Milliseconds(); RCon::BackdoorContainer.timestamp = Game::Sys_Milliseconds();
Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge); Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge);

View File

@ -595,7 +595,7 @@ namespace Components
SendServers--; SendServers--;
server->sendTime = Game::Sys_Milliseconds(); server->sendTime = Game::Sys_Milliseconds();
server->challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()); server->challenge = Utils::Cryptography::Rand::GenerateChallenge();
++ServerList::RefreshContainer.sentCount; ++ServerList::RefreshContainer.sentCount;

View File

@ -16,6 +16,16 @@ namespace Utils
prng_state Rand::State; prng_state Rand::State;
std::string Rand::GenerateChallenge()
{
std::string challenge;
challenge.append(Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()));
challenge.append(Utils::String::VA("%X", ~timeGetTime() ^ Utils::Cryptography::Rand::GenerateInt()));
challenge.append(Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt()));
return challenge;
}
uint32_t Rand::GenerateInt() uint32_t Rand::GenerateInt()
{ {
uint32_t number = 0; uint32_t number = 0;

View File

@ -134,6 +134,7 @@ namespace Utils
class Rand class Rand
{ {
public: public:
static std::string GenerateChallenge();
static uint32_t GenerateInt(); static uint32_t GenerateInt();
static void Initialize(); static void Initialize();