blob: 0d637d8e1c8bb1adc99fef6a74e39acdaea1c26e [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};
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -070023use crate::permission::{KeyPerm, KeystorePerm};
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080024use crate::super_key::{SuperKeyManager, UserState};
John Wu16db29e2022-01-13 15:21:43 -080025use crate::utils::{
Janis Danisevskisf84d0b02022-01-26 14:11:14 -080026 check_key_permission, check_keystore_permission, list_key_entries, uid_to_android_user,
27 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};
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +000032use android_security_maintenance::aidl::android::security::maintenance::{
John Wu16db29e2022-01-13 15:21:43 -080033 IKeystoreMaintenance::{BnKeystoreMaintenance, IKeystoreMaintenance, UID_SELF},
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +000034 UserState::UserState as AidlUserState,
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;
John Wu16db29e2022-01-13 15:21:43 -080043use keystore2_selinux as selinux;
Hasini Gunasingheda895552021-01-27 19:34:37 +000044
Janis Danisevskis5898d152021-06-15 08:23:46 -070045/// Reexport Domain for the benefit of DeleteListener
46pub use android_system_keystore2::aidl::android::system::keystore2::Domain::Domain;
47
48/// The Maintenance module takes a delete listener argument which observes user and namespace
49/// deletion events.
50pub trait DeleteListener {
51 /// Called by the maintenance module when an app/namespace is deleted.
52 fn delete_namespace(&self, domain: Domain, namespace: i64) -> Result<()>;
53 /// Called by the maintenance module when a user is deleted.
54 fn delete_user(&self, user_id: u32) -> Result<()>;
55}
56
Hasini Gunasingheda895552021-01-27 19:34:37 +000057/// This struct is defined to implement the aforementioned AIDL interface.
Janis Danisevskis5898d152021-06-15 08:23:46 -070058pub struct Maintenance {
59 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
60}
Hasini Gunasingheda895552021-01-27 19:34:37 +000061
Janis Danisevskis34a0cf22021-03-08 09:19:03 -080062impl Maintenance {
Janis Danisevskis5898d152021-06-15 08:23:46 -070063 /// Create a new instance of Keystore Maintenance service.
64 pub fn new_native_binder(
65 delete_listener: Box<dyn DeleteListener + Send + Sync + 'static>,
66 ) -> Result<Strong<dyn IKeystoreMaintenance>> {
Andrew Walbrande45c8b2021-04-13 14:42:38 +000067 Ok(BnKeystoreMaintenance::new_binder(
Janis Danisevskis5898d152021-06-15 08:23:46 -070068 Self { delete_listener },
Andrew Walbrande45c8b2021-04-13 14:42:38 +000069 BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
70 ))
Hasini Gunasingheda895552021-01-27 19:34:37 +000071 }
72
Paul Crowleyf61fee72021-03-17 14:38:44 -070073 fn on_user_password_changed(user_id: i32, password: Option<Password>) -> Result<()> {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080074 // Check permission. Function should return if this failed. Therefore having '?' at the end
75 // is very important.
Janis Danisevskisa916d992021-10-19 15:46:09 -070076 check_keystore_permission(KeystorePerm::ChangePassword)
Hasini Gunasingheda895552021-01-27 19:34:37 +000077 .context("In on_user_password_changed.")?;
78
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080079 let mut skm = SUPER_KEY.write().unwrap();
80
Paul Crowley7a658392021-03-18 17:08:20 -070081 if let Some(pw) = password.as_ref() {
82 DB.with(|db| {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080083 skm.unlock_screen_lock_bound_key(&mut db.borrow_mut(), user_id as u32, pw)
Paul Crowley7a658392021-03-18 17:08:20 -070084 })
Paul Crowley8d5b2532021-03-19 10:53:07 -070085 .context("In on_user_password_changed: unlock_screen_lock_bound_key failed")?;
Paul Crowley7a658392021-03-18 17:08:20 -070086 }
87
Hasini Gunasingheda895552021-01-27 19:34:37 +000088 match DB
89 .with(|db| {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -080090 skm.reset_or_init_user_and_get_user_state(
Hasini Gunasingheda895552021-01-27 19:34:37 +000091 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -080092 &LEGACY_IMPORTER,
Hasini Gunasingheda895552021-01-27 19:34:37 +000093 user_id as u32,
Paul Crowleyf61fee72021-03-17 14:38:44 -070094 password.as_ref(),
Hasini Gunasingheda895552021-01-27 19:34:37 +000095 )
96 })
97 .context("In on_user_password_changed.")?
98 {
99 UserState::LskfLocked => {
Janis Danisevskiseed69842021-02-18 20:04:10 -0800100 // Error - password can not be changed when the device is locked
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700101 Err(Error::Rc(ResponseCode::LOCKED))
Hasini Gunasingheda895552021-01-27 19:34:37 +0000102 .context("In on_user_password_changed. Device is locked.")
103 }
104 _ => {
Janis Danisevskiseed69842021-02-18 20:04:10 -0800105 // LskfLocked is the only error case for password change
Hasini Gunasingheda895552021-01-27 19:34:37 +0000106 Ok(())
107 }
108 }
109 }
110
Janis Danisevskis5898d152021-06-15 08:23:46 -0700111 fn add_or_remove_user(&self, user_id: i32) -> Result<()> {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000112 // Check permission. Function should return if this failed. Therefore having '?' at the end
113 // is very important.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700114 check_keystore_permission(KeystorePerm::ChangeUser).context("In add_or_remove_user.")?;
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800115
Janis Danisevskiseed69842021-02-18 20:04:10 -0800116 DB.with(|db| {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800117 SUPER_KEY.write().unwrap().reset_user(
Janis Danisevskiseed69842021-02-18 20:04:10 -0800118 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800119 &LEGACY_IMPORTER,
Janis Danisevskiseed69842021-02-18 20:04:10 -0800120 user_id as u32,
121 false,
122 )
123 })
Janis Danisevskis5898d152021-06-15 08:23:46 -0700124 .context("In add_or_remove_user: Trying to delete keys from db.")?;
125 self.delete_listener
126 .delete_user(user_id as u32)
127 .context("In add_or_remove_user: While invoking the delete listener.")
Hasini Gunasingheda895552021-01-27 19:34:37 +0000128 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800129
Janis Danisevskis5898d152021-06-15 08:23:46 -0700130 fn clear_namespace(&self, domain: Domain, nspace: i64) -> Result<()> {
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800131 // Permission check. Must return on error. Do not touch the '?'.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700132 check_keystore_permission(KeystorePerm::ClearUID).context("In clear_namespace.")?;
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800133
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800134 LEGACY_IMPORTER
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800135 .bulk_delete_uid(domain, nspace)
136 .context("In clear_namespace: Trying to delete legacy keys.")?;
137 DB.with(|db| db.borrow_mut().unbind_keys_for_namespace(domain, nspace))
Janis Danisevskis5898d152021-06-15 08:23:46 -0700138 .context("In clear_namespace: Trying to delete keys from db.")?;
139 self.delete_listener
140 .delete_namespace(domain, nspace)
141 .context("In clear_namespace: While invoking the delete listener.")
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800142 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000143
144 fn get_state(user_id: i32) -> Result<AidlUserState> {
145 // Check permission. Function should return if this failed. Therefore having '?' at the end
146 // is very important.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700147 check_keystore_permission(KeystorePerm::GetState).context("In get_state.")?;
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000148 let state = DB
149 .with(|db| {
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800150 SUPER_KEY.read().unwrap().get_user_state(
151 &mut db.borrow_mut(),
Janis Danisevskis0ffb8a82022-02-06 22:37:21 -0800152 &LEGACY_IMPORTER,
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800153 user_id as u32,
154 )
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000155 })
156 .context("In get_state. Trying to get UserState.")?;
157
158 match state {
159 UserState::Uninitialized => Ok(AidlUserState::UNINITIALIZED),
160 UserState::LskfUnlocked(_) => Ok(AidlUserState::LSKF_UNLOCKED),
161 UserState::LskfLocked => Ok(AidlUserState::LSKF_LOCKED),
162 }
163 }
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700164
Paul Crowley46c703e2021-08-06 15:13:53 -0700165 fn call_with_watchdog<F>(sec_level: SecurityLevel, name: &'static str, op: &F) -> Result<()>
166 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000167 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700168 {
Janis Danisevskis5f3a0572021-06-18 11:26:42 -0700169 let (km_dev, _, _) = get_keymint_device(&sec_level)
Paul Crowley46c703e2021-08-06 15:13:53 -0700170 .context("In call_with_watchdog: getting keymint device")?;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700171
Paul Crowley46c703e2021-08-06 15:13:53 -0700172 let _wp = wd::watch_millis_with("In call_with_watchdog", 500, move || {
173 format!("Seclevel: {:?} Op: {}", sec_level, name)
174 });
175 map_km_error(op(km_dev)).with_context(|| format!("In keymint device: calling {}", name))?;
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800176 Ok(())
177 }
178
Paul Crowley46c703e2021-08-06 15:13:53 -0700179 fn call_on_all_security_levels<F>(name: &'static str, op: F) -> Result<()>
180 where
Stephen Crane23cf7242022-01-19 17:49:46 +0000181 F: Fn(Strong<dyn IKeyMintDevice>) -> binder::Result<()>,
Paul Crowley46c703e2021-08-06 15:13:53 -0700182 {
183 let sec_levels = [
184 (SecurityLevel::TRUSTED_ENVIRONMENT, "TRUSTED_ENVIRONMENT"),
185 (SecurityLevel::STRONGBOX, "STRONGBOX"),
186 ];
187 sec_levels.iter().fold(Ok(()), move |result, (sec_level, sec_level_string)| {
188 let curr_result = Maintenance::call_with_watchdog(*sec_level, name, &op);
189 match curr_result {
190 Ok(()) => log::info!(
191 "Call to {} succeeded for security level {}.",
192 name,
193 &sec_level_string
194 ),
195 Err(ref e) => log::error!(
196 "Call to {} failed for security level {}: {}.",
197 name,
198 &sec_level_string,
199 e
200 ),
201 }
202 result.and(curr_result)
203 })
204 }
205
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800206 fn early_boot_ended() -> Result<()> {
Janis Danisevskisa916d992021-10-19 15:46:09 -0700207 check_keystore_permission(KeystorePerm::EarlyBootEnded)
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800208 .context("In early_boot_ended. Checking permission")?;
Paul Crowley44c02da2021-04-08 17:04:43 +0000209 log::info!("In early_boot_ended.");
210
Janis Danisevskis0fd25a62022-01-04 19:53:37 -0800211 if let Err(e) =
212 DB.with(|db| SuperKeyManager::set_up_boot_level_cache(&SUPER_KEY, &mut db.borrow_mut()))
213 {
Paul Crowley44c02da2021-04-08 17:04:43 +0000214 log::error!("SUPER_KEY.set_up_boot_level_cache failed:\n{:?}\n:(", e);
215 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700216 Maintenance::call_on_all_security_levels("earlyBootEnded", |dev| dev.earlyBootEnded())
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800217 }
218
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700219 fn on_device_off_body() -> Result<()> {
220 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700221 check_keystore_permission(KeystorePerm::ReportOffBody).context("In on_device_off_body.")?;
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700222
Matthew Maurerd7815ca2021-05-06 21:58:45 -0700223 DB.with(|db| db.borrow_mut().update_last_off_body(MonotonicRawTime::now()));
224 Ok(())
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700225 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700226
227 fn migrate_key_namespace(source: &KeyDescriptor, destination: &KeyDescriptor) -> Result<()> {
Ashwini Orugantidaf73bc2021-11-15 10:46:31 -0800228 let migrate_any_key_permission =
229 check_keystore_permission(KeystorePerm::MigrateAnyKey).is_ok();
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700230
John Wu16db29e2022-01-13 15:21:43 -0800231 let src_uid = match source.domain {
232 Domain::SELINUX | Domain::KEY_ID => ThreadState::get_calling_uid(),
233 Domain::APP if source.nspace == UID_SELF.into() => ThreadState::get_calling_uid(),
234 Domain::APP if source.nspace != UID_SELF.into() && migrate_any_key_permission => {
235 source.nspace as u32
236 }
237 _ => {
238 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT)).context(
Janis Danisevskis478a9a22022-01-28 08:22:59 -0800239 "In migrate_key_namespace: \
John Wu16db29e2022-01-13 15:21:43 -0800240 Source domain must be one of APP, SELINUX, or KEY_ID.",
241 )
242 }
243 };
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700244
John Wu16db29e2022-01-13 15:21:43 -0800245 let dest_uid = match destination.domain {
246 Domain::SELINUX => ThreadState::get_calling_uid(),
247 Domain::APP if destination.nspace == UID_SELF.into() => ThreadState::get_calling_uid(),
248 Domain::APP if destination.nspace != UID_SELF.into() && migrate_any_key_permission => {
249 destination.nspace as u32
250 }
251 _ => {
252 return Err(Error::Rc(ResponseCode::INVALID_ARGUMENT)).context(
Janis Danisevskis478a9a22022-01-28 08:22:59 -0800253 "In migrate_key_namespace: \
John Wu16db29e2022-01-13 15:21:43 -0800254 Destination domain must be one of APP or SELINUX.",
255 )
256 }
257 };
258
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800259 let user_id = uid_to_android_user(dest_uid);
John Wu16db29e2022-01-13 15:21:43 -0800260
Janis Danisevskisf84d0b02022-01-26 14:11:14 -0800261 if user_id != uid_to_android_user(src_uid)
262 && (source.domain == Domain::APP || destination.domain == Domain::APP)
263 {
264 return Err(Error::sys()).context(
265 "In migrate_key_namespace: Keys cannot be migrated across android users.",
266 );
267 }
268
269 let super_key = SUPER_KEY.read().unwrap().get_per_boot_key_by_user_id(user_id);
270
271 DB.with(|db| {
272 if let Some((key_id_guard, _)) = LEGACY_IMPORTER
273 .with_try_import_or_migrate_namespaces(
274 (src_uid, source),
275 (dest_uid, destination),
276 super_key,
277 migrate_any_key_permission,
278 || {
279 db.borrow_mut().load_key_entry(
280 source,
281 KeyType::Client,
282 KeyEntryLoadBits::NONE,
283 src_uid,
284 |k, av| {
285 if migrate_any_key_permission {
286 Ok(())
287 } else {
288 check_key_permission(KeyPerm::Use, k, &av)?;
289 check_key_permission(KeyPerm::Delete, k, &av)?;
290 check_key_permission(KeyPerm::Grant, k, &av)
291 }
292 },
293 )
294 },
295 )
296 .context("In migrate_key_namespace: Failed to load key blob.")?
297 {
298 db.borrow_mut().migrate_key_namespace(key_id_guard, destination, dest_uid, |k| {
299 if migrate_any_key_permission {
300 Ok(())
301 } else {
302 check_key_permission(KeyPerm::Rebind, k, &None)
303 }
304 })
305 } else {
306 Ok(())
307 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700308 })
309 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700310
311 fn delete_all_keys() -> Result<()> {
312 // Security critical permission check. This statement must return on fail.
Janis Danisevskisa916d992021-10-19 15:46:09 -0700313 check_keystore_permission(KeystorePerm::DeleteAllKeys)
Paul Crowley46c703e2021-08-06 15:13:53 -0700314 .context("In delete_all_keys. Checking permission")?;
315 log::info!("In delete_all_keys.");
316
317 Maintenance::call_on_all_security_levels("deleteAllKeys", |dev| dev.deleteAllKeys())
318 }
John Wu16db29e2022-01-13 15:21:43 -0800319
320 fn list_entries(domain: Domain, nspace: i64) -> Result<Vec<KeyDescriptor>> {
321 let k = match domain {
322 Domain::APP | Domain::SELINUX => KeyDescriptor{domain, nspace, ..Default::default()},
323 _ => return Err(Error::perm()).context(
324 "In list_entries: List entries is only supported for Domain::APP and Domain::SELINUX."
325 ),
326 };
327
328 // The caller has to have either GetInfo for the namespace or List permission
329 check_key_permission(KeyPerm::GetInfo, &k, &None)
330 .or_else(|e| {
331 if Some(&selinux::Error::PermissionDenied)
332 == e.root_cause().downcast_ref::<selinux::Error>()
333 {
334 check_keystore_permission(KeystorePerm::List)
335 } else {
336 Err(e)
337 }
338 })
339 .context("In list_entries: While checking key and keystore permission.")?;
340
341 DB.with(|db| list_key_entries(&mut db.borrow_mut(), domain, nspace))
342 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000343}
344
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800345impl Interface for Maintenance {}
Hasini Gunasingheda895552021-01-27 19:34:37 +0000346
Janis Danisevskis34a0cf22021-03-08 09:19:03 -0800347impl IKeystoreMaintenance for Maintenance {
Hasini Gunasingheda895552021-01-27 19:34:37 +0000348 fn onUserPasswordChanged(&self, user_id: i32, password: Option<&[u8]>) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000349 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserPasswordChanged", 500);
Paul Crowleyf61fee72021-03-17 14:38:44 -0700350 map_or_log_err(Self::on_user_password_changed(user_id, password.map(|pw| pw.into())), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000351 }
352
353 fn onUserAdded(&self, user_id: i32) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000354 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserAdded", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700355 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000356 }
357
358 fn onUserRemoved(&self, user_id: i32) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000359 let _wp = wd::watch_millis("IKeystoreMaintenance::onUserRemoved", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700360 map_or_log_err(self.add_or_remove_user(user_id), Ok)
Hasini Gunasingheda895552021-01-27 19:34:37 +0000361 }
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800362
363 fn clearNamespace(&self, domain: Domain, nspace: i64) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000364 let _wp = wd::watch_millis("IKeystoreMaintenance::clearNamespace", 500);
Janis Danisevskis5898d152021-06-15 08:23:46 -0700365 map_or_log_err(self.clear_namespace(domain, nspace), Ok)
Janis Danisevskisddd6e752021-02-22 18:46:55 -0800366 }
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000367
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700368 fn getState(&self, user_id: i32) -> BinderResult<AidlUserState> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000369 let _wp = wd::watch_millis("IKeystoreMaintenance::getState", 500);
Hasini Gunasinghe9ee18412021-03-11 20:12:44 +0000370 map_or_log_err(Self::get_state(user_id), Ok)
371 }
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700372
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800373 fn earlyBootEnded(&self) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000374 let _wp = wd::watch_millis("IKeystoreMaintenance::earlyBootEnded", 500);
Satya Tangirala5b9e5b12021-03-09 12:54:21 -0800375 map_or_log_err(Self::early_boot_ended(), Ok)
376 }
377
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700378 fn onDeviceOffBody(&self) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000379 let _wp = wd::watch_millis("IKeystoreMaintenance::onDeviceOffBody", 500);
Janis Danisevskis333b7c02021-03-23 18:57:41 -0700380 map_or_log_err(Self::on_device_off_body(), Ok)
381 }
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700382
383 fn migrateKeyNamespace(
384 &self,
385 source: &KeyDescriptor,
386 destination: &KeyDescriptor,
387 ) -> BinderResult<()> {
Hasini Gunasinghe5a893e82021-05-05 14:32:32 +0000388 let _wp = wd::watch_millis("IKeystoreMaintenance::migrateKeyNamespace", 500);
Janis Danisevskiscdcf4e52021-04-14 15:44:36 -0700389 map_or_log_err(Self::migrate_key_namespace(source, destination), Ok)
390 }
Paul Crowley46c703e2021-08-06 15:13:53 -0700391
John Wu16db29e2022-01-13 15:21:43 -0800392 fn listEntries(&self, domain: Domain, namespace: i64) -> BinderResult<Vec<KeyDescriptor>> {
393 let _wp = wd::watch_millis("IKeystoreMaintenance::listEntries", 500);
394 map_or_log_err(Self::list_entries(domain, namespace), Ok)
395 }
396
Paul Crowley46c703e2021-08-06 15:13:53 -0700397 fn deleteAllKeys(&self) -> BinderResult<()> {
398 let _wp = wd::watch_millis("IKeystoreMaintenance::deleteAllKeys", 500);
399 map_or_log_err(Self::delete_all_keys(), Ok)
400 }
Hasini Gunasingheda895552021-01-27 19:34:37 +0000401}