blob: c4921206ba6c6128c77da97391412bdb7f1d19fc [file] [log] [blame]
Janis Danisevskisa75e2082020-10-07 16:44:26 -07001// Copyright 2020, 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
15//! This module holds global state of Keystore such as the thread local
16//! database connections and connections to services that Keystore needs
17//! to talk to.
18
Janis Danisevskis93927dd2020-12-23 12:23:08 -080019use crate::gc::Gc;
Hasini Gunasinghea020b532021-01-07 21:42:35 +000020use crate::legacy_blob::LegacyBlobLoader;
Hasini Gunasinghe3ed5da72021-02-04 15:18:54 +000021use crate::legacy_migrator::LegacyMigrator;
Janis Danisevskisb42fc182020-12-15 08:41:27 -080022use crate::super_key::SuperKeyManager;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -070023use crate::utils::watchdog as wd;
Janis Danisevskisba998992020-12-29 16:08:40 -080024use crate::utils::Asp;
Janis Danisevskis5ed8c532021-01-11 14:19:42 -080025use crate::{async_task::AsyncTask, database::MonotonicRawTime};
Janis Danisevskisba998992020-12-29 16:08:40 -080026use crate::{
27 database::KeystoreDB,
Max Bires8e93d2b2021-01-14 13:17:59 -080028 database::Uuid,
Janis Danisevskis8c6378e2021-01-01 09:30:37 -080029 error::{map_binder_status, map_binder_status_code, Error, ErrorCode},
Janis Danisevskisba998992020-12-29 16:08:40 -080030};
Max Bires8e93d2b2021-01-14 13:17:59 -080031use crate::{enforcements::Enforcements, error::map_km_error};
32use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
Max Biresb2e1d032021-02-08 21:35:05 -080033 IKeyMintDevice::IKeyMintDevice, IRemotelyProvisionedComponent::IRemotelyProvisionedComponent,
34 KeyMintHardwareInfo::KeyMintHardwareInfo, SecurityLevel::SecurityLevel,
Max Bires8e93d2b2021-01-14 13:17:59 -080035};
Stephen Crane221bbb52020-12-16 15:52:10 -080036use android_hardware_security_keymint::binder::{StatusCode, Strong};
Janis Danisevskis8c6378e2021-01-01 09:30:37 -080037use android_security_compat::aidl::android::security::compat::IKeystoreCompatService::IKeystoreCompatService;
Janis Danisevskisba998992020-12-29 16:08:40 -080038use anyhow::{Context, Result};
David Drysdale0e45a612021-02-25 17:24:36 +000039use binder::FromIBinder;
Janis Danisevskisef14e1a2021-02-23 23:16:55 -080040use keystore2_vintf::get_aidl_instances;
Janis Danisevskisb42fc182020-12-15 08:41:27 -080041use lazy_static::lazy_static;
Janis Danisevskis7e8b4622021-02-13 10:01:59 -080042use std::sync::{Arc, Mutex};
Janis Danisevskis93927dd2020-12-23 12:23:08 -080043use std::{cell::RefCell, sync::Once};
Janis Danisevskis3f2955c2021-02-02 21:53:35 -080044use std::{collections::HashMap, path::Path, path::PathBuf};
Janis Danisevskis93927dd2020-12-23 12:23:08 -080045
46static DB_INIT: Once = Once::new();
47
48/// Open a connection to the Keystore 2.0 database. This is called during the initialization of
49/// the thread local DB field. It should never be called directly. The first time this is called
50/// we also call KeystoreDB::cleanup_leftovers to restore the key lifecycle invariant. See the
Janis Danisevskis7e8b4622021-02-13 10:01:59 -080051/// documentation of cleanup_leftovers for more details. The function also constructs a blob
52/// garbage collector. The initializing closure constructs another database connection without
53/// a gc. Although one GC is created for each thread local database connection, this closure
54/// is run only once, as long as the ASYNC_TASK instance is the same. So only one additional
55/// database connection is created for the garbage collector worker.
Hasini Gunasinghe3ed5da72021-02-04 15:18:54 +000056pub fn create_thread_local_db() -> KeystoreDB {
Janis Danisevskis3395f862021-05-06 10:54:17 -070057 let mut db = KeystoreDB::new(
58 &DB_PATH.lock().expect("Could not get the database directory."),
59 Some(GC.clone()),
60 )
61 .expect("Failed to open database.");
Janis Danisevskis93927dd2020-12-23 12:23:08 -080062 DB_INIT.call_once(|| {
63 log::info!("Touching Keystore 2.0 database for this first time since boot.");
Janis Danisevskis5ed8c532021-01-11 14:19:42 -080064 db.insert_last_off_body(MonotonicRawTime::now())
65 .expect("Could not initialize database with last off body.");
Janis Danisevskis93927dd2020-12-23 12:23:08 -080066 log::info!("Calling cleanup leftovers.");
67 let n = db.cleanup_leftovers().expect("Failed to cleanup database on startup.");
68 if n != 0 {
69 log::info!(
70 concat!(
71 "Cleaned up {} failed entries. ",
72 "This indicates keystore crashed during key generation."
73 ),
74 n
75 );
76 }
Janis Danisevskis93927dd2020-12-23 12:23:08 -080077 });
78 db
79}
Janis Danisevskisa75e2082020-10-07 16:44:26 -070080
81thread_local! {
82 /// Database connections are not thread safe, but connecting to the
83 /// same database multiple times is safe as long as each connection is
84 /// used by only one thread. So we store one database connection per
85 /// thread in this thread local key.
86 pub static DB: RefCell<KeystoreDB> =
Janis Danisevskis93927dd2020-12-23 12:23:08 -080087 RefCell::new(create_thread_local_db());
Janis Danisevskisa75e2082020-10-07 16:44:26 -070088}
Janis Danisevskisb42fc182020-12-15 08:41:27 -080089
Max Bires8e93d2b2021-01-14 13:17:59 -080090#[derive(Default)]
91struct DevicesMap {
92 devices_by_uuid: HashMap<Uuid, (Asp, KeyMintHardwareInfo)>,
93 uuid_by_sec_level: HashMap<SecurityLevel, Uuid>,
94}
95
96impl DevicesMap {
97 fn dev_by_sec_level(
98 &self,
99 sec_level: &SecurityLevel,
100 ) -> Option<(Asp, KeyMintHardwareInfo, Uuid)> {
101 self.uuid_by_sec_level.get(sec_level).and_then(|uuid| self.dev_by_uuid(uuid))
102 }
103
104 fn dev_by_uuid(&self, uuid: &Uuid) -> Option<(Asp, KeyMintHardwareInfo, Uuid)> {
105 self.devices_by_uuid
106 .get(uuid)
107 .map(|(dev, hw_info)| ((*dev).clone(), (*hw_info).clone(), *uuid))
108 }
109
David Drysdale0e45a612021-02-25 17:24:36 +0000110 fn devices<T: FromIBinder + ?Sized>(&self) -> Vec<Strong<T>> {
111 self.devices_by_uuid.values().filter_map(|(asp, _)| asp.get_interface::<T>().ok()).collect()
112 }
113
Max Bires8e93d2b2021-01-14 13:17:59 -0800114 /// The requested security level and the security level of the actual implementation may
115 /// differ. So we map the requested security level to the uuid of the implementation
116 /// so that there cannot be any confusion as to which KeyMint instance is requested.
117 fn insert(&mut self, sec_level: SecurityLevel, dev: Asp, hw_info: KeyMintHardwareInfo) {
118 // For now we use the reported security level of the KM instance as UUID.
119 // TODO update this section once UUID was added to the KM hardware info.
120 let uuid: Uuid = sec_level.into();
121 self.devices_by_uuid.insert(uuid, (dev, hw_info));
122 self.uuid_by_sec_level.insert(sec_level, uuid);
123 }
124}
125
Max Biresb2e1d032021-02-08 21:35:05 -0800126#[derive(Default)]
127struct RemotelyProvisionedDevicesMap {
128 devices_by_sec_level: HashMap<SecurityLevel, Asp>,
129}
130
131impl RemotelyProvisionedDevicesMap {
132 fn dev_by_sec_level(&self, sec_level: &SecurityLevel) -> Option<Asp> {
133 self.devices_by_sec_level.get(sec_level).map(|dev| (*dev).clone())
134 }
135
136 fn insert(&mut self, sec_level: SecurityLevel, dev: Asp) {
137 self.devices_by_sec_level.insert(sec_level, dev);
138 }
139}
140
Janis Danisevskisb42fc182020-12-15 08:41:27 -0800141lazy_static! {
Janis Danisevskis3f2955c2021-02-02 21:53:35 -0800142 /// The path where keystore stores all its keys.
143 pub static ref DB_PATH: Mutex<PathBuf> = Mutex::new(
144 Path::new("/data/misc/keystore").to_path_buf());
Janis Danisevskisb42fc182020-12-15 08:41:27 -0800145 /// Runtime database of unwrapped super keys.
Janis Danisevskis7e8b4622021-02-13 10:01:59 -0800146 pub static ref SUPER_KEY: Arc<SuperKeyManager> = Default::default();
Janis Danisevskisba998992020-12-29 16:08:40 -0800147 /// Map of KeyMint devices.
Max Bires8e93d2b2021-01-14 13:17:59 -0800148 static ref KEY_MINT_DEVICES: Mutex<DevicesMap> = Default::default();
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800149 /// Timestamp service.
150 static ref TIME_STAMP_DEVICE: Mutex<Option<Asp>> = Default::default();
Max Biresb2e1d032021-02-08 21:35:05 -0800151 /// RemotelyProvisionedComponent HAL devices.
152 static ref REMOTELY_PROVISIONED_COMPONENT_DEVICES: Mutex<RemotelyProvisionedDevicesMap> = Default::default();
Janis Danisevskis93927dd2020-12-23 12:23:08 -0800153 /// A single on-demand worker thread that handles deferred tasks with two different
154 /// priorities.
Janis Danisevskis7e8b4622021-02-13 10:01:59 -0800155 pub static ref ASYNC_TASK: Arc<AsyncTask> = Default::default();
Janis Danisevskis5ed8c532021-01-11 14:19:42 -0800156 /// Singleton for enforcements.
Paul Crowley7c57bf12021-02-02 16:26:57 -0800157 pub static ref ENFORCEMENTS: Enforcements = Default::default();
Hasini Gunasinghea020b532021-01-07 21:42:35 +0000158 /// LegacyBlobLoader is initialized and exists globally.
159 /// The same directory used by the database is used by the LegacyBlobLoader as well.
Hasini Gunasinghe3ed5da72021-02-04 15:18:54 +0000160 pub static ref LEGACY_BLOB_LOADER: Arc<LegacyBlobLoader> = Arc::new(LegacyBlobLoader::new(
161 &DB_PATH.lock().expect("Could not get the database path for legacy blob loader.")));
162 /// Legacy migrator. Atomically migrates legacy blobs to the database.
163 pub static ref LEGACY_MIGRATOR: Arc<LegacyMigrator> =
Janis Danisevskisec6586d2021-04-30 10:54:07 -0700164 Arc::new(LegacyMigrator::new(Arc::new(Default::default())));
Pavel Grafov94243c22021-04-21 18:03:11 +0100165 /// Background thread which handles logging via statsd and logd
166 pub static ref LOGS_HANDLER: Arc<AsyncTask> = Default::default();
Janis Danisevskis3395f862021-05-06 10:54:17 -0700167
168 static ref GC: Arc<Gc> = Arc::new(Gc::new_init_with(ASYNC_TASK.clone(), || {
169 (
170 Box::new(|uuid, blob| {
171 let km_dev: Strong<dyn IKeyMintDevice> =
172 get_keymint_dev_by_uuid(uuid).map(|(dev, _)| dev)?.get_interface()?;
173 let _wp = wd::watch_millis("In invalidate key closure: calling deleteKey", 500);
174 map_km_error(km_dev.deleteKey(&*blob))
175 .context("In invalidate key closure: Trying to invalidate key blob.")
176 }),
177 KeystoreDB::new(&DB_PATH.lock().expect("Could not get the database directory."), None)
178 .expect("Failed to open database."),
179 SUPER_KEY.clone(),
180 )
181 }));
Janis Danisevskisba998992020-12-29 16:08:40 -0800182}
183
184static KEYMINT_SERVICE_NAME: &str = "android.hardware.security.keymint.IKeyMintDevice";
185
186/// Make a new connection to a KeyMint device of the given security level.
Janis Danisevskis8c6378e2021-01-01 09:30:37 -0800187/// If no native KeyMint device can be found this function also brings
188/// up the compatibility service and attempts to connect to the legacy wrapper.
Max Bires8e93d2b2021-01-14 13:17:59 -0800189fn connect_keymint(security_level: &SecurityLevel) -> Result<(Asp, KeyMintHardwareInfo)> {
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800190 let keymint_instances =
191 get_aidl_instances("android.hardware.security.keymint", 1, "IKeyMintDevice");
192
Max Bires8e93d2b2021-01-14 13:17:59 -0800193 let service_name = match *security_level {
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800194 SecurityLevel::TRUSTED_ENVIRONMENT => {
195 if keymint_instances.as_vec()?.iter().any(|instance| *instance == "default") {
196 Some(format!("{}/default", KEYMINT_SERVICE_NAME))
197 } else {
198 None
199 }
200 }
201 SecurityLevel::STRONGBOX => {
202 if keymint_instances.as_vec()?.iter().any(|instance| *instance == "strongbox") {
203 Some(format!("{}/strongbox", KEYMINT_SERVICE_NAME))
204 } else {
205 None
206 }
207 }
Janis Danisevskisba998992020-12-29 16:08:40 -0800208 _ => {
209 return Err(Error::Km(ErrorCode::HARDWARE_TYPE_UNAVAILABLE))
210 .context("In connect_keymint.")
211 }
212 };
213
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800214 let keymint = if let Some(service_name) = service_name {
215 map_binder_status_code(binder::get_interface(&service_name))
216 .context("In connect_keymint: Trying to connect to genuine KeyMint service.")
217 } else {
218 // This is a no-op if it was called before.
219 keystore2_km_compat::add_keymint_device_service();
Janis Danisevskis8c6378e2021-01-01 09:30:37 -0800220
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800221 let keystore_compat_service: Strong<dyn IKeystoreCompatService> =
222 map_binder_status_code(binder::get_interface("android.security.compat"))
223 .context("In connect_keymint: Trying to connect to compat service.")?;
224 map_binder_status(keystore_compat_service.getKeyMintDevice(*security_level))
225 .map_err(|e| match e {
226 Error::BinderTransaction(StatusCode::NAME_NOT_FOUND) => {
227 Error::Km(ErrorCode::HARDWARE_TYPE_UNAVAILABLE)
Janis Danisevskis8c6378e2021-01-01 09:30:37 -0800228 }
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800229 e => e,
230 })
231 .context("In connect_keymint: Trying to get Legacy wrapper.")
232 }?;
Janis Danisevskisba998992020-12-29 16:08:40 -0800233
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700234 let wp = wd::watch_millis("In connect_keymint: calling getHardwareInfo()", 500);
Max Bires8e93d2b2021-01-14 13:17:59 -0800235 let hw_info = map_km_error(keymint.getHardwareInfo())
236 .context("In connect_keymint: Failed to get hardware info.")?;
Janis Danisevskis2ee014b2021-05-05 14:29:08 -0700237 drop(wp);
Max Bires8e93d2b2021-01-14 13:17:59 -0800238
239 Ok((Asp::new(keymint.as_binder()), hw_info))
Janis Danisevskisba998992020-12-29 16:08:40 -0800240}
241
242/// Get a keymint device for the given security level either from our cache or
Max Bires8e93d2b2021-01-14 13:17:59 -0800243/// by making a new connection. Returns the device, the hardware info and the uuid.
244/// TODO the latter can be removed when the uuid is part of the hardware info.
245pub fn get_keymint_device(
246 security_level: &SecurityLevel,
247) -> Result<(Asp, KeyMintHardwareInfo, Uuid)> {
Janis Danisevskisba998992020-12-29 16:08:40 -0800248 let mut devices_map = KEY_MINT_DEVICES.lock().unwrap();
Max Bires8e93d2b2021-01-14 13:17:59 -0800249 if let Some((dev, hw_info, uuid)) = devices_map.dev_by_sec_level(&security_level) {
250 Ok((dev, hw_info, uuid))
Janis Danisevskisba998992020-12-29 16:08:40 -0800251 } else {
Max Bires8e93d2b2021-01-14 13:17:59 -0800252 let (dev, hw_info) = connect_keymint(security_level).context("In get_keymint_device.")?;
253 devices_map.insert(*security_level, dev, hw_info);
254 // Unwrap must succeed because we just inserted it.
255 Ok(devices_map.dev_by_sec_level(security_level).unwrap())
256 }
257}
258
259/// Get a keymint device for the given uuid. This will only access the cache, but will not
260/// attempt to establish a new connection. It is assumed that the cache is already populated
261/// when this is called. This is a fair assumption, because service.rs iterates through all
262/// security levels when it gets instantiated.
263pub fn get_keymint_dev_by_uuid(uuid: &Uuid) -> Result<(Asp, KeyMintHardwareInfo)> {
264 let devices_map = KEY_MINT_DEVICES.lock().unwrap();
265 if let Some((dev, hw_info, _)) = devices_map.dev_by_uuid(uuid) {
266 Ok((dev, hw_info))
267 } else {
268 Err(Error::sys()).context("In get_keymint_dev_by_uuid: No KeyMint instance found.")
Janis Danisevskisba998992020-12-29 16:08:40 -0800269 }
Janis Danisevskisb42fc182020-12-15 08:41:27 -0800270}
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800271
David Drysdale0e45a612021-02-25 17:24:36 +0000272/// Return all known keymint devices.
273pub fn get_keymint_devices() -> Vec<Strong<dyn IKeyMintDevice>> {
274 KEY_MINT_DEVICES.lock().unwrap().devices()
275}
276
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800277static TIME_STAMP_SERVICE_NAME: &str = "android.hardware.security.secureclock.ISecureClock";
278
279/// Make a new connection to a secure clock service.
280/// If no native SecureClock device can be found brings up the compatibility service and attempts
281/// to connect to the legacy wrapper.
282fn connect_secureclock() -> Result<Asp> {
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800283 let secureclock_instances =
284 get_aidl_instances("android.hardware.security.secureclock", 1, "ISecureClock");
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800285
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800286 let secure_clock_available =
287 secureclock_instances.as_vec()?.iter().any(|instance| *instance == "default");
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800288
Max Bires130e51b2021-04-05 14:07:20 -0700289 let default_time_stamp_service_name = format!("{}/default", TIME_STAMP_SERVICE_NAME);
290
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800291 let secureclock = if secure_clock_available {
Max Bires130e51b2021-04-05 14:07:20 -0700292 map_binder_status_code(binder::get_interface(&default_time_stamp_service_name))
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800293 .context("In connect_secureclock: Trying to connect to genuine secure clock service.")
294 } else {
295 // This is a no-op if it was called before.
296 keystore2_km_compat::add_keymint_device_service();
297
298 let keystore_compat_service: Strong<dyn IKeystoreCompatService> =
299 map_binder_status_code(binder::get_interface("android.security.compat"))
300 .context("In connect_secureclock: Trying to connect to compat service.")?;
301
302 // Legacy secure clock services were only implemented by TEE.
303 map_binder_status(keystore_compat_service.getSecureClock())
304 .map_err(|e| match e {
305 Error::BinderTransaction(StatusCode::NAME_NOT_FOUND) => {
306 Error::Km(ErrorCode::HARDWARE_TYPE_UNAVAILABLE)
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800307 }
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800308 e => e,
309 })
310 .context("In connect_secureclock: Trying to get Legacy wrapper.")
311 }?;
Janis Danisevskisc3a496b2021-01-05 10:37:22 -0800312
313 Ok(Asp::new(secureclock.as_binder()))
314}
315
316/// Get the timestamp service that verifies auth token timeliness towards security levels with
317/// different clocks.
318pub fn get_timestamp_service() -> Result<Asp> {
319 let mut ts_device = TIME_STAMP_DEVICE.lock().unwrap();
320 if let Some(dev) = &*ts_device {
321 Ok(dev.clone())
322 } else {
323 let dev = connect_secureclock().context("In get_timestamp_service.")?;
324 *ts_device = Some(dev.clone());
325 Ok(dev)
326 }
327}
Max Biresb2e1d032021-02-08 21:35:05 -0800328
329static REMOTE_PROVISIONING_HAL_SERVICE_NAME: &str =
330 "android.hardware.security.keymint.IRemotelyProvisionedComponent";
331
332fn connect_remotely_provisioned_component(security_level: &SecurityLevel) -> Result<Asp> {
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800333 let remotely_prov_instances =
334 get_aidl_instances("android.hardware.security.keymint", 1, "IRemotelyProvisionedComponent");
335
Max Biresb2e1d032021-02-08 21:35:05 -0800336 let service_name = match *security_level {
337 SecurityLevel::TRUSTED_ENVIRONMENT => {
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800338 if remotely_prov_instances.as_vec()?.iter().any(|instance| *instance == "default") {
339 Some(format!("{}/default", REMOTE_PROVISIONING_HAL_SERVICE_NAME))
340 } else {
341 None
342 }
Max Biresb2e1d032021-02-08 21:35:05 -0800343 }
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800344 SecurityLevel::STRONGBOX => {
345 if remotely_prov_instances.as_vec()?.iter().any(|instance| *instance == "strongbox") {
346 Some(format!("{}/strongbox", REMOTE_PROVISIONING_HAL_SERVICE_NAME))
347 } else {
348 None
349 }
Max Biresb2e1d032021-02-08 21:35:05 -0800350 }
Janis Danisevskisef14e1a2021-02-23 23:16:55 -0800351 _ => None,
352 }
353 .ok_or(Error::Km(ErrorCode::HARDWARE_TYPE_UNAVAILABLE))
354 .context("In connect_remotely_provisioned_component.")?;
Max Biresb2e1d032021-02-08 21:35:05 -0800355
356 let rem_prov_hal: Strong<dyn IRemotelyProvisionedComponent> =
357 map_binder_status_code(binder::get_interface(&service_name))
358 .context(concat!(
359 "In connect_remotely_provisioned_component: Trying to connect to",
360 " RemotelyProvisionedComponent service."
361 ))
362 .map_err(|e| e)?;
363 Ok(Asp::new(rem_prov_hal.as_binder()))
364}
365
366/// Get a remote provisiong component device for the given security level either from the cache or
367/// by making a new connection. Returns the device.
368pub fn get_remotely_provisioned_component(security_level: &SecurityLevel) -> Result<Asp> {
369 let mut devices_map = REMOTELY_PROVISIONED_COMPONENT_DEVICES.lock().unwrap();
370 if let Some(dev) = devices_map.dev_by_sec_level(&security_level) {
371 Ok(dev)
372 } else {
373 let dev = connect_remotely_provisioned_component(security_level)
374 .context("In get_remotely_provisioned_component.")?;
375 devices_map.insert(*security_level, dev);
376 // Unwrap must succeed because we just inserted it.
377 Ok(devices_map.dev_by_sec_level(security_level).unwrap())
378 }
379}