Skip to content

Commit

Permalink
Merge pull request trussed-dev#3 from Nitrokey/skip-up-timeout
Browse files Browse the repository at this point in the history
Skip user presence check directly after boot
  • Loading branch information
robin-nitrokey authored Aug 3, 2022
2 parents fc6d866 + 3a33294 commit b0408cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/ctap1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ impl<UP: UserPresence, T: TrussedRequirements> Authenticator for crate::Authenti
};
}
ControlByte::EnforceUserPresenceAndSign => {
self.up
.user_present(&mut self.trussed, constants::U2F_UP_TIMEOUT)
.map_err(|_| Error::ConditionsOfUseNotSatisfied)?;
if !self.skip_up_check() {
self.up
.user_present(&mut self.trussed, constants::U2F_UP_TIMEOUT)
.map_err(|_| Error::ConditionsOfUseNotSatisfied)?;
}
0x01
}
ControlByte::DontEnforceUserPresenceAndSign => 0x00,
Expand Down
8 changes: 5 additions & 3 deletions src/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,11 @@ impl<UP: UserPresence, T: TrussedRequirements> Authenticator for crate::Authenti

// 7. collect user presence
let up_performed = if do_up {
info_now!("asking for up");
self.up
.user_present(&mut self.trussed, constants::FIDO2_UP_TIMEOUT)?;
if !self.skip_up_check() {
info_now!("asking for up");
self.up
.user_present(&mut self.trussed, constants::FIDO2_UP_TIMEOUT)?;
}
true
} else {
info_now!("not asking for up");
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
extern crate delog;
generate_macros!();

use core::time::Duration;

use trussed::{client, syscall, types::Message, Client as TrussedClient};

use ctap_types::heapless_bytes::Bytes;
Expand Down Expand Up @@ -71,6 +73,9 @@ pub struct Config {
pub max_msg_size: usize,
// pub max_creds_in_list: usize,
// pub max_cred_id_length: usize,
/// If set, the first Get Assertion or Authenticate request within the specified time after
/// boot is accepted without additional user presence verification.
pub skip_up_timeout: Option<Duration>,
}

// impl Default for Config {
Expand Down Expand Up @@ -229,6 +234,19 @@ where
let hash = syscall!(self.trussed.hash_sha256(data)).hash;
hash.to_bytes().expect("hash should fit")
}

fn skip_up_check(&mut self) -> bool {
// If enabled in the configuration, we don't require an additional user presence
// verification for a certain duration after boot.
if let Some(timeout) = self.config.skip_up_timeout.take() {
let uptime = syscall!(self.trussed.uptime()).uptime;
if uptime < timeout {
info_now!("skip up check directly after boot");
return true;
}
}
false
}
}

#[cfg(test)]
Expand Down

0 comments on commit b0408cb

Please sign in to comment.