mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
pvimg: Improve error messages
Improve error messages for errors when reading the SE header protection key or when the decryption/verification of the SE header has failed. Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Marc Hartmayer <marc@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
87966251c4
commit
95fb1e2b03
@@ -4,14 +4,14 @@
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use log::{info, warn};
|
||||
use pv::{
|
||||
misc::{open_file, read_file},
|
||||
request::SymKey,
|
||||
};
|
||||
use pvimg::{
|
||||
error::OwnExitCode,
|
||||
error::{Error, OwnExitCode},
|
||||
uvdata::{KeyExchangeTrait, SeH, SeHdr, UvDataTrait},
|
||||
};
|
||||
|
||||
@@ -28,9 +28,16 @@ pub fn info(opt: &InfoArgs) -> Result<OwnExitCode> {
|
||||
SeHdr::seek_sehdr(&mut img, None)?;
|
||||
let hdr = SeHdr::try_from_io(&mut img)?;
|
||||
let se_hdr = if let Some(key_path) = &opt.hdr_key {
|
||||
let key =
|
||||
SymKey::try_from_data(hdr.key_type(), read_file(key_path, "Reading key")?.into())?;
|
||||
let decrypted_hdr = hdr.decrypt(&key)?;
|
||||
let key = SymKey::try_from_data(
|
||||
hdr.key_type(),
|
||||
read_file(key_path, "Reading header protection key")?.into(),
|
||||
)
|
||||
.map_err(|err| Error::InvalidSeHdrProtectionKey {
|
||||
source: Box::new(Error::Pv(err)),
|
||||
})?;
|
||||
let decrypted_hdr = hdr
|
||||
.decrypt(&key)
|
||||
.context("Failed to authenticate and decrypt the Secure Execution header")?;
|
||||
SeH::DecryptedSeHdr {
|
||||
se_hdr: decrypted_hdr,
|
||||
verified: true,
|
||||
|
||||
@@ -33,6 +33,9 @@ pub enum Error {
|
||||
#[error("Secure Execution header size {given} is larger than the maximum of {maximum} bytes")]
|
||||
InvalidSeHdrTooLarge { given: usize, maximum: usize },
|
||||
|
||||
#[error("Invalid Secure Execution header protection key")]
|
||||
InvalidSeHdrProtectionKey { source: Box<Error> },
|
||||
|
||||
#[error("Invalid component metadata.")]
|
||||
InvalidComponentMetadata,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user