mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Add a CLI compatible Rust implementation of pvattest-C. - All (non-experimental) options are supported and work exactly as in the C implementation. For some options/parameters new variants are available. - `perform` now also accepts positional arguments, while keep accepting -i and -o that was mandatory in the C implementation. - `version` may also be a command instead of an option now. - -V is deprecated - -v increases verbosity instead of showing the version - all experimental options are dropped Acked-by: Qi Feng Huo <huoqif@cn.ibm.com> Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
// SPDX-License-Identifier: MIT
|
|
//
|
|
// Copyright IBM Corp. 2024
|
|
|
|
use crate::{
|
|
cli::PerformAttOptComb,
|
|
exchange::{ExchangeFormatRequest, ExchangeFormatResponse, ExchangeFormatVersion},
|
|
};
|
|
use anyhow::Result;
|
|
use pv::{
|
|
misc::{create_file, open_file, read_file},
|
|
uv::{AttestationCmd, UvDevice},
|
|
};
|
|
use std::process::ExitCode;
|
|
|
|
pub fn perform<'a, P>(opt: P) -> Result<ExitCode>
|
|
where
|
|
P: Into<PerformAttOptComb<'a>>,
|
|
{
|
|
let opt = opt.into();
|
|
let mut input = open_file(opt.input)?;
|
|
let mut output = create_file(opt.output)?;
|
|
let uvdevice = UvDevice::open()?;
|
|
|
|
let ex_in = ExchangeFormatRequest::read(&mut input)?;
|
|
let user_data = opt
|
|
.user_data
|
|
.map(|u| read_file(u, "user-data"))
|
|
.transpose()?;
|
|
|
|
let mut cmd = AttestationCmd::new_request(
|
|
ex_in.arcb.clone().into(),
|
|
user_data.clone(),
|
|
ex_in.exp_measurement,
|
|
ex_in.exp_additional,
|
|
)?;
|
|
|
|
uvdevice.send_cmd(&mut cmd)?;
|
|
|
|
let measurement = cmd.measurement();
|
|
let additional = cmd.additional_owned();
|
|
let cuid = cmd.cuid();
|
|
|
|
let ex_out = ExchangeFormatResponse::new(
|
|
ex_in.arcb,
|
|
measurement.to_owned(),
|
|
additional,
|
|
user_data,
|
|
cuid.to_owned(),
|
|
)?;
|
|
ex_out.write(&mut output, ExchangeFormatVersion::One)?;
|
|
|
|
Ok(ExitCode::SUCCESS)
|
|
}
|