mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Add support for '--image-key'. This new option can be used to select the
components encryption key (e.g. kernel, initrd, and kernel command
line). Previously, this was only available as an experimental
option ('--x-comp-key').
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
83 lines
2.2 KiB
Rust
83 lines
2.2 KiB
Rust
// SPDX-License-Identifier: MIT
|
|
//
|
|
// Copyright IBM Corp. 2024
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use anyhow::Result;
|
|
use log::info;
|
|
use pv::{misc::read_file, request::Confidential};
|
|
|
|
use crate::cli::UserKeys;
|
|
|
|
#[macro_export]
|
|
/// Makes it easier to
|
|
macro_rules! log_println {
|
|
($($arg:tt)+) => { warn!($($arg)+) };
|
|
}
|
|
|
|
pub struct UserProvidedKeys {
|
|
pub(crate) cck: Option<(PathBuf, Confidential<Vec<u8>>)>,
|
|
pub(crate) components_key: Option<(PathBuf, Confidential<Vec<u8>>)>,
|
|
pub(crate) aead_key: Option<(PathBuf, Confidential<Vec<u8>>)>,
|
|
}
|
|
|
|
/// Reads all user provided keys.
|
|
pub fn read_user_provided_keys(keys: &UserKeys) -> Result<UserProvidedKeys> {
|
|
let components_key = {
|
|
match &keys.image_key {
|
|
Some(key_path) => {
|
|
info!(
|
|
"Use file '{}' as the image components protection key",
|
|
key_path.display()
|
|
);
|
|
Some((
|
|
key_path.to_owned(),
|
|
Confidential::new(read_file(key_path, "image components key")?),
|
|
))
|
|
}
|
|
None => None,
|
|
}
|
|
};
|
|
let aead_key = {
|
|
match &keys.hdr_key {
|
|
Some(key_path) => {
|
|
info!(
|
|
"Use file '{}' as the Secure Execution header protection",
|
|
key_path.display()
|
|
);
|
|
Some((
|
|
key_path.to_owned(),
|
|
Confidential::new(read_file(
|
|
key_path,
|
|
"Secure Execution header protection key",
|
|
)?),
|
|
))
|
|
}
|
|
None => None,
|
|
}
|
|
};
|
|
|
|
let cck = {
|
|
match &keys.cck {
|
|
Some(key_path) => {
|
|
info!(
|
|
"Use file '{}' as the customer communication key (CCK)",
|
|
key_path.display()
|
|
);
|
|
Some((
|
|
key_path.to_owned(),
|
|
(Confidential::new(read_file(key_path, "customer communication key (CCK)")?)),
|
|
))
|
|
}
|
|
None => None,
|
|
}
|
|
};
|
|
|
|
Ok(UserProvidedKeys {
|
|
cck,
|
|
components_key,
|
|
aead_key,
|
|
})
|
|
}
|