@@ -14,6 +14,7 @@ use std::{borrow::Cow, time::SystemTime};
1414use anyhow:: { anyhow, bail, Context , Result } ;
1515use cc_eventlog:: { RuntimeEvent , TdxEvent } ;
1616use dcap_qvl:: {
17+ collateral:: CollateralClient ,
1718 quote:: { EnclaveReport , Quote , Report , TDReport10 , TDReport15 } ,
1819 verify:: VerifiedReport as TdxVerifiedReport ,
1920} ;
@@ -44,6 +45,13 @@ const DSTACK_AMD_SEV_SNP: &str = "dstack-amd-sev-snp";
4445const DSTACK_GCP_TDX : & str = "dstack-gcp-tdx" ;
4546const DSTACK_NITRO_ENCLAVE : & str = "dstack-nitro-enclave" ;
4647
48+ fn dcap_collateral_client ( pccs_url : Option < & str > ) -> Result < CollateralClient > {
49+ match pccs_url. map ( str:: trim) . filter ( |url| !url. is_empty ( ) ) {
50+ Some ( pccs_url) => CollateralClient :: with_default_http ( pccs_url) ,
51+ None => CollateralClient :: from_env ( ) ,
52+ }
53+ }
54+
4755/// Path to sys-config.json in the host-shared dir.
4856///
4957/// Honors `DSTACK_HOST_SHARED_DIR` (exported by `dstack-util setup` because the
@@ -1419,17 +1427,10 @@ async fn verify_tdx_quote_with_events(
14191427 runtime_events : & [ RuntimeEvent ] ,
14201428 report_data : & [ u8 ; 64 ] ,
14211429) -> Result < TdxVerifiedReport > {
1422- let mut pccs_url = Cow :: Borrowed ( pccs_url. unwrap_or_default ( ) ) ;
1423- if pccs_url. is_empty ( ) {
1424- pccs_url = match std:: env:: var ( "PCCS_URL" ) {
1425- Ok ( url) => Cow :: Owned ( url) ,
1426- Err ( _) => Cow :: Borrowed ( "" ) ,
1427- } ;
1428- }
1429- let tdx_report =
1430- dcap_qvl:: collateral:: get_collateral_and_verify ( quote, Some ( pccs_url. as_ref ( ) ) )
1431- . await
1432- . context ( "Failed to get collateral" ) ?;
1430+ let tdx_report = dcap_collateral_client ( pccs_url) ?
1431+ . fetch_and_verify ( quote)
1432+ . await
1433+ . context ( "Failed to get collateral" ) ?;
14331434 validate_tcb ( & tdx_report) ?;
14341435
14351436 let td_report = tdx_report. report . as_td10 ( ) . context ( "no td report" ) ?;
@@ -1997,18 +1998,10 @@ impl Attestation {
19971998 }
19981999
19992000 async fn verify_tdx ( & self , pccs_url : Option < & str > , quote : & [ u8 ] ) -> Result < TdxVerifiedReport > {
2000- let mut pccs_url = Cow :: Borrowed ( pccs_url. unwrap_or_default ( ) ) ;
2001- if pccs_url. is_empty ( ) {
2002- // try to read from PCCS_URL env var
2003- pccs_url = match std:: env:: var ( "PCCS_URL" ) {
2004- Ok ( url) => Cow :: Owned ( url) ,
2005- Err ( _) => Cow :: Borrowed ( "" ) ,
2006- } ;
2007- }
2008- let tdx_report =
2009- dcap_qvl:: collateral:: get_collateral_and_verify ( quote, Some ( pccs_url. as_ref ( ) ) )
2010- . await
2011- . context ( "Failed to get collateral" ) ?;
2001+ let tdx_report = dcap_collateral_client ( pccs_url) ?
2002+ . fetch_and_verify ( quote)
2003+ . await
2004+ . context ( "Failed to get collateral" ) ?;
20122005 validate_tcb ( & tdx_report) ?;
20132006
20142007 let td_report = tdx_report. report . as_td10 ( ) . context ( "no td report" ) ?;
0 commit comments