diff --git a/apps-baosec/vault2/src/actions.rs b/apps-baosec/vault2/src/actions.rs index 5c684c388..41317f46d 100644 --- a/apps-baosec/vault2/src/actions.rs +++ b/apps-baosec/vault2/src/actions.rs @@ -6,11 +6,14 @@ use std::sync::{ Arc, Mutex, atomic::{AtomicBool, Ordering}, }; +use std::time::SystemTime; #[cfg(feature = "hosted-baosec")] use bao1x_emu::trng::Trng; +use bao1x_hal_service::api::TimeOp; #[cfg(feature = "board-baosec")] use bao1x_hal_service::trng::Trng; +use chrono::{DateTime, Utc}; use keystore::Keystore; use locales::t; use num_traits::*; @@ -74,6 +77,8 @@ pub struct ActionManager { keystore: Keystore, gfx: ux_api::service::gfx::Gfx, + // used to set time when QR codes are scanned + rtc_conn: xous::CID, } impl ActionManager { pub fn new( @@ -86,6 +91,9 @@ impl ActionManager { let storage_manager = storage::Manager::new(&xns); let mc = (*mode.lock().unwrap()).clone(); + let rtc_conn = + xous::connect(xous::SID::from_bytes(bao1x_hal_service::api::TIME_SERVER_PUBLIC).unwrap()) + .unwrap(); ActionManager { modals: modals::Modals::new(&xns).unwrap(), storage: RefCell::new(storage_manager), @@ -102,6 +110,7 @@ impl ActionManager { main_conn, keystore: Keystore::new(&xns), gfx: ux_api::service::gfx::Gfx::new(&xns).unwrap(), + rtc_conn, } } @@ -1076,7 +1085,31 @@ impl ActionManager { } } "pwauth" => { - // todo + if let Some((op_type, rest)) = data.split_once('/') { + match op_type { + "pass" => { + if let Some(time_pos) = rest.rfind("?time=") { + let url = &rest[..time_pos]; + let time_str = &rest[time_pos + 6..]; + self.set_time(time_str); + log::info!("URL: {}", url); + // now try to lookup the password; if it does not exist, offer + // to create a password + + // TODO: left off here + } + } + "new" => { + if let Some(pass_pos) = rest.find("?pass=") { + let url = &rest[..pass_pos]; + let password = &rest[pass_pos + 6..]; + log::info!("URL: {}", url); + log::info!("Password: {}", password); + } + } + _ => log::error!("Unknown pwauth operation: {}", op_type), + } + } } "time" => { // todo @@ -1100,6 +1133,41 @@ impl ActionManager { } } + pub(crate) fn set_time(&self, time_str: &str) { + match DateTime::parse_from_rfc3339(time_str) { + Ok(datetime) => { + let utc_time = datetime.with_timezone(&Utc); + log::info!("Time (UTC): {}", utc_time); + let since_epoch_ms = utc_time.timestamp_millis(); + xous::send_message( + self.rtc_conn, + xous::Message::new_scalar( + TimeOp::SetUtcTimeMs.to_usize().unwrap(), + ((since_epoch_ms >> 32) & 0xFFFF_FFFF) as usize, + (since_epoch_ms & 0xFFFF_FFFF) as usize, + 0, + 0, + ), + ) + .ok(); + let offset = datetime.offset(); + let offset_ms = (offset.local_minus_utc() as i64) * 1000; + xous::send_message( + self.rtc_conn, + xous::Message::new_scalar( + TimeOp::SetTzOffsetMs.to_usize().unwrap(), + (((offset_ms as u64) >> 32) & 0xFFFF_FFFF) as usize, + (offset_ms & 0xFFFF_FFFF) as usize, + 0, + 0, + ), + ) + .ok(); + } + Err(e) => log::error!("Failed to parse time: {}", e), + } + } + /// This is just a placeholder function - needs to be upgraded to consider prompting the user for /// a PIN value, etc. pub(crate) fn get_pin_key(&self) -> [u8; 32] { diff --git a/apps-baosec/vault2/src/main.rs b/apps-baosec/vault2/src/main.rs index 4059fa290..6c74cc0c6 100644 --- a/apps-baosec/vault2/src/main.rs +++ b/apps-baosec/vault2/src/main.rs @@ -411,7 +411,7 @@ fn main() -> ! { } Some(VaultOp::KeyPress) => xous::msg_scalar_unpack!(msg, k1, _k2, _k3, _k4, { let k = char::from_u32(k1 as u32).unwrap_or('\u{0000}'); - log::info!("key {}", k); + log::debug!("key {}", k); if menu_active { menu_mgr.key_press(k); } else {