1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

feat(core): add ThpInvalidDataError

[no changelog]
This commit is contained in:
M1nd3r 2024-07-29 13:47:12 +02:00
parent 894c9989e6
commit 5cde36050b
2 changed files with 13 additions and 1 deletions

View File

@ -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
@ -26,6 +30,7 @@ class ThpErrorType(IntEnum):
TRANSPORT_BUSY = 1
UNALLOCATED_CHANNEL = 2
DECRYPTION_FAILED = 3
INVALID_DATA = 4
class ChannelState(IntEnum):

View File

@ -27,6 +27,7 @@ from . import (
ThpDecryptionError,
ThpError,
ThpErrorType,
ThpInvalidDataError,
ThpUnallocatedSessionError,
)
from . import alternating_bit_protocol as ABP
@ -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")
@ -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(