Skip to content

Commit

Permalink
feat(core): add ThpInvalidDataError
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
M1nd3r committed Jul 29, 2024
1 parent 7bf745d commit e402934
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/trezor/wire/thp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ThpDecryptionError(ThpError):
pass


class ThpInvalidDataError(ThpError):
pass


class ThpUnallocatedSessionError(ThpError):
def __init__(self, session_id: int):
self.session_id = session_id
Expand All @@ -26,6 +30,7 @@ class ThpErrorType(IntEnum):
TRANSPORT_BUSY = 1
UNALLOCATED_CHANNEL = 2
DECRYPTION_FAILED = 3
INVALID_DATA = 4


class ChannelState(IntEnum):
Expand Down
9 changes: 8 additions & 1 deletion core/src/trezor/wire/thp/received_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ThpDecryptionError,
ThpError,
ThpErrorType,
ThpInvalidDataError,
ThpUnallocatedSessionError,
)
from . import alternating_bit_protocol as ABP
Expand Down Expand Up @@ -115,6 +116,10 @@ async def handle_received_message(
await ctx.write_error(ThpErrorType.DECRYPTION_FAILED)
ctx.clear()
print(e)
except ThpInvalidDataError as e:
await ctx.write_error(ThpErrorType.INVALID_DATA)
ctx.clear()
print(e)
if __debug__:
log.debug(__name__, "handle_received_message - end")

Expand Down Expand Up @@ -282,7 +287,9 @@ async def _handle_state_TH2(ctx: Channel, message_length: int, ctrl_byte: int) -
assert ThpHandshakeCompletionReqNoisePayload.is_type_of(noise_payload)
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:
if method not in enabled_methods:
raise ThpInvalidDataError()
if method not in ctx.selected_pairing_methods:
ctx.selected_pairing_methods.append(method)
if __debug__:
log.debug(
Expand Down

0 comments on commit e402934

Please sign in to comment.