From 8965c6c8fb2d3879dcb84ec9efdd2af8899947c0 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Tue, 8 Dec 2020 20:45:27 +0100 Subject: [PATCH] Rename and use HARDWARE_FAILURE error --- src/ctap/status_code.rs | 13 +++---------- src/ctap/storage.rs | 28 +++++++++++++--------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/ctap/status_code.rs b/src/ctap/status_code.rs index 638caef..097d7ec 100644 --- a/src/ctap/status_code.rs +++ b/src/ctap/status_code.rs @@ -81,17 +81,10 @@ pub enum Ctap2StatusCode { /// This type of error is unexpected and the current state is undefined. CTAP2_ERR_VENDOR_INTERNAL_ERROR = 0xF2, - /// The persistent storage invariant is broken. + /// The hardware is malfunctioning. /// - /// There can be multiple reasons: - /// - The persistent storage has not been erased before its first usage. - /// - The persistent storage has been tempered with by a third party. - /// - The flash is malfunctioning (including the Tock driver). - /// - /// In the first 2 cases the persistent storage should be completely erased. If the error - /// reproduces, it may indicate a software bug or a hardware deficiency. In both cases, the - /// error should be reported. - CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE = 0xF3, + /// It may be possible that some of those errors are actually internal errors. + CTAP2_ERR_VENDOR_HARDWARE_FAILURE = 0xF3, CTAP2_ERR_VENDOR_LAST = 0xFF, } diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index 40ec89a..0660b6c 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -216,7 +216,7 @@ impl PersistentStore { && credential.user_handle == new_credential.user_handle { if old_key.is_some() { - return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE); + return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); } old_key = Some(key); } @@ -231,7 +231,7 @@ impl PersistentStore { None => key::CREDENTIALS .take(MAX_SUPPORTED_RESIDENTIAL_KEYS) .find(|key| !keys.contains(key)) - .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE)?, + .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?, // This is an existing credential being updated, we reuse its key. Some(x) => x, }; @@ -298,7 +298,7 @@ impl PersistentStore { match self.store.find(key::GLOBAL_SIGNATURE_COUNTER)? { None => Ok(INITIAL_SIGNATURE_COUNTER), Some(value) if value.len() == 4 => Ok(u32::from_ne_bytes(*array_ref!(&value, 0, 4))), - Some(_) => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE), + Some(_) => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), } } @@ -317,9 +317,9 @@ impl PersistentStore { let master_keys = self .store .find(key::MASTER_KEYS)? - .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE)?; + .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?; if master_keys.len() != 64 { - return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE); + return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); } Ok(MasterKeys { encryption: *array_ref![master_keys, 0, 32], @@ -334,7 +334,7 @@ impl PersistentStore { Some(pin_hash) => pin_hash, }; if pin_hash.len() != PIN_AUTH_LENGTH { - return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE); + return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); } Ok(Some(*array_ref![pin_hash, 0, PIN_AUTH_LENGTH])) } @@ -354,7 +354,7 @@ impl PersistentStore { match self.store.find(key::PIN_RETRIES)? { None => Ok(MAX_PIN_RETRIES), Some(value) if value.len() == 1 => Ok(value[0]), - _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE), + _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), } } @@ -379,7 +379,7 @@ impl PersistentStore { match self.store.find(key::MIN_PIN_LENGTH)? { None => Ok(DEFAULT_MIN_PIN_LENGTH), Some(value) if value.len() == 1 => Ok(value[0]), - _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE), + _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), } } @@ -437,7 +437,7 @@ impl PersistentStore { key_material::ATTESTATION_PRIVATE_KEY_LENGTH ])) } - Some(_) => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE), + Some(_) => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), } } @@ -481,9 +481,9 @@ impl PersistentStore { let aaguid = self .store .find(key::AAGUID)? - .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE)?; + .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?; if aaguid.len() != key_material::AAGUID_LENGTH { - return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE); + return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); } Ok(*array_ref![aaguid, 0, key_material::AAGUID_LENGTH]) } @@ -521,9 +521,7 @@ impl From for Ctap2StatusCode { StoreError::InvalidArgument => Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR, // This error is not expected. The storage has been tempered with. We could erase the // storage. - StoreError::InvalidStorage => { - Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE - } + StoreError::InvalidStorage => Ctap2StatusCode::CTAP2_ERR_VENDOR_HARDWARE_FAILURE, // This error is not expected. The kernel is failing our syscalls. StoreError::StorageError => Ctap2StatusCode::CTAP1_ERR_OTHER, } @@ -566,7 +564,7 @@ impl<'a> IterCredentials<'a> { /// instead of statements only. fn unwrap(&mut self, x: Option) -> Option { if x.is_none() { - *self.result = Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE); + *self.result = Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); } x }