blob: 74858de1d062af753ae2360a546886ac53d1c779 [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
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -070017use crate::database::{KeyEntryLoadBits, KeyType, MonotonicRawTime};
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::{
John Wu889c1cc2022-03-14 16:02:56 -070027 check_key_permission, check_keystore_permission, uid_to_android_user, watchdog as wd,
John Wu16db29e2022-01-13 15:21:43 -080028};
Paul Crowley46c703e2021-08-06 15:13:53 -070029use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
30 IKeyMintDevice::IKeyMintDevice, SecurityLevel::SecurityLevel,
31};
Eric Biggers2f9498a2023-10-09 23:16:05 +000032use android_security_maintenance::aidl::android::security::maintenance::IKeystoreMaintenance::{
33 BnKeystoreMaintenance, IKeystoreMaintenance,
Hasini Gunasingheda895552021-01-27 19:34:37 +000034};
Andrew Walbrande45c8b2021-04-13 14:42:38 +000035use android_security_maintenance::binder::{
36 BinderFeatures, Interface, Result as BinderResult, Strong, ThreadState,
37};
Janis Danisevskis5898d152021-06-15 08:23:46 -070038use android_system_keystore2::aidl::android::system::keystore2::KeyDescriptor::KeyDescriptor;
Hasini Gunasingheda895552021-01-27 19:34:37 +000039use android_system_keystore2::aidl::android::system::keystore2::ResponseCode::ResponseCode;
40use anyhow::{Context, Result};
Paul Crowleyf61fee72021-03-17 14:38:44 -070041use keystore2_crypto::Password;
Hasini Gunasingheda895552021-01-27 19:34:37 +000042
Janis Danisevskis5898d152021-06-15 08:23:46 -070043/// Reexport Domain for the benefit of DeleteListener
44pub use android_system_keystore2::aidl::android::system::keystore2::Domain::Domain;
45
46/// The Maintenance module takes a delete listener argument which observes user and namespace
47/// deletion events.
48pub trait DeleteListener {
49 /// Called by the maintenance module when an app/namespace is deleted.
50 fn delete_namespace(&self, domain: Domain, namespace: i64) -> Result<()>;
51 /// Called by the maintenance module when a user is deleted.
52 fn delete_user(&self, user_id: u32) -> Result<()>;
53}
54
Hasini Gunasingheda895552021-01-27 19:34:37 +000055/// This struct is defined to implement the aforementioned AIDL interface.
Janis Danisevskis5898d152021-06-15 08:23:46 -070056pub struct Maintenance {
57 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
58}
Hasini Gunasingheda895552021-01-27 19:34:37 +000059
Janis Danisevskis34a0cf22021-03-08 09:19:03 -080060impl Maintenance {
Janis Danisevskis5898d152021-06-15 08:23:46 -070061 /// Create a new instance of Keystore Maintenance service.
62 pub fn new_native_binder(
63 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
64 ) -> Result<Strong<dyn IKeystoreMaintenance>> {
Andrew Walbrande45c8b2021-04-13 14:42:38 +000065 Ok(BnKeystoreMaintenance::new_binder(
Janis Danisevskis5898d152021-06-15 08:23:46 -070066 Self { delete_listener },
Andrew Walbrande45c8b2021-04-13 14:42:38 +000067 BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
68 ))
Hasini Gunasingheda895552021-01-27 19:34:37 +000069 }
70
Paul Crowleyf61fee72021-03-17 14:38:44 -070071 fn on_user_password_changed(user_id: i32, password: Option<Password>) -> Result<()> {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080072 // Check permission. Function should return if this failed. Therefore having '?' at the end
73 // is very important.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +000074 check_keystore_permission(KeystorePerm::ChangePassword).context(ks_err!())?;
Hasini Gunasingheda895552021-01-27 19:34:37 +000075
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080076 let mut skm = SUPER_KEY.write().unwrap();
77
Paul Crowley7a658392021-03-18 17:08:20 -070078 if let Some(pw) = password.as_ref() {
79 DB.with(|db| {
Eric Biggersb1f641d2023-10-18 01:54:18 +000080 skm.unlock_unlocked_device_required_keys(&mut db.borrow_mut(), user_id as u32, pw)
Paul Crowley7a658392021-03-18 17:08:20 -070081 })
Eric Biggersb1f641d2023-10-18 01:54:18 +000082 .context(ks_err!("unlock_unlocked_device_required_keys failed"))?;
Paul Crowley7a658392021-03-18 17:08:20 -070083 }
84
Eric Biggers13869372023-10-18 01:54:18 +000085 if let UserState::BeforeFirstUnlock = DB
Nathan Huckleberry204a0442023-03-30 17:27:47 +000086 .with(|db| skm.get_user_state(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32))
87 .context(ks_err!("Could not get user state while changing password!"))?
Hasini Gunasingheda895552021-01-27 19:34:37 +000088 {
Nathan Huckleberry204a0442023-03-30 17:27:47 +000089 // Error - password can not be changed when the device is locked
90 return Err(Error::Rc(ResponseCode::LOCKED)).context(ks_err!("Device is locked."));
Hasini Gunasingheda895552021-01-27 19:34:37 +000091 }
Nathan Huckleberry204a0442023-03-30 17:27:47 +000092
93 DB.with(|db| match password {
94 Some(pass) => {
95 skm.init_user(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32, &pass)
96 }
97 None => {
98 // User transitioned to swipe.
99 skm.reset_user(&mut db.borrow_mut(), &LEGACY_IMPORTER, user_id as u32)
100 }
101 })
102 .context(ks_err!("Failed to change user password!"))
Hasini Gunasingheda895552021-01-27 19:34:37 +0000103 }
104
Janis Danisevskis5898d152021-06-15 08:23:46 -0700105 fn add_or_remove_user(&self, user_id: i32) -> Result<()> {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000106 // Check permission. Function should return if this failed. Therefore having '?' at the end
107 // is very important.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000108 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800109
Janis Danisevskiseed69842021-02-18 20:04:10 -0800110 DB.with(|db| {
Nathan Huckleberry204a0442023-03-30 17:27:47 +0000111 SUPER_KEY.write().unwrap().remove_user(
Janis Danisevskiseed69842021-02-18 20:04:10 -0800112 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800113 &LEGACY_IMPORTER,
Janis Danisevskiseed69842021-02-18 20:04:10 -0800114 user_id as u32,
Janis Danisevskiseed69842021-02-18 20:04:10 -0800115 )
116 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000117 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -0700118 self.delete_listener
119 .delete_user(user_id as u32)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000120 .context(ks_err!("While invoking the delete listener."))
Hasini Gunasingheda895552021-01-27 19:34:37 +0000121 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800122
Eric Biggersb0478cf2023-10-27 03:55:29 +0000123 fn init_user_super_keys(
124 &self,
125 user_id: i32,
126 password: Password,
127 allow_existing: bool,
128 ) -> Result<()> {
129 // Permission check. Must return on error. Do not touch the '?'.
130 check_keystore_permission(KeystorePerm::ChangeUser).context(ks_err!())?;
131
132 let mut skm = SUPER_KEY.write().unwrap();
133 DB.with(|db| {
134 skm.initialize_user(
135 &mut db.borrow_mut(),
136 &LEGACY_IMPORTER,
137 user_id as u32,
138 &password,
139 allow_existing,
140 )
141 })
142 .context(ks_err!("Failed to initialize user super keys"))
143 }
144
145 // Deletes all auth-bound keys when the user's LSKF is removed.
146 fn on_user_lskf_removed(user_id: i32) -> Result<()> {
147 // Permission check. Must return on error. Do not touch the '?'.
148 check_keystore_permission(KeystorePerm::ChangePassword).context(ks_err!())?;
149
150 LEGACY_IMPORTER
151 .bulk_delete_user(user_id as u32, true)
152 .context(ks_err!("Failed to delete legacy keys."))?;
153
154 DB.with(|db| db.borrow_mut().unbind_auth_bound_keys_for_user(user_id as u32))
155 .context(ks_err!("Failed to delete auth-bound keys."))
156 }
157
Janis Danisevskis5898d152021-06-15 08:23:46 -0700158 fn clear_namespace(&self, domain: Domain, nspace: i64) -> Result<()> {
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800159 // Permission check. Must return on error. Do not touch the '?'.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700160 check_keystore_permission(KeystorePerm::ClearUID).context("In clear_namespace.")?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800161
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800162 LEGACY_IMPORTER
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800163 .bulk_delete_uid(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000164 .context(ks_err!("Trying to delete legacy keys."))?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800165 DB.with(|db| db.borrow_mut().unbind_keys_for_namespace(domain, nspace))
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000166 .context(ks_err!("Trying to delete keys from db."))?;
Janis Danisevskis5898d152021-06-15 08:23:46 -0700167 self.delete_listener
168 .delete_namespace(domain, nspace)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000169 .context(ks_err!("While invoking the delete listener."))
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800170 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000171
Paul Crowley46c703e2021-08-06 15:13:53 -0700172 fn call_with_watchdog<F>(sec_level: SecurityLevel, name: &'static str, op: &F) -> Result<()>
173 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000174 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700175 {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000176 let (km_dev, _, _) =
177 get_keymint_device(&sec_level).context(ks_err!("getting keymint device"))?;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700178
Paul Crowley46c703e2021-08-06 15:13:53 -0700179 let _wp = wd::watch_millis_with("In call_with_watchdog", 500, move || {
180 format!("Seclevel: {:?} Op: {}", sec_level, name)
181 });
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000182 map_km_error(op(km_dev)).with_context(|| ks_err!("calling {}", name))?;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800183 Ok(())
184 }
185
Paul Crowley46c703e2021-08-06 15:13:53 -0700186 fn call_on_all_security_levels<F>(name: &'static str, op: F) -> Result<()>
187 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000188 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700189 {
190 let sec_levels = [
191 (SecurityLevel::TRUSTED_ENVIRONMENT, "TRUSTED_ENVIRONMENT"),
192 (SecurityLevel::STRONGBOX, "STRONGBOX"),
193 ];
James Farrelld77b97f2023-08-15 20:03:38 +0000194 sec_levels.iter().try_fold((), |_result, (sec_level, sec_level_string)| {
Paul Crowley46c703e2021-08-06 15:13:53 -0700195 let curr_result = Maintenance::call_with_watchdog(*sec_level, name, &op);
196 match curr_result {
197 Ok(()) => log::info!(
198 "Call to {} succeeded for security level {}.",
199 name,
200 &sec_level_string
201 ),
202 Err(ref e) => log::error!(
203 "Call to {} failed for security level {}: {}.",
204 name,
205 &sec_level_string,
206 e
207 ),
208 }
James Farrelld77b97f2023-08-15 20:03:38 +0000209 curr_result
Paul Crowley46c703e2021-08-06 15:13:53 -0700210 })
211 }
212
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800213 fn early_boot_ended() -> Result<()> {
Janis Danisevskisa916d992021-10-19 15:46:09 -0700214 check_keystore_permission(KeystorePerm::EarlyBootEnded)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000215 .context(ks_err!("Checking permission"))?;
Paul Crowley44c02da2021-04-08 17:04:43 +0000216 log::info!("In early_boot_ended.");
217
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800218 if let Err(e) =
219 DB.with(|db| SuperKeyManager::set_up_boot_level_cache(&SUPER_KEY, &mut db.borrow_mut()))
220 {
Paul Crowley44c02da2021-04-08 17:04:43 +0000221 log::error!("SUPER_KEY.set_up_boot_level_cache failed:\n{:?}\n:(", e);
222 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700223 Maintenance::call_on_all_security_levels("earlyBootEnded", |dev| dev.earlyBootEnded())
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800224 }
225
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700226 fn on_device_off_body() -> Result<()> {
227 // Security critical permission check. This statement must return on fail.
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000228 check_keystore_permission(KeystorePerm::ReportOffBody).context(ks_err!())?;
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700229
Matthew Maurerd7815ca2021-05-06 21:58:45 -0700230 DB.with(|db| db.borrow_mut().update_last_off_body(MonotonicRawTime::now()));
231 Ok(())
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700232 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700233
234 fn migrate_key_namespace(source: &KeyDescriptor, destination: &KeyDescriptor) -> Result<()> {
John Wu889c1cc2022-03-14 16:02:56 -0700235 let calling_uid = ThreadState::get_calling_uid();
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700236
John Wu889c1cc2022-03-14 16:02:56 -0700237 match source.domain {
238 Domain::SELINUX | Domain::KEY_ID | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800239 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000240 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
241 .context(ks_err!("Source domain must be one of APP, SELINUX, or KEY_ID."));
John Wu16db29e2022-01-13 15:21:43 -0800242 }
243 };
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700244
John Wu889c1cc2022-03-14 16:02:56 -0700245 match destination.domain {
246 Domain::SELINUX | Domain::APP => (),
John Wu16db29e2022-01-13 15:21:43 -0800247 _ => {
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000248 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT))
249 .context(ks_err!("Destination domain must be one of APP or SELINUX."));
John Wu16db29e2022-01-13 15:21:43 -0800250 }
251 };
252
John Wu889c1cc2022-03-14 16:02:56 -0700253 let user_id = uid_to_android_user(calling_uid);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800254
Eric Biggers673d34a2023-10-18 01:54:18 +0000255 let super_key = SUPER_KEY.read().unwrap().get_after_first_unlock_key_by_user_id(user_id);
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800256
257 DB.with(|db| {
John Wu889c1cc2022-03-14 16:02:56 -0700258 let (key_id_guard, _) = LEGACY_IMPORTER
259 .with_try_import(source, calling_uid, super_key, || {
260 db.borrow_mut().load_key_entry(
261 source,
262 KeyType::Client,
263 KeyEntryLoadBits::NONE,
264 calling_uid,
265 |k, av| {
266 check_key_permission(KeyPerm::Use, k, &av)?;
267 check_key_permission(KeyPerm::Delete, k, &av)?;
268 check_key_permission(KeyPerm::Grant, k, &av)
269 },
270 )
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800271 })
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000272 .context(ks_err!("Failed to load key blob."))?;
John Wu889c1cc2022-03-14 16:02:56 -0700273 {
274 db.borrow_mut().migrate_key_namespace(key_id_guard, destination, calling_uid, |k| {
275 check_key_permission(KeyPerm::Rebind, k, &None)
276 })
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800277 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700278 })
279 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700280
281 fn delete_all_keys() -> Result<()> {
282 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700283 check_keystore_permission(KeystorePerm::DeleteAllKeys)
Shaquille Johnson9da2e1c2022-09-19 12:39:01 +0000284 .context(ks_err!("Checking permission"))?;
Paul Crowley46c703e2021-08-06 15:13:53 -0700285 log::info!("In delete_all_keys.");
286
287 Maintenance::call_on_all_security_levels("deleteAllKeys", |dev| dev.deleteAllKeys())
288 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000289}
290
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800291impl Interface for Maintenance {}
Hasini Gunasingheda895552021-01-27 19:34:37 +0000292
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800293impl IKeystoreMaintenance for Maintenance {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000294 fn onUserPasswordChanged(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100295 log::info!(
296 "onUserPasswordChanged(user={}, password.is_some()={})",
297 user_id,
298 password.is_some()
299 );
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000300 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserPasswordChanged", 500);
Paul Crowleyf61fee72021-03-17 14:38:44 -0700301 map_or_log_err(Self::on_user_password_changed(user_id, password.map(|pw| pw.into())), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000302 }
303
304 fn onUserAdded(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100305 log::info!("onUserAdded(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000306 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserAdded", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700307 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000308 }
309
Eric Biggersb0478cf2023-10-27 03:55:29 +0000310 fn initUserSuperKeys(
311 &self,
312 user_id: i32,
313 password: &[u8],
314 allow_existing: bool,
315 ) -> BinderResult<()> {
316 log::info!("initUserSuperKeys(user={user_id}, allow_existing={allow_existing})");
317 let _wp = wd::watch_millis("IKeystoreMaintenance::initUserSuperKeys", 500);
318 map_or_log_err(self.init_user_super_keys(user_id, password.into(), allow_existing), Ok)
319 }
320
Hasini Gunasingheda895552021-01-27 19:34:37 +0000321 fn onUserRemoved(&self, user_id: i32) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100322 log::info!("onUserRemoved(user={user_id})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000323 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserRemoved", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700324 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000325 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800326
Eric Biggersb0478cf2023-10-27 03:55:29 +0000327 fn onUserLskfRemoved(&self, user_id: i32) -> BinderResult<()> {
328 log::info!("onUserLskfRemoved(user={user_id})");
329 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserLskfRemoved", 500);
330 map_or_log_err(Self::on_user_lskf_removed(user_id), Ok)
331 }
332
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800333 fn clearNamespace(&self, domain: Domain, nspace: i64) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100334 log::info!("clearNamespace({domain:?}, nspace={nspace})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000335 let _wp = wd::watch_millis("IKeystoreMaintenance::clearNamespace", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700336 map_or_log_err(self.clear_namespace(domain, nspace), Ok)
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800337 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000338
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800339 fn earlyBootEnded(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100340 log::info!("earlyBootEnded()");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000341 let _wp = wd::watch_millis("IKeystoreMaintenance::earlyBootEnded", 500);
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800342 map_or_log_err(Self::early_boot_ended(), Ok)
343 }
344
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700345 fn onDeviceOffBody(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100346 log::info!("onDeviceOffBody()");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000347 let _wp = wd::watch_millis("IKeystoreMaintenance::onDeviceOffBody", 500);
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700348 map_or_log_err(Self::on_device_off_body(), Ok)
349 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700350
351 fn migrateKeyNamespace(
352 &self,
353 source: &KeyDescriptor,
354 destination: &KeyDescriptor,
355 ) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100356 log::info!("migrateKeyNamespace(src={source:?}, dest={destination:?})");
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000357 let _wp = wd::watch_millis("IKeystoreMaintenance::migrateKeyNamespace", 500);
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700358 map_or_log_err(Self::migrate_key_namespace(source, destination), Ok)
359 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700360
361 fn deleteAllKeys(&self) -> BinderResult<()> {
David Drysdalee85523f2023-06-19 12:28:53 +0100362 log::warn!("deleteAllKeys()");
Paul Crowley46c703e2021-08-06 15:13:53 -0700363 let _wp = wd::watch_millis("IKeystoreMaintenance::deleteAllKeys", 500);
364 map_or_log_err(Self::delete_all_keys(), Ok)
365 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000366}