Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dstack-attest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_json.workspace = true
sha2.workspace = true
sha3.workspace = true
tdx-attest.workspace = true
tracing.workspace = true
insta.workspace = true
errify.workspace = true

Expand Down
15 changes: 13 additions & 2 deletions dstack-attest/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

//! Attestation functions

/// Byte range of the REPORT_DATA field within a TDX quote.
/// In Intel TDX ECDSA quote format, the TD Report body starts at offset 568
/// and REPORT_DATA occupies bytes 568..632 (64 bytes).
pub const TDX_QUOTE_REPORT_DATA_RANGE: std::ops::Range<usize> = 568..632;

use std::{borrow::Cow, time::SystemTime};

use anyhow::{anyhow, bail, Context, Result};
Expand Down Expand Up @@ -274,8 +279,14 @@ impl VersionedAttestation {
let VersionedAttestation::V0 { attestation } = self;
attestation.report_data = report_data;
if let Some(tdx_quote) = attestation.tdx_quote_mut() {
if tdx_quote.quote.len() >= 632 {
tdx_quote.quote[568..632].copy_from_slice(&report_data);
if tdx_quote.quote.len() >= TDX_QUOTE_REPORT_DATA_RANGE.end {
tdx_quote.quote[TDX_QUOTE_REPORT_DATA_RANGE].copy_from_slice(&report_data);
} else {
tracing::warn!(
"TDX quote too short to patch report_data ({} < {})",
tdx_quote.quote.len(),
TDX_QUOTE_REPORT_DATA_RANGE.end
);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions guest-agent/src/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use k256::ecdsa::SigningKey;
use or_panic::ResultOrPanic;
use ra_rpc::{Attestation, CallContext, RpcCall};
use ra_tls::{
attestation::{QuoteContentType, VersionedAttestation, DEFAULT_HASH_ALGORITHM},
attestation::{
QuoteContentType, VersionedAttestation, DEFAULT_HASH_ALGORITHM, TDX_QUOTE_REPORT_DATA_RANGE,
},
cert::CertConfigV2,
kdf::{derive_key, derive_p256_key_pair_from_bytes},
};
Expand Down Expand Up @@ -486,7 +488,7 @@ fn simulate_quote(
return Err(anyhow::anyhow!("Quote not found"));
};

quote.quote[568..632].copy_from_slice(&report_data);
quote.quote[TDX_QUOTE_REPORT_DATA_RANGE].copy_from_slice(&report_data);
Ok(GetQuoteResponse {
quote: quote.quote.to_vec(),
event_log: serde_json::to_string(&quote.event_log)
Expand Down
Loading