-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pack the TPM2 PCR files as CPIOs if they are present
- Loading branch information
1 parent
07f6158
commit f260b6f
Showing
5 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
use goblin::pe::{section_table::SectionTable, PE}; | ||
|
||
use crate::pe_section::pe_section_data; | ||
|
||
/// List of PE sections that have a special meaning with respect to | ||
/// UKI specification. | ||
/// This is the canonical order in which they are measured into TPM | ||
/// PCR 11. | ||
/// !!! DO NOT REORDER !!! | ||
pub enum UnifiedSection { | ||
pub enum UnifiedSection<'a> { | ||
Linux, | ||
OsRel, | ||
CmdLine, | ||
Initrd, | ||
Splash, | ||
DTB, | ||
PcrSig, | ||
PcrPkey | ||
} | ||
|
||
impl TryFrom<&str> for UnifiedSection { | ||
type Error = uefi::Error; | ||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
Ok(match value { | ||
".linux" => Self::Linux, | ||
".osrel" => Self::OsRel, | ||
".cmdline" => Self::CmdLine, | ||
".initrd" => Self::Initrd, | ||
".splash" => Self::Splash, | ||
".dtb" => Self::DTB, | ||
".pcrsig" => Self::PcrSig, | ||
".pcrpkey" => Self::PcrPkey, | ||
_ => return Err(uefi::Status::INVALID_PARAMETER.into()) | ||
}) | ||
} | ||
// We only need to store the data for those for now, | ||
// because we need to pack them as CPIOs. | ||
PcrSig(&'a [u8]), | ||
PcrPkey(&'a [u8]) | ||
} | ||
|
||
impl UnifiedSection { | ||
impl<'a> UnifiedSection<'a> { | ||
/// Whether this section should be measured into TPM. | ||
pub fn should_be_measured(&self) -> bool { | ||
match self { | ||
UnifiedSection::PcrSig => false, | ||
UnifiedSection::PcrSig(_) => false, | ||
_ => true | ||
} | ||
} | ||
|
||
pub fn from_section_table(pe: &'a [u8], section: &SectionTable) -> uefi::Result<Self> { | ||
if let Some(data) = pe_section_data(pe, §ion) { | ||
Ok(match section.name().unwrap() { | ||
".linux" => Self::Linux, | ||
".osrel" => Self::OsRel, | ||
".cmdline" => Self::CmdLine, | ||
".initrd" => Self::Initrd, | ||
".splash" => Self::Splash, | ||
".dtb" => Self::DTB, | ||
".pcrsig" => Self::PcrSig(data), | ||
".pcrpkey" => Self::PcrPkey(data), | ||
_ => return Err(uefi::Status::INVALID_PARAMETER.into()) | ||
}) | ||
} else { | ||
// No data in the section is equivalent to missing section. | ||
Err(uefi::Status::INVALID_PARAMETER.into()) | ||
} | ||
} | ||
|
||
} |