diff --git a/ultimates/ultimate-common/src/string.rs b/ultimates/ultimate-common/src/string.rs index b2ddc25..9829995 100644 --- a/ultimates/ultimate-common/src/string.rs +++ b/ultimates/ultimate-common/src/string.rs @@ -65,7 +65,7 @@ pub fn ser_vecu8_to_str(v: &[u8], s: S) -> core::result::Result Result { + pub fn load() -> Result { let c = load_config()?; let ultimate_config = UltimateConfig::try_from(&c)?; Ok(Self::new(Arc::new(c), Arc::new(ultimate_config))) diff --git a/ultimates/ultimate/src/configuration/model/security_config.rs b/ultimates/ultimate/src/configuration/model/security_config.rs index 65311cd..2db84c6 100644 --- a/ultimates/ultimate/src/configuration/model/security_config.rs +++ b/ultimates/ultimate/src/configuration/model/security_config.rs @@ -72,10 +72,10 @@ pub struct TokenConf { pub(crate) expires_in: i64, #[serde(deserialize_with = "deser_str_to_vecu8", serialize_with = "ser_vecu8_to_str")] - public_key: Vec, + pub(crate) public_key: Vec, #[serde(deserialize_with = "deser_str_to_vecu8", serialize_with = "ser_vecu8_to_str")] - private_key: Vec, + pub(crate) private_key: Vec, } impl TokenConf { diff --git a/ultimates/ultimate/src/security/jose.rs b/ultimates/ultimate/src/security/jose.rs index f1fa31d..6454c6b 100644 --- a/ultimates/ultimate/src/security/jose.rs +++ b/ultimates/ultimate/src/security/jose.rs @@ -79,19 +79,15 @@ pub fn decode_jwt_hs256( #[cfg(test)] mod tests { - use std::{ - sync::OnceLock, - time::{Duration, SystemTime}, - }; - - use ultimate_common::string; - + use super::*; use crate::configuration::{ load_config, model::{KeyConf, SecruityConfig}, }; - - use super::*; + use std::{ + sync::OnceLock, + time::{Duration, SystemTime}, + }; #[test] fn test_jwe_ecdh_es() -> anyhow::Result<()> { @@ -116,19 +112,19 @@ mod tests { #[test] fn test_jwe_dir() -> anyhow::Result<()> { - let (sc, expires_at) = helper(); + let secret_key = b"0123456789ABCDEF0123456789ABCDEF"; + let expires_at = SystemTime::now() + Duration::from_secs(60 * 60 * 24); let mut jwt_payload = JwtPayload::new(); jwt_payload.set_subject("subject"); - jwt_payload.set_expires_at(expires_at); + jwt_payload.set_expires_at(&expires_at); // Encrypting JWT - println!("secret key is {}", string::b64u_encode(sc.token().secret_key())); - let jwt = encrypt_jwe_dir(sc.token().secret_key(), &jwt_payload).unwrap(); + let jwt = encrypt_jwe_dir(secret_key, &jwt_payload).unwrap(); println!("Encrypting JWT with DIR signre is: {}", jwt); // Decrypting JWT - let (payload, header) = decrypt_jwe_dir(sc.token().secret_key(), jwt).unwrap(); + let (payload, header) = decrypt_jwe_dir(secret_key, jwt).unwrap(); println!("Encrypting JWT with DIR JwsHeader is: {:?}", header); println!("Encrypting JWT with DIR JwtPayload is: {:?}", payload);