Hold cryptLock around RNG use in admin and key verification (#11096)

setPassKey drew the session passkey outside cryptLock, unlike the signing
and key verification paths. Also replaces random() for the key verification
nonce with the hardware RNG.
This commit is contained in:
Thomas Göttgens
2026-07-20 18:36:06 -05:00
committed by GitHub
parent 67e2012136
commit 51019b14f4
2 changed files with 17 additions and 3 deletions
+8 -1
View File
@@ -151,7 +151,14 @@ bool KeyVerificationModule::sendInitialRequest(NodeNum remoteNode)
return false;
}
updateState(true);
currentNonce = random();
// The nonce binds the handshake, so draw it from the hardware RNG (falling back to the CSPRNG)
// under cryptLock, as allocReply does for the security number. random() is both predictable and
// only 32 bits wide, leaving half of this nonce zero.
{
concurrency::LockGuard g(cryptLock);
if (!HardwareRNG::fill((uint8_t *)&currentNonce, sizeof(currentNonce)))
CryptRNG.rand((uint8_t *)&currentNonce, sizeof(currentNonce));
}
currentNonceTimestamp = getTime();
currentRemoteNode = remoteNode;
meshtastic_KeyVerification KeyVerification = meshtastic_KeyVerification_init_zero;