Add support for Aes key management in tests

This commit is contained in:
Sosthène Guédon
2024-03-01 14:29:40 +01:00
committed by Nicolas Stalder
parent 2ef4a7db4a
commit b38ae6a654
3 changed files with 10 additions and 3 deletions
+1
View File
@@ -41,6 +41,7 @@ hex = "0.4"
test-log = "0.2"
ron = "0.8"
des = "0.8"
aes = "0.8.2"
[features]
+4 -2
View File
@@ -9,7 +9,7 @@ use trussed::{
api::reply::Metadata,
config::MAX_MESSAGE_LENGTH,
syscall, try_syscall,
types::{KeyId, Location, Mechanism, PathBuf},
types::{KeyId, KeySerialization, Location, Mechanism, PathBuf},
};
use crate::constants::*;
@@ -455,9 +455,11 @@ impl Persistent {
pub fn initialize(client: &mut impl trussed::Client) -> Self {
info!("initializing PIV state");
let management_key = ManagementKey {
id: syscall!(client.unsafe_inject_shared_key(
id: syscall!(client.unsafe_inject_key(
YUBICO_DEFAULT_MANAGEMENT_KEY_ALG.mechanism(),
YUBICO_DEFAULT_MANAGEMENT_KEY,
trussed::types::Location::Internal,
KeySerialization::Raw
))
.key,
alg: YUBICO_DEFAULT_MANAGEMENT_KEY_ALG,
+5 -1
View File
@@ -6,6 +6,7 @@ mod setup;
use std::borrow::Cow;
use aes::Aes256Enc;
use hex_literal::hex;
use serde::Deserialize;
use trussed::types::GenericArray;
@@ -348,7 +349,10 @@ impl IoCmd {
let cipher = TdesEde3::new(GenericArray::from_slice(&key));
cipher.encrypt_block(GenericArray::from_mut_slice(challenge));
}
Algorithm::Aes256 => todo!(),
Algorithm::Aes256 => {
let cipher = Aes256Enc::new(GenericArray::from_slice(&key));
cipher.encrypt_block(GenericArray::from_mut_slice(challenge));
}
_ => panic!(),
}
let second_data = tlv(&[0x7C], &tlv(&[0x82], challenge));