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