mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
reset: make backup workflow independent of initialization
This commit is contained in:
parent
91a1b6c4bc
commit
9298e4d9e3
@ -442,10 +442,19 @@ void fsm_msgResetDevice(ResetDevice *msg)
|
||||
msg->has_pin_protection && msg->pin_protection,
|
||||
msg->has_language ? msg->language : 0,
|
||||
msg->has_label ? msg->label : 0,
|
||||
msg->has_u2f_counter ? msg->u2f_counter : 0
|
||||
msg->has_u2f_counter ? msg->u2f_counter : 0,
|
||||
msg->has_skip_backup ? msg->skip_backup : false
|
||||
);
|
||||
}
|
||||
|
||||
void fsm_msgBackupDevice(BackupDevice *msg)
|
||||
{
|
||||
CHECK_INITIALIZED
|
||||
|
||||
(void)msg;
|
||||
reset_backup();
|
||||
}
|
||||
|
||||
void fsm_msgSignTx(SignTx *msg)
|
||||
{
|
||||
CHECK_INITIALIZED
|
||||
|
@ -36,6 +36,7 @@ void fsm_msgGetEntropy(GetEntropy *msg);
|
||||
void fsm_msgGetPublicKey(GetPublicKey *msg);
|
||||
void fsm_msgLoadDevice(LoadDevice *msg);
|
||||
void fsm_msgResetDevice(ResetDevice *msg);
|
||||
void fsm_msgBackupDevice(BackupDevice *msg);
|
||||
void fsm_msgSignTx(SignTx *msg);
|
||||
//void fsm_msgPinMatrixAck(PinMatrixAck *msg);
|
||||
void fsm_msgCancel(Cancel *msg);
|
||||
|
@ -22,6 +22,7 @@
|
||||
{ 'n', 'i', MessageType_MessageType_ApplySettings, ApplySettings_fields, (void (*)(void *)) fsm_msgApplySettings },
|
||||
// Message ButtonAck is used in tiny mode
|
||||
{ 'n', 'i', MessageType_MessageType_GetAddress, GetAddress_fields, (void (*)(void *)) fsm_msgGetAddress },
|
||||
{ 'n', 'i', MessageType_MessageType_BackupDevice, BackupDevice_fields, (void (*)(void *)) fsm_msgBackupDevice },
|
||||
{ 'n', 'i', MessageType_MessageType_EntropyAck, EntropyAck_fields, (void (*)(void *)) fsm_msgEntropyAck },
|
||||
{ 'n', 'i', MessageType_MessageType_SignMessage, SignMessage_fields, (void (*)(void *)) fsm_msgSignMessage },
|
||||
{ 'n', 'i', MessageType_MessageType_VerifyMessage, VerifyMessage_fields, (void (*)(void *)) fsm_msgVerifyMessage },
|
||||
|
@ -179,7 +179,7 @@ static void recovery_done(void) {
|
||||
_("The seed is"), _("INVALID!"), NULL, NULL, NULL, NULL);
|
||||
protectButton(ButtonRequestType_ButtonRequest_Other, true);
|
||||
}
|
||||
fsm_sendFailure(FailureType_Failure_DataError, _("Invalid mnemonic, are words in correct order?"));
|
||||
fsm_sendFailure(FailureType_Failure_DataError, _("Invalid seed, are words in correct order?"));
|
||||
}
|
||||
awaiting_word = 0;
|
||||
layoutHome();
|
||||
|
@ -33,12 +33,14 @@
|
||||
static uint32_t strength;
|
||||
static uint8_t int_entropy[32];
|
||||
static bool awaiting_entropy = false;
|
||||
static bool skip_backup = false;
|
||||
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter)
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter, bool _skip_backup)
|
||||
{
|
||||
if (_strength != 128 && _strength != 192 && _strength != 256) return;
|
||||
|
||||
strength = _strength;
|
||||
skip_backup = _skip_backup;
|
||||
|
||||
random_buffer(int_entropy, 32);
|
||||
|
||||
@ -75,8 +77,6 @@ void reset_init(bool display_random, uint32_t _strength, bool passphrase_protect
|
||||
awaiting_entropy = true;
|
||||
}
|
||||
|
||||
static char current_word[10], current_word_display[11];
|
||||
|
||||
void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
|
||||
{
|
||||
if (!awaiting_entropy) {
|
||||
@ -92,6 +92,33 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
|
||||
memset(int_entropy, 0, 32);
|
||||
awaiting_entropy = false;
|
||||
|
||||
storage.has_mnemonic = true;
|
||||
storage.has_needs_backup = true;
|
||||
storage.needs_backup = true;
|
||||
|
||||
if (skip_backup) {
|
||||
storage_commit();
|
||||
fsm_sendSuccess(_("Device successfully initialized"));
|
||||
layoutHome();
|
||||
} else {
|
||||
reset_backup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static char current_word[10], current_word_display[11];
|
||||
|
||||
void reset_backup(void)
|
||||
{
|
||||
if (!storage.has_needs_backup || !storage.needs_backup) {
|
||||
fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Seed already backed up"));
|
||||
return;
|
||||
} else {
|
||||
storage.has_needs_backup = false;
|
||||
storage.needs_backup = false;
|
||||
storage_commit();
|
||||
}
|
||||
|
||||
int pass, word_pos, i = 0, j;
|
||||
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
@ -146,10 +173,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
storage.has_mnemonic = true;
|
||||
storage_commit();
|
||||
fsm_sendSuccess(_("Device reset"));
|
||||
fsm_sendSuccess(_("Seed successfully backed up"));
|
||||
layoutHome();
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter);
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter, bool skip_backup);
|
||||
void reset_entropy(const uint8_t *ext_entropy, uint32_t len);
|
||||
void reset_backup(void);
|
||||
uint32_t reset_get_int_entropy(uint8_t *entropy);
|
||||
const char *reset_get_word(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user