bool protectChangePin(void) { const char *pin; char pin1[17], pin2[17]; pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, "Please enter new PIN:"); if (!pin) { return false; } strlcpy(pin1, pin, sizeof(pin1)); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, "Please re-enter new PIN:"); if (!pin) { return false; } strlcpy(pin2, pin, sizeof(pin2)); if (strcmp(pin1, pin2) == 0) { storage_setPin(pin1); return true; } else { return false; } }
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); } }
void fsm_msgChangePin(ChangePin *msg) { bool removal = msg->has_remove && msg->remove; if (removal) { if (storage_hasPin()) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "remove current PIN?", NULL, NULL, NULL, NULL); } else { fsm_sendSuccess("PIN removed"); return; } } else { if (storage_hasPin()) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change current PIN?", NULL, NULL, NULL, NULL); } else { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "set new PIN?", NULL, NULL, NULL, NULL); } } if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, removal ? "PIN removal cancelled" : "PIN change cancelled"); layoutHome(); return; } if (!protectPin(false)) { layoutHome(); return; } if (removal) { storage_setPin(0); fsm_sendSuccess("PIN removed"); } else { if (protectChangePin()) { fsm_sendSuccess("PIN changed"); } else { fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); } } layoutHome(); }