From 58621711d1e8ef3cf901e00ad9cc2f584ffb037a Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 25 Aug 2020 16:04:36 +0200 Subject: [PATCH] legacy: implement EndSession --- legacy/firmware/config.c | 18 ++++++++++++------ legacy/firmware/config.h | 1 + legacy/firmware/fsm_msg_common.h | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/legacy/firmware/config.c b/legacy/firmware/config.c index a15ad1cf63..90443a39df 100644 --- a/legacy/firmware/config.c +++ b/legacy/firmware/config.c @@ -582,9 +582,13 @@ static void get_root_node_callback(uint32_t iter, uint32_t total) { } const uint8_t *config_getSeed(void) { + if (activeSessionCache == NULL) { + fsm_sendFailure(FailureType_Failure_ProcessError, "Invalid session"); + return NULL; + } + // root node is properly cached - if ((activeSessionCache != NULL) && - (activeSessionCache->seedCached == sectrue)) { + if (activeSessionCache->seedCached == sectrue) { return activeSessionCache->seed; } @@ -608,10 +612,6 @@ const uint8_t *config_getSeed(void) { } } char oldTiny = usbTiny(1); - if (activeSessionCache == NULL) { - // this should not happen if the Host behaves and sends Initialize first - session_startSession(NULL); - } mnemonic_to_seed(mnemonic, passphrase, activeSessionCache->seed, get_root_node_callback); // BIP-0039 memzero(mnemonic, sizeof(mnemonic)); @@ -858,6 +858,12 @@ uint8_t *session_startSession(const uint8_t *received_session_id) { return activeSessionCache->id; } +void session_endCurrentSession(void) { + if (activeSessionCache == NULL) return; + session_clearCache(activeSessionCache); + activeSessionCache = NULL; +} + bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); } bool config_isInitialized(void) { diff --git a/legacy/firmware/config.h b/legacy/firmware/config.h index cbb50bfe0b..b7146fe51a 100644 --- a/legacy/firmware/config.h +++ b/legacy/firmware/config.h @@ -90,6 +90,7 @@ extern Storage configUpdate; void config_init(void); void session_clear(bool lock); +void session_endCurrentSession(void); void config_lockDevice(void); void config_loadDevice(const LoadDevice *msg); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index bdc498b094..3959feff02 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -354,8 +354,8 @@ void fsm_msgLockDevice(const LockDevice *msg) { void fsm_msgEndSession(const EndSession *msg) { (void)msg; - // TODO - fsm_sendFailure(FailureType_Failure_FirmwareError, "Not implemented"); + session_endCurrentSession(); + fsm_sendSuccess(_("Session ended")); } void fsm_msgApplySettings(const ApplySettings *msg) {