Skip to content

Commit 047a246

Browse files
committed
kms: Validate TCB attributes
1 parent 7ad4797 commit 047a246

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

ra-tls/src/attestation.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Attestation functions
22
3-
use anyhow::{anyhow, Context, Result};
3+
use anyhow::{anyhow, bail, Context, Result};
44
use dcap_qvl::quote::Quote;
5-
use qvl::{quote::Report, verify::VerifiedReport};
5+
use qvl::{
6+
quote::{EnclaveReport, Report, TDReport10, TDReport15},
7+
verify::VerifiedReport,
8+
};
69
use serde::Serialize;
710
use sha2::{Digest as _, Sha384};
811
use x509_parser::parse_x509_certificate;
@@ -77,7 +80,7 @@ impl QuoteContentType<'_> {
7780
"keccak384" => do_hash!(sha3::Keccak384),
7881
"keccak512" => do_hash!(sha3::Keccak512),
7982
"raw" => content.try_into().ok().context("invalid content length")?,
80-
_ => anyhow::bail!("invalid hash algorithm"),
83+
_ => bail!("invalid hash algorithm"),
8184
};
8285
Ok(output)
8386
}
@@ -289,7 +292,7 @@ impl Attestation {
289292
) -> Result<VerifiedAttestation> {
290293
let quote = &self.quote;
291294
if &self.decode_report_data()? != report_data {
292-
anyhow::bail!("report data mismatch");
295+
bail!("report data mismatch");
293296
}
294297
let report = qvl::collateral::get_collateral_and_verify(quote, pccs_url)
295298
.await
@@ -300,9 +303,10 @@ impl Attestation {
300303
.replay_event_logs(None)
301304
.context("Failed to replay event logs")?;
302305
if rtmrs != [report.rt_mr0, report.rt_mr1, report.rt_mr2, report.rt_mr3] {
303-
anyhow::bail!("RTMR mismatch");
306+
bail!("RTMR mismatch");
304307
}
305308
}
309+
validate_tcb(&report)?;
306310
Ok(VerifiedAttestation {
307311
quote: self.quote,
308312
raw_event_log: self.raw_event_log,
@@ -314,6 +318,47 @@ impl Attestation {
314318

315319
impl Attestation<VerifiedReport> {}
316320

321+
/// Validate the TCB attributes
322+
pub fn validate_tcb(report: &VerifiedReport) -> Result<()> {
323+
fn validate_td10(report: &TDReport10) -> Result<()> {
324+
let is_debug = report.td_attributes[0] & 0x01 != 0;
325+
if is_debug {
326+
bail!("Debug mode is not allowed");
327+
}
328+
if report.mr_signer_seam != [0u8; 48] {
329+
bail!("Invalid mr signer seam");
330+
}
331+
if report.mr_config_id != [0u8; 48] {
332+
bail!("Invalid mr config id");
333+
}
334+
if report.mr_owner != [0u8; 48] {
335+
bail!("Invalid mr owner");
336+
}
337+
if report.mr_owner_config != [0u8; 48] {
338+
bail!("Invalid mr owner config");
339+
}
340+
Ok(())
341+
}
342+
fn validate_td15(report: &TDReport15) -> Result<()> {
343+
if report.mr_service_td != [0u8; 48] {
344+
bail!("Invalid mr service td");
345+
}
346+
validate_td10(&report.base)
347+
}
348+
fn validate_sgx(report: &EnclaveReport) -> Result<()> {
349+
let is_debug = report.attributes[0] & 0x02 != 0;
350+
if is_debug {
351+
bail!("Debug mode is not allowed");
352+
}
353+
Ok(())
354+
}
355+
match &report.report {
356+
Report::TD15(report) => validate_td15(report),
357+
Report::TD10(report) => validate_td10(report),
358+
Report::SgxEnclave(report) => validate_sgx(report),
359+
}
360+
}
361+
317362
/// Information about the app extracted from event log
318363
#[derive(Debug, Clone, Serialize)]
319364
pub struct AppInfo {

tdxctl/src/host_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use host_api::{
88
Notification,
99
};
1010
use key_provider_client::guest::{generate_keypair, open_sealed_box, PUBLICKEYBYTES};
11+
use ra_tls::attestation::validate_tcb;
1112
use tracing::warn;
1213

1314
pub(crate) struct KeyProvision {
@@ -103,6 +104,7 @@ impl HostApi {
103104
dcap_qvl::verify::verify(&provision.provider_quote, &quote_collateral, now)
104105
.ok()
105106
.context("Failed to verify key provider quote")?;
107+
validate_tcb(&verified_report)?;
106108
let sgx_report = verified_report
107109
.report
108110
.as_sgx()

0 commit comments

Comments
 (0)