1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-22 14:38:27 +00:00

feat(core): use random suffix for BLE name when pairing

[no changelog]
This commit is contained in:
Martin Milata 2025-07-03 15:04:40 +02:00
parent 00d8683e77
commit 1faad192d8

View File

@ -2,6 +2,7 @@ import trezorble as ble
import trezorui_api
from storage import device as storage_device
from trezor import utils
from trezor.crypto import random
from trezor.ui.layouts import CONFIRMED, raise_if_not_confirmed
from trezor.wire import ActionCancelled
@ -13,8 +14,25 @@ def _end_pairing() -> None:
ble.stop_advertising()
def _default_ble_name() -> str:
"""Return model name and three random letters.
>>> n1 = _default_ble_name()
>>> n1.startswith(utils.MODE_FULL_NAME)
True
>>> n2 = _default_ble_name()
>>> n2.startswith(utils.MODE_FULL_NAME)
True
>>> n1 == n2
False
"""
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
random_chars = "".join(charset[random.uniform(len(charset))] for _ in range(3))
return f"{utils.MODEL_FULL_NAME} ({random_chars})"
async def pair_new_device() -> None:
label = storage_device.get_label() or utils.MODEL_FULL_NAME
label = storage_device.get_label() or _default_ble_name()
ble.start_advertising(False, label)
try:
code = await raise_if_not_confirmed(