diff --git a/keystore2/src/globals.rs b/keystore2/src/globals.rs index 2d5c20a7..c7b495df 100644 --- a/keystore2/src/globals.rs +++ b/keystore2/src/globals.rs @@ -44,8 +44,8 @@ use android_hardware_security_secureclock::aidl::android::hardware::security::se }; use android_security_compat::aidl::android::security::compat::IKeystoreCompatService::IKeystoreCompatService; use anyhow::{Context, Result}; -use binder::get_declared_instances; use binder::FromIBinder; +use binder::{get_declared_instances, is_declared}; use lazy_static::lazy_static; use std::sync::{Arc, Mutex, RwLock}; use std::{cell::RefCell, sync::Once}; @@ -420,19 +420,20 @@ pub fn get_timestamp_service() -> Result> { pub fn get_remotely_provisioned_component_name(security_level: &SecurityLevel) -> Result { let remote_prov_descriptor: &str = ::get_descriptor(); - let remotely_prov_instances = get_declared_instances(remote_prov_descriptor).unwrap(); match *security_level { SecurityLevel::TRUSTED_ENVIRONMENT => { - if remotely_prov_instances.iter().any(|instance| *instance == "default") { - Some(format!("{}/default", remote_prov_descriptor)) + let instance = format!("{}/default", remote_prov_descriptor); + if is_declared(&instance)? { + Some(instance) } else { None } } SecurityLevel::STRONGBOX => { - if remotely_prov_instances.iter().any(|instance| *instance == "strongbox") { - Some(format!("{}/strongbox", remote_prov_descriptor)) + let instance = format!("{}/strongbox", remote_prov_descriptor); + if is_declared(&instance)? { + Some(instance) } else { None }