void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_protection, const char *language, const char *label, bool _enforce_wordlist) { if (_word_count != 12 && _word_count != 18 && _word_count != 24) { fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid word count (has to be 12, 18 or 24 bits)"); go_home(); return; } word_count = _word_count; enforce_wordlist = _enforce_wordlist; if (pin_protection && !change_pin()) { go_home(); return; } storage_set_passphrase_protected(passphrase_protection); storage_set_language(language); storage_set_label(label); uint32_t i; for (i = 0; i < word_count; i++) { word_order[i] = i + 1; } for (i = word_count; i < 24; i++) { word_order[i] = 0; } random_permute(word_order, 24); awaiting_word = true; word_index = 0; next_word(); }
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label) { if(_strength != 128 && _strength != 192 && _strength != 256) { fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid strength (has to be 128, 192 or 256 bits)"); go_home(); return; } strength = _strength; random_buffer(int_entropy, 32); char ent_str[4][17]; data2hex(int_entropy , 8, ent_str[0]); data2hex(int_entropy + 8, 8, ent_str[1]); data2hex(int_entropy + 16, 8, ent_str[2]); data2hex(int_entropy + 24, 8, ent_str[3]); if(display_random) { if(!confirm(ButtonRequestType_ButtonRequest_ResetDevice, "Internal Entropy", "%s %s %s %s", ent_str[0], ent_str[1], ent_str[2], ent_str[3])) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled"); go_home(); return; } } if(pin_protection && !change_pin()) { go_home(); return; } storage_set_passphrase_protected(passphrase_protection); storage_set_language(language); storage_set_label(label); EntropyRequest resp; memset(&resp, 0, sizeof(EntropyRequest)); msg_write(MessageType_MessageType_EntropyRequest, &resp); awaiting_entropy = true; }
void fsm_msgApplySettings(ApplySettings *msg) { if(msg->has_label) { if(!confirm(ButtonRequestType_ButtonRequest_ChangeLabel, "Change Label", "Do you want to change the label to \"%s\"?", msg->label)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); go_home(); return; } } if(msg->has_language) { if(!confirm(ButtonRequestType_ButtonRequest_ChangeLanguage, "Change Language", "Do you want to change the language to %s?", msg->language)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); go_home(); return; } } if(msg->has_use_passphrase) { if(msg->use_passphrase) { if(!confirm(ButtonRequestType_ButtonRequest_EnablePassphrase, "Enable Passphrase", "Do you want to enable passphrase encryption?", msg->language)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); go_home(); return; } } else { if(!confirm(ButtonRequestType_ButtonRequest_DisablePassphrase, "Disable Passphrase", "Do you want to disable passphrase encryption?", msg->language)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); go_home(); return; } } } if(!msg->has_label && !msg->has_language && !msg->has_use_passphrase) { fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided"); return; } if(!pin_protect_cached()) { go_home(); return; } if(msg->has_label) { storage_set_label(msg->label); } if(msg->has_language) { storage_set_language(msg->language); } if(msg->has_use_passphrase) { storage_set_passphrase_protected(msg->use_passphrase); } storage_commit(); fsm_sendSuccess("Settings applied"); go_home(); }