[Cryptography] Generate secure challenges
This commit is contained in:
parent
724efa1050
commit
06bb09e1f0
@ -31,7 +31,7 @@ namespace Components
|
||||
|
||||
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 maxPort = Dvar::Var("net_discoveryPortRangeMax").get<unsigned int>();
|
||||
|
@ -245,7 +245,7 @@ namespace Components
|
||||
|
||||
if (Dedicated::IsEnabled())
|
||||
{
|
||||
entry->challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
entry->challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
|
||||
Proto::Node::Packet packet;
|
||||
packet.set_challenge(entry->challenge);
|
||||
@ -393,7 +393,7 @@ namespace Components
|
||||
{
|
||||
if (Dvar::Var("sv_lanOnly").get<bool>()) return;
|
||||
|
||||
std::string challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
std::string challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
|
||||
Proto::Node::Packet packet;
|
||||
packet.set_challenge(challenge);
|
||||
@ -431,7 +431,7 @@ namespace Components
|
||||
if (packet.challenge().empty()) return;
|
||||
|
||||
std::string signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, packet.challenge());
|
||||
std::string challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
std::string challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
|
||||
// The challenge this client sent is exactly the challenge we stored for this client
|
||||
// That means this is us, so we're going to ignore us :P
|
||||
@ -656,7 +656,7 @@ namespace Components
|
||||
#endif
|
||||
|
||||
// Initialize session data
|
||||
session->challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
session->challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
session->lastTime = Game::Sys_Milliseconds();
|
||||
session->valid = false;
|
||||
|
||||
@ -909,7 +909,7 @@ namespace Components
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::string message = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
std::string message = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
std::string signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, message);
|
||||
|
||||
if (!Utils::Cryptography::ECC::VerifyMessage(Node::SignatureKey, message, signature))
|
||||
@ -925,7 +925,7 @@ namespace Components
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::string message = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
std::string message = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
std::string signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, message);
|
||||
|
||||
// Invalidate the message...
|
||||
@ -943,7 +943,7 @@ namespace Components
|
||||
printf("Testing ECDSA key import...");
|
||||
|
||||
std::string pubKey = Node::SignatureKey.getPublicKey();
|
||||
std::string message = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
std::string message = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
std::string signature = Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, message);
|
||||
|
||||
Utils::Cryptography::ECC::Key testKey;
|
||||
|
@ -30,7 +30,7 @@ namespace Components
|
||||
Party::Container.awaitingPlaylist = false;
|
||||
Party::Container.joinTime = Game::Sys_Milliseconds();
|
||||
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);
|
||||
|
||||
|
@ -129,7 +129,7 @@ namespace Components
|
||||
Network::Handle("rconRequest", [] (Network::Address address, std::string data)
|
||||
{
|
||||
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();
|
||||
|
||||
Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge);
|
||||
|
@ -595,7 +595,7 @@ namespace Components
|
||||
SendServers--;
|
||||
|
||||
server->sendTime = Game::Sys_Milliseconds();
|
||||
server->challenge = Utils::String::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||
server->challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
|
||||
++ServerList::RefreshContainer.sentCount;
|
||||
|
||||
|
@ -16,6 +16,16 @@ namespace Utils
|
||||
|
||||
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 number = 0;
|
||||
|
@ -134,6 +134,7 @@ namespace Utils
|
||||
class Rand
|
||||
{
|
||||
public:
|
||||
static std::string GenerateChallenge();
|
||||
static uint32_t GenerateInt();
|
||||
static void Initialize();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user