void fsm_msgChangePin(ChangePin *msg) { bool removal = msg->has_remove && msg->remove; bool confirmed = false; if(removal) { if(storage_has_pin()) { confirmed = confirm(ButtonRequestType_ButtonRequest_RemovePin, "Remove PIN", "Do you want to remove PIN protection?"); } else { fsm_sendSuccess("PIN removed"); return; } } else { if(storage_has_pin()) confirmed = confirm(ButtonRequestType_ButtonRequest_ChangePin, "Change PIN", "Do you want to change your PIN?"); else confirmed = confirm(ButtonRequestType_ButtonRequest_CreatePin, "Create PIN", "Do you want to add PIN protection?"); } if(!confirmed) { fsm_sendFailure(FailureType_Failure_ActionCancelled, removal ? "PIN removal cancelled" : "PIN change cancelled"); go_home(); return; } if(!pin_protect("Enter Current PIN")) { go_home(); return; } if(removal) { storage_set_pin(0); storage_commit(); fsm_sendSuccess("PIN removed"); } else { if(change_pin()) { storage_commit(); fsm_sendSuccess("PIN changed"); } } go_home(); }
/* * storage_load_device() - Load configuration data from usb message to shadow memory * * INPUT * - msg: load device message * OUTPUT * none */ void storage_load_device(LoadDevice *msg) { storage_reset(); shadow_config.storage.has_imported = true; shadow_config.storage.imported = true; if(msg->has_pin > 0) { storage_set_pin(msg->pin); } if(msg->has_passphrase_protection) { shadow_config.storage.has_passphrase_protection = true; shadow_config.storage.passphrase_protection = msg->passphrase_protection; } else { shadow_config.storage.has_passphrase_protection = false; } if(msg->has_node) { shadow_config.storage.has_node = true; shadow_config.storage.has_mnemonic = false; memcpy(&shadow_config.storage.node, &(msg->node), sizeof(HDNodeType)); sessionRootNodeCached = false; memset(&sessionRootNode, 0, sizeof(sessionRootNode)); } else if(msg->has_mnemonic) { shadow_config.storage.has_mnemonic = true; shadow_config.storage.has_node = false; strlcpy(shadow_config.storage.mnemonic, msg->mnemonic, sizeof(shadow_config.storage.mnemonic)); sessionRootNodeCached = false; memset(&sessionRootNode, 0, sizeof(sessionRootNode)); } if(msg->has_language) { storage_set_language(msg->language); } if(msg->has_label) { storage_set_label(msg->label); } }