Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verifier-cli: Persist artifacts as json instead of raw binary. #221

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions verifier-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ sha3.workspace = true
tempfile.workspace = true
dice-verifier.path = "../verifier"
x509-cert = { workspace = true, default-features = true }
serde_json.workspace = true
39 changes: 27 additions & 12 deletions verifier-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use anyhow::{anyhow, Context, Result};
use attest_data::{Attestation, Nonce};
use attest_data::{Attestation, Log, Nonce};
use clap::{Parser, Subcommand, ValueEnum};
use dice_verifier::PkiPathSignatureVerifier;
use env_logger::Builder;
Expand Down Expand Up @@ -554,23 +554,32 @@ fn verify<P: AsRef<Path>>(
let nonce = Nonce::from_platform_rng()?;

// write nonce to temp dir
let nonce_path = work_dir.as_ref().join("nonce.bin");
let nonce_path = work_dir.as_ref().join("nonce.json");
info!("writing nonce to: {}", nonce_path.display());
fs::write(&nonce_path, nonce)?;
let nonce_str = serde_json::to_string(&nonce)?;
fs::write(&nonce_path, nonce_str)?;

// get attestation
info!("getting attestation");
let mut attestation = vec![0u8; attest.attest_len()? as usize];
attest.attest(nonce, &mut attestation)?;
let attestation_path = work_dir.as_ref().join("attest.bin");
// deserialize hubpack encoded attestation
let (attestation, _): (Attestation, _) = hubpack::deserialize(&attestation)
.map_err(|e| anyhow!("Failed to deserialize Attestation: {}", e))?;
// serialize attestation to json & write to file
let attestation = serde_json::to_string(&attestation)?;
let attestation_path = work_dir.as_ref().join("attest.json");
info!("writing attestation to: {}", attestation_path.display());
fs::write(&attestation_path, &attestation)?;

// get log
info!("getting measurement log");
let mut log = vec![0u8; attest.log_len()? as usize];
attest.log(&mut log)?;
let log_path = work_dir.as_ref().join("log.bin");
let (log, _): (Log, _) = hubpack::deserialize(&log)
.map_err(|e| anyhow!("Failed to deserialize Log: {}", e))?;
let log = serde_json::to_string(&log)?;
let log_path = work_dir.as_ref().join("log.json");
info!("writing measurement log to: {}", log_path.display());
fs::write(&log_path, &log)?;

Expand Down Expand Up @@ -614,13 +623,19 @@ fn verify_attestation(
nonce: &PathBuf,
) -> Result<()> {
info!("verifying attestation");
let attestation = fs::read(attestation)?;
let (attestation, _): (Attestation, _) = hubpack::deserialize(&attestation)
.map_err(|e| anyhow!("Failed to deserialize Attestation: {}", e))?;

let log = fs::read(log)?;

let nonce: Nonce = fs::read(nonce)?.try_into()?;
let attestation = fs::read_to_string(attestation)?;
let attestation: Attestation = serde_json::from_str(&attestation)?;

// deserialize Log from json & serialize to hubpacked bytes
let log = fs::read_to_string(log)?;
let log: Log = serde_json::from_str(&log)?;
let mut buf = vec![0u8; Log::MAX_SIZE];
hubpack::serialize(&mut buf, &log)
.map_err(|_| anyhow!("failed to serialize Log"))?;
let log = buf;

let nonce = fs::read_to_string(nonce)?;
let nonce: Nonce = serde_json::from_str(&nonce)?;

let alias = fs::read(alias_cert)?;
let alias = match pem_rfc7468::decode_vec(&alias) {
Expand Down
Loading