From 41966c60dbb460ae454bc3fe9fb5cf5e65a7a6fe Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Tue, 28 Apr 2020 07:23:51 +0000 Subject: [PATCH] legacy: initialized field in Features is true only if mnemonic is stored --- legacy/firmware/config.c | 2 ++ legacy/firmware/config.h | 1 + legacy/firmware/fsm_msg_common.h | 3 ++- storage/storage.c | 5 +++++ storage/storage.h | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/legacy/firmware/config.c b/legacy/firmware/config.c index 2691bd033..a7eac1932 100644 --- a/legacy/firmware/config.c +++ b/legacy/firmware/config.c @@ -714,6 +714,8 @@ bool config_getMnemonic(char *dest, uint16_t dest_size) { return sectrue == config_get_string(KEY_MNEMONIC, dest, dest_size); } +bool config_hasMnemonic(void) { return sectrue == storage_has(KEY_MNEMONIC); } + /* Check whether mnemonic matches storage. The mnemonic must be * a null-terminated string. */ diff --git a/legacy/firmware/config.h b/legacy/firmware/config.h index 6f190db89..ff6daa6da 100644 --- a/legacy/firmware/config.h +++ b/legacy/firmware/config.h @@ -113,6 +113,7 @@ uint8_t *session_startSession(const uint8_t *received_session_id); 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_getMnemonicBytes(uint8_t *dest, uint16_t dest_size, uint16_t *real_size); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 32b959417..3a5facad3 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -46,7 +46,8 @@ bool get_features(Features *resp) { config_getLanguage(resp->language, sizeof(resp->language)); resp->has_label = config_getLabel(resp->label, sizeof(resp->label)); resp->has_initialized = true; - resp->initialized = config_isInitialized(); + // imported xprv is not supported anymore so we require mnemonic + resp->initialized = config_isInitialized() && config_hasMnemonic(); resp->has_imported = config_getImported(&(resp->imported)); resp->has_pin_cached = true; resp->pin_cached = session_isUnlocked() && config_hasPin(); diff --git a/storage/storage.c b/storage/storage.c index 4ee652dab..87815d8ec 100644 --- a/storage/storage.c +++ b/storage/storage.c @@ -1104,6 +1104,11 @@ static secbool storage_get_encrypted(const uint16_t key, void *val_dest, return sectrue; } +secbool storage_has(const uint16_t key) { + uint16_t len = 0; + return storage_get(key, NULL, 0, &len); +} + /* * Finds the data stored under key and writes its length to len. If val_dest is * not NULL and max_len >= len, then the data is copied to val_dest. diff --git a/storage/storage.h b/storage/storage.h index 9a99042eb..113b5fd70 100644 --- a/storage/storage.h +++ b/storage/storage.h @@ -56,6 +56,7 @@ void storage_ensure_not_wipe_code(uint32_t pin); secbool storage_has_wipe_code(void); secbool storage_change_wipe_code(uint32_t pin, const uint8_t *ext_salt, uint32_t wipe_code); +secbool storage_has(const uint16_t key); secbool storage_get(const uint16_t key, void *val, const uint16_t max_len, uint16_t *len); secbool storage_set(const uint16_t key, const void *val, const uint16_t len);