add storage limits on FIDO cred count

perfomance regression on the PDDB with the latest fixes make
the device stop passing compliance when the database grows
to about 40-ish keys. For now, we set the cred limit to 32,
until the performance issues are addressed. (note that yubico
has a limit of 25 credentials, so, 32 is not insanely low).
This commit is contained in:
bunnie 2022-06-27 00:04:46 +08:00
parent 79c20eb498
commit 9cf48fcaa5
2 changed files with 13 additions and 9 deletions

View file

@ -65,8 +65,9 @@ pub(crate) const CRED_INITAL_SIZE: usize = 512;
// With P=20 and K=150, we have I=2M which is enough for 500 increments per day for 10 years.
#[allow(dead_code)] // openSK legacy
const NUM_PAGES: usize = 20;
#[allow(dead_code)] // OpenSK legacy
const MAX_SUPPORTED_RESIDENTIAL_KEYS: usize = 150;
// The limit is based on the performance of the PDDB to get a query response within
// the compliance time-out limit. Optimization is needed to improve this number!
const MAX_SUPPORTED_RESIDENTIAL_KEYS: usize = 32;
const MAX_PIN_RETRIES: u8 = 8;
#[cfg(feature = "with_ctap2_1")]
@ -389,6 +390,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
Some(CREDENTIAL_ID_SIZE), Some(crate::basis_change)
) {
Ok(mut cred) => {
log::trace!("find {}", shortid);
let mut data = Vec::<u8>::new();
cred.read_to_end(&mut data).or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?;
match deserialize_credential(&data) {
@ -428,6 +430,9 @@ openssl asn1parse -in opensk_cert.pem -inform pem
&mut self,
new_credential: PublicKeyCredentialSource,
) -> Result<(), Ctap2StatusCode> {
if self.count_credentials()? >= MAX_SUPPORTED_RESIDENTIAL_KEYS {
return Err(Ctap2StatusCode::CTAP2_ERR_KEY_STORE_FULL);
}
let shortid = self.cid_to_str(&new_credential.credential_id);
match self.pddb.borrow().get(
FIDO_CRED_DICT,
@ -437,6 +442,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
) {
Ok(mut cred) => {
let value = serialize_credential(new_credential)?;
log::trace!("writing {}", shortid);
cred.write(&value)
.or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?;
self.pddb.borrow().sync()
@ -465,11 +471,13 @@ openssl asn1parse -in opensk_cert.pem -inform pem
None, false, false,
Some(CREDENTIAL_ID_SIZE), Some(crate::basis_change)
).ok() {
log::trace!("checking {}", cred_name);
let mut data = Vec::<u8>::new();
cred_entry.read_to_end(&mut data).or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR))?;
if let Some(cred) = deserialize_credential(&data) {
if cred.rp_id == rp_id
&& (cred.is_discoverable() || !check_cred_protect) {
log::trace!("filtered {}", cred_name);
result.push(cred);
}
}
@ -479,9 +487,8 @@ openssl asn1parse -in opensk_cert.pem -inform pem
}
/// Returns the number of credentials.
#[cfg(test)]
pub fn count_credentials(&self) -> Result<usize, Ctap2StatusCode> {
let mut cred_list = self.pddb.borrow().list_keys(
let cred_list = self.pddb.borrow().list_keys(
FIDO_CRED_DICT, None).unwrap_or(Vec::new());
Ok(cred_list.len())
}
@ -615,7 +622,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
let mut pin_hash = [0u8; PIN_AUTH_LENGTH];
match ph.read(&mut pin_hash) {
Ok(PIN_AUTH_LENGTH) => {
log::info!("pin_hash: {:x?}", &pin_hash);
log::trace!("pin_hash: {:x?}", &pin_hash);
Ok(Some(pin_hash))
},
Ok(l) => {

View file

@ -108,9 +108,6 @@ To clear test entries:
pddb dictdelete fido.cred
pddb dictdelete fido.u2fapps
Issue: editing an entry in a non-secret basis while a secret basis is open won't work because
the delete key function doesn't work in that case. Need to modify the `get` routine to return
the basis so we can specify which basis to edit...
*/
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
@ -161,7 +158,7 @@ const ERR_TIMEOUT_MS: usize = 5000;
fn main() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Debug);
log::set_max_level(log::LevelFilter::Info);
log::info!("my PID is {}", xous::process::id());
let xns = xous_names::XousNames::new().unwrap();