mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-23 15:08:19 +00:00
feat(core): use random suffix for BLE name when pairing
[no changelog]
This commit is contained in:
parent
00d8683e77
commit
1faad192d8
@ -2,6 +2,7 @@ import trezorble as ble
|
|||||||
import trezorui_api
|
import trezorui_api
|
||||||
from storage import device as storage_device
|
from storage import device as storage_device
|
||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
from trezor.crypto import random
|
||||||
from trezor.ui.layouts import CONFIRMED, raise_if_not_confirmed
|
from trezor.ui.layouts import CONFIRMED, raise_if_not_confirmed
|
||||||
from trezor.wire import ActionCancelled
|
from trezor.wire import ActionCancelled
|
||||||
|
|
||||||
@ -13,8 +14,25 @@ def _end_pairing() -> None:
|
|||||||
ble.stop_advertising()
|
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:
|
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)
|
ble.start_advertising(False, label)
|
||||||
try:
|
try:
|
||||||
code = await raise_if_not_confirmed(
|
code = await raise_if_not_confirmed(
|
||||||
|
Loading…
Reference in New Issue
Block a user