Skip to content

Commit eb96b5e

Browse files
committed
commander: separate main and hidden wallet backup checks
Before, checking the backup recovery password when logged in using the main password would succeed for both the main and the hidden wallet recovery password. This was the only way to check the hidden wallet password, as everything sd-card was in the hidden wallet. With this commit, one can only check the main recovery password in the main wallet, and the hidden recovery password when in the hidden wallet.
1 parent 0d0f207 commit eb96b5e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/commander.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,15 @@ static int commander_process_backup_check(const char *key, const char *filename,
305305
if (wallet_generate_node(key, seed, &node) == DBB_ERROR) {
306306
ret = DBB_ERROR;
307307
} 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];
308312
uint8_t main_ok = MEMEQ(node.private_key, memory_master_hww(NULL), MEM_PAGE_LEN) &&
309313
MEMEQ(node.chain_code, memory_master_hww_chaincode(NULL), MEM_PAGE_LEN);
310314
uint8_t hidden_ok = MEMEQ(node.private_key, memory_hidden_hww(NULL), MEM_PAGE_LEN) &&
311315
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
313317
}
314318
utils_zero(seed, sizeof(seed));
315319
}

tests/tests_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,18 +607,22 @@ static void tests_seed_xpub_backup(void)
607607
ASSERT_SUCCESS;
608608

609609
{
610-
// Check backup should also work with the hidden password.
611610
char set_hidden_wallet_cmd[512];
612611
snprintf(set_hidden_wallet_cmd, sizeof(set_hidden_wallet_cmd),
613612
"{\"%s\":\"%s\",\"%s\":\"%s\"}", cmd_str(CMD_password),
614613
hidden_pwd, cmd_str(CMD_key), "hiddenpassword");
615614
api_format_send_cmd(cmd_str(CMD_hidden_password), set_hidden_wallet_cmd, KEY_STANDARD);
616615
ASSERT_SUCCESS;
617616

618-
617+
// Check backup of hidden wallet should not work using the main device password.
619618
snprintf(check, sizeof(check), "{\"check\":\"%s\", \"key\":\"hiddenpassword\"}",
620619
filename);
621620
api_format_send_cmd(cmd_str(CMD_backup), check, KEY_STANDARD);
621+
ASSERT_REPORT_HAS(flag_msg(DBB_ERR_SD_NO_MATCH));
622+
// Works with the hidden wallet device password.
623+
snprintf(check, sizeof(check), "{\"check\":\"%s\", \"key\":\"hiddenpassword\"}",
624+
filename);
625+
api_format_send_cmd(cmd_str(CMD_backup), check, KEY_HIDDEN);
622626
ASSERT_SUCCESS;
623627
}
624628

0 commit comments

Comments
 (0)