Skip to content

Commit 1f19ed7

Browse files
Use simple algorithm specifiers in certification_keys object (#1140)
Update key_algorithm reporting in the certification_keys object to use simple specifiers ("rsa" or "ecc") instead of full algorithm names ("rsa2048", "ecc256", etc.) to comply with the push model protocol specification. This is not an issue for algorithm identification because the certification_keys object also includes the key_size field, allowing complete identification of the exact algorithm in use. Signed-off-by: Sergio Correia <[email protected]>
1 parent 672bc1b commit 1f19ed7

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

keylime/src/algorithms.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@ pub fn get_key_size(tpm_encryption_alg: &EncryptionAlgorithm) -> usize {
185185
}
186186
}
187187

188+
pub fn get_key_algorithm_family(
189+
tpm_encryption_alg: &EncryptionAlgorithm,
190+
) -> &'static str {
191+
match tpm_encryption_alg {
192+
EncryptionAlgorithm::Rsa1024
193+
| EncryptionAlgorithm::Rsa2048
194+
| EncryptionAlgorithm::Rsa3072
195+
| EncryptionAlgorithm::Rsa4096 => "rsa",
196+
EncryptionAlgorithm::Ecc192
197+
| EncryptionAlgorithm::Ecc224
198+
| EncryptionAlgorithm::Ecc256
199+
| EncryptionAlgorithm::Ecc384
200+
| EncryptionAlgorithm::Ecc521
201+
| EncryptionAlgorithm::EccSm2 => "ecc",
202+
}
203+
}
204+
188205
impl From<EncryptionAlgorithm> for AsymmetricAlgorithm {
189206
fn from(enc_alg: EncryptionAlgorithm) -> Self {
190207
match enc_alg {
@@ -485,6 +502,29 @@ mod tests {
485502
}
486503
} // test_get_key_size
487504

505+
#[test]
506+
fn test_get_key_algorithm_family() {
507+
let algorithms = [
508+
(EncryptionAlgorithm::Rsa1024, "rsa"),
509+
(EncryptionAlgorithm::Rsa2048, "rsa"),
510+
(EncryptionAlgorithm::Rsa3072, "rsa"),
511+
(EncryptionAlgorithm::Rsa4096, "rsa"),
512+
(EncryptionAlgorithm::Ecc192, "ecc"),
513+
(EncryptionAlgorithm::Ecc224, "ecc"),
514+
(EncryptionAlgorithm::Ecc256, "ecc"),
515+
(EncryptionAlgorithm::Ecc384, "ecc"),
516+
(EncryptionAlgorithm::Ecc521, "ecc"),
517+
(EncryptionAlgorithm::EccSm2, "ecc"),
518+
];
519+
for (alg, expected_family) in algorithms {
520+
let family = get_key_algorithm_family(&alg);
521+
assert_eq!(
522+
family, expected_family,
523+
"Algorithm family mismatch for {alg}"
524+
);
525+
}
526+
} // test_get_key_algorithm_family
527+
488528
#[test]
489529
fn test_get_ecc_curve_key_size() {
490530
let curves = [

keylime/src/context_info.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ impl ContextInfo {
281281
}
282282

283283
pub fn get_key_algorithm(&self) -> String {
284-
self.tpm_encryption_alg.to_string()
284+
algorithms::get_key_algorithm_family(&self.tpm_encryption_alg)
285+
.to_string()
285286
}
286287

287288
pub fn get_ek_handle(&self) -> KeyHandle {
@@ -301,7 +302,8 @@ impl ContextInfo {
301302
}
302303

303304
pub fn get_ak_key_algorithm_str(&self) -> String {
304-
self.tpm_encryption_alg.to_string()
305+
algorithms::get_key_algorithm_family(&self.tpm_encryption_alg)
306+
.to_string()
305307
}
306308

307309
pub fn get_ak_public_enum_ref(&self) -> &TssPublic {
@@ -631,7 +633,7 @@ mod tests {
631633
assert!(!context_info.get_public_key_as_base64().unwrap().is_empty()); //#[allow_ci]
632634
assert_eq!(context_info.get_key_class(), "asymmetric");
633635
assert_eq!(context_info.get_key_size(), 2048);
634-
assert_eq!(context_info.get_key_algorithm(), "rsa2048");
636+
assert_eq!(context_info.get_key_algorithm(), "rsa");
635637
let ek_handle = context_info.get_ek_handle();
636638
let ak_handle = context_info.get_ak_handle();
637639
assert!(context_info
@@ -740,7 +742,7 @@ mod tests {
740742
assert!(!context_info.get_public_key_as_base64().unwrap().is_empty()); //#[allow_ci]
741743
assert_eq!(context_info.get_key_class(), "asymmetric");
742744
assert_eq!(context_info.get_key_size(), 2048);
743-
assert_eq!(context_info.get_key_algorithm(), "rsa2048");
745+
assert_eq!(context_info.get_key_algorithm(), "rsa");
744746
assert!(!context_info.get_ak_key_class_str().is_empty());
745747
assert!(!context_info.get_ak_key_algorithm_str().is_empty());
746748
assert!(context_info.get_ak_key_size().is_ok());

0 commit comments

Comments
 (0)