Skip to content

Commit a11ddbf

Browse files
committed
fix: unify RA-TLS cert attestation format and fix onboard os_image_hash
1. ra-tls: use unified PHALA_RATLS_ATTESTATION OID for all cert types (including TDX) instead of the legacy separate TDX_QUOTE + EVENT_LOG OIDs. The new format preserves vm_config (including os_image_hash). The reader already prefers the new OID and falls back to old OIDs for backward compat with existing certs. 2. kms: when the remote source KMS uses the old cert format (missing vm_config), the receiver-side ensure_kms_allowed fills os_image_hash from the local KMS value. This is safe because mrAggregated already validates OS image integrity through the RTMR measurement chain. TODO: remove once all source KMS instances use the new cert format.
1 parent de92515 commit a11ddbf

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

kms/src/main_service/upgrade_authority.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,19 @@ pub(crate) async fn ensure_kms_allowed(
224224
cfg: &KmsConfig,
225225
attestation: &VerifiedAttestation,
226226
) -> Result<()> {
227-
let boot_info = build_boot_info(attestation, false, "")
227+
let mut boot_info = build_boot_info(attestation, false, "")
228228
.context("failed to build KMS boot info from attestation")?;
229+
// Workaround: old source KMS instances use the legacy cert format (separate TDX_QUOTE +
230+
// EVENT_LOG OIDs) which lacks vm_config, resulting in an empty os_image_hash.
231+
// Fill it from the local KMS's own value. This is safe because mrAggregated already
232+
// validates OS image integrity transitively through the RTMR measurement chain.
233+
// TODO: remove once all source KMS instances use the unified PHALA_RATLS_ATTESTATION format.
234+
if boot_info.os_image_hash.is_empty() {
235+
let local_info = local_kms_boot_info(cfg.pccs_url.as_deref())
236+
.await
237+
.context("failed to get local KMS boot info for os_image_hash fallback")?;
238+
boot_info.os_image_hash = local_info.os_image_hash;
239+
}
229240
let response = cfg
230241
.auth_api
231242
.is_app_allowed(&boot_info, true)

ra-tls/src/cert.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ use x509_parser::x509::SubjectPublicKeyInfo;
2525

2626
use crate::oids::{
2727
PHALA_RATLS_APP_ID, PHALA_RATLS_APP_INFO, PHALA_RATLS_ATTESTATION, PHALA_RATLS_CERT_USAGE,
28-
PHALA_RATLS_EVENT_LOG, PHALA_RATLS_TDX_QUOTE,
2928
};
3029
use crate::traits::CertExt;
3130
#[cfg(feature = "quote")]
3231
use dstack_attest::attestation::QuoteContentType;
33-
use dstack_attest::attestation::{AppInfo, Attestation, AttestationQuote, VersionedAttestation};
32+
use dstack_attest::attestation::{AppInfo, Attestation, VersionedAttestation};
3433

3534
/// A CA certificate and private key.
3635
pub struct CaCert {
@@ -389,21 +388,8 @@ impl<Key> CertRequest<'_, Key> {
389388
add_ext(&mut params, PHALA_RATLS_CERT_USAGE, usage);
390389
}
391390
if let Some(ver_att) = self.attestation {
392-
let VersionedAttestation::V0 { attestation } = &ver_att;
393-
match &attestation.quote {
394-
AttestationQuote::DstackTdx(tdx_quote) => {
395-
// For backward compatibility, we serialize the quote to the classic oids.
396-
let event_log = serde_json::to_vec(&tdx_quote.event_log)
397-
.context("Failed to serialize event log")?;
398-
add_ext(&mut params, PHALA_RATLS_TDX_QUOTE, &tdx_quote.quote);
399-
add_ext(&mut params, PHALA_RATLS_EVENT_LOG, &event_log);
400-
}
401-
_ => {
402-
// The event logs are too large on GCP TDX to put in the certificate, so we strip them
403-
let attestation_bytes = ver_att.clone().into_stripped().to_scale();
404-
add_ext(&mut params, PHALA_RATLS_ATTESTATION, &attestation_bytes);
405-
}
406-
}
391+
let attestation_bytes = ver_att.clone().into_stripped().to_scale();
392+
add_ext(&mut params, PHALA_RATLS_ATTESTATION, &attestation_bytes);
407393
}
408394
if let Some(ca_level) = self.ca_level {
409395
params.is_ca = IsCa::Ca(BasicConstraints::Constrained(ca_level));
@@ -576,7 +562,7 @@ pub fn generate_ra_cert_with_app_id(
576562
#[cfg(test)]
577563
mod tests {
578564
use super::*;
579-
use dstack_attest::attestation::TdxQuote;
565+
use dstack_attest::attestation::{AttestationQuote, TdxQuote};
580566
use rcgen::PKCS_ECDSA_P256_SHA256;
581567
use scale::Encode;
582568

0 commit comments

Comments
 (0)