diff --git a/apps/vault/src/ctap/storage.rs b/apps/vault/src/ctap/storage.rs index 2dceb54da..45edcf9d2 100644 --- a/apps/vault/src/ctap/storage.rs +++ b/apps/vault/src/ctap/storage.rs @@ -43,7 +43,7 @@ use super::CREDENTIAL_ID_SIZE; /// credentials, but what happens in this case is just a re-allocation in the PDDB. /// Whereas if this number is "too big" you end up with wasted space. I think a /// typical record will be around 300-400 bytes, so, this is a good compromise. -const CRED_INITAL_SIZE: usize = 512; +pub(crate) const CRED_INITAL_SIZE: usize = 512; // Those constants may be modified before compilation to tune the behavior of the key. // @@ -149,10 +149,8 @@ impl PersistentStore { } // Generate and store the CredRandom secrets if they are missing. - // note this goes into the FIDO_CRED_DICT, in order to force its creation. - // It does mean we have a special case key in the dictionary. match self.pddb.borrow().get( - FIDO_CRED_DICT, + FIDO_DICT, key::CRED_RANDOM_SECRET, None, true, true, Some(64), Some(crate::basis_change) @@ -387,7 +385,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem match self.pddb.borrow().get( FIDO_CRED_DICT, &shortid, - None, false, false, + None, true, false, Some(CREDENTIAL_ID_SIZE), Some(crate::basis_change) ) { Ok(mut cred) => { @@ -431,7 +429,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem match self.pddb.borrow().get( FIDO_CRED_DICT, &shortid, - None, false, true, + None, true, true, Some(CRED_INITAL_SIZE), Some(crate::basis_change) ) { Ok(mut cred) => { @@ -457,7 +455,6 @@ openssl asn1parse -in opensk_cert.pem -inform pem let mut result = Vec::::new(); let mut cred_list = self.pddb.borrow().list_keys( FIDO_CRED_DICT, None).or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?; - cred_list.retain(|name| name != key::CRED_RANDOM_SECRET); // don't try to investigate this one key for cred_name in cred_list.iter() { if let Some(mut cred_entry) = self.pddb.borrow().get( FIDO_CRED_DICT, @@ -483,7 +480,6 @@ openssl asn1parse -in opensk_cert.pem -inform pem pub fn count_credentials(&self) -> Result { let mut cred_list = self.pddb.borrow().list_keys( FIDO_CRED_DICT, None).or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?; - cred_list.retain(|name| name != key::CRED_RANDOM_SECRET); // don't count this special case key Ok(cred_list.len()) } @@ -492,7 +488,6 @@ openssl asn1parse -in opensk_cert.pem -inform pem let mut max = 0; let mut cred_list = self.pddb.borrow().list_keys( FIDO_CRED_DICT, None).or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?; - cred_list.retain(|name| name != key::CRED_RANDOM_SECRET); // don't try to investigate this one key if cred_list.len() == 0 { return Ok(0) } @@ -588,7 +583,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem /// Returns the CredRandom secret. pub fn cred_random_secret(&self, has_uv: bool) -> Result<[u8; 32], Ctap2StatusCode> { match self.pddb.borrow().get( - FIDO_CRED_DICT, + FIDO_DICT, key::CRED_RANDOM_SECRET, None, false, false, None, Some(crate::basis_change) ) { @@ -1000,13 +995,13 @@ openssl asn1parse -in opensk_cert.pem -inform pem } /// Deserializes a credential from storage representation. -fn deserialize_credential(data: &[u8]) -> Option { +pub(crate) fn deserialize_credential(data: &[u8]) -> Option { let cbor = cbor::read(data).ok()?; cbor.try_into().ok() } /// Serializes a credential to storage representation. -fn serialize_credential(credential: PublicKeyCredentialSource) -> Result, Ctap2StatusCode> { +pub(crate) fn serialize_credential(credential: PublicKeyCredentialSource) -> Result, Ctap2StatusCode> { let mut data = Vec::new(); if cbor::write(credential.into(), &mut data) { Ok(data)