Skip to content

Commit 92f2120

Browse files
authored
Changes the Env API to late choice of template ID (#746)
* Changes the Env API to late choice of template ID Before, a fingerprint sensor had to choose a template ID at the start of the enrollment process. Not all sensors assign one immediately, and it conceptually makes more sense to expect an ID after a successful enrollment. We introduce a state that tracks whether - The fingerprint sensor chose a template ID already, - and we sent a random template ID over CTAP until then. We also add tests for the introduced state. Since the command is not considered stateful by CTAP, it means that enrollment can interleave with other CTAP commands. And the state is not part of `StatefulCommand`. * Fixes incorrect documentation
1 parent 3c7384c commit 92f2120

File tree

6 files changed

+377
-77
lines changed

6 files changed

+377
-77
lines changed

libraries/opensk/src/api/fingerprint.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ impl From<Ctap2EnrollFeedback> for cbor::Value {
4545

4646
pub trait Fingerprint {
4747
/// Starts the fingerprint enrollment process.
48-
///
49-
/// Returns the newly assigned template ID.
50-
fn prepare_enrollment(&mut self) -> CtapResult<Vec<u8>>;
48+
fn prepare_enrollment(&mut self) -> CtapResult<()>;
5149

5250
/// Captures a fingerprint image.
5351
///
@@ -56,14 +54,22 @@ pub trait Fingerprint {
5654
/// `prepare_enrollment` must be called first.
5755
/// A returned `Ctap2StatusCode` indicates an unexpected failure processing
5856
/// the command.
59-
/// The `Ctap2EnrollFeedback` contains expected errors from the fingerprint
60-
/// capture process.
61-
/// Also returns the expected number of remaining samples.
57+
///
58+
/// This function returns:
59+
/// - The `Ctap2EnrollFeedback` contains expected errors from the
60+
/// fingerprint capture process.
61+
/// - The expected number of remaining samples.
62+
/// If the sensor finished template creation, return a hardware ID for this
63+
/// template. This ID is different from the FIDO template ID, but they are
64+
/// mapped to each other in OpenSK. This should happen exactly when the
65+
/// returned number of `remainingSamples` is 0.
66+
///
67+
/// There is always only one fingerprint enrollment in progress, and the
68+
/// capture implicitly refers to that.
6269
fn capture_sample(
6370
&mut self,
64-
template_id: &[u8],
6571
timeout_ms: Option<usize>,
66-
) -> CtapResult<(Ctap2EnrollFeedback, usize)>;
72+
) -> CtapResult<(Ctap2EnrollFeedback, usize, Option<Vec<u8>>)>;
6773

6874
/// Cancel a fingerprint enrollment.
6975
fn cancel_enrollment(&mut self) -> CtapResult<()>;

libraries/opensk/src/ctap/client_pin.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,6 @@ mod test {
700700
use super::super::pin_protocol::authenticate_pin_uv_auth_token;
701701
use super::*;
702702
use crate::api::crypto::HASH_SIZE;
703-
#[cfg(feature = "fingerprint")]
704-
use crate::api::fingerprint::Fingerprint;
705703
use crate::env::test::TestEnv;
706704
use crate::env::EcdhSk;
707705
use alloc::vec;
@@ -1181,8 +1179,7 @@ mod test {
11811179
.unwrap();
11821180
let mut env = TestEnv::default();
11831181
set_standard_pin(&mut env);
1184-
let template_id = env.fingerprint().prepare_enrollment().unwrap();
1185-
let _ = env.fingerprint().capture_sample(&template_id, Some(30_000));
1182+
assert!(env.create_fingerprint().is_ok());
11861183

11871184
let response = client_pin
11881185
.process_command(&mut env, params.clone(), DUMMY_CHANNEL)

0 commit comments

Comments
 (0)