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

Length refactor #130

Merged
merged 1 commit into from
Nov 30, 2023
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
52 changes: 18 additions & 34 deletions verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,36 @@ impl AttestHiffy {
}
}

/// Get length of the certificate chain from the Attest task. This cert
/// chain may be self signed or will terminate at the intermediate before
/// the root.
fn cert_chain_len(&self) -> Result<u32> {
/// This convenience function encapsulates a pattern common to
/// the hiffy command line for the `Attest` operations that get the
/// lengths of the data returned in leases.
fn get_len_cmd(&self, op: &str, args: Option<String>) -> Result<u32> {
// rely on environment for target & archive?
// check that they are set before continuing
let mut cmd = Command::new("humility");

cmd.arg("hiffy");
cmd.arg("--call");
cmd.arg(format!("{}.cert_chain_len", self.interface));
cmd.arg(format!("{}.{}", self.interface, op));
if let Some(a) = args {
cmd.arg(format!("--arguments={}", a));
}
debug!("executing command: {:?}", cmd);

let output = cmd.output()?;
Self::u32_from_cmd_output(output)
}

/// Get length of the certificate chain from the Attest task. This cert
/// chain may be self signed or will terminate at the intermediate before
/// the root.
fn cert_chain_len(&self) -> Result<u32> {
self.get_len_cmd("cert_chain_len", None)
}

/// Get length of the certificate at the provided index in bytes.
fn cert_len(&self, index: u32) -> Result<u32> {
let mut cmd = Command::new("humility");

cmd.arg("hiffy");
cmd.arg("--call");
cmd.arg(format!("{}.cert_len", self.interface));
cmd.arg("--arguments");
cmd.arg(format!("index={}", index));
debug!("executing command: {:?}", cmd);

let output = cmd.output()?;
Self::u32_from_cmd_output(output)
self.get_len_cmd("cert_len", Some(format!("index={}", index)))
}

/// Get a chunk of the measurement log defined by `offset` and `length`.
Expand Down Expand Up @@ -227,28 +227,12 @@ impl AttestHiffy {

/// Get length of the measurement log in bytes.
fn log_len(&self) -> Result<u32> {
let mut cmd = Command::new("humility");

cmd.arg("hiffy");
cmd.arg("--call");
cmd.arg(format!("{}.log_len", self.interface));
debug!("executing command: {:?}", cmd);

let output = cmd.output()?;
Self::u32_from_cmd_output(output)
self.get_len_cmd("log_len", None)
}

/// Get length of the measurement log in bytes.
fn quote_len(&self) -> Result<u32> {
let mut cmd = Command::new("humility");

cmd.arg("hiffy");
cmd.arg("--call");
cmd.arg(format!("{}.quote_len", self.interface));
debug!("executing command: {:?}", cmd);

let output = cmd.output()?;
Self::u32_from_cmd_output(output)
self.get_len_cmd("quote_len", None)
}
}

Expand Down
Loading