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:
Marc Hartmayer
2026-05-11 14:43:53 +02:00
committed by Jan Höppner
parent 3d5f75d6c3
commit f8fb9ce32a
120 changed files with 825 additions and 900 deletions
+3 -4
View File
@@ -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};
+19 -15
View File
@@ -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() {
+21 -31
View File
@@ -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 -3
View File
@@ -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() {
+4 -2
View File
@@ -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);
+6 -9
View File
@@ -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);
+10 -9
View File
@@ -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
+15 -18
View File
@@ -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();
+8 -12
View File
@@ -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.
///
+3 -4
View File
@@ -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.
///
+3 -4
View File
@@ -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;
+14 -20
View File
@@ -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];
+12 -10
View File
@@ -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];
+15 -16
View File
@@ -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)]
+20 -26
View File
@@ -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];
+14 -13
View File
@@ -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,
+9 -12
View File
@@ -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() {
+7 -6
View File
@@ -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
///
+24 -20
View File
@@ -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
+8 -3
View File
@@ -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>>> {