mirror of
https://github.com/esphome/esphome.git
synced 2026-02-19 07:55:35 -07:00
[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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user