Skip to content

Commit

Permalink
Rename and use HARDWARE_FAILURE error
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Dec 8, 2020
1 parent c5007e3 commit 8965c6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
13 changes: 3 additions & 10 deletions src/ctap/status_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
28 changes: 13 additions & 15 deletions src/ctap/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
};
Expand Down Expand Up @@ -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),
}
}

Expand All @@ -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],
Expand All @@ -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]))
}
Expand All @@ -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),
}
}

Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -521,9 +521,7 @@ impl From<persistent_store::StoreError> 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,
}
Expand Down Expand Up @@ -566,7 +564,7 @@ impl<'a> IterCredentials<'a> {
/// instead of statements only.
fn unwrap<T>(&mut self, x: Option<T>) -> Option<T> {
if x.is_none() {
*self.result = Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INVALID_PERSISTENT_STORAGE);
*self.result = Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR);
}
x
}
Expand Down

0 comments on commit 8965c6c

Please sign in to comment.