42#include "status_words.h"
54#if defined(HAVE_ADDRESS_BOOK)
57#define STRUCT_VERSION 0x01
69#define EDIT_SCOPE_TAGS(X) \
70 X(0x01, TAG_STRUCTURE_TYPE, handle_struct_type, ENFORCE_UNIQUE_TAG) \
71 X(0x02, TAG_STRUCTURE_VERSION, handle_struct_version, ENFORCE_UNIQUE_TAG) \
72 X(0xf0, TAG_CONTACT_NAME, handle_contact_name, ENFORCE_UNIQUE_TAG) \
73 X(0xf1, TAG_SCOPE, handle_scope, ENFORCE_UNIQUE_TAG) \
74 X(0xf2, TAG_ACCOUNT_IDENTIFIER, handle_identifier, ENFORCE_UNIQUE_TAG) \
75 X(0xf5, TAG_PREVIOUS_SCOPE, handle_previous_scope, ENFORCE_UNIQUE_TAG) \
76 X(0xf6, TAG_GROUP_HANDLE, handle_group_handle, ENFORCE_UNIQUE_TAG) \
77 X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
78 X(0x29, TAG_HMAC_PROOF, handle_hmac_proof, ENFORCE_UNIQUE_TAG) \
79 X(0xf7, TAG_HMAC_REST, handle_hmac_rest, ENFORCE_UNIQUE_TAG) \
80 X(0x51, TAG_BLOCKCHAIN_FAMILY, handle_blockchain_family, ENFORCE_UNIQUE_TAG)
99 PRINTF(
"[Edit Scope] Invalid STRUCTURE_TYPE value\n");
118 PRINTF(
"[Edit Scope] Invalid STRUCTURE_VERSION value\n");
138 PRINTF(
"[Edit Scope] CONTACT_NAME: failed to parse\n");
159 PRINTF(
"[Edit Scope] SCOPE: failed to parse\n");
178 PRINTF(
"[Edit Scope] IDENTIFIER: failed to extract\n");
201 PRINTF(
"[Edit Scope] PREVIOUS_SCOPE: failed to parse\n");
220 PRINTF(
"[Edit Scope] GROUP_HANDLE: invalid length (expected %d bytes)\n",
269 PRINTF(
"[Edit Scope] HMAC_PROOF: invalid length (expected %d bytes)\n", CX_SHA256_SIZE);
289 PRINTF(
"[Edit Scope] HMAC_REST: invalid length (expected %d bytes)\n", CX_SHA256_SIZE);
308 TAG_STRUCTURE_VERSION,
311 TAG_ACCOUNT_IDENTIFIER,
314 TAG_BLOCKCHAIN_FAMILY,
318 PRINTF(
"[Edit Scope] Missing mandatory fields!\n");
324 PRINTF(
"[Edit Scope] Missing CHAIN_ID for Ethereum!\n");
340 PRINTF(
"****************************************************************************\n");
341 PRINTF(
"[Edit Scope] - Retrieved Descriptor:\n");
343 PRINTF(
"[Edit Scope] - Old scope: %s\n", context->
edit->
old_scope);
345 PRINTF(
"[Edit Scope] - Blockchain family: %s\n",
362 uint8_t hmac_rest[CX_SHA256_SIZE] = {0};
371 PRINTF(
"[Edit Scope] Error: Failed to compute new HMAC_REST\n");
372 explicit_bzero(hmac_rest,
sizeof(hmac_rest));
376 explicit_bzero(hmac_rest,
sizeof(hmac_rest));
389 const char *successMsg
392 :
"Address name changed";
397 PRINTF(
"[Edit Scope] Error: Failed to build and send HMAC proof\n");
416 g_ab_ui.pairs[nbPairs].item =
"Contact name";
419 g_ab_ui.pairs[nbPairs].item = isBitcoin ?
"Old scope" :
"Old address name";
422 g_ab_ui.pairs[nbPairs].item = isBitcoin ?
"New scope" :
"New address name";
426 g_ab_ui.list.nbPairs = nbPairs;
428 "Review change to contact details",
429#ifdef SCREEN_SIZE_WALLET
446bolos_err_t
edit_scope(uint8_t *buffer_in,
size_t buffer_in_length)
448 const buffer_t payload = {.ptr = buffer_in, .size = buffer_in_length};
456 if (!edit_scope_tlv_parser(&payload, &ctx, &ctx.
received_tags)) {
457 PRINTF(
"[Edit Scope] TLV parsing failed\n");
458 return SWO_INCORRECT_DATA;
461 return SWO_INCORRECT_DATA;
467 PRINTF(
"[Edit Scope] Group handle verification failed\n");
468 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
475 PRINTF(
"[Edit Scope] HMAC_PROOF verification failed\n");
476 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
487 PRINTF(
"[Edit Scope] HMAC_REST verification failed\n");
488 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
493 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.
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.
void address_book_display_review(const nbgl_icon_details_t *icon, const char *reviewTitle, const char *confirmText, nbgl_choiceCallback_t choiceCallback)
Display a confirmation review for an Address Book operation.
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_rest(const uint8_t gid[GID_SIZE], const char *scope, const uint8_t *identifier, uint8_t identifier_len, blockchain_family_e family, uint64_t chain_id, uint8_t hmac_out[CX_SHA256_SIZE])
Compute HMAC_REST for an Identity contact.
bool address_book_verify_hmac_proof(const uint8_t gid[GID_SIZE], const char *name, const uint8_t hmac_expected[CX_SHA256_SIZE])
Verify HMAC_PROOF for an Identity contact.
bool address_book_verify_group_handle(const uint8_t group_handle[GROUP_HANDLE_SIZE], uint8_t gid_out[GID_SIZE])
Verify a group handle and extract the gid.
bool address_book_verify_hmac_rest(const uint8_t gid[GID_SIZE], const char *scope, const uint8_t *identifier, uint8_t identifier_len, blockchain_family_e family, uint64_t chain_id, const uint8_t hmac_expected[CX_SHA256_SIZE])
Verify HMAC_REST for an Identity contact.
void finalize_ui_edit_scope(void)
Handle called to finalize the UI flow for editing a scope.
void on_edit_scope_applied(const edit_scope_t *edit)
Notification that a scope edit was successfully applied.
Register / Edit Contact Name / Edit Scope / Edit Identifier.
#define GROUP_HANDLE_SIZE
group_handle = gid(32) | MAC(K_group, gid)(32)
#define IDENTIFIER_MAX_LENGTH
blockchain address or public key, raw bytes
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_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_struct_type(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_TYPE.
static bool handle_previous_scope(const tlv_data_t *data, void *context_ptr)
Handler for tag PREVIOUS_SCOPE.
static bool handle_scope(const tlv_data_t *data, void *context_ptr)
Handler for tag SCOPE.
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 void ui_display(void)
Display the Edit Scope review screen.
static bool handle_struct_version(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_VERSION.
static bool handle_identifier(const tlv_data_t *data, void *context_ptr)
Handler for tag ACCOUNT_IDENTIFIER.
#define EDIT_SCOPE_TAGS(X)
bolos_err_t edit_scope(uint8_t *buffer_in, size_t buffer_in_length)
Edit the SCOPE of an existing Identity contact.
static bool handle_group_handle(const tlv_data_t *data, void *context_ptr)
Handler for tag GROUP_HANDLE.
static void print_payload(const s_edit_scope_ctx *context)
Print the received descriptor.
static bool handle_hmac_rest(const tlv_data_t *data, void *context_ptr)
Handler for tag HMAC_REST.
static bool verify_fields(const s_edit_scope_ctx *context)
Check that all mandatory TLV tags were received.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
size_t size
Pointer to byte buffer.
Data extracted from an Edit Scope Name TLV payload.
char old_scope[SCOPE_LENGTH]
Scope being replaced.
identity_t identity
New identity (scope = new).
blockchain_family_e blockchain_family
uint64_t chain_id
Mandatory when blockchain_family == FAMILY_ETHEREUM.
uint8_t identifier[IDENTIFIER_MAX_LENGTH]
char contact_name[CONTACT_NAME_LENGTH]
uint8_t group_handle[GROUP_HANDLE_SIZE]
Group handle from wallet (verified later).
uint8_t hmac_proof[CX_SHA256_SIZE]
HMAC_PROOF — verifies contact name.
TLV_reception_t received_tags
uint8_t hmac_rest[CX_SHA256_SIZE]
HMAC_REST — verifies old scope.
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,...)