chore(net): improve readability of Grunt::ClientLink command handlers

This commit is contained in:
fallenoak 2025-09-25 15:05:48 -07:00
parent d39789d624
commit 92f507820b
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D

View File

@ -190,11 +190,32 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) {
// OsSecureRandom(randomSeed, sizeof(randomSeed)); // OsSecureRandom(randomSeed, sizeof(randomSeed));
SRP6_Random srpRandom(randomSeed, sizeof(randomSeed)); SRP6_Random srpRandom(randomSeed, sizeof(randomSeed));
if (this->m_srpClient.CalculateProof(largeSafePrime, largeSafePrimeLen, generator, generatorLen, salt, 32, serverPublicKey, 32, srpRandom)) { // Calculate proof
auto calculateResult = this->m_srpClient.CalculateProof(
largeSafePrime,
largeSafePrimeLen,
generator,
generatorLen,
salt,
SALT_LEN,
serverPublicKey,
SERVER_PUBLIC_KEY_LEN,
srpRandom
);
// Calculate proof failure
if (calculateResult != SRP6_OK) {
this->SetState(STATE_CONNECTED); this->SetState(STATE_CONNECTED);
this->m_clientResponse->LogonResult(GRUNT_RESULT_5, nullptr, 0, 0); this->m_clientResponse->LogonResult(GRUNT_RESULT_5, nullptr, 0, 0);
} else {
return 2;
}
// Calculate proof success
this->SetState(STATE_CONNECT_VERSION); this->SetState(STATE_CONNECT_VERSION);
this->m_clientResponse->SetPinInfo(pinEnabled, pinGridSeed, pinSalt); this->m_clientResponse->SetPinInfo(pinEnabled, pinGridSeed, pinSalt);
@ -215,7 +236,6 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) {
this->m_clientResponse->SetTokenInfo(tokenEnabled, tokenRequired); this->m_clientResponse->SetTokenInfo(tokenEnabled, tokenRequired);
this->m_clientResponse->GetVersionProof(versionChallenge); this->m_clientResponse->GetVersionProof(versionChallenge);
}
return 2; return 2;
} }
@ -256,7 +276,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
// Authentication success // Authentication success
void* serverProof; uint8_t* serverProof;
uint32_t accountFlags = 0x0; uint32_t accountFlags = 0x0;
uint32_t surveyID; uint32_t surveyID;
@ -264,7 +284,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
return 0; return 0;
} }
msg.GetDataInSitu(serverProof, SERVER_PROOF_LEN); msg.GetDataInSitu(reinterpret_cast<void*&>(serverProof), SERVER_PROOF_LEN);
msg.Get(accountFlags); msg.Get(accountFlags);
msg.Get(surveyID); msg.Get(surveyID);
@ -280,11 +300,22 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
return 1; return 1;
} }
if (this->m_srpClient.VerifyServerProof(static_cast<uint8_t*>(serverProof), SERVER_PROOF_LEN)) { // Verify server proof
auto verifyResult = this->m_srpClient.VerifyServerProof(serverProof, SERVER_PROOF_LEN);
// Verify server proof failure
if (verifyResult != SRP6_OK) {
this->SetState(STATE_CONNECTED); this->SetState(STATE_CONNECTED);
this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_11, nullptr, 0, 0); this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_11, nullptr, 0, 0x0);
} else {
return 2;
}
// Verify server proof success
this->m_accountFlags = accountFlags; this->m_accountFlags = accountFlags;
// TODO // TODO
// this->uint94 = 0; // this->uint94 = 0;
@ -293,7 +324,6 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
this->SetState(STATE_AUTHENTICATED); this->SetState(STATE_AUTHENTICATED);
this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_0, this->m_srpClient.sessionKey, 40, logonFlags); this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_0, this->m_srpClient.sessionKey, 40, logonFlags);
}
return 2; return 2;
} }