From 5a65b5b1f350ada5d05486c4d5db46a3b9045a01 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Thu, 19 Dec 2024 16:09:50 +0100 Subject: [PATCH] chore(core): remove management session code from handle_ThpCreateNewSession [no changelog] --- core/src/apps/base.py | 67 ++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/core/src/apps/base.py b/core/src/apps/base.py index cb06d5a5ad..29caf1aedf 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -225,10 +225,7 @@ if utils.USE_THP: from trezor.wire.context import get_context from trezor.wire.errors import ActionCancelled, DataError from trezor.wire.thp.session_context import GenericSessionContext - from trezor.wire.thp.session_manager import ( - get_new_management_session_ctx, - get_new_session_context, - ) + from trezor.wire.thp.session_manager import get_new_session_context from apps.common.seed import derive_and_store_roots @@ -243,58 +240,38 @@ if utils.USE_THP: # Do not use `ctx` beyond this point, as it is techically # allowed to change in between await statements - is_management = ( - message.passphrase is None - and message.on_device is not True - and message.derive_cardano is not True - ) - if not 0 <= session_id <= 255: return Failure( code=FailureType.DataError, message="Invalid session_id for session creation.", ) - if is_management: - # TODO this block is completely useless and will be removed - or will result in session.clear - new_session = get_new_management_session_ctx( - channel_ctx=channel, session_id=session_id + new_session = get_new_session_context( + channel_ctx=channel, session_id=session_id + ) + try: + await unlock_device() + await derive_and_store_roots(new_session, message) + except DataError as e: + return Failure(code=FailureType.DataError, message=e.message) + except ActionCancelled as e: + return Failure(code=FailureType.ActionCancelled, message=e.message) + except NotInitialized as e: + return Failure(code=FailureType.NotInitialized, message=e.message) + # TODO handle other errors (`Exception` when "Cardano icarus secret is already set!") + + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: + log.debug( + __name__, + "New session with sid %d and passphrase %s created.", + session_id, + message.passphrase if message.passphrase is not None else "", ) - succ_message = "New management session created." - - if __debug__ and utils.ALLOW_DEBUG_MESSAGES: - log.debug( - __name__, "New management session with sid %d created.", session_id - ) - else: - new_session = get_new_session_context( - channel_ctx=channel, session_id=session_id - ) - try: - await unlock_device() - await derive_and_store_roots(new_session, message) - except DataError as e: - return Failure(code=FailureType.DataError, message=e.message) - except ActionCancelled as e: - return Failure(code=FailureType.ActionCancelled, message=e.message) - except NotInitialized as e: - return Failure(code=FailureType.NotInitialized, message=e.message) - # TODO handle other errors (`Exception` when "Cardano icarus secret is already set!") - - succ_message = "New session created." - - if __debug__ and utils.ALLOW_DEBUG_MESSAGES: - log.debug( - __name__, - "New session with sid %d and passphrase %s created.", - session_id, - message.passphrase if message.passphrase is not None else "", - ) channel.sessions[new_session.session_id] = new_session loop.schedule(new_session.handle()) - return Success(message=succ_message) + return Success(message="New session created.") else: