diff --git a/core/src/trezor/wire/thp/received_message_handler.py b/core/src/trezor/wire/thp/received_message_handler.py index fb812593c..2b3c539c1 100644 --- a/core/src/trezor/wire/thp/received_message_handler.py +++ b/core/src/trezor/wire/thp/received_message_handler.py @@ -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__, diff --git a/core/src/trezor/wire/thp/thp_messages.py b/core/src/trezor/wire/thp/thp_messages.py index 7d2758f8b..a506daaea 100644 --- a/core/src/trezor/wire/thp/thp_messages.py +++ b/core/src/trezor/wire/thp/thp_messages.py @@ -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,