Skip to content

Commit

Permalink
fix(legacy): fix cardano derive when session is reused (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxyx authored May 11, 2023
1 parent 56a4a86 commit d9cabcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 8 additions & 1 deletion legacy/firmware/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,13 @@ bool config_getTrezorCompMode(bool *trezor_comp_mode) {
return sectrue == config_get_bool(KEY_TREZOR_COMP_MODE, trezor_comp_mode);
}

bool config_getDeriveCardano(void) { return derive_cardano; }
bool config_getDeriveCardano(void) {
if ((activeSessionCache->cardanoSecretCached != sectrue) &&
(activeSessionCache->seedCached == sectrue)) {
return false; // only BIP-0039
}

return true;
}

void config_setDeriveCardano(bool on) { derive_cardano = on; }
18 changes: 13 additions & 5 deletions legacy/firmware/fsm_msg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ bool get_features(Features *resp) {

void fsm_msgInitialize(const Initialize *msg) {
fsm_abortWorkflows();
if (msg && msg->has_derive_cardano && msg->derive_cardano) {
config_setDeriveCardano(true);
} else {
config_setDeriveCardano(false);
}

uint8_t *session_id;
if (msg && msg->has_session_id) {
Expand All @@ -222,6 +217,19 @@ void fsm_msgInitialize(const Initialize *msg) {
session_id = session_startSession(NULL);
}

if (msg && msg->has_derive_cardano && msg->derive_cardano) {
if (!config_getDeriveCardano()) {
// seed is already derived, and host wants to change derive_cardano
// setting
// => create a new session
session_endCurrentSession();
session_id = session_startSession(NULL);
}
config_setDeriveCardano(true);
} else {
config_setDeriveCardano(false);
}

RESP_INIT(Features);
get_features(resp);

Expand Down

0 comments on commit d9cabcb

Please sign in to comment.