@@ -305,11 +305,15 @@ static int commander_process_backup_check(const char *key, const char *filename,
305
305
if (wallet_generate_node (key , seed , & node ) == DBB_ERROR ) {
306
306
ret = DBB_ERROR ;
307
307
} else {
308
+ uint8_t is_hidden = wallet_is_hidden ();
309
+ // constant time !is_hidden
310
+ uint8_t negated [] = {1 , 0 };
311
+ uint8_t is_main = negated [is_hidden ];
308
312
uint8_t main_ok = MEMEQ (node .private_key , memory_master_hww (NULL ), MEM_PAGE_LEN ) &&
309
313
MEMEQ (node .chain_code , memory_master_hww_chaincode (NULL ), MEM_PAGE_LEN );
310
314
uint8_t hidden_ok = MEMEQ (node .private_key , memory_hidden_hww (NULL ), MEM_PAGE_LEN ) &&
311
315
MEMEQ (node .chain_code , memory_hidden_hww_chaincode (NULL ), MEM_PAGE_LEN );
312
- ret = (main_ok | hidden_ok ) ? DBB_OK : DBB_ERROR ; // bitwise for constant time
316
+ ret = (is_main & main_ok ) | ( is_hidden & hidden_ok ) ? DBB_OK : DBB_ERROR ; // bitwise for constant time
313
317
}
314
318
utils_zero (seed , sizeof (seed ));
315
319
}
@@ -395,11 +399,6 @@ static void commander_process_backup(yajl_val json_node)
395
399
char source [MAX (MAX (strlens (attr_str (ATTR_U2F )), strlens (attr_str (ATTR_HWW ))),
396
400
strlens (attr_str (ATTR_all ))) + 1 ];
397
401
398
- if (wallet_is_locked ()) {
399
- commander_fill_report (cmd_str (CMD_backup ), NULL , DBB_ERR_IO_LOCKED );
400
- return ;
401
- }
402
-
403
402
if (strlens (value )) {
404
403
if (STREQ (value , attr_str (ATTR_list ))) {
405
404
sd_list (CMD_backup );
@@ -410,17 +409,6 @@ static void commander_process_backup(yajl_val json_node)
410
409
return ;
411
410
}
412
411
413
- if (strlens (erase )) {
414
- // Erase single file
415
- int status = touch_button_press (TOUCH_LONG_WARN );
416
- if (status == DBB_TOUCHED ) {
417
- sd_erase (CMD_backup , erase );
418
- } else {
419
- commander_fill_report (cmd_str (CMD_backup ), NULL , status );
420
- }
421
- return ;
422
- }
423
-
424
412
if (strlens (source_y )) {
425
413
snprintf (source , sizeof (source ), "%s" , source_y );
426
414
} else {
@@ -432,12 +420,6 @@ static void commander_process_backup(yajl_val json_node)
432
420
}
433
421
}
434
422
435
- if (!strlens (key ) && !STREQ (source , attr_str (ATTR_U2F ))) {
436
- // Exit if backing up HWW but no key given
437
- commander_fill_report (cmd_str (CMD_seed ), NULL , DBB_ERR_SD_KEY );
438
- return ;
439
- }
440
-
441
423
if (check ) {
442
424
// Verify existing backup
443
425
if (STREQ (source , attr_str (ATTR_all ))) {
@@ -448,6 +430,30 @@ static void commander_process_backup(yajl_val json_node)
448
430
return ;
449
431
}
450
432
433
+
434
+ if (wallet_is_locked ()) {
435
+ commander_fill_report (cmd_str (CMD_backup ), NULL , DBB_ERR_IO_LOCKED );
436
+ return ;
437
+ }
438
+
439
+ if (strlens (erase )) {
440
+ // Erase single file
441
+ int status = touch_button_press (TOUCH_LONG_WARN );
442
+ if (status == DBB_TOUCHED ) {
443
+ sd_erase (CMD_backup , erase );
444
+ } else {
445
+ commander_fill_report (cmd_str (CMD_backup ), NULL , status );
446
+ }
447
+ return ;
448
+ }
449
+
450
+
451
+ if (!strlens (key ) && !STREQ (source , attr_str (ATTR_U2F ))) {
452
+ // Exit if backing up HWW but no key given
453
+ commander_fill_report (cmd_str (CMD_seed ), NULL , DBB_ERR_SD_KEY );
454
+ return ;
455
+ }
456
+
451
457
if (filename ) {
452
458
// Create new backup
453
459
commander_process_backup_create (key , filename , source );
0 commit comments