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: Port attest command to lease-based hiffy interface. #161

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
42 changes: 30 additions & 12 deletions verifier-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{anyhow, Context, Result};
use attest_data::{Attestation, Nonce};
use clap::{Parser, Subcommand, ValueEnum};
use env_logger::Builder;
use hubpack::SerializedSize;
use log::{debug, error, info, warn, LevelFilter};
use pem_rfc7468::{LineEnding, PemLabel};
use sha3::{Digest, Sha3_256};
Expand Down Expand Up @@ -251,16 +252,22 @@ impl AttestHiffy {
op: &str,
length: usize,
output: &Path,
args: String,
args: Option<&str>,
input: Option<&str>,
) -> Result<()> {
let mut cmd = Command::new("humility");

cmd.arg("hiffy");
cmd.arg(format!("--call={}.{}", self.interface, op));
cmd.arg(format!("--num={}", length));
cmd.arg(format!("--output={}", output.to_string_lossy()));
cmd.arg("--arguments");
cmd.arg(args);
if let Some(args) = args {
cmd.arg("--arguments");
cmd.arg(args);
}
if let Some(i) = input {
cmd.arg(format!("--input={}", i));
}
debug!("executing command: {:?}", cmd);

let output = cmd.output()?;
Expand All @@ -278,15 +285,22 @@ impl AttestHiffy {
}

fn attest(&self, nonce: Nonce, out: &mut [u8]) -> Result<()> {
let mut tmp = tempfile::NamedTempFile::new()?;
let mut attestation_tmp = tempfile::NamedTempFile::new()?;
let mut nonce_tmp = tempfile::NamedTempFile::new()?;

let mut buf = [0u8; Nonce::MAX_SIZE];
hubpack::serialize(&mut buf, &nonce)
.map_err(|_| anyhow!("failed to serialize Nonce"))?;
nonce_tmp.write_all(&buf)?;

self.get_chunk(
"attest",
out.len(),
tmp.path(),
format!("nonce={}", nonce),
attestation_tmp.path(),
None,
Some(&nonce_tmp.path().to_string_lossy()),
)?;
tmp.read_exact(&mut out[..])?;
Ok(())
Ok(attestation_tmp.read_exact(&mut out[..])?)
}

/// Get length of the measurement log in bytes.
Expand Down Expand Up @@ -315,7 +329,8 @@ impl AttestHiffy {
"cert",
Self::CHUNK_SIZE,
tmp.path(),
format!("index={},offset={}", index, offset),
Some(&format!("index={},offset={}", index, offset)),
None,
)?;
tmp.read_exact(&mut out[offset..offset + Self::CHUNK_SIZE])?;
}
Expand All @@ -328,7 +343,8 @@ impl AttestHiffy {
"cert",
remain,
tmp.path(),
format!("index={},offset={}", index, offset),
Some(&format!("index={},offset={}", index, offset)),
None,
)?;
tmp.read_exact(&mut out[offset..])?;
}
Expand All @@ -347,7 +363,8 @@ impl AttestHiffy {
"log",
Self::CHUNK_SIZE,
tmp.path(),
format!("offset={}", offset),
Some(&format!("offset={}", offset)),
None,
)?;
tmp.read_exact(&mut out[offset..offset + Self::CHUNK_SIZE])?;
}
Expand All @@ -360,7 +377,8 @@ impl AttestHiffy {
"log",
remain,
tmp.path(),
format!("offset={}", offset),
Some(&format!("offset={}", offset)),
None,
)?;
tmp.read_exact(&mut out[offset..])?;
}
Expand Down
Loading