1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

chore(core): remove management session code from handle_ThpCreateNewSession

[no changelog]
This commit is contained in:
M1nd3r 2024-12-19 16:09:50 +01:00
parent e2e811e072
commit 5a65b5b1f3

View File

@ -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: