blob: 3e34cff3698d0544fc1b26f34070765243e885c9 [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 Biggers19b3b0d2024-01-31 22:46:47 +000017use crate::database::{BootTime, KeyEntryLoadBits, KeyType};
Satya Tangirala5b9e5b12021-03-09 12:54:21 -080018use crate::error::map_km_error;
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -070019use crate::error::map_or_log_err;
20use 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};
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080025use crate::super_key::{SuperKeyManager, UserState};
John Wu16db29e2022-01-13 15:21:43 -080026use crate::utils::{
Eran Messericfe79f12024-02-05 17:50:41 +000027 check_get_app_uids_affected_by_sid_permissions, check_key_permission,
28 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::{
31 IKeyMintDevice::IKeyMintDevice, SecurityLevel::SecurityLevel,
32};
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};
Janis Danisevskis5898d152021-06-15 08:23:46 -070039use android_system_keystore2::aidl::android::system::keystore2::KeyDescriptor::KeyDescriptor;
Hasini Gunasingheda895552021-01-27 19:34:37 +000040use android_system_keystore2::aidl::android::system::keystore2::ResponseCode::ResponseCode;
41use anyhow::{Context, Result};
Paul Crowleyf61fee72021-03-17 14:38:44 -070042use keystore2_crypto::Password;
Hasini Gunasingheda895552021-01-27 19:34:37 +000043
Janis Danisevskis5898d152021-06-15 08:23:46 -070044/// Reexport Domain for the benefit of DeleteListener
45pub use android_system_keystore2::aidl::android::system::keystore2::Domain::Domain;
46
47/// The Maintenance module takes a delete listener argument which observes user and namespace
48/// deletion events.
49pub trait DeleteListener {
50 /// Called by the maintenance module when an app/namespace is deleted.
51 fn delete_namespace(&self, domain: Domain, namespace: i64) -> Result<()>;
52 /// Called by the maintenance module when a user is deleted.
53 fn delete_user(&self, user_id: u32) -> Result<()>;
54}
55
Hasini Gunasingheda895552021-01-27 19:34:37 +000056/// This struct is defined to implement the aforementioned AIDL interface.
Janis Danisevskis5898d152021-06-15 08:23:46 -070057pub struct Maintenance {
58 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
59}
Hasini Gunasingheda895552021-01-27 19:34:37 +000060
Janis Danisevskis34a0cf22021-03-08 09:19:03 -080061impl Maintenance {
Janis Danisevskis5898d152021-06-15 08:23:46 -070062 /// Create a new instance of Keystore Maintenance service.
63 pub fn new_native_binder(
64 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
65 ) -> Result<Strong<dyn IKeystoreMaintenance>> {
Andrew Walbrande45c8b2021-04-13 14:42:38 +000066 Ok(BnKeystoreMaintenance::new_binder(
Janis Danisevskis5898d152021-06-15 08:23:46 -070067 Self { delete_listener },
Andrew Walbrande45c8b2021-04-13 14:42:38 +000068 BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
69 ))
Hasini Gunasingheda895552021-01-27 19:34:37 +000070 }
71
Paul Crowleyf61fee72021-03-17 14:38:44 -070072 fn on_user_password_changed(user_id: i32, password: Option<Password>) -> Result<()> {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080073 // Check permission. Function should return if this failed. Therefore having '?' at the end
74 // is very important.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000075 check_keystore_permission(KeystorePerm::ChangePassword).context(ks_err!())?;
Hasini Gunasingheda895552021-01-27 19:34:37 +000076
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080077 let mut skm = SUPER_KEY.write().unwrap();
78
Paul Crowley7a658392021-03-18 17:08:20 -070079 if let Some(pw) = password.as_ref() {
80 DB.with(|db| {
Eric Biggersb1f641d2023-10-18 01:54:18 +000081 skm.unlock_unlocked_device_required_keys(&mut db.borrow_mut(), user_id as u32, pw)
Paul Crowley7a658392021-03-18 17:08:20 -070082 })
Eric Biggersb1f641d2023-10-18 01:54:18 +000083 .context(ks_err!("unlock_unlocked_device_required_keys failed"))?;
Paul Crowley7a658392021-03-18 17:08:20 -070084 }
85
Eric Biggers13869372023-10-18 01:54:18 +000086 if let UserState::BeforeFirstUnlock = DB
Nathan Huckleberry204a0442023-03-30 17:27:47 +000087 .with(|db| skm.get_user_state(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32))
88 .context(ks_err!("Could not get user state while changing password!"))?
Hasini Gunasingheda895552021-01-27 19:34:37 +000089 {
Nathan Huckleberry204a0442023-03-30 17:27:47 +000090 // Error - password can not be changed when the device is locked
91 return Err(Error::Rc(ResponseCode::LOCKED)).context(ks_err!("Device is locked."));
Hasini Gunasingheda895552021-01-27 19:34:37 +000092 }
Nathan Huckleberry204a0442023-03-30 17:27:47 +000093
94 DB.with(|db| match password {
95 Some(pass) => {
96 skm.init_user(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32, &pass)
97 }
98 None => {
99 // User transitioned to swipe.
100 skm.reset_user(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32)
101 }
102 })
103 .context(ks_err!("Failed to change user password!"))
Hasini Gunasingheda895552021-01-27 19:34:37 +0000104 }
105
Janis Danisevskis5898d152021-06-15 08:23:46 -0700106 fn add_or_remove_user(&self, user_id: i32) -> Result<()> {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000107 // Check permission. Function should return if this failed. Therefore having '?' at the end
108 // is very important.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000109 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800110
Janis Danisevskiseed69842021-02-18 20:04:10 -0800111 DB.with(|db| {
Nathan Huckleberry204a0442023-03-30 17:27:47 +0000112 SUPER_KEY.write().unwrap().remove_user(
Janis Danisevskiseed69842021-02-18 20:04:10 -0800113 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800114 &LEGACY_IMPORTER,
Janis Danisevskiseed69842021-02-18 20:04:10 -0800115 user_id as u32,
Janis Danisevskiseed69842021-02-18 20:04:10 -0800116 )
117 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000118 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -0700119 self.delete_listener
120 .delete_user(user_id as u32)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000121 .context(ks_err!("While invoking the delete listener."))
Hasini Gunasingheda895552021-01-27 19:34:37 +0000122 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800123
Eric Biggersb0478cf2023-10-27 03:55:29 +0000124 fn init_user_super_keys(
125 &self,
126 user_id: i32,
127 password: Password,
128 allow_existing: bool,
129 ) -> Result<()> {
130 // Permission check. Must return on error. Do not touch the '?'.
131 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
132
133 let mut skm = SUPER_KEY.write().unwrap();
134 DB.with(|db| {
135 skm.initialize_user(
136 &mut db.borrow_mut(),
137 &LEGACY_IMPORTER,
138 user_id as u32,
139 &password,
140 allow_existing,
141 )
142 })
143 .context(ks_err!("Failed to initialize user super keys"))
144 }
145
146 // Deletes all auth-bound keys when the user's LSKF is removed.
147 fn on_user_lskf_removed(user_id: i32) -> Result<()> {
148 // Permission check. Must return on error. Do not touch the '?'.
149 check_keystore_permission(KeystorePerm::ChangePassword).context(ks_err!())?;
150
151 LEGACY_IMPORTER
152 .bulk_delete_user(user_id as u32, true)
153 .context(ks_err!("Failed to delete legacy keys."))?;
154
155 DB.with(|db| db.borrow_mut().unbind_auth_bound_keys_for_user(user_id as u32))
156 .context(ks_err!("Failed to delete auth-bound keys."))
157 }
158
Janis Danisevskis5898d152021-06-15 08:23:46 -0700159 fn clear_namespace(&self, domain: Domain, nspace: i64) -> Result<()> {
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800160 // Permission check. Must return on error. Do not touch the '?'.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700161 check_keystore_permission(KeystorePerm::ClearUID).context("In clear_namespace.")?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800162
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800163 LEGACY_IMPORTER
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800164 .bulk_delete_uid(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000165 .context(ks_err!("Trying to delete legacy keys."))?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800166 DB.with(|db| db.borrow_mut().unbind_keys_for_namespace(domain, nspace))
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000167 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -0700168 self.delete_listener
169 .delete_namespace(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000170 .context(ks_err!("While invoking the delete listener."))
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800171 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000172
Paul Crowley46c703e2021-08-06 15:13:53 -0700173 fn call_with_watchdog<F>(sec_level: SecurityLevel, name: &'static str, op: &F) -> Result<()>
174 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000175 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700176 {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000177 let (km_dev, _, _) =
178 get_keymint_device(&sec_level).context(ks_err!("getting keymint device"))?;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700179
Paul Crowley46c703e2021-08-06 15:13:53 -0700180 let _wp = wd::watch_millis_with("In call_with_watchdog", 500, move || {
181 format!("Seclevel: {:?} Op: {}", sec_level, name)
182 });
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000183 map_km_error(op(km_dev)).with_context(|| ks_err!("calling {}", name))?;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800184 Ok(())
185 }
186
Paul Crowley46c703e2021-08-06 15:13:53 -0700187 fn call_on_all_security_levels<F>(name: &'static str, op: F) -> Result<()>
188 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000189 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700190 {
191 let sec_levels = [
192 (SecurityLevel::TRUSTED_ENVIRONMENT, "TRUSTED_ENVIRONMENT"),
193 (SecurityLevel::STRONGBOX, "STRONGBOX"),
194 ];
James Farrelld77b97f2023-08-15 20:03:38 +0000195 sec_levels.iter().try_fold((), |_result, (sec_level, sec_level_string)| {
Paul Crowley46c703e2021-08-06 15:13:53 -0700196 let curr_result = Maintenance::call_with_watchdog(*sec_level, name, &op);
197 match curr_result {
198 Ok(()) => log::info!(
199 "Call to {} succeeded for security level {}.",
200 name,
201 &sec_level_string
202 ),
203 Err(ref e) => log::error!(
204 "Call to {} failed for security level {}: {}.",
205 name,
206 &sec_level_string,
207 e
208 ),
209 }
James Farrelld77b97f2023-08-15 20:03:38 +0000210 curr_result
Paul Crowley46c703e2021-08-06 15:13:53 -0700211 })
212 }
213
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800214 fn early_boot_ended() -> Result<()> {
Janis Danisevskisa916d992021-10-19 15:46:09 -0700215 check_keystore_permission(KeystorePerm::EarlyBootEnded)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000216 .context(ks_err!("Checking permission"))?;
Paul Crowley44c02da2021-04-08 17:04:43 +0000217 log::info!("In early_boot_ended.");
218
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800219 if let Err(e) =
220 DB.with(|db| SuperKeyManager::set_up_boot_level_cache(&SUPER_KEY, &mut db.borrow_mut()))
221 {
Paul Crowley44c02da2021-04-08 17:04:43 +0000222 log::error!("SUPER_KEY.set_up_boot_level_cache failed:\n{:?}\n:(", e);
223 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700224 Maintenance::call_on_all_security_levels("earlyBootEnded", |dev| dev.earlyBootEnded())
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800225 }
226
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700227 fn on_device_off_body() -> Result<()> {
228 // Security critical permission check. This statement must return on fail.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000229 check_keystore_permission(KeystorePerm::ReportOffBody).context(ks_err!())?;
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700230
Eric Biggers19b3b0d2024-01-31 22:46:47 +0000231 DB.with(|db| db.borrow_mut().update_last_off_body(BootTime::now()));
Matthew Maurerd7815ca2021-05-06 21:58:45 -0700232 Ok(())
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700233 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700234
235 fn migrate_key_namespace(source: &KeyDescriptor, destination: &KeyDescriptor) -> Result<()> {
John Wu889c1cc2022-03-14 16:02:56 -0700236 let calling_uid = ThreadState::get_calling_uid();
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700237
John Wu889c1cc2022-03-14 16:02:56 -0700238 match source.domain {
239 Domain::SELINUX | Domain::KEY_ID | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800240 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000241 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
242 .context(ks_err!("Source domain must be one of APP, SELINUX, or KEY_ID."));
John Wu16db29e2022-01-13 15:21:43 -0800243 }
244 };
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700245
John Wu889c1cc2022-03-14 16:02:56 -0700246 match destination.domain {
247 Domain::SELINUX | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800248 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000249 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
250 .context(ks_err!("Destination domain must be one of APP or SELINUX."));
John Wu16db29e2022-01-13 15:21:43 -0800251 }
252 };
253
John Wu889c1cc2022-03-14 16:02:56 -0700254 let user_id = uid_to_android_user(calling_uid);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800255
Eric Biggers673d34a2023-10-18 01:54:18 +0000256 let super_key = SUPER_KEY.read().unwrap().get_after_first_unlock_key_by_user_id(user_id);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800257
258 DB.with(|db| {
John Wu889c1cc2022-03-14 16:02:56 -0700259 let (key_id_guard, _) = LEGACY_IMPORTER
260 .with_try_import(source, calling_uid, super_key, || {
261 db.borrow_mut().load_key_entry(
262 source,
263 KeyType::Client,
264 KeyEntryLoadBits::NONE,
265 calling_uid,
266 |k, av| {
267 check_key_permission(KeyPerm::Use, k, &av)?;
268 check_key_permission(KeyPerm::Delete, k, &av)?;
269 check_key_permission(KeyPerm::Grant, k, &av)
270 },
271 )
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800272 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000273 .context(ks_err!("Failed to load key blob."))?;
John Wu889c1cc2022-03-14 16:02:56 -0700274 {
275 db.borrow_mut().migrate_key_namespace(key_id_guard, destination, calling_uid, |k| {
276 check_key_permission(KeyPerm::Rebind, k, &None)
277 })
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800278 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700279 })
280 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700281
282 fn delete_all_keys() -> Result<()> {
283 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700284 check_keystore_permission(KeystorePerm::DeleteAllKeys)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000285 .context(ks_err!("Checking permission"))?;
Paul Crowley46c703e2021-08-06 15:13:53 -0700286 log::info!("In delete_all_keys.");
287
288 Maintenance::call_on_all_security_levels("deleteAllKeys", |dev| dev.deleteAllKeys())
289 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000290
291 fn get_app_uids_affected_by_sid(
292 user_id: i32,
293 secure_user_id: i64,
294 ) -> Result<std::vec::Vec<i64>> {
295 // This method is intended to be called by Settings and discloses a list of apps
Eran Messericfe79f12024-02-05 17:50:41 +0000296 // associated with a user, so it requires the "android.permission.MANAGE_USERS"
297 // permission (to avoid leaking list of apps to unauthorized callers).
298 check_get_app_uids_affected_by_sid_permissions().context(ks_err!())?;
Eran Messeri4dc27b52024-01-09 12:43:31 +0000299 DB.with(|db| db.borrow_mut().get_app_uids_affected_by_sid(user_id, secure_user_id))
300 .context(ks_err!("Failed to get app UIDs affected by SID"))
301 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000302}
303
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800304impl Interface for Maintenance {}
Hasini Gunasingheda895552021-01-27 19:34:37 +0000305
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800306impl IKeystoreMaintenance for Maintenance {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000307 fn onUserPasswordChanged(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100308 log::info!(
309 "onUserPasswordChanged(user={}, password.is_some()={})",
310 user_id,
311 password.is_some()
312 );
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000313 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserPasswordChanged", 500);
Paul Crowleyf61fee72021-03-17 14:38:44 -0700314 map_or_log_err(Self::on_user_password_changed(user_id, password.map(|pw| pw.into())), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000315 }
316
317 fn onUserAdded(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100318 log::info!("onUserAdded(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000319 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserAdded", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700320 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000321 }
322
Eric Biggersb0478cf2023-10-27 03:55:29 +0000323 fn initUserSuperKeys(
324 &self,
325 user_id: i32,
326 password: &[u8],
327 allow_existing: bool,
328 ) -> BinderResult<()> {
329 log::info!("initUserSuperKeys(user={user_id}, allow_existing={allow_existing})");
330 let _wp = wd::watch_millis("IKeystoreMaintenance::initUserSuperKeys", 500);
331 map_or_log_err(self.init_user_super_keys(user_id, password.into(), allow_existing), Ok)
332 }
333
Hasini Gunasingheda895552021-01-27 19:34:37 +0000334 fn onUserRemoved(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100335 log::info!("onUserRemoved(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000336 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserRemoved", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700337 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000338 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800339
Eric Biggersb0478cf2023-10-27 03:55:29 +0000340 fn onUserLskfRemoved(&self, user_id: i32) -> BinderResult<()> {
341 log::info!("onUserLskfRemoved(user={user_id})");
342 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserLskfRemoved", 500);
343 map_or_log_err(Self::on_user_lskf_removed(user_id), Ok)
344 }
345
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800346 fn clearNamespace(&self, domain: Domain, nspace: i64) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100347 log::info!("clearNamespace({domain:?}, nspace={nspace})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000348 let _wp = wd::watch_millis("IKeystoreMaintenance::clearNamespace", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700349 map_or_log_err(self.clear_namespace(domain, nspace), Ok)
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800350 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000351
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800352 fn earlyBootEnded(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100353 log::info!("earlyBootEnded()");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000354 let _wp = wd::watch_millis("IKeystoreMaintenance::earlyBootEnded", 500);
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800355 map_or_log_err(Self::early_boot_ended(), Ok)
356 }
357
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700358 fn onDeviceOffBody(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100359 log::info!("onDeviceOffBody()");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000360 let _wp = wd::watch_millis("IKeystoreMaintenance::onDeviceOffBody", 500);
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700361 map_or_log_err(Self::on_device_off_body(), Ok)
362 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700363
364 fn migrateKeyNamespace(
365 &self,
366 source: &KeyDescriptor,
367 destination: &KeyDescriptor,
368 ) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100369 log::info!("migrateKeyNamespace(src={source:?}, dest={destination:?})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000370 let _wp = wd::watch_millis("IKeystoreMaintenance::migrateKeyNamespace", 500);
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700371 map_or_log_err(Self::migrate_key_namespace(source, destination), Ok)
372 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700373
374 fn deleteAllKeys(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100375 log::warn!("deleteAllKeys()");
Paul Crowley46c703e2021-08-06 15:13:53 -0700376 let _wp = wd::watch_millis("IKeystoreMaintenance::deleteAllKeys", 500);
377 map_or_log_err(Self::delete_all_keys(), Ok)
378 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000379
380 fn getAppUidsAffectedBySid(
381 &self,
382 user_id: i32,
383 secure_user_id: i64,
384 ) -> BinderResult<std::vec::Vec<i64>> {
385 log::info!("getAppUidsAffectedBySid(secure_user_id={secure_user_id:?})");
386 let _wp = wd::watch_millis("IKeystoreMaintenance::getAppUidsAffectedBySid", 500);
387 map_or_log_err(Self::get_app_uids_affected_by_sid(user_id, secure_user_id), Ok)
388 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000389}