Alice Wang | 28cbcf1 | 2022-12-01 07:58:28 +0000 | [diff] [blame] | 1 | // Copyright 2022, 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 | |
Alice Wang | f3d96b1 | 2022-12-15 13:10:47 +0000 | [diff] [blame] | 15 | //! This module handles the pvmfw payload verification. |
Alice Wang | 28cbcf1 | 2022-12-01 07:58:28 +0000 | [diff] [blame] | 16 | |
Alice Wang | 167ab3f | 2023-01-23 13:39:25 +0000 | [diff] [blame] | 17 | use crate::ops::{Ops, Payload}; |
Alice Wang | 8077a86 | 2023-01-18 16:06:37 +0000 | [diff] [blame] | 18 | use crate::partition::PartitionName; |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 19 | use crate::PvmfwVerifyError; |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 20 | use alloc::vec; |
| 21 | use alloc::vec::Vec; |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 22 | use avb::{ |
| 23 | Descriptor, DescriptorError, DescriptorResult, HashDescriptor, PartitionData, |
| 24 | PropertyDescriptor, SlotVerifyError, SlotVerifyNoDataResult, VbmetaData, |
| 25 | }; |
Alice Wang | 28cbcf1 | 2022-12-01 07:58:28 +0000 | [diff] [blame] | 26 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 27 | // We use this for the rollback_index field if SlotVerifyData has empty rollback_indexes |
Shikha Panwar | a26f16a | 2023-09-27 09:39:00 +0000 | [diff] [blame] | 28 | const DEFAULT_ROLLBACK_INDEX: u64 = 0; |
| 29 | |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 30 | /// SHA256 digest type for kernel and initrd. |
| 31 | pub type Digest = [u8; 32]; |
| 32 | |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 33 | /// Verified data returned when the payload verification succeeds. |
Pierre-Clément Tosi | 81ca080 | 2023-02-14 10:41:38 +0000 | [diff] [blame] | 34 | #[derive(Debug, PartialEq, Eq)] |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 35 | pub struct VerifiedBootData<'a> { |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 36 | /// DebugLevel of the VM. |
| 37 | pub debug_level: DebugLevel, |
| 38 | /// Kernel digest. |
| 39 | pub kernel_digest: Digest, |
| 40 | /// Initrd digest if initrd exists. |
| 41 | pub initrd_digest: Option<Digest>, |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 42 | /// Trusted public key. |
| 43 | pub public_key: &'a [u8], |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 44 | /// VM capabilities. |
| 45 | pub capabilities: Vec<Capability>, |
Shikha Panwar | a26f16a | 2023-09-27 09:39:00 +0000 | [diff] [blame] | 46 | /// Rollback index of kernel. |
| 47 | pub rollback_index: u64, |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Shikha Panwar | 4a0651d | 2023-09-28 13:06:13 +0000 | [diff] [blame] | 50 | impl VerifiedBootData<'_> { |
| 51 | /// Returns whether the kernel have the given capability |
| 52 | pub fn has_capability(&self, cap: Capability) -> bool { |
| 53 | self.capabilities.contains(&cap) |
| 54 | } |
| 55 | } |
| 56 | |
Alice Wang | 5c1a756 | 2023-01-13 17:19:57 +0000 | [diff] [blame] | 57 | /// This enum corresponds to the `DebugLevel` in `VirtualMachineConfig`. |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 58 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
Alice Wang | 5c1a756 | 2023-01-13 17:19:57 +0000 | [diff] [blame] | 59 | pub enum DebugLevel { |
| 60 | /// Not debuggable at all. |
| 61 | None, |
| 62 | /// Fully debuggable. |
| 63 | Full, |
| 64 | } |
| 65 | |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 66 | /// VM Capability. |
Shikha Panwar | 4a0651d | 2023-09-28 13:06:13 +0000 | [diff] [blame] | 67 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 68 | pub enum Capability { |
| 69 | /// Remote attestation. |
| 70 | RemoteAttest, |
Shikha Panwar | 4a0651d | 2023-09-28 13:06:13 +0000 | [diff] [blame] | 71 | /// Secretkeeper protected secrets. |
| 72 | SecretkeeperProtection, |
Nikolina Ilic | 57ba9c4 | 2024-10-01 09:50:48 +0000 | [diff] [blame] | 73 | /// UEFI support for booting guest kernel. |
| 74 | SupportsUefiBoot, |
| 75 | /// (internal) |
| 76 | #[allow(non_camel_case_types)] // TODO: Use mem::variant_count once stable. |
| 77 | _VARIANT_COUNT, |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | impl Capability { |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 81 | const KEY: &'static str = "com.android.virt.cap"; |
Chris Wailes | 98f1823 | 2023-12-07 12:04:21 -0800 | [diff] [blame] | 82 | const REMOTE_ATTEST: &'static [u8] = b"remote_attest"; |
| 83 | const SECRETKEEPER_PROTECTION: &'static [u8] = b"secretkeeper_protection"; |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 84 | const SEPARATOR: u8 = b'|'; |
Nikolina Ilic | 57ba9c4 | 2024-10-01 09:50:48 +0000 | [diff] [blame] | 85 | const SUPPORTS_UEFI_BOOT: &'static [u8] = b"supports_uefi_boot"; |
| 86 | /// Number of supported capabilites. |
| 87 | pub const COUNT: usize = Self::_VARIANT_COUNT as usize; |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 88 | |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 89 | /// Returns the capabilities indicated in `descriptor`, or error if the descriptor has |
| 90 | /// unexpected contents. |
| 91 | fn get_capabilities(descriptor: &PropertyDescriptor) -> Result<Vec<Self>, PvmfwVerifyError> { |
| 92 | if descriptor.key != Self::KEY { |
| 93 | return Err(PvmfwVerifyError::UnknownVbmetaProperty); |
| 94 | } |
| 95 | |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 96 | let mut res = Vec::new(); |
| 97 | |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 98 | for v in descriptor.value.split(|b| *b == Self::SEPARATOR) { |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 99 | let cap = match v { |
| 100 | Self::REMOTE_ATTEST => Self::RemoteAttest, |
Shikha Panwar | 4a0651d | 2023-09-28 13:06:13 +0000 | [diff] [blame] | 101 | Self::SECRETKEEPER_PROTECTION => Self::SecretkeeperProtection, |
Nikolina Ilic | 57ba9c4 | 2024-10-01 09:50:48 +0000 | [diff] [blame] | 102 | Self::SUPPORTS_UEFI_BOOT => Self::SupportsUefiBoot, |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 103 | _ => return Err(PvmfwVerifyError::UnknownVbmetaProperty), |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 104 | }; |
| 105 | if res.contains(&cap) { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 106 | return Err(SlotVerifyError::InvalidMetadata.into()); |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 107 | } |
| 108 | res.push(cap); |
| 109 | } |
| 110 | Ok(res) |
| 111 | } |
| 112 | } |
| 113 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 114 | fn verify_only_one_vbmeta_exists(vbmeta_data: &[VbmetaData]) -> SlotVerifyNoDataResult<()> { |
| 115 | if vbmeta_data.len() == 1 { |
Alice Wang | d3f28ae | 2023-01-25 10:41:40 +0000 | [diff] [blame] | 116 | Ok(()) |
| 117 | } else { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 118 | Err(SlotVerifyError::InvalidMetadata) |
Alice Wang | d3f28ae | 2023-01-25 10:41:40 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 122 | fn verify_vbmeta_is_from_kernel_partition(vbmeta_image: &VbmetaData) -> SlotVerifyNoDataResult<()> { |
| 123 | match vbmeta_image.partition_name().try_into() { |
Alice Wang | 9dfb296 | 2023-01-18 10:01:34 +0000 | [diff] [blame] | 124 | Ok(PartitionName::Kernel) => Ok(()), |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 125 | _ => Err(SlotVerifyError::InvalidMetadata), |
Alice Wang | 9dfb296 | 2023-01-18 10:01:34 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 129 | fn verify_loaded_partition_has_expected_length( |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 130 | loaded_partitions: &[PartitionData], |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 131 | partition_name: PartitionName, |
| 132 | expected_len: usize, |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 133 | ) -> SlotVerifyNoDataResult<()> { |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 134 | if loaded_partitions.len() != 1 { |
| 135 | // Only one partition should be loaded in each verify result. |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 136 | return Err(SlotVerifyError::Io); |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 137 | } |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 138 | let loaded_partition = &loaded_partitions[0]; |
| 139 | if !PartitionName::try_from(loaded_partition.partition_name()) |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 140 | .map_or(false, |p| p == partition_name) |
| 141 | { |
| 142 | // Only the requested partition should be loaded. |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 143 | return Err(SlotVerifyError::Io); |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 144 | } |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 145 | if loaded_partition.data().len() == expected_len { |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 146 | Ok(()) |
| 147 | } else { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 148 | Err(SlotVerifyError::Verification(None)) |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 152 | /// Verifies that the vbmeta contains at most one property descriptor and it indicates the |
| 153 | /// vm type is service VM. |
| 154 | fn verify_property_and_get_capabilities( |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 155 | descriptors: &[Descriptor], |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 156 | ) -> Result<Vec<Capability>, PvmfwVerifyError> { |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 157 | let mut iter = descriptors.iter().filter_map(|d| match d { |
| 158 | Descriptor::Property(p) => Some(p), |
| 159 | _ => None, |
| 160 | }); |
| 161 | |
| 162 | let descriptor = match iter.next() { |
| 163 | // No property descriptors -> no capabilities. |
| 164 | None => return Ok(vec![]), |
| 165 | Some(d) => d, |
| 166 | }; |
| 167 | |
| 168 | // Multiple property descriptors -> error. |
| 169 | if iter.next().is_some() { |
| 170 | return Err(DescriptorError::InvalidContents.into()); |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 171 | } |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 172 | |
| 173 | Capability::get_capabilities(descriptor) |
| 174 | } |
| 175 | |
| 176 | /// Hash descriptors extracted from a vbmeta image. |
| 177 | /// |
| 178 | /// We always have a kernel hash descriptor and may have initrd normal or debug descriptors. |
| 179 | struct HashDescriptors<'a> { |
| 180 | kernel: &'a HashDescriptor<'a>, |
| 181 | initrd_normal: Option<&'a HashDescriptor<'a>>, |
| 182 | initrd_debug: Option<&'a HashDescriptor<'a>>, |
| 183 | } |
| 184 | |
| 185 | impl<'a> HashDescriptors<'a> { |
| 186 | /// Extracts the hash descriptors from all vbmeta descriptors. Any unexpected hash descriptor |
| 187 | /// is an error. |
| 188 | fn get(descriptors: &'a [Descriptor<'a>]) -> DescriptorResult<Self> { |
| 189 | let mut kernel = None; |
| 190 | let mut initrd_normal = None; |
| 191 | let mut initrd_debug = None; |
| 192 | |
| 193 | for descriptor in descriptors.iter().filter_map(|d| match d { |
| 194 | Descriptor::Hash(h) => Some(h), |
| 195 | _ => None, |
| 196 | }) { |
| 197 | let target = match descriptor |
| 198 | .partition_name |
| 199 | .as_bytes() |
| 200 | .try_into() |
| 201 | .map_err(|_| DescriptorError::InvalidContents)? |
| 202 | { |
| 203 | PartitionName::Kernel => &mut kernel, |
| 204 | PartitionName::InitrdNormal => &mut initrd_normal, |
| 205 | PartitionName::InitrdDebug => &mut initrd_debug, |
| 206 | }; |
| 207 | |
| 208 | if target.is_some() { |
| 209 | // Duplicates of the same partition name is an error. |
| 210 | return Err(DescriptorError::InvalidContents); |
| 211 | } |
| 212 | target.replace(descriptor); |
| 213 | } |
| 214 | |
| 215 | // Kernel is required, the others are optional. |
| 216 | Ok(Self { |
| 217 | kernel: kernel.ok_or(DescriptorError::InvalidContents)?, |
| 218 | initrd_normal, |
| 219 | initrd_debug, |
| 220 | }) |
| 221 | } |
| 222 | |
| 223 | /// Returns an error if either initrd descriptor exists. |
| 224 | fn verify_no_initrd(&self) -> Result<(), PvmfwVerifyError> { |
| 225 | match self.initrd_normal.or(self.initrd_debug) { |
| 226 | Some(_) => Err(SlotVerifyError::InvalidMetadata.into()), |
| 227 | None => Ok(()), |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /// Returns a copy of the SHA256 digest in `descriptor`, or error if the sizes don't match. |
| 233 | fn copy_digest(descriptor: &HashDescriptor) -> SlotVerifyNoDataResult<Digest> { |
| 234 | let mut digest = Digest::default(); |
| 235 | if descriptor.digest.len() != digest.len() { |
| 236 | return Err(SlotVerifyError::InvalidMetadata); |
| 237 | } |
| 238 | digest.clone_from_slice(descriptor.digest); |
| 239 | Ok(digest) |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 240 | } |
| 241 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 242 | /// Verifies the given initrd partition, and checks that the resulting contents looks like expected. |
| 243 | fn verify_initrd( |
| 244 | ops: &mut Ops, |
| 245 | partition_name: PartitionName, |
| 246 | expected_initrd: &[u8], |
| 247 | ) -> SlotVerifyNoDataResult<()> { |
| 248 | let result = |
| 249 | ops.verify_partition(partition_name.as_cstr()).map_err(|e| e.without_verify_data())?; |
| 250 | verify_loaded_partition_has_expected_length( |
| 251 | result.partition_data(), |
| 252 | partition_name, |
| 253 | expected_initrd.len(), |
| 254 | ) |
| 255 | } |
| 256 | |
Alice Wang | f3d96b1 | 2022-12-15 13:10:47 +0000 | [diff] [blame] | 257 | /// Verifies the payload (signed kernel + initrd) against the trusted public key. |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 258 | pub fn verify_payload<'a>( |
Alice Wang | 6b486f1 | 2023-01-06 13:12:16 +0000 | [diff] [blame] | 259 | kernel: &[u8], |
| 260 | initrd: Option<&[u8]>, |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 261 | trusted_public_key: &'a [u8], |
David Pursell | a7c727b | 2023-08-14 16:24:40 -0700 | [diff] [blame] | 262 | ) -> Result<VerifiedBootData<'a>, PvmfwVerifyError> { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 263 | let payload = Payload::new(kernel, initrd, trusted_public_key); |
| 264 | let mut ops = Ops::new(&payload); |
Alice Wang | 167ab3f | 2023-01-23 13:39:25 +0000 | [diff] [blame] | 265 | let kernel_verify_result = ops.verify_partition(PartitionName::Kernel.as_cstr())?; |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 266 | |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 267 | let vbmeta_images = kernel_verify_result.vbmeta_data(); |
Shikha Panwar | a26f16a | 2023-09-27 09:39:00 +0000 | [diff] [blame] | 268 | // TODO(b/302093437): Use explicit rollback_index_location instead of default |
| 269 | // location (first element). |
| 270 | let rollback_index = |
| 271 | *kernel_verify_result.rollback_indexes().first().unwrap_or(&DEFAULT_ROLLBACK_INDEX); |
Alice Wang | d3f28ae | 2023-01-25 10:41:40 +0000 | [diff] [blame] | 272 | verify_only_one_vbmeta_exists(vbmeta_images)?; |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 273 | let vbmeta_image = &vbmeta_images[0]; |
| 274 | verify_vbmeta_is_from_kernel_partition(vbmeta_image)?; |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 275 | let descriptors = vbmeta_image.descriptors()?; |
| 276 | let hash_descriptors = HashDescriptors::get(&descriptors)?; |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 277 | let capabilities = verify_property_and_get_capabilities(&descriptors)?; |
Alice Wang | d3f28ae | 2023-01-25 10:41:40 +0000 | [diff] [blame] | 278 | |
Alice Wang | 167ab3f | 2023-01-23 13:39:25 +0000 | [diff] [blame] | 279 | if initrd.is_none() { |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 280 | hash_descriptors.verify_no_initrd()?; |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 281 | return Ok(VerifiedBootData { |
| 282 | debug_level: DebugLevel::None, |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 283 | kernel_digest: copy_digest(hash_descriptors.kernel)?, |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 284 | initrd_digest: None, |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 285 | public_key: trusted_public_key, |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 286 | capabilities, |
Shikha Panwar | a26f16a | 2023-09-27 09:39:00 +0000 | [diff] [blame] | 287 | rollback_index, |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 288 | }); |
Alice Wang | 86383df | 2023-01-11 10:03:56 +0000 | [diff] [blame] | 289 | } |
Alice Wang | 5c1a756 | 2023-01-13 17:19:57 +0000 | [diff] [blame] | 290 | |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 291 | let initrd = initrd.unwrap(); |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 292 | let (debug_level, initrd_descriptor) = |
David Pursell | 09bfc85 | 2024-02-02 11:24:24 -0800 | [diff] [blame] | 293 | if verify_initrd(&mut ops, PartitionName::InitrdNormal, initrd).is_ok() { |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 294 | (DebugLevel::None, hash_descriptors.initrd_normal) |
David Pursell | 09bfc85 | 2024-02-02 11:24:24 -0800 | [diff] [blame] | 295 | } else if verify_initrd(&mut ops, PartitionName::InitrdDebug, initrd).is_ok() { |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 296 | (DebugLevel::Full, hash_descriptors.initrd_debug) |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 297 | } else { |
David Pursell | b59bcc4 | 2023-11-10 16:59:19 -0800 | [diff] [blame] | 298 | return Err(SlotVerifyError::Verification(None).into()); |
Alice Wang | 75d0563 | 2023-01-25 13:31:18 +0000 | [diff] [blame] | 299 | }; |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 300 | let initrd_descriptor = initrd_descriptor.ok_or(DescriptorError::InvalidContents)?; |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 301 | Ok(VerifiedBootData { |
| 302 | debug_level, |
David Pursell | c420c8b | 2024-01-17 10:52:19 -0800 | [diff] [blame] | 303 | kernel_digest: copy_digest(hash_descriptors.kernel)?, |
| 304 | initrd_digest: Some(copy_digest(initrd_descriptor)?), |
Pierre-Clément Tosi | f58f3a3 | 2023-02-02 16:24:23 +0000 | [diff] [blame] | 305 | public_key: trusted_public_key, |
Alice Wang | ab0d020 | 2023-05-17 08:07:41 +0000 | [diff] [blame] | 306 | capabilities, |
Shikha Panwar | a26f16a | 2023-09-27 09:39:00 +0000 | [diff] [blame] | 307 | rollback_index, |
Alice Wang | 1f0add0 | 2023-01-23 16:22:53 +0000 | [diff] [blame] | 308 | }) |
Alice Wang | 28cbcf1 | 2022-12-01 07:58:28 +0000 | [diff] [blame] | 309 | } |