mirror of
https://github.com/esphome/esphome.git
synced 2026-03-03 03:08:21 -07:00
[wizard] Use secrets module for fallback AP password generation
Replace random.choice() with secrets.choice() for generating the fallback hotspot password. The random module uses Mersenne Twister which is not cryptographically secure. The secrets module is the correct choice for credential generation. The file already imports secrets for other credential generation.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import base64
|
||||
from pathlib import Path
|
||||
import random
|
||||
import secrets
|
||||
import string
|
||||
from typing import Literal, NotRequired, TypedDict, Unpack
|
||||
@@ -130,7 +129,7 @@ def wizard_file(**kwargs: Unpack[WizardFileKwargs]) -> str:
|
||||
if len(ap_name) > 32:
|
||||
ap_name = ap_name_base
|
||||
kwargs["fallback_name"] = ap_name
|
||||
kwargs["fallback_psk"] = "".join(random.choice(letters) for _ in range(12))
|
||||
kwargs["fallback_psk"] = "".join(secrets.choice(letters) for _ in range(12))
|
||||
|
||||
base = BASE_CONFIG_FRIENDLY if kwargs.get("friendly_name") else BASE_CONFIG
|
||||
|
||||
|
||||
Reference in New Issue
Block a user