Skip to content

Commit b1a010a

Browse files
committed
Merge branch 'pr/106'
2 parents e0cd2a1 + 4bff7a9 commit b1a010a

File tree

22 files changed

+392
-229
lines changed

22 files changed

+392
-229
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/py/bitbox02/generated linguist-generated=true
2-
/py/bitbox02u2f/generated linguist-generated=true
1+
/py/bitbox02/generated/* linguist-generated=true
2+
/py/bitbox02u2f/generated/* linguist-generated=true

messages/hww.proto

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ message CreateBackupRequest {
6262

6363
message RestoreBackupRequest {
6464
string id = 1;
65+
uint32 timestamp = 2;
66+
int32 timezone_offset = 3;
6567
}
6668

6769
message ListBackupsRequest {
@@ -129,7 +131,7 @@ message PubResponse {
129131
message BackupInfo {
130132
string id = 1;
131133
uint32 timestamp = 2;
132-
uint32 timezone_offset = 3;
134+
// uint32 timezone_offset = 3;
133135
string name = 4;
134136
}
135137

@@ -257,7 +259,10 @@ message ETHResponse {
257259

258260
message ResetRequest {}
259261

260-
message RestoreFromMnemonicRequest {}
262+
message RestoreFromMnemonicRequest {
263+
uint32 timestamp = 1;
264+
int32 timezone_offset = 2;
265+
}
261266

262267
message Request {
263268
oneof request {

py/bitbox02/bitbox02.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def restore_backup(self, backup_id: str) -> bool:
349349
# pylint: disable=no-member
350350
request = hww.Request()
351351
request.restore_backup.id = backup_id
352+
request.restore_backup.timestamp = int(time.time())
353+
request.restore_backup.timezone_offset = time.localtime().tm_gmtoff
352354
try:
353355
self._msg_query(request, expected_response="success")
354356
except Bitbox02Exception as err:
@@ -695,7 +697,11 @@ def restore_from_mnemonic(self) -> bool:
695697
"""
696698
request = hww.Request()
697699
# pylint: disable=no-member
698-
request.restore_from_mnemonic.CopyFrom(hww.RestoreFromMnemonicRequest())
700+
request.restore_from_mnemonic.CopyFrom(
701+
hww.RestoreFromMnemonicRequest(
702+
timestamp=int(time.time()), timezone_offset=time.localtime().tm_gmtoff
703+
)
704+
)
699705
try:
700706
self._msg_query(request)
701707
except Bitbox02Exception as err:

py/bitbox02/generated/hww_pb2.py

Lines changed: 103 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/generated/hww_pb2.pyi

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02u2f/generated/hww_pb2.py

Lines changed: 103 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02u2f/generated/hww_pb2.pyi

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ set(DBB-FIRMWARE-SOURCES
2424
${CMAKE_SOURCE_DIR}/src/util.c
2525
${CMAKE_SOURCE_DIR}/src/sd.c
2626
${CMAKE_SOURCE_DIR}/src/hww.c
27-
${CMAKE_SOURCE_DIR}/src/u2f.c
28-
${CMAKE_SOURCE_DIR}/src/u2f/u2f_app.c
2927
${CMAKE_SOURCE_DIR}/src/memory.c
3028
${CMAKE_SOURCE_DIR}/src/salt.c
3129
${CMAKE_SOURCE_DIR}/src/i2c_ecc.c
@@ -40,6 +38,7 @@ set(DBB-FIRMWARE-SOURCES
4038
${CMAKE_SOURCE_DIR}/src/workflow/workflow.c
4139
${CMAKE_SOURCE_DIR}/src/workflow/trinary_input.c
4240
${CMAKE_SOURCE_DIR}/src/workflow/confirm.c
41+
${CMAKE_SOURCE_DIR}/src/workflow/confirm_time.c
4342
${CMAKE_SOURCE_DIR}/src/workflow/status.c
4443
${CMAKE_SOURCE_DIR}/src/workflow/password.c
4544
${CMAKE_SOURCE_DIR}/src/workflow/password_enter.c
@@ -290,6 +289,12 @@ set_source_files_properties(
290289
COMPILE_FLAGS "-Wno-switch-default"
291290
)
292291

292+
set(FIRMWARE-U2F-SOURCES
293+
${CMAKE_SOURCE_DIR}/src/u2f.c
294+
${CMAKE_SOURCE_DIR}/src/u2f/u2f_app.c
295+
)
296+
set(FIRMWARE-U2F-SOURCES ${FIRMWARE-U2F-SOURCES} PARENT_SCOPE)
297+
293298
#-----------------------------------------------------------------------------
294299
# Include directories
295300

@@ -502,8 +507,10 @@ if(CMAKE_CROSSCOMPILING)
502507

503508
target_sources(firmware.elf PRIVATE firmware.c)
504509
target_compile_definitions(firmware.elf PRIVATE APP_BTC APP_LTC APP_ETH APP_U2F)
510+
target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES})
505511

506512
target_sources(firmware-semihosting.elf PRIVATE firmware.c)
513+
target_sources(firmware-semihosting.elf PRIVATE ${FIRMWARE-U2F-SOURCES})
507514
# Select an implementation of the system calls that can communicate with the debugger
508515
target_compile_options(firmware-semihosting.elf PRIVATE --specs=rdimon.specs)
509516
target_link_libraries(firmware-semihosting.elf PRIVATE --specs=rdimon.specs)

src/commander/commander.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ static commander_error_t _api_reset(void)
219219
return COMMANDER_OK;
220220
}
221221

222-
static commander_error_t _api_restore_from_mnemonic(void)
222+
static commander_error_t _api_restore_from_mnemonic(const RestoreFromMnemonicRequest* request)
223223
{
224-
if (!workflow_restore_from_mnemonic()) {
224+
if (!workflow_restore_from_mnemonic(request)) {
225225
return COMMANDER_ERR_GENERIC;
226226
}
227227
return COMMANDER_OK;
@@ -317,7 +317,7 @@ static commander_error_t _api_process(const Request* request, Response* response
317317
return _api_reset();
318318
case Request_restore_from_mnemonic_tag:
319319
response->which_response = Response_success_tag;
320-
return _api_restore_from_mnemonic();
320+
return _api_restore_from_mnemonic(&(request->request.restore_from_mnemonic));
321321
default:
322322
screen_print_debug("command unknown", 1000);
323323
return COMMANDER_ERR_INVALID_INPUT;

src/securechip/securechip.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ bool securechip_ecc_unsafe_sign(const uint8_t* priv_key, const uint8_t* msg, uin
660660
return true;
661661
}
662662

663+
#if defined(APP_U2F) || defined(FACTORYSETUP)
663664
// Read a "standard" sized block from a data slot (must be 32 bytes)
664665
static ATCA_STATUS _read_data_slot_block(uint8_t* bytes, uint16_t slot, uint8_t block)
665666
{
@@ -688,23 +689,25 @@ static ATCA_STATUS _write_data_slot_block(uint8_t* bytes, uint16_t slot, uint8_t
688689
return atcab_write_enc(slot, block, bytes, encryption_key, SECURECHIP_SLOT_ENCRYPTION_KEY);
689690
}
690691

691-
bool securechip_u2f_counter_set(uint32_t value)
692+
bool securechip_u2f_counter_set(uint32_t counter)
692693
{
693694
data_9_0_t data = {0};
694695
ATCA_STATUS result = _read_data_slot_block(&data.bytes, SECURECHIP_SLOT_DATA0, 0);
695696
if (result != ATCA_SUCCESS) {
696697
return false;
697698
}
698699

699-
data.fields.u2f_counter = value;
700+
data.fields.u2f_counter = counter;
700701

701702
result = _write_data_slot_block(&data.bytes, SECURECHIP_SLOT_DATA0, 0);
702703
if (result != ATCA_SUCCESS) {
703704
return false;
704705
}
705706
return true;
706707
}
708+
#endif
707709

710+
#if defined(APP_U2F)
708711
bool securechip_u2f_counter_inc(uint32_t* counter)
709712
{
710713
data_9_0_t data = {0};
@@ -722,3 +725,4 @@ bool securechip_u2f_counter_inc(uint32_t* counter)
722725
}
723726
return true;
724727
}
728+
#endif

0 commit comments

Comments
 (0)