Skip to content

Commit 5aabbd0

Browse files
authored
Merge pull request #542 from Dstack-TEE/fix/simulator-report-data-constant
refactor: extract TDX quote report_data offset as a named constant
2 parents 00d3a9f + 3eac438 commit 5aabbd0

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

Cargo.lock

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

dstack-attest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde_json.workspace = true
2626
sha2.workspace = true
2727
sha3.workspace = true
2828
tdx-attest.workspace = true
29+
tracing.workspace = true
2930
insta.workspace = true
3031
errify.workspace = true
3132

dstack-attest/src/attestation.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
//! Attestation functions
66
7+
/// Byte range of the REPORT_DATA field within a TDX quote.
8+
/// In Intel TDX ECDSA quote format, the TD Report body starts at offset 568
9+
/// and REPORT_DATA occupies bytes 568..632 (64 bytes).
10+
pub const TDX_QUOTE_REPORT_DATA_RANGE: std::ops::Range<usize> = 568..632;
11+
712
use std::{borrow::Cow, time::SystemTime};
813

914
use anyhow::{anyhow, bail, Context, Result};
@@ -274,8 +279,14 @@ impl VersionedAttestation {
274279
let VersionedAttestation::V0 { attestation } = self;
275280
attestation.report_data = report_data;
276281
if let Some(tdx_quote) = attestation.tdx_quote_mut() {
277-
if tdx_quote.quote.len() >= 632 {
278-
tdx_quote.quote[568..632].copy_from_slice(&report_data);
282+
if tdx_quote.quote.len() >= TDX_QUOTE_REPORT_DATA_RANGE.end {
283+
tdx_quote.quote[TDX_QUOTE_REPORT_DATA_RANGE].copy_from_slice(&report_data);
284+
} else {
285+
tracing::warn!(
286+
"TDX quote too short to patch report_data ({} < {})",
287+
tdx_quote.quote.len(),
288+
TDX_QUOTE_REPORT_DATA_RANGE.end
289+
);
279290
}
280291
}
281292
}

guest-agent/src/rpc_service.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use k256::ecdsa::SigningKey;
2828
use or_panic::ResultOrPanic;
2929
use ra_rpc::{Attestation, CallContext, RpcCall};
3030
use ra_tls::{
31-
attestation::{QuoteContentType, VersionedAttestation, DEFAULT_HASH_ALGORITHM},
31+
attestation::{
32+
QuoteContentType, VersionedAttestation, DEFAULT_HASH_ALGORITHM, TDX_QUOTE_REPORT_DATA_RANGE,
33+
},
3234
cert::CertConfigV2,
3335
kdf::{derive_key, derive_p256_key_pair_from_bytes},
3436
};
@@ -486,7 +488,7 @@ fn simulate_quote(
486488
return Err(anyhow::anyhow!("Quote not found"));
487489
};
488490

489-
quote.quote[568..632].copy_from_slice(&report_data);
491+
quote.quote[TDX_QUOTE_REPORT_DATA_RANGE].copy_from_slice(&report_data);
490492
Ok(GetQuoteResponse {
491493
quote: quote.quote.to_vec(),
492494
event_log: serde_json::to_string(&quote.event_log)

0 commit comments

Comments
 (0)