summaryrefslogtreecommitdiff
path: root/keystore2/src/raw_device.rs
diff options
context:
space:
mode:
authorShaquille Johnson <ssjohnson@google.com>2022-09-19 12:39:01 +0000
committerShaquille Johnson <ssjohnson@google.com>2022-10-18 15:08:41 +0000
commit9da2e1cd3d5dd683766547c27735472afc327be2 (patch)
treeaed0b0e230dbf8e9b0c2d0fb7a8bf8e25eaaeb83 /keystore2/src/raw_device.rs
parentd45bc5b0bd5dc0e8990301ce4825e50d3d722484 (diff)
downloadsecurity-9da2e1cd3d5dd683766547c27735472afc327be2.tar.gz
Changing code to have better error logging
This changes the error logs to show the file and line number instead of naming a specific a function where the error originated. In some cases the function name is kept where it made sense for readibility of the logs. Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases` Bug: 241924261 Change-Id: I2ea970dd83e18033506555f2726c716626697cdf
Diffstat (limited to 'keystore2/src/raw_device.rs')
-rw-r--r--keystore2/src/raw_device.rs37
1 files changed, 14 insertions, 23 deletions
diff --git a/keystore2/src/raw_device.rs b/keystore2/src/raw_device.rs
index 4ce9dceb..fe044ee4 100644
--- a/keystore2/src/raw_device.rs
+++ b/keystore2/src/raw_device.rs
@@ -22,6 +22,7 @@ use crate::{
},
error::{map_km_error, Error, ErrorCode},
globals::get_keymint_device,
+ ks_err,
super_key::KeyBlob,
utils::{key_characteristics_to_internal, watchdog as wd, AID_KEYSTORE},
};
@@ -152,7 +153,7 @@ impl KeyMintDevice {
key_type: KeyType,
) -> Result<(KeyIdGuard, KeyEntry)> {
db.load_key_entry(key_desc, key_type, KeyEntryLoadBits::KM, AID_KEYSTORE, |_, _| Ok(()))
- .context("In lookup_from_desc: load_key_entry failed.")
+ .context(ks_err!("load_key_entry failed."))
}
/// Look up the key in the database, and return None if it is absent.
@@ -187,7 +188,7 @@ impl KeyMintDevice {
// - because it avoids holding database locks during slow
// KeyMint operations
let lookup = Self::not_found_is_none(Self::lookup_from_desc(db, key_desc, key_type))
- .context("In lookup_or_generate_key: first lookup failed")?;
+ .context(ks_err!("first lookup failed"))?;
if let Some((key_id_guard, mut key_entry)) = lookup {
// If the key is associated with a different km instance
@@ -220,7 +221,7 @@ impl KeyMintDevice {
})
},
)
- .context("In lookup_or_generate_key: calling getKeyCharacteristics")?;
+ .context(ks_err!("calling getKeyCharacteristics"))?;
if validate_characteristics(&key_characteristics) {
return Ok((key_id_guard, key_blob));
@@ -234,7 +235,7 @@ impl KeyMintDevice {
self.create_and_store_key(db, key_desc, key_type, |km_dev| {
km_dev.generateKey(params, None)
})
- .context("In lookup_or_generate_key: generate_and_store_key failed")?;
+ .context(ks_err!("generate_and_store_key failed"))?;
Self::lookup_from_desc(db, key_desc, key_type)
.and_then(|(key_id_guard, mut key_entry)| {
Ok((
@@ -246,7 +247,7 @@ impl KeyMintDevice {
.context("Missing key blob info.")?,
))
})
- .context("In lookup_or_generate_key: second lookup failed")
+ .context(ks_err!("second lookup failed"))
}
/// Call the passed closure; if it returns `KEY_REQUIRES_UPGRADE`, call upgradeKey, and
@@ -270,7 +271,7 @@ impl KeyMintDevice {
);
self.km_dev.upgradeKey(&key_blob, &[])
})
- .context("In upgrade_keyblob_if_required_with: Upgrade failed")?;
+ .context(ks_err!("Upgrade failed"))?;
let mut new_blob_metadata = BlobMetaData::new();
new_blob_metadata.add(BlobMetaEntry::KmUuid(self.km_uuid));
@@ -281,22 +282,14 @@ impl KeyMintDevice {
Some(&upgraded_blob),
Some(&new_blob_metadata),
)
- .context(concat!(
- "In upgrade_keyblob_if_required_with: ",
- "Failed to insert upgraded blob into the database"
- ))?;
+ .context(ks_err!("Failed to insert upgraded blob into the database"))?;
Ok((
- f(&upgraded_blob).context(
- "In upgrade_keyblob_if_required_with: Closure failed after upgrade",
- )?,
+ f(&upgraded_blob).context(ks_err!("Closure failed after upgrade"))?,
KeyBlob::NonSensitive(upgraded_blob),
))
}
- result => Ok((
- result.context("In upgrade_keyblob_if_required_with: Closure failed")?,
- key_blob,
- )),
+ result => Ok((result.context(ks_err!("Closure failed"))?, key_blob)),
}
}
@@ -322,15 +315,13 @@ impl KeyMintDevice {
self.km_dev.begin(purpose, blob, operation_parameters, auth_token)
})
})
- .context("In use_key_in_one_step: Failed to begin operation.")?;
- let operation: Strong<dyn IKeyMintOperation> = begin_result
- .operation
- .ok_or_else(Error::sys)
- .context("In use_key_in_one_step: Operation missing")?;
+ .context(ks_err!("Failed to begin operation."))?;
+ let operation: Strong<dyn IKeyMintOperation> =
+ begin_result.operation.ok_or_else(Error::sys).context(ks_err!("Operation missing"))?;
map_km_error({
let _wp = wd::watch_millis("In use_key_in_one_step: calling: finish", 500);
operation.finish(Some(input), None, None, None, None)
})
- .context("In use_key_in_one_step: Failed to finish operation.")
+ .context(ks_err!("Failed to finish operation."))
}
}