Handle signature counter overflows

As described in Requirement 2.3.2 of the Security Requirements v1.5, a
signature counter value of zero indicates an error. If the authenticator
returns zero once, it may not return a non-zero value in subsequent
calls, so we have to stay in the error state if an overflow occurs.
This commit is contained in:
Robin Krahl
2026-05-31 15:03:59 +02:00
parent 731668e87a
commit a3ee89d091
2 changed files with 13 additions and 2 deletions
+1
View File
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix signature counter to improve spec compliance:
- Set the initial signature counter to 1.
- Correctly handle signature counter overflows by returning 0.
## [v0.4.0-rc.1](https://github.com/trussed-dev/fido-authenticator/releases/tag/v0.4.0-rc.1) (2026-05-29)
+12 -2
View File
@@ -397,8 +397,18 @@ impl PersistentState {
pub fn signature_counter<T: FilesystemClient>(&mut self, trussed: &mut T) -> Result<u32> {
let now = self.timestamp;
self.timestamp += 1;
self.save(trussed)?;
// 0 indicates a counter overflow. If this is the case, we can no longer increment the
// counter and have to always return 0, see Requirement 2.3.2 in the Security Requirements
// v1.5.
if now > 0 {
if let Some(timestamp) = self.timestamp.checked_add(1) {
self.timestamp = timestamp;
} else {
// Indicate an overflow by setting the counter to 0.
self.timestamp = 0;
}
self.save(trussed)?;
}
Ok(now)
}