suppress codegen for unused policy menu (save RAM/disk space)

This commit is contained in:
bunnie 2022-01-17 04:26:49 +08:00
parent d719360a4d
commit 11162860a8
3 changed files with 68 additions and 48 deletions

View file

@ -64,6 +64,7 @@ features = ["u32_backend", "rand"]
utralib = { path = "../../utralib"} utralib = { path = "../../utralib"}
[features] [features]
policy-menu = [] # provisions for users to set their password retention policies (on the block for deprecation)
hazardous-debug = [] # this feature enables the printing of secret materials for debug purposes hazardous-debug = [] # this feature enables the printing of secret materials for debug purposes
default = [] default = []

View file

@ -53,7 +53,9 @@ pub(crate) enum Opcode {
// General Ux calls // General Ux calls
UxGutter, // NOP for UX calls that require a destination UxGutter, // NOP for UX calls that require a destination
#[cfg(feature = "policy-menu")]
UxGetPolicy, UxGetPolicy,
#[cfg(feature = "policy-menu")]
UxPolicyReturn, UxPolicyReturn,
UxTryReboot, UxTryReboot,
UxDoReboot, UxDoReboot,

View file

@ -4,11 +4,15 @@
mod api; mod api;
use api::*; use api::*;
use xous::{msg_scalar_unpack, send_message, msg_blocking_scalar_unpack}; use xous::{msg_scalar_unpack, send_message, msg_blocking_scalar_unpack};
use xous_ipc::{String, Buffer}; #[cfg(feature = "policy-menu")]
use xous_ipc::String;
use xous_ipc::Buffer;
use num_traits::*; use num_traits::*;
use gam::modal::*; use gam::modal::*;
#[cfg(feature = "policy-menu")]
use gam::{MenuItem, MenuPayload}; use gam::{MenuItem, MenuPayload};
use locales::t; use locales::t;
@ -287,30 +291,35 @@ fn xmain() -> ! {
let mut susres = susres::Susres::new(None, &xns, api::Opcode::SuspendResume as u32, main_cid).expect("couldn't create suspend/resume object"); let mut susres = susres::Susres::new(None, &xns, api::Opcode::SuspendResume as u32, main_cid).expect("couldn't create suspend/resume object");
// create a policy menu object // create a policy menu object
let mut menu_items = Vec::<MenuItem>::new(); #[cfg(feature = "policy-menu")]
menu_items.push(MenuItem { {
name: String::from_str(t!("rootkeys.policy_keep", xous::LANG)), let mut menu_items = Vec::<MenuItem>::new();
action_conn: Some(main_cid), menu_items.push(MenuItem {
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(), name: String::from_str(t!("rootkeys.policy_keep", xous::LANG)),
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysKeep.to_u32().unwrap(), 0, 0, 0,]), action_conn: Some(main_cid),
close_on_select: true, action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
}); action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysKeep.to_u32().unwrap(), 0, 0, 0,]),
menu_items.push(MenuItem { close_on_select: true,
name: String::from_str(t!("rootkeys.policy_suspend", xous::LANG)), });
action_conn: Some(main_cid), menu_items.push(MenuItem {
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(), name: String::from_str(t!("rootkeys.policy_suspend", xous::LANG)),
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::EraseOnSuspend.to_u32().unwrap(), 0, 0, 0,]), action_conn: Some(main_cid),
close_on_select: true, action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
}); action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::EraseOnSuspend.to_u32().unwrap(), 0, 0, 0,]),
menu_items.push(MenuItem { close_on_select: true,
name: String::from_str(t!("rootkeys.policy_clear", xous::LANG)), });
action_conn: Some(main_cid), menu_items.push(MenuItem {
action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(), name: String::from_str(t!("rootkeys.policy_clear", xous::LANG)),
action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysPurge.to_u32().unwrap(), 0, 0, 0,]), action_conn: Some(main_cid),
close_on_select: true, action_opcode: Opcode::UxPolicyReturn.to_u32().unwrap(),
}); action_payload: MenuPayload::Scalar([PasswordRetentionPolicy::AlwaysPurge.to_u32().unwrap(), 0, 0, 0,]),
gam::menu_matic(menu_items, crate::ROOTKEY_MENU_NAME, None); close_on_select: true,
let mut policy_followup_action: Option<usize> = None; });
gam::menu_matic(menu_items, crate::ROOTKEY_MENU_NAME, None);
let mut policy_followup_action: Option<usize> = None;
}
// this is the basic default policy of high-security keys -- they stick around until the next suspend
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
// create our very own password modal -- so that critical passwords aren't being shuffled between servers left and right // create our very own password modal -- so that critical passwords aren't being shuffled between servers left and right
let mut password_action = TextEntry { let mut password_action = TextEntry {
@ -340,6 +349,7 @@ fn xmain() -> ! {
// a modals manager for less-secure, run-of-the-mill operations // a modals manager for less-secure, run-of-the-mill operations
let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); let modals = modals::Modals::new(&xns).expect("can't connect to Modals server");
#[cfg(feature = "policy-menu")]
let gam = gam::Gam::new(&xns).expect("couldn't establish connection to GAM"); let gam = gam::Gam::new(&xns).expect("couldn't establish connection to GAM");
let mut reboot_initiated = false; let mut reboot_initiated = false;
@ -682,16 +692,19 @@ fn xmain() -> ! {
// this is a bit of legacy code to handle a return from a menu that would set our password policy. // this is a bit of legacy code to handle a return from a menu that would set our password policy.
// for now, this is short-circuited because every branch that leads into here selects "policy_suspend", // for now, this is short-circuited because every branch that leads into here selects "policy_suspend",
// which is a 99% correct but 100% more user-friendly policy // which is a 99% correct but 100% more user-friendly policy
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; #[cfg(feature = "policy-menu")]
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap(); {
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) { let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep)); let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) { if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend)); keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
} else if payload.as_str() == "no change" { } else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
// don't change the policy keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
} else { } else if payload.as_str() == "no change" {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level // don't change the policy
} else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
} }
keys.set_ux_password_type(None); keys.set_ux_password_type(None);
@ -751,17 +764,19 @@ fn xmain() -> ! {
.map(|_| ()).expect("couldn't send action message"); .map(|_| ()).expect("couldn't send action message");
}, },
Some(Opcode::UxSignXousRun) => { Some(Opcode::UxSignXousRun) => {
// legacy code to set policy, if it were to be inserted in the flow #[cfg(feature = "policy-menu")]
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; {// legacy code to set policy, if it were to be inserted in the flow
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap(); let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) { let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep)); if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) { keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend)); } else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
} else if payload.as_str() == "no change" { keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
// don't change the policy } else if payload.as_str() == "no change" {
} else { // don't change the policy
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level } else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
} }
keys.set_ux_password_type(None); keys.set_ux_password_type(None);
@ -848,7 +863,7 @@ fn xmain() -> ! {
rootkeys_modal.activate(); rootkeys_modal.activate();
}, },
Some(Opcode::UxAesEnsureReturn) => { Some(Opcode::UxAesEnsureReturn) => {
/* #[cfg(feature = "policy-menu")]
{ // in case we want to bring back the policy check { // in case we want to bring back the policy check
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap(); let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
@ -861,7 +876,7 @@ fn xmain() -> ! {
} else { } else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
} }
}*/ }
{ {
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();
@ -996,9 +1011,11 @@ fn xmain() -> ! {
// dummy test for now // dummy test for now
xous::return_scalar(msg.sender, 1234).unwrap(); xous::return_scalar(msg.sender, 1234).unwrap();
}), }),
#[cfg(feature = "policy-menu")]
Some(Opcode::UxGetPolicy) => { Some(Opcode::UxGetPolicy) => {
gam.raise_menu(ROOTKEY_MENU_NAME).expect("couldn't raise policy menu"); gam.raise_menu(ROOTKEY_MENU_NAME).expect("couldn't raise policy menu");
} }
#[cfg(feature = "policy-menu")]
Some(Opcode::UxPolicyReturn) => 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));
if let Some(action) = policy_followup_action { if let Some(action) = policy_followup_action {