Skip to content

Commit 016e81c

Browse files
authored
Fixes the error code for blocked UV (#755)
* Fixes the error code for blocked UV First, with an answer on the specification question, we change the comment on the error code being a potential typo: fido-alliance/fido-2-specs#1672 Also, I realized that the default was wrong before, so now the error code with `*_UV_*` is used for UV operations as intended. * Code style suggestion fix * Fixes documentation with private repo links
1 parent ec4c03d commit 016e81c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

libraries/opensk/src/ctap/fingerprint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn perform_built_in_uv<E: Env>(
138138
internal_retry: bool,
139139
) -> CtapResult<()> {
140140
if storage::uv_retries(env)? == 0 {
141-
return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED);
141+
return Err(Ctap2StatusCode::CTAP2_ERR_UV_BLOCKED);
142142
}
143143
env.fingerprint().check_fingerprint_init()?;
144144
let result = check_fingerprint_loop(env, channel, internal_retry);
@@ -180,7 +180,7 @@ fn check_fingerprint_loop<E: Env>(
180180
FingerprintCheckError::NoMatch | FingerprintCheckError::Other => {
181181
storage::decr_uv_retries(env)?;
182182
if storage::uv_retries(env)? == 0 {
183-
return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED);
183+
return Err(Ctap2StatusCode::CTAP2_ERR_UV_BLOCKED);
184184
}
185185
retries -= 1;
186186
if retries == 0 {
@@ -345,7 +345,7 @@ pub fn process_bio_enrollment<E: Env>(
345345
enrollment_status: &mut EnrollmentStatus,
346346
) -> CtapResult<ResponseData> {
347347
// Enforcing modaility is not explicitly mentioned in the specification.
348-
// https://github.com/fido-alliance/fido-2-specs/issues/1673
348+
// https://github.com/fido-alliance/fido-2-specs/issues/1673 (private)
349349
// Let's be strict until we know which is correct.
350350
if params.sub_command.is_some() {
351351
let modality = ok_or_missing(params.modality)?;
@@ -446,7 +446,7 @@ mod test {
446446
{
447447
assert_eq!(
448448
perform_built_in_uv(&mut env, DUMMY_CHANNEL, true),
449-
Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED)
449+
Err(Ctap2StatusCode::CTAP2_ERR_UV_BLOCKED)
450450
);
451451
} else {
452452
assert_eq!(

libraries/opensk/src/ctap/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ fn truncate_to_char_boundary(s: &str, mut max: usize) -> &str {
263263
}
264264
}
265265

266+
// For MakeCredential and GetAssertion, the specification says:
267+
// If the uvRetries counter is 0, return CTAP2_ERR_PIN_BLOCKED. See:
268+
// https://github.com/fido-alliance/fido-2-specs/issues/1672 (private)
269+
#[cfg(feature = "fingerprint")]
270+
fn map_uv_block_error(result: CtapResult<()>) -> CtapResult<()> {
271+
result.map_err(|e| match e {
272+
Ctap2StatusCode::CTAP2_ERR_UV_BLOCKED => Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED,
273+
other => other,
274+
})
275+
}
276+
266277
/// Send non-critical packets using fire-and-forget.
267278
pub fn send_packets<E: Env>(
268279
env: &mut E,
@@ -845,12 +856,8 @@ impl<E: Env> CtapState<E> {
845856
if options.uv {
846857
#[cfg(not(feature = "fingerprint"))]
847858
return Err(Ctap2StatusCode::CTAP2_ERR_INVALID_OPTION);
848-
// The specification says:
849-
// If the uvRetries counter is 0, return CTAP2_ERR_PIN_BLOCKED.
850-
// But I assume this is a typo and should be UV_BLOCKED instead.
851-
// https://github.com/fido-alliance/fido-2-specs/issues/1672
852859
#[cfg(feature = "fingerprint")]
853-
perform_built_in_uv(env, channel, true)?;
860+
map_uv_block_error(perform_built_in_uv(env, channel, true))?;
854861
#[cfg(feature = "fingerprint")]
855862
UV_FLAG
856863
} else {
@@ -1226,10 +1233,8 @@ impl<E: Env> CtapState<E> {
12261233
if options.uv {
12271234
#[cfg(not(feature = "fingerprint"))]
12281235
return Err(Ctap2StatusCode::CTAP2_ERR_INVALID_OPTION);
1229-
// Same error code ambiguity as in MakeCredential.
1230-
// https://github.com/fido-alliance/fido-2-specs/issues/1672
12311236
#[cfg(feature = "fingerprint")]
1232-
perform_built_in_uv(env, channel, true)?;
1237+
map_uv_block_error(perform_built_in_uv(env, channel, true))?;
12331238
#[cfg(feature = "fingerprint")]
12341239
UV_FLAG
12351240
} else {

0 commit comments

Comments
 (0)