add an abort option to the initialization flow

This commit is contained in:
bunnie 2021-08-10 02:48:32 +08:00
parent 29f7cbe53b
commit 352b725f7a
5 changed files with 72 additions and 18 deletions

View file

@ -397,6 +397,7 @@ pub struct RadioButtons {
pub action_payload: RadioButtonPayload, // the current "radio button" selection pub action_payload: RadioButtonPayload, // the current "radio button" selection
pub select_index: i16, // the current candidate to be selected pub select_index: i16, // the current candidate to be selected
pub max_items: i16, pub max_items: i16,
pub is_password: bool,
} }
impl RadioButtons { impl RadioButtons {
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self { pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
@ -407,6 +408,7 @@ impl RadioButtons {
action_payload: RadioButtonPayload::new(""), action_payload: RadioButtonPayload::new(""),
select_index: 0, select_index: 0,
max_items: 0, max_items: 0,
is_password: false,
} }
} }
pub fn add_item(&mut self, new_item: ItemName) -> Option<ItemName> { pub fn add_item(&mut self, new_item: ItemName) -> Option<ItemName> {
@ -423,6 +425,9 @@ impl RadioButtons {
} }
return Some(new_item); return Some(new_item);
} }
fn is_password(&self) -> bool {
self.is_password
}
} }
impl ActionApi for RadioButtons { impl ActionApi for RadioButtons {
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op} fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
@ -432,9 +437,15 @@ impl ActionApi for RadioButtons {
for item in self.items.iter() { for item in self.items.iter() {
if item.is_some(){ total_items += 1} if item.is_some(){ total_items += 1}
} }
(total_items + 1) * glyph_height + margin * 2 + 5 // +4 for some bottom margin slop (total_items + 1) * glyph_height + margin * 2 + margin * 2 + 5 // +4 for some bottom margin slop
} }
fn redraw(&self, at_height: i16, modal: &Modal) { fn redraw(&self, at_height: i16, modal: &Modal) {
let color = if self.is_password {
PixelColor::Light
} else {
PixelColor::Dark
};
// prime a textview with the correct general style parameters // prime a textview with the correct general style parameters
let mut tv = TextView::new( let mut tv = TextView::new(
modal.canvas, modal.canvas,
@ -442,7 +453,7 @@ impl ActionApi for RadioButtons {
); );
tv.ellipsis = true; tv.ellipsis = true;
tv.style = modal.style; tv.style = modal.style;
tv.invert = false; tv.invert = self.is_password;
tv.draw_border= false; tv.draw_border= false;
tv.margin = Point::new(0, 0,); tv.margin = Point::new(0, 0,);
tv.insertion = None; tv.insertion = None;
@ -459,7 +470,7 @@ impl ActionApi for RadioButtons {
let mut do_okay = true; let mut do_okay = true;
for maybe_item in self.items.iter() { for maybe_item in self.items.iter() {
if let Some(item) = maybe_item { if let Some(item) = maybe_item {
let cur_y = at_height + cur_line * modal.line_height; let cur_y = at_height + cur_line * modal.line_height + modal.margin * 2;
if cur_line == self.select_index { if cur_line == self.select_index {
// draw the cursor // draw the cursor
tv.text.clear(); tv.text.clear();
@ -494,7 +505,7 @@ impl ActionApi for RadioButtons {
} }
} }
cur_line += 1; cur_line += 1;
let cur_y = at_height + cur_line * modal.line_height; let cur_y = at_height + cur_line * modal.line_height + modal.margin * 2;
if do_okay { if do_okay {
tv.text.clear(); tv.text.clear();
tv.bounds_computed = None; tv.bounds_computed = None;
@ -515,9 +526,9 @@ impl ActionApi for RadioButtons {
// divider lines // divider lines
modal.gam.draw_line(modal.canvas, Line::new_with_style( modal.gam.draw_line(modal.canvas, Line::new_with_style(
Point::new(modal.margin, at_height), Point::new(modal.margin, at_height + modal.margin),
Point::new(modal.canvas_width - modal.margin, at_height), Point::new(modal.canvas_width - modal.margin, at_height + modal.margin),
DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1)) DrawStyle::new(color, color, 1))
).expect("couldn't draw entry line"); ).expect("couldn't draw entry line");
} }
fn key_action(&mut self, k: char) -> (Option<xous_ipc::String::<512>>, bool) { fn key_action(&mut self, k: char) -> (Option<xous_ipc::String::<512>>, bool) {

View file

@ -15,10 +15,25 @@
"en-audio": "Root keys already initialized." "en-audio": "Root keys already initialized."
}, },
"rootkeys.setup": { "rootkeys.setup": {
"en": "This will init the root keys.\nI'm going to need two\npasswords:\n 1. Device unlock\n 2. Software update", "en": "This will init the root keys.\nI'm going to need two\npasswords:\n 1. Device unlock\n 2. Software update\nDo not lose them!",
"zh": "这将初始化根密钥\n需要两个密码\n1.解锁\n2.软件更新", "zh": "这将初始化根密钥\n需要两个密码\n1.解锁\n2.软件更新",
"en-audio": "This will initialize the root keys. We're going to need two passwords, one for device unlock, and one for software updates." "en-audio": "This will initialize the root keys. We're going to need two passwords, one for device unlock, and one for software updates."
}, },
"rootkeys.confirm": {
"en": "You should only proceed\nif you have inspected\nyour device and are ready\nto trust it.",
"zh": "仅当您准备好信\n任此设备时才\n应继续",
"en-audio": "You should only proceed with this operation if you are ready to trust this device."
},
"rootkeys.confirm.yes": {
"en": "I'm ready!",
"zh": "确定",
"en-audio": "I'm ready!"
},
"rootkeys.confirm.no": {
"en": "Not yet, maybe later.",
"zh": "我先检查一下,稍后再试",
"en-audio": "I'll try again after inspecting my device."
},
"rootkeys.setup_wait": { "rootkeys.setup_wait": {
"en": "Initializing keys.\nThis takes a few minutes.\nDo not reset or sleep!", "en": "Initializing keys.\nThis takes a few minutes.\nDo not reset or sleep!",
"zh": "现在正在初始化\n可能还要等一下\n不要重置或睡眠!\n", "zh": "现在正在初始化\n可能还要等一下\n不要重置或睡眠!\n",

View file

@ -16,6 +16,8 @@ pub(crate) enum Opcode {
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned. /// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
UxTryInitKeys, UxTryInitKeys,
UxConfirmInitKeys,
UxConfirmation,
UxInitRequestPassword, UxInitRequestPassword,
UxInitPasswordReturn, UxInitPasswordReturn,
UxGutter, // NOP for UX calls that require a destination UxGutter, // NOP for UX calls that require a destination

View file

@ -165,7 +165,7 @@ fn xmain() -> ! {
Some(t!("rootkeys.bootpass", xous::LANG)), Some(t!("rootkeys.bootpass", xous::LANG)),
None, None,
GlyphStyle::Small, GlyphStyle::Small,
4 8
); );
rootkeys_modal.spawn_helper(keys_sid, rootkeys_modal.sid, rootkeys_modal.spawn_helper(keys_sid, rootkeys_modal.sid,
Opcode::ModalRedraw.to_u32().unwrap(), Opcode::ModalRedraw.to_u32().unwrap(),
@ -218,22 +218,48 @@ fn xmain() -> ! {
None, true, None); None, true, None);
keys.set_ux_password_type(None); keys.set_ux_password_type(None);
} else { } else {
dismiss_modal_action.set_action_opcode(Opcode::UxInitRequestPassword.to_u32().unwrap()); dismiss_modal_action.set_action_opcode(Opcode::UxConfirmInitKeys.to_u32().unwrap());
rootkeys_modal.modify( rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)), Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.setup", xous::LANG)), false, Some(t!("rootkeys.setup", xous::LANG)), false,
None, true, None); None, true, None);
////// insert the "are you sure" message at this point in the flow -- don't call setup_key_init() until we're confirmed!
// setup_key_init() prepares the salt and other items necessary to receive a password safely
keys.setup_key_init();
// request the boot password first
keys.set_ux_password_type(Some(PasswordType::Boot));
} }
rootkeys_modal.activate(); rootkeys_modal.activate();
rootkeys_modal.redraw();
} }
}), }),
Some(Opcode::UxConfirmInitKeys) => {
let mut confirm_radiobox = gam::modal::RadioButtons::new(
main_cid,
Opcode::UxConfirmation.to_u32().unwrap()
);
confirm_radiobox.is_password = true;
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.confirm.yes", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.confirm.no", xous::LANG)));
////// insert the "are you sure" message at this point in the flow -- don't call setup_key_init() until we're confirmed!
rootkeys_modal.modify(
Some(ActionType::RadioButtons(confirm_radiobox)),
Some(t!("rootkeys.confirm", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxConfirmation) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.confirm.yes", xous::LANG) {
// setup_key_init() prepares the salt and other items necessary to receive a password safely
keys.setup_key_init();
// request the boot password first
keys.set_ux_password_type(Some(PasswordType::Boot));
send_message(main_cid,
xous::Message::new_scalar(Opcode::UxInitRequestPassword.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't send message to kick off the password request process");
} else {
log::info!("init keys process aborted, no harm no foul");
continue;
}
},
Some(Opcode::UxInitRequestPassword) => { Some(Opcode::UxInitRequestPassword) => {
password_action.set_action_opcode(Opcode::UxInitPasswordReturn.to_u32().unwrap()); password_action.set_action_opcode(Opcode::UxInitPasswordReturn.to_u32().unwrap());
if let Some(pwt) = keys.get_ux_password_type() { if let Some(pwt) = keys.get_ux_password_type() {

View file

@ -444,7 +444,7 @@ pub fn main_menu_thread(keys_init: usize, key_conn: usize, key_op: usize, selfsi
}; };
menu.add_item(sleep_item); menu.add_item(sleep_item);
if keys_init == 1 { if keys_init == 0 {
let initkeys_item = MenuItem { let initkeys_item = MenuItem {
name: String::<64>::from_str(t!("mainmenu.init_keys", xous::LANG)), name: String::<64>::from_str(t!("mainmenu.init_keys", xous::LANG)),
action_conn: key_conn as u32, action_conn: key_conn as u32,