Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: small corrections #142

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions crates/sgx_validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,53 +89,53 @@ impl Sgx {
hash.as_slice() == &rpt.reportdata[..hash.as_slice().len()],
"sgx report data is invalid"
);
}

if let Some(config) = config {
if !config.measurements.signer.is_empty() {
let signed = config.measurements.signer.contains(&rpt.mrsigner);
ensure!(signed, "sgx untrusted enarx signer");
}

if !config.measurements.hash.is_empty() {
let approved = config.measurements.hash.contains(&rpt.mrenclave);
ensure!(approved, "sgx untrusted enarx hash");
}

if !config.measurements.hash_blacklist.is_empty() {
let denied = config.measurements.hash_blacklist.contains(&rpt.mrenclave);
ensure!(!denied, "sgx untrusted enarx hash");
}

if let Some(product_id) = config.enclave_product_id {
ensure!(
rpt.enclave_product_id() == product_id,
"sgx untrusted enclave product id",
);
}

if let Some(version) = config.enclave_security_version {
ensure!(
rpt.enclave_security_version() >= version,
"sgx untrusted enclave security version"
);
}

if !config.features.is_empty()
&& !rpt
.attributes()
.features()
.difference(config.features)
.is_empty()
{
bail!("sgx untrusted features");
}

if let Some(config) = config {
if !config.measurements.signer.is_empty() {
let signed = config.measurements.signer.contains(&rpt.mrsigner);
ensure!(signed, "sgx untrusted enarx signer");
}

if !config.measurements.hash.is_empty() {
let approved = config.measurements.hash.contains(&rpt.mrenclave);
ensure!(approved, "sgx untrusted enarx hash");
}

if !config.measurements.hash_blacklist.is_empty() {
let denied = config.measurements.hash_blacklist.contains(&rpt.mrenclave);
ensure!(!denied, "sgx untrusted enarx hash");
}

if let Some(product_id) = config.enclave_product_id {
ensure!(
rpt.enclave_product_id() == product_id,
"sgx untrusted enclave product id",
);
}

if let Some(version) = config.enclave_security_version {
ensure!(
rpt.enclave_security_version() >= version,
"sgx untrusted enclave security version"
);
}

if !config.features.is_empty()
&& !rpt
.attributes()
.features()
.difference(config.features)
.is_empty()
{
bail!("sgx untrusted features");
}

if !config.misc_select.is_empty() {
ensure!(
rpt.misc_select().difference(config.misc_select).is_empty(),
"sgx untrusted misc select"
);
}
if !config.misc_select.is_empty() {
ensure!(
rpt.misc_select().difference(config.misc_select).is_empty(),
"sgx untrusted misc select"
);
}
}

Expand Down
34 changes: 16 additions & 18 deletions crates/snp_validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ impl Snp {
)
.context("snp report contains invalid signature")?;

// TODO: additional field validations.

// Should only be version 2
ensure!(
report.body.version == 2,
Expand Down Expand Up @@ -369,21 +367,35 @@ impl Snp {
"snp report platform_info reserved fields were set"
);

// Check fields not set by Enarx
ensure!(report.body.sig_algo == 1, "snp signature algorithm not 1");

// Check fields not set by Enarx
// Check fields set by Enarx
ensure!(report.body.family_id == [0; 16], "snp family id was set");

ensure!(report.body.image_id == [0; 16], "snp image id was set");

// Check fields set by Enarx
ensure!(
report.body.host_data == [0; 32],
"snp report host_data field should not be set by Enarx"
);

ensure!(report.body.vmpl == 0, "snp report vmpl field invalid value");

if !dbg {
// Validate that the certification request came from an SNP VM.
let hash = Sha384::digest(cri.public_key.to_vec()?);
ensure!(
hash.as_slice() == &report.body.report_data[..hash.as_slice().len()],
"snp report.report_data is invalid"
);

ensure!(
!report.body.policy.flags.contains(PolicyFlags::Debug),
"snp guest policy permits debugging"
);
}

if let Some(config) = config {
ensure!(
config.abi.matches(&report.body.policy.into()),
Expand Down Expand Up @@ -436,20 +448,6 @@ impl Snp {
}
}

if !dbg {
// Validate that the certification request came from an SNP VM.
let hash = Sha384::digest(cri.public_key.to_vec()?);
ensure!(
hash.as_slice() == &report.body.report_data[..hash.as_slice().len()],
"snp report.report_data is invalid"
);

ensure!(
!report.body.policy.flags.contains(PolicyFlags::Debug),
"snp guest policy permits debugging"
);
}

Ok(false)
}
}