From 8d0c62025787b9ad8f1dba55a59fb1483d8b412f Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 11 Nov 2024 14:14:15 +0000 Subject: [PATCH] rust/pv: Add `get_test_key_and_cert` Useful for tests that also check the host-key document. Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Signed-off-by: Steffen Eiden --- rust/pv/src/test_utils.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rust/pv/src/test_utils.rs b/rust/pv/src/test_utils.rs index ef7874e9..072fe6d8 100644 --- a/rust/pv/src/test_utils.rs +++ b/rust/pv/src/test_utils.rs @@ -4,6 +4,11 @@ // 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 openssl::{ bn::BigNum, ec::{EcGroup, EcKey}, @@ -12,10 +17,6 @@ use openssl::{ pkey::{PKey, Private, Public}, x509::{X509Crl, X509}, }; -use std::{ - fs, - path::{Path, PathBuf}, -}; /// TEST ONLY! Loads the specified asset into the binary at compile time. /// @@ -71,11 +72,11 @@ pub fn load_gen_crl>(asset_path: P) -> X509Crl { .unwrap() } -/// TEST ONLY! Get a fixed private/public pair and a fixed public key +/// TEST ONLY! Get a fixed private/public pair and a fixed host-key document /// /// Intended for TESTING only. All parts of the key including the private key are checked in git and /// visible for the public -pub fn get_test_keys() -> (PKey, PKey) { +pub fn get_test_key_and_cert() -> (PKey, X509) { let pub_key = get_test_asset!("keys/public_cust.bin"); let priv_key = get_test_asset!("keys/private_cust.bin"); let host_key = get_test_asset!("keys/host.pem.crt"); @@ -84,11 +85,20 @@ pub fn get_test_keys() -> (PKey, PKey) { assert_eq!(priv_key.len(), 80); let cust_key = get_keypair(pub_key, priv_key).unwrap(); - let host_key = X509::from_pem(host_key).unwrap().public_key().unwrap(); + let host_key = X509::from_pem(host_key).unwrap(); (cust_key, host_key) } +/// TEST ONLY! Get a fixed private/public pair and a fixed public key +/// +/// Intended for TESTING only. All parts of the key including the private key are checked in git and +/// visible for the public +pub fn get_test_keys() -> (PKey, PKey) { + let (cust_key, host) = get_test_key_and_cert(); + (cust_key, host.public_key().unwrap()) +} + fn read_ecdh_pubkey(coords: &[u8]) -> Result, ErrorStack> { assert!(coords.len() == 160); let x = BigNum::from_slice(&coords[..80])?;