api: expose stage0 version in device info
What changed, and why it matters
This commit adds a new read-only piece of information to the BitBox02's device-info API response: the version of the installed 'stage0' bootloader component. It does not change any security behavior, access controls, or data handling. It simply lets host software see which stage0 version is present, or omit the field if none is installed. There is no indication this fixes or introduces a vulnerability.
No security action required. Treat as a normal feature/API enhancement. Reviewers may optionally verify that the descriptor address and magic check match the stage0 layout, but the diff shows no unsafe behavior.
Security signals we found
Read-only API addition with no state mutation
Descriptor magic validated before returning version
Optional protobuf field; absent when stage0 not installed
No privilege, authentication, or access-control changes
No buffer parsing beyond existing fixed-size descriptor
Evidence from the diff
The change exposes an existing stage0 descriptor’s numeric image version through the DeviceInfoResponse protobuf message as optional uint32 stage0_version. A new memory_get_stage0_version() C helper reads the descriptor at BB02_STAGE0_DESCRIPTOR_ADDR, validates its magic, and returns the version. Rust and Python client bindings are updated to surface the value, and unit/hardware-fake tests are added. The field is absent when no valid stage0 descriptor exists. No logic is modified beyond adding this read-only accessor and API field.
Changed components
BitBox02 firmware device-info APImessages/bitbox02_system.protosrc/memory/memory.c memory_get_stage0_versionsrc/rust/bitbox02-rust/src/hww/api/device_info.rspy/bitbox02 Python clientInspect captured patch +178 / −20
### CHANGELOG.md
@@ -7,6 +7,7 @@ recorded separately.
## Firmware
### Unreleased
+- API: include the installed stage0 version in the device info response
- Allow entering the optional BIP39 passphrase on the host, with device approval and confirmation
- Reject malformed microSD backups instead of crashing
- Hold the screen reset pin low until firmware is ready initalize it.
### messages/bitbox02_system.proto
@@ -40,6 +40,8 @@ message DeviceInfoResponse {
string language = 10;
// Empty on firmware without supported-language reporting.
repeated string supported_languages = 11;
+ // Image version of the installed stage0. Not present if no stage0 is installed.
+ optional uint32 stage0_version = 12;
}
message InsertRemoveSDCardRequest {
### py/bitbox02/CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
## [Unreleased]
+- `device_info()`: add the installed stage0 version, or `None` if absent
- Bitcoin: fix signing Taproot wallet policies and avoid requiring previous transactions
when all inputs are Taproot
- Validate ECDSA signatures and recovery IDs in Anti-Klepto and direct signing flows
### py/bitbox02/bitbox02/bitbox02/bitbox02.py
@@ -187,6 +187,11 @@ def device_info(self) -> Dict[str, Any]:
if response.device_info.HasField("bootloader_version")
else None
),
+ "stage0_version": (
+ response.device_info.stage0_version
+ if response.device_info.HasField("stage0_version")
+ else None
+ ),
"initialized": response.device_info.initialized,
"mnemonic_passphrase_enabled": response.device_info.mnemonic_passphrase_enabled,
"monotonic_increments_remaining": response.device_info.monotonic_increments_remaining,
### py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.py
@@ -13,7 +13,7 @@
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x62itbox02_system.proto\x12\x14shiftcrypto.bitbox02\"\x14\n\x12\x43heckSDCardRequest\"\'\n\x13\x43heckSDCardResponse\x12\x10\n\x08inserted\x18\x01 \x01(\x08\"\x13\n\x11\x44\x65viceInfoRequest\"\xe1\x03\n\x12\x44\x65viceInfoResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0binitialized\x18\x02 \x01(\x08\x12\x0f\n\x07version\x18\x03 \x01(\t\x12#\n\x1bmnemonic_passphrase_enabled\x18\x04 \x01(\x08\x12&\n\x1emonotonic_increments_remaining\x18\x05 \x01(\r\x12\x18\n\x10securechip_model\x18\x06 \x01(\t\x12J\n\tbluetooth\x18\x07 \x01(\x0b\x32\x32.shiftcrypto.bitbox02.DeviceInfoResponse.BluetoothH\x00\x88\x01\x01\x12 \n\x18password_stretching_algo\x18\x08 \x01(\t\x12\x1f\n\x12\x62ootloader_version\x18\t \x01(\tH\x01\x88\x01\x01\x12\x10\n\x08language\x18\n \x01(\t\x12\x1b\n\x13supported_languages\x18\x0b \x03(\t\x1aM\n\tBluetooth\x12\x15\n\rfirmware_hash\x18\x01 \x01(\x0c\x12\x18\n\x10\x66irmware_version\x18\x02 \x01(\t\x12\x0f\n\x07\x65nabled\x18\x03 \x01(\x08\x42\x0c\n\n_bluetoothB\x15\n\x13_bootloader_version\"\x9b\x01\n\x19InsertRemoveSDCardRequest\x12L\n\x06\x61\x63tion\x18\x01 \x01(\x0e\x32<.shiftcrypto.bitbox02.InsertRemoveSDCardRequest.SDCardAction\"0\n\x0cSDCardAction\x12\x0f\n\x0bREMOVE_CARD\x10\x00\x12\x0f\n\x0bINSERT_CARD\x10\x01\"\x0e\n\x0cResetRequest\",\n\x18SetDeviceLanguageRequest\x12\x10\n\x08language\x18\x01 \x01(\t\"$\n\x14SetDeviceNameRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"%\n\x12SetPasswordRequest\x12\x0f\n\x07\x65ntropy\x18\x01 \x01(\x0c\"\x17\n\x15\x43hangePasswordRequestb\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x62itbox02_system.proto\x12\x14shiftcrypto.bitbox02\"\x14\n\x12\x43heckSDCardRequest\"\'\n\x13\x43heckSDCardResponse\x12\x10\n\x08inserted\x18\x01 \x01(\x08\"\x13\n\x11\x44\x65viceInfoRequest\"\x91\x04\n\x12\x44\x65viceInfoResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0binitialized\x18\x02 \x01(\x08\x12\x0f\n\x07version\x18\x03 \x01(\t\x12#\n\x1bmnemonic_passphrase_enabled\x18\x04 \x01(\x08\x12&\n\x1emonotonic_increments_remaining\x18\x05 \x01(\r\x12\x18\n\x10securechip_model\x18\x06 \x01(\t\x12J\n\tbluetooth\x18\x07 \x01(\x0b\x32\x32.shiftcrypto.bitbox02.DeviceInfoResponse.BluetoothH\x00\x88\x01\x01\x12 \n\x18password_stretching_algo\x18\x08 \x01(\t\x12\x1f\n\x12\x62ootloader_version\x18\t \x01(\tH\x01\x88\x01\x01\x12\x10\n\x08language\x18\n \x01(\t\x12\x1b\n\x13supported_languages\x18\x0b \x03(\t\x12\x1b\n\x0estage0_version\x18\x0c \x01(\rH\x02\x88\x01\x01\x1aM\n\tBluetooth\x12\x15\n\rfirmware_hash\x18\x01 \x01(\x0c\x12\x18\n\x10\x66irmware_version\x18\x02 \x01(\t\x12\x0f\n\x07\x65nabled\x18\x03 \x01(\x08\x42\x0c\n\n_bluetoothB\x15\n\x13_bootloader_versionB\x11\n\x0f_stage0_version\"\x9b\x01\n\x19InsertRemoveSDCardRequest\x12L\n\x06\x61\x63tion\x18\x01 \x01(\x0e\x32<.shiftcrypto.bitbox02.InsertRemoveSDCardRequest.SDCardAction\"0\n\x0cSDCardAction\x12\x0f\n\x0bREMOVE_CARD\x10\x00\x12\x0f\n\x0bINSERT_CARD\x10\x01\"\x0e\n\x0cResetRequest\",\n\x18SetDeviceLanguageRequest\x12\x10\n\x08language\x18\x01 \x01(\t\"$\n\x14SetDeviceNameRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"%\n\x12SetPasswordRequest\x12\x0f\n\x07\x65ntropy\x18\x01 \x01(\x0c\"\x17\n\x15\x43hangePasswordRequestb\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'bitbox02_system_pb2', globals())
@@ -27,21 +27,21 @@
_DEVICEINFOREQUEST._serialized_start=110
_DEVICEINFOREQUEST._serialized_end=129
_DEVICEINFORESPONSE._serialized_start=132
- _DEVICEINFORESPONSE._serialized_end=613
- _DEVICEINFORESPONSE_BLUETOOTH._serialized_start=499
- _DEVICEINFORESPONSE_BLUETOOTH._serialized_end=576
- _INSERTREMOVESDCARDREQUEST._serialized_start=616
- _INSERTREMOVESDCARDREQUEST._serialized_end=771
- _INSERTREMOVESDCARDREQUEST_SDCARDACTION._serialized_start=723
- _INSERTREMOVESDCARDREQUEST_SDCARDACTION._serialized_end=771
- _RESETREQUEST._serialized_start=773
- _RESETREQUEST._serialized_end=787
- _SETDEVICELANGUAGEREQUEST._serialized_start=789
- _SETDEVICELANGUAGEREQUEST._serialized_end=833
- _SETDEVICENAMEREQUEST._serialized_start=835
- _SETDEVICENAMEREQUEST._serialized_end=871
- _SETPASSWORDREQUEST._serialized_start=873
- _SETPASSWORDREQUEST._serialized_end=910
- _CHANGEPASSWORDREQUEST._serialized_start=912
- _CHANGEPASSWORDREQUEST._serialized_end=935
+ _DEVICEINFORESPONSE._serialized_end=661
+ _DEVICEINFORESPONSE_BLUETOOTH._serialized_start=528
+ _DEVICEINFORESPONSE_BLUETOOTH._serialized_end=605
+ _INSERTREMOVESDCARDREQUEST._serialized_start=664
+ _INSERTREMOVESDCARDREQUEST._serialized_end=819
+ _INSERTREMOVESDCARDREQUEST_SDCARDACTION._serialized_start=771
+ _INSERTREMOVESDCARDREQUEST_SDCARDACTION._serialized_end=819
+ _RESETREQUEST._serialized_start=821
+ _RESETREQUEST._serialized_end=835
+ _SETDEVICELANGUAGEREQUEST._serialized_start=837
+ _SETDEVICELANGUAGEREQUEST._serialized_end=881
+ _SETDEVICENAMEREQUEST._serialized_start=883
+ _SETDEVICENAMEREQUEST._serialized_end=919
+ _SETPASSWORDREQUEST._serialized_start=921
+ _SETPASSWORDREQUEST._serialized_end=958
+ _CHANGEPASSWORDREQUEST._serialized_start=960
+ _CHANGEPASSWORDREQUEST._serialized_end=983
# @@protoc_insertion_point(module_scope)
### py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.pyi
@@ -91,6 +91,7 @@ class DeviceInfoResponse(google.protobuf.message.Message):
BOOTLOADER_VERSION_FIELD_NUMBER: builtins.int
LANGUAGE_FIELD_NUMBER: builtins.int
SUPPORTED_LANGUAGES_FIELD_NUMBER: builtins.int
+ STAGE0_VERSION_FIELD_NUMBER: builtins.int
name: builtins.str
initialized: builtins.bool
version: builtins.str
@@ -106,6 +107,8 @@ class DeviceInfoResponse(google.protobuf.message.Message):
"""Marketing version of the installed stage1 bootloader. Not present on legacy bootloaders."""
language: builtins.str
"""Current UI language code, e.g. "en" or "de". Empty on firmware without language support."""
+ stage0_version: builtins.int
+ """Image version of the installed stage0. Not present if no stage0 is installed."""
@property
def bluetooth(self) -> global___DeviceInfoResponse.Bluetooth:
"""Only present in Bluetooth-enabled devices."""
@@ -128,13 +131,16 @@ class DeviceInfoResponse(google.protobuf.message.Message):
bootloader_version: builtins.str | None = ...,
language: builtins.str = ...,
supported_languages: collections.abc.Iterable[builtins.str] | None = ...,
+ stage0_version: builtins.int | None = ...,
) -> None: ...
- def HasField(self, field_name: typing.Literal["_bluetooth", b"_bluetooth", "_bootloader_version", b"_bootloader_version", "bluetooth", b"bluetooth", "bootloader_version", b"bootloader_version"]) -> builtins.bool: ...
- def ClearField(self, field_name: typing.Literal["_bluetooth", b"_bluetooth", "_bootloader_version", b"_bootloader_version", "bluetooth", b"bluetooth", "bootloader_version", b"bootloader_version", "initialized", b"initialized", "language", b"language", "mnemonic_passphrase_enabled", b"mnemonic_passphrase_enabled", "monotonic_increments_remaining", b"monotonic_increments_remaining", "name", b"name", "password_stretching_algo", b"password_stretching_algo", "securechip_model", b"securechip_model", "supported_languages", b"supported_languages", "version", b"version"]) -> None: ...
+ def HasField(self, field_name: typing.Literal["_bluetooth", b"_bluetooth", "_bootloader_version", b"_bootloader_version", "_stage0_version", b"_stage0_version", "bluetooth", b"bluetooth", "bootloader_version", b"bootloader_version", "stage0_version", b"stage0_version"]) -> builtins.bool: ...
+ def ClearField(self, field_name: typing.Literal["_bluetooth", b"_bluetooth", "_bootloader_version", b"_bootloader_version", "_stage0_version", b"_stage0_version", "bluetooth", b"bluetooth", "bootloader_version", b"bootloader_version", "initialized", b"initialized", "language", b"language", "mnemonic_passphrase_enabled", b"mnemonic_passphrase_enabled", "monotonic_increments_remaining", b"monotonic_increments_remaining", "name", b"name", "password_stretching_algo", b"password_stretching_algo", "securechip_model", b"securechip_model", "stage0_version", b"stage0_version", "supported_languages", b"supported_languages", "version", b"version"]) -> None: ...
@typing.overload
def WhichOneof(self, oneof_group: typing.Literal["_bluetooth", b"_bluetooth"]) -> typing.Literal["bluetooth"] | None: ...
@typing.overload
def WhichOneof(self, oneof_group: typing.Literal["_bootloader_version", b"_bootloader_version"]) -> typing.Literal["bootloader_version"] | None: ...
+ @typing.overload
+ def WhichOneof(self, oneof_group: typing.Literal["_stage0_version", b"_stage0_version"]) -> typing.Literal["stage0_version"] | None: ...
global___DeviceInfoResponse = DeviceInfoResponse
### src/memory/memory.c
@@ -14,6 +14,7 @@
#include "util.h"
#include <rust/rust.h>
+#include "bootloader/stage0/stage0_descriptor.h"
#include "bootloader_upgrade/bootloader_upgrade.h"
#ifndef TESTING
@@ -819,6 +820,28 @@ bool memory_get_bootloader_version(uint8_t* version_out, size_t* version_len_out
return true;
}
+bool memory_get_stage0_version(uint16_t* version_out)
+{
+ if (version_out == NULL) {
+ return false;
+ }
+ *version_out = 0;
+
+#ifdef TESTING
+ const bb02_stage0_descriptor_t* descriptor =
+ (const bb02_stage0_descriptor_t*)memory_get_bootloader_stage0_descriptor_fake();
+#else
+ const bb02_stage0_descriptor_t* descriptor =
+ (const bb02_stage0_descriptor_t*)BB02_STAGE0_DESCRIPTOR_ADDR;
+#endif
+
+ if (descriptor->magic != BB02_STAGE0_DESCRIPTOR_MAGIC) {
+ return false;
+ }
+ *version_out = descriptor->stage0_version;
+ return true;
+}
+
bool memory_bootloader_set_flags(auto_enter_t auto_enter, upside_down_t upside_down)
{
chunk_shared_t chunk = {0};
### src/memory/memory.h
@@ -216,6 +216,13 @@ void memory_bootloader_hash(uint8_t* hash_out);
*/
USE_RESULT bool memory_get_bootloader_version(uint8_t* version_out, size_t* version_len_out);
+/**
+ * @param[out] version_out Receives the image version, or zero on failure if non-NULL.
+ * @return false if version_out is NULL or the descriptor magic is invalid (including when no stage0
+ * is installed). A valid descriptor with version zero returns true.
+ */
+USE_RESULT bool memory_get_stage0_version(uint16_t* version_out);
+
typedef struct {
secbool_u8 value;
} auto_enter_t;
### src/rust/bitbox-hal/src/memory.rs
@@ -73,6 +73,7 @@ pub trait Memory {
fn ble_enable(&mut self, enable: bool) -> Result<(), ()>;
fn get_active_ble_firmware_version(&mut self) -> Result<String, Error>;
fn get_bootloader_version(&mut self) -> Option<String>;
+ fn get_stage0_version(&mut self) -> Option<u16>;
fn ble_firmware_flash_chunk(
&mut self,
slot: BleFirmwareSlot,
### src/rust/bitbox-platform-host/src/memory.rs
@@ -14,6 +14,7 @@ pub struct FakeMemory {
ble_firmware_slots: [Vec<u8>; 2],
active_ble_firmware_version: String,
bootloader_version: Option<String>,
+ stage0_version: Option<u16>,
securechip_type: SecurechipType,
optiga_config_version: OptigaConfigVersion,
platform: Platform,
@@ -63,6 +64,7 @@ impl FakeMemory {
],
active_ble_firmware_version: "0.0.0".into(),
bootloader_version: None,
+ stage0_version: None,
securechip_type: SecurechipType::Optiga,
optiga_config_version: OptigaConfigVersion::V0,
platform: Platform::BitBox02,
@@ -97,6 +99,10 @@ impl FakeMemory {
self.bootloader_version = version.map(String::from);
}
+ pub fn set_stage0_version(&mut self, version: Option<u16>) {
+ self.stage0_version = version;
+ }
+
pub fn set_salt_root(&mut self, salt_root: &[u8; 32]) {
self.salt_root = *salt_root;
}
@@ -144,6 +150,10 @@ impl bitbox_hal::Memory for FakeMemory {
self.bootloader_version.clone()
}
+ fn get_stage0_version(&mut self) -> Option<u16> {
+ self.stage0_version
+ }
+
fn ble_firmware_flash_chunk(
&mut self,
slot: BleFirmwareSlot,
### src/rust/bitbox-proto/src/generated/shiftcrypto.bitbox02.rs
@@ -130,6 +130,9 @@ pub struct DeviceInfoResponse {
/// Empty on firmware without supported-language reporting.
#[prost(string, repeated, tag = "11")]
pub supported_languages: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
+ /// Image version of the installed stage0. Not present if no stage0 is installed.
+ #[prost(uint32, optional, tag = "12")]
+ pub stage0_version: ::core::option::Option<u32>,
}
/// Nested message and enum types in `DeviceInfoResponse`.
pub mod device_info_response {
### src/rust/bitbox02-rust/src/hww/api/device_info.rs
@@ -54,12 +54,14 @@ pub async fn process(hal: &mut impl crate::hal::Hal) -> Result<Response, Error>
hal_memory::PasswordStretchAlgo::V1 => "V2".into(),
},
bootloader_version: hal.memory().get_bootloader_version(),
+ stage0_version: hal.memory().get_stage0_version().map(u32::from),
}))
}
#[cfg(test)]
mod tests {
use super::*;
+ use prost::Message;
use crate::hal::testing::TestingHal;
@@ -102,4 +104,20 @@ mod tests {
hal.memory.set_bootloader_version(None);
assert_eq!(_device_info(&mut hal).await.bootloader_version, None);
}
+
+ #[async_test::test]
+ async fn test_process_stage0_version() {
+ let mut hal = TestingHal::new();
+ assert_eq!(_device_info(&mut hal).await.stage0_version, None);
+
+ for version in [Some(1), Some(0), Some(u16::MAX), None] {
+ hal.memory.set_stage0_version(version);
+ let info = _device_info(&mut hal).await;
+ assert_eq!(info.stage0_version, version.map(u32::from));
+
+ let encoded = info.encode_to_vec();
+ let decoded = pb::DeviceInfoResponse::decode(encoded.as_slice()).unwrap();
+ assert_eq!(decoded.stage0_version, version.map(u32::from));
+ }
+ }
}
### src/rust/bitbox02-sys/build.rs
@@ -114,6 +114,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"memory_get_salt_root",
"memory_get_securechip_type",
"memory_get_seed_birthdate",
+ "memory_get_stage0_version",
"memory_is_initialized",
"memory_is_mnemonic_passphrase_enabled",
"memory_is_seeded",
### src/rust/bitbox02/src/hal/memory.rs
@@ -118,6 +118,10 @@ impl Memory for BitBox02Memory {
crate::memory::get_bootloader_version()
}
+ fn get_stage0_version(&mut self) -> Option<u16> {
+ crate::memory::get_stage0_version()
+ }
+
fn ble_firmware_flash_chunk(
&mut self,
slot: BleFirmwareSlot,
### src/rust/bitbox02/src/memory.rs
@@ -117,6 +117,15 @@ pub fn get_bootloader_version() -> Option<String> {
)
}
+pub fn get_stage0_version() -> Option<u16> {
+ let mut version = 0u16;
+ if unsafe { bitbox02_sys::memory_get_stage0_version(&mut version) } {
+ Some(version)
+ } else {
+ None
+ }
+}
+
pub fn get_attestation_pubkey_and_certificate(
device_pubkey: &mut [u8; 64],
certificate: &mut [u8; 64],
### src/rust/bitbox03/src/memory.rs
@@ -23,6 +23,10 @@ impl hal::memory::Memory for BitBox03Memory {
None
}
+ fn get_stage0_version(&mut self) -> Option<u16> {
+ None
+ }
+
fn ble_firmware_flash_chunk(
&mut self,
_slot: bitbox_hal::memory::BleFirmwareSlot,
### test/hardware-fakes/include/fake_memory.h
@@ -21,4 +21,6 @@ void memory_bootloader_hash_fake(uint8_t* hash_out);
void memory_set_bootloader_hash_fake(const uint8_t* fake_hash);
const uint8_t* memory_get_bootloader_stage1_header_fake(void);
void memory_set_bootloader_stage1_header_fake(const uint8_t* header, size_t header_len);
+const uint8_t* memory_get_bootloader_stage0_descriptor_fake(void);
+void memory_set_bootloader_stage0_descriptor_fake(const uint8_t* descriptor, size_t descriptor_len);
#endif
### test/hardware-fakes/src/fake_memory.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
+#include <bootloader/stage0/stage0_descriptor.h>
#include <bootloader_upgrade/bootloader_upgrade.h>
#include <fake_memory.h>
#include <flags.h>
@@ -19,6 +20,7 @@ static uint8_t _memory_shared_data[FLASH_SHARED_DATA_LEN] = {0};
static uint8_t _memory_app_data[FLASH_APPDATA_LEN] = {0};
static uint8_t _memory_smarteeprom[SMARTEEPROM_RESERVED_FLASH_PAGES * FLASH_PAGE_SIZE] = {0};
static bb02_stage1_header_t _bootloader_stage1_header = {0};
+static bb02_stage0_descriptor_t _bootloader_stage0_descriptor = {0};
static void _init_file_if_needed(
const char* base_path,
@@ -54,6 +56,7 @@ void fake_memory_factoryreset(void)
memset(_memory_app_data, 0xff, sizeof(_memory_app_data));
memset(_memory_smarteeprom, 0xff, sizeof(_memory_smarteeprom));
memset(&_bootloader_stage1_header, 0, sizeof(_bootloader_stage1_header));
+ memset(&_bootloader_stage0_descriptor, 0, sizeof(_bootloader_stage0_descriptor));
const char* base_path = getenv(FAKE_MEMORY_ENV_VAR);
if (base_path) {
@@ -254,3 +257,15 @@ void memory_set_bootloader_stage1_header_fake(const uint8_t* header, size_t head
assert(header_len == sizeof(_bootloader_stage1_header));
memcpy(&_bootloader_stage1_header, header, sizeof(_bootloader_stage1_header));
}
+
+const uint8_t* memory_get_bootloader_stage0_descriptor_fake(void)
+{
+ return (const uint8_t*)&_bootloader_stage0_descriptor;
+}
+
+void memory_set_bootloader_stage0_descriptor_fake(const uint8_t* descriptor, size_t descriptor_len)
+{
+ assert(descriptor != NULL);
+ assert(descriptor_len == sizeof(_bootloader_stage0_descriptor));
+ memcpy(&_bootloader_stage0_descriptor, descriptor, sizeof(_bootloader_stage0_descriptor));
+}
### test/unit-test/test_memory.c
@@ -5,6 +5,7 @@
#include <stddef.h>
#include <cmocka.h>
+#include <bootloader/stage0/stage0_descriptor.h>
#include <bootloader_upgrade/bootloader_upgrade.h>
#include <fake_memory.h>
#include <memory/memory.h>
@@ -690,6 +691,48 @@ static void _test_memory_get_bootloader_version_invalid_arguments(void** state)
assert_false(memory_get_bootloader_version(version_out, NULL));
}
+static void _test_memory_get_stage0_version(void** state)
+{
+ (void)state;
+ const uint16_t versions[] = {0, 1, BB02_STAGE0_IMAGE_VERSION + 1, UINT16_MAX};
+ for (size_t i = 0; i < sizeof(versions) / sizeof(versions[0]); i++) {
+ const bb02_stage0_descriptor_t descriptor = {
+ .stage0_version = versions[i],
+ .magic = BB02_STAGE0_DESCRIPTOR_MAGIC,
+ };
+ memory_set_bootloader_stage0_descriptor_fake(
+ (const uint8_t*)&descriptor, sizeof(descriptor));
+
+ uint16_t version = 123;
+ assert_true(memory_get_stage0_version(&version));
+ assert_int_equal(version, versions[i]);
+ }
+}
+
+static void _test_memory_get_stage0_version_invalid_magic(void** state)
+{
+ (void)state;
+ const uint32_t magic_values[] = {0, UINT32_MAX, BB02_STAGE0_DESCRIPTOR_MAGIC ^ 1u};
+ for (size_t i = 0; i < sizeof(magic_values) / sizeof(magic_values[0]); i++) {
+ const bb02_stage0_descriptor_t descriptor = {
+ .stage0_version = 42,
+ .magic = magic_values[i],
+ };
+ memory_set_bootloader_stage0_descriptor_fake(
+ (const uint8_t*)&descriptor, sizeof(descriptor));
+
+ uint16_t version = 123;
+ assert_false(memory_get_stage0_version(&version));
+ assert_int_equal(version, 0);
+ }
+}
+
+static void _test_memory_get_stage0_version_invalid_argument(void** state)
+{
+ (void)state;
+ assert_false(memory_get_stage0_version(NULL));
+}
+
static void _test_memory_set_attestation_device_pubkey(void** state)
{
EMPTYCHUNK(empty_chunk);
@@ -784,6 +827,9 @@ int main(void)
cmocka_unit_test(_test_memory_get_bootloader_version_invalid_magic),
cmocka_unit_test(_test_memory_get_bootloader_version_invalid_length),
cmocka_unit_test(_test_memory_get_bootloader_version_invalid_arguments),
+ cmocka_unit_test(_test_memory_get_stage0_version),
+ cmocka_unit_test(_test_memory_get_stage0_version_invalid_magic),
+ cmocka_unit_test(_test_memory_get_stage0_version_invalid_argument),
cmocka_unit_test(_test_memory_set_attestation_device_pubkey),
cmocka_unit_test(_test_memory_set_attestation_certificate),
};Why this scored 19/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.