Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Update factory reset condition to ignore write attempt #451

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/interfaces/flash_interface/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ bool wallet_is_filled(uint8_t index, wallet_state *state_output) {
return false;
}

bool wallet_is_filled_with_share(uint8_t index) {
if (MAX_WALLETS_ALLOWED <= index) {
return false;
}

/* Make sure that we always work on the latest RAM instance */
get_flash_ram_instance();

wallet_state state = flash_ram_instance.wallets[index].state;
// Read card states without write attempt state
uint8_t cards_states = flash_ram_instance.wallets[index].cards_states & 0x0F;

// If wallet state state is where share is present on device and card state is
// not zero, then wallet is filled
if (((UNVERIFIED_VALID_WALLET == state) || (VALID_WALLET == state) ||
(INVALID_WALLET == state)) &&
(0x00 != cards_states)) {
return true;
}

return false;
}

/**
* @brief Save a new wallet on the flash
*
Expand Down
11 changes: 11 additions & 0 deletions common/interfaces/flash_interface/flash_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
*/
bool wallet_is_filled(uint8_t index, wallet_state *state_output);

/**
* @brief The function checks if a wallet is filled with a share based on its
* index.
*
* @param index The index required to be checked for wallet existance
*
* @return a boolean value. It returns true if the wallet at the given index is
* filled with a share, and false otherwise.
*/
bool wallet_is_filled_with_share(uint8_t index);

/**
* Update auth state and first_boot_on_update variables in firewall
*/
Expand Down
1 change: 0 additions & 1 deletion src/card_flows/card_flow_delete_wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ card_error_type_e card_flow_delete_wallet(Wallet *selected_wallet) {
// If wallet is deleted on all cards, delete from flash as well
check_card_state_and_delete_wallet(
(const char *)delete_cfg.wallet->wallet_name);
clear_wallet_data();

return error_code;
}
4 changes: 1 addition & 3 deletions src/wallet/wallet_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ uint8_t get_filled_wallet_meta_data_list(wallet_list_t *list) {
}

for (uint8_t wallet_idx = 0; wallet_idx < MAX_WALLETS_ALLOWED; wallet_idx++) {
wallet_state state = INVALID_WALLET;
if (!wallet_is_filled(wallet_idx, &state) ||
VALID_WALLET_WITHOUT_DEVICE_SHARE == state) {
if (!wallet_is_filled_with_share(wallet_idx)) {
continue;
}

Expand Down