mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
refactor ux flow, now on a good footing
This commit is contained in:
parent
41843db988
commit
d7d052b6ff
9 changed files with 224 additions and 104 deletions
|
|
@ -3,5 +3,10 @@
|
||||||
"en": "[ Okay ]",
|
"en": "[ Okay ]",
|
||||||
"zh": "[ 确定 ]",
|
"zh": "[ 确定 ]",
|
||||||
"en-audio": "Accept and close radio box"
|
"en-audio": "Accept and close radio box"
|
||||||
|
},
|
||||||
|
"notification.dismiss": {
|
||||||
|
"en": "[ Press any key ]",
|
||||||
|
"zh": "[ 按任意键 ]",
|
||||||
|
"en-audio": "Press any key"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,6 +47,8 @@ General form for modals:
|
||||||
- slider - left/right moves the slider, enter/select closes the modal
|
- slider - left/right moves the slider, enter/select closes the modal
|
||||||
*/
|
*/
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
|
use xous::MessageEnvelope;
|
||||||
|
use xous::send_message;
|
||||||
|
|
||||||
use crate::api::*;
|
use crate::api::*;
|
||||||
use crate::Gam;
|
use crate::Gam;
|
||||||
|
|
@ -163,6 +165,7 @@ pub struct TextEntry {
|
||||||
pub validator: Option<fn(TextEntryPayload, u32) -> Option<xous_ipc::String::<512>> >,
|
pub validator: Option<fn(TextEntryPayload, u32) -> Option<xous_ipc::String::<512>> >,
|
||||||
}
|
}
|
||||||
impl ActionApi for TextEntry {
|
impl ActionApi for TextEntry {
|
||||||
|
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||||
fn is_password(&self) -> bool {
|
fn is_password(&self) -> bool {
|
||||||
self.is_password
|
self.is_password
|
||||||
}
|
}
|
||||||
|
|
@ -417,6 +420,7 @@ impl RadioButtons {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ActionApi for RadioButtons {
|
impl ActionApi for RadioButtons {
|
||||||
|
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||||
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
||||||
let mut total_items = 0;
|
let mut total_items = 0;
|
||||||
// total items, then +1 for the "Okay" message
|
// total items, then +1 for the "Okay" message
|
||||||
|
|
@ -589,6 +593,7 @@ impl CheckBoxes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ActionApi for CheckBoxes {
|
impl ActionApi for CheckBoxes {
|
||||||
|
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||||
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
||||||
let mut total_items = 0;
|
let mut total_items = 0;
|
||||||
// total items, then +1 for the "Okay" message
|
// total items, then +1 for the "Okay" message
|
||||||
|
|
@ -731,6 +736,96 @@ impl ActionApi for CheckBoxes {
|
||||||
(None, false)
|
(None, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct Notification {
|
||||||
|
pub action_conn: xous::CID,
|
||||||
|
pub action_opcode: u32,
|
||||||
|
pub is_password: bool,
|
||||||
|
}
|
||||||
|
impl Notification {
|
||||||
|
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
||||||
|
Notification {
|
||||||
|
action_conn,
|
||||||
|
action_opcode,
|
||||||
|
is_password: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn set_is_password(&mut self, setting: bool) {
|
||||||
|
// this will cause text to be inverted. Untrusted entities can try to set this,
|
||||||
|
// but the GAM should defeat this for dialog boxes outside of the trusted boot
|
||||||
|
// set because they can't achieve a high enough trust level.
|
||||||
|
self.is_password = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ActionApi for Notification {
|
||||||
|
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||||
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
||||||
|
glyph_height + margin * 2 + 5
|
||||||
|
}
|
||||||
|
fn redraw(&self, at_height: i16, modal: &Modal) {
|
||||||
|
// prime a textview with the correct general style parameters
|
||||||
|
let mut tv = TextView::new(
|
||||||
|
modal.canvas,
|
||||||
|
TextBounds::BoundingBox(Rectangle::new_coords(0, 0, 1, 1))
|
||||||
|
);
|
||||||
|
tv.ellipsis = true;
|
||||||
|
tv.style = modal.style;
|
||||||
|
tv.invert = self.is_password;
|
||||||
|
tv.draw_border= false;
|
||||||
|
tv.margin = Point::new(0, 0,);
|
||||||
|
tv.insertion = None;
|
||||||
|
|
||||||
|
tv.bounds_computed = None;
|
||||||
|
tv.bounds_hint = TextBounds::GrowableFromTl(
|
||||||
|
Point::new(modal.margin, at_height + modal.margin * 2),
|
||||||
|
(modal.canvas_width - modal.margin * 2) as u16
|
||||||
|
);
|
||||||
|
write!(tv, "{}", t!("notification.dismiss", xous::LANG)).unwrap();
|
||||||
|
modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size");
|
||||||
|
let textwidth = if let Some(bounds) = tv.bounds_computed {
|
||||||
|
bounds.br.x - bounds.tl.x
|
||||||
|
} else {
|
||||||
|
modal.canvas_width - modal.margin * 2
|
||||||
|
};
|
||||||
|
log::info!("tw: {}", textwidth);
|
||||||
|
let offset = (modal.canvas_width - textwidth) / 2;
|
||||||
|
log::info!("offset2: {}", offset);
|
||||||
|
tv.bounds_computed = None;
|
||||||
|
tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new(
|
||||||
|
Point::new(offset, at_height + modal.margin * 2),
|
||||||
|
Point::new(modal.canvas_width - modal.margin, at_height + modal.line_height + modal.margin * 2)
|
||||||
|
));
|
||||||
|
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
|
||||||
|
|
||||||
|
// divider lines
|
||||||
|
let color = if self.is_password {
|
||||||
|
PixelColor::Light
|
||||||
|
} else {
|
||||||
|
PixelColor::Dark
|
||||||
|
};
|
||||||
|
|
||||||
|
modal.gam.draw_line(modal.canvas, Line::new_with_style(
|
||||||
|
Point::new(modal.margin, at_height + modal.margin),
|
||||||
|
Point::new(modal.canvas_width - modal.margin, at_height + modal.margin),
|
||||||
|
DrawStyle::new(color, color, 1))
|
||||||
|
).expect("couldn't draw entry line");
|
||||||
|
}
|
||||||
|
fn key_action(&mut self, k: char) -> (Option<xous_ipc::String::<512>>, bool) {
|
||||||
|
log::trace!("key_action: {}", k);
|
||||||
|
match k {
|
||||||
|
'\u{0}' => {
|
||||||
|
// ignore null messages
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
send_message(self.action_conn, xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0)).expect("couldn't pass on dismissal");
|
||||||
|
return(None, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(None, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Slider {
|
pub struct Slider {
|
||||||
pub min: u32,
|
pub min: u32,
|
||||||
|
|
@ -749,6 +844,7 @@ impl ActionApi for Slider {
|
||||||
*/
|
*/
|
||||||
glyph_height * 3 + margin * 2
|
glyph_height * 3 + margin * 2
|
||||||
}
|
}
|
||||||
|
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -756,13 +852,14 @@ impl ActionApi for Slider {
|
||||||
|
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
trait ActionApi {
|
pub trait ActionApi {
|
||||||
fn height(&self, glyph_height: i16, margin: i16) -> i16 {glyph_height + margin * 2}
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {glyph_height + margin * 2}
|
||||||
fn redraw(&self, _at_height: i16, _modal: &Modal) { unimplemented!() }
|
fn redraw(&self, _at_height: i16, _modal: &Modal) { unimplemented!() }
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
fn is_password(&self) -> bool { false }
|
fn is_password(&self) -> bool { false }
|
||||||
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
|
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
|
||||||
fn key_action(&mut self, _key: char) -> (Option<xous_ipc::String::<512>>, bool) {(None, true)}
|
fn key_action(&mut self, _key: char) -> (Option<xous_ipc::String::<512>>, bool) {(None, true)}
|
||||||
|
fn set_action_opcode(&mut self, _op: u32) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch(ActionApi)]
|
#[enum_dispatch(ActionApi)]
|
||||||
|
|
@ -771,7 +868,8 @@ pub enum ActionType {
|
||||||
TextEntry,
|
TextEntry,
|
||||||
RadioButtons,
|
RadioButtons,
|
||||||
CheckBoxes,
|
CheckBoxes,
|
||||||
Slider
|
Slider,
|
||||||
|
Notification,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[derive(Debug)]
|
//#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@
|
||||||
"zh": "输入密码\n软件更新\n安全含义:至关重要 ",
|
"zh": "输入密码\n软件更新\n安全含义:至关重要 ",
|
||||||
"en-audio": "Enter update password. This password is critically important."
|
"en-audio": "Enter update password. This password is critically important."
|
||||||
},
|
},
|
||||||
|
"rootkeys.already_init": {
|
||||||
|
"en": "Root keys already initialized.",
|
||||||
|
"zh": "根密码已经设置",
|
||||||
|
"en-audio": "Root keys already initialized."
|
||||||
|
},
|
||||||
|
"rootkeys.setup": {
|
||||||
|
"en": "This will init the root keys.\nI'm going to need two\npasswords:\n 1. Device unlock\n 2. Software update",
|
||||||
|
"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."
|
||||||
|
},
|
||||||
"rootkeys.policy_clear": {
|
"rootkeys.policy_clear": {
|
||||||
"en": "Clear after use",
|
"en": "Clear after use",
|
||||||
"zh": "使用后删除",
|
"zh": "使用后删除",
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,16 @@ pub(crate) const ROOTKEY_MENU_NAME: &'static str = "rootkeys menu";
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
pub(crate) enum Opcode {
|
pub(crate) enum Opcode {
|
||||||
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
|
|
||||||
TryInitKeys,
|
|
||||||
/// use to check if we've been initialized
|
/// use to check if we've been initialized
|
||||||
KeysInitialized,
|
KeysInitialized,
|
||||||
|
|
||||||
TestUx,
|
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
|
||||||
|
UxTryInitKeys,
|
||||||
|
UxRequestBootPassword,
|
||||||
|
UxPasswordReturn,
|
||||||
|
UxPolicyReturn,
|
||||||
|
UxGutter, // NOP for UX calls that require a destination
|
||||||
/// UX opcodes
|
/// UX opcodes
|
||||||
PasswordModalEntry,
|
|
||||||
PasswordPolicy,
|
|
||||||
RaisePolicyMenu,
|
|
||||||
MenuRedraw,
|
MenuRedraw,
|
||||||
MenuKeys,
|
MenuKeys,
|
||||||
MenuDrop,
|
MenuDrop,
|
||||||
|
|
|
||||||
|
|
@ -326,62 +326,29 @@ impl RootKeys {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_init_keys(&mut self) {
|
pub fn setup_key_init(&mut self) {
|
||||||
let mut step = 0; // current step
|
|
||||||
let total = 10; // total number of steps
|
|
||||||
|
|
||||||
{ // this block checks if we're already initialized, and aborts if we are
|
|
||||||
let progress_cid = if let Some(progress_sid) = maybe_progress {
|
|
||||||
Some(xous::connect(progress_sid).expect("couldn't connect to originator for progress updates"))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
// first progress update: we could make a progress update
|
|
||||||
step += 1;
|
|
||||||
self.update_progress(progress_cid, step, total, false);
|
|
||||||
|
|
||||||
self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, KeyRomLocations::CONFIG as u32);
|
|
||||||
|
|
||||||
if self.is_initialized() {
|
|
||||||
self.update_progress(progress_cid, step, total, true);
|
|
||||||
// don't re-initialize an initialized KEYROM
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// block suspend/resume ops during security-sensitive operations
|
// block suspend/resume ops during security-sensitive operations
|
||||||
self.susres.set_suspendable(false).expect("couldn't block suspend/resume");
|
self.susres.set_suspendable(false).expect("couldn't block suspend/resume");
|
||||||
|
// in this block, keyrom data is copied into RAM.
|
||||||
{ // in this block, keyrom data is copied into RAM.
|
// make a copy of the KEYROM to hold the new mods, in the sensitive data area
|
||||||
// make a copy of the KEYROM to hold the new mods, in the sensitive data area
|
let sensitive_slice = self.sensitive_data.as_slice_mut::<u32>();
|
||||||
let sensitive_slice = self.sensitive_data.as_slice_mut::<u32>();
|
for addr in 0..256 {
|
||||||
for addr in 0..256 {
|
self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, addr);
|
||||||
self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, addr);
|
sensitive_slice[addr as usize] = self.keyrom.rf(utra::keyrom::DATA_DATA);
|
||||||
sensitive_slice[addr as usize] = self.keyrom.rf(utra::keyrom::DATA_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the following keys should be provisioned:
|
|
||||||
// - self-signing private key
|
|
||||||
// - self-signing public key
|
|
||||||
// - user root key
|
|
||||||
// - pepper
|
|
||||||
|
|
||||||
// provision the pepper
|
|
||||||
for keyword in sensitive_slice[KeyRomLocations::PEPPER as usize..(KeyRomLocations::PEPPER + 4) as usize].iter_mut() {
|
|
||||||
*keyword = self.trng.get_u32().expect("couldn't get random number");
|
|
||||||
}
|
|
||||||
|
|
||||||
// prompt the user for a password
|
|
||||||
self.cur_password_type = Some(PasswordType::Boot);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// zeroize the RAM-backed data
|
|
||||||
for data in sensitive_slice.iter_mut() {
|
|
||||||
*data = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// provision the pepper
|
||||||
|
for keyword in sensitive_slice[KeyRomLocations::PEPPER as usize..(KeyRomLocations::PEPPER + 4) as usize].iter_mut() {
|
||||||
|
*keyword = self.trng.get_u32().expect("couldn't get random number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn finish_key_init(&mut self) {
|
||||||
|
let sensitive_slice = self.sensitive_data.as_slice_mut::<u32>();
|
||||||
|
// zeroize the RAM-backed data
|
||||||
|
for data in sensitive_slice.iter_mut() {
|
||||||
|
*data = 0;
|
||||||
|
}
|
||||||
// re-allow suspend/resume ops
|
// re-allow suspend/resume ops
|
||||||
self.susres.set_suspendable(true).expect("couldn't re-allow suspend/resume");
|
self.susres.set_suspendable(true).expect("couldn't re-allow suspend/resume");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ impl RootKeys {
|
||||||
}
|
}
|
||||||
pub fn conn(&self) -> CID {self.conn}
|
pub fn conn(&self) -> CID {self.conn}
|
||||||
pub fn get_try_init_keys_op(&self) -> u32 {
|
pub fn get_try_init_keys_op(&self) -> u32 {
|
||||||
Opcode::TryInitKeys.to_u32().unwrap()
|
Opcode::UxTryInitKeys.to_u32().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_progress_server(&mut self) -> xous::SID {
|
fn ensure_progress_server(&mut self) -> xous::SID {
|
||||||
|
|
@ -93,7 +93,7 @@ impl RootKeys {
|
||||||
/// if the KEYROM entries are not 0, it will abort without any user prompt, but with an error code.
|
/// if the KEYROM entries are not 0, it will abort without any user prompt, but with an error code.
|
||||||
pub fn try_init_keys(&mut self) -> Result<(), xous::Error> {
|
pub fn try_init_keys(&mut self) -> Result<(), xous::Error> {
|
||||||
send_message(self.conn,
|
send_message(self.conn,
|
||||||
Message::new_scalar(Opcode::TryInitKeys.to_usize().unwrap(),
|
Message::new_scalar(Opcode::UxTryInitKeys.to_usize().unwrap(),
|
||||||
0, 0, 0, 0)
|
0, 0, 0, 0)
|
||||||
).map(|_| ())
|
).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
@ -119,13 +119,13 @@ impl RootKeys {
|
||||||
pub fn self_sign(&mut self, which: ImageType) -> Result<(), xous::Error> {
|
pub fn self_sign(&mut self, which: ImageType) -> Result<(), xous::Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
pub fn test_ux(&mut self, arg: usize) {
|
pub fn test_ux(&mut self, arg: usize) {
|
||||||
send_message(self.conn,
|
send_message(self.conn,
|
||||||
Message::new_scalar(Opcode::TestUx.to_usize().unwrap(),
|
Message::new_scalar(Opcode::TestUx.to_usize().unwrap(),
|
||||||
arg, 0, 0, 0)
|
arg, 0, 0, 0)
|
||||||
).expect("couldn't send test message");
|
).expect("couldn't send test message");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,14 @@ mod implementation {
|
||||||
log::info!("policy updated: {:?}", policy);
|
log::info!("policy updated: {:?}", policy);
|
||||||
}
|
}
|
||||||
pub fn hash_and_save_password(&mut self, pw: &str) {
|
pub fn hash_and_save_password(&mut self, pw: &str) {
|
||||||
log::info!("got password plaintext: {}, type: {:?}", pw, pw_type);
|
log::info!("got password plaintext: {}", pw);
|
||||||
}
|
}
|
||||||
pub fn try_init_keys(&mut self) {
|
pub fn try_init_keys(&mut self) {
|
||||||
}
|
}
|
||||||
pub fn set_ux_password_type(&mut self, _cur_type: PasswordType) {
|
pub fn set_ux_password_type(&mut self, _cur_type: PasswordType) {
|
||||||
}
|
}
|
||||||
pub fn is_initialized(&self) -> bool {false}
|
pub fn is_initialized(&self) -> bool {false}
|
||||||
|
pub fn setup_key_init(&mut self) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,21 +101,21 @@ fn xmain() -> ! {
|
||||||
policy_menu.add_item(MenuItem {
|
policy_menu.add_item(MenuItem {
|
||||||
name: String::<64>::from_str(t!("rootkeys.policy_keep", xous::LANG)),
|
name: String::<64>::from_str(t!("rootkeys.policy_keep", xous::LANG)),
|
||||||
action_conn: main_cid,
|
action_conn: main_cid,
|
||||||
action_opcode: Opcode::PasswordPolicy.to_u32().unwrap(),
|
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
|
||||||
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysKeep.to_u32().unwrap(), 0, 0, 0,]),
|
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysKeep.to_u32().unwrap(), 0, 0, 0,]),
|
||||||
close_on_select: true,
|
close_on_select: true,
|
||||||
});
|
});
|
||||||
policy_menu.add_item(MenuItem {
|
policy_menu.add_item(MenuItem {
|
||||||
name: String::<64>::from_str(t!("rootkeys.policy_suspend", xous::LANG)),
|
name: String::<64>::from_str(t!("rootkeys.policy_suspend", xous::LANG)),
|
||||||
action_conn: main_cid,
|
action_conn: main_cid,
|
||||||
action_opcode: Opcode::PasswordPolicy.to_u32().unwrap(),
|
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
|
||||||
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::EraseOnSuspend.to_u32().unwrap(), 0, 0, 0,]),
|
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::EraseOnSuspend.to_u32().unwrap(), 0, 0, 0,]),
|
||||||
close_on_select: true,
|
close_on_select: true,
|
||||||
});
|
});
|
||||||
policy_menu.add_item(MenuItem {
|
policy_menu.add_item(MenuItem {
|
||||||
name: String::<64>::from_str(t!("rootkeys.policy_clear", xous::LANG)),
|
name: String::<64>::from_str(t!("rootkeys.policy_clear", xous::LANG)),
|
||||||
action_conn: main_cid,
|
action_conn: main_cid,
|
||||||
action_opcode: Opcode::PasswordPolicy.to_u32().unwrap(),
|
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
|
||||||
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysPurge.to_u32().unwrap(), 0, 0, 0,]),
|
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysPurge.to_u32().unwrap(), 0, 0, 0,]),
|
||||||
close_on_select: true,
|
close_on_select: true,
|
||||||
});
|
});
|
||||||
|
|
@ -123,24 +124,26 @@ fn xmain() -> ! {
|
||||||
Opcode::MenuKeys.to_u32().unwrap(),
|
Opcode::MenuKeys.to_u32().unwrap(),
|
||||||
Opcode::MenuDrop.to_u32().unwrap());
|
Opcode::MenuDrop.to_u32().unwrap());
|
||||||
|
|
||||||
//xous::create_thread_0(rootkeys_ux_thread).expect("couldn't start rootkeys UX thread");
|
let password_action = TextEntry {
|
||||||
let password_action = gam::modal::TextEntry {
|
|
||||||
is_password: true,
|
is_password: true,
|
||||||
visibility: gam::modal::TextEntryVisibility::LastChars,
|
visibility: TextEntryVisibility::LastChars,
|
||||||
action_conn: main_cid,
|
action_conn: main_cid,
|
||||||
action_opcode: Opcode::PasswordModalEntry.to_u32().unwrap(),
|
action_opcode: Opcode::UxPasswordReturn.to_u32().unwrap(),
|
||||||
action_payload: TextEntryPayload::new(),
|
action_payload: TextEntryPayload::new(),
|
||||||
validator: None,
|
validator: None,
|
||||||
};
|
};
|
||||||
let mut password_modal = gam::Modal::new(
|
let mut dismiss_modal_action = Notification::new(main_cid, Opcode::UxGutter.to_u32().unwrap());
|
||||||
|
dismiss_modal_action.set_is_password(true);
|
||||||
|
|
||||||
|
let mut rootkeys_modal = Modal::new(
|
||||||
crate::api::ROOTKEY_MODAL_NAME,
|
crate::api::ROOTKEY_MODAL_NAME,
|
||||||
gam::ActionType::TextEntry(password_action),
|
ActionType::TextEntry(password_action),
|
||||||
Some(t!("rootpass.top", xous::LANG)),
|
Some(t!("rootpass.top", xous::LANG)),
|
||||||
None,
|
None,
|
||||||
GlyphStyle::Small,
|
GlyphStyle::Small,
|
||||||
4
|
4
|
||||||
);
|
);
|
||||||
password_modal.spawn_helper(keys_sid, password_modal.sid,
|
rootkeys_modal.spawn_helper(keys_sid, rootkeys_modal.sid,
|
||||||
Opcode::ModalRedraw.to_u32().unwrap(),
|
Opcode::ModalRedraw.to_u32().unwrap(),
|
||||||
Opcode::ModalKeys.to_u32().unwrap(),
|
Opcode::ModalKeys.to_u32().unwrap(),
|
||||||
Opcode::ModalDrop.to_u32().unwrap(),
|
Opcode::ModalDrop.to_u32().unwrap(),
|
||||||
|
|
@ -156,9 +159,6 @@ fn xmain() -> ! {
|
||||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||||
keys.resume();
|
keys.resume();
|
||||||
}),
|
}),
|
||||||
Some(Opcode::TryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {
|
|
||||||
keys.try_init_keys();
|
|
||||||
}),
|
|
||||||
Some(Opcode::KeysInitialized) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::KeysInitialized) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
if keys.is_initialized() {
|
if keys.is_initialized() {
|
||||||
xous::return_scalar(msg.sender, 1).unwrap();
|
xous::return_scalar(msg.sender, 1).unwrap();
|
||||||
|
|
@ -166,13 +166,48 @@ fn xmain() -> ! {
|
||||||
xous::return_scalar(msg.sender, 0).unwrap();
|
xous::return_scalar(msg.sender, 0).unwrap();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(Opcode::TestUx) => msg_scalar_unpack!(msg, arg, _, _, _, {
|
|
||||||
log::debug!("activating password modal");
|
// UX flow opcodes
|
||||||
keys.set_ux_password_type(PasswordType::Boot);
|
Some(Opcode::UxTryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
password_modal.activate();
|
// overall flow:
|
||||||
//policy_menu.activate();
|
// - setup the init
|
||||||
|
// - prompt for root password
|
||||||
|
// - prompt for boot password
|
||||||
|
// - create the keys
|
||||||
|
// - write the keys
|
||||||
|
// - clear the passwords
|
||||||
|
// - reboot
|
||||||
|
// the following keys should be provisioned:
|
||||||
|
// - self-signing private key
|
||||||
|
// - self-signing public key
|
||||||
|
// - user root key
|
||||||
|
// - pepper
|
||||||
|
if keys.is_initialized() {
|
||||||
|
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
|
||||||
|
rootkeys_modal.modify(
|
||||||
|
Some(ActionType::Notification(dismiss_modal_action)),
|
||||||
|
Some(t!("rootkeys.already_init", xous::LANG)), false,
|
||||||
|
None, true, None);
|
||||||
|
} else {
|
||||||
|
dismiss_modal_action.set_action_opcode(Opcode::UxRequestBootPassword.to_u32().unwrap());
|
||||||
|
rootkeys_modal.modify(
|
||||||
|
Some(ActionType::Notification(dismiss_modal_action)),
|
||||||
|
Some(t!("rootkeys.setup", xous::LANG)), false,
|
||||||
|
None, true, None);
|
||||||
|
}
|
||||||
|
rootkeys_modal.activate();
|
||||||
}),
|
}),
|
||||||
Some(Opcode::PasswordModalEntry) => {
|
Some(Opcode::UxRequestBootPassword) => {
|
||||||
|
keys.setup_key_init();
|
||||||
|
keys.set_ux_password_type(PasswordType::Boot);
|
||||||
|
rootkeys_modal.modify(
|
||||||
|
Some(ActionType::TextEntry(password_action)),
|
||||||
|
Some(t!("rootpass.top", xous::LANG)), false,
|
||||||
|
None, true, None
|
||||||
|
);
|
||||||
|
rootkeys_modal.activate();
|
||||||
|
}
|
||||||
|
Some(Opcode::UxPasswordReturn) => {
|
||||||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
|
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
|
||||||
|
|
||||||
|
|
@ -181,17 +216,23 @@ fn xmain() -> ! {
|
||||||
buf.volatile_clear();
|
buf.volatile_clear();
|
||||||
|
|
||||||
// always explicitly request a policy decision for rootkeys
|
// always explicitly request a policy decision for rootkeys
|
||||||
xous::send_message(main_cid,
|
|
||||||
Message::new_scalar(Opcode::RaisePolicyMenu.to_usize().unwrap(), 0, 0, 0, 0)
|
|
||||||
).expect("couldn't raise policy menu follow-up dialogue");
|
|
||||||
},
|
|
||||||
Some(Opcode::RaisePolicyMenu) => {
|
|
||||||
log::debug!("raising policy menu");
|
|
||||||
policy_menu.activate();
|
policy_menu.activate();
|
||||||
}
|
},
|
||||||
Some(Opcode::PasswordPolicy) => msg_scalar_unpack!(msg, policy_code, _, _, _, {
|
Some(Opcode::UxPolicyReturn) => msg_scalar_unpack!(msg, policy_code, _, _, _, {
|
||||||
keys.update_policy(FromPrimitive::from_usize(policy_code));
|
keys.update_policy(FromPrimitive::from_usize(policy_code));
|
||||||
}),
|
}),
|
||||||
|
/*
|
||||||
|
Some(Opcode::TestUx) => msg_scalar_unpack!(msg, arg, _, _, _, {
|
||||||
|
log::debug!("activating password modal");
|
||||||
|
keys.set_ux_password_type(PasswordType::Boot);
|
||||||
|
rootkeys_modal.activate();
|
||||||
|
//policy_menu.activate();
|
||||||
|
}),*/
|
||||||
|
Some(Opcode::UxGutter) => {
|
||||||
|
// an intentional NOP for UX actions that require a destintation but need no action
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// boilerplate Ux handlers
|
// boilerplate Ux handlers
|
||||||
Some(Opcode::MenuRedraw) => {
|
Some(Opcode::MenuRedraw) => {
|
||||||
|
|
@ -210,7 +251,7 @@ fn xmain() -> ! {
|
||||||
panic!("Menu handler for rootkeys quit unexpectedly");
|
panic!("Menu handler for rootkeys quit unexpectedly");
|
||||||
},
|
},
|
||||||
Some(Opcode::ModalRedraw) => {
|
Some(Opcode::ModalRedraw) => {
|
||||||
password_modal.redraw();
|
rootkeys_modal.redraw();
|
||||||
},
|
},
|
||||||
Some(Opcode::ModalKeys) => msg_scalar_unpack!(msg, k1, k2, k3, k4, {
|
Some(Opcode::ModalKeys) => msg_scalar_unpack!(msg, k1, k2, k3, k4, {
|
||||||
let keys = [
|
let keys = [
|
||||||
|
|
@ -219,7 +260,7 @@ fn xmain() -> ! {
|
||||||
if let Some(a) = core::char::from_u32(k3 as u32) {a} else {'\u{0000}'},
|
if let Some(a) = core::char::from_u32(k3 as u32) {a} else {'\u{0000}'},
|
||||||
if let Some(a) = core::char::from_u32(k4 as u32) {a} else {'\u{0000}'},
|
if let Some(a) = core::char::from_u32(k4 as u32) {a} else {'\u{0000}'},
|
||||||
];
|
];
|
||||||
password_modal.key_event(keys);
|
rootkeys_modal.key_event(keys);
|
||||||
}),
|
}),
|
||||||
Some(Opcode::ModalDrop) => {
|
Some(Opcode::ModalDrop) => {
|
||||||
panic!("Password modal for rootkeys quit unexpectedly")
|
panic!("Password modal for rootkeys quit unexpectedly")
|
||||||
|
|
|
||||||
|
|
@ -750,7 +750,7 @@ fn xmain() -> ! {
|
||||||
Some(Opcode::UxSetTime) => msg_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::UxSetTime) => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
rtc_textentry.action_opcode = Opcode::UxMonth.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxMonth.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)), Some(t!("rtc.month", xous::LANG)), false, None, true, None);
|
modal.modify(Some(TextEntry(rtc_textentry)), Some(t!("rtc.month", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}),
|
}),
|
||||||
Some(Opcode::UxMonth) => {
|
Some(Opcode::UxMonth) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -762,7 +762,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxDay.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxDay.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)),
|
modal.modify(Some(TextEntry(rtc_textentry)),
|
||||||
Some(t!("rtc.day", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.day", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxDay) => {
|
Some(Opcode::UxDay) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -774,7 +774,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxYear.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxYear.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)),
|
modal.modify(Some(TextEntry(rtc_textentry)),
|
||||||
Some(t!("rtc.year", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.year", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxYear) => {
|
Some(Opcode::UxYear) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -785,7 +785,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxDayOfWeek.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxDayOfWeek.to_u32().unwrap();
|
||||||
modal.modify(Some(RadioButtons(rtc_radiobox)),
|
modal.modify(Some(RadioButtons(rtc_radiobox)),
|
||||||
Some(t!("rtc.day_of_week", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.day_of_week", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxDayOfWeek) => {
|
Some(Opcode::UxDayOfWeek) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -810,7 +810,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxHour.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxHour.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)),
|
modal.modify(Some(TextEntry(rtc_textentry)),
|
||||||
Some(t!("rtc.hour", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.hour", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxHour) => {
|
Some(Opcode::UxHour) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -821,7 +821,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxMinute.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxMinute.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)),
|
modal.modify(Some(TextEntry(rtc_textentry)),
|
||||||
Some(t!("rtc.minute", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.minute", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxMinute) => {
|
Some(Opcode::UxMinute) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
@ -832,7 +832,7 @@ fn xmain() -> ! {
|
||||||
rtc_textentry.action_opcode = Opcode::UxSeconds.to_u32().unwrap();
|
rtc_textentry.action_opcode = Opcode::UxSeconds.to_u32().unwrap();
|
||||||
modal.modify(Some(TextEntry(rtc_textentry)),
|
modal.modify(Some(TextEntry(rtc_textentry)),
|
||||||
Some(t!("rtc.seconds", xous::LANG)), false, None, true, None);
|
Some(t!("rtc.seconds", xous::LANG)), false, None, true, None);
|
||||||
gam.raise_modal(crate::RTC_MODAL_NAME).expect("couldn't raise RTC modal");
|
modal.activate();
|
||||||
}
|
}
|
||||||
Some(Opcode::UxSeconds) => {
|
Some(Opcode::UxSeconds) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ impl<'a> ShellCmdApi<'a> for Keys {
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
"ux" => {
|
/*"ux" => {
|
||||||
self.rootkeys.test_ux(0);
|
self.rootkeys.test_ux(0);
|
||||||
//debug_here::debug_here!();
|
//debug_here::debug_here!();
|
||||||
write!(ret, "show UX").unwrap();
|
write!(ret, "show UX").unwrap();
|
||||||
}
|
}*/
|
||||||
"usblock" => {
|
"usblock" => {
|
||||||
env.llio.debug_usb(Some(true)).unwrap();
|
env.llio.debug_usb(Some(true)).unwrap();
|
||||||
write!(ret, "USB debug port locked out; one word at 0x80000000 is disclosable via USB.").unwrap();
|
write!(ret, "USB debug port locked out; one word at 0x80000000 is disclosable via USB.").unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue