mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-22 20:42:03 +00:00
feat(core): add verification of selected pairing methods, add NoMethod pairing for usb interface
[no changelog]
This commit is contained in:
parent
5727c7e319
commit
878d03f236
@ -280,9 +280,10 @@ async def _handle_state_TH2(ctx: Channel, message_length: int, ctrl_byte: int) -
|
||||
)
|
||||
if TYPE_CHECKING:
|
||||
assert ThpHandshakeCompletionReqNoisePayload.is_type_of(noise_payload)
|
||||
for i in noise_payload.pairing_methods:
|
||||
if i not in ctx.selected_pairing_methods:
|
||||
ctx.selected_pairing_methods.append(i)
|
||||
enabled_methods = thp_messages.get_enabled_pairing_methods(ctx.iface)
|
||||
for method in noise_payload.pairing_methods:
|
||||
if method in enabled_methods and method not in ctx.selected_pairing_methods:
|
||||
ctx.selected_pairing_methods.append(method)
|
||||
if __debug__:
|
||||
log.debug(
|
||||
__name__,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import ustruct
|
||||
from micropython import const
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from storage.cache_thp import BROADCAST_CHANNEL_ID
|
||||
from trezor import protobuf, utils
|
||||
@ -31,6 +32,9 @@ TREZOR_STATE_PAIRED = b"\x01"
|
||||
if __debug__:
|
||||
from trezor import log
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from trezor.wire import WireInterface
|
||||
|
||||
|
||||
class PacketHeader:
|
||||
format_str_init = ">BHH"
|
||||
@ -70,17 +74,28 @@ class PacketHeader:
|
||||
|
||||
_ENCODED_DEVICE_PROPERTIES: bytes | None = None
|
||||
|
||||
_ENABLED_PAIRING_METHODS = [
|
||||
_DEFAULT_ENABLED_PAIRING_METHODS = [
|
||||
ThpPairingMethod.CodeEntry,
|
||||
ThpPairingMethod.QrCode,
|
||||
ThpPairingMethod.NFC_Unidirectional,
|
||||
]
|
||||
|
||||
|
||||
def _get_device_properties() -> ThpDeviceProperties:
|
||||
def get_enabled_pairing_methods(
|
||||
iface: WireInterface | None = None,
|
||||
) -> list[ThpPairingMethod]:
|
||||
import usb
|
||||
|
||||
l = _DEFAULT_ENABLED_PAIRING_METHODS.copy()
|
||||
if iface is not None and iface is usb.iface_wire:
|
||||
l.append(ThpPairingMethod.NoMethod)
|
||||
return l
|
||||
|
||||
|
||||
def _get_device_properties(iface: WireInterface | None = None) -> ThpDeviceProperties:
|
||||
# TODO define model variants
|
||||
return ThpDeviceProperties(
|
||||
pairing_methods=_ENABLED_PAIRING_METHODS,
|
||||
pairing_methods=get_enabled_pairing_methods(iface),
|
||||
internal_model=utils.INTERNAL_MODEL,
|
||||
model_variant=0,
|
||||
bootloader_mode=False,
|
||||
|
Loading…
Reference in New Issue
Block a user