From c758c9547059d81940463c87be11a82a9fcf93ff Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 5 Dec 2023 23:10:02 +0100 Subject: [PATCH] Fix field order in CredentialData large_blob_key has to be added in the end so that index-based deserialization still works for existing data. --- src/credential.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/credential.rs b/src/credential.rs index 9b17cdd..7612313 100644 --- a/src/credential.rs +++ b/src/credential.rs @@ -226,8 +226,6 @@ pub struct CredentialData { pub hmac_secret: Option, #[serde(skip_serializing_if = "Option::is_none")] pub cred_protect: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub large_blob_key: Option>, // TODO: add `sig_counter: Option`, // and grant RKs a per-credential sig-counter. @@ -237,6 +235,10 @@ pub struct CredentialData { // used as a marker for new credentials. #[serde(skip_serializing_if = "Option::is_none")] use_short_id: Option, + + // extensions (cont. -- we can only append new options due to index-based deserialization) + #[serde(skip_serializing_if = "Option::is_none")] + pub large_blob_key: Option>, } // TODO: figure out sizes @@ -521,6 +523,7 @@ mod test { hmac_secret: Some(false), cred_protect: None, use_short_id: Some(true), + large_blob_key: Some(Bytes::from_slice(&[0xff; 32]).unwrap()), } } @@ -599,6 +602,7 @@ mod test { hmac_secret: Some(false), cred_protect: None, use_short_id: Some(true), + large_blob_key: Some(random_bytes()), } } @@ -680,6 +684,7 @@ mod test { nonce: Bytes::from_slice(&[u8::MAX; 12]).unwrap(), hmac_secret: Some(true), cred_protect: Some(CredentialProtectionPolicy::Required), + large_blob_key: Some(Bytes::from_slice(&[0xff; 32]).unwrap()), }; trussed::virt::with_ram_client("fido", |mut client| { let kek = syscall!(client.generate_chacha8poly1305_key(Location::Internal)).key; @@ -688,7 +693,7 @@ mod test { .to_bytes() .unwrap(); let id = credential.id(&mut client, kek, &rp_id_hash).unwrap(); - assert_eq!(id.0.len(), 204); + assert_eq!(id.0.len(), 239); }); }