Skip to content

Commit 7911a5b

Browse files
authored
Merge pull request #83 from Freax13/enhancement/bundle-vcek
bundle VCEK with attestaton report
2 parents 5ff53a0 + 4cb1fb3 commit 7911a5b

File tree

10 files changed

+379
-165
lines changed

10 files changed

+379
-165
lines changed

host/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

host/mushroom-verify/src/lib.rs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,72 @@
11
use io::input::Header;
22
use sha2::{Digest, Sha256};
3+
#[cfg(feature = "snp")]
4+
use snp_types::{attestation::TcbVersion, guest_policy::GuestPolicy};
5+
#[cfg(feature = "tdx")]
6+
use tdx_types::td_quote::TeeTcbSvn;
37

48
#[cfg(feature = "snp")]
5-
pub mod snp;
9+
mod snp;
610
#[cfg(feature = "tdx")]
7-
pub mod tdx;
11+
mod tdx;
12+
13+
pub struct Configuration(ConfigurationImpl);
14+
15+
enum ConfigurationImpl {
16+
#[cfg(feature = "snp")]
17+
Snp(snp::Configuration),
18+
#[cfg(feature = "tdx")]
19+
Tdx(tdx::Configuration),
20+
}
21+
22+
impl Configuration {
23+
#[cfg(feature = "snp")]
24+
pub fn new_snp(
25+
supervisor: &[u8],
26+
kernel: &[u8],
27+
init: &[u8],
28+
load_kasan_shadow_mappings: bool,
29+
policy: GuestPolicy,
30+
min_tcb: TcbVersion,
31+
) -> Self {
32+
Self(ConfigurationImpl::Snp(snp::Configuration::new(
33+
supervisor,
34+
kernel,
35+
init,
36+
load_kasan_shadow_mappings,
37+
policy,
38+
min_tcb,
39+
)))
40+
}
41+
42+
#[cfg(feature = "tdx")]
43+
pub fn new_tdx(supervisor: &[u8], kernel: &[u8], init: &[u8], tee_tcb_svn: TeeTcbSvn) -> Self {
44+
Self(ConfigurationImpl::Tdx(tdx::Configuration::new(
45+
supervisor,
46+
kernel,
47+
init,
48+
tee_tcb_svn,
49+
)))
50+
}
51+
52+
pub fn verify(
53+
&self,
54+
input_hash: InputHash,
55+
output_hash: OutputHash,
56+
attestation_report: &[u8],
57+
) -> Result<(), VerificationError> {
58+
match self.0 {
59+
#[cfg(feature = "snp")]
60+
ConfigurationImpl::Snp(ref configuration) => {
61+
configuration.verify(input_hash, output_hash, attestation_report)
62+
}
63+
#[cfg(feature = "tdx")]
64+
ConfigurationImpl::Tdx(ref configuration) => {
65+
configuration.verify(input_hash, output_hash, attestation_report)
66+
}
67+
}
68+
}
69+
}
870

971
#[derive(Debug)]
1072
pub struct VerificationError(());

host/mushroom-verify/src/snp.rs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use std::{
2-
cmp::Ordering,
3-
fmt::{self, Display},
4-
mem::size_of,
5-
};
1+
use std::{cmp::Ordering, mem::size_of};
62

73
use bytemuck::{bytes_of, checked::try_pod_read_unaligned, pod_read_unaligned, NoUninit};
84
use loader::{generate_base_load_commands, LoadCommand, LoadCommandPayload};
@@ -60,10 +56,18 @@ impl Configuration {
6056
input_hash: InputHash,
6157
output_hash: OutputHash,
6258
attestation_report: &[u8],
63-
vcek: &Vcek,
6459
) -> Result<(), VerificationError> {
60+
// The VCEK is appended to the attestation report. Split the two.
61+
const REPORT_LEN: usize = size_of::<AttestionReport>();
62+
if attestation_report.len() < REPORT_LEN {
63+
return Err(VerificationError(()));
64+
}
65+
let (attestation_report, vcek) = attestation_report.split_at(REPORT_LEN);
66+
67+
// Parse the attestation report and the VCEK.
6568
let report = try_pod_read_unaligned::<AttestionReport>(attestation_report)
6669
.map_err(|_| VerificationError(()))?;
70+
let vcek = Vcek::from_bytes(vcek.to_owned()).map_err(|_| VerificationError(()))?;
6771

6872
let AttestionReport::V2(report) = report;
6973

@@ -114,45 +118,6 @@ impl Configuration {
114118
}
115119
}
116120

117-
#[derive(Clone, Copy)]
118-
pub struct VcekParameters {
119-
pub chip_id: ChipId,
120-
pub tcb: TcbVersion,
121-
}
122-
123-
impl VcekParameters {
124-
/// Extract the VCEK parameters from an attestation report.
125-
///
126-
/// This information is necessairy to retrieve the VCEK.
127-
pub fn for_attestaton_report(
128-
attestation_report: &[u8],
129-
) -> Result<VcekParameters, VerificationError> {
130-
let attestion_report = try_pod_read_unaligned::<AttestionReport>(attestation_report)
131-
.map_err(|_| VerificationError(()))?;
132-
let AttestionReport::V2(report) = attestion_report;
133-
Ok(VcekParameters {
134-
chip_id: ChipId {
135-
chip_id: report.chip_id,
136-
},
137-
tcb: report.reported_tcb,
138-
})
139-
}
140-
}
141-
142-
#[derive(Clone, Copy)]
143-
pub struct ChipId {
144-
pub chip_id: [u8; 64],
145-
}
146-
147-
impl Display for ChipId {
148-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149-
for b in self.chip_id.iter() {
150-
write!(f, "{b:02x}")?;
151-
}
152-
Ok(())
153-
}
154-
}
155-
156121
#[derive(Clone, Copy, NoUninit)]
157122
#[repr(C)]
158123
struct PageInfo {

host/mushroom/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ required-features = ["bin"]
1010
[features]
1111
default = ["insecure", "snp", "tdx"]
1212
insecure = ["dep:loader", "dep:snp-types", "dep:supervisor-services"]
13-
snp = ["dep:loader", "mushroom-verify?/snp", "dep:snp-types"]
13+
snp = ["dep:loader", "mushroom-verify?/snp", "dep:snp-types", "dep:vcek-kds"]
1414
tdx = ["dep:loader", "mushroom-verify?/tdx", "dep:qgs-client", "dep:tdx-types"]
15-
bin = ["dep:clap", "dep:mushroom-verify", "dep:tokio", "dep:tracing-subscriber", "dep:vcek-kds"]
15+
bin = ["dep:clap", "dep:mushroom-verify", "dep:tokio", "dep:tracing-subscriber", "dep:xdg"]
1616

1717
[dependencies]
1818
anyhow = "1.0.81"
@@ -37,3 +37,4 @@ tracing-subscriber = { version = "0.3.18", optional = true }
3737
vcek-kds = { workspace = true, optional = true }
3838
volatile = { version = "0.5.1", features = [] }
3939
x86_64 = { version = "0.15.1", default-features = false }
40+
xdg = { version = "2.5.2", optional = true }

0 commit comments

Comments
 (0)