diff --git a/firmware/config.c b/firmware/config.c index 344910497d..32186d0b85 100644 --- a/firmware/config.c +++ b/firmware/config.c @@ -165,12 +165,6 @@ static secbool config_get_bool(uint16_t key, bool *value) } } -static secbool config_has_key(uint16_t key) -{ - uint16_t len = 0; - return storage_get(key, NULL, 0, &len); -} - static secbool config_get_string(uint16_t key, char *dest, uint16_t dest_size) { uint16_t len = 0; @@ -410,17 +404,19 @@ static void config_setNode(const HDNodeType *node) { if (sectrue == storage_set(KEY_NODE, &storageHDNode, sizeof(storageHDNode))) { config_set_bool(KEY_INITIALIZED, true); } + memzero(&storageHDNode, sizeof(storageHDNode)); } #if DEBUG_LINK -void config_dumpNode(HDNodeType *node) +bool config_dumpNode(HDNodeType *node) { memzero(node, sizeof(HDNodeType)); StorageHDNode storageNode; uint16_t len = 0; if (sectrue != storage_get(KEY_NODE, &storageNode, sizeof(storageNode), &len) || len != sizeof(StorageHDNode)) { - return; + memzero(&storageNode, sizeof(storageNode)); + return false; } node->depth = storageNode.depth; @@ -437,6 +433,7 @@ void config_dumpNode(HDNodeType *node) } memzero(&storageNode, sizeof(storageNode)); + return true; } #endif @@ -649,11 +646,6 @@ bool config_setMnemonic(const char *mnemonic) return false; } - if (sectrue != config_set_bool(KEY_INITIALIZED, true)) { - storage_delete(KEY_MNEMONIC); - return false; - } - StorageHDNode u2fNode; memzero(&u2fNode, sizeof(u2fNode)); config_compute_u2froot(mnemonic, &u2fNode); @@ -662,22 +654,14 @@ bool config_setMnemonic(const char *mnemonic) if (sectrue != ret) { storage_delete(KEY_MNEMONIC); - storage_delete(KEY_INITIALIZED); return false; } + + config_set_bool(KEY_INITIALIZED, true); + return true; } -bool config_hasNode(void) -{ - return sectrue == config_has_key(KEY_NODE); -} - -bool config_hasMnemonic(void) -{ - return sectrue == config_has_key(KEY_MNEMONIC); -} - bool config_getMnemonic(char *dest, uint16_t dest_size) { return sectrue == config_get_string(KEY_MNEMONIC, dest, dest_size); diff --git a/firmware/config.h b/firmware/config.h index df7bd58f55..9fd8cd089e 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -113,12 +113,10 @@ bool session_getState(const uint8_t *salt, uint8_t *state, const char *passphras bool config_setMnemonic(const char *mnemonic); bool config_containsMnemonic(const char *mnemonic); -bool config_hasMnemonic(void); bool config_getMnemonic(char *dest, uint16_t dest_size); -bool config_hasNode(void); #if DEBUG_LINK -void config_dumpNode(HDNodeType *node); +bool config_dumpNode(HDNodeType *node); #endif bool config_containsPin(const char *pin); diff --git a/firmware/fsm_msg_debug.h b/firmware/fsm_msg_debug.h index 0ef38279f6..0ed3bd1bce 100644 --- a/firmware/fsm_msg_debug.h +++ b/firmware/fsm_msg_debug.h @@ -52,12 +52,9 @@ void fsm_msgDebugLinkGetState(const DebugLinkGetState *msg) resp.has_recovery_word_pos = true; resp.recovery_word_pos = recovery_get_word_pos(); - resp.has_mnemonic = config_getMnemonic(resp.mnemonic, sizeof(resp.mnemonic)); + resp.has_mnemonic = config_getMnemonic(resp.mnemonic, sizeof(resp.mnemonic)); - if (config_hasNode()) { - resp.has_node = true; - config_dumpNode(&(resp.node)); - } + resp.has_node = config_dumpNode(&(resp.node)); resp.has_passphrase_protection = config_getPassphraseProtection(&(resp.passphrase_protection));