From b9365d87d5f8f7087f190d485a75276d5d8e3022 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Wed, 11 Dec 2024 07:16:10 +0000 Subject: [PATCH] cli: Support for custom PCCS_URL --- cli/src/main.rs | 15 +++++++++++---- src/quote.rs | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index c737689..e7f543a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use anyhow::{Context as _, Result}; use clap::{Args, Parser, Subcommand}; -use dcap_qvl::collateral::get_collateral_from_pcs; +use dcap_qvl::collateral::{get_collateral, get_collateral_from_pcs}; use dcap_qvl::quote::Quote; use dcap_qvl::verify::verify; @@ -64,14 +64,21 @@ fn command_decode_quote(args: DecodeQuoteArgs) -> Result<()> { async fn command_verify_quote(args: VerifyQuoteArgs) -> Result<()> { let quote = std::fs::read(args.quote_file).context("Failed to read quote file")?; let quote = hex_decode("e, args.hex)?; - println!("Getting collateral..."); - let collateral = get_collateral_from_pcs("e, std::time::Duration::from_secs(60)).await?; + let pccs_url = std::env::var("PCCS_URL").unwrap_or_default(); + let collateral = if pccs_url.is_empty() { + eprintln!("Getting collateral from PCS..."); + get_collateral_from_pcs("e, std::time::Duration::from_secs(60)).await? + } else { + eprintln!("Getting collateral from {pccs_url}"); + get_collateral(&pccs_url, "e, std::time::Duration::from_secs(60)).await? + }; let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH)? .as_secs(); - verify("e, &collateral, now) + let report = verify("e, &collateral, now) .ok() .context("Failed to verify quote")?; + println!("{}", serde_json::to_string(&report).unwrap()); eprintln!("Quote verified"); Ok(()) } diff --git a/src/quote.rs b/src/quote.rs index 031b0f1..48d348e 100644 --- a/src/quote.rs +++ b/src/quote.rs @@ -232,7 +232,7 @@ fn decode_auth_data(ver: u16, input: &mut &[u8]) -> Result Err(scale::Error::from("unsupported quote version")), + _ => Err(scale::Error::from("unsupported auth data version")), } }