Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 1 | // Copyright 2023, 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 | //! Class for encapsulating & managing represent VM secrets. |
| 16 | |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 17 | use anyhow::{anyhow, ensure, Result}; |
| 18 | use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::IVirtualMachineService; |
| 19 | use android_hardware_security_secretkeeper::aidl::android::hardware::security::secretkeeper::ISecretkeeper::ISecretkeeper; |
| 20 | use secretkeeper_comm::data_types::request::Request; |
| 21 | use binder::{Strong}; |
| 22 | use coset::CborSerializable; |
Shikha Panwar | 101ac8f | 2024-01-19 11:20:18 +0000 | [diff] [blame^] | 23 | use dice_policy_builder::{CertIndex, ConstraintSpec, ConstraintType, policy_for_dice_chain, MissingAction, WILDCARD_FULL_ARRAY}; |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 24 | use diced_open_dice::{DiceArtifacts, OwnedDiceArtifacts}; |
| 25 | use keystore2_crypto::ZVec; |
| 26 | use openssl::hkdf::hkdf; |
| 27 | use openssl::md::Md; |
| 28 | use openssl::sha; |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 29 | use secretkeeper_client::dice::OwnedDiceArtifactsWithExplicitKey; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 30 | use secretkeeper_client::SkSession; |
| 31 | use secretkeeper_comm::data_types::{Id, ID_SIZE, Secret, SECRET_SIZE}; |
| 32 | use secretkeeper_comm::data_types::response::Response; |
| 33 | use secretkeeper_comm::data_types::packet::{ResponsePacket, ResponseType}; |
| 34 | use secretkeeper_comm::data_types::request_response_impl::{ |
| 35 | StoreSecretRequest, GetSecretResponse, GetSecretRequest}; |
| 36 | use secretkeeper_comm::data_types::error::SecretkeeperError; |
| 37 | use zeroize::Zeroizing; |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 38 | |
Shikha Panwar | 3d3a70a | 2023-08-21 20:02:08 +0000 | [diff] [blame] | 39 | const ENCRYPTEDSTORE_KEY_IDENTIFIER: &str = "encryptedstore_key"; |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 40 | const AUTHORITY_HASH: i64 = -4670549; |
| 41 | const MODE: i64 = -4670551; |
| 42 | const CONFIG_DESC: i64 = -4670548; |
| 43 | const SECURITY_VERSION: i64 = -70005; |
Shikha Panwar | 101ac8f | 2024-01-19 11:20:18 +0000 | [diff] [blame^] | 44 | const SUBCOMPONENT_DESCRIPTORS: i64 = -71002; |
| 45 | const SUBCOMPONENT_SECURITY_VERSION: i64 = 2; |
| 46 | const SUBCOMPONENT_AUTHORITY_HASH: i64 = 4; |
| 47 | // Index of DiceChainEntry corresponding to Payload (relative to the end considering DICE Chain |
| 48 | // as an array) |
| 49 | const PAYLOAD_INDEX_FROM_END: usize = 0; |
Shikha Panwar | 3d3a70a | 2023-08-21 20:02:08 +0000 | [diff] [blame] | 50 | |
Shikha Panwar | 3d3a70a | 2023-08-21 20:02:08 +0000 | [diff] [blame] | 51 | // Generated using hexdump -vn32 -e'14/1 "0x%02X, " 1 "\n"' /dev/urandom |
| 52 | const SALT_ENCRYPTED_STORE: &[u8] = &[ |
| 53 | 0xFC, 0x1D, 0x35, 0x7B, 0x96, 0xF3, 0xEF, 0x17, 0x78, 0x7D, 0x70, 0xED, 0xEA, 0xFE, 0x1D, 0x6F, |
| 54 | 0xB3, 0xF9, 0x40, 0xCE, 0xDD, 0x99, 0x40, 0xAA, 0xA7, 0x0E, 0x92, 0x73, 0x90, 0x86, 0x4A, 0x75, |
| 55 | ]; |
| 56 | const SALT_PAYLOAD_SERVICE: &[u8] = &[ |
| 57 | 0x8B, 0x0F, 0xF0, 0xD3, 0xB1, 0x69, 0x2B, 0x95, 0x84, 0x2C, 0x9E, 0x3C, 0x99, 0x56, 0x7A, 0x22, |
| 58 | 0x55, 0xF8, 0x08, 0x23, 0x81, 0x5F, 0xF5, 0x16, 0x20, 0x3E, 0xBE, 0xBA, 0xB7, 0xA8, 0x43, 0x92, |
| 59 | ]; |
| 60 | |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 61 | const SKP_SECRET_NP_VM: [u8; SECRET_SIZE] = [ |
| 62 | 0xA9, 0x89, 0x97, 0xFE, 0xAE, 0x97, 0x55, 0x4B, 0x32, 0x35, 0xF0, 0xE8, 0x93, 0xDA, 0xEA, 0x24, |
| 63 | 0x06, 0xAC, 0x36, 0x8B, 0x3C, 0x95, 0x50, 0x16, 0x67, 0x71, 0x65, 0x26, 0xEB, 0xD0, 0xC3, 0x98, |
| 64 | ]; |
| 65 | |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 66 | pub enum VmSecret { |
| 67 | // V2 secrets are derived from 2 independently secured secrets: |
| 68 | // 1. Secretkeeper protected secrets (skp secret). |
| 69 | // 2. Dice Sealing CDIs (Similar to V1). |
| 70 | // |
| 71 | // These are protected against rollback of boot images i.e. VM instance rebooted |
| 72 | // with downgraded images will not have access to VM's secret. |
| 73 | // V2 secrets require hardware support - Secretkeeper HAL, which (among other things) |
| 74 | // is backed by tamper-evident storage, providing rollback protection to these secrets. |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 75 | V2 { dice_artifacts: OwnedDiceArtifactsWithExplicitKey, skp_secret: ZVec }, |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 76 | // V1 secrets are not protected against rollback of boot images. |
| 77 | // They are reliable only if rollback of images was prevented by verified boot ie, |
| 78 | // each stage (including pvmfw/Microdroid/Microdroid Manager) prevents downgrade of next |
| 79 | // stage. These are now legacy secrets & used only when Secretkeeper HAL is not supported |
| 80 | // by device. |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 81 | V1 { dice_artifacts: OwnedDiceArtifacts }, |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | impl VmSecret { |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 85 | pub fn new( |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 86 | id: [u8; ID_SIZE], |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 87 | dice_artifacts: OwnedDiceArtifacts, |
| 88 | vm_service: &Strong<dyn IVirtualMachineService>, |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 89 | ) -> Result<Self> { |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 90 | ensure!(dice_artifacts.bcc().is_some(), "Dice chain missing"); |
| 91 | |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 92 | let Some(sk_service) = is_sk_supported(vm_service)? else { |
| 93 | // Use V1 secrets if Secretkeeper is not supported. |
| 94 | return Ok(Self::V1 { dice_artifacts }); |
| 95 | }; |
| 96 | let explicit_dice = |
| 97 | OwnedDiceArtifactsWithExplicitKey::from_owned_artifacts(dice_artifacts)?; |
| 98 | let explicit_dice_chain = explicit_dice |
| 99 | .explicit_key_dice_chain() |
| 100 | .ok_or(anyhow!("Missing explicit dice chain, this is unusual"))?; |
| 101 | let policy = sealing_policy(explicit_dice_chain).map_err(anyhow_err)?; |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 102 | |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 103 | // Start a new session with Secretkeeper! |
| 104 | let mut session = SkSession::new(sk_service, &explicit_dice)?; |
| 105 | let mut skp_secret = Zeroizing::new([0u8; SECRET_SIZE]); |
| 106 | if super::is_strict_boot() { |
| 107 | if super::is_new_instance() { |
| 108 | *skp_secret = rand::random(); |
| 109 | store_secret(&mut session, id, skp_secret.clone(), policy)?; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 110 | } else { |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 111 | // Subsequent run of the pVM -> get the secret stored in Secretkeeper. |
| 112 | *skp_secret = get_secret(&mut session, id, Some(policy))?; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 113 | } |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 114 | } else { |
| 115 | // TODO(b/291213394): Non protected VM don't need to use Secretkeeper, remove this |
| 116 | // once we have sufficient testing on protected VM. |
| 117 | store_secret(&mut session, id, SKP_SECRET_NP_VM.into(), policy)?; |
| 118 | *skp_secret = get_secret(&mut session, id, None)?; |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 119 | } |
Shikha Panwar | 0503cb0 | 2024-01-05 10:11:28 +0000 | [diff] [blame] | 120 | Ok(Self::V2 { |
| 121 | dice_artifacts: explicit_dice, |
| 122 | skp_secret: ZVec::try_from(skp_secret.to_vec())?, |
| 123 | }) |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 124 | } |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 125 | |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 126 | pub fn dice_artifacts(&self) -> &dyn DiceArtifacts { |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 127 | match self { |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 128 | Self::V2 { dice_artifacts, .. } => dice_artifacts, |
| 129 | Self::V1 { dice_artifacts } => dice_artifacts, |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | fn get_vm_secret(&self, salt: &[u8], identifier: &[u8], key: &mut [u8]) -> Result<()> { |
| 134 | match self { |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 135 | Self::V2 { dice_artifacts, skp_secret } => { |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 136 | let mut hasher = sha::Sha256::new(); |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 137 | hasher.update(dice_artifacts.cdi_seal()); |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 138 | hasher.update(skp_secret); |
| 139 | hkdf(key, Md::sha256(), &hasher.finish(), salt, identifier)? |
| 140 | } |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 141 | Self::V1 { dice_artifacts } => { |
| 142 | hkdf(key, Md::sha256(), dice_artifacts.cdi_seal(), salt, identifier)? |
| 143 | } |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 144 | } |
| 145 | Ok(()) |
| 146 | } |
| 147 | |
Shikha Panwar | 3d3a70a | 2023-08-21 20:02:08 +0000 | [diff] [blame] | 148 | /// Derive sealing key for payload with following identifier. |
| 149 | pub fn derive_payload_sealing_key(&self, identifier: &[u8], key: &mut [u8]) -> Result<()> { |
| 150 | self.get_vm_secret(SALT_PAYLOAD_SERVICE, identifier, key) |
| 151 | } |
| 152 | |
| 153 | /// Derive encryptedstore key. This uses hardcoded random salt & fixed identifier. |
| 154 | pub fn derive_encryptedstore_key(&self, key: &mut [u8]) -> Result<()> { |
| 155 | self.get_vm_secret(SALT_ENCRYPTED_STORE, ENCRYPTEDSTORE_KEY_IDENTIFIER.as_bytes(), key) |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 159 | // Construct a sealing policy on the dice chain. VMs uses the following set of constraint for |
| 160 | // protecting secrets against rollback of boot images. |
| 161 | // 1. ExactMatch on AUTHORITY_HASH (Required ie, each DiceChainEntry must have it). |
| 162 | // 2. ExactMatch on MODE (Required) - Secret should be inaccessible if any of the runtime |
| 163 | // configuration changes. For ex, the secrets stored with a boot stage being in Normal mode |
| 164 | // should be inaccessible when the same stage is booted in Debug mode. |
| 165 | // 3. GreaterOrEqual on SECURITY_VERSION (Optional): The secrets will be accessible if version of |
| 166 | // any image is greater or equal to the set version. This is an optional field, certain |
| 167 | // components may chose to prevent booting of rollback images for ex, ABL is expected to provide |
| 168 | // rollback protection of pvmfw. Such components may chose to not put SECURITY_VERSION in the |
| 169 | // corresponding DiceChainEntry. |
Shikha Panwar | 101ac8f | 2024-01-19 11:20:18 +0000 | [diff] [blame^] | 170 | // 4. For each Subcomponent on the last DiceChainEntry (which corresponds to VM payload, See |
| 171 | // microdroid_manager/src/vm_config.cddl): |
| 172 | // - GreaterOrEqual on SECURITY_VERSION (Required) |
| 173 | // - ExactMatch on AUTHORITY_HASH (Required). |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 174 | fn sealing_policy(dice: &[u8]) -> Result<Vec<u8>, String> { |
| 175 | let constraint_spec = [ |
Shikha Panwar | 101ac8f | 2024-01-19 11:20:18 +0000 | [diff] [blame^] | 176 | ConstraintSpec::new( |
| 177 | ConstraintType::ExactMatch, |
| 178 | vec![AUTHORITY_HASH], |
| 179 | MissingAction::Fail, |
| 180 | CertIndex::All, |
| 181 | ), |
| 182 | ConstraintSpec::new( |
| 183 | ConstraintType::ExactMatch, |
| 184 | vec![MODE], |
| 185 | MissingAction::Fail, |
| 186 | CertIndex::All, |
| 187 | ), |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 188 | ConstraintSpec::new( |
| 189 | ConstraintType::GreaterOrEqual, |
| 190 | vec![CONFIG_DESC, SECURITY_VERSION], |
Shikha Panwar | 091bfbe | 2024-01-15 09:37:06 +0000 | [diff] [blame] | 191 | MissingAction::Ignore, |
Shikha Panwar | 101ac8f | 2024-01-19 11:20:18 +0000 | [diff] [blame^] | 192 | CertIndex::All, |
| 193 | ), |
| 194 | ConstraintSpec::new( |
| 195 | ConstraintType::GreaterOrEqual, |
| 196 | vec![ |
| 197 | CONFIG_DESC, |
| 198 | SUBCOMPONENT_DESCRIPTORS, |
| 199 | WILDCARD_FULL_ARRAY, |
| 200 | SUBCOMPONENT_SECURITY_VERSION, |
| 201 | ], |
| 202 | MissingAction::Fail, |
| 203 | CertIndex::FromEnd(PAYLOAD_INDEX_FROM_END), |
| 204 | ), |
| 205 | ConstraintSpec::new( |
| 206 | ConstraintType::ExactMatch, |
| 207 | vec![ |
| 208 | CONFIG_DESC, |
| 209 | SUBCOMPONENT_DESCRIPTORS, |
| 210 | WILDCARD_FULL_ARRAY, |
| 211 | SUBCOMPONENT_AUTHORITY_HASH, |
| 212 | ], |
| 213 | MissingAction::Fail, |
| 214 | CertIndex::FromEnd(PAYLOAD_INDEX_FROM_END), |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 215 | ), |
| 216 | ]; |
| 217 | |
Shikha Panwar | e763ce1 | 2024-01-19 11:20:18 +0000 | [diff] [blame] | 218 | policy_for_dice_chain(dice, &constraint_spec)? |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 219 | .to_vec() |
| 220 | .map_err(|e| format!("DicePolicy construction failed {e:?}")) |
| 221 | } |
| 222 | |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 223 | fn store_secret( |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 224 | session: &mut SkSession, |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 225 | id: [u8; ID_SIZE], |
| 226 | secret: Zeroizing<[u8; SECRET_SIZE]>, |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 227 | sealing_policy: Vec<u8>, |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 228 | ) -> Result<()> { |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 229 | let store_request = StoreSecretRequest { id: Id(id), secret: Secret(*secret), sealing_policy }; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 230 | log::info!("Secretkeeper operation: {:?}", store_request); |
| 231 | |
| 232 | let store_request = store_request.serialize_to_packet().to_vec().map_err(anyhow_err)?; |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 233 | let store_response = session.secret_management_request(&store_request)?; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 234 | let store_response = ResponsePacket::from_slice(&store_response).map_err(anyhow_err)?; |
| 235 | let response_type = store_response.response_type().map_err(anyhow_err)?; |
| 236 | ensure!( |
| 237 | response_type == ResponseType::Success, |
| 238 | "Secretkeeper store failed with error: {:?}", |
| 239 | *SecretkeeperError::deserialize_from_packet(store_response).map_err(anyhow_err)? |
| 240 | ); |
| 241 | Ok(()) |
| 242 | } |
| 243 | |
| 244 | fn get_secret( |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 245 | session: &mut SkSession, |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 246 | id: [u8; ID_SIZE], |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 247 | updated_sealing_policy: Option<Vec<u8>>, |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 248 | ) -> Result<[u8; SECRET_SIZE]> { |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 249 | let get_request = GetSecretRequest { id: Id(id), updated_sealing_policy }; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 250 | log::info!("Secretkeeper operation: {:?}", get_request); |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 251 | let get_request = get_request.serialize_to_packet().to_vec().map_err(anyhow_err)?; |
Shikha Panwar | 6b17832 | 2023-12-23 00:05:17 +0000 | [diff] [blame] | 252 | let get_response = session.secret_management_request(&get_request)?; |
Shikha Panwar | 5d6a675 | 2023-12-14 22:08:26 +0000 | [diff] [blame] | 253 | let get_response = ResponsePacket::from_slice(&get_response).map_err(anyhow_err)?; |
| 254 | let response_type = get_response.response_type().map_err(anyhow_err)?; |
| 255 | ensure!( |
| 256 | response_type == ResponseType::Success, |
| 257 | "Secretkeeper get failed with error: {:?}", |
| 258 | *SecretkeeperError::deserialize_from_packet(get_response).map_err(anyhow_err)? |
| 259 | ); |
| 260 | let get_response = |
| 261 | *GetSecretResponse::deserialize_from_packet(get_response).map_err(anyhow_err)?; |
| 262 | Ok(get_response.secret.0) |
| 263 | } |
| 264 | |
| 265 | #[inline] |
| 266 | fn anyhow_err<E: core::fmt::Debug>(err: E) -> anyhow::Error { |
| 267 | anyhow!("{:?}", err) |
| 268 | } |
| 269 | |
| 270 | // Get the secretkeeper connection if supported. Host can be consulted whether the device supports |
| 271 | // secretkeeper but that should be used with caution for protected VM. |
| 272 | fn is_sk_supported( |
| 273 | host: &Strong<dyn IVirtualMachineService>, |
| 274 | ) -> Result<Option<Strong<dyn ISecretkeeper>>> { |
| 275 | let sk = if cfg!(llpvm_changes) { |
| 276 | if super::is_strict_boot() { |
| 277 | // TODO: For protected VM check for Secretkeeper authentication data in device tree. |
| 278 | None |
| 279 | } else { |
| 280 | // For non-protected VM, believe what host claims. |
| 281 | host.getSecretkeeper() |
| 282 | // TODO rename this error! |
| 283 | .map_err(|e| { |
| 284 | super::MicrodroidError::FailedToConnectToVirtualizationService(e.to_string()) |
| 285 | })? |
| 286 | } |
| 287 | } else { |
| 288 | // LLPVM flag is disabled |
| 289 | None |
| 290 | }; |
| 291 | Ok(sk) |
Shikha Panwar | 95084df | 2023-07-22 11:47:45 +0000 | [diff] [blame] | 292 | } |