Skip to content

Commit

Permalink
cli: Support for custom PCCS_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 11, 2024
1 parent eadf882 commit b9365d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(&quote, args.hex)?;
println!("Getting collateral...");
let collateral = get_collateral_from_pcs(&quote, 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(&quote, std::time::Duration::from_secs(60)).await?
} else {
eprintln!("Getting collateral from {pccs_url}");
get_collateral(&pccs_url, &quote, std::time::Duration::from_secs(60)).await?
};
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)?
.as_secs();
verify(&quote, &collateral, now)
let report = verify(&quote, &collateral, now)
.ok()
.context("Failed to verify quote")?;
println!("{}", serde_json::to_string(&report).unwrap());
eprintln!("Quote verified");
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn decode_auth_data(ver: u16, input: &mut &[u8]) -> Result<AuthData, scale::Erro
let auth_data = AuthDataV4::decode(input)?;
Ok(AuthData::V4(auth_data))
}
_ => Err(scale::Error::from("unsupported quote version")),
_ => Err(scale::Error::from("unsupported auth data version")),
}
}

Expand Down

0 comments on commit b9365d8

Please sign in to comment.