37#include "status_words.h"
49#if defined(HAVE_ADDRESS_BOOK) && defined(HAVE_ADDRESS_BOOK_LEDGER_ACCOUNT)
52#define STRUCT_VERSION 0x01
65#define EDIT_LEDGER_ACCOUNT_TAGS(X) \
66 X(0x01, TAG_STRUCTURE_TYPE, handle_struct_type, ENFORCE_UNIQUE_TAG) \
67 X(0x02, TAG_STRUCTURE_VERSION, handle_struct_version, ENFORCE_UNIQUE_TAG) \
68 X(0xf0, TAG_CONTACT_NAME, handle_contact_name, ENFORCE_UNIQUE_TAG) \
69 X(0xf3, TAG_PREVIOUS_NAME, handle_previous_name, ENFORCE_UNIQUE_TAG) \
70 X(0x69, TAG_DERIVATION_PATH, handle_derivation_path, ENFORCE_UNIQUE_TAG) \
71 X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
72 X(0x29, TAG_HMAC_PROOF, handle_hmac_proof, ENFORCE_UNIQUE_TAG) \
73 X(0x51, TAG_BLOCKCHAIN_FAMILY, handle_blockchain_family, ENFORCE_UNIQUE_TAG)
92 PRINTF(
"[Edit Ledger Account] Invalid STRUCTURE_TYPE value\n");
111 PRINTF(
"[Edit Ledger Account] Invalid STRUCTURE_VERSION value\n");
131 PRINTF(
"CONTACT_NAME: failed to parse\n");
150 PRINTF(
"PREVIOUS_NAME: failed to parse\n");
212 PRINTF(
"[Edit Ledger Account] HMAC_PROOF: invalid length (expected %d bytes)\n",
232 TAG_STRUCTURE_VERSION,
236 TAG_BLOCKCHAIN_FAMILY,
239 PRINTF(
"Missing mandatory fields in Edit Ledger Account descriptor!\n");
242 if (context->edit->ledger_account.blockchain_family ==
FAMILY_ETHEREUM) {
245 PRINTF(
"Missing CHAIN_ID for Ethereum family in Edit Ledger Account descriptor!\n");
263 PRINTF(
"****************************************************************************\n");
264 PRINTF(
"[Edit Ledger Account] - Retrieved Descriptor:\n");
266 PRINTF(
"[Edit Ledger Account] - New name: %s\n",
269 PRINTF(
"[Edit Ledger Account] - Derivation path[%d]: %s\n",
274 PRINTF(
"[Edit Ledger Account] - Derivation path length[%d] (failed to format)\n",
277 PRINTF(
"[Edit Ledger Account] - Blockchain family: %s\n",
280 PRINTF(
"[Edit Ledger Account] - Chain ID: %llu\n",
295 uint8_t hmac_proof[CX_SHA256_SIZE] = {0};
298 (
const char *)
g_ab_payload.edit_ledger_account.ledger_account.account_name,
299 &
g_ab_payload.edit_ledger_account.ledger_account.bip32_path,
300 g_ab_payload.edit_ledger_account.ledger_account.blockchain_family,
301 g_ab_payload.edit_ledger_account.ledger_account.chain_id,
303 PRINTF(
"[Edit Ledger Account] Error: Failed to compute new HMAC proof\n");
308 explicit_bzero(hmac_proof,
sizeof(hmac_proof));
325 PRINTF(
"[Edit Ledger Account] Error: Failed to build and send HMAC proof\n");
346 const buffer_t payload = {.ptr = buffer_in, .size = buffer_in_length};
354 if (!edit_ledger_account_tlv_parser(&payload, &ctx, &ctx.
received_tags)) {
355 PRINTF(
"[Edit Ledger Account] TLV parsing failed\n");
356 return SWO_INCORRECT_DATA;
359 return SWO_INCORRECT_DATA;
366 &
g_ab_payload.edit_ledger_account.ledger_account.bip32_path,
367 g_ab_payload.edit_ledger_account.ledger_account.blockchain_family,
368 g_ab_payload.edit_ledger_account.ledger_account.chain_id,
370 PRINTF(
"[Edit Ledger Account] HMAC proof verification failed\n");
371 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
376 PRINTF(
"[Edit Ledger Account] Coin-app rejected edit\n");
377 return SWO_INCORRECT_DATA;
382 return SWO_NO_RESPONSE;
void address_book_finalize_review(bool success, const char *successMsg, const char *errorMsg, nbgl_callback_t finalize)
Common handling of a confirmed Address Book review's outcome.
void address_book_handle_review_rejected(nbgl_callback_t finalize)
Common handling of a rejected Address Book review.
bool address_book_handle_blockchain_family(const tlv_data_t *data, blockchain_family_e *family)
Generic handler for blockchain family.
bool address_book_handle_derivation_path(const tlv_data_t *data, path_bip32_t *bip32_path)
Generic handler for BIP32 derivation path.
ab_payload_u g_ab_payload
bool address_book_handle_printable_string(const tlv_data_t *data, char *output_buffer, size_t buffer_size)
Generic handler for printable string extraction.
bool address_book_handle_chain_id(const tlv_data_t *data, uint64_t *chain_id)
Generic handler for chain ID.
bool address_book_send_hmac_proof(uint8_t type, const uint8_t hmac_proof[CX_SHA256_SIZE])
Send an HMAC proof response for Edit operations.
bool address_book_compute_hmac_proof_ledger_account(const char *name, const path_bip32_t *bip32_path, blockchain_family_e family, uint64_t chain_id, uint8_t hmac_out[CX_SHA256_SIZE])
Compute an HMAC-SHA256 Proof of Registration for a Ledger Account.
bool address_book_verify_hmac_proof_ledger_account(const char *name, const path_bip32_t *bip32_path, blockchain_family_e family, uint64_t chain_id, const uint8_t hmac_expected[CX_SHA256_SIZE])
Verify an HMAC Proof of Registration for a Ledger Account.
void on_edit_ledger_account_applied(const edit_ledger_account_t *edit)
Notification that a Ledger Account edit was successfully applied.
bool handle_check_edit_ledger_account(edit_ledger_account_t *params)
Handle called to validate the Edit Ledger Account parameters.
void display_register_ledger_account_review(nbgl_choiceCallback_t choice_callback)
Handle called to display the Ledger Account registration review screen.
void finalize_ui_ledger_account(void)
Handle called to finalize the UI flow for a Ledger Account operation.
bool bip32_path_format_simple(path_bip32_t *bip32, char *out, size_t out_len)
Format a BIP32 path as a string.
#define TYPE_EDIT_LEDGER_ACCOUNT
static bool handle_contact_name(const tlv_data_t *data, void *context_ptr)
Handler for tag CONTACT_NAME.
static bool handle_blockchain_family(const tlv_data_t *data, void *context_ptr)
Handler for tag BLOCKCHAIN_FAMILY.
static bool handle_derivation_path(const tlv_data_t *data, void *context_ptr)
Handler for tag DERIVATION_PATH.
static bool handle_hmac_proof(const tlv_data_t *data, void *context_ptr)
Handler for tag HMAC_PROOF.
static void review_choice(bool confirm)
NBGL callback invoked after the user confirms or rejects the edit.
static bool handle_previous_name(const tlv_data_t *data, void *context_ptr)
Handler for tag PREVIOUS_NAME.
static bool handle_struct_type(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_TYPE.
static bool handle_chain_id(const tlv_data_t *data, void *context_ptr)
Handler for tag CHAIN_ID.
static bool build_and_send_response(void)
Build and send response.
static bool handle_struct_version(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_VERSION.
#define EDIT_LEDGER_ACCOUNT_TAGS(X)
bolos_err_t edit_ledger_account(uint8_t *buffer_in, size_t buffer_in_length)
Edit the name of an existing Ledger Account.
static bool verify_fields(const s_edit_ledger_account_ctx *context)
Check that all mandatory TLV tags were received.
static void print_payload(const s_edit_ledger_account_ctx *context)
Print the received descriptor.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
Data extracted from a Rename Ledger Account TLV payload.
char old_account_name[ACCOUNT_NAME_LENGTH]
Name being replaced.
ledger_account_t ledger_account
New account (account_name = new name).
char account_name[ACCOUNT_NAME_LENGTH]
blockchain_family_e blockchain_family
TLV_reception_t received_tags
edit_ledger_account_t * edit
uint8_t hmac_proof[CX_SHA256_SIZE]
HMAC proof of the previous registration.
bool tlv_enforce_u8_value(const tlv_data_t *data, uint8_t expected_value)
Enforce that a TLV data contains the expected uint8 value.
bool get_buffer_from_tlv_data(const tlv_data_t *data, buffer_t *out, uint16_t min_size, uint16_t max_size)
Extract a sized buffer from TLV data (zero-copy).
TLV_reception_internal_t TLV_reception_t
#define DEFINE_TLV_PARSER(TAG_LIST, COMMON_HANDLER, PARSE_FUNCTION_NAME)
Creates a parser function for a given TLV use case.
struct tlv_data_s tlv_data_t
#define TLV_CHECK_RECEIVED_TAGS(received,...)