From 8b2c35c22829852bdd570eb5296499cd5f4f7c95 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:22:24 +0000 Subject: [PATCH 1/3] attest: carry the boot disk's GPT digests (vaportpm#12) The firmware measures the boot disk's GPT as EV_EFI_GPT_EVENT (PCR5; PCR2 on GCE TDX), and stage2 rewrites that GPT, so a verifier cannot replay the PCR from release artifacts after a first boot. The attestation now carries H(UEFI_GPT_DATA) in sha256 and sha384, read from the disk (not the firmware event log, which not every platform hands to Linux intact). - gpt module: UEFI_GPT_DATA as EDK2 builds it (92-byte header, UINT64 count, non-empty entries), from a block reader or a device/image path. - AttestationOutput.gpt is required; attest()/attest_with() take it; the CLI is `attest [NONCE_HEX]`. - vaportpm-verify's CLI outputs gpt next to the verified PCRs. The quote does not cover it: a replay uses it and is checked against the quoted PCR. The flat (zkVM) format is unchanged. - Test fixtures predate the field and get an all-zero gpt. Co-Authored-By: Claude Opus 5.5 --- crates/vaportpm-attest/README.md | 6 +- crates/vaportpm-attest/src/a9n.rs | 22 +- crates/vaportpm-attest/src/bin/attest.rs | 27 ++- crates/vaportpm-attest/src/gpt.rs | 221 ++++++++++++++++++ crates/vaportpm-attest/src/lib.rs | 2 + crates/vaportpm-verify/src/bin/verify.rs | 31 ++- crates/vaportpm-verify/src/lib.rs | 5 + .../vaportpm-verify/test-gcp-amd-fixture.json | 6 +- .../vaportpm-verify/test-gcp-tdx-fixture.json | 6 +- .../vaportpm-verify/test-nitro-fixture.json | 4 + 10 files changed, 310 insertions(+), 20 deletions(-) create mode 100644 crates/vaportpm-attest/src/gpt.rs diff --git a/crates/vaportpm-attest/README.md b/crates/vaportpm-attest/README.md index 66fa97e..f8522df 100644 --- a/crates/vaportpm-attest/README.md +++ b/crates/vaportpm-attest/README.md @@ -3,9 +3,10 @@ Produces a self-contained attestation document from a cloud vTPM. The output can be verified offline using [`vaportpm-verify`](../vaportpm-verify/). ```rust -use vaportpm_attest::attest; +use vaportpm_attest::{attest, GptDigests}; -let json = attest(nonce)?; +let gpt = GptDigests::read_device(Path::new("/dev/nvme0n1"))?; // the boot disk +let json = attest(nonce, &gpt)?; // Send json to verifier ``` @@ -13,6 +14,7 @@ The library auto-detects the cloud platform (AWS Nitro, GCP Confidential VM) and - TPM2_Quote (signed PCR values) - Platform-specific trust chain (Nitro document or GCP AK certificate) - PCR values and nonce for verification +- The boot disk's GPT digests (`H(UEFI_GPT_DATA)`, sha256 and sha384), read from the disk. Not covered by the quote: they are input for replaying the PCR the firmware's `EV_EFI_GPT_EVENT` extended (PCR5; PCR2 on GCE TDX), and the replayed value is compared with the quoted one. This needs no firmware event log. --- diff --git a/crates/vaportpm-attest/src/a9n.rs b/crates/vaportpm-attest/src/a9n.rs index 5aef411..757d61f 100644 --- a/crates/vaportpm-attest/src/a9n.rs +++ b/crates/vaportpm-attest/src/a9n.rs @@ -16,6 +16,7 @@ use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; use crate::cert::{der_to_pem, fetch_cert_chain, CertFetcher, DER_SEQUENCE_LONG}; +use crate::gpt::GptDigests; use crate::{KeyOps, NsmOps, NvOps, PcrOps, PublicKey, Tpm, TPM_RH_ENDORSEMENT}; /// GCP AK certificate NV index (ECC) @@ -41,6 +42,11 @@ pub struct AttestationOutput { /// Attestation Key public keys (hex-encoded ECC coordinates) pub ak_pubkeys: BTreeMap, pub attestation: AttestationContainer, + /// The boot disk's `H(UEFI_GPT_DATA)` in each bank, read from the disk when the + /// attestation was made. Not covered by the quote: it is input for replaying the PCR the + /// firmware's `EV_EFI_GPT_EVENT` extended (PCR5, or PCR2 on GCE TDX), which the quote does + /// cover. Present whether or not the platform measures the GPT. + pub gpt: GptDigests, } /// ECC public key coordinates @@ -117,6 +123,7 @@ fn is_gcp_tpm(tpm: &mut Tpm) -> bool { /// /// # Arguments /// * `nonce` - User-provided nonce/challenge to include in attestation +/// * `gpt` - The boot disk's GPT digests, carried as replay input (see [`AttestationOutput::gpt`]) /// /// # Returns /// JSON-encoded attestation document containing all attestation data @@ -126,7 +133,12 @@ fn is_gcp_tpm(tpm: &mut Tpm) -> bool { /// Produce the unified attestation JSON for an already-open TPM, using `fetcher` to /// retrieve any AIA intermediate certificates. no_std + alloc: a UEFI caller passes a /// `Tpm` over EFI_TCG2 and a `CertFetcher` over EFI_TCP4. -pub fn attest_with(tpm: &mut Tpm, nonce: &[u8], fetcher: &dyn CertFetcher) -> Result { +pub fn attest_with( + tpm: &mut Tpm, + nonce: &[u8], + gpt: &GptDigests, + fetcher: &dyn CertFetcher, +) -> Result { // Step 1: Detect platform // GCP detection is cheap - just checks for NV index existence let is_nitro = tpm.is_nitro_tpm()?; @@ -221,6 +233,7 @@ pub fn attest_with(tpm: &mut Tpm, nonce: &[u8], fetcher: &dyn CertFetcher) -> Re pcrs: pcrs_by_alg, ak_pubkeys: signing_key_public_keys, attestation, + gpt: gpt.clone(), }; let json = serde_json::to_string_pretty(&output)?; @@ -228,11 +241,12 @@ pub fn attest_with(tpm: &mut Tpm, nonce: &[u8], fetcher: &dyn CertFetcher) -> Re Ok(json) } -/// Convenience std entrypoint: open /dev/tpm0 and use the built-in HTTP fetcher. +/// Convenience std entrypoint: open /dev/tpm0 and use the built-in HTTP fetcher. `gpt` is +/// the boot disk's ([`GptDigests::read_device`]). #[cfg(feature = "http-fetch")] -pub fn attest(nonce: &[u8]) -> Result { +pub fn attest(nonce: &[u8], gpt: &GptDigests) -> Result { let mut tpm = Tpm::open_direct()?; - attest_with(&mut tpm, nonce, &crate::cert::StdHttpFetcher) + attest_with(&mut tpm, nonce, gpt, &crate::cert::StdHttpFetcher) } /// Nitro attestation path: create restricted AK and use TPM2_Quote diff --git a/crates/vaportpm-attest/src/bin/attest.rs b/crates/vaportpm-attest/src/bin/attest.rs index 99608e8..28a6b6d 100644 --- a/crates/vaportpm-attest/src/bin/attest.rs +++ b/crates/vaportpm-attest/src/bin/attest.rs @@ -3,12 +3,14 @@ //! vaportpm-attest — TPM attestation and PCR-bound key derivation //! //! Usage: -//! vaportpm-attest attest [NONCE_HEX] Attestation (JSON to stdout) +//! vaportpm-attest attest [NONCE_HEX] +//! Attestation (JSON to stdout); DISK is the boot +//! disk, whose GPT digests the attestation carries //! vaportpm-attest derive