What changed, and why it matters
This commit fixes a programming bug where the firmware could crash with a panic if the secure keystore returned certain error codes that the Rust code did not know how to handle. The patch adds mappings for two newly introduced error conditions (decryption failures and a key-stretching failure for retained seed backup) so they are reported gracefully instead of crashing the device. A crash could cause denial of service or unexpected device behavior, but there is no direct evidence in the commit that it could be exploited to steal funds or bypass security.
Treat as a hardening fix and include in the next firmware release. Review whether any other keystore_error_t values remain unmapped and consider replacing the panic branch with a safe fallback error to avoid future crashes. No immediate incident response is indicated by the diff alone.
Security signals we found
Removal of a panic fallback in error conversion
Mapping of previously unhandled keystore error codes
Defensive hardening of Rust/C FFI error handling
Potential denial-of-service via unexpected error code path
Evidence from the diff
The Rust wrapper in src/rust/bitbox02/src/keystore.rs converts C keystore_error_t values into a Rust Error enum. Previously the catch-all branch panicked with ‘cannot convert error’ for any unmapped error code. The patch adds enum variants Decrypt and StretchRetainedSeedKey and maps KEYSTORE_ERR_DECRYPT and KEYSTORE_ERR_STRETCH_RETAINED_SEED_KEY to them, preventing a panic. The change is defensive and partial: other future or existing error codes could still trigger the same panic path.
Changed components
src/rust/bitbox02/src/keystore.rsRust keystore error conversion layerC-to-Rust FFI error handlingInspect captured patch +8 / −2
diff --git a/src/rust/bitbox02/src/keystore.rs b/src/rust/bitbox02/src/keystore.rs
index 8b078db..c6c9561 100644
--- a/src/rust/bitbox02/src/keystore.rs
+++ b/src/rust/bitbox02/src/keystore.rs
@@ -40,10 +40,12 @@ pub enum Error {
Memory,
// Securechip error with the error code from securechip.c. 0 if the error is unspecified.
SecureChip(i32),
+ SeedSize,
Salt,
Hash,
- SeedSize,
Encrypt,
+ Decrypt,
+ StretchRetainedSeedKey,
}
impl core::convert::From<keystore_error_t> for Error {
@@ -52,11 +54,15 @@ impl core::convert::From<keystore_error_t> for Error {
keystore_error_t::KEYSTORE_ERR_MAX_ATTEMPTS_EXCEEDED => Error::MaxAttemptsExceeded,
keystore_error_t::KEYSTORE_ERR_UNSEEDED => Error::Unseeded,
keystore_error_t::KEYSTORE_ERR_MEMORY => Error::Memory,
- keystore_error_t::KEYSTORE_ERR_SEED_SIZE => Error::SeedSize,
keystore_error_t::KEYSTORE_ERR_SECURECHIP => Error::SecureChip(0),
+ keystore_error_t::KEYSTORE_ERR_SEED_SIZE => Error::SeedSize,
keystore_error_t::KEYSTORE_ERR_SALT => Error::Salt,
keystore_error_t::KEYSTORE_ERR_HASH => Error::Hash,
keystore_error_t::KEYSTORE_ERR_ENCRYPT => Error::Encrypt,
+ keystore_error_t::KEYSTORE_ERR_DECRYPT => Error::Decrypt,
+ keystore_error_t::KEYSTORE_ERR_STRETCH_RETAINED_SEED_KEY => {
+ Error::StretchRetainedSeedKey
+ }
_ => panic!("cannot convert error"),
}
}
Why this scored 43/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.