#azure #tdx #tpm #virtualization

bin+lib az-tdx-vtpm

vTPM based TDX attestation for Azure Confidential VMs

6 releases

new 0.5.3 May 14, 2024
0.5.2 Feb 23, 2024
0.5.1 Jan 26, 2024
0.4.1 Dec 19, 2023
0.4.0 Nov 28, 2023

#992 in Cryptography

Download history 529/week @ 2024-01-24 432/week @ 2024-01-31 293/week @ 2024-02-07 424/week @ 2024-02-14 538/week @ 2024-02-21 241/week @ 2024-02-28 393/week @ 2024-03-06 358/week @ 2024-03-13 268/week @ 2024-03-20 204/week @ 2024-03-27 263/week @ 2024-04-03 210/week @ 2024-04-10 442/week @ 2024-04-17 306/week @ 2024-04-24 179/week @ 2024-05-01 167/week @ 2024-05-08

1,142 downloads per month

MIT license

36KB
626 lines

az-tdx-vtpm

Rust Crate Docs

This library enables guest attestation and verification for TDX CVMs on Azure.

Build & Install

cargo b --release -p az-tdx-vtpm
scp ../target/release/tdx-vtpm azureuser@$CONFIDENTIAL_VM:

Run Binary

On the TDX CVM, retrieve a TD Quote and write it to disk:

sudo ./tdx-vtpm

lib.rs:

This library enables guest attestation flows for TDX CVMs on Azure.

A TD report can be retrieved in parsed form using report::get_report() function, or as raw bytes including the hcl envelope using vtpm::get_report(). The library provides a function to retrieve the TD quote from the Azure Instance Metadata Service (IMDS) using imds::get_td_quote(), produce returning a quote signed by a TDX Quoting Enclave.

Variable Data is part of the HCL envelope and holds the public part of the vTPM Attestation Key (AK). A hash of the Variable Data block is included in the TD report as reportdata. TPM quotes retrieved with vtpm::get_quote() should be signed by this AK. A verification function would need to check this to ensure the TD report is linked to this unique TDX CVM.

use az_tdx_vtpm::{hcl, imds, report, tdx, vtpm};
use openssl::pkey::{PKey, Public};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
  let td_report = report::get_report()?;
  let td_quote_bytes = imds::get_td_quote(&td_report)?;
  std::fs::write("td_quote.bin", td_quote_bytes)?;

  let bytes = vtpm::get_report()?;
  let hcl_report = hcl::HclReport::new(bytes)?;
  let var_data_hash = hcl_report.var_data_sha256();
  let ak_pub = hcl_report.ak_pub()?;

  let td_report: tdx::TdReport = hcl_report.try_into()?;
  assert!(var_data_hash == td_report.report_mac.reportdata[..32]);
  let nonce = "a nonce".as_bytes();

  let tpm_quote = vtpm::get_quote(nonce)?;
  let der = ak_pub.key.try_to_der()?;
  let pub_key = PKey::public_key_from_der(&der)?;
  tpm_quote.verify(&pub_key, nonce)?;

  Ok(())
}

Dependencies

~15–27MB
~450K SLoC