Allow factory-reset when the state fails to load

This commit is contained in:
Sosthène Guédon
2025-03-06 09:55:34 +01:00
committed by sosthene-nitrokey
parent 8538648ada
commit dc41df2f20
+14 -7
View File
@@ -212,17 +212,24 @@ where
YubicoPivExtension::Attest(_slot) => return Err(Status::FunctionNotSupported),
YubicoPivExtension::Reset => {
let this = self.load()?;
if this.state.persistent.remaining_pin_retries(this.trussed) != 0 {
return Err(Status::ConditionsOfUseNotSatisfied);
}
let mut this;
let trussed = match self.load() {
Err(_err) => &mut self.trussed,
Ok(loaded) => {
this = loaded;
if this.state.persistent.remaining_pin_retries(this.trussed) != 0 {
return Err(Status::ConditionsOfUseNotSatisfied);
}
&mut this.trussed
}
};
// TODO: find out what all needs resetting :)
for location in [Location::Volatile, Location::External, Location::Internal] {
try_syscall!(this.trussed.delete_all(location)).ok();
try_syscall!(this.trussed.remove_dir_all(location, PathBuf::new())).ok();
try_syscall!(trussed.delete_all(location)).ok();
try_syscall!(trussed.remove_dir_all(location, PathBuf::new())).ok();
}
try_syscall!(this.trussed.delete_all_pins()).ok();
try_syscall!(trussed.delete_all_pins()).ok();
self.state.persistent = None;
}