What changed, and why it matters
This commit adds a way for the BitBox02 hardware wallet to remember whether its secure chip (Optiga) has been upgraded to a new configuration. Previously, the device may have re-applied the same secure-chip configuration every time it booted. Now it records a 'version' in flash memory and only applies the update if needed, then verifies the chip's metadata matches expectations. This is a hardening and reliability improvement rather than a fix for an obvious remote attack, but it touches security-critical setup code for the secure chip that protects keys.
Treat this as a security-hardening change in the secure-chip setup path. Review the _maybe_update_config_v1() logic for correct error handling, ensure the version field is atomically persisted only after successful verification, and confirm that downgrade or rollback of the persisted version cannot occur. No immediate user action is indicated by the commit alone.
Security signals we found
Secure element/Optiga configuration lifecycle change
New persistent version field in memory chunk 0
Metadata verification added after secure chip object configuration
Repeated reconfiguration of write-protected objects now gated by persisted version
New error code SC_ERR_MEMORY for memory/versioning failures
Test-only Rust bindings for version get/set
Evidence from the diff
The patch introduces memory_optiga_config_version_t (V0/V1) persisted in chunk 0 of flash, replacing part of a reserved field. It exposes get/set APIs in C and Rust (test-only wrappers). In optiga.c, _update_config() is replaced by _maybe_update_config_v1(), which reads the persisted version, applies HMAC and counter HMAC write-protected object configuration only if not already done (or if LCSO is not operational), then verifies metadata tags (0xC0, 0xE8, 0xD0, 0xD1, 0xD3 for HMAC; 0xC0, 0xD0, 0xD1, 0xD3 for counter) and persists V1 only when the lifecycle state is operational. A new SC_ERR_MEMORY error code is added. The change is defensive: it prevents repeated reconfiguration and adds verification, but the commit itself does not disclose a specific vulnerability or CVE.
Changed components
src/memory/memory.csrc/memory/memory.hsrc/optiga/optiga.csrc/rust/bitbox02-sys/build.rssrc/rust/bitbox02/src/memory.rssrc/securechip/securechip.hInspect captured patch +168 / −20
diff --git a/src/memory/memory.c b/src/memory/memory.c
index 5cbd852..3873d8b 100644
--- a/src/memory/memory.c
+++ b/src/memory/memory.c
@@ -58,7 +58,9 @@ typedef struct __attribute__((__packed__)) {
typedef union {
struct __attribute__((__packed__)) {
secbool_u8 factory_setup_done;
- uint8_t reserved[3];
+ // see `memory_optiga_config_version_t`.
+ uint8_t optiga_config_version;
+ uint8_t reserved[2];
uint8_t io_protection_key[32];
uint8_t authorization_key[32];
uint8_t encryption_key[32];
@@ -952,3 +954,40 @@ bool memory_ble_enable(bool enable)
}
return _write_to_address(FLASH_SHARED_DATA_START, 0, chunk.bytes);
}
+
+bool memory_get_optiga_config_version(memory_optiga_config_version_t* version_out)
+{
+ chunk_0_t chunk = {0};
+ CLEANUP_CHUNK(chunk);
+ _read_chunk(CHUNK_0_PERMANENT, chunk.bytes);
+ switch (chunk.fields.optiga_config_version) {
+ case 0xFF:
+ *version_out = MEMORY_OPTIGA_CONFIG_V0;
+ return true;
+ case 0x00:
+ *version_out = MEMORY_OPTIGA_CONFIG_V1;
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool memory_set_optiga_config_version(memory_optiga_config_version_t version)
+{
+ chunk_0_t chunk = {0};
+ CLEANUP_CHUNK(chunk);
+ _read_chunk(CHUNK_0_PERMANENT, chunk.bytes);
+
+ switch (version) {
+ case MEMORY_OPTIGA_CONFIG_V0:
+ chunk.fields.optiga_config_version = 0xFF;
+ break;
+ case MEMORY_OPTIGA_CONFIG_V1:
+ chunk.fields.optiga_config_version = 0x00;
+ break;
+ default:
+ return false;
+ }
+
+ return _write_chunk(CHUNK_0_PERMANENT, chunk.bytes);
+}
diff --git a/src/memory/memory.h b/src/memory/memory.h
index 42e3f21..31ab8a1 100644
--- a/src/memory/memory.h
+++ b/src/memory/memory.h
@@ -17,6 +17,14 @@
// How many multisig configurations (accounts) can be registered.
#define MEMORY_MULTISIG_NUM_ENTRIES 25
+typedef enum {
+ // Legacy/initial value, corresponds to the original Optiga factorysetup config.
+ MEMORY_OPTIGA_CONFIG_V0,
+ // Updated config V1, which configures the `OID_HMAC_WRITEPROTECTED` and
+ // `OID_COUNTER_HMAC_WRITEPROTECTED` slots.
+ MEMORY_OPTIGA_CONFIG_V1,
+} memory_optiga_config_version_t;
+
typedef enum {
// Legacy/initial value for BitBox02 and BitBox02 Nova using the initial stretch algo in
// ATECC/Optiga.
@@ -272,4 +280,7 @@ USE_RESULT bool memory_multisig_get_by_hash(const uint8_t* hash, char* name_out)
*/
USE_RESULT bool memory_ble_enable(bool enable);
+USE_RESULT bool memory_get_optiga_config_version(memory_optiga_config_version_t* version_out);
+USE_RESULT bool memory_set_optiga_config_version(memory_optiga_config_version_t version);
+
#endif // _MEMORY_H_
diff --git a/src/optiga/optiga.c b/src/optiga/optiga.c
index 36971b0..d8f1389 100644
--- a/src/optiga/optiga.c
+++ b/src/optiga/optiga.c
@@ -1019,24 +1019,6 @@ static int _configure_object_counter_hmac_writeprotected(void)
sizeof(_counter_hmac_writeprotected_metadata));
}
-static int _update_config(void)
-{
- optiga_lib_status_t res;
-
- res = _configure_object_hmac_writeprotected();
- if (res != OPTIGA_LIB_SUCCESS) {
- return res;
- }
-
- res = _configure_object_counter_hmac_writeprotected();
- if (res != OPTIGA_LIB_SUCCESS) {
- return res;
- }
-
- return 0;
-}
-
-#if VERIFY_METADATA == 1
static int _verify_metadata(
uint16_t oid,
const uint8_t* expected_metadata,
@@ -1082,8 +1064,83 @@ static int _verify_metadata(
}
return 0;
}
+
+// Updates Optiga config to V1 if not already done.
+static int _maybe_update_config_v1(void)
+{
+#ifdef TESTING
+ // We don't yet unit-test the config update.
+ return 0;
#endif
+ memory_optiga_config_version_t config_version;
+ if (!memory_get_optiga_config_version(&config_version)) {
+ return SC_ERR_MEMORY;
+ }
+
+ if (config_version >= MEMORY_OPTIGA_CONFIG_V1) {
+ if (FINAL_LCSO_STATE_V1 >= LCSO_STATE_OPERATIONAL) {
+ // Already configured
+ util_log("optiga: config v1 already configured");
+ return 0;
+ }
+ util_log(
+ "optiga: config v1 configured, but re-doing it because LCSO state is not operational");
+ }
+
+ optiga_lib_status_t res;
+
+ res = _configure_object_hmac_writeprotected();
+ if (res != OPTIGA_LIB_SUCCESS) {
+ return res;
+ }
+
+ res = _configure_object_counter_hmac_writeprotected();
+ if (res != OPTIGA_LIB_SUCCESS) {
+ return res;
+ }
+
+ // Verify metadata tags are setup as expected.
+
+ {
+ const uint8_t check_tags[] = {0xC0, 0xE8, 0xD0, 0xD1, 0xD3};
+ res = _verify_metadata(
+ OID_HMAC_WRITEPROTECTED,
+ _hmac_writeprotected_metadata,
+ sizeof(_hmac_writeprotected_metadata),
+ check_tags,
+ sizeof(check_tags));
+ if (res) {
+ util_log("verify config failed (hmac_writeprotected): %i", res);
+ return res;
+ }
+ util_log("verify config OK (hmac_writeprotected)");
+ }
+
+ {
+ const uint8_t check_tags[] = {0xC0, 0xD0, 0xD1, 0xD3};
+ res = _verify_metadata(
+ OID_COUNTER_HMAC_WRITEPROTECTED,
+ _counter_hmac_writeprotected_metadata,
+ sizeof(_counter_hmac_writeprotected_metadata),
+ check_tags,
+ sizeof(check_tags));
+ if (res) {
+ util_log("verify config failed (counter_hmac_writeprotected): %i", res);
+ return res;
+ }
+ util_log("verify config OK (counter_hmac_writeprotected)");
+ }
+
+ if (FINAL_LCSO_STATE_V1 >= LCSO_STATE_OPERATIONAL) {
+ if (!memory_set_optiga_config_version(MEMORY_OPTIGA_CONFIG_V1)) {
+ return SC_ERR_MEMORY;
+ }
+ }
+
+ return 0;
+}
+
static int _set_password(
const uint8_t* password_secret,
size_t password_secret_len,
@@ -1411,7 +1468,7 @@ int optiga_setup(const securechip_interface_functions_t* ifs)
}
// Apply config updates.
- res = _update_config();
+ res = _maybe_update_config_v1();
if (res) {
util_log("factory setup failed");
return res;
diff --git a/src/rust/bitbox02-sys/build.rs b/src/rust/bitbox02-sys/build.rs
index 941916e..8ca923d 100644
--- a/src/rust/bitbox02-sys/build.rs
+++ b/src/rust/bitbox02-sys/build.rs
@@ -92,6 +92,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"memory_get_encryption_key",
"memory_get_io_protection_key",
"memory_get_noise_static_private_key",
+ "memory_get_optiga_config_version",
"memory_get_platform",
"memory_get_salt_root",
"memory_get_securechip_type",
@@ -110,6 +111,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"memory_set_encrypted_seed_and_hmac",
"memory_set_initialized",
"memory_set_mnemonic_passphrase_enabled",
+ "memory_set_optiga_config_version",
"memory_set_salt_root",
"memory_set_bootloader_hash_fake",
"memory_set_seed_birthdate",
@@ -189,6 +191,7 @@ const ALLOWLIST_FNS: &[&str] = &[
const RUSTIFIED_ENUMS: &[&str] = &[
"event_types",
"keystore_secp256k1_pubkey_format",
+ "memory_optiga_config_version_t",
"memory_password_stretch_algo_t",
"memory_result_t",
"multisig_script_type_t",
diff --git a/src/rust/bitbox02/src/memory.rs b/src/rust/bitbox02/src/memory.rs
index ab40266..3242e8a 100644
--- a/src/rust/bitbox02/src/memory.rs
+++ b/src/rust/bitbox02/src/memory.rs
@@ -12,6 +12,7 @@ pub const MULTISIG_NAME_MAX_LEN: usize = bitbox02_sys::MEMORY_MULTISIG_NAME_MAX_
pub use bitbox02_sys::memory_ble_metadata_t as BleMetadata;
+pub use bitbox02_sys::memory_optiga_config_version_t as OptigaConfigVersion;
pub use bitbox02_sys::memory_password_stretch_algo_t as PasswordStretchAlgo;
pub use bitbox02_sys::memory_result_t as MemoryError;
@@ -367,6 +368,25 @@ fn set_attestation_bootloader_hash(hash: &[u8; 32]) -> bool {
unsafe { bitbox02_sys::memory_set_attestation_bootloader_hash(hash.as_ptr()) }
}
+#[cfg(test)]
+fn get_optiga_config_version() -> Result<OptigaConfigVersion, ()> {
+ let mut version = core::mem::MaybeUninit::uninit();
+ unsafe {
+ match bitbox02_sys::memory_get_optiga_config_version(version.as_mut_ptr()) {
+ true => Ok(version.assume_init()),
+ false => Err(()),
+ }
+ }
+}
+
+#[cfg(test)]
+fn set_optiga_config_version(version: OptigaConfigVersion) -> Result<(), ()> {
+ match unsafe { bitbox02_sys::memory_set_optiga_config_version(version) } {
+ true => Ok(()),
+ false => Err(()),
+ }
+}
+
#[cfg(all(test, feature = "testing"))]
mod tests {
use super::*;
@@ -826,4 +846,21 @@ mod tests {
assert_eq!(get_attestation_bootloader_hash(), mock1);
}
+
+ #[test]
+ fn test_optiga_config_version_roundtrip() {
+ mock_memory();
+
+ assert!(matches!(
+ get_optiga_config_version(),
+ Ok(OptigaConfigVersion::MEMORY_OPTIGA_CONFIG_V0),
+ ));
+
+ set_optiga_config_version(OptigaConfigVersion::MEMORY_OPTIGA_CONFIG_V1).unwrap();
+
+ assert!(matches!(
+ get_optiga_config_version(),
+ Ok(OptigaConfigVersion::MEMORY_OPTIGA_CONFIG_V1),
+ ));
+ }
}
diff --git a/src/securechip/securechip.h b/src/securechip/securechip.h
index 0c599fc..533b8db 100644
--- a/src/securechip/securechip.h
+++ b/src/securechip/securechip.h
@@ -23,6 +23,7 @@ typedef enum {
SC_ERR_INCORRECT_PASSWORD = -6,
// The password stretch algo is not supported
SC_ERR_INVALID_PASSWORD_STRETCH_ALGO = -7,
+ SC_ERR_MEMORY = -8,
// Errors specific to the ATECC
SC_ATECC_ERR_ZONE_UNLOCKED_CONFIG = -100,
Why this scored 45/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.