mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Improve code formatting
Do some formatting that are in experimental stage but improve the code readability. Use rustfmt with a nightly toolchain and enable: format_code_in_doc_comments = true reorder_impl_items = true comment_width = 100 wrap_comments = true normalize_comments = true (see .rustfmt.toml) Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
+1
-2
@@ -177,7 +177,6 @@ impl ReqEncrCtx {
|
||||
/// | Request type dependent AAD data |
|
||||
/// |-------------------------------------------------------------|
|
||||
/// ```
|
||||
///
|
||||
pub fn build_aad<O>(
|
||||
&self,
|
||||
version: RequestVersion,
|
||||
@@ -571,7 +570,7 @@ mod tests {
|
||||
let hdr_bin_exp = [
|
||||
0x12, 0x34, 0x56, 0x89, 0xab, 0xcd, 0xef, 0, // magic
|
||||
0, 0, 2, 0, // vers
|
||||
0, 0, 0x12, 0x34, //size
|
||||
0, 0, 0x12, 0x34, // size
|
||||
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, // iv
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // res
|
||||
15, // nks
|
||||
|
||||
@@ -111,7 +111,7 @@ impl From<AddSecretVersion> for RequestVersion {
|
||||
/// An ASRCB wraps a secret to securely transport it to the Ultravisor.
|
||||
///
|
||||
/// Layout:
|
||||
///```none
|
||||
/// ```none
|
||||
/// _______________________________________________________________
|
||||
/// | generic header (48)
|
||||
/// | --------------------------------------------------- |
|
||||
@@ -130,7 +130,7 @@ impl From<AddSecretVersion> for RequestVersion {
|
||||
/// | --------------------------------------------------- |
|
||||
/// | AES GCM Tag (16) |
|
||||
/// |_____________________________________________________________|
|
||||
///```
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
pub struct AddSecretRequest {
|
||||
version: AddSecretVersion,
|
||||
@@ -148,7 +148,6 @@ impl AddSecretRequest {
|
||||
///
|
||||
/// The request has no extension secret, no configuration UID, no host-keys,
|
||||
/// and no user data
|
||||
///
|
||||
pub fn new(
|
||||
version: AddSecretVersion,
|
||||
secret: GuestSecret,
|
||||
@@ -207,7 +206,8 @@ impl AddSecretRequest {
|
||||
/// - RSA 2048 bit (up to 256 byte message)
|
||||
/// - RSA 3072 bit (up to 128 byte message)
|
||||
///
|
||||
/// The signature can be verified during the verification of the secret-request on the target machine.
|
||||
/// The signature can be verified during the verification of the secret-request on the target
|
||||
/// machine.
|
||||
pub fn set_user_data<T: Into<Vec<u8>>>(
|
||||
&mut self,
|
||||
msg: T,
|
||||
@@ -258,7 +258,7 @@ impl AddSecretRequest {
|
||||
/// Encrypts data, sign request with user-provided signing key, insert signature into aad,
|
||||
/// calculate request tag
|
||||
fn encrypt_with_signed_user_data(&self, ctx: &ReqEncrCtx) -> Result<Vec<u8>> {
|
||||
//encrypt data w/o aead
|
||||
// encrypt data w/o aead
|
||||
let conf = self.conf.to_bytes();
|
||||
let aad = self.aad(ctx, conf.value().len())?;
|
||||
let AesGcmResult {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#[allow(unused_imports)] //used for more convenient docstring
|
||||
#[allow(unused_imports)] // used for more convenient docstring
|
||||
use super::asrcb::AddSecretRequest;
|
||||
use crate::assert_size;
|
||||
use crate::{
|
||||
@@ -74,11 +74,12 @@ impl GuestSecret {
|
||||
GuestSecret::Association { secret, .. } => secret.value().as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the non-confidential part of the secret ad-hoc
|
||||
pub(crate) fn auth(&self) -> SecretAuth {
|
||||
match &self {
|
||||
GuestSecret::Null => SecretAuth::Null,
|
||||
//Panic: every non null secret type is listable -> no panic
|
||||
// Panic: every non null secret type is listable -> no panic
|
||||
listable => {
|
||||
SecretAuth::Listable(ListableSecretHdr::from_guest_secret(listable).unwrap())
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ impl UserData {
|
||||
let magic: AddSecretMagic = self.data_type().into();
|
||||
magic.get()
|
||||
}
|
||||
|
||||
/// Creates new user data
|
||||
///
|
||||
/// Verifies that the provided data + signature fits into 512 bytes
|
||||
@@ -264,7 +265,7 @@ pub fn verify_asrcb_and_get_user_data(
|
||||
return Err(Error::BinAsrcbInvVersion);
|
||||
}
|
||||
|
||||
//preventing the two lines after the truncate from panicking
|
||||
// preventing the two lines after the truncate from panicking
|
||||
let req_len = req.len();
|
||||
if asrcb.len() < req_len
|
||||
|| req_len < AddSecretRequest::V1_USER_DATA_OFFS + UserData::USER_DATA_SIZE
|
||||
@@ -353,7 +354,7 @@ impl VerifiedUserData {
|
||||
UserDataType::Unsigned => unreachable!(),
|
||||
};
|
||||
|
||||
//overwrite signature field with zeros
|
||||
// overwrite signature field with zeros
|
||||
sgn.fill(0);
|
||||
ret
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ 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
|
||||
/// for details).
|
||||
///
|
||||
const SECURITY_LEVEL: usize = 2;
|
||||
const SECURITY_BITS_ARRAY: [u32; 6] = [0, 80, 112, 128, 192, 256];
|
||||
const SECURITY_BITS: u32 = SECURITY_BITS_ARRAY[SECURITY_LEVEL];
|
||||
@@ -44,8 +43,8 @@ pub fn verify_hkd_options(hkd: &X509Ref, sign_key: &X509Ref) -> Result<()> {
|
||||
if SECURITY_BITS > 0 && SECURITY_BITS > security_bits {
|
||||
return Err(Error::HkdVerify(SecurityBits(security_bits, SECURITY_BITS)));
|
||||
}
|
||||
// TODO rust-openssl fix X509::not.after/before() impl to return Option& not panic on nullptr from C?
|
||||
// try_... rust-openssl
|
||||
// TODO rust-openssl fix X509::not.after/before() impl to return Option& not panic on nullptr
|
||||
// from C? try_... rust-openssl
|
||||
// verify that the HKD is still valid
|
||||
check_validity_period(hkd.not_before(), hkd.not_after())?;
|
||||
|
||||
@@ -183,7 +182,7 @@ pub fn extract_ibm_sign_key(certs: Vec<X509>) -> Result<(X509, Stack<X509>)> {
|
||||
}
|
||||
|
||||
// Name Entry values of an IBM Z key signing cert
|
||||
//Asn1StringRef::as_slice aka ASN1_STRING_get0_data gives a string without \0 delimiter
|
||||
// Asn1StringRef::as_slice aka ASN1_STRING_get0_data gives a string without \0 delimiter
|
||||
const IBM_Z_COMMON_NAME: &[u8; 43usize] = b"International Business Machines Corporation";
|
||||
const IBM_Z_COUNTRY_NAME: &[u8; 2usize] = b"US";
|
||||
const IBM_Z_LOCALITY_NAME_POUGHKEEPSIE: &[u8; 12usize] = b"Poughkeepsie";
|
||||
@@ -274,7 +273,7 @@ fn load_crl_to_store<P: AsRef<Path>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///Run through the forest of the distribution points and find them
|
||||
/// Run through the forest of the distribution points and find them
|
||||
pub fn x509_dist_points(cert: &X509Ref) -> Vec<String> {
|
||||
let mut res = Vec::<String>::with_capacity(1);
|
||||
let dps = match cert.crl_distribution_points() {
|
||||
@@ -303,8 +302,8 @@ pub fn x509_dist_points(cert: &X509Ref) -> Vec<String> {
|
||||
/// Searches for CRL Distribution points and downloads the CRL. Stops after the first successful
|
||||
/// download.
|
||||
///
|
||||
/// Error if something bad(=unexpected) happens (not bad: CRL not available at link, unexpected format)
|
||||
/// Other issues are mapped to Ok(None)
|
||||
/// Error if something bad(=unexpected) happens (not bad: CRL not available at link, unexpected
|
||||
/// format) Other issues 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;
|
||||
@@ -359,10 +358,8 @@ const NIDS_CORRECT_ORDER: [Nid; 6] = [
|
||||
Nid::STATEORPROVINCENAME,
|
||||
Nid::COMMONNAME,
|
||||
];
|
||||
/**
|
||||
* Workaround to fix the mismatch between issuer name of the
|
||||
* IBM Z signing CRLs and the IBM Z signing key subject name.
|
||||
*/
|
||||
/// Workaround to fix the mismatch between issuer name of the
|
||||
/// IBM Z signing CRLs and the IBM Z signing key subject name.
|
||||
pub fn reorder_x509_names(subject: &X509NameRef) -> std::result::Result<X509Name, ErrorStack> {
|
||||
let mut correct_subj = X509Name::builder()?;
|
||||
for nid in NIDS_CORRECT_ORDER {
|
||||
@@ -373,11 +370,9 @@ pub fn reorder_x509_names(subject: &X509NameRef) -> std::result::Result<X509Name
|
||||
Ok(correct_subj.build())
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for potential locality mismatches between CRLs and Certs
|
||||
* # Return
|
||||
* fixed subject or none if locality was not Armonk or any OpenSSL error
|
||||
*/
|
||||
/// Workaround for potential locality mismatches between CRLs and Certs
|
||||
/// # Return
|
||||
/// fixed subject or none if locality was not Armonk or any OpenSSL error
|
||||
pub fn armonk_locality_fixup(subject: &X509NameRef) -> Option<X509Name> {
|
||||
if !name_data_eq(subject, Nid::LOCALITYNAME, IBM_Z_LOCALITY_NAME_ARMONK) {
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user