[ota] Use secrets module for OTA authentication cnonce

Replace random.random() with secrets.token_hex() for generating
the client nonce in OTA challenge-response authentication.

The random module uses Mersenne Twister which is not
cryptographically secure. The secrets module is the correct
choice for security-sensitive token generation.
This commit is contained in:
J. Nick Koston
2026-02-08 06:40:30 -06:00
parent 7b40e8afcb
commit 9616596146

View File

@@ -6,7 +6,7 @@ import hashlib
import io
import logging
from pathlib import Path
import random
import secrets
import socket
import sys
import time
@@ -301,7 +301,7 @@ def perform_ota(
_LOGGER.debug("Auth: %s Nonce is %s", hash_name, nonce)
# Generate cnonce
cnonce = hash_func(str(random.random()).encode()).hexdigest()
cnonce = secrets.token_hex(32)
_LOGGER.debug("Auth: %s CNonce is %s", hash_name, cnonce)
send_check(sock, cnonce, "auth cnonce")