From 9510aaef3a07fcfd0028b4e7042b9d54c7cbc7f3 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Thu, 21 Mar 2024 09:42:02 +0100 Subject: [PATCH] Packet handlers, first draft --- core/src/all_modules.py | 2 ++ core/src/trezor/wire/thp/__init__.py | 18 ++++++++++++++++++ core/src/trezor/wire/thp/channel_context.py | 4 +--- core/src/trezor/wire/thp/packet_handlers.py | 13 +++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 core/src/trezor/wire/thp/packet_handlers.py diff --git a/core/src/all_modules.py b/core/src/all_modules.py index c7deb897d..f5e3727d2 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -215,6 +215,8 @@ trezor.wire.thp.channel_context import trezor.wire.thp.channel_context trezor.wire.thp.checksum import trezor.wire.thp.checksum +trezor.wire.thp.packet_handlers +import trezor.wire.thp.packet_handlers trezor.wire.thp.session_context import trezor.wire.thp.session_context trezor.wire.thp.thp_messages diff --git a/core/src/trezor/wire/thp/__init__.py b/core/src/trezor/wire/thp/__init__.py index e69de29bb..c01a6948d 100644 --- a/core/src/trezor/wire/thp/__init__.py +++ b/core/src/trezor/wire/thp/__init__.py @@ -0,0 +1,18 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from enum import IntEnum +else: + IntEnum = object + + +class ChannelState(IntEnum): + UNALLOCATED = 0 + TH1 = 1 + TH2 = 2 + TP1 = 3 + TP2 = 4 + TP3 = 5 + TP4 = 6 + TP5 = 7 + ENCRYPTED_TRANSPORT = 8 diff --git a/core/src/trezor/wire/thp/channel_context.py b/core/src/trezor/wire/thp/channel_context.py index 003798222..eb81b510c 100644 --- a/core/src/trezor/wire/thp/channel_context.py +++ b/core/src/trezor/wire/thp/channel_context.py @@ -93,9 +93,7 @@ class ChannelContext(Context): passphrase="", ) -> None: # TODO change it to output session data pass - # TODO check, wheter a session with this passphrase already exists - # if not, create a new session with this passphrase - # if yes, what TODO TODO ??? + # create a new session with this passphrase def _is_ctrl_byte_continuation(ctrl_byte: int) -> bool: diff --git a/core/src/trezor/wire/thp/packet_handlers.py b/core/src/trezor/wire/thp/packet_handlers.py new file mode 100644 index 000000000..0caffb0cb --- /dev/null +++ b/core/src/trezor/wire/thp/packet_handlers.py @@ -0,0 +1,13 @@ +from .channel_context import ChannelContext +from . import ChannelState + + +def getPacketHandler( + channel: ChannelContext, packet: bytes +): # TODO is the packet bytes or BufferType? + if channel.get_management_session_state is ChannelState.TH1: # TODO is correct + return handler_TH_1 + + +def handler_TH_1(packet): + pass