What changed, and why it matters
This commit only adds two new automated tests for the BitBox02 hardware wallet's keystore. The tests verify that the failed-unlock-attempt counter resets correctly after a successful password entry, both when the device was previously locked and when it stays unlocked. No production code was changed, so this commit does not introduce or fix a live security issue by itself.
No action required. Treat as routine test-coverage improvement. If reviewing a larger series, check whether a preceding commit actually changed the reset behavior that these tests now cover.
Security signals we found
Tests assert that failed password attempts reset after a correct unlock
Tests reference `MAX_UNLOCK_ATTEMPTS` and `Error::IncorrectPassword { remaining_attempts }`
No changes to unlock logic, memory layout, or cryptography
Evidence from the diff
The diff adds Rust unit tests in src/rust/bitbox02-rust/src/keystore.rs: test_unlock_failed_attempts_reset_locked and test_unlock_failed_attempts_reset_unlocked. They exercise unlock(), copy_seed(), and memory::is_seeded() to confirm that MAX_UNLOCK_ATTEMPTS is not prematurely exhausted by interleaving wrong and correct password attempts. The underlying reset behavior is already implemented; the commit merely increases test coverage.
Changed components
src/rust/bitbox02-rust/src/keystore.rsInspect captured patch +74 / −0
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index bb08c28..b3c230c 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -925,6 +925,80 @@ mod tests {
assert!(matches!(unlock("password"), Err(Error::Unseeded)));
}
+ /// Ensures the failed-attempt counter resets once a correct password is entered while the
+ /// keystore is locked, so a later wrong attempt after relocking still sees the full allowance.
+ #[test]
+ fn test_unlock_failed_attempts_reset_locked() {
+ mock_memory();
+ lock();
+
+ let seed = hex!("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044");
+ let mock_salt_root =
+ hex!("3333333333333333444444444444444411111111111111112222222222222222");
+ bitbox02::memory::set_salt_root(&mock_salt_root).unwrap();
+
+ assert!(encrypt_and_store_seed(&mut TestingHal::new(), &seed, "password").is_ok());
+ lock();
+
+ let wrong_attempt = || {
+ assert!(matches!(
+ unlock("wrong"),
+ Err(Error::IncorrectPassword { remaining_attempts })
+ if remaining_attempts == bitbox02::memory::MAX_UNLOCK_ATTEMPTS - 1
+ ));
+ };
+
+ wrong_attempt();
+ assert!(copy_seed().is_err());
+
+ assert_eq!(unlock("password").unwrap().as_slice(), seed);
+ assert!(copy_seed().is_ok());
+
+ lock();
+ assert!(copy_seed().is_err());
+
+ wrong_attempt();
+ assert!(copy_seed().is_err());
+ assert!(bitbox02::memory::is_seeded());
+ }
+
+ /// Ensures the failed-attempt counter resets when the keystore stays unlocked throughout, so
+ /// interleaving wrong attempts with successful unlocks cannot exhaust the counter prematurely.
+ #[test]
+ fn test_unlock_failed_attempts_reset_unlocked() {
+ mock_memory();
+ lock();
+
+ let seed = hex!("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044");
+ let mock_salt_root =
+ hex!("3333333333333333444444444444444411111111111111112222222222222222");
+ bitbox02::memory::set_salt_root(&mock_salt_root).unwrap();
+
+ assert!(encrypt_and_store_seed(&mut TestingHal::new(), &seed, "password").is_ok());
+ lock();
+
+ assert_eq!(unlock("password").unwrap().as_slice(), seed);
+ assert!(copy_seed().is_ok());
+
+ let wrong_attempt = || {
+ assert!(matches!(
+ unlock("wrong"),
+ Err(Error::IncorrectPassword { remaining_attempts })
+ if remaining_attempts == bitbox02::memory::MAX_UNLOCK_ATTEMPTS - 1
+ ));
+ };
+
+ wrong_attempt();
+ assert!(copy_seed().is_ok());
+
+ assert_eq!(unlock("password").unwrap().as_slice(), seed);
+ assert!(copy_seed().is_ok());
+
+ wrong_attempt();
+ assert!(copy_seed().is_ok());
+ assert!(bitbox02::memory::is_seeded());
+ }
+
#[test]
fn test_unlock_bip39() {
mock_memory();
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.