Lines Matching full:context
71 use anyhow::{anyhow, Context, Result};
171 .context(ks_err!("KeyMetaData::load_from_db: prepare statement failed."))?; in load_from_db()
177 .context(ks_err!("KeyMetaData::load_from_db: query failed."))?; in load_from_db()
179 let db_tag: i64 = row.get(0).context("Failed to read tag.")?; in load_from_db()
183 .context("Failed to read KeyMetaEntry.")?, in load_from_db()
187 .context(ks_err!("KeyMetaData::load_from_db."))?; in load_from_db()
198 .context(ks_err!("KeyMetaData::store_in_db: Failed to prepare statement."))?; in store_in_db()
247 .context(ks_err!("BlobMetaData::load_from_db: prepare statement failed."))?; in load_from_db()
251 let mut rows = stmt.query(params![blob_id]).context(ks_err!("query failed."))?; in load_from_db()
253 let db_tag: i64 = row.get(0).context("Failed to read tag.")?; in load_from_db()
257 .context("Failed to read BlobMetaEntry.")?, in load_from_db()
261 .context(ks_err!("BlobMetaData::load_from_db"))?; in load_from_db()
272 .context(ks_err!("BlobMetaData::store_in_db: Failed to prepare statement.",))?; in store_in_db()
936 .context(ks_err!("KeystoreDB::new: trying to upgrade database."))?; in new()
937 Self::init_tables(tx).context("Trying to initialize tables.").no_gc() in new()
958 .context(ks_err!("Failed to delete logical boot level keys."))?; in from_0_to_1()
972 .context(ks_err!("Failed to add state column"))?; in from_1_to_2()
988 .context("Trying to prepare query to mark superseded keyblobs")?; in from_1_to_2()
990 .context(ks_err!("Failed to set state=superseded state for keyblobs"))?; in from_1_to_2()
1003 .context("Trying to prepare query to mark orphaned keyblobs")?; in from_1_to_2()
1005 .context(ks_err!("Failed to set state=orphaned for keyblobs"))?; in from_1_to_2()
1015 .context("Failed to create index blobentry_state_index.")?; in from_1_to_2()
1024 .context("Failed to create index keyentry_state_index.")?; in from_1_to_2()
1042 .context("Failed to initialize \"keyentry\" table.")?; in init_tables()
1049 .context("Failed to create index keyentry_id_index.")?; in init_tables()
1056 .context("Failed to create index keyentry_domain_namespace_index.")?; in init_tables()
1064 .context("Failed to create index keyentry_state_index.")?; in init_tables()
1075 .context("Failed to initialize \"blobentry\" table.")?; in init_tables()
1082 .context("Failed to create index blobentry_keyentryid_index.")?; in init_tables()
1090 .context("Failed to create index blobentry_state_index.")?; in init_tables()
1101 .context("Failed to initialize \"blobmetadata\" table.")?; in init_tables()
1108 .context("Failed to create index blobmetadata_blobentryid_index.")?; in init_tables()
1118 .context("Failed to initialize \"keyparameter\" table.")?; in init_tables()
1125 .context("Failed to create index keyparameter_keyentryid_index.")?; in init_tables()
1135 .context("Failed to initialize \"keymetadata\" table.")?; in init_tables()
1142 .context("Failed to create index keymetadata_keyentryid_index.")?; in init_tables()
1152 .context("Failed to initialize \"grant\" table.")?; in init_tables()
1171 Connection::open_in_memory().context("Failed to initialize SQLite connection.")?; in make_connection()
1176 .context("Failed to attach database persistent.") in make_connection()
1190 .context("Failed to decrease cache size for persistent db")?; in make_connection()
1311 .context(ks_err!("Trying to delete blob metadata: {:?}", blob_id))?; in handle_next_superseded_blobs()
1313 .context(ks_err!("Trying to delete blob: {:?}", blob_id))?; in handle_next_superseded_blobs()
1316 Self::cleanup_unreferenced(tx).context("Trying to cleanup unreferenced.")?; in handle_next_superseded_blobs()
1327 .context("Trying to prepare query for superseded blobs.")?; in handle_next_superseded_blobs()
1334 .context("Trying to query superseded blob.")?; in handle_next_superseded_blobs()
1337 .context("Trying to extract superseded blobs.")? in handle_next_superseded_blobs()
1353 .context("Trying to prepare query for superseded blobs.")?; in handle_next_superseded_blobs()
1364 .context("Trying to query superseded blob.")?; in handle_next_superseded_blobs()
1367 .context("Trying to extract superseded blobs.")? in handle_next_superseded_blobs()
1381 .context("Trying to load blob metadata.")?; in handle_next_superseded_blobs()
1395 .context("Trying to purge out-of-date blobs (other than keyblobs)")?; in handle_next_superseded_blobs()
1410 .context("Trying to purge superseded blobs.")?; in handle_next_superseded_blobs()
1415 .context(ks_err!()) in handle_next_superseded_blobs()
1434 .context("Failed to execute query.") in cleanup_leftovers()
1437 .context(ks_err!()) in cleanup_leftovers()
1458 _ => Err(error).context(ks_err!("Failed to find if the key exists.")), in key_exists()
1463 .context(ks_err!()) in key_exists()
1494 .context("Failed to insert into keyentry table.")?; in store_super_key()
1496 key_metadata.store_in_db(key_id, tx).context("KeyMetaData::store_in_db failed")?; in store_super_key()
1505 .context("Failed to store key blob.")?; in store_super_key()
1508 .context("Trying to load key components.") in store_super_key()
1511 .context(ks_err!()) in store_super_key()
1533 .context(ks_err!("Failed to load key entry."))?; in load_super_key()
1538 _ => Err(error).context(ks_err!()), in load_super_key()
1543 .context(ks_err!()) in load_super_key()
1558 .context(ks_err!()) in with_transaction()
1564 tx.commit().context(ks_err!("Failed to commit transaction."))?; in with_transaction()
1574 return Err(e).context(ks_err!()); in with_transaction()
1608 .context(ks_err!("Domain {:?} must be either App or SELinux.", domain)); in create_key_entry_internal()
1627 .context(ks_err!())?, in create_key_entry_internal()
1650 .context(ks_err!()) in set_blob()
1670 .context(ks_err!()) in set_deleted_blob()
1688 .context(ks_err!( in set_blob_internal()
1700 .context(ks_err!("Failed to insert blob."))?; in set_blob_internal()
1707 .context(ks_err!("Failed to get new blob id."))?; in set_blob_internal()
1711 .context(ks_err!("Trying to store blob metadata."))?; in set_blob_internal()
1720 .context(ks_err!("Failed to delete blob."))?; in set_blob_internal()
1724 .context(ks_err!("Other blobs cannot be deleted in this way.")); in set_blob_internal()
1737 .context(ks_err!()) in insert_keyparameter()
1750 .context(ks_err!("Failed to prepare statement."))?; in insert_keyparameter_internal()
1770 .context(ks_err!()) in insert_key_metadata()
1790 .context(ks_err!("Domain {:?} must be either App or SELinux.", domain)); in rebind_alias()
1800 .context(ks_err!("Failed to rebind existing entry."))?; in rebind_alias()
1816 .context(ks_err!("Failed to set alias."))?; in rebind_alias()
1818 return Err(KsError::sys()).context(ks_err!( in rebind_alias()
1842 .context(format!("Domain {:?} must be either APP or SELINUX.", domain)); in migrate_key_namespace()
1847 check_permission(&destination).context(ks_err!("Trying to check permission."))?; in migrate_key_namespace()
1853 .context(ks_err!("Alias must be specified."))?; in migrate_key_namespace()
1865 .context("Failed to query destination.")? in migrate_key_namespace()
1869 .context("Target already exists."); in migrate_key_namespace()
1879 .context("Failed to update key entry.")?; in migrate_key_namespace()
1883 .context(format!("Update succeeded, but {} rows were updated.", updated)); in migrate_key_namespace()
1887 .context(ks_err!()) in migrate_key_namespace()
1915 .context(ks_err!("Need alias and domain must be APP or SELINUX.")); in store_new_key()
1920 .context("Trying to create new key entry.")?; in store_new_key()
1936 .context("Trying to insert superseded key blob.")?; in store_new_key()
1949 .context("Trying to insert the key blob.")?; in store_new_key()
1952 .context("Trying to insert the certificate.")?; in store_new_key()
1962 .context("Trying to insert the certificate chain.")?; in store_new_key()
1965 .context("Trying to insert key parameters.")?; in store_new_key()
1966 metadata.store_in_db(key_id.id(), tx).context("Trying to insert key metadata.")?; in store_new_key()
1968 .context("Trying to rebind alias.")? in store_new_key()
1972 .context(ks_err!()) in store_new_key()
1994 .context(ks_err!("Need alias and domain must be APP or SELINUX.")); in store_new_certificate()
1999 .context("Trying to create new key entry.")?; in store_new_certificate()
2008 .context("Trying to insert certificate.")?; in store_new_certificate()
2012 DateTime::now().context("Trying to make creation time.")?, in store_new_certificate()
2015 metadata.store_in_db(key_id.id(), tx).context("Trying to insert key metadata.")?; in store_new_certificate()
2018 .context("Trying to rebind alias.")?; in store_new_certificate()
2021 .context(ks_err!()) in store_new_certificate()
2032 .context("In load_key_entry_id: Alias must be specified.")?; in load_key_entry_id()
2043 .context("In load_key_entry_id: Failed to select from keyentry table.")?; in load_key_entry_id()
2046 .context("In load_key_entry_id: Failed to read from keyentry table.")?; in load_key_entry_id()
2050 .context("Failed to unpack id.") in load_key_entry_id()
2052 .context(ks_err!()) in load_key_entry_id()
2102 .context("Domain::GRANT prepare statement failed")?; in load_access_tuple()
2105 .context("Domain:Grant: query failed.")?; in load_access_tuple()
2111 r.get(0).context("Failed to unpack key_id.")?, in load_access_tuple()
2112 r.get(1).context("Failed to unpack access_vector.")?, in load_access_tuple()
2115 .context("Domain::GRANT.")?; in load_access_tuple()
2134 .context("Domain::KEY_ID: prepare statement failed")?; in load_access_tuple()
2137 .context("Domain::KEY_ID: query failed.")?; in load_access_tuple()
2142 Domain(r.get(0).context("Failed to unpack domain.")?), in load_access_tuple()
2143 r.get(1).context("Failed to unpack namespace.")?, in load_access_tuple()
2146 .context("Domain::KEY_ID.")? in load_access_tuple()
2165 .context("Domain::KEY_ID: query grant failed.")?; in load_access_tuple()
2192 .context(ks_err!("prepare statement failed."))?; in load_blob_components()
2194 let mut rows = stmt.query(params![key_id]).context(ks_err!("query failed."))?; in load_blob_components()
2202 row.get(1).context("Failed to extract subcomponent_type.")?; in load_blob_components()
2207 row.get(0).context("Failed to extract key blob id.")?, in load_blob_components()
2208 row.get(2).context("Failed to extract key blob.")?, in load_blob_components()
2213 Some(row.get(2).context("Failed to extract public certificate blob.")?); in load_blob_components()
2217 Some(row.get(2).context("Failed to extract certificate chain blob.")?); in load_blob_components()
2222 _ => Err(KsError::sys()).context("Unknown subcomponent type.")?, in load_blob_components()
2226 .context(ks_err!())?; in load_blob_components()
2232 .context(ks_err!("Trying to load blob_metadata."))?, in load_blob_components()
2245 .context("In load_key_parameters: prepare statement failed.")?; in load_key_parameters()
2250 stmt.query(params![key_id]).context("In load_key_parameters: query failed.")?; in load_key_parameters()
2252 let tag = Tag(row.get(0).context("Failed to read tag.")?); in load_key_parameters()
2253 let sec_level = SecurityLevel(row.get(2).context("Failed to read sec_level.")?); in load_key_parameters()
2256 .context("Failed to read KeyParameter.")?, in load_key_parameters()
2260 .context(ks_err!())?; in load_key_parameters()
2280 .context("Trying to load usage count")?; in check_and_update_key_usage_count()
2284 .context("The Key no longer exists. Key is exhausted.")?; in check_and_update_key_usage_count()
2292 .context("Failed to update key usage count.")?; in check_and_update_key_usage_count()
2297 .context("Trying to mark limited use key for deletion."), in check_and_update_key_usage_count()
2298 0 => Err(KsError::Km(ErrorCode::INVALID_KEY_BLOB)).context("Key is exhausted."), in check_and_update_key_usage_count()
2302 .context(ks_err!()) in check_and_update_key_usage_count()
2334 return Err(e).context(ks_err!()); in load_key_entry()
2360 .context(ks_err!("Failed to initialize transaction."))?; in load_key_entry_internal()
2363 let access = Self::load_access_tuple(&tx, key, key_type, caller_uid).context(ks_err!())?; in load_key_entry_internal()
2367 check_permission(&access.descriptor, access.vector).context(ks_err!())?; in load_key_entry_internal()
2384 tx.rollback().context(ks_err!("Failed to roll back transaction."))?; in load_key_entry_internal()
2393 .context(ks_err!("Failed to initialize transaction."))?; in load_key_entry_internal()
2407 .context(ks_err!("(deferred key lock)"))?; in load_key_entry_internal()
2416 Self::load_key_components(&tx, load_bits, key_id_guard.id()).context(ks_err!())?; in load_key_entry_internal()
2418 tx.commit().context(ks_err!("Failed to commit transaction."))?; in load_key_entry_internal()
2426 .context("Trying to delete keyentry.")?; in mark_unreferenced()
2428 .context("Trying to delete keymetadata.")?; in mark_unreferenced()
2430 .context("Trying to delete keyparameters.")?; in mark_unreferenced()
2432 .context("Trying to delete grants to other apps.")?; in mark_unreferenced()
2443 .context("Trying to mark blobentrys as superseded")?; in mark_unreferenced()
2453 .context(format!( in delete_received_grants()
2473 .context("Trying to get access tuple.")?; in unbind_key()
2478 .context("While checking permission.")?; in unbind_key()
2482 .context("Trying to mark the key unreferenced.") in unbind_key()
2484 .context(ks_err!()) in unbind_key()
2493 .context(ks_err!()) in get_key_km_uuid()
2502 return Err(KsError::Rc(ResponseCode::INVALID_ARGUMENT)).context(ks_err!()); in unbind_keys_for_namespace()
2513 .context("Trying to delete keymetadata.")?; in unbind_keys_for_namespace()
2522 .context("Trying to delete keyparameters.")?; in unbind_keys_for_namespace()
2531 .context(format!( in unbind_keys_for_namespace()
2539 .context(format!( in unbind_keys_for_namespace()
2549 .context("Trying to delete keyentry.")?; in unbind_keys_for_namespace()
2552 .context(ks_err!()) in unbind_keys_for_namespace()
2566 .context("Trying to delete keymetadata.")?; in cleanup_unreferenced()
2575 .context("Trying to delete keyparameters.")?; in cleanup_unreferenced()
2584 .context("Trying to delete grants.")?; in cleanup_unreferenced()
2590 .context("Trying to delete keyentry.")?; in cleanup_unreferenced()
2593 .context(ks_err!()) in cleanup_unreferenced()
2601 Self::delete_received_grants(tx, user_id).context(format!( in unbind_keys_for_user()
2621 .context(concat!( in unbind_keys_for_user()
2638 .context(ks_err!("Failed to query the keys created by apps."))?; in unbind_keys_for_user()
2643 .push(row.get(0).context("Failed to read key id of a key created by an app.")?); in unbind_keys_for_user()
2646 .context(ks_err!())?; in unbind_keys_for_user()
2651 .context("In unbind_keys_for_user. Failed to mark key id as unreferenced.")? in unbind_keys_for_user()
2656 .context(ks_err!()) in unbind_keys_for_user()
2681 .context(concat!( in unbind_auth_bound_keys_for_user()
2688 .context(ks_err!("Failed to query the keys created by apps."))?; in unbind_auth_bound_keys_for_user()
2693 .push(row.get(0).context("Failed to read key id of a key created by an app.")?); in unbind_auth_bound_keys_for_user()
2696 .context(ks_err!())?; in unbind_auth_bound_keys_for_user()
2706 .context("Failed to load key parameters.")?; in unbind_auth_bound_keys_for_user()
2712 .context("In unbind_auth_bound_keys_for_user.")? in unbind_auth_bound_keys_for_user()
2720 .context(ks_err!()) in unbind_auth_bound_keys_for_user()
2728 let metadata = KeyMetaData::load_from_db(key_id, tx).context("In load_key_components.")?; in load_key_components()
2731 Self::load_blob_components(key_id, load_bits, tx).context("In load_key_components.")?; in load_key_components()
2734 .context("In load_key_components: Trying to load key parameters.")?; in load_key_components()
2737 .context("In load_key_components: Trying to get KM uuid.")?; in load_key_components()
2782 let mut stmt = tx.prepare(&query).context(ks_err!("Failed to prepare."))?; in list_past_alias()
2793 .context(ks_err!("Failed to query."))?, in list_past_alias()
2796 .context(ks_err!("Failed to query."))?, in list_past_alias()
2804 alias: Some(row.get(0).context("Trying to extract alias.")?), in list_past_alias()
2809 .context(ks_err!("Failed to extract rows."))?; in list_past_alias()
2835 .context(ks_err!("Failed to count number of keys.")) in count_keys()
2868 Self::load_access_tuple(tx, key, KeyType::Client, caller_uid).context(ks_err!())?; in grant()
2876 .context(ks_err!("check_permission failed"))?; in grant()
2886 .context(ks_err!("Failed get optional existing grant id."))? in grant()
2894 .context(ks_err!("Failed to update existing grant."))?; in grant()
2904 .context(ks_err!())? in grant()
2927 Self::load_access_tuple(tx, key, KeyType::Client, caller_uid).context(ks_err!())?; in ungrant()
2931 check_permission(&access.descriptor).context(ks_err!("check_permission failed."))?; in ungrant()
2938 .context("Failed to delete grant.")?; in ungrant()
2963 return Err(e).context(ks_err!("failed to insert into database.")); in insert_with_retry()
3002 .context("Trying to load key descriptor") in load_key_descriptor()
3005 .context(ks_err!()) in load_key_descriptor()
3028 .context(concat!( in get_app_uids_affected_by_sid()
3035 .context(ks_err!("Failed to query the keys created by apps."))?; in get_app_uids_affected_by_sid()
3040 row.get(0).context("Failed to read key id of a key created by an app.")?, in get_app_uids_affected_by_sid()
3041 row.get(1).context("Failed to read the app uid")?, in get_app_uids_affected_by_sid()
3056 .context("Failed to load key parameters.")?; in get_app_uids_affected_by_sid()
3081 .context(format!("failed to read pragma {name}")) in pragma()