mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Run rustfmt with some experimental options
+ Sort and group the imports + Normalize and format comments (100 characters width) Command used: $ cargo +nightly fmt -- Acked-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
3d5f75d6c3
commit
f8fb9ce32a
@@ -7,11 +7,11 @@ mod msa;
|
||||
mod query;
|
||||
mod stfle;
|
||||
|
||||
use anyhow::bail;
|
||||
use anyhow::Result as anyhowRes;
|
||||
use clap::Parser;
|
||||
use std::io::ErrorKind;
|
||||
use std::result::Result::Ok;
|
||||
|
||||
use anyhow::{bail, Result as anyhowRes};
|
||||
use clap::Parser;
|
||||
use utils::print_version;
|
||||
|
||||
use crate::cli::{Cli, Format};
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::cli::Cli;
|
||||
use core::fmt::{Display, Formatter, Result};
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use utils::HexSlice;
|
||||
|
||||
use crate::cli::Cli;
|
||||
|
||||
/// Number of total function codes (0 to 127)
|
||||
pub const NUMBER_FUNC_CODES: usize = 128;
|
||||
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::io::Read;
|
||||
use std::io::{Error, Read};
|
||||
use std::ops::Index;
|
||||
use std::result::Result;
|
||||
|
||||
use zerocopy::FromBytes;
|
||||
|
||||
use crate::msa::InstructionKind;
|
||||
use crate::msa::QueryAuthInfo;
|
||||
use crate::msa::{InstructionKind, QueryAuthInfo};
|
||||
|
||||
/// Path to sysfs in which the query and qai informations are fetched from
|
||||
const SYSFS_PATH: &str = "/sys/devices/system/cpu/cpacf/";
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use pv::request::EcPubKeyCoord;
|
||||
use pv_core::misc::encode_hex;
|
||||
use s390_pv as pv;
|
||||
|
||||
use std::env::args;
|
||||
|
||||
use pv::misc::{read_certs, read_file};
|
||||
use pv::request::EcPubKeyCoord;
|
||||
use pv::{Error, Result};
|
||||
use pv_core::misc::encode_hex;
|
||||
use s390_pv as pv;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let hkd = args().nth(1).expect("Expect one Host-key document");
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023, 2024
|
||||
|
||||
use std::{
|
||||
io::{Read, Seek, SeekFrom::Current},
|
||||
mem::size_of,
|
||||
};
|
||||
use std::io::SeekFrom::Current;
|
||||
use std::io::{Read, Seek};
|
||||
use std::mem::size_of;
|
||||
|
||||
use log::{debug, warn};
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64};
|
||||
|
||||
@@ -2,25 +2,28 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023, 2024
|
||||
|
||||
use std::{convert::TryInto, fmt::Display, ops::Range};
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Display;
|
||||
use std::ops::Range;
|
||||
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use openssl::{
|
||||
derive::Deriver,
|
||||
ec::{EcGroup, EcKey},
|
||||
hash::{DigestBytes, MessageDigest},
|
||||
md::MdRef,
|
||||
nid::Nid,
|
||||
pkey::{HasPublic, Id, PKey, PKeyRef, Private, Public},
|
||||
pkey_ctx::{HkdfMode, PkeyCtx},
|
||||
rand::rand_bytes,
|
||||
rsa::Padding,
|
||||
sign::{Signer, Verifier},
|
||||
symm::{decrypt_aead as openssl_decrypt_aead, encrypt_aead as openssl_encrypt_aead, Cipher},
|
||||
use openssl::derive::Deriver;
|
||||
use openssl::ec::{EcGroup, EcKey};
|
||||
use openssl::hash::{DigestBytes, MessageDigest};
|
||||
use openssl::md::MdRef;
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::{HasPublic, Id, PKey, PKeyRef, Private, Public};
|
||||
use openssl::pkey_ctx::{HkdfMode, PkeyCtx};
|
||||
use openssl::rand::rand_bytes;
|
||||
use openssl::rsa::Padding;
|
||||
use openssl::sign::{Signer, Verifier};
|
||||
use openssl::symm::{
|
||||
decrypt_aead as openssl_decrypt_aead, encrypt_aead as openssl_encrypt_aead, Cipher,
|
||||
};
|
||||
use pv_core::request::Confidential;
|
||||
|
||||
use crate::{error::Result, Error};
|
||||
use crate::error::Result;
|
||||
use crate::Error;
|
||||
|
||||
/// An AES256-GCM key that will purge itself out of the memory when going out of scope
|
||||
pub type Aes256GcmKey = Confidential<[u8; SymKeyType::AES_256_GCM_KEY_LEN]>;
|
||||
@@ -540,7 +543,8 @@ pub(crate) fn verify_signature<T: HasPublic>(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{get_test_asset, test_utils::*, PvCoreError};
|
||||
use crate::test_utils::*;
|
||||
use crate::{get_test_asset, PvCoreError};
|
||||
|
||||
#[test]
|
||||
fn sign_ec() {
|
||||
|
||||
@@ -63,13 +63,11 @@ pub mod uv {
|
||||
pub mod attest {
|
||||
pub use pv_core::attest::*;
|
||||
|
||||
pub use crate::uvattest::{
|
||||
additional::AdditionalData,
|
||||
arcb::{
|
||||
AttestationAuthenticated, AttestationFlags, AttestationRequest, AttestationVersion,
|
||||
},
|
||||
attest::{AttestationItems, AttestationMeasurement},
|
||||
pub use crate::uvattest::additional::AdditionalData;
|
||||
pub use crate::uvattest::arcb::{
|
||||
AttestationAuthenticated, AttestationFlags, AttestationRequest, AttestationVersion,
|
||||
};
|
||||
pub use crate::uvattest::attest::{AttestationItems, AttestationMeasurement};
|
||||
}
|
||||
|
||||
/// Definitions and functions to write objects in PEM format
|
||||
@@ -91,27 +89,22 @@ pub use crate::error::HkdVerifyErrorType;
|
||||
|
||||
/// Functionalities to build UV requests
|
||||
pub mod request {
|
||||
pub use crate::{
|
||||
brcb::{seek_se_hdr_start, BootHdrTags, SeImgMetaData},
|
||||
crypto::{
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, random_array,
|
||||
AeadDecryptionResult, AeadEncryptionResult, Aes256GcmKey, Aes256XtsKey, SymKey,
|
||||
SymKeyType, SHA_512_HASH_LEN,
|
||||
},
|
||||
req::{EcPubKeyCoord, Encrypt, Keyslot, ReqEncrCtx, Request},
|
||||
verify::{CertVerifier, HkdVerifier, NoVerifyHkd},
|
||||
pub use crate::brcb::{seek_se_hdr_start, BootHdrTags, SeImgMetaData};
|
||||
pub use crate::crypto::{
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, random_array,
|
||||
AeadDecryptionResult, AeadEncryptionResult, Aes256GcmKey, Aes256XtsKey, SymKey, SymKeyType,
|
||||
SHA_512_HASH_LEN,
|
||||
};
|
||||
pub use crate::req::{EcPubKeyCoord, Encrypt, Keyslot, ReqEncrCtx, Request};
|
||||
pub use crate::verify::{CertVerifier, HkdVerifier, NoVerifyHkd};
|
||||
|
||||
/// Reexports some useful OpenSSL symbols
|
||||
pub mod openssl {
|
||||
pub use openssl::{
|
||||
error::ErrorStack,
|
||||
hash::DigestBytes,
|
||||
nid::Nid,
|
||||
pkey,
|
||||
sha::{Sha256, Sha512},
|
||||
x509,
|
||||
};
|
||||
pub use openssl::error::ErrorStack;
|
||||
pub use openssl::hash::DigestBytes;
|
||||
pub use openssl::nid::Nid;
|
||||
pub use openssl::sha::{Sha256, Sha512};
|
||||
pub use openssl::{pkey, x509};
|
||||
// rust-OpenSSL does not define these NIDs
|
||||
#[allow(missing_docs)]
|
||||
pub const NID_ED25519: Nid = Nid::from_raw(openssl_sys::NID_ED25519);
|
||||
@@ -120,7 +113,6 @@ pub mod request {
|
||||
}
|
||||
|
||||
pub use pv_core::request::*;
|
||||
|
||||
pub use pv_core::PolicyReference;
|
||||
}
|
||||
|
||||
@@ -128,11 +120,9 @@ pub mod request {
|
||||
pub mod secret {
|
||||
pub use pv_core::secret::*;
|
||||
|
||||
pub use crate::uvsecret::{
|
||||
asrcb::{AddSecretFlags, AddSecretRequest, AddSecretVersion},
|
||||
ext_secret::ExtSecret,
|
||||
guest_secret::GuestSecret,
|
||||
retr_secret::{IbmProtectedKey, RetrievedSecret},
|
||||
user_data::verify_asrcb_and_get_user_data,
|
||||
};
|
||||
pub use crate::uvsecret::asrcb::{AddSecretFlags, AddSecretRequest, AddSecretVersion};
|
||||
pub use crate::uvsecret::ext_secret::ExtSecret;
|
||||
pub use crate::uvsecret::guest_secret::GuestSecret;
|
||||
pub use crate::uvsecret::retr_secret::{IbmProtectedKey, RetrievedSecret};
|
||||
pub use crate::uvsecret::user_data::verify_asrcb_and_get_user_data;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use std::ffi::c_int;
|
||||
use std::fmt;
|
||||
|
||||
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
|
||||
use openssl::x509::{X509CrlRef, X509Ref};
|
||||
use std::ffi::c_int;
|
||||
|
||||
mod ffi {
|
||||
extern "C" {
|
||||
@@ -99,9 +99,8 @@ impl AkidExtension for X509CrlRef {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::test_utils::load_gen_cert;
|
||||
|
||||
use super::*;
|
||||
use crate::test_utils::load_gen_cert;
|
||||
|
||||
#[test]
|
||||
fn akid() {
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use core::slice;
|
||||
use std::ffi::c_int;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl_sys::BIO_new_mem_buf;
|
||||
use std::ffi::c_int;
|
||||
use std::{marker::PhantomData, ptr};
|
||||
|
||||
pub struct BioMem(*mut openssl_sys::BIO);
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
pub use crate::openssl_extensions::stackable_crl::*;
|
||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||
use openssl::{
|
||||
error::ErrorStack,
|
||||
stack::{Stack, StackRef},
|
||||
x509::{
|
||||
store::{X509StoreBuilderRef, X509StoreRef},
|
||||
X509CrlRef, X509NameRef, X509Ref, X509StoreContextRef, X509,
|
||||
},
|
||||
};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::stack::{Stack, StackRef};
|
||||
use openssl::x509::store::{X509StoreBuilderRef, X509StoreRef};
|
||||
use openssl::x509::{X509CrlRef, X509NameRef, X509Ref, X509StoreContextRef, X509};
|
||||
|
||||
pub use crate::openssl_extensions::stackable_crl::*;
|
||||
|
||||
pub fn opt_to_ptr<T: ForeignTypeRef>(o: Option<&T>) -> *mut T::CType {
|
||||
match o {
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use crate::openssl_extensions::bio::BioMemSlice;
|
||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||
use openssl::{
|
||||
error::ErrorStack,
|
||||
stack::Stackable,
|
||||
x509::{X509Crl, X509CrlRef},
|
||||
};
|
||||
use std::ptr;
|
||||
|
||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::stack::Stackable;
|
||||
use openssl::x509::{X509Crl, X509CrlRef};
|
||||
|
||||
use crate::openssl_extensions::bio::BioMemSlice;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StackableX509Crl(*mut openssl_sys::X509_CRL);
|
||||
|
||||
|
||||
@@ -2,18 +2,19 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::Result;
|
||||
use crate::{openssl_extensions::BioMem, Error};
|
||||
use std::ffi::{c_char, CString};
|
||||
use std::fmt::Display;
|
||||
|
||||
use openssl::error::ErrorStack;
|
||||
use pv_core::request::Confidential;
|
||||
use std::{
|
||||
ffi::{c_char, CString},
|
||||
fmt::Display,
|
||||
};
|
||||
|
||||
use crate::openssl_extensions::BioMem;
|
||||
use crate::{Error, Result};
|
||||
|
||||
mod ffi {
|
||||
use openssl_sys::BIO;
|
||||
use std::ffi::{c_char, c_int, c_long, c_uchar};
|
||||
|
||||
use openssl_sys::BIO;
|
||||
extern "C" {
|
||||
pub fn PEM_write_bio(
|
||||
bio: *mut BIO,
|
||||
@@ -141,8 +142,8 @@ impl Pem {
|
||||
|
||||
let inner_pem = InnerPem::new(name, header, data.as_ref())?;
|
||||
|
||||
// Create the PEM format eagerly so that to_string/display cannot fail because of ASCII or OpenSSL Errors
|
||||
// Both error should be very unlikely
|
||||
// Create the PEM format eagerly so that to_string/display cannot fail because of ASCII or
|
||||
// OpenSSL Errors Both error should be very unlikely
|
||||
// OpenSSL should be able to create PEM if there is enough memory and produce a non-null
|
||||
// terminated ASCII-string
|
||||
// Unwrap succeeds it's all ASCII
|
||||
|
||||
@@ -3,27 +3,22 @@
|
||||
// Copyright IBM Corp. 2023
|
||||
use std::mem::size_of;
|
||||
|
||||
use openssl::{
|
||||
bn::{BigNum, BigNumContext},
|
||||
ec::{EcGroup, EcGroupRef, EcKey, EcPointRef},
|
||||
error::ErrorStack,
|
||||
hash::{DigestBytes, MessageDigest},
|
||||
nid::Nid,
|
||||
pkey::{PKey, PKeyRef, Private, Public},
|
||||
};
|
||||
use openssl::bn::{BigNum, BigNumContext};
|
||||
use openssl::ec::{EcGroup, EcGroupRef, EcKey, EcPointRef};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::hash::{DigestBytes, MessageDigest};
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::{PKey, PKeyRef, Private, Public};
|
||||
use pv_core::request::{RequestMagic, RequestVersion};
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32};
|
||||
|
||||
use crate::{
|
||||
assert_size,
|
||||
crypto::{
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, hash, random_array,
|
||||
AeadEncryptionResult, SymKey, SymKeyType,
|
||||
},
|
||||
misc::to_u32,
|
||||
request::Confidential,
|
||||
Error, Result,
|
||||
use crate::crypto::{
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, hash, random_array,
|
||||
AeadEncryptionResult, SymKey, SymKeyType,
|
||||
};
|
||||
use crate::misc::to_u32;
|
||||
use crate::request::Confidential;
|
||||
use crate::{assert_size, Error, Result};
|
||||
/// Encrypt a _secret_ using self and a given private key.
|
||||
pub trait Encrypt {
|
||||
/// Encrypts `secret` using `self` and `priv_key` the encryption.
|
||||
@@ -520,7 +515,9 @@ impl<'a> BinReqValues<'a> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{get_test_asset, request::SymKey, test_utils::*};
|
||||
use crate::get_test_asset;
|
||||
use crate::request::SymKey;
|
||||
use crate::test_utils::*;
|
||||
|
||||
static TEST_MAGIC: [u8; 8] = 0x12345689abcdef00u64.to_be_bytes();
|
||||
|
||||
|
||||
@@ -4,19 +4,15 @@
|
||||
|
||||
// DO NOT USE ANY OF THESE ITEMS IN PRODUCTION CODE
|
||||
// USED FOR INTERNAL UNIT AND FVT TESTING ONLY!!!
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use openssl::{
|
||||
bn::BigNum,
|
||||
ec::{EcGroup, EcKey},
|
||||
error::ErrorStack,
|
||||
nid::Nid,
|
||||
pkey::{PKey, Private, Public},
|
||||
x509::{X509Crl, X509},
|
||||
};
|
||||
use openssl::bn::BigNum;
|
||||
use openssl::ec::{EcGroup, EcKey};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::{PKey, Private, Public};
|
||||
use openssl::x509::{X509Crl, X509};
|
||||
|
||||
/// TEST ONLY! Loads the specified asset into the binary at compile time.
|
||||
///
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::x509::{X509Crl, X509};
|
||||
|
||||
use crate::{Error, Result};
|
||||
use openssl::{
|
||||
error::ErrorStack,
|
||||
x509::{X509Crl, X509},
|
||||
};
|
||||
|
||||
/// Read all CRLs from the buffer and parse them into a vector.
|
||||
///
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use serde::Serialize;
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::req::Keyslot;
|
||||
use crate::static_assert;
|
||||
use crate::{Error, Result};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::arcb::AttestationFlags;
|
||||
use crate::req::Keyslot;
|
||||
use crate::{static_assert, Error, Result};
|
||||
|
||||
/// Hash for additional-data stuff used for parsing [`AdditionalData`]
|
||||
pub(super) const PHKH_SIZE: u32 = 0x20;
|
||||
|
||||
@@ -2,27 +2,20 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use openssl::pkey::{PKey, Public};
|
||||
use std::mem::size_of;
|
||||
|
||||
use openssl::pkey::{PKey, Public};
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32};
|
||||
|
||||
use crate::{
|
||||
assert_size,
|
||||
attest::{AttestationMagic, AttestationMeasAlg},
|
||||
crypto::random_array,
|
||||
misc::Flags,
|
||||
req::{Aad, BinReqValues, Keyslot, ReqEncrCtx},
|
||||
request::{Confidential, MagicValue, Request, RequestVersion, SymKey, Zeroize},
|
||||
static_assert,
|
||||
uv::UvFlags,
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
use super::{
|
||||
additional::{FW_STATE_SIZE, PHKH_SIZE, SECRET_STORE_HASH_SIZE},
|
||||
AttNonce,
|
||||
};
|
||||
|
||||
use super::additional::{FW_STATE_SIZE, PHKH_SIZE, SECRET_STORE_HASH_SIZE};
|
||||
use super::AttNonce;
|
||||
use crate::attest::{AttestationMagic, AttestationMeasAlg};
|
||||
use crate::crypto::random_array;
|
||||
use crate::misc::Flags;
|
||||
use crate::req::{Aad, BinReqValues, Keyslot, ReqEncrCtx};
|
||||
use crate::request::{Confidential, MagicValue, Request, RequestVersion, SymKey, Zeroize};
|
||||
use crate::uv::UvFlags;
|
||||
use crate::{assert_size, static_assert, Error, Result};
|
||||
#[cfg(doc)]
|
||||
use crate::{
|
||||
request::SymKeyType,
|
||||
@@ -419,8 +412,9 @@ impl Zeroize for ReqConfData {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use crate::{get_test_asset, request::SymKey, test_utils::get_test_keys};
|
||||
use crate::get_test_asset;
|
||||
use crate::request::SymKey;
|
||||
use crate::test_utils::get_test_keys;
|
||||
|
||||
const ARPK: [u8; 32] = [0x17; 32];
|
||||
const NONCE: [u8; 16] = [0xab; 16];
|
||||
|
||||
@@ -2,20 +2,21 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use super::AttNonce;
|
||||
use crate::{
|
||||
attest::AttestationMeasAlg, brcb::BootHdrTags, crypto::calculate_hmac, request::Confidential,
|
||||
uv::ConfigUid, Result,
|
||||
};
|
||||
use openssl::{
|
||||
hash::MessageDigest,
|
||||
pkey::{PKeyRef, Private},
|
||||
};
|
||||
use std::mem::size_of;
|
||||
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::pkey::{PKeyRef, Private};
|
||||
use zerocopy::{BigEndian, IntoBytes, U16, U32};
|
||||
|
||||
use super::AttNonce;
|
||||
use crate::attest::AttestationMeasAlg;
|
||||
#[cfg(doc)]
|
||||
use crate::attest::AttestationRequest;
|
||||
use crate::brcb::BootHdrTags;
|
||||
use crate::crypto::calculate_hmac;
|
||||
use crate::request::Confidential;
|
||||
use crate::uv::ConfigUid;
|
||||
use crate::Result;
|
||||
|
||||
/// Holds the data to be measured.
|
||||
///
|
||||
@@ -151,9 +152,10 @@ impl From<Vec<u8>> for AttestationMeasurement {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use openssl::pkey::PKey;
|
||||
|
||||
use super::*;
|
||||
|
||||
const M_KEY: [u8; 64] = [0x41; 64];
|
||||
const BOOT_HDR_TAGS: BootHdrTags = BootHdrTags::new([1; 64], [2; 64], [3; 64], [4; 16]);
|
||||
const CUID: [u8; 16] = [5; 16];
|
||||
|
||||
@@ -2,24 +2,23 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::{guest_secret::ListableSecretHdr, user_data::UserData};
|
||||
use crate::{
|
||||
assert_size,
|
||||
crypto::{hkdf_rfc_5869, AeadEncryptionResult},
|
||||
misc::Flags,
|
||||
req::{Aad, BinReqValues, Keyslot, ReqEncrCtx},
|
||||
request::{BootHdrTags, Confidential, Request},
|
||||
secret::{ExtSecret, GuestSecret},
|
||||
uv::{ConfigUid, UvFlags},
|
||||
Result,
|
||||
};
|
||||
use openssl::{
|
||||
md::Md,
|
||||
pkey::{PKey, Private, Public},
|
||||
};
|
||||
use pv_core::{request::RequestVersion, secret::AddSecretMagic, uv::SecretId};
|
||||
use openssl::md::Md;
|
||||
use openssl::pkey::{PKey, Private, Public};
|
||||
use pv_core::request::RequestVersion;
|
||||
use pv_core::secret::AddSecretMagic;
|
||||
use pv_core::uv::SecretId;
|
||||
use zerocopy::{Immutable, IntoBytes};
|
||||
|
||||
use super::guest_secret::ListableSecretHdr;
|
||||
use super::user_data::UserData;
|
||||
use crate::crypto::{hkdf_rfc_5869, AeadEncryptionResult};
|
||||
use crate::misc::Flags;
|
||||
use crate::req::{Aad, BinReqValues, Keyslot, ReqEncrCtx};
|
||||
use crate::request::{BootHdrTags, Confidential, Request};
|
||||
use crate::secret::{ExtSecret, GuestSecret};
|
||||
use crate::uv::{ConfigUid, UvFlags};
|
||||
use crate::{assert_size, Result};
|
||||
|
||||
/// Authenticated data w/o user data
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, IntoBytes, Immutable)]
|
||||
|
||||
@@ -2,31 +2,25 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#[allow(unused_imports)] // used for more convenient docstring
|
||||
use super::asrcb::AddSecretRequest;
|
||||
use crate::{
|
||||
assert_size,
|
||||
crypto::{hash, random_array, SymKeyType},
|
||||
request::{
|
||||
openssl::{NID_ED25519, NID_ED448},
|
||||
Confidential,
|
||||
},
|
||||
uv::{
|
||||
AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListableSecretType, RetrievableSecret,
|
||||
RetrieveCmd, SecretId,
|
||||
},
|
||||
Error, Result,
|
||||
};
|
||||
use openssl::{
|
||||
hash::MessageDigest,
|
||||
nid::Nid,
|
||||
pkey::{Id, PKey, PKeyRef, Private},
|
||||
};
|
||||
use std::fmt::Display;
|
||||
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::{Id, PKey, PKeyRef, Private};
|
||||
use pv_core::static_assert;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use zerocopy::{BigEndian, KnownLayout};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, U16, U32};
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32};
|
||||
|
||||
#[allow(unused_imports)] // used for more convenient docstring
|
||||
use super::asrcb::AddSecretRequest;
|
||||
use crate::crypto::{hash, random_array, SymKeyType};
|
||||
use crate::request::openssl::{NID_ED25519, NID_ED448};
|
||||
use crate::request::Confidential;
|
||||
use crate::uv::{
|
||||
AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListableSecretType, RetrievableSecret,
|
||||
RetrieveCmd, SecretId,
|
||||
};
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
const ASSOC_SECRET_SIZE: usize = 32;
|
||||
const CCK_SIZE: usize = 32;
|
||||
@@ -476,13 +470,13 @@ impl UpdateCckHdr {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::HmacShaSizes as HmacSizes;
|
||||
use super::RetrievableSecret::*;
|
||||
use super::*;
|
||||
use openssl::ec::{EcGroup, EcKey};
|
||||
use pv_core::uv::AesSizes;
|
||||
use serde_test::{assert_tokens, Token};
|
||||
|
||||
use super::RetrievableSecret::*;
|
||||
use super::{HmacShaSizes as HmacSizes, *};
|
||||
|
||||
#[test]
|
||||
fn association() {
|
||||
let secret_value = [0x11; 32];
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{crypto::SymKeyType, pem::Pem, uvsecret::guest_secret::MAX_SIZE_PLAIN_PAYLOAD, Result};
|
||||
|
||||
use log::warn;
|
||||
use pv_core::{
|
||||
request::Confidential,
|
||||
uv::{ListableSecretType, RetrievableSecret, RetrieveCmd},
|
||||
};
|
||||
use zerocopy::BigEndian;
|
||||
use zerocopy::{FromBytes, U16};
|
||||
use pv_core::request::Confidential;
|
||||
use pv_core::uv::{ListableSecretType, RetrievableSecret, RetrieveCmd};
|
||||
use zerocopy::{BigEndian, FromBytes, U16};
|
||||
|
||||
use crate::crypto::SymKeyType;
|
||||
use crate::pem::Pem;
|
||||
use crate::uvsecret::guest_secret::MAX_SIZE_PLAIN_PAYLOAD;
|
||||
use crate::Result;
|
||||
|
||||
/// An IBM Protected Key
|
||||
///
|
||||
@@ -72,8 +72,8 @@ impl From<RetrieveCmd> for RetrievedSecret {
|
||||
|
||||
match kind {
|
||||
ListableSecretType::Retrievable(RetrievableSecret::PlainText) => {
|
||||
// Will not run into default, retrieve has a granularity of 16 bytes and 16 bytes is the
|
||||
// minimum size
|
||||
// Will not run into default, retrieve has a granularity of 16 bytes and 16 bytes is
|
||||
// the minimum size
|
||||
let len = U16::<BigEndian>::read_from_prefix(key.value())
|
||||
.unwrap_or_default()
|
||||
.0
|
||||
@@ -81,8 +81,8 @@ impl From<RetrieveCmd> for RetrievedSecret {
|
||||
|
||||
// Test if the plain text secret has a size:
|
||||
// 1. len <= 8190
|
||||
// 2. first two bytes are max 15 less than buffer-size+2 i.e. smaller than the
|
||||
// block length
|
||||
// 2. first two bytes are max 15 less than buffer-size+2 i.e. smaller than the block
|
||||
// length
|
||||
// 3. bytes after len + 2 are zero
|
||||
match len <= MAX_SIZE_PLAIN_PAYLOAD
|
||||
&& key.value().len() - (len + 2) < SymKeyType::AES_256_GCM_BLOCK_LEN
|
||||
@@ -148,9 +148,10 @@ impl RetrievedSecret {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pv_core::uv::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn mk_retr(secret: &[u8]) -> RetrievedSecret {
|
||||
let entry = SecretEntry::new(
|
||||
0,
|
||||
|
||||
@@ -2,21 +2,17 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::assert_size;
|
||||
use crate::{
|
||||
crypto::{sign_msg, verify_signature},
|
||||
req::BinReqValues,
|
||||
request::{
|
||||
openssl::pkey::{HasParams, HasPublic, Id, PKey, PKeyRef, Private, Public},
|
||||
RequestMagic,
|
||||
},
|
||||
secret::{AddSecretMagic, AddSecretRequest, AddSecretVersion, UserDataType},
|
||||
Error, Result,
|
||||
};
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::nid::Nid;
|
||||
use zerocopy::{BigEndian, FromBytes, IntoBytes, KnownLayout, U16};
|
||||
|
||||
use crate::crypto::{sign_msg, verify_signature};
|
||||
use crate::req::BinReqValues;
|
||||
use crate::request::openssl::pkey::{HasParams, HasPublic, Id, PKey, PKeyRef, Private, Public};
|
||||
use crate::request::RequestMagic;
|
||||
use crate::secret::{AddSecretMagic, AddSecretRequest, AddSecretVersion, UserDataType};
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
/// User data.
|
||||
///
|
||||
/// User defined data can be:
|
||||
@@ -380,7 +376,8 @@ impl From<VerifiedUserData> for Vec<u8> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{get_test_asset, test_utils::get_test_keys};
|
||||
use crate::get_test_asset;
|
||||
use crate::test_utils::get_test_keys;
|
||||
|
||||
#[test]
|
||||
fn sign_null() {
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use crate::openssl_extensions::{StackableX509Crl, X509StoreContextExtension, X509StoreExtension};
|
||||
use core::slice;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(test))]
|
||||
use helper::download_first_crl_from_x509;
|
||||
use log::{debug, trace};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::stack::Stack;
|
||||
use openssl::x509::store::X509Store;
|
||||
use openssl::x509::{CrlStatus, X509NameRef, X509Ref, X509StoreContext, X509StoreContextRef, X509};
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(test))]
|
||||
use helper::download_first_crl_from_x509;
|
||||
#[cfg(test)]
|
||||
use test::download_first_crl_from_x509;
|
||||
|
||||
use crate::error::bail_hkd_verify;
|
||||
use crate::misc::{read_certs, read_file};
|
||||
use crate::openssl_extensions::{StackableX509Crl, X509StoreContextExtension, X509StoreExtension};
|
||||
use crate::Result;
|
||||
|
||||
mod helper;
|
||||
@@ -167,7 +167,8 @@ impl CertVerifier {
|
||||
/// * `cert_paths` - Paths to certificates for the chain of trust
|
||||
/// * `crl_paths` - Paths to certificate revocation lists for the chain of trust
|
||||
/// * `root_ca_path` - Path to the root of trust
|
||||
/// * `offline` - if set to true the verification process will not try to download CRLs from the internet.
|
||||
/// * `offline` - if set to true the verification process will not try to download CRLs from the
|
||||
/// internet.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
||||
@@ -2,27 +2,28 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::ffi::c_int;
|
||||
use std::path::Path;
|
||||
use std::str::from_utf8;
|
||||
|
||||
use log::debug;
|
||||
use openssl::asn1::{Asn1Time, Asn1TimeRef};
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::nid::Nid;
|
||||
use openssl::ssl::SslFiletype;
|
||||
use openssl::stack::Stack;
|
||||
use openssl::x509::store::{File, X509Lookup, X509StoreBuilder, X509StoreRef};
|
||||
use openssl::x509::verify::{X509VerifyFlags, X509VerifyParam};
|
||||
use openssl::x509::{
|
||||
X509CrlRef, X509Name, X509NameRef, X509PurposeId, X509Ref, X509StoreContext,
|
||||
X509StoreContextRef, X509VerifyResult, X509,
|
||||
};
|
||||
|
||||
use crate::error::bail_hkd_verify;
|
||||
use crate::openssl_extensions::{AkidCheckResult, AkidExtension};
|
||||
use crate::HkdVerifyErrorType::*;
|
||||
use crate::{Error, Result};
|
||||
use log::debug;
|
||||
use openssl::{
|
||||
asn1::{Asn1Time, Asn1TimeRef},
|
||||
error::ErrorStack,
|
||||
nid::Nid,
|
||||
ssl::SslFiletype,
|
||||
stack::Stack,
|
||||
x509::{
|
||||
store::{File, X509Lookup, X509StoreBuilder, X509StoreRef},
|
||||
verify::{X509VerifyFlags, X509VerifyParam},
|
||||
X509CrlRef, X509Name, X509NameRef, X509PurposeId, X509Ref, X509StoreContext,
|
||||
X509StoreContextRef, X509VerifyResult, X509,
|
||||
},
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::str::from_utf8;
|
||||
use std::{cmp::Ordering, ffi::c_int};
|
||||
|
||||
/// Minimum security level for the keys/certificates used to establish a chain of
|
||||
/// trust (see <https://www.openssl.org/docs/man1.1.1/man3/X509_VERIFY_PARAM_set_auth_level.html>
|
||||
@@ -306,9 +307,11 @@ pub fn x509_dist_points(cert: &X509Ref) -> Vec<String> {
|
||||
/// CRL not available at all URIs and unexpected format at all URIs are mapped to Ok(None)
|
||||
#[cfg(not(test))]
|
||||
pub fn download_first_crl_from_x509(cert: &X509Ref) -> Result<Option<Vec<openssl::x509::X509Crl>>> {
|
||||
use crate::utils::read_crls;
|
||||
use curl::easy::{Easy2, Handler, WriteError};
|
||||
use std::time::Duration;
|
||||
|
||||
use curl::easy::{Easy2, Handler, WriteError};
|
||||
|
||||
use crate::utils::read_crls;
|
||||
const CRL_TIMEOUT_MAX: Duration = Duration::from_secs(3);
|
||||
struct Buf(Vec<u8>);
|
||||
|
||||
@@ -397,9 +400,10 @@ pub fn armonk_locality_fixup(subject: &X509NameRef) -> Option<X509Name> {
|
||||
/// tests for some private functions
|
||||
mod test {
|
||||
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use super::*;
|
||||
use crate::test_utils::*;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
fn sys_to_asn1_time(syst: SystemTime) -> Asn1Time {
|
||||
let secs = syst
|
||||
|
||||
@@ -4,12 +4,17 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use super::{helper, helper::*, *};
|
||||
use crate::{utils::read_crls, Error, HkdVerifyErrorType::*};
|
||||
use openssl::{stack::Stack, x509::X509Crl};
|
||||
use std::path::Path;
|
||||
|
||||
use openssl::stack::Stack;
|
||||
use openssl::x509::X509Crl;
|
||||
|
||||
use super::helper::*;
|
||||
use super::{helper, *};
|
||||
use crate::test_utils::*;
|
||||
use crate::utils::read_crls;
|
||||
use crate::Error;
|
||||
use crate::HkdVerifyErrorType::*;
|
||||
|
||||
// Mock function
|
||||
pub fn download_first_crl_from_x509(cert: &X509Ref) -> Result<Option<Vec<X509Crl>>> {
|
||||
|
||||
@@ -3,25 +3,18 @@
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#![allow(missing_docs)]
|
||||
use openssl::{
|
||||
ec::{EcGroup, EcKey},
|
||||
nid::Nid,
|
||||
pkey::Private,
|
||||
};
|
||||
use s390_pv::{
|
||||
get_test_asset,
|
||||
request::{
|
||||
openssl::pkey::{PKey, Public},
|
||||
BootHdrTags, ReqEncrCtx, Request, SymKey,
|
||||
},
|
||||
secret::{
|
||||
verify_asrcb_and_get_user_data, AddSecretFlags, AddSecretRequest, AddSecretVersion,
|
||||
ExtSecret, GuestSecret,
|
||||
},
|
||||
test_utils::get_test_keys,
|
||||
uv::ConfigUid,
|
||||
Result,
|
||||
use openssl::ec::{EcGroup, EcKey};
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::Private;
|
||||
use s390_pv::request::openssl::pkey::{PKey, Public};
|
||||
use s390_pv::request::{BootHdrTags, ReqEncrCtx, Request, SymKey};
|
||||
use s390_pv::secret::{
|
||||
verify_asrcb_and_get_user_data, AddSecretFlags, AddSecretRequest, AddSecretVersion, ExtSecret,
|
||||
GuestSecret,
|
||||
};
|
||||
use s390_pv::test_utils::get_test_keys;
|
||||
use s390_pv::uv::ConfigUid;
|
||||
use s390_pv::{get_test_asset, Result};
|
||||
|
||||
const TAGS: BootHdrTags = BootHdrTags::new([1; 64], [2; 64], [3; 64], [4; 16]);
|
||||
const CUID: ConfigUid = [0x42u8; 16];
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#![allow(missing_docs)]
|
||||
use std::ffi::c_int;
|
||||
|
||||
use s390_pv::request::CertVerifier;
|
||||
use s390_pv::test_utils::*;
|
||||
use s390_pv::{Error, HkdVerifyErrorType::*};
|
||||
use std::ffi::c_int;
|
||||
use s390_pv::Error;
|
||||
use s390_pv::HkdVerifyErrorType::*;
|
||||
|
||||
#[track_caller]
|
||||
fn verify_sign_error(exp_raw: c_int, obs: Error) {
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
//! AP support functions
|
||||
//
|
||||
|
||||
use crate::{
|
||||
utils::{pv_guest_bit_set, read_file_string, write_file},
|
||||
Error, Result,
|
||||
};
|
||||
use std::{fmt, thread, time};
|
||||
|
||||
use regex::Regex;
|
||||
use std::fmt;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
|
||||
use crate::utils::{pv_guest_bit_set, read_file_string, write_file};
|
||||
use crate::{Error, Result};
|
||||
|
||||
const PATH_SYS_DEVICES_AP: &str = "/sys/devices/ap";
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ impl<T: Default> Zeroize for Vec<T> {
|
||||
|
||||
impl Zeroize for String {
|
||||
fn zeroize(&mut self) {
|
||||
// SAFETY: The Vec<u8> zerorize function overwrites memory with the zero byte -> still valid UTF-8
|
||||
// SAFETY: The Vec<u8> zerorize function overwrites memory with the zero byte -> still valid
|
||||
// UTF-8
|
||||
unsafe { self.as_mut_vec().zeroize() };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ mod uvdevice;
|
||||
mod uvsecret;
|
||||
|
||||
pub use error::{Error, FileAccessErrorType, FileIoErrorType, Result};
|
||||
|
||||
/// Early Boot Customization (EBC) utilities.
|
||||
///
|
||||
/// This module provides types and functions for working with Early Boot
|
||||
@@ -28,13 +27,11 @@ pub mod attest {
|
||||
|
||||
/// Miscellaneous functions and definitions
|
||||
pub mod misc {
|
||||
pub use crate::utils::pv_guest_bit_set;
|
||||
pub use crate::utils::{create_file, open_file};
|
||||
pub use crate::utils::{decode_hex, encode_hex, parse_hex};
|
||||
pub use crate::utils::{read, write};
|
||||
pub use crate::utils::{read_exact_file, read_file, read_file_string, write_file};
|
||||
pub use crate::utils::{to_u16, to_u32, try_parse_u128, try_parse_u64};
|
||||
pub use crate::utils::{Flags, Lsb0Flags64, Msb0Flags64};
|
||||
pub use crate::utils::{
|
||||
create_file, decode_hex, encode_hex, open_file, parse_hex, pv_guest_bit_set, read,
|
||||
read_exact_file, read_file, read_file_string, to_u16, to_u32, try_parse_u128,
|
||||
try_parse_u64, write, write_file, Flags, Lsb0Flags64, Msb0Flags64,
|
||||
};
|
||||
}
|
||||
|
||||
/// Definitions and functions for interacting with the Ultravisor
|
||||
@@ -43,8 +40,9 @@ pub mod misc {
|
||||
/// [`crate::uv::UvCmd`]
|
||||
pub mod uv {
|
||||
pub use crate::uvdevice::attest::AttestationCmd;
|
||||
pub use crate::uvdevice::retr_secret::RetrievableSecret;
|
||||
pub use crate::uvdevice::retr_secret::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes};
|
||||
pub use crate::uvdevice::retr_secret::{
|
||||
AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, RetrievableSecret,
|
||||
};
|
||||
pub use crate::uvdevice::secret::{AddCmd, ListCmd, LockCmd, RetrieveCmd};
|
||||
pub use crate::uvdevice::secret_list::{ListableSecretType, SecretEntry, SecretId, SecretList};
|
||||
pub use crate::uvdevice::{ConfigUid, UvCmd, UvDevice, UvDeviceInfo, UvFlags, UvcSuccess};
|
||||
@@ -77,15 +75,12 @@ pub mod request {
|
||||
|
||||
/// Functionalities for reading add-secret requests
|
||||
pub mod secret {
|
||||
pub use crate::uvsecret::AddSecretMagic;
|
||||
pub use crate::uvsecret::UserDataType;
|
||||
pub use crate::uvsecret::{AddSecretMagic, UserDataType};
|
||||
}
|
||||
|
||||
/// Functionalities for the AP bus
|
||||
pub mod ap {
|
||||
pub use crate::apdevice::Apqn;
|
||||
pub use crate::apdevice::RE_QUEUE_DIR;
|
||||
pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state};
|
||||
pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state, Apqn, RE_QUEUE_DIR};
|
||||
/// AP modes
|
||||
pub mod apqn_mode {
|
||||
pub use crate::apdevice::ApqnMode::{self, *};
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// Copyright IBM Corp.
|
||||
|
||||
use std::fmt::{Display, Formatter, Result as Resfmt};
|
||||
use std::fs::File;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::from_utf8;
|
||||
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes};
|
||||
|
||||
use crate::misc::encode_hex;
|
||||
use crate::utils::open_file;
|
||||
use crate::{Error, Result};
|
||||
use std::{
|
||||
fmt::{Display, Formatter, Result as Resfmt},
|
||||
fs::File,
|
||||
os::unix::ffi::OsStrExt,
|
||||
path::{Path, PathBuf},
|
||||
str::from_utf8,
|
||||
};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes};
|
||||
|
||||
const HASH_LEN: usize = 32;
|
||||
// UserDataType::Unsigned.max() returns 512
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, U64};
|
||||
|
||||
use crate::{
|
||||
macros::{bail_spec, file_error},
|
||||
Error, FileAccessErrorType, Result,
|
||||
};
|
||||
use crate::macros::{bail_spec, file_error};
|
||||
use crate::{Error, FileAccessErrorType, Result};
|
||||
|
||||
/// Trait that describes bitflags, represented by `T`.
|
||||
pub trait Flags<T>: From<T> + for<'a> From<&'a T> {
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{request::MagicValue, Error};
|
||||
use zerocopy::U32;
|
||||
use zerocopy::{BigEndian, ByteOrder};
|
||||
use zerocopy::{BigEndian, ByteOrder, U32};
|
||||
|
||||
use crate::request::MagicValue;
|
||||
use crate::Error;
|
||||
|
||||
/// The magic value used to identify an attestation request
|
||||
///
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
use crate::FileAccessErrorType;
|
||||
use crate::{Error, Result};
|
||||
use log::debug;
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
fs::File,
|
||||
os::unix::prelude::{AsRawFd, RawFd},
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use std::os::unix::prelude::{AsRawFd, RawFd};
|
||||
|
||||
#[cfg(not(test))]
|
||||
use ::libc::ioctl;
|
||||
use log::debug;
|
||||
#[cfg(test)]
|
||||
use test::mock_libc::ioctl;
|
||||
|
||||
use crate::{Error, FileAccessErrorType, Result};
|
||||
|
||||
/// Contains the rust representation of asm/uvdevice.h
|
||||
/// from kernel version: 6.5 verify
|
||||
mod ffi;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
use std::ptr;
|
||||
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
use super::{ffi, AttestationUserData, ConfigUid, UvCmd};
|
||||
use crate::{Error, Result};
|
||||
use std::ptr;
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
/// _Retrieve Attestation Measurement_ UVC
|
||||
///
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
use crate::{assert_size, static_assert};
|
||||
use zerocopy::{FromBytes, IntoBytes};
|
||||
|
||||
use crate::{assert_size, static_assert};
|
||||
|
||||
pub const UVIO_ATT_ARCB_MAX_LEN: usize = 0x100000;
|
||||
pub const UVIO_ATT_MEASUREMENT_MAX_LEN: usize = 0x8000;
|
||||
pub const UVIO_ATT_ADDITIONAL_MAX_LEN: usize = 0x8000;
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi::{self, uvio_uvdev_info};
|
||||
use crate::{
|
||||
misc::{Flags, Lsb0Flags64},
|
||||
uv::{UvCmd, UvDevice},
|
||||
Result,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
use super::ffi::{self, uvio_uvdev_info};
|
||||
use crate::misc::{Flags, Lsb0Flags64};
|
||||
use crate::uv::{UvCmd, UvDevice};
|
||||
use crate::Result;
|
||||
|
||||
/// Information of supported functions by the uvdevice
|
||||
///
|
||||
/// * `supp_uvio_cmds` - supported IOCTLs by this device
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::uv::{ListableSecretType, RetrieveCmd};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
|
||||
use crate::uv::{ListableSecretType, RetrieveCmd};
|
||||
|
||||
/// Allowed sizes for AES keys
|
||||
#[non_exhaustive]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
@@ -335,8 +337,8 @@ mod test {
|
||||
assert_tokens(&retr, &[Token::Str("19 (EC-SECP521R1-PRIVATE-KEY)")]);
|
||||
}
|
||||
|
||||
// Ensure that the string representation of the retrievable types stay constant, or PEM will have
|
||||
// different, incompatible types
|
||||
// Ensure that the string representation of the retrievable types stay constant, or PEM will
|
||||
// have different, incompatible types
|
||||
#[test]
|
||||
fn stable_type_names() {
|
||||
assert_eq!("PLAINTEXT", RetrievableSecret::PlainText.to_string());
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi;
|
||||
use crate::{
|
||||
request::{Confidential, MagicValue},
|
||||
uv::{SecretEntry, UvCmd},
|
||||
uvsecret::AddSecretMagic,
|
||||
Error, Result, PAGESIZE,
|
||||
};
|
||||
use std::io::Read;
|
||||
use std::mem::size_of_val;
|
||||
|
||||
use log::debug;
|
||||
use std::{io::Read, mem::size_of_val};
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::ffi;
|
||||
use crate::request::{Confidential, MagicValue};
|
||||
use crate::uv::{SecretEntry, UvCmd};
|
||||
use crate::uvsecret::AddSecretMagic;
|
||||
use crate::{Error, Result, PAGESIZE};
|
||||
|
||||
/// _List Secrets_ Ultravisor command.
|
||||
///
|
||||
/// The List Secrets Ultravisor call is used to list the
|
||||
|
||||
@@ -2,24 +2,20 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{
|
||||
assert_size,
|
||||
uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret},
|
||||
uvdevice::UvCmd,
|
||||
Error, Result,
|
||||
};
|
||||
use std::cmp::min;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::{Debug, Display, LowerHex, UpperHex};
|
||||
use std::io::{Cursor, Read, Seek, Write};
|
||||
use std::mem::size_of;
|
||||
use std::slice::Iter;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::{
|
||||
cmp::min,
|
||||
ffi::CStr,
|
||||
fmt::{Debug, Display, LowerHex, UpperHex},
|
||||
io::{Cursor, Read, Seek, Write},
|
||||
mem::size_of,
|
||||
slice::Iter,
|
||||
vec::IntoIter,
|
||||
};
|
||||
use zerocopy::{BigEndian, ByteOrder};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32};
|
||||
use zerocopy::{BigEndian, ByteOrder, FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32};
|
||||
|
||||
use crate::uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret};
|
||||
use crate::uvdevice::UvCmd;
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
/// The 32 byte long ID of an UV secret
|
||||
///
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::{c_int, c_ulong},
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
use std::ffi::{c_int, c_ulong};
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::*;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
/// needed to serialize all tests as tests operate on static data required by the mock
|
||||
@@ -129,8 +128,8 @@ impl UvCmd for TestCmd {
|
||||
}
|
||||
|
||||
impl UvDevice {
|
||||
/// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never touches the
|
||||
/// passed file
|
||||
/// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never
|
||||
/// touches the passed file
|
||||
fn test_dev() -> Self {
|
||||
Self(File::open(".").unwrap())
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use crate::assert_size;
|
||||
use crate::{
|
||||
request::{MagicValue, RequestMagic},
|
||||
Error, Result,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::mem::size_of;
|
||||
|
||||
use byteorder::ByteOrder;
|
||||
use std::{fmt::Display, mem::size_of};
|
||||
use zerocopy::{BigEndian, Immutable, IntoBytes, U16};
|
||||
|
||||
use crate::request::{MagicValue, RequestMagic};
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
/// The magic value used to identify an `AddSecretRequest`.
|
||||
///
|
||||
/// The magic value is ASCII:
|
||||
@@ -145,11 +145,9 @@ impl From<UserDataType> for AddSecretMagic {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{
|
||||
request::MagicValue,
|
||||
secret::{AddSecretMagic, UserDataType},
|
||||
Error,
|
||||
};
|
||||
use crate::request::MagicValue;
|
||||
use crate::secret::{AddSecretMagic, UserDataType};
|
||||
use crate::Error;
|
||||
|
||||
#[test]
|
||||
fn convert_user_data() {
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
// Copyright IBM Corp. 2024
|
||||
// it under the terms of the MIT license. See LICENSE for details.
|
||||
|
||||
use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use std::env;
|
||||
use std::io::Error;
|
||||
|
||||
use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
//! AP support functions for pvapconfig
|
||||
//
|
||||
|
||||
use crate::helper::*;
|
||||
use pv_core::ap::*;
|
||||
use pv_core::misc::read_file_string;
|
||||
use std::path::Path;
|
||||
use std::slice::Iter;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use std::{thread, time};
|
||||
|
||||
use pv_core::ap::*;
|
||||
use pv_core::misc::read_file_string;
|
||||
|
||||
use crate::helper::*;
|
||||
|
||||
const RE_CARD_DIR: &str = r"^card([[:xdigit:]]{2})$";
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
//! Functions around handling the pvapconfig configuration file
|
||||
//
|
||||
|
||||
use std::fs::File;
|
||||
use std::slice::Iter;
|
||||
|
||||
use openssl::sha::sha256;
|
||||
use pv_core::misc::encode_hex;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml::{self};
|
||||
use std::fs::File;
|
||||
use std::slice::Iter;
|
||||
|
||||
pub const STR_MODE_EP11: &str = "ep11";
|
||||
pub const STR_MODE_ACCEL: &str = "accel";
|
||||
@@ -209,10 +210,10 @@ impl ApConfigList {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::{env, fs};
|
||||
|
||||
use super::*;
|
||||
|
||||
const GOOD_CONFIGS: [&str; 8] = [
|
||||
"# good test 1
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
//! Collection of helper functions for pvapconfig
|
||||
//
|
||||
|
||||
use regex::Regex;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
pub const PATH_PVAPCONFIG_LOCK: &str = "/run/lock/pvapconfig.lock";
|
||||
|
||||
/// For a given (sysfs) directory construct a list of all subdirs
|
||||
@@ -129,9 +130,10 @@ impl Drop for LockFile {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use utils::TemporaryDirectory;
|
||||
|
||||
use super::*;
|
||||
|
||||
// Only very simple tests
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -12,6 +12,8 @@ mod config;
|
||||
mod helper;
|
||||
mod uv;
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
use ap::ApqnList;
|
||||
use cli::ARGS;
|
||||
use config::{ApConfigEntry, ApConfigList};
|
||||
@@ -19,7 +21,6 @@ use helper::{LockFile, PATH_PVAPCONFIG_LOCK};
|
||||
use pv_core::ap::{self as pvap, Apqn};
|
||||
use pv_core::misc::encode_hex;
|
||||
use pv_core::uv::{ListableSecretType, SecretList};
|
||||
use std::process::ExitCode;
|
||||
use utils::print_version;
|
||||
|
||||
/// Simple macro for
|
||||
@@ -456,8 +457,10 @@ fn config_and_apqn_match(apc: &ApConfigEntry, apqn: &Apqn) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use pv_core::misc::decode_hex;
|
||||
use pv_core::uv::SecretEntry;
|
||||
|
||||
use super::*;
|
||||
use pv_core::{misc::decode_hex, uv::SecretEntry};
|
||||
|
||||
// This is more or less only a test for the do_ap_config() function
|
||||
// However, this is THE main functionality of the whole application.
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
// it under the terms of the MIT license. See LICENSE for details.
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use std::env;
|
||||
use std::io::Error;
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate_to, Shell};
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::exchange::ExchangeFormatResponse;
|
||||
use std::fmt::Display;
|
||||
|
||||
use anyhow::Result;
|
||||
use pv::attest::{AdditionalData, AttestationFlags};
|
||||
use serde::Serialize;
|
||||
use std::fmt::Display;
|
||||
use utils::HexSlice;
|
||||
|
||||
use crate::exchange::ExchangeFormatResponse;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AttestationResult<'a> {
|
||||
pub cuid: HexSlice<'a>,
|
||||
|
||||
@@ -58,7 +58,8 @@ pub enum Command {
|
||||
|
||||
/// Check if the attestation result matches defined policies.
|
||||
///
|
||||
/// After the attestation verification, check whether the attestation result complies with user-defined policies.
|
||||
/// After the attestation verification, check whether the attestation result complies with
|
||||
/// user-defined policies.
|
||||
Check(CheckOpt),
|
||||
|
||||
/// Print version information and exit.
|
||||
@@ -103,7 +104,8 @@ pub enum AttAddFlags {
|
||||
/// additional-data.
|
||||
PhkhAtt,
|
||||
|
||||
/// Request a hash over all successful Add-secret requests and the lock state as additional-data.
|
||||
/// Request a hash over all successful Add-secret requests and the lock state as
|
||||
/// additional-data.
|
||||
SecretStoreHash,
|
||||
|
||||
/// Request the state of the firmware as additional-data.
|
||||
|
||||
@@ -6,28 +6,22 @@ mod firmware;
|
||||
mod host_key;
|
||||
mod secret_store;
|
||||
|
||||
use self::{
|
||||
firmware::firmware_check,
|
||||
host_key::{host_key_check, HostKeyCheck},
|
||||
secret_store::secret_store_check,
|
||||
secret_store::SecretStoreCheck,
|
||||
};
|
||||
use crate::{
|
||||
additional::AttestationResult,
|
||||
cli::{CheckOpt, CheckOptIO},
|
||||
exchange::ExchangeFormatResponse,
|
||||
};
|
||||
use std::process::ExitCode;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::{debug, info, warn};
|
||||
use pv::{
|
||||
attest::AttestationRequest,
|
||||
misc::{create_file, open_file, read_file},
|
||||
};
|
||||
use pv::attest::AttestationRequest;
|
||||
use pv::misc::{create_file, open_file, read_file};
|
||||
use serde::Serialize;
|
||||
use std::process::ExitCode;
|
||||
use utils::HexSlice;
|
||||
|
||||
use self::firmware::firmware_check;
|
||||
use self::host_key::{host_key_check, HostKeyCheck};
|
||||
use self::secret_store::{secret_store_check, SecretStoreCheck};
|
||||
use crate::additional::AttestationResult;
|
||||
use crate::cli::{CheckOpt, CheckOptIO};
|
||||
use crate::exchange::ExchangeFormatResponse;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
enum CheckState<T> {
|
||||
#[default]
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{fmt::Display, time::Duration};
|
||||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use base64::prelude::*;
|
||||
@@ -11,7 +12,8 @@ use log::{debug, info, log_enabled};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{bail_check, CheckState};
|
||||
use crate::{additional::AttestationResult, cli::CheckOpt};
|
||||
use crate::additional::AttestationResult;
|
||||
use crate::cli::CheckOpt;
|
||||
|
||||
const CHECK_DEFAULT_ENDP: &str = "https://esupport.ibm.com/eccedge/ent/z";
|
||||
const VERIFY_API: &str = "hmrs/firmware/attestation/v1/verify";
|
||||
|
||||
@@ -2,21 +2,20 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::{debug, info};
|
||||
use pv::{
|
||||
misc::{read_certs, read_file},
|
||||
request::{openssl::DigestBytes, EcPubKeyCoord},
|
||||
};
|
||||
use pv::misc::{read_certs, read_file};
|
||||
use pv::request::openssl::DigestBytes;
|
||||
use pv::request::EcPubKeyCoord;
|
||||
use serde::Serialize;
|
||||
use std::{fmt::Display, path::Path};
|
||||
use utils::HexSlice;
|
||||
|
||||
use super::CheckState;
|
||||
use crate::{
|
||||
additional::AttestationResult,
|
||||
cli::{CheckOpt, HostKeyCheckPolicy},
|
||||
};
|
||||
use crate::additional::AttestationResult;
|
||||
use crate::cli::{CheckOpt, HostKeyCheckPolicy};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum HkCheck {
|
||||
|
||||
@@ -6,13 +6,14 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use log::info;
|
||||
use openssl::hash::DigestBytes;
|
||||
use openssl::hash::{hash, MessageDigest};
|
||||
use pv::{misc::read_file, secret::AddSecretRequest};
|
||||
use openssl::hash::{hash, DigestBytes, MessageDigest};
|
||||
use pv::misc::read_file;
|
||||
use pv::secret::AddSecretRequest;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{bail_check, CheckState};
|
||||
use crate::{additional::AttestationResult, cli::CheckOpt};
|
||||
use crate::additional::AttestationResult;
|
||||
use crate::cli::CheckOpt;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SecretStoreCheck<'a> {
|
||||
|
||||
@@ -2,18 +2,16 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{
|
||||
cli::{AttAddFlags, CreateAttOpt},
|
||||
exchange::{ExchangeFormatRequest, ExchangeFormatVersion},
|
||||
};
|
||||
use std::process::ExitCode;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use log::{debug, warn};
|
||||
use pv::{
|
||||
attest::{AttestationFlags, AttestationMeasAlg, AttestationRequest, AttestationVersion},
|
||||
misc::{create_file, write_file},
|
||||
request::{ReqEncrCtx, Request, SymKey, SymKeyType},
|
||||
};
|
||||
use std::process::ExitCode;
|
||||
use pv::attest::{AttestationFlags, AttestationMeasAlg, AttestationRequest, AttestationVersion};
|
||||
use pv::misc::{create_file, write_file};
|
||||
use pv::request::{ReqEncrCtx, Request, SymKey, SymKeyType};
|
||||
|
||||
use crate::cli::{AttAddFlags, CreateAttOpt};
|
||||
use crate::exchange::{ExchangeFormatRequest, ExchangeFormatVersion};
|
||||
|
||||
fn flags(cli_flags: &[AttAddFlags]) -> AttestationFlags {
|
||||
let mut att_flags = AttestationFlags::default();
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
//
|
||||
// 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;
|
||||
|
||||
use anyhow::Result;
|
||||
use pv::misc::{create_file, open_file, read_file};
|
||||
use pv::uv::{AttestationCmd, UvDevice};
|
||||
|
||||
use crate::cli::PerformAttOptComb;
|
||||
use crate::exchange::{ExchangeFormatRequest, ExchangeFormatResponse, ExchangeFormatVersion};
|
||||
|
||||
pub fn perform<'a, P>(opt: P) -> Result<ExitCode>
|
||||
where
|
||||
P: Into<PerformAttOptComb<'a>>,
|
||||
|
||||
@@ -2,22 +2,20 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::{debug, warn};
|
||||
use pv::{
|
||||
attest::{AttestationItems, AttestationMeasurement, AttestationRequest},
|
||||
misc::{create_file, open_file, read_exact_file, write_file},
|
||||
request::{openssl::pkey::PKey, BootHdrTags, Confidential, SymKey},
|
||||
};
|
||||
use std::process::ExitCode;
|
||||
use pv::attest::{AttestationItems, AttestationMeasurement, AttestationRequest};
|
||||
use pv::misc::{create_file, open_file, read_exact_file, write_file};
|
||||
use pv::request::openssl::pkey::PKey;
|
||||
use pv::request::{BootHdrTags, Confidential, SymKey};
|
||||
use utils::HexSlice;
|
||||
|
||||
use crate::{
|
||||
additional::AttestationResult,
|
||||
cli::{OutputType, VerifyOpt},
|
||||
exchange::ExchangeFormatResponse,
|
||||
EXIT_CODE_ATTESTATION_FAIL,
|
||||
};
|
||||
use crate::additional::AttestationResult;
|
||||
use crate::cli::{OutputType, VerifyOpt};
|
||||
use crate::exchange::ExchangeFormatResponse;
|
||||
use crate::EXIT_CODE_ATTESTATION_FAIL;
|
||||
|
||||
pub fn verify(opt: &VerifyOpt) -> Result<ExitCode> {
|
||||
let mut input = open_file(&opt.input)?;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
#![allow(unused)]
|
||||
use std::io::{ErrorKind, Read, Seek, SeekFrom, Write};
|
||||
use std::mem::size_of;
|
||||
|
||||
use anyhow::{anyhow, bail, Error, Result};
|
||||
use pv::{assert_size, request::MagicValue, uv::AttestationCmd, uv::ConfigUid};
|
||||
use std::{
|
||||
io::{ErrorKind, Read, Seek, SeekFrom, Write},
|
||||
mem::size_of,
|
||||
};
|
||||
use zerocopy::ByteOrder;
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64};
|
||||
use pv::assert_size;
|
||||
use pv::request::MagicValue;
|
||||
use pv::uv::{AttestationCmd, ConfigUid};
|
||||
use zerocopy::{BigEndian, ByteOrder, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64};
|
||||
|
||||
const INV_EXCHANGE_FMT_ERROR_TEXT: &str = "The input has not the correct format:";
|
||||
|
||||
@@ -583,9 +583,10 @@ mod test {
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
use super::*;
|
||||
use pv::misc::read_file;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn exchange_from_slice() {
|
||||
let val = &[0; 17];
|
||||
|
||||
@@ -8,10 +8,11 @@ mod cli;
|
||||
mod cmd;
|
||||
mod exchange;
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
use clap::{CommandFactory, Parser};
|
||||
use cli::{CliOptions, Command};
|
||||
use log::trace;
|
||||
use std::process::ExitCode;
|
||||
use utils::{print_cli_error, print_error, print_version, PvLogger};
|
||||
|
||||
use crate::cmd::{check, create, perform, verify, CMD_FN, UV_CMD_FN};
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// Copyright IBM Corp.
|
||||
|
||||
use std::{path::PathBuf, sync::OnceLock};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use clap::{ArgAction, Parser, ValueHint};
|
||||
|
||||
@@ -21,8 +22,8 @@ pub struct Cli {
|
||||
/// Specifies the toc.asr which is the root of the EBC resources
|
||||
///
|
||||
/// Specify the add-secret request file toc.asr that serves as the root of the EBC resources.
|
||||
/// Its user data must contain a reference to toc.pol as generated by pvsecret with the --policy
|
||||
/// option.
|
||||
/// Its user data must contain a reference to toc.pol as generated by pvsecret with the
|
||||
/// --policy option.
|
||||
#[arg(short, long, value_name = "FILE", value_hint = ValueHint::FilePath)]
|
||||
pub toc: PathBuf,
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
//
|
||||
// Copyright IBM Corp.
|
||||
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use pv_core::misc::open_file;
|
||||
use std::{io::Read, path::Path};
|
||||
|
||||
/// Length of the MAC tag in bytes (last 16 bytes of AddSecretRequest files)
|
||||
pub const MAC_TAG_LEN: usize = 16;
|
||||
|
||||
@@ -20,27 +20,23 @@
|
||||
mod cli;
|
||||
mod ebc_utils;
|
||||
|
||||
#[cfg(target_arch = "s390x")]
|
||||
use pv_core::uv::{AddCmd, UvDevice};
|
||||
#[cfg(target_arch = "s390x")]
|
||||
use utils::get_reader_from_cli_file_arg;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{BufRead, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitCode;
|
||||
use std::str::from_utf8;
|
||||
|
||||
use anyhow::{bail, Context, Error, Result};
|
||||
use clap::Parser;
|
||||
use pv_core::{
|
||||
misc::{decode_hex, encode_hex},
|
||||
PolicyReference,
|
||||
};
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::{BufRead, Read},
|
||||
path::{Path, PathBuf},
|
||||
process::ExitCode,
|
||||
str::from_utf8,
|
||||
};
|
||||
use pv_core::misc::{decode_hex, encode_hex};
|
||||
#[cfg(target_arch = "s390x")]
|
||||
use pv_core::uv::{AddCmd, UvDevice};
|
||||
use pv_core::PolicyReference;
|
||||
// Don't use openssl here because this tool is intended to run in the initramfs
|
||||
// phase of the boot and there we don't want to dynamically link against a C lib
|
||||
use sha2::{self, Digest};
|
||||
#[cfg(target_arch = "s390x")]
|
||||
use utils::get_reader_from_cli_file_arg;
|
||||
use zerocopy::TryFromBytes;
|
||||
|
||||
use crate::cli::Cli;
|
||||
|
||||
@@ -3,27 +3,21 @@
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
#![allow(missing_docs)]
|
||||
use std::{
|
||||
fmt::Display,
|
||||
fs::{File, OpenOptions},
|
||||
io::{BufReader, Read, Write},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{BufReader, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::{anyhow, Context, Error};
|
||||
use clap::{Parser, ValueHint};
|
||||
use log::{info, warn};
|
||||
use pv::{
|
||||
misc::{decode_hex, open_file, read_certs, read_file, try_parse_u64},
|
||||
request::SymKeyType,
|
||||
Error as PvError, Result,
|
||||
};
|
||||
use pvimg::{
|
||||
misc::PSW,
|
||||
secured_comp::{ComponentTrait, Layout, SecuredComponentBuilder},
|
||||
uvdata::{BuilderTrait, SeHdrBuilder, SeHdrVersion},
|
||||
};
|
||||
use pv::misc::{decode_hex, open_file, read_certs, read_file, try_parse_u64};
|
||||
use pv::request::SymKeyType;
|
||||
use pv::{Error as PvError, Result};
|
||||
use pvimg::misc::PSW;
|
||||
use pvimg::secured_comp::{ComponentTrait, Layout, SecuredComponentBuilder};
|
||||
use pvimg::uvdata::{BuilderTrait, SeHdrBuilder, SeHdrVersion};
|
||||
use utils::{AtomicFile, AtomicFileOperation, HexSlice, PvLogger, VerbosityOptions};
|
||||
|
||||
/// Converts the hexstring into a byte vector.
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::{fs::File, io::Write, path::PathBuf};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::{Parser, ValueEnum, ValueHint};
|
||||
use log::info;
|
||||
use pv::{
|
||||
misc::{open_file, parse_hex, read_file},
|
||||
request::SymKey,
|
||||
};
|
||||
use pvimg::{
|
||||
error::Result,
|
||||
uvdata::{
|
||||
KeyExchangeTrait, SeHdr, SeHdrBinV1, SeHdrData, SeHdrDataV1, SeHdrVersioned,
|
||||
UvDataPlainTrait, UvDataTrait,
|
||||
},
|
||||
use pv::misc::{open_file, parse_hex, read_file};
|
||||
use pv::request::SymKey;
|
||||
use pvimg::error::Result;
|
||||
use pvimg::uvdata::{
|
||||
KeyExchangeTrait, SeHdr, SeHdrBinV1, SeHdrData, SeHdrDataV1, SeHdrVersioned, UvDataPlainTrait,
|
||||
UvDataTrait,
|
||||
};
|
||||
use utils::{PvLogger, VerbosityOptions};
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt::Display;
|
||||
use std::io::IsTerminal;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::string::ToString;
|
||||
use std::{env, ffi::OsStr, io::IsTerminal, path::PathBuf};
|
||||
|
||||
use clap::{
|
||||
builder::{PossibleValue, TypedValueParser},
|
||||
Arg, ArgGroup, Args, Command, CommandFactory, Parser, ValueEnum, ValueHint,
|
||||
};
|
||||
use clap::builder::{PossibleValue, TypedValueParser};
|
||||
use clap::{Arg, ArgGroup, Args, Command, CommandFactory, Parser, ValueEnum, ValueHint};
|
||||
use log::warn;
|
||||
use utils::{CertificateOptions, DeprecatedVerbosityOptions};
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::info;
|
||||
use pv::{misc::read_file, request::Confidential};
|
||||
use pv::misc::read_file;
|
||||
use pv::request::Confidential;
|
||||
|
||||
use crate::cli::UserKeys;
|
||||
|
||||
|
||||
@@ -2,29 +2,27 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{fs::OpenOptions, io::BufReader};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::BufReader;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use log::{debug, warn};
|
||||
use pv::misc::{open_file, try_parse_u64};
|
||||
use pvimg::{
|
||||
error::OwnExitCode,
|
||||
secured_comp::ComponentTrait,
|
||||
uvdata::{
|
||||
ControlFlagTrait, ControlFlagsTrait, FlagData, PcfV1, PlaintextControlFlagsV1, ScfV1,
|
||||
SeHdrDataV1, SecretControlFlagsV1,
|
||||
},
|
||||
use pvimg::error::OwnExitCode;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
use pvimg::uvdata::{
|
||||
ControlFlagTrait, ControlFlagsTrait, FlagData, PcfV1, PlaintextControlFlagsV1, ScfV1,
|
||||
SeHdrDataV1, SecretControlFlagsV1,
|
||||
};
|
||||
use utils::{AtomicFile, AtomicFileOperation};
|
||||
|
||||
use crate::{
|
||||
cli::{ComponentPaths, CreateBootImageArgs},
|
||||
cmd::common::read_user_provided_keys,
|
||||
se_img::{SeHdrArgs, SeImgBuilder},
|
||||
se_img_comps::{
|
||||
check_components, cmdline::Cmdline, kernel::S390Kernel, ramdisk::Ramdisk, Component,
|
||||
},
|
||||
};
|
||||
use crate::cli::{ComponentPaths, CreateBootImageArgs};
|
||||
use crate::cmd::common::read_user_provided_keys;
|
||||
use crate::se_img::{SeHdrArgs, SeImgBuilder};
|
||||
use crate::se_img_comps::cmdline::Cmdline;
|
||||
use crate::se_img_comps::kernel::S390Kernel;
|
||||
use crate::se_img_comps::ramdisk::Ramdisk;
|
||||
use crate::se_img_comps::{check_components, Component};
|
||||
|
||||
/// The returned vector is sorted by the occurrence in the memory layout:
|
||||
/// First the kernel, then the ramdisk and then the kernel cmdline.
|
||||
|
||||
@@ -6,14 +6,10 @@ use std::io::Write;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use log::{info, warn};
|
||||
use pv::{
|
||||
misc::{open_file, read_file},
|
||||
request::SymKey,
|
||||
};
|
||||
use pvimg::{
|
||||
error::{Error, OwnExitCode},
|
||||
uvdata::{EnvelopeSeHdrV1, KeyExchangeTrait, SeH, SeHdr, UvDataTrait},
|
||||
};
|
||||
use pv::misc::{open_file, read_file};
|
||||
use pv::request::SymKey;
|
||||
use pvimg::error::{Error, OwnExitCode};
|
||||
use pvimg::uvdata::{EnvelopeSeHdrV1, KeyExchangeTrait, SeH, SeHdr, UvDataTrait};
|
||||
|
||||
use crate::cli::{InfoArgs, OutputFormatKind, OutputFormatSpec, OutputFormatVariant};
|
||||
|
||||
|
||||
@@ -6,17 +6,14 @@ use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::{info, warn};
|
||||
use pv::{
|
||||
misc::{open_file, read_certs, read_file},
|
||||
FileAccessErrorType, PvCoreError,
|
||||
};
|
||||
use pvimg::{
|
||||
error::{Error, OwnExitCode, PvError},
|
||||
uvdata::{KeyExchangeTrait, SeHdr, UvKeyHashesV1},
|
||||
};
|
||||
use pv::misc::{open_file, read_certs, read_file};
|
||||
use pv::{FileAccessErrorType, PvCoreError};
|
||||
use pvimg::error::{Error, OwnExitCode, PvError};
|
||||
use pvimg::uvdata::{KeyExchangeTrait, SeHdr, UvKeyHashesV1};
|
||||
use utils::HexSlice;
|
||||
|
||||
use crate::{cli::TestArgs, log_println};
|
||||
use crate::cli::TestArgs;
|
||||
use crate::log_println;
|
||||
|
||||
/// Returns `Ok(true)` if at least one of the hashes is included.
|
||||
fn hdr_test_target_hashes(hdr: &SeHdr, key_hashes: &Path) -> Result<bool> {
|
||||
|
||||
@@ -16,7 +16,8 @@ mod cmd;
|
||||
mod se_img;
|
||||
mod se_img_comps;
|
||||
|
||||
use std::{env, process::ExitCode};
|
||||
use std::env;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use clap::{Command, CommandFactory, Parser};
|
||||
use cli::{validate_cli, CliOptions, SubCommands};
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
pub use pv::Error as PvError;
|
||||
pub use pv::PvCoreError;
|
||||
pub use pv::{Error as PvError, PvCoreError};
|
||||
use utils::{impl_exitcodetrait, ExitCodeTrait};
|
||||
|
||||
/// Result type for this crate
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
use std::{collections::BTreeSet, fmt::Display, rc::Rc};
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt::Display;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{
|
||||
misc::round_up,
|
||||
pv_utils::error::{Error, Result},
|
||||
};
|
||||
use crate::misc::round_up;
|
||||
use crate::pv_utils::error::{Error, Result};
|
||||
|
||||
/// Represents a range from [start, stop) (inclusive start, exclusive stop)
|
||||
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
|
||||
@@ -194,12 +194,11 @@ impl IntoIterator for Layout {
|
||||
#[allow(clippy::shadow_unrelated)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::BTreeSet, rc::Rc};
|
||||
use std::collections::BTreeSet;
|
||||
use std::rc::Rc;
|
||||
|
||||
use proptest::{
|
||||
prelude::{Just, Strategy},
|
||||
prop_assert, prop_assert_eq, proptest,
|
||||
};
|
||||
use proptest::prelude::{Just, Strategy};
|
||||
use proptest::{prop_assert, prop_assert_eq, proptest};
|
||||
|
||||
use crate::pv_utils::{Interval, Layout};
|
||||
|
||||
|
||||
@@ -67,10 +67,8 @@ pub fn try_copy_slice_to_array<const COUNT: usize, T: Copy + Default>(
|
||||
mod tests {
|
||||
use pv::PvCoreError;
|
||||
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
pv_utils::try_copy_slice_to_array,
|
||||
};
|
||||
use crate::error::{Error, Result};
|
||||
use crate::pv_utils::try_copy_slice_to_array;
|
||||
|
||||
#[test]
|
||||
fn test_try_copy_slice_to_array() {
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use deku::{ctx::Endian, DekuRead, DekuWrite};
|
||||
use deku::ctx::Endian;
|
||||
use deku::{DekuRead, DekuWrite};
|
||||
use pv::request::Zeroize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -81,7 +82,8 @@ impl TryFrom<PSW> for ShortPsw {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ShortPsw, PSW};
|
||||
use crate::pv_utils::{error::Result, psw::PSW_MASK_BIT_12};
|
||||
use crate::pv_utils::error::Result;
|
||||
use crate::pv_utils::psw::PSW_MASK_BIT_12;
|
||||
|
||||
#[test]
|
||||
fn test_from_psw_to_short_psw_ok() {
|
||||
|
||||
@@ -1,40 +1,31 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
use std::{
|
||||
fmt::Display,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
mem::size_of,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::io::{Read, Seek, SeekFrom};
|
||||
use std::mem::size_of;
|
||||
|
||||
use deku::{ctx::Endian, prelude::*};
|
||||
use deku::ctx::Endian;
|
||||
use deku::prelude::*;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use pv::{
|
||||
request::{
|
||||
openssl::pkey::{PKey, PKeyRef, Private, Public},
|
||||
seek_se_hdr_start, Aes256XtsKey, Confidential, SymKey, SymKeyType,
|
||||
},
|
||||
static_assert,
|
||||
};
|
||||
use pv::request::openssl::pkey::{PKey, PKeyRef, Private, Public};
|
||||
use pv::request::{seek_se_hdr_start, Aes256XtsKey, Confidential, SymKey, SymKeyType};
|
||||
use pv::static_assert;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utils::S390ToolsMetaData;
|
||||
|
||||
pub use super::hdr_v1::{SeHdrBinV1, SeHdrDataV1};
|
||||
use super::{PlaintextControlFlagsV1, SecretControlFlagsV1};
|
||||
use crate::{
|
||||
misc::PAGESIZE,
|
||||
pv_utils::{
|
||||
error::{Error, Result},
|
||||
misc::display_indented,
|
||||
serializing::{serde_hex_array, serialize_to_bytes},
|
||||
uvdata::{
|
||||
AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait,
|
||||
UvDataTrait,
|
||||
},
|
||||
uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait},
|
||||
PSW,
|
||||
},
|
||||
use crate::misc::PAGESIZE;
|
||||
use crate::pv_utils::error::{Error, Result};
|
||||
use crate::pv_utils::misc::display_indented;
|
||||
use crate::pv_utils::serializing::{serde_hex_array, serialize_to_bytes};
|
||||
use crate::pv_utils::uvdata::{
|
||||
AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait,
|
||||
UvDataTrait,
|
||||
};
|
||||
use crate::pv_utils::uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait};
|
||||
use crate::pv_utils::PSW;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
||||
@@ -4,19 +4,18 @@
|
||||
|
||||
use pv::request::Confidential;
|
||||
|
||||
use super::{hdr_v1::SeHdrDataV1, SeHdr};
|
||||
use crate::pv_utils::{
|
||||
error::{Error, Result},
|
||||
se_hdr::{
|
||||
brb::{SeHdrCommon, SeHdrConfBuilderTrait, SeHdrData, SeHdrPubBuilderTrait},
|
||||
ComponentMetadata, SeHdrPlain, SeHdrVersion,
|
||||
},
|
||||
uvdata::UvDataPlainTrait,
|
||||
uvdata_builder::{
|
||||
AeadCipherBuilderTrait, BuilderTrait, KeyExchangeBuilderTrait, UvDataBuilder,
|
||||
},
|
||||
PlaintextControlFlagsV1, SecretControlFlagsV1, PSW,
|
||||
use super::hdr_v1::SeHdrDataV1;
|
||||
use super::SeHdr;
|
||||
use crate::pv_utils::error::{Error, Result};
|
||||
use crate::pv_utils::se_hdr::brb::{
|
||||
SeHdrCommon, SeHdrConfBuilderTrait, SeHdrData, SeHdrPubBuilderTrait,
|
||||
};
|
||||
use crate::pv_utils::se_hdr::{ComponentMetadata, SeHdrPlain, SeHdrVersion};
|
||||
use crate::pv_utils::uvdata::UvDataPlainTrait;
|
||||
use crate::pv_utils::uvdata_builder::{
|
||||
AeadCipherBuilderTrait, BuilderTrait, KeyExchangeBuilderTrait, UvDataBuilder,
|
||||
};
|
||||
use crate::pv_utils::{PlaintextControlFlagsV1, SecretControlFlagsV1, PSW};
|
||||
|
||||
/// `SeHdrBuilder`
|
||||
pub type SeHdrBuilder<'a> = UvDataBuilder<'a, SeHdrPlain>;
|
||||
@@ -96,17 +95,13 @@ impl BuilderTrait for SeHdrBuilder<'_> {
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
|
||||
use pv::{
|
||||
request::{Confidential, SymKeyType, SHA_512_HASH_LEN},
|
||||
test_utils::get_test_key_and_cert,
|
||||
};
|
||||
use pv::request::{Confidential, SymKeyType, SHA_512_HASH_LEN};
|
||||
use pv::test_utils::get_test_key_and_cert;
|
||||
|
||||
use super::*;
|
||||
use crate::pv_utils::{
|
||||
se_hdr::ComponentMetadataV1,
|
||||
uvdata::{AeadDataTrait, AeadPlainDataTrait},
|
||||
UvDataTrait,
|
||||
};
|
||||
use crate::pv_utils::se_hdr::ComponentMetadataV1;
|
||||
use crate::pv_utils::uvdata::{AeadDataTrait, AeadPlainDataTrait};
|
||||
use crate::pv_utils::UvDataTrait;
|
||||
|
||||
#[test]
|
||||
fn builder_test() {
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
//! assert!(flags.is_set(PcfV1::AllowDumping));
|
||||
//! ```
|
||||
|
||||
use std::{fmt::Display, fmt::LowerHex, marker::PhantomData, mem::size_of};
|
||||
use std::fmt::{Display, LowerHex};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::size_of;
|
||||
|
||||
use pv::misc::{Flags, Msb0Flags64};
|
||||
|
||||
|
||||
@@ -1,53 +1,44 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
use std::{
|
||||
fmt::Display,
|
||||
mem::{size_of, size_of_val},
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::mem::{size_of, size_of_val};
|
||||
|
||||
use base64::prelude::*;
|
||||
use deku::{ctx::Endian, prelude::*};
|
||||
use openssl::{
|
||||
nid::Nid,
|
||||
pkey::{PKeyRef, Public},
|
||||
};
|
||||
use deku::ctx::Endian;
|
||||
use deku::prelude::*;
|
||||
use openssl::nid::Nid;
|
||||
use openssl::pkey::{PKeyRef, Public};
|
||||
use pv::request::openssl::pkey::{PKey, Private};
|
||||
use pv::request::{
|
||||
gen_ec_key,
|
||||
openssl::pkey::{PKey, Private},
|
||||
random_array, Aes256XtsKey, Confidential, EcPubKeyCoord, Encrypt, Keyslot, SymKey, SymKeyType,
|
||||
Zeroize, SHA_512_HASH_LEN,
|
||||
gen_ec_key, random_array, Aes256XtsKey, Confidential, EcPubKeyCoord, Encrypt, Keyslot, SymKey,
|
||||
SymKeyType, Zeroize, SHA_512_HASH_LEN,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utils::HexSlice;
|
||||
|
||||
use super::keys::phkh_v1;
|
||||
use crate::{
|
||||
error::Error,
|
||||
misc::PAGESIZE,
|
||||
pv_utils::{
|
||||
error::Result,
|
||||
misc::display_indented,
|
||||
se_hdr::{
|
||||
brb::{
|
||||
ComponentMetadata, ComponentMetadataV1, SeHdrCommon, SeHdrConfBuilderTrait,
|
||||
SeHdrPlainTrait, SeHdrPubBuilderTrait, SeHdrTrait,
|
||||
},
|
||||
keys::{BinaryKeySlotV1, EcPubKeyCoordV1},
|
||||
},
|
||||
serializing::{
|
||||
bytesize, bytesize_confidential, confidential_read_slice, confidential_write_slice,
|
||||
serde_base64, serde_hex_array, serde_hex_confidential_array, serde_hex_left_padded_u64,
|
||||
serialize_to_bytes,
|
||||
},
|
||||
try_copy_slice_to_array,
|
||||
uvdata::{
|
||||
AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait,
|
||||
UvDataTrait,
|
||||
},
|
||||
uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait},
|
||||
PlaintextControlFlagsV1, SecretControlFlagsV1, PSW,
|
||||
},
|
||||
use crate::error::Error;
|
||||
use crate::misc::PAGESIZE;
|
||||
use crate::pv_utils::error::Result;
|
||||
use crate::pv_utils::misc::display_indented;
|
||||
use crate::pv_utils::se_hdr::brb::{
|
||||
ComponentMetadata, ComponentMetadataV1, SeHdrCommon, SeHdrConfBuilderTrait, SeHdrPlainTrait,
|
||||
SeHdrPubBuilderTrait, SeHdrTrait,
|
||||
};
|
||||
use crate::pv_utils::se_hdr::keys::{BinaryKeySlotV1, EcPubKeyCoordV1};
|
||||
use crate::pv_utils::serializing::{
|
||||
bytesize, bytesize_confidential, confidential_read_slice, confidential_write_slice,
|
||||
serde_base64, serde_hex_array, serde_hex_confidential_array, serde_hex_left_padded_u64,
|
||||
serialize_to_bytes,
|
||||
};
|
||||
use crate::pv_utils::uvdata::{
|
||||
AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait,
|
||||
UvDataTrait,
|
||||
};
|
||||
use crate::pv_utils::uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait};
|
||||
use crate::pv_utils::{
|
||||
try_copy_slice_to_array, PlaintextControlFlagsV1, SecretControlFlagsV1, PSW,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{fmt::Display, mem::size_of};
|
||||
use std::fmt::Display;
|
||||
use std::mem::size_of;
|
||||
|
||||
use base64::prelude::*;
|
||||
use deku::{ctx::Endian, DekuRead, DekuWrite};
|
||||
use openssl::{
|
||||
hash::{hash, MessageDigest},
|
||||
pkey::{PKey, PKeyRef, Public},
|
||||
};
|
||||
use pv::{request::EcPubKeyCoord, static_assert};
|
||||
use deku::ctx::Endian;
|
||||
use deku::{DekuRead, DekuWrite};
|
||||
use openssl::hash::{hash, MessageDigest};
|
||||
use openssl::pkey::{PKey, PKeyRef, Public};
|
||||
use pv::request::EcPubKeyCoord;
|
||||
use pv::static_assert;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utils::HexSlice;
|
||||
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
pv_utils::{serializing::serde_hex_array, try_copy_slice_to_array},
|
||||
};
|
||||
use crate::error::{Error, Result};
|
||||
use crate::pv_utils::serializing::serde_hex_array;
|
||||
use crate::pv_utils::try_copy_slice_to_array;
|
||||
|
||||
/// Try to hash the public EC key.
|
||||
///
|
||||
|
||||
@@ -2,28 +2,22 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{
|
||||
fmt::{Debug, Formatter},
|
||||
io::{Read, Write},
|
||||
rc::Rc,
|
||||
};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::io::{Read, Write};
|
||||
use std::rc::Rc;
|
||||
|
||||
use log::debug;
|
||||
use openssl::{
|
||||
bn::BigNum,
|
||||
cipher::{Cipher, CipherRef},
|
||||
cipher_ctx::{CipherCtx, CipherCtxRef},
|
||||
hash::{Hasher, MessageDigest},
|
||||
nid::Nid,
|
||||
};
|
||||
use openssl::bn::BigNum;
|
||||
use openssl::cipher::{Cipher, CipherRef};
|
||||
use openssl::cipher_ctx::{CipherCtx, CipherCtxRef};
|
||||
use openssl::hash::{Hasher, MessageDigest};
|
||||
use openssl::nid::Nid;
|
||||
use pv::request::{Confidential, SymKey, SymKeyType};
|
||||
|
||||
use super::{try_copy_slice_to_array, Layout};
|
||||
use crate::pv_utils::{
|
||||
error::{Error, PvError, Result},
|
||||
se_hdr::{ComponentMetadata, ComponentMetadataV1},
|
||||
Interval,
|
||||
};
|
||||
use crate::pv_utils::error::{Error, PvError, Result};
|
||||
use crate::pv_utils::se_hdr::{ComponentMetadata, ComponentMetadataV1};
|
||||
use crate::pv_utils::Interval;
|
||||
|
||||
/// Operation mode for component preparation.
|
||||
#[allow(unused)]
|
||||
@@ -651,7 +645,8 @@ impl SecuredComponentBuilder {
|
||||
#[allow(clippy::shadow_unrelated)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fmt::Debug, io::Cursor};
|
||||
use std::fmt::Debug;
|
||||
use std::io::Cursor;
|
||||
|
||||
use pv::request::Aes256XtsKey;
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use deku::{
|
||||
reader::Reader, writer::Writer, DekuContainerRead, DekuContainerWrite, DekuError, DekuReader,
|
||||
DekuWriter,
|
||||
};
|
||||
use deku::reader::Reader;
|
||||
use deku::writer::Writer;
|
||||
use deku::{DekuContainerRead, DekuContainerWrite, DekuError, DekuReader, DekuWriter};
|
||||
use pv::request::{Confidential, Zeroize};
|
||||
|
||||
use crate::pv_utils::error::Result;
|
||||
@@ -13,8 +12,7 @@ use crate::pv_utils::error::Result;
|
||||
pub mod serde_hex_left_padded_u64 {
|
||||
use std::fmt::LowerHex;
|
||||
|
||||
use serde::Deserializer;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn serialize<S: Serializer, B: LowerHex>(
|
||||
data: &B,
|
||||
@@ -219,7 +217,8 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use deku::{ctx::Endian, DekuContainerWrite, DekuRead, DekuWrite};
|
||||
use deku::ctx::Endian;
|
||||
use deku::{DekuContainerWrite, DekuRead, DekuWrite};
|
||||
use pv::request::Confidential;
|
||||
|
||||
use crate::pv_utils::serializing::{confidential_read_slice, confidential_write_slice};
|
||||
|
||||
@@ -119,7 +119,8 @@ mod tests {
|
||||
|
||||
use pv::misc::decode_hex;
|
||||
|
||||
use crate::{pv_utils::uv_keys::UvKeyHashV1, uvdata::UvKeyHashesV1};
|
||||
use crate::pv_utils::uv_keys::UvKeyHashV1;
|
||||
use crate::uvdata::UvKeyHashesV1;
|
||||
|
||||
#[test]
|
||||
fn from_reader() {
|
||||
|
||||
@@ -3,17 +3,14 @@
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use pv::request::openssl::pkey::{PKey, PKeyRef, Private, Public};
|
||||
use pv::request::{
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead,
|
||||
openssl::pkey::{PKey, PKeyRef, Private, Public},
|
||||
Confidential, SymKey, SymKeyType,
|
||||
decrypt_aead, derive_aes256_gcm_key, encrypt_aead, Confidential, SymKey, SymKeyType,
|
||||
};
|
||||
|
||||
use super::se_hdr::{SeHdrBinV1, SeHdrData, SeHdrVersioned};
|
||||
use crate::pv_utils::{
|
||||
error::{Error, Result},
|
||||
serializing::deserialize_from_bytes,
|
||||
};
|
||||
use crate::pv_utils::error::{Error, Result};
|
||||
use crate::pv_utils::serializing::deserialize_from_bytes;
|
||||
|
||||
/// Trait to be used for Authenticated Encryption with Associated Data (AEAD)
|
||||
/// data structures.
|
||||
|
||||
@@ -7,11 +7,9 @@ use openssl::pkey::{PKey, PKeyRef, Private, Public};
|
||||
use pv::request::{Confidential, SymKey};
|
||||
|
||||
use super::Error;
|
||||
use crate::pv_utils::{
|
||||
error::Result,
|
||||
se_hdr::SeHdrData,
|
||||
uvdata::{AeadCipherTrait, UvDataPlainTrait},
|
||||
};
|
||||
use crate::pv_utils::error::Result;
|
||||
use crate::pv_utils::se_hdr::SeHdrData;
|
||||
use crate::pv_utils::uvdata::{AeadCipherTrait, UvDataPlainTrait};
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait AeadCipherBuilderTrait: AeadCipherTrait {
|
||||
|
||||
@@ -2,31 +2,34 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{
|
||||
fmt::Display,
|
||||
io::{Cursor, Seek, SeekFrom, Write},
|
||||
path::PathBuf,
|
||||
rc::Rc,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::io::{Cursor, Seek, SeekFrom, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use deku::DekuContainerRead;
|
||||
use log::debug;
|
||||
use openssl::pkey::{PKey, Public};
|
||||
use pv::{misc::read_file, request::Confidential};
|
||||
use pvimg::{
|
||||
error::Error,
|
||||
misc::{round_up, serialize_to_bytes, ShortPsw, PSW, PSW_MASK_BA, PSW_MASK_EA},
|
||||
secured_comp::{ComponentTrait, Interval, Layout, SecuredComponent, SecuredComponentBuilder},
|
||||
uvdata::{
|
||||
BuilderTrait, PlaintextControlFlagsV1, SeHdrBuilder, SeHdrVersion, SecretControlFlagsV1,
|
||||
},
|
||||
use pv::misc::read_file;
|
||||
use pv::request::Confidential;
|
||||
use pvimg::error::Error;
|
||||
use pvimg::misc::{round_up, serialize_to_bytes, ShortPsw, PSW, PSW_MASK_BA, PSW_MASK_EA};
|
||||
use pvimg::secured_comp::{
|
||||
ComponentTrait, Interval, Layout, SecuredComponent, SecuredComponentBuilder,
|
||||
};
|
||||
use pvimg::uvdata::{
|
||||
BuilderTrait, PlaintextControlFlagsV1, SeHdrBuilder, SeHdrVersion, SecretControlFlagsV1,
|
||||
};
|
||||
|
||||
use crate::se_img_comps::ipib::Ipib;
|
||||
use crate::se_img_comps::kernel::S390Kernel;
|
||||
use crate::se_img_comps::metadata::ImgMetaData;
|
||||
use crate::se_img_comps::sehdr::SeHdrComp;
|
||||
use crate::se_img_comps::shortpsw::ShortPSWComp;
|
||||
use crate::se_img_comps::{
|
||||
create_ipib, ipib::Ipib, kernel::S390Kernel, metadata::ImgMetaData, render_stage3a,
|
||||
render_stage3b, sehdr::SeHdrComp, shortpsw::ShortPSWComp, stage3a_path, stage3b_path,
|
||||
CompTweakV1, Component, ComponentKind, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS,
|
||||
create_ipib, render_stage3a, render_stage3b, stage3a_path, stage3b_path, CompTweakV1,
|
||||
Component, ComponentKind, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS,
|
||||
};
|
||||
|
||||
pub struct SeHdrArgs<'a> {
|
||||
@@ -482,7 +485,8 @@ mod tests {
|
||||
use std::io::Cursor;
|
||||
|
||||
use super::SeImgBuilder;
|
||||
use crate::{se_img::stage3a_path, se_img_comps::stage3b_path};
|
||||
use crate::se_img::stage3a_path;
|
||||
use crate::se_img_comps::stage3b_path;
|
||||
|
||||
#[test]
|
||||
fn test_comp_ctx_new() {
|
||||
|
||||
@@ -2,21 +2,25 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{
|
||||
fmt::{Debug, Display},
|
||||
io::{Read, Seek, SeekFrom},
|
||||
};
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::io::{Read, Seek, SeekFrom};
|
||||
|
||||
use anyhow::Context;
|
||||
use deku::{ctx::Endian, DekuRead, DekuWrite};
|
||||
use deku::ctx::Endian;
|
||||
use deku::{DekuRead, DekuWrite};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use pv::request::random_array;
|
||||
use pvimg::{error::Result, secured_comp::ComponentTrait};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use self::{
|
||||
cmdline::Cmdline, kernel::S390Kernel, metadata::ImgMetaData, ramdisk::Ramdisk,
|
||||
sehdr::SeHdrComp, shortpsw::ShortPSWComp, stage3a::Stage3a, stage3b::Stage3b,
|
||||
};
|
||||
use self::cmdline::Cmdline;
|
||||
use self::kernel::S390Kernel;
|
||||
use self::metadata::ImgMetaData;
|
||||
use self::ramdisk::Ramdisk;
|
||||
use self::sehdr::SeHdrComp;
|
||||
use self::shortpsw::ShortPSWComp;
|
||||
use self::stage3a::Stage3a;
|
||||
use self::stage3b::Stage3b;
|
||||
pub use crate::se_img_comps::bootloader::{
|
||||
create_ipib, render_stage3a, render_stage3b, stage3a_path, stage3b_path, STAGE3A_ENTRY,
|
||||
STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS,
|
||||
@@ -306,13 +310,12 @@ impl CompTweakV1 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use deku::{DekuContainerRead, DekuContainerWrite};
|
||||
use proptest::{
|
||||
prelude::{Just, Strategy},
|
||||
prop_assert_eq, prop_oneof, proptest,
|
||||
};
|
||||
use proptest::prelude::{Just, Strategy};
|
||||
use proptest::{prop_assert_eq, prop_oneof, proptest};
|
||||
|
||||
use super::{ComponentCheckCtx, ComponentKind};
|
||||
use crate::se_img_comps::{check_components, kernel::S390Kernel, CompTweakPrefV1, CompTweakV1};
|
||||
use crate::se_img_comps::kernel::S390Kernel;
|
||||
use crate::se_img_comps::{check_components, CompTweakPrefV1, CompTweakV1};
|
||||
|
||||
fn component_kind_strategy() -> impl Strategy<Value = ComponentKind> {
|
||||
prop_oneof![
|
||||
|
||||
@@ -2,36 +2,33 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use std::{io::Cursor, path::PathBuf, rc::Rc};
|
||||
use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub mod ipl;
|
||||
mod stage3a_defs;
|
||||
mod stage3b_defs;
|
||||
use ipl::IPL_PARM_BLOCK_PV_VERSION;
|
||||
use log::trace;
|
||||
use pvimg::{
|
||||
error::{Error, Result},
|
||||
misc::{serialize_to_bytes, PSW},
|
||||
secured_comp::Interval,
|
||||
};
|
||||
use pvimg::error::{Error, Result};
|
||||
use pvimg::misc::{serialize_to_bytes, PSW};
|
||||
use pvimg::secured_comp::Interval;
|
||||
|
||||
use self::ipl::{
|
||||
ipl_parameter_block, ipl_pb0_pv, ipl_pb0_pv_comp, ipl_pbt_IPL_PBT_PV, ipl_pl_hdr,
|
||||
IPL_PARM_BLOCK_VERSION,
|
||||
};
|
||||
pub use self::stage3a_defs::{
|
||||
STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS,
|
||||
};
|
||||
use self::{
|
||||
ipl::{
|
||||
ipl_parameter_block, ipl_pb0_pv, ipl_pb0_pv_comp, ipl_pbt_IPL_PBT_PV, ipl_pl_hdr,
|
||||
IPL_PARM_BLOCK_VERSION,
|
||||
},
|
||||
stage3b_defs::{memblob, stage3b_args},
|
||||
};
|
||||
use self::stage3b_defs::{memblob, stage3b_args};
|
||||
use super::CompTweakPrefV1;
|
||||
use crate::{
|
||||
se_img::ImgComponent,
|
||||
se_img_comps::{
|
||||
bootloader::stage3a_defs::stage3a_args, stage3a::Stage3a, stage3b::Stage3b, ComponentKind,
|
||||
},
|
||||
};
|
||||
use crate::se_img::ImgComponent;
|
||||
use crate::se_img_comps::bootloader::stage3a_defs::stage3a_args;
|
||||
use crate::se_img_comps::stage3a::Stage3a;
|
||||
use crate::se_img_comps::stage3b::Stage3b;
|
||||
use crate::se_img_comps::ComponentKind;
|
||||
|
||||
/// Get the `PVIMG_PKGDATADIR` used for `pvimg`
|
||||
///
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
// Based on the output of rust-bindgen 0.69.1
|
||||
#![allow(nonstandard_style, unused)]
|
||||
|
||||
use deku::{ctx::Endian, prelude::*};
|
||||
use pvimg::{error::Result, misc::bytesize};
|
||||
use deku::ctx::Endian;
|
||||
use deku::prelude::*;
|
||||
use pvimg::error::Result;
|
||||
use pvimg::misc::bytesize;
|
||||
|
||||
pub const IPL_FLAG_SECURE: u32 = 64;
|
||||
pub const IPL_RB_COMPONENT_FLAG_SIGNED: u32 = 128;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
// Based on the output of rust-bindgen 0.69.1
|
||||
#![allow(nonstandard_style)]
|
||||
use deku::{ctx::Endian, prelude::*};
|
||||
use deku::ctx::Endian;
|
||||
use deku::prelude::*;
|
||||
|
||||
pub const IMAGE_ENTRY: u64 = 0x10000;
|
||||
pub const STAGE3A_INIT_ENTRY: u64 = IMAGE_ENTRY;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
// Based on the output of rust-bindgen 0.69.1
|
||||
#![allow(non_camel_case_types, non_snake_case, nonstandard_style)]
|
||||
use deku::{ctx::Endian, prelude::*};
|
||||
use deku::ctx::Endian;
|
||||
use deku::prelude::*;
|
||||
use pvimg::misc::PSW;
|
||||
|
||||
#[derive(Debug, Default, Clone, DekuRead, DekuWrite)]
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::io::{Read, Seek};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ipib(CompReader);
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
use std::io::{Cursor, Read, Seek};
|
||||
|
||||
use pv::{request::SeImgMetaData, static_assert};
|
||||
use pv::request::SeImgMetaData;
|
||||
use pv::static_assert;
|
||||
use pvimg::error::Result;
|
||||
|
||||
use super::{
|
||||
bootloader::{STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE},
|
||||
CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait,
|
||||
};
|
||||
use super::bootloader::{STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ImgMetaData(CompReader);
|
||||
|
||||
@@ -6,8 +6,10 @@ use std::io::{Read, Seek};
|
||||
|
||||
use pvimg::error::Result;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentTrait, ReadSeekDebug};
|
||||
use super::{
|
||||
CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait,
|
||||
ReadSeekDebug,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ramdisk(CompReader);
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::io::{Read, Seek};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SeHdrComp(pub CompReader);
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::io::{Read, Seek};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ShortPSWComp(CompReader);
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::io::{Read, Seek};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Stage3a(CompReader);
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::io::{Read, Seek};
|
||||
use pvimg::error::Result;
|
||||
use pvimg::secured_comp::ComponentTrait;
|
||||
|
||||
use super::ComponentKind;
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug};
|
||||
use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Stage3b(CompReader);
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
// it under the terms of the MIT license. See LICENSE for details.
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use std::env;
|
||||
use std::io::Error;
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate_to, Shell};
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
|
||||
//! Handlers for processing CLI flags and subcommands
|
||||
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::io_utils::{collect_bit_messages, collect_version_flags, read_hex_from_file};
|
||||
use crate::strings::*;
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// Represents metadata for a supported content file.
|
||||
struct Content {
|
||||
@@ -18,7 +19,7 @@ struct Content {
|
||||
}
|
||||
|
||||
impl Content {
|
||||
//Reads a hex file, then prints either:
|
||||
// Reads a hex file, then prints either:
|
||||
// bit messages or version flags
|
||||
fn handle_flag(&self, writer: &mut dyn Write, query_dir: &Path) -> io::Result<String> {
|
||||
let hex = match read_hex_from_file(query_dir.join(self.file), self.label) {
|
||||
@@ -132,10 +133,12 @@ pub fn handle_supported_flags(
|
||||
// Unit Tests for handlers
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::*;
|
||||
|
||||
// Verifies that handle_supported_flags correctly processes all
|
||||
#[test]
|
||||
fn test_handle_supported_flags_with_buffer() {
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
//! I/O utilities for the PV Info Tool
|
||||
|
||||
use crate::constants::*;
|
||||
use anyhow::{Context, Result};
|
||||
use pv_core::misc::{read_file, read_file_string, try_parse_u64};
|
||||
use pv_core::misc::{Flags, Msb0Flags64};
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::str;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use pv_core::misc::{read_file, read_file_string, try_parse_u64, Flags, Msb0Flags64};
|
||||
|
||||
use crate::constants::*;
|
||||
|
||||
// Verify that the Ultravisor directory exists
|
||||
pub fn check_uv_exists() -> Result<()> {
|
||||
let uv_path = Path::new(BASE_DIR);
|
||||
@@ -143,11 +144,13 @@ pub fn collect_limits(query_dir: &Path) -> HashMap<String, u64> {
|
||||
mod test {
|
||||
//! Unit Tests for io_utils
|
||||
|
||||
use super::*;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use tempfile::{tempdir, NamedTempFile};
|
||||
|
||||
use super::*;
|
||||
|
||||
// Tests check_uv_exists() by observing the real BASE_DIR at test runtime
|
||||
// if BASE_DIR exists on the machine running the tests, check_uv_exists() must return Ok
|
||||
// otherwise, it must return Err(anyhow::Error) whose cause is an io::ErrorKind::NotFound,
|
||||
@@ -280,7 +283,8 @@ mod test {
|
||||
let hex = (1u64 << 63) | (1u64 << 61);
|
||||
let messages = collect_bit_messages(hex, desc);
|
||||
|
||||
// Expect "First Feature" and "Third Feature" (and the reserved line should get the " Bit-<index>" if matched)
|
||||
// Expect "First Feature" and "Third Feature" (and the reserved line should get the "
|
||||
// Bit-<index>" if matched)
|
||||
assert!(messages.iter().any(|m| m == "First Feature"));
|
||||
assert!(messages.iter().any(|m| m == "Third Feature"));
|
||||
// reserved wasn't set here; now test reserved specifically below
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user