Skip to content

Instantly share code, notes, and snippets.

@alexhulbert
Created September 10, 2025 00:51
Show Gist options
  • Select an option

  • Save alexhulbert/58724da78b7eeba413053b99eba79d08 to your computer and use it in GitHub Desktop.

Select an option

Save alexhulbert/58724da78b7eeba413053b99eba79d08 to your computer and use it in GitHub Desktop.
Gets Google OVMF firmware based on MRTD
#!/usr/bin/env python3
import sys, os, subprocess, tempfile, urllib.request
with tempfile.TemporaryDirectory() as d:
# Download proto files
urllib.request.urlretrieve("https://raw.githubusercontent.com/google/gce-tcb-verifier/refs/heads/main/proto/endorsement.proto", f"{d}/endorsement.proto")
os.makedirs(f"{d}/google/protobuf", exist_ok=True)
urllib.request.urlretrieve("https://raw.githubusercontent.com/protocolbuffers/protobuf/main/src/google/protobuf/timestamp.proto", f"{d}/google/protobuf/timestamp.proto")
# Download binarypb
subprocess.run(['gsutil', 'cp', f'gs://gce_tcb_integrity/ovmf_x64_csm/tdx/{sys.argv[1]}.binarypb', f'{d}/m.pb'], check=True)
# Compile proto and extract digest
subprocess.run(['protoc', f'--proto_path={d}', f'--python_out={d}', f'{d}/endorsement.proto'], check=True)
sys.path.insert(0, d)
import endorsement_pb2
e = endorsement_pb2.VMLaunchEndorsement()
e.ParseFromString(open(f'{d}/m.pb', 'rb').read())
g = endorsement_pb2.VMGoldenMeasurement()
g.ParseFromString(e.serialized_uefi_golden)
# Download firmware
subprocess.run(['gsutil', 'cp', f'gs://gce_tcb_integrity/ovmf_x64_csm/{g.digest.hex()}.fd', 'firmware.fd'], check=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment