diff --git a/apps/vault/locales/i18n.json b/apps/vault/locales/i18n.json index 32c16be67..822d994d3 100644 --- a/apps/vault/locales/i18n.json +++ b/apps/vault/locales/i18n.json @@ -1,4 +1,40 @@ { + "vault.fido.countdown": { + "en": "s until abort", + "ja": "秒 中止するまで", + "zh": "秒 直到中止", + "en-tts": "s until abort" + }, + "vault.fido.make_credential": { + "en": "FIDO Make Credential Request.\nPress any key to approve.", + "ja": "FIDOは資格情報を要求します\n承認するには任意のキーを押してください", + "zh": "FIDO 提出凭证请求\n按任意键批准", + "en-tts": "FIDO Make Credential Request. Press any key to approve." + }, + "vault.fido.exclude_list": { + "en": "FIDO server is excluding existing credentials.\nPress any key to acknowledge.", + "ja": "FIDOサーバーは既存のクレデンシャルを除外しています。\n任意のキーを押して確認します。", + "zh": "FIDO 服务器正在排除现有凭据。\n按任意键确认。", + "en-tts": "FIDO server is excluding existing credentials.\nPress any key to acknowledge." + }, + "vault.u2f.reset_check": { + "en": "Please re-confirm the reset by pressing any key.", + "ja": "いずれかのキーを押して、リセットを再確認してください。", + "zh": "请按任意键重新确认复位。", + "en-tts": "Please re-confirm the reset by pressing any key." + }, + "vault.u2f.vendor_configure": { + "en": "Press any key to allow vendor configuration.", + "ja": "ベンダー設定を許可するには、任意のキーを押します。", + "zh": "按任意键允许供应商配置。", + "en-tts": "Press any key to allow vendor configuration." + }, + "vault.u2f.authenticator_selection": { + "en": "Press any key to make this the primary authenticator.", + "ja": "いずれかのキーを押して、これをプライマリオーセンティケーターにします。", + "zh": "按任意键使其成为主要身份验证器。", + "en-tts": "Press any key to make this the primary authenticator." + }, "vault.u2f.factoryreset": { "en": "Host has requested a factory reset of FIDO/U2F credentials.\n\nThis will permanently erase all registrations!!\n\nPress 'y' to allow, any other key to abort.", "ja": "ホストがFIDO/U2Fクレデンシャルの工場出荷時のリセットを要求しました。 これにより、すべての登録が完全に消去されます。\n「y」を押して許可します。他のキーを中止しますか?", diff --git a/apps/vault/src/ctap/command.rs b/apps/vault/src/ctap/command.rs index 3c71fb381..1a4ee6702 100644 --- a/apps/vault/src/ctap/command.rs +++ b/apps/vault/src/ctap/command.rs @@ -33,7 +33,8 @@ use core::convert::TryFrom; pub const MAX_CREDENTIAL_COUNT_IN_LIST: Option = None; // CTAP specification (version 20190130) section 6.1 -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub enum Command { AuthenticatorMakeCredential(AuthenticatorMakeCredentialParameters), AuthenticatorGetAssertion(AuthenticatorGetAssertionParameters), @@ -127,7 +128,8 @@ impl Command { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct AuthenticatorMakeCredentialParameters { pub client_data_hash: Vec, pub rp: PublicKeyCredentialRpEntity, @@ -212,7 +214,8 @@ impl TryFrom for AuthenticatorMakeCredentialParameters { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct AuthenticatorGetAssertionParameters { pub rp_id: String, pub client_data_hash: Vec, @@ -284,7 +287,8 @@ impl TryFrom for AuthenticatorGetAssertionParameters { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct AuthenticatorClientPinParameters { pub pin_protocol: u64, pub sub_command: ClientPinSubCommand, @@ -385,7 +389,8 @@ impl TryFrom for AuthenticatorClientPinParameters { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct AuthenticatorAttestationMaterial { pub certificate: Vec, pub private_key: [u8; key_material::ATTESTATION_PRIVATE_KEY_LENGTH], @@ -414,7 +419,8 @@ impl TryFrom for AuthenticatorAttestationMaterial { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct AuthenticatorVendorConfigureParameters { pub lockdown: bool, pub attestation_material: Option, diff --git a/apps/vault/src/ctap/ctap1.rs b/apps/vault/src/ctap/ctap1.rs index e0ba282ad..29be1434d 100644 --- a/apps/vault/src/ctap/ctap1.rs +++ b/apps/vault/src/ctap/ctap1.rs @@ -30,8 +30,8 @@ pub type Ctap1StatusCode = ApduStatusCode; // The specification referenced in this file is at: // https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.pdf -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug))] -#[derive(PartialEq)] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone))] +#[derive(PartialEq, Debug)] pub enum Ctap1Flags { CheckOnly = 0x07, EnforceUpAndSign = 0x03, @@ -57,7 +57,8 @@ impl Into for Ctap1Flags { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] // TODO: remove #allow when https://github.com/rust-lang/rust/issues/64362 is fixed enum U2fCommand { #[allow(dead_code)] diff --git a/apps/vault/src/ctap/data_formats.rs b/apps/vault/src/ctap/data_formats.rs index 547d37b7e..9e1ea7d3b 100644 --- a/apps/vault/src/ctap/data_formats.rs +++ b/apps/vault/src/ctap/data_formats.rs @@ -24,7 +24,8 @@ use ctap_crypto::{ecdh, ecdsa}; use enum_iterator::IntoEnumIterator; // https://www.w3.org/TR/webauthn/#dictdef-publickeycredentialrpentity -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct PublicKeyCredentialRpEntity { pub rp_id: String, pub rp_name: Option, @@ -56,7 +57,8 @@ impl TryFrom for PublicKeyCredentialRpEntity { } // https://www.w3.org/TR/webauthn/#dictdef-publickeycredentialuserentity -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] +#[derive(Debug)] pub struct PublicKeyCredentialUserEntity { pub user_id: Vec, pub user_name: Option, @@ -139,6 +141,7 @@ impl TryFrom for PublicKeyCredentialType { // https://www.w3.org/TR/webauthn/#dictdef-publickeycredentialparameters #[derive(PartialEq)] #[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +#[derive(Debug)] pub struct PublicKeyCredentialParameter { pub cred_type: PublicKeyCredentialType, pub alg: SignatureAlgorithm, @@ -171,8 +174,9 @@ impl From for cbor::Value { } // https://www.w3.org/TR/webauthn/#enumdef-authenticatortransport -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] #[cfg_attr(test, derive(IntoEnumIterator))] +#[derive(Debug)] pub enum AuthenticatorTransport { Usb, Nfc, @@ -208,7 +212,8 @@ impl TryFrom for AuthenticatorTransport { } // https://www.w3.org/TR/webauthn/#dictdef-publickeycredentialdescriptor -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] +#[derive(Debug)] pub struct PublicKeyCredentialDescriptor { pub key_type: PublicKeyCredentialType, pub key_id: Vec, @@ -259,7 +264,8 @@ impl From for cbor::Value { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] +#[derive(Debug)] pub struct MakeCredentialExtensions { pub hmac_secret: bool, pub cred_protect: Option, @@ -287,7 +293,8 @@ impl TryFrom for MakeCredentialExtensions { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] +#[derive(Debug)] pub struct GetAssertionExtensions { pub hmac_secret: Option, } @@ -310,7 +317,8 @@ impl TryFrom for GetAssertionExtensions { } #[derive(Clone)] -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct GetAssertionHmacSecretInput { pub key_agreement: CoseKey, pub salt_enc: Vec, @@ -341,7 +349,8 @@ impl TryFrom for GetAssertionHmacSecretInput { } // Even though options are optional, we can use the default if not present. -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct MakeCredentialOptions { pub rk: bool, pub uv: bool, @@ -374,7 +383,8 @@ impl TryFrom for MakeCredentialOptions { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct GetAssertionOptions { pub up: bool, pub uv: bool, @@ -430,8 +440,7 @@ impl From for cbor::Value { } } -#[derive(PartialEq)] -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +#[derive(PartialEq, Debug)] pub enum SignatureAlgorithm { ES256 = ecdsa::PubKey::ES256_ALGORITHM as isize, // This is the default for all numbers not covered above. @@ -637,7 +646,8 @@ impl PublicKeyCredentialSource { // It depends on the algorithm though, I think. // So before creating a mess, this is my workaround. #[derive(Clone)] -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(PartialEq))] +#[derive(Debug)] pub struct CoseKey(pub BTreeMap); // This is the algorithm specifier that is supposed to be used in a COSE key @@ -715,8 +725,9 @@ impl TryFrom for ecdh::PubKey { } } -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, Debug, PartialEq))] +#[cfg_attr(any(test, feature = "debug_ctap"), derive(Clone, PartialEq))] #[cfg_attr(test, derive(IntoEnumIterator))] +#[derive(Debug)] pub enum ClientPinSubCommand { GetPinRetries = 0x01, GetKeyAgreement = 0x02, diff --git a/apps/vault/src/ctap/hid/mod.rs b/apps/vault/src/ctap/hid/mod.rs index f0858ec9a..520eac44d 100644 --- a/apps/vault/src/ctap/hid/mod.rs +++ b/apps/vault/src/ctap/hid/mod.rs @@ -201,7 +201,7 @@ impl CtapHid { } // CTAP specification (version 20190130) section 8.1.9.1.2 CtapHid::COMMAND_CBOR => { - log::debug!("COMMAND_CBOR"); + log::trace!("COMMAND_CBOR"); // CTAP specification (version 20190130) section 8.1.5.1 // Each transaction is atomic, so we process the command directly here and // don't handle any other packet in the meantime. diff --git a/apps/vault/src/ctap/mod.rs b/apps/vault/src/ctap/mod.rs index 7460e402f..58bab96ef 100644 --- a/apps/vault/src/ctap/mod.rs +++ b/apps/vault/src/ctap/mod.rs @@ -68,6 +68,7 @@ use ctap_crypto::Hash256; #[cfg(feature = "debug_ctap")] use libtock_drivers::console::Console; use crate::shims::{ClockValue, Duration}; +use locales::t; // This flag enables or disables basic attestation for FIDO2. U2F is unaffected by // this setting. The basic attestation uses the signing key from key_material.rs @@ -161,7 +162,7 @@ pub struct CtapState<'a, R: Rng256, CheckUserPresence: Fn(ChannelID) -> Result<( rng: &'a mut R, // A function to check user presence, ultimately returning true if user presence was detected, // false otherwise. - check_user_presence: CheckUserPresence, + _check_user_presence: CheckUserPresence, persistent_store: PersistentStore, pin_protocol_v1: PinProtocolV1, #[cfg(feature = "with_ctap1")] @@ -180,14 +181,14 @@ where pub fn new( rng: &'a mut R, - check_user_presence: CheckUserPresence, + _check_user_presence: CheckUserPresence, now: ClockValue, ) -> CtapState<'a, R, CheckUserPresence> { let persistent_store = PersistentStore::new(rng); let pin_protocol_v1 = PinProtocolV1::new(rng); CtapState { rng, - check_user_presence, + _check_user_presence, persistent_store, pin_protocol_v1, #[cfg(feature = "with_ctap1")] @@ -199,11 +200,11 @@ where stateful_command_type: Some(StatefulCommand::Reset), } } - + #[allow(dead_code)] // Tock Legacy pub fn update_command_permission(&mut self, now: ClockValue) { self.stateful_command_permission = self.stateful_command_permission.check_expiration(now); } - + #[allow(dead_code)] // Tock Legacy fn check_command_permission(&mut self, now: ClockValue) -> Result<(), Ctap2StatusCode> { self.update_command_permission(now); if self.stateful_command_permission.is_granted(now) { @@ -321,6 +322,7 @@ where writeln!(&mut Console::new(), "Received command: {:#?}", cmd).unwrap(); match cmd { Ok(command) => { + log::debug!("{:?}", command); // Correct behavior between CTAP1 and CTAP2 isn't defined yet. Just a guess. #[cfg(feature = "with_ctap1")] { @@ -394,7 +396,10 @@ where if let Some(auth_param) = &pin_uv_auth_param { // This case was added in FIDO 2.1. if auth_param.is_empty() { - (self.check_user_presence)(cid)?; + //(self.check_user_presence)(cid)?; + if crate::ux::request_permission_blocking("pin_uv_auth_precheck".to_string(), cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } if self.persistent_store.pin_hash()?.is_none() { return Err(Ctap2StatusCode::CTAP2_ERR_PIN_NOT_SET); } else { @@ -464,7 +469,17 @@ where { // Perform this check, so bad actors can't brute force exclude_list // without user interaction. - (self.check_user_presence)(cid)?; + // (self.check_user_presence)(cid)?; + let mut desc = String::from(t!("vault.fido.exclude_list", xous::LANG)); + desc.push_str( + &format!("\nRelying Party: {}\nUser name: {}", + if let Some(name) = rp.rp_name {name.to_string()} else {rp_id.to_string()}, + if let Some(name) = user.user_display_name {name} else {user.user_name.unwrap_or("*Unspecified*".to_string())}, + ) + ); + if crate::ux::request_permission_blocking(desc, cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } return Err(Ctap2StatusCode::CTAP2_ERR_CREDENTIAL_EXCLUDED); } } @@ -504,7 +519,19 @@ where } }; - (self.check_user_presence)(cid)?; + //(self.check_user_presence)(cid)?; + let mut make_cred_desc = String::from(t!("vault.fido.make_credential", xous::LANG)); + let alt_name = user.user_name.as_deref().unwrap_or("*Unspecified*"); + make_cred_desc.push_str( + &format!("\nRelying Party: {}\nUser name: {}", + // prefer the "friendly name" over the technical name + if let Some(name) = &rp.rp_name {name.to_string()} else {rp_id.to_string()}, + if let Some(name) = &user.user_display_name {name} else {alt_name} + ) + ); + if crate::ux::request_permission_blocking(make_cred_desc, cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } let sk = ctap_crypto::ecdsa::SecKey::gensk(self.rng); let pk = sk.genpk(); @@ -787,7 +814,10 @@ where // This check comes before CTAP2_ERR_NO_CREDENTIALS in CTAP 2.0. // For CTAP 2.1, it was moved to a later protocol step. if options.up { - (self.check_user_presence)(cid)?; + //(self.check_user_presence)(cid)?; + if crate::ux::request_permission_blocking("process_get_assertion requests user presence".to_string(), cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } } let credential = applicable_credentials @@ -819,9 +849,12 @@ where fn process_get_next_assertion( &mut self, - now: ClockValue, + _now: ClockValue, ) -> Result { - self.check_command_permission(now)?; + //self.check_command_permission(now)?; + if crate::ux::request_permission_blocking("GetAssertion".to_string(), [0xff, 0xff, 0xff, 0xff]).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED); + } let (assertion_input, credential) = if let Some(StatefulCommand::GetAssertion(assertion_state)) = &mut self.stateful_command_type @@ -910,7 +943,10 @@ where Some(StatefulCommand::Reset) => (), _ => return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED), } - (self.check_user_presence)(cid)?; + //(self.check_user_presence)(cid)?; + if crate::ux::request_permission_blocking(t!("vault.u2f.reset_check", xous::LANG).to_string(), cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } self.persistent_store.reset(self.rng)?; self.pin_protocol_v1.reset(self.rng); @@ -926,7 +962,10 @@ where #[cfg(feature = "with_ctap2_1")] fn process_selection(&self, cid: ChannelID) -> Result { - (self.check_user_presence)(cid)?; + //(self.check_user_presence)(cid)?; + if crate::ux::request_permission_blocking(t!("vault.u2f.authenticator_selection", xous::LANG).to_string(), cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } Ok(ResponseData::AuthenticatorSelection) } @@ -935,7 +974,10 @@ where params: AuthenticatorVendorConfigureParameters, cid: ChannelID, ) -> Result { - (self.check_user_presence)(cid)?; + // (self.check_user_presence)(cid)?; + if crate::ux::request_permission_blocking(t!("vault.u2f.vendor_configure", xous::LANG).to_string(), cid).is_none() { + return Err(Ctap2StatusCode::CTAP2_ERR_NOT_ALLOWED) + } // Sanity checks let current_priv_key = self.persistent_store.attestation_private_key()?; diff --git a/apps/vault/src/ctap/pin_protocol_v1.rs b/apps/vault/src/ctap/pin_protocol_v1.rs index 451ac1e53..b225d7cff 100644 --- a/apps/vault/src/ctap/pin_protocol_v1.rs +++ b/apps/vault/src/ctap/pin_protocol_v1.rs @@ -496,7 +496,7 @@ impl PinProtocolV1 { #[cfg(feature = "with_ctap2_1")] return Err(Ctap2StatusCode::CTAP1_ERR_INVALID_PARAMETER); } - + log::info!("{:?}", sub_command); let response = match sub_command { ClientPinSubCommand::GetPinRetries => { Some(self.process_get_pin_retries(persistent_store)?) diff --git a/apps/vault/src/ctap/storage.rs b/apps/vault/src/ctap/storage.rs index 47ecf6c31..4b57c3281 100644 --- a/apps/vault/src/ctap/storage.rs +++ b/apps/vault/src/ctap/storage.rs @@ -608,8 +608,18 @@ openssl asn1parse -in opensk_cert.pem -inform pem Ok(mut ph) => { let mut pin_hash = [0u8; PIN_AUTH_LENGTH]; match ph.read(&mut pin_hash) { - Ok(PIN_AUTH_LENGTH) => Ok(Some(pin_hash)), - _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), + Ok(PIN_AUTH_LENGTH) => { + log::info!("pin_hash: {:x?}", &pin_hash); + Ok(Some(pin_hash)) + }, + Ok(l) => { + log::error!("pin_hash read length incorrect: {}", l); + Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + } + Err(e) => { + log::error!("pin_hash returned an error: {:?}", e); + Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + }, } } Err(e) => match e.kind() { @@ -635,8 +645,14 @@ openssl asn1parse -in opensk_cert.pem -inform pem Ok(mut ph) => { match ph.write(pin_hash) { Ok(PIN_AUTH_LENGTH) => Ok(()), - // note that this also throws errors on all write return results that are the wrong length! - _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + Ok(l) => { + log::error!("set_pin_hash incorrect length: {}", l); + Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + } + Err(e) => { + log::error!("set_pin_hash write error: {:?}", e); + Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + } } } _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) @@ -947,6 +963,13 @@ openssl asn1parse -in opensk_cert.pem -inform pem } Ok(_) => Ok(()), }?; + match self.pddb.borrow().delete_dict(crate::ux::U2F_APP_DICT, None) { + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => Ok(()), + _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error + } + Ok(_) => Ok(()), + }?; // don't delete the persistent dictionary... self.init()?; Ok(()) diff --git a/apps/vault/src/ctap/timed_permission.rs b/apps/vault/src/ctap/timed_permission.rs index 9a45a21b3..f937fcbc0 100644 --- a/apps/vault/src/ctap/timed_permission.rs +++ b/apps/vault/src/ctap/timed_permission.rs @@ -30,6 +30,7 @@ impl TimedPermission { } // Checks if the timeout is not reached, false for differing ClockValue frequencies. + #[allow(dead_code)] // Tock legacy pub fn is_granted(&self, now: ClockValue) -> bool { if let TimedPermission::Granted(timeout) = self { log::info!("is_granted timeout: {}, now {}", timeout.ms(), now.ms()); @@ -42,6 +43,7 @@ impl TimedPermission { // Consumes the state and returns the current new permission state at time "now". // Returns a new state for differing ClockValue frequencies. + #[allow(dead_code)] // Tock legacy pub fn check_expiration(self, now: ClockValue) -> TimedPermission { if let TimedPermission::Granted(timeout) = self { log::info!("check_expiration timeout: {}, now {}", timeout.ms(), now.ms()); diff --git a/apps/vault/src/ux.rs b/apps/vault/src/ux.rs index a49f7fe19..d5df17b60 100644 --- a/apps/vault/src/ux.rs +++ b/apps/vault/src/ux.rs @@ -10,7 +10,7 @@ use std::io::{Write, Read}; use chrono::{Utc, DateTime, NaiveDateTime}; use std::time::{SystemTime, UNIX_EPOCH}; -const U2F_APP_DICT: &'static str = "fido.u2fapps"; +pub(crate) const U2F_APP_DICT: &'static str = "fido.u2fapps"; #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] pub(crate) struct FidoRequest { @@ -33,6 +33,7 @@ pub(crate) enum UxOp { U2fAppUx, Quit } +#[allow(dead_code)] // presence_timeout is not used right now, but might be needed in the future if I am not understanding the spec correctly... struct Timeouts { /// how long after an interaction has happened that the interaction may still be deemed valid and "consumed" pub presence_timeout_ms: i64, @@ -40,6 +41,7 @@ struct Timeouts { pub prompt_timeout_ms: i64, } #[derive(Eq, PartialEq, Debug)] +#[allow(dead_code)] enum UxState { Idle, Prompt(i64), @@ -98,7 +100,7 @@ fn request_permission_inner(reason: String, channel_id: [u8; 4], blocking: bool, } const DEFAULT_PRESENCE_TIMEOUT_MS: i64 = 30_000; -const DEFAULT_PROMPT_TIMEOUT_MS: i64 = 10_000; +const DEFAULT_PROMPT_TIMEOUT_MS: i64 = 30_000; const POLLED_PROMPT_TIMEOUT_MS: i64 = 1000; // how long the screen stays up after the host "gives up" polling const KEEPALIVE_MS: usize = 100; pub(crate) fn start_ux_thread() { @@ -303,7 +305,7 @@ pub(crate) fn start_ux_thread() { t!("vault.u2f.appinfo.authcount", xous::LANG), info.count, )); - } else { + } else if !deferred { // no record of the app. Just give the hash. request_str.push_str(&format!("\n{}{}", t!("vault.u2f.newapphash", xous::LANG), @@ -311,12 +313,12 @@ pub(crate) fn start_ux_thread() { )) } if deferred { - last_timer = 1 + (prompt_expiration_ms - tt.elapsed_ms() as i64) / 1000; + last_timer = 1 + (prompt_expiration_ms - tt.elapsed_ms() as i64 - 1) / 1000; request_str.push_str( - &format!("{}\n\n{}s remaining", - &request_str_base, - last_timer) - ); + &format!("\n\n⚠ {}{} ⚠", + last_timer, + t!("vault.fido.countdown", xous::LANG) + )); } modals.dynamic_notification( Some(t!("vault.u2freq", xous::LANG)), @@ -386,12 +388,13 @@ pub(crate) fn start_ux_thread() { log::info!("new_timer: {}", new_timer); let mut request_str = String::from(&request_str_base); request_str.push_str( - &format!("{}\n\n{}s remaining", + &format!("{}\n\n⚠ {}{} ⚠", &request_str_base, - new_timer) - ); + new_timer, + t!("vault.fido.countdown", xous::LANG) + )); modals.dynamic_notification_update( - Some(t!("vault.u2freq", xous::LANG)), + None, Some(&request_str), ).unwrap(); last_timer = new_timer; @@ -407,7 +410,12 @@ pub(crate) fn start_ux_thread() { log::info!("returning {:?}", fido_request.granted); buffer.replace(fido_request).unwrap(); } - ux_state = UxState::Present(tt.elapsed_ms() as i64 + timeouts.presence_timeout_ms); + + // this is used only if we want presence to persist after the touch + //ux_state = UxState::Present(tt.elapsed_ms() as i64 + timeouts.presence_timeout_ms); + // this will take us straight back to Idle after a touch + ux_state = UxState::Idle; + modals.dynamic_notification_close().unwrap(); send_message(self_cid, Message::new_scalar(UxOp::Pump.to_usize().unwrap(), KEEPALIVE_MS, 0, 0, 0)