blob: 4c895aed5f4d39b1482155d94ea96e7451c13590 [file] [log] [blame]
Hasini Gunasingheda895552021-01-27 19:34:37 +00001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Janis Danisevskis34a0cf22021-03-08 09:19:03 -080015//! This module implements IKeystoreMaintenance AIDL interface.
Hasini Gunasingheda895552021-01-27 19:34:37 +000016
Eric Biggersb5613da2024-03-13 19:31:42 +000017use crate::database::{KeyEntryLoadBits, KeyType};
David Drysdaledb7ddde2024-06-07 16:22:49 +010018use crate::error::into_logged_binder;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -080019use crate::error::map_km_error;
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -070020use crate::error::Error;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -080021use crate::globals::get_keymint_device;
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -080022use crate::globals::{DB, LEGACY_IMPORTER, SUPER_KEY};
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000023use crate::ks_err;
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -070024use crate::permission::{KeyPerm, KeystorePerm};
Eric Biggers9f7ebeb2024-06-20 14:59:32 +000025use crate::super_key::SuperKeyManager;
John Wu16db29e2022-01-13 15:21:43 -080026use crate::utils::{
David Drysdale0fefae32024-09-16 13:32:27 +010027 check_dump_permission, check_get_app_uids_affected_by_sid_permissions, check_key_permission,
Eran Messericfe79f12024-02-05 17:50:41 +000028 check_keystore_permission, uid_to_android_user, watchdog as wd,
John Wu16db29e2022-01-13 15:21:43 -080029};
Paul Crowley46c703e2021-08-06 15:13:53 -070030use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
David Drysdalece2b90b2024-07-17 15:56:29 +010031 ErrorCode::ErrorCode, IKeyMintDevice::IKeyMintDevice, SecurityLevel::SecurityLevel,
Paul Crowley46c703e2021-08-06 15:13:53 -070032};
Eric Biggers2f9498a2023-10-09 23:16:05 +000033use android_security_maintenance::aidl::android::security::maintenance::IKeystoreMaintenance::{
34 BnKeystoreMaintenance, IKeystoreMaintenance,
Hasini Gunasingheda895552021-01-27 19:34:37 +000035};
Andrew Walbrande45c8b2021-04-13 14:42:38 +000036use android_security_maintenance::binder::{
37 BinderFeatures, Interface, Result as BinderResult, Strong, ThreadState,
38};
David Drysdale0fefae32024-09-16 13:32:27 +010039use android_security_metrics::aidl::android::security::metrics::{
40 KeystoreAtomPayload::KeystoreAtomPayload::StorageStats
41};
Janis Danisevskis5898d152021-06-15 08:23:46 -070042use android_system_keystore2::aidl::android::system::keystore2::KeyDescriptor::KeyDescriptor;
Hasini Gunasingheda895552021-01-27 19:34:37 +000043use android_system_keystore2::aidl::android::system::keystore2::ResponseCode::ResponseCode;
44use anyhow::{Context, Result};
Paul Crowleyf61fee72021-03-17 14:38:44 -070045use keystore2_crypto::Password;
Hasini Gunasingheda895552021-01-27 19:34:37 +000046
Janis Danisevskis5898d152021-06-15 08:23:46 -070047/// Reexport Domain for the benefit of DeleteListener
48pub use android_system_keystore2::aidl::android::system::keystore2::Domain::Domain;
49
50/// The Maintenance module takes a delete listener argument which observes user and namespace
51/// deletion events.
52pub trait DeleteListener {
53 /// Called by the maintenance module when an app/namespace is deleted.
54 fn delete_namespace(&self, domain: Domain, namespace: i64) -> Result<()>;
55 /// Called by the maintenance module when a user is deleted.
56 fn delete_user(&self, user_id: u32) -> Result<()>;
57}
58
Hasini Gunasingheda895552021-01-27 19:34:37 +000059/// This struct is defined to implement the aforementioned AIDL interface.
Janis Danisevskis5898d152021-06-15 08:23:46 -070060pub struct Maintenance {
61 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
62}
Hasini Gunasingheda895552021-01-27 19:34:37 +000063
Janis Danisevskis34a0cf22021-03-08 09:19:03 -080064impl Maintenance {
Janis Danisevskis5898d152021-06-15 08:23:46 -070065 /// Create a new instance of Keystore Maintenance service.
66 pub fn new_native_binder(
67 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
68 ) -> Result<Strong<dyn IKeystoreMaintenance>> {
Andrew Walbrande45c8b2021-04-13 14:42:38 +000069 Ok(BnKeystoreMaintenance::new_binder(
Janis Danisevskis5898d152021-06-15 08:23:46 -070070 Self { delete_listener },
Andrew Walbrande45c8b2021-04-13 14:42:38 +000071 BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
72 ))
Hasini Gunasingheda895552021-01-27 19:34:37 +000073 }
74
Janis Danisevskis5898d152021-06-15 08:23:46 -070075 fn add_or_remove_user(&self, user_id: i32) -> Result<()> {
Hasini Gunasingheda895552021-01-27 19:34:37 +000076 // Check permission. Function should return if this failed. Therefore having '?' at the end
77 // is very important.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000078 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080079
Janis Danisevskiseed69842021-02-18 20:04:10 -080080 DB.with(|db| {
Nathan Huckleberry204a0442023-03-30 17:27:47 +000081 SUPER_KEY.write().unwrap().remove_user(
Janis Danisevskiseed69842021-02-18 20:04:10 -080082 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -080083 &LEGACY_IMPORTER,
Janis Danisevskiseed69842021-02-18 20:04:10 -080084 user_id as u32,
Janis Danisevskiseed69842021-02-18 20:04:10 -080085 )
86 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000087 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -070088 self.delete_listener
89 .delete_user(user_id as u32)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000090 .context(ks_err!("While invoking the delete listener."))
Hasini Gunasingheda895552021-01-27 19:34:37 +000091 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -080092
Eric Biggersb0478cf2023-10-27 03:55:29 +000093 fn init_user_super_keys(
94 &self,
95 user_id: i32,
96 password: Password,
97 allow_existing: bool,
98 ) -> Result<()> {
99 // Permission check. Must return on error. Do not touch the '?'.
100 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
101
102 let mut skm = SUPER_KEY.write().unwrap();
103 DB.with(|db| {
104 skm.initialize_user(
105 &mut db.borrow_mut(),
106 &LEGACY_IMPORTER,
107 user_id as u32,
108 &password,
109 allow_existing,
110 )
111 })
112 .context(ks_err!("Failed to initialize user super keys"))
113 }
114
115 // Deletes all auth-bound keys when the user's LSKF is removed.
116 fn on_user_lskf_removed(user_id: i32) -> Result<()> {
117 // Permission check. Must return on error. Do not touch the '?'.
118 check_keystore_permission(KeystorePerm::ChangePassword).context(ks_err!())?;
119
120 LEGACY_IMPORTER
121 .bulk_delete_user(user_id as u32, true)
122 .context(ks_err!("Failed to delete legacy keys."))?;
123
124 DB.with(|db| db.borrow_mut().unbind_auth_bound_keys_for_user(user_id as u32))
125 .context(ks_err!("Failed to delete auth-bound keys."))
126 }
127
Janis Danisevskis5898d152021-06-15 08:23:46 -0700128 fn clear_namespace(&self, domain: Domain, nspace: i64) -> Result<()> {
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800129 // Permission check. Must return on error. Do not touch the '?'.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700130 check_keystore_permission(KeystorePerm::ClearUID).context("In clear_namespace.")?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800131
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800132 LEGACY_IMPORTER
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800133 .bulk_delete_uid(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000134 .context(ks_err!("Trying to delete legacy keys."))?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800135 DB.with(|db| db.borrow_mut().unbind_keys_for_namespace(domain, nspace))
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000136 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -0700137 self.delete_listener
138 .delete_namespace(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000139 .context(ks_err!("While invoking the delete listener."))
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800140 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000141
Paul Crowley46c703e2021-08-06 15:13:53 -0700142 fn call_with_watchdog<F>(sec_level: SecurityLevel, name: &'static str, op: &F) -> Result<()>
143 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000144 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700145 {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000146 let (km_dev, _, _) =
147 get_keymint_device(&sec_level).context(ks_err!("getting keymint device"))?;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700148
David Drysdalec652f6c2024-07-18 13:01:23 +0100149 let _wp = wd::watch_millis_with("Maintenance::call_with_watchdog", 500, (sec_level, name));
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000150 map_km_error(op(km_dev)).with_context(|| ks_err!("calling {}", name))?;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800151 Ok(())
152 }
153
Paul Crowley46c703e2021-08-06 15:13:53 -0700154 fn call_on_all_security_levels<F>(name: &'static str, op: F) -> Result<()>
155 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000156 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700157 {
158 let sec_levels = [
159 (SecurityLevel::TRUSTED_ENVIRONMENT, "TRUSTED_ENVIRONMENT"),
160 (SecurityLevel::STRONGBOX, "STRONGBOX"),
161 ];
James Farrelld77b97f2023-08-15 20:03:38 +0000162 sec_levels.iter().try_fold((), |_result, (sec_level, sec_level_string)| {
Paul Crowley46c703e2021-08-06 15:13:53 -0700163 let curr_result = Maintenance::call_with_watchdog(*sec_level, name, &op);
164 match curr_result {
165 Ok(()) => log::info!(
166 "Call to {} succeeded for security level {}.",
167 name,
168 &sec_level_string
169 ),
David Drysdalece2b90b2024-07-17 15:56:29 +0100170 Err(ref e) => {
171 if *sec_level == SecurityLevel::STRONGBOX
172 && e.downcast_ref::<Error>()
173 == Some(&Error::Km(ErrorCode::HARDWARE_TYPE_UNAVAILABLE))
174 {
175 log::info!("Call to {} failed for StrongBox as it is not available", name,)
176 } else {
177 log::error!(
178 "Call to {} failed for security level {}: {}.",
179 name,
180 &sec_level_string,
181 e
182 )
183 }
184 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700185 }
James Farrelld77b97f2023-08-15 20:03:38 +0000186 curr_result
Paul Crowley46c703e2021-08-06 15:13:53 -0700187 })
188 }
189
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800190 fn early_boot_ended() -> Result<()> {
Janis Danisevskisa916d992021-10-19 15:46:09 -0700191 check_keystore_permission(KeystorePerm::EarlyBootEnded)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000192 .context(ks_err!("Checking permission"))?;
Paul Crowley44c02da2021-04-08 17:04:43 +0000193 log::info!("In early_boot_ended.");
194
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800195 if let Err(e) =
196 DB.with(|db| SuperKeyManager::set_up_boot_level_cache(&SUPER_KEY, &mut db.borrow_mut()))
197 {
Paul Crowley44c02da2021-04-08 17:04:43 +0000198 log::error!("SUPER_KEY.set_up_boot_level_cache failed:\n{:?}\n:(", e);
199 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700200 Maintenance::call_on_all_security_levels("earlyBootEnded", |dev| dev.earlyBootEnded())
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800201 }
202
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700203 fn migrate_key_namespace(source: &KeyDescriptor, destination: &KeyDescriptor) -> Result<()> {
John Wu889c1cc2022-03-14 16:02:56 -0700204 let calling_uid = ThreadState::get_calling_uid();
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700205
John Wu889c1cc2022-03-14 16:02:56 -0700206 match source.domain {
207 Domain::SELINUX | Domain::KEY_ID | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800208 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000209 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
210 .context(ks_err!("Source domain must be one of APP, SELINUX, or KEY_ID."));
John Wu16db29e2022-01-13 15:21:43 -0800211 }
212 };
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700213
John Wu889c1cc2022-03-14 16:02:56 -0700214 match destination.domain {
215 Domain::SELINUX | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800216 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000217 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
218 .context(ks_err!("Destination domain must be one of APP or SELINUX."));
John Wu16db29e2022-01-13 15:21:43 -0800219 }
220 };
221
John Wu889c1cc2022-03-14 16:02:56 -0700222 let user_id = uid_to_android_user(calling_uid);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800223
Eric Biggers673d34a2023-10-18 01:54:18 +0000224 let super_key = SUPER_KEY.read().unwrap().get_after_first_unlock_key_by_user_id(user_id);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800225
226 DB.with(|db| {
John Wu889c1cc2022-03-14 16:02:56 -0700227 let (key_id_guard, _) = LEGACY_IMPORTER
228 .with_try_import(source, calling_uid, super_key, || {
229 db.borrow_mut().load_key_entry(
230 source,
231 KeyType::Client,
232 KeyEntryLoadBits::NONE,
233 calling_uid,
234 |k, av| {
235 check_key_permission(KeyPerm::Use, k, &av)?;
236 check_key_permission(KeyPerm::Delete, k, &av)?;
237 check_key_permission(KeyPerm::Grant, k, &av)
238 },
239 )
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800240 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000241 .context(ks_err!("Failed to load key blob."))?;
John Wu889c1cc2022-03-14 16:02:56 -0700242 {
243 db.borrow_mut().migrate_key_namespace(key_id_guard, destination, calling_uid, |k| {
244 check_key_permission(KeyPerm::Rebind, k, &None)
245 })
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800246 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700247 })
248 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700249
250 fn delete_all_keys() -> Result<()> {
251 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700252 check_keystore_permission(KeystorePerm::DeleteAllKeys)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000253 .context(ks_err!("Checking permission"))?;
Paul Crowley46c703e2021-08-06 15:13:53 -0700254 log::info!("In delete_all_keys.");
255
256 Maintenance::call_on_all_security_levels("deleteAllKeys", |dev| dev.deleteAllKeys())
257 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000258
259 fn get_app_uids_affected_by_sid(
260 user_id: i32,
261 secure_user_id: i64,
262 ) -> Result<std::vec::Vec<i64>> {
263 // This method is intended to be called by Settings and discloses a list of apps
Eran Messericfe79f12024-02-05 17:50:41 +0000264 // associated with a user, so it requires the "android.permission.MANAGE_USERS"
265 // permission (to avoid leaking list of apps to unauthorized callers).
266 check_get_app_uids_affected_by_sid_permissions().context(ks_err!())?;
Eran Messeri4dc27b52024-01-09 12:43:31 +0000267 DB.with(|db| db.borrow_mut().get_app_uids_affected_by_sid(user_id, secure_user_id))
268 .context(ks_err!("Failed to get app UIDs affected by SID"))
269 }
David Drysdale0fefae32024-09-16 13:32:27 +0100270
271 fn dump_state(&self, f: &mut dyn std::io::Write) -> std::io::Result<()> {
272 writeln!(f, "keystore2 running")?;
273 writeln!(f)?;
274
275 // Display underlying device information
276 for sec_level in &[SecurityLevel::TRUSTED_ENVIRONMENT, SecurityLevel::STRONGBOX] {
277 let Ok((_dev, hw_info, uuid)) = get_keymint_device(sec_level) else { continue };
278
279 writeln!(f, "Device info for {sec_level:?} with {uuid:?}")?;
280 writeln!(f, " HAL version: {}", hw_info.versionNumber)?;
281 writeln!(f, " Implementation name: {}", hw_info.keyMintName)?;
282 writeln!(f, " Implementation author: {}", hw_info.keyMintAuthorName)?;
283 writeln!(f, " Timestamp token required: {}", hw_info.timestampTokenRequired)?;
284 }
285 writeln!(f)?;
286
287 // Display database size information.
288 match crate::metrics_store::pull_storage_stats() {
289 Ok(atoms) => {
290 writeln!(f, "Database size information (in bytes):")?;
291 for atom in atoms {
292 if let StorageStats(stats) = &atom.payload {
293 let stype = format!("{:?}", stats.storage_type);
294 if stats.unused_size == 0 {
295 writeln!(f, " {:<40}: {:>12}", stype, stats.size)?;
296 } else {
297 writeln!(
298 f,
299 " {:<40}: {:>12} (unused {})",
300 stype, stats.size, stats.unused_size
301 )?;
302 }
303 }
304 }
305 }
306 Err(e) => {
307 writeln!(f, "Failed to retrieve storage stats: {e:?}")?;
308 }
309 }
310 writeln!(f)?;
311
David Drysdale49811e22023-05-22 18:51:30 +0100312 // Display accumulated metrics.
313 writeln!(f, "Metrics information:")?;
314 writeln!(f)?;
315 write!(f, "{:?}", *crate::metrics_store::METRICS_STORE)?;
316 writeln!(f)?;
317
David Drysdale0fefae32024-09-16 13:32:27 +0100318 // Reminder: any additional information added to the `dump_state()` output needs to be
319 // careful not to include confidential information (e.g. key material).
320
321 Ok(())
322 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000323}
324
David Drysdale0fefae32024-09-16 13:32:27 +0100325impl Interface for Maintenance {
326 fn dump(
327 &self,
328 f: &mut dyn std::io::Write,
329 _args: &[&std::ffi::CStr],
330 ) -> Result<(), binder::StatusCode> {
331 if !keystore2_flags::enable_dump() {
332 log::info!("skipping dump() as flag not enabled");
333 return Ok(());
334 }
335 log::info!("dump()");
336 let _wp = wd::watch("IKeystoreMaintenance::dump");
337 check_dump_permission().map_err(|_e| {
338 log::error!("dump permission denied");
339 binder::StatusCode::PERMISSION_DENIED
340 })?;
341
342 self.dump_state(f).map_err(|e| {
343 log::error!("dump_state failed: {e:?}");
344 binder::StatusCode::UNKNOWN_ERROR
345 })
346 }
347}
Hasini Gunasingheda895552021-01-27 19:34:37 +0000348
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800349impl IKeystoreMaintenance for Maintenance {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000350 fn onUserAdded(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100351 log::info!("onUserAdded(user={user_id})");
David Drysdale541846b2024-05-23 13:16:07 +0100352 let _wp = wd::watch("IKeystoreMaintenance::onUserAdded");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100353 self.add_or_remove_user(user_id).map_err(into_logged_binder)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000354 }
355
Eric Biggersb0478cf2023-10-27 03:55:29 +0000356 fn initUserSuperKeys(
357 &self,
358 user_id: i32,
359 password: &[u8],
360 allow_existing: bool,
361 ) -> BinderResult<()> {
362 log::info!("initUserSuperKeys(user={user_id}, allow_existing={allow_existing})");
David Drysdale541846b2024-05-23 13:16:07 +0100363 let _wp = wd::watch("IKeystoreMaintenance::initUserSuperKeys");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100364 self.init_user_super_keys(user_id, password.into(), allow_existing)
365 .map_err(into_logged_binder)
Eric Biggersb0478cf2023-10-27 03:55:29 +0000366 }
367
Hasini Gunasingheda895552021-01-27 19:34:37 +0000368 fn onUserRemoved(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100369 log::info!("onUserRemoved(user={user_id})");
David Drysdale541846b2024-05-23 13:16:07 +0100370 let _wp = wd::watch("IKeystoreMaintenance::onUserRemoved");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100371 self.add_or_remove_user(user_id).map_err(into_logged_binder)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000372 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800373
Eric Biggersb0478cf2023-10-27 03:55:29 +0000374 fn onUserLskfRemoved(&self, user_id: i32) -> BinderResult<()> {
375 log::info!("onUserLskfRemoved(user={user_id})");
David Drysdale541846b2024-05-23 13:16:07 +0100376 let _wp = wd::watch("IKeystoreMaintenance::onUserLskfRemoved");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100377 Self::on_user_lskf_removed(user_id).map_err(into_logged_binder)
Eric Biggersb0478cf2023-10-27 03:55:29 +0000378 }
379
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800380 fn clearNamespace(&self, domain: Domain, nspace: i64) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100381 log::info!("clearNamespace({domain:?}, nspace={nspace})");
David Drysdale541846b2024-05-23 13:16:07 +0100382 let _wp = wd::watch("IKeystoreMaintenance::clearNamespace");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100383 self.clear_namespace(domain, nspace).map_err(into_logged_binder)
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800384 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000385
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800386 fn earlyBootEnded(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100387 log::info!("earlyBootEnded()");
David Drysdale541846b2024-05-23 13:16:07 +0100388 let _wp = wd::watch("IKeystoreMaintenance::earlyBootEnded");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100389 Self::early_boot_ended().map_err(into_logged_binder)
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800390 }
391
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700392 fn migrateKeyNamespace(
393 &self,
394 source: &KeyDescriptor,
395 destination: &KeyDescriptor,
396 ) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100397 log::info!("migrateKeyNamespace(src={source:?}, dest={destination:?})");
David Drysdale541846b2024-05-23 13:16:07 +0100398 let _wp = wd::watch("IKeystoreMaintenance::migrateKeyNamespace");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100399 Self::migrate_key_namespace(source, destination).map_err(into_logged_binder)
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700400 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700401
402 fn deleteAllKeys(&self) -> BinderResult<()> {
David Drysdalece2b90b2024-07-17 15:56:29 +0100403 log::warn!("deleteAllKeys() invoked, indicating initial setup or post-factory reset");
David Drysdale541846b2024-05-23 13:16:07 +0100404 let _wp = wd::watch("IKeystoreMaintenance::deleteAllKeys");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100405 Self::delete_all_keys().map_err(into_logged_binder)
Paul Crowley46c703e2021-08-06 15:13:53 -0700406 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000407
408 fn getAppUidsAffectedBySid(
409 &self,
410 user_id: i32,
411 secure_user_id: i64,
412 ) -> BinderResult<std::vec::Vec<i64>> {
413 log::info!("getAppUidsAffectedBySid(secure_user_id={secure_user_id:?})");
David Drysdale541846b2024-05-23 13:16:07 +0100414 let _wp = wd::watch("IKeystoreMaintenance::getAppUidsAffectedBySid");
David Drysdaledb7ddde2024-06-07 16:22:49 +0100415 Self::get_app_uids_affected_by_sid(user_id, secure_user_id).map_err(into_logged_binder)
Eran Messeri4dc27b52024-01-09 12:43:31 +0000416 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000417}