Skip to content

Commit f9f9cb7

Browse files
committed
validate: change parameters, now accept a full cert chain
In keeping with the tool's approach, which handles the entire SEV certificate chain, make the same adjustment for the `validate` command: allow the file path to the entire certificate chain instead of just a single file with the PEK certificate, as extracting the PEK alone is not possible with `sevctl`. Signed-off-by: Roman Penyaev <[email protected]>
1 parent 516cf41 commit f9f9cb7

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ enum SevctlCmd {
130130

131131
/// Validate subcommands
132132
Validate {
133-
/// PEK directory path
134-
#[arg(short, long = "pek", required = true)]
135-
pek_path: PathBuf,
133+
/// Path to the SEV cert chain, can be obtained by the `export` subcommand
134+
#[arg(value_name = "sev-cert-chain", required = true)]
135+
chain_path: PathBuf,
136136

137-
/// Attestation Report directory path
138-
#[arg(short, long = "attestation-report", required = true)]
137+
/// Path to the attestation report binary file
138+
#[arg(value_name = "attestation-report", required = true)]
139139
ar_path: PathBuf,
140140
},
141141

@@ -266,7 +266,10 @@ fn main() -> Result<()> {
266266
SevctlCmd::Session { name, pdh, policy } => session::cmd(name, pdh, policy),
267267
SevctlCmd::Show { cmd } => show::cmd(cmd),
268268
SevctlCmd::Verify { sev, oca, ca } => verify::cmd(sevctl.quiet, sev, oca, ca),
269-
SevctlCmd::Validate { pek_path, ar_path } => validate::cmd(pek_path, ar_path),
269+
SevctlCmd::Validate {
270+
chain_path,
271+
ar_path,
272+
} => validate::cmd(chain_path, ar_path),
270273
SevctlCmd::Vmsa(option) => match option {
271274
VmsaCmd::Build(args) => vmsa::build::cmd(args),
272275
VmsaCmd::Show(args) => vmsa::show::cmd(args),

src/validate.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
use sev::certs::sev::{sev::Certificate, Verifiable};
3+
use sev::certs::sev::{sev::Chain, Verifiable};
44
use sev::firmware::host::LegacyAttestationReport;
55

6+
use anyhow::{Context, Result};
67
use std::{fs, path::PathBuf};
78

8-
static PEK_NAME: &str = "pek.cert";
9-
static AR_NAME: &str = "attestation_report.bin";
9+
use codicon::*;
1010

1111
/// Validates the provided Platform Endorsement Key signed the specified Attestation Report.
12-
/// This assumes the PEK name to be `pek.cert` and the report name to be `attestation_report.bin`.
13-
pub fn cmd(mut pek: PathBuf, mut report: PathBuf) -> Result<(), anyhow::Error> {
14-
if pek.exists() && pek.is_dir() {
15-
pek = pek.join(PEK_NAME);
16-
}
17-
18-
if report.exists() && report.is_dir() {
19-
report = report.join(AR_NAME);
20-
}
21-
12+
pub fn cmd(chain_path: PathBuf, report: PathBuf) -> Result<(), anyhow::Error> {
2213
// Verify the binary being provided is of the correct size.
2314
if fs::metadata(report.clone())?.len() as usize
2415
!= std::mem::size_of::<LegacyAttestationReport>()
@@ -31,11 +22,10 @@ pub fn cmd(mut pek: PathBuf, mut report: PathBuf) -> Result<(), anyhow::Error> {
3122

3223
buf.clear();
3324

34-
buf = fs::read(pek)?;
35-
let pek_cert: Certificate = bincode::deserialize(&buf)?;
36-
37-
drop(buf);
25+
let mut chainf =
26+
fs::File::open(chain_path).context("unable to open SEV certificate chain file")?;
27+
let chain = Chain::decode(&mut chainf, ()).context("unable to decode chain")?;
3828

3929
// Verify using the implementation
40-
Ok((&pek_cert, &legacy_report).verify()?)
30+
Ok((&chain.pek, &legacy_report).verify()?)
4131
}

0 commit comments

Comments
 (0)