Skip to content

Commit 0365f72

Browse files
committed
api: return securechip model in DeviceInfo
1 parent c842929 commit 0365f72

File tree

9 files changed

+52
-4
lines changed

9 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44
- Attempt to fix flaky SD behavior
5+
- Add securechip_model to DeviceInfo: ATECCC608A or ATECC608B.
56

67
## 9.5.0 [released 2021-03-10]
78
- RestoreFrommnemonic: ported to Rust. Will now return UserAbortError on user abort instead of GenericError.

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ endif()
8989
#
9090
# Versions MUST contain three parts and start with lowercase 'v'.
9191
# Example 'v1.0.0'. They MUST not contain a pre-release label such as '-beta'.
92-
set(FIRMWARE_VERSION "v9.5.0")
93-
set(FIRMWARE_BTC_ONLY_VERSION "v9.5.0")
94-
set(FIRMWARE_BITBOXBASE_VERSION "v9.5.0")
92+
set(FIRMWARE_VERSION "v9.6.0")
93+
set(FIRMWARE_BTC_ONLY_VERSION "v9.6.0")
94+
set(FIRMWARE_BITBOXBASE_VERSION "v9.6.0")
9595
set(BOOTLOADER_VERSION "v1.0.3")
9696

9797
find_package(PythonInterp 3.6 REQUIRED)

py/bitbox02/bitbox02/bitbox02/bitbox02.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ def device_info(self) -> Dict[str, Any]:
135135
device_info_request = bitbox02_system.DeviceInfoRequest()
136136
request.device_info.CopyFrom(device_info_request)
137137
response = self._msg_query(request, expected_response="device_info")
138-
return {
138+
result = {
139139
"name": response.device_info.name,
140140
"version": response.device_info.version,
141141
"initialized": response.device_info.initialized,
142142
"mnemonic_passphrase_enabled": response.device_info.mnemonic_passphrase_enabled,
143143
"monotonic_increments_remaining": response.device_info.monotonic_increments_remaining,
144144
}
145+
if self.version >= semver.VersionInfo(9, 6, 0):
146+
result["securechip_model"] = response.device_info.securechip_model
147+
148+
return result
145149

146150
def set_device_name(self, device_name: str) -> None:
147151
# pylint: disable=no-member

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ add_custom_target(rust-bindgen
344344
--whitelist-function securechip_attestation_sign
345345
--whitelist-function securechip_monotonic_increments_remaining
346346
--whitelist-function securechip_u2f_counter_set
347+
--whitelist-function securechip_model
348+
--rustified-enum securechip_model_t
347349
--whitelist-function keystore_is_locked
348350
--whitelist-function keystore_unlock
349351
--whitelist-function keystore_unlock_bip39

src/rust/bitbox02-rust/src/hww/api/device_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ pub fn process() -> Result<Response, Error> {
2626
version: bitbox02::version_short().into(),
2727
mnemonic_passphrase_enabled: memory::is_mnemonic_passphrase_enabled(),
2828
monotonic_increments_remaining: securechip::monotonic_increments_remaining()?,
29+
securechip_model: match securechip::model()? {
30+
securechip::Model::SECURECHIP_ATECC608A => "ATECC608A".into(),
31+
securechip::Model::SECURECHIP_ATECC608B => "ATECC608B".into(),
32+
},
2933
}))
3034
}

src/rust/bitbox02/src/securechip.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
pub use bitbox02_sys::securechip_model_t as Model;
16+
1517
pub fn attestation_sign(challenge: &[u8; 32], signature: &mut [u8; 64]) -> Result<(), ()> {
1618
match unsafe {
1719
bitbox02_sys::securechip_attestation_sign(challenge.as_ptr(), signature.as_mut_ptr())
@@ -49,3 +51,11 @@ pub fn u2f_counter_set(counter: u32) -> Result<(), ()> {
4951
pub fn u2f_counter_set(_counter: u32) -> Result<(), ()> {
5052
unimplemented!();
5153
}
54+
55+
pub fn model() -> Result<Model, ()> {
56+
let mut ver = core::mem::MaybeUninit::uninit();
57+
match unsafe { bitbox02_sys::securechip_model(ver.as_mut_ptr()) } {
58+
true => Ok(unsafe { ver.assume_init() }),
59+
false => Err(()),
60+
}
61+
}

src/securechip/securechip.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,13 @@ bool securechip_u2f_counter_inc(uint32_t* counter)
764764
return _write_data_slot_block(&data.bytes[0], SECURECHIP_SLOT_DATA0, 0);
765765
}
766766
#endif
767+
768+
bool securechip_model(securechip_model_t* model_out)
769+
{
770+
uint8_t revision[4] = {0};
771+
if (atcab_info(revision) != ATCA_SUCCESS) {
772+
return false;
773+
}
774+
*model_out = revision[3] >= 0x03 ? SECURECHIP_ATECC608B : SECURECHIP_ATECC608A;
775+
return true;
776+
}

src/securechip/securechip.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,16 @@ USE_RESULT bool securechip_u2f_counter_set(uint32_t counter);
159159
USE_RESULT bool securechip_u2f_counter_inc(uint32_t* counter);
160160
#endif
161161

162+
typedef enum {
163+
SECURECHIP_ATECC608A,
164+
SECURECHIP_ATECC608B,
165+
} securechip_model_t;
166+
167+
/**
168+
* Output the securechip model.
169+
* @param[out] model_out securechip model
170+
* @return True if success
171+
*/
172+
USE_RESULT bool securechip_model(securechip_model_t* model_out);
173+
162174
#endif

test/unit-test/framework/mock_securechip.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ bool securechip_monotonic_increments_remaining(uint32_t* remaining_out)
7070
{
7171
return false;
7272
}
73+
74+
bool securechip_model(securechip_model_t* model_out)
75+
{
76+
return false;
77+
}

0 commit comments

Comments
 (0)