blob: 8780e9e98844704aa7c9f02bf3fd26b553207e1c [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};
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 Danisevskiscdcf4e52021-04-14 15:44:36 -0700227 fn migrate_key_namespace(source: &KeyDescriptor, destination: &KeyDescriptor) -> Result<()> {
John Wu889c1cc2022-03-14 16:02:56 -0700228 let calling_uid = ThreadState::get_calling_uid();
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700229
John Wu889c1cc2022-03-14 16:02:56 -0700230 match source.domain {
231 Domain::SELINUX | Domain::KEY_ID | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800232 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000233 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
234 .context(ks_err!("Source domain must be one of APP, SELINUX, or KEY_ID."));
John Wu16db29e2022-01-13 15:21:43 -0800235 }
236 };
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700237
John Wu889c1cc2022-03-14 16:02:56 -0700238 match destination.domain {
239 Domain::SELINUX | 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!("Destination domain must be one of APP or SELINUX."));
John Wu16db29e2022-01-13 15:21:43 -0800243 }
244 };
245
John Wu889c1cc2022-03-14 16:02:56 -0700246 let user_id = uid_to_android_user(calling_uid);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800247
Eric Biggers673d34a2023-10-18 01:54:18 +0000248 let super_key = SUPER_KEY.read().unwrap().get_after_first_unlock_key_by_user_id(user_id);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800249
250 DB.with(|db| {
John Wu889c1cc2022-03-14 16:02:56 -0700251 let (key_id_guard, _) = LEGACY_IMPORTER
252 .with_try_import(source, calling_uid, super_key, || {
253 db.borrow_mut().load_key_entry(
254 source,
255 KeyType::Client,
256 KeyEntryLoadBits::NONE,
257 calling_uid,
258 |k, av| {
259 check_key_permission(KeyPerm::Use, k, &av)?;
260 check_key_permission(KeyPerm::Delete, k, &av)?;
261 check_key_permission(KeyPerm::Grant, k, &av)
262 },
263 )
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800264 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000265 .context(ks_err!("Failed to load key blob."))?;
John Wu889c1cc2022-03-14 16:02:56 -0700266 {
267 db.borrow_mut().migrate_key_namespace(key_id_guard, destination, calling_uid, |k| {
268 check_key_permission(KeyPerm::Rebind, k, &None)
269 })
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800270 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700271 })
272 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700273
274 fn delete_all_keys() -> Result<()> {
275 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700276 check_keystore_permission(KeystorePerm::DeleteAllKeys)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000277 .context(ks_err!("Checking permission"))?;
Paul Crowley46c703e2021-08-06 15:13:53 -0700278 log::info!("In delete_all_keys.");
279
280 Maintenance::call_on_all_security_levels("deleteAllKeys", |dev| dev.deleteAllKeys())
281 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000282
283 fn get_app_uids_affected_by_sid(
284 user_id: i32,
285 secure_user_id: i64,
286 ) -> Result<std::vec::Vec<i64>> {
287 // This method is intended to be called by Settings and discloses a list of apps
Eran Messericfe79f12024-02-05 17:50:41 +0000288 // associated with a user, so it requires the "android.permission.MANAGE_USERS"
289 // permission (to avoid leaking list of apps to unauthorized callers).
290 check_get_app_uids_affected_by_sid_permissions().context(ks_err!())?;
Eran Messeri4dc27b52024-01-09 12:43:31 +0000291 DB.with(|db| db.borrow_mut().get_app_uids_affected_by_sid(user_id, secure_user_id))
292 .context(ks_err!("Failed to get app UIDs affected by SID"))
293 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000294}
295
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800296impl Interface for Maintenance {}
Hasini Gunasingheda895552021-01-27 19:34:37 +0000297
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800298impl IKeystoreMaintenance for Maintenance {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000299 fn onUserPasswordChanged(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100300 log::info!(
301 "onUserPasswordChanged(user={}, password.is_some()={})",
302 user_id,
303 password.is_some()
304 );
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000305 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserPasswordChanged", 500);
Paul Crowleyf61fee72021-03-17 14:38:44 -0700306 map_or_log_err(Self::on_user_password_changed(user_id, password.map(|pw| pw.into())), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000307 }
308
309 fn onUserAdded(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100310 log::info!("onUserAdded(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000311 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserAdded", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700312 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000313 }
314
Eric Biggersb0478cf2023-10-27 03:55:29 +0000315 fn initUserSuperKeys(
316 &self,
317 user_id: i32,
318 password: &[u8],
319 allow_existing: bool,
320 ) -> BinderResult<()> {
321 log::info!("initUserSuperKeys(user={user_id}, allow_existing={allow_existing})");
322 let _wp = wd::watch_millis("IKeystoreMaintenance::initUserSuperKeys", 500);
323 map_or_log_err(self.init_user_super_keys(user_id, password.into(), allow_existing), Ok)
324 }
325
Hasini Gunasingheda895552021-01-27 19:34:37 +0000326 fn onUserRemoved(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100327 log::info!("onUserRemoved(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000328 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserRemoved", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700329 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000330 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800331
Eric Biggersb0478cf2023-10-27 03:55:29 +0000332 fn onUserLskfRemoved(&self, user_id: i32) -> BinderResult<()> {
333 log::info!("onUserLskfRemoved(user={user_id})");
334 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserLskfRemoved", 500);
335 map_or_log_err(Self::on_user_lskf_removed(user_id), Ok)
336 }
337
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800338 fn clearNamespace(&self, domain: Domain, nspace: i64) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100339 log::info!("clearNamespace({domain:?}, nspace={nspace})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000340 let _wp = wd::watch_millis("IKeystoreMaintenance::clearNamespace", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700341 map_or_log_err(self.clear_namespace(domain, nspace), Ok)
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800342 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000343
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800344 fn earlyBootEnded(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100345 log::info!("earlyBootEnded()");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000346 let _wp = wd::watch_millis("IKeystoreMaintenance::earlyBootEnded", 500);
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800347 map_or_log_err(Self::early_boot_ended(), Ok)
348 }
349
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700350 fn migrateKeyNamespace(
351 &self,
352 source: &KeyDescriptor,
353 destination: &KeyDescriptor,
354 ) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100355 log::info!("migrateKeyNamespace(src={source:?}, dest={destination:?})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000356 let _wp = wd::watch_millis("IKeystoreMaintenance::migrateKeyNamespace", 500);
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700357 map_or_log_err(Self::migrate_key_namespace(source, destination), Ok)
358 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700359
360 fn deleteAllKeys(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100361 log::warn!("deleteAllKeys()");
Paul Crowley46c703e2021-08-06 15:13:53 -0700362 let _wp = wd::watch_millis("IKeystoreMaintenance::deleteAllKeys", 500);
363 map_or_log_err(Self::delete_all_keys(), Ok)
364 }
Eran Messeri4dc27b52024-01-09 12:43:31 +0000365
366 fn getAppUidsAffectedBySid(
367 &self,
368 user_id: i32,
369 secure_user_id: i64,
370 ) -> BinderResult<std::vec::Vec<i64>> {
371 log::info!("getAppUidsAffectedBySid(secure_user_id={secure_user_id:?})");
372 let _wp = wd::watch_millis("IKeystoreMaintenance::getAppUidsAffectedBySid", 500);
373 map_or_log_err(Self::get_app_uids_affected_by_sid(user_id, secure_user_id), Ok)
374 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000375}