From 8208a86c085f0013e8f1225562250afda266e54d Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 4 Dec 2022 18:12:30 +0800 Subject: [PATCH] add the UX front-end for backup key burning - instructions for BBRAM flow (refers to wiki) - consent for efuse flow - fix a blocking issue on backup prep (minor problem, just gives users more time to contemplate without a panic) --- services/status/Cargo.toml | 1 + services/status/locales/i18n.json | 42 +++++++++++++ services/status/src/main.rs | 97 ++++++++++++++++++++++++++----- services/status/src/mainmenu.rs | 11 ++++ 4 files changed, 135 insertions(+), 16 deletions(-) diff --git a/services/status/Cargo.toml b/services/status/Cargo.toml index 9b97d87f7..29fb6c6ef 100644 --- a/services/status/Cargo.toml +++ b/services/status/Cargo.toml @@ -60,4 +60,5 @@ tts = [] dbg-ecupdate = [] ditherpunk = [] test-rekey = [] +efuse = [] default = [] diff --git a/services/status/locales/i18n.json b/services/status/locales/i18n.json index a3fed5382..f4f14b022 100644 --- a/services/status/locales/i18n.json +++ b/services/status/locales/i18n.json @@ -13,6 +13,41 @@ "ja": "PDDB とルート キーのバックアップの準備をしますか?\n\nプロセスは、いったん開始すると中止できません。", "zh": "准备 PDDB 和根密钥备份吗?\n\n进程一旦启动就不能中止。" }, + "burnkey.type": { + "en": "Please select the type of key to use.\n\nUnsure which one to use? See github.com/betrusted-io/faq", + "en-tt": "Please select the type of key to use.\n\nUnsure which one to use? See github.com/betrusted-io/faq", + "fr": "Veuillez sélectionner le type de clé à utiliser.\n\nVous ne savez pas lequel utiliser ? Voir github.com/betrusted-io/faq *MT*", + "ja": "使用する鍵の種類を選択してください。\n\nどちらを使用するかわからない場合 github.com/betrusted-io/faq を参照してください", + "zh": "请选择要使用的密钥类型。 不确定使用哪一个?\n\n请参阅 github.com/betrusted-io/faq" + }, + "burnkey.efuse_confirm": { + "en": "This will permanently burn a backup key into your device. If you lose this key and brick the device, you will have to buy a new device.\n\nTHIS FLOW IS BETA. BY PROCEEDING YOU ACKNOWLEDGE THE RISK OF PERMANENT DAMAGE TO YOUR DEVICE WITH NO WARRANTY REPAIR OPTION.\n\nNOTE: You may also set a backup key using the BBRAM flow, with no risk of permanent damage to hardware.\n\nProceed?", + "en-tts": "This will permanently burn a backup key into your device.\nIf you lose the key and brick the device, you will have to buy a new device.\nTHIS FLOW IS BETA. BY PROCEEDING YOU ACKNOWLEDGE THE RISK OF PERMANENT DAMAGE TO YOUR DEVICE WITH NO WARRANTY REPAIR OPTION.\nProceed?", + "fr": "Cela gravera définitivement une clé de sauvegarde dans votre appareil.\nSi vous perdez la clé et briquez l'appareil, vous devrez acheter un nouvel appareil.\nCE FLUX EST BÊTA. EN POURSUIVANT, VOUS RECONNAISSEZ LE RISQUE DE DOMMAGES PERMANENTS À VOTRE APPAREIL SANS OPTION DE RÉPARATION SOUS GARANTIE.\nPoursuivre?", + "ja": "これにより、バックアップ キーがデバイスに永久に焼き付けられます。\nキーを紛失してデバイスをブリックした場合は、新しいデバイスを購入する必要があります。\nこのフローはベータ版です。 続行することにより、保証修理オプションなしでデバイスに恒久的な損傷が生じるリスクを認めたことになります。\n続行しますか?", + "zh": "这会将备份密钥永久地刻录到您的设备中。\n如果您丢失密钥并使设备变砖,您将不得不购买新设备。\n此流程是测试版。 继续,即表示您承认您的设备存在永久损坏的风险,且不提供保修维修选项。\n继续吗?" + }, + "burnkey.bbram": { + "en" : "BBRAM", + "en-tts": "BBRAM", + "fr" : "BBRAM", + "ja" : "BBRAM", + "zh" : "BBRAM" + }, + "burnkey.efuse": { + "en" : "eFuse", + "en-tts": "eFuse", + "fr" : "eFuse", + "ja" : "eFuse", + "zh" : "eFuse" + }, + "burnkey.bbram_exec": { + "en" : "Close this dialog box, then follow the instructions at https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM)", + "en-tts" : "Close this dialog box, then follow the instructions at https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM)", + "fr" : "Fermez cette boîte de dialogue, puis suivez les instructions sur https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM) *MT*", + "ja" : "このダイアログ ボックスを閉じて、https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM) の指示に従います。", + "zh" : "关闭此对话框,然后按照 https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM) 中的说明进行操作" + }, "ecup.abort": { "en": "EC update aborted due to error!", "en-tts": "EC update aborted due to error!", @@ -97,6 +132,13 @@ "ja": "バックライト点灯", "zh": "背光开启" }, + "mainmenu.backup_key": { + "en": "Burn backup key (BETA)", + "en-tts": "Burn backup key (BETA)", + "fr": "Graver la clé de sauvegarde (BETA) *MT*", + "ja": "バックアップ キーの書き込み (ベータ版)", + "zh": "刻录备份密钥(测试版)" + }, "mainmenu.battery_disconnect": { "en": "Shutdown", "en-tts": "Shutdown", diff --git a/services/status/src/main.rs b/services/status/src/main.rs index 94f41cd45..ec156cd6f 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -66,8 +66,13 @@ pub(crate) enum StatusOpcode { /// Prepare for a backup PrepareBackup, + PrepareBackupConfirmed, PrepareBackupPhase2, + /// Burn a backup key + #[cfg(feature="efuse")] + BurnBackupKey, + /// Tells keyboard watching thread that a new keypress happened. Keypress, /// Turns backlight off. @@ -747,7 +752,7 @@ fn wrapped_main() -> ! { loop { let msg = xous::receive_message(status_sid).unwrap(); let opcode: Option = FromPrimitive::from_usize(msg.body.id()); - log::debug!("{:?}", opcode); + log::info!("{:?}", opcode); match opcode { Some(StatusOpcode::EnableAutomaticBacklight) => { if *autobacklight_enabled.lock().unwrap() { @@ -1082,6 +1087,12 @@ fn wrapped_main() -> ! { } }, Some(StatusOpcode::BatteryDisconnect) => { // this is described as "Shutdown" on the menu + // NOTE: this implementation takes a "shortcut" and blocks, which causes the + // status thread to block while the dialog boxes are up. This can eventually lead + // to deadlock in the system, but we assume that the user will acknowledge these + // dialog boxes fairly quickly. If this turns out not to be the case, we can + // turn the interactive dialog box into a thread that fires a message to move + // to the next stage (see `PrepareBackup` implementation for a template). if ((llio.adc_vbus().unwrap() as u32) * 503) > 150_000 { modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG), None).expect("couldn't notify that power is plugged in"); } else { @@ -1166,22 +1177,77 @@ fn wrapped_main() -> ! { *run_lock = false; com.set_backlight(0, 0).expect("cannot set backlight off"); }, - Some(StatusOpcode::PrepareBackup) => { - log::info!("{}BACKUP.CONFIRM,{}", xous::BOOKEND_START, xous::BOOKEND_END); - modals.add_list_item(t!("rootkeys.gwup.yes", xous::LANG)).expect("couldn't build radio item list"); - modals.add_list_item(t!("rootkeys.gwup.no", xous::LANG)).expect("couldn't build radio item list"); - match modals.get_radiobutton(t!("backup.confirm", xous::LANG)) { - Ok(response) => { - if response.as_str() == t!("rootkeys.gwup.yes", xous::LANG) { - {} - } else { - // abort the flow now by returning to the main dispatch handler - continue; + #[cfg(feature="efuse")] + Some(StatusOpcode::BurnBackupKey) => { + log::info!("{}BURNKEY.TYPE,{}", xous::BOOKEND_START, xous::BOOKEND_END); + thread::spawn({ + let keys = keys.clone(); + move || { + let xns = xous_names::XousNames::new().unwrap(); + let modals = modals::Modals::new(&xns).unwrap(); + modals.add_list_item(t!("burnkey.bbram", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("burnkey.efuse", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("wlan.cancel", xous::LANG)).expect("couldn't build radio item list"); + match modals.get_radiobutton(t!("burnkey.type", xous::LANG)) { + Ok(response) => { + if response.as_str() == t!("burnkey.bbram", xous::LANG) { + // do BBRAM flow + log::info!("{}BBRAM.CONFIRM,{}", xous::BOOKEND_START, xous::BOOKEND_END); + // punts to a script-driven flow on the pi + modals.show_notification( + t!("burnkey.bbram_exec", xous::LANG), + Some("https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM)"), + ).ok(); + } else if response.as_str() == t!("burnkey.efuse", xous::LANG) { + log::info!("{}EFUSE.CONFIRM,{}", xous::BOOKEND_START, xous::BOOKEND_END); + // do eFuse flow + modals.add_list_item(t!("rootkeys.gwup.yes", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("rootkeys.gwup.no", xous::LANG)).expect("couldn't build radio item list"); + match modals.get_radiobutton(t!("burnkey.efuse_confirm", xous::LANG)) { + Ok(response) => { + if response.as_str() == t!("rootkeys.gwup.yes", xous::LANG) { + // do the efuse burn + keys.lock().unwrap().do_efuse_burn(); + } else { + // abort the flow by doing nothing + } + } + _ => (), + } + } else { + // abort flow by doing nothing + } + } + _ => (), } } - _ => (), - } - + }); + } + Some(StatusOpcode::PrepareBackup) => { + // don't block while prompting for backup confirmation + thread::spawn({ + move || { + let xns = xous_names::XousNames::new().unwrap(); + let modals = modals::Modals::new(&xns).unwrap(); + modals.add_list_item(t!("rootkeys.gwup.yes", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("rootkeys.gwup.no", xous::LANG)).expect("couldn't build radio item list"); + log::info!("{}BACKUP.CONFIRM,{}", xous::BOOKEND_START, xous::BOOKEND_END); + match modals.get_radiobutton(t!("backup.confirm", xous::LANG)) { + Ok(response) => { + if response.as_str() == t!("rootkeys.gwup.yes", xous::LANG) { + send_message(cb_cid, + Message::new_scalar(StatusOpcode::PrepareBackupConfirmed.to_usize().unwrap(), 0, 0, 0, 0) + ).expect("couldn't initiate backup"); + } else { + // abort by just falling through + } + } + _ => (), + } + } + }); + }, + Some(StatusOpcode::PrepareBackupConfirmed) => { // disconnect from the network, so that incoming network packets don't trigger any processes that // could write to the PDDB. netmgr.connection_manager_wifi_off_and_stop().ok(); @@ -1202,7 +1268,6 @@ fn wrapped_main() -> ! { // sync the PDDB to disk prior to making backups let pddb = pddb::Pddb::new(); if !pddb.try_unmount() { - // this is a rare case path...not worth turning the modals object into a mutex-wrapped thing just for this let xns = xous_names::XousNames::new().unwrap(); let modals = modals::Modals::new(&xns).unwrap(); modals.show_notification(t!("socup.unmount_fail", xous::LANG), None).ok(); diff --git a/services/status/src/mainmenu.rs b/services/status/src/mainmenu.rs index 23726e93b..46ae6dd1b 100644 --- a/services/status/src/mainmenu.rs +++ b/services/status/src/mainmenu.rs @@ -101,6 +101,17 @@ pub fn create_main_menu(keys: Arc>, menu_management_sid: xous::S close_on_select: true, }); + #[cfg(feature="efuse")] + if keys.lock().unwrap().is_zero_key().unwrap() == Some(true) { + menuitems.push(MenuItem { + name: String::from_str(t!("mainmenu.backup_key", xous::LANG)), + action_conn: Some(status_conn), + action_opcode: StatusOpcode::BurnBackupKey.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }); + } + if key_init { menuitems.push(MenuItem { name: String::from_str(t!("mainmenu.prep_backup", xous::LANG)),