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)"); layoutHome(); return; } word_count = _word_count; enforce_wordlist = _enforce_wordlist; if (pin_protection && !protectChangePin()) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); layoutHome(); return; } storage.has_passphrase_protection = true; storage.passphrase_protection = passphrase_protection; storage_setLanguage(language); storage_setLabel(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 fsm_msgApplySettings(ApplySettings *msg) { if (msg->has_label && msg->has_language) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "and language to", msg->language, "?"); } else if (msg->has_label) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); } else if (msg->has_language) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); } else { fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided"); return; } if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); return; } if (!protectPin(true)) { layoutHome(); return; } if (msg->has_label) { storage_setLabel(msg->label); } if (msg->has_language) { storage_setLanguage(msg->language); } storage_commit(); fsm_sendSuccess("Settings applied"); layoutHome(); }
void fsm_msgApplySettings(ApplySettings *msg) { if (msg->has_label) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); return; } } if (msg->has_language) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); return; } } if (msg->has_use_passphrase) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", msg->use_passphrase ? "enable passphrase" : "disable passphrase", "encryption?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); return; } } if (msg->has_homescreen) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change the home", "screen ?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); return; } } if (!msg->has_label && !msg->has_language && !msg->has_use_passphrase && !msg->has_homescreen) { fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided"); return; } if (!protectPin(true)) { layoutHome(); return; } if (msg->has_label) { storage_setLabel(msg->label); } if (msg->has_language) { storage_setLanguage(msg->language); } if (msg->has_use_passphrase) { storage_setPassphraseProtection(msg->use_passphrase); } if (msg->has_homescreen) { storage_setHomescreen(msg->homescreen.bytes, msg->homescreen.size); } storage_commit(); fsm_sendSuccess("Settings applied"); layoutHome(); }
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)"); layoutHome(); 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) { layoutDialogSwipe(DIALOG_ICON_INFO, "Cancel", "Continue", NULL, "Internal entropy:", ent_str[0], ent_str[1], ent_str[2], ent_str[3], NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ResetDevice, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled"); layoutHome(); return; } } if (pin_protection && !protectChangePin()) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); layoutHome(); return; } storage.has_passphrase_protection = true; storage.passphrase_protection = passphrase_protection; storage_setLanguage(language); storage_setLabel(label); EntropyRequest resp; memset(&resp, 0, sizeof(EntropyRequest)); msg_write(MessageType_MessageType_EntropyRequest, &resp); awaiting_entropy = true; }
void storage_loadDevice(LoadDevice *msg) { storage_reset(); storage.has_imported = true; storage.imported = true; if (msg->has_pin > 0) { storage_setPin(msg->pin); } if (msg->has_passphrase_protection) { storage.has_passphrase_protection = true; storage.passphrase_protection = msg->passphrase_protection; } else { storage.has_passphrase_protection = false; } if (msg->has_node) { storage.has_node = true; storage.has_mnemonic = false; memcpy(&storage.node, &(msg->node), sizeof(HDNodeType)); sessionRootNodeCached = false; memset(&sessionRootNode, 0, sizeof(sessionRootNode)); } else if (msg->has_mnemonic) { storage.has_mnemonic = true; storage.has_node = false; strlcpy(storage.mnemonic, msg->mnemonic, sizeof(storage.mnemonic)); sessionRootNodeCached = false; memset(&sessionRootNode, 0, sizeof(sessionRootNode)); } if (msg->has_language) { storage_setLanguage(msg->language); } if (msg->has_label) { storage_setLabel(msg->label); } }