39#include "status_words.h"
40#include "tlv_library.h"
51#if defined(HAVE_ADDRESS_BOOK)
54#define STRUCT_VERSION 0x01
59 edit_contact_name_t *edit;
60 TLV_reception_t received_tags;
61 uint8_t hmac_proof[CX_SHA256_SIZE];
62 uint8_t group_handle[GROUP_HANDLE_SIZE];
63} s_edit_contact_name_ctx;
66#define EDIT_CONTACT_NAME_TAGS(X) \
67 X(0x01, TAG_STRUCTURE_TYPE, handle_struct_type, ENFORCE_UNIQUE_TAG) \
68 X(0x02, TAG_STRUCTURE_VERSION, handle_struct_version, ENFORCE_UNIQUE_TAG) \
69 X(0xf0, TAG_CONTACT_NAME, handle_contact_name, ENFORCE_UNIQUE_TAG) \
70 X(0xf3, TAG_PREVIOUS_NAME, handle_previous_name, ENFORCE_UNIQUE_TAG) \
71 X(0xf6, TAG_GROUP_HANDLE, handle_group_handle, ENFORCE_UNIQUE_TAG) \
72 X(0x21, TAG_DERIVATION_PATH, handle_derivation_path, ENFORCE_UNIQUE_TAG) \
73 X(0x29, TAG_HMAC_PROOF, handle_hmac_proof, ENFORCE_UNIQUE_TAG)
86static bool handle_struct_type(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
89 if (!tlv_enforce_u8_value(data, TYPE_EDIT_CONTACT_NAME)) {
90 PRINTF(
"[Edit Contact Name] Invalid STRUCTURE_TYPE value\n");
103static bool handle_struct_version(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
106 if (!tlv_enforce_u8_value(data, STRUCT_VERSION)) {
107 PRINTF(
"[Edit Contact Name] Invalid STRUCTURE_VERSION value\n");
120static bool handle_contact_name(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
122 if (!address_book_handle_printable_string(
123 data, context->edit->contact_name,
sizeof(context->edit->contact_name))) {
124 PRINTF(
"[Edit Contact Name] CONTACT_NAME: failed to parse\n");
137static bool handle_previous_name(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
139 if (!address_book_handle_printable_string(
140 data, context->edit->old_contact_name,
sizeof(context->edit->old_contact_name))) {
141 PRINTF(
"[Edit Contact Name] PREVIOUS_CONTACT_NAME: failed to parse\n");
154static bool handle_group_handle(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
157 if (!get_buffer_from_tlv_data(data, &buf, GROUP_HANDLE_SIZE, GROUP_HANDLE_SIZE)) {
158 PRINTF(
"[Edit Contact Name] GROUP_HANDLE: invalid length (expected %d bytes)\n",
162 memmove(context->group_handle, buf.
ptr, GROUP_HANDLE_SIZE);
173static bool handle_derivation_path(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
175 return address_book_handle_derivation_path(data, &context->edit->bip32_path);
185static bool handle_hmac_proof(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
188 if (!get_buffer_from_tlv_data(data, &buf, CX_SHA256_SIZE, CX_SHA256_SIZE)) {
189 PRINTF(
"[Edit Contact Name] HMAC_PROOF: invalid length (expected %d bytes)\n",
193 memmove(context->hmac_proof, buf.
ptr, CX_SHA256_SIZE);
197DEFINE_TLV_PARSER(EDIT_CONTACT_NAME_TAGS, NULL, edit_contact_name_tlv_parser)
205static bool verify_fields(
const s_edit_contact_name_ctx *context)
207 bool result = TLV_CHECK_RECEIVED_TAGS(context->received_tags,
209 TAG_STRUCTURE_VERSION,
216 PRINTF(
"[Edit Contact Name] Missing mandatory fields!\n");
227static void print_payload(
const s_edit_contact_name_ctx *context)
230 PRINTF(
"****************************************************************************\n");
231 PRINTF(
"[Edit Contact Name] - Retrieved Descriptor:\n");
232 PRINTF(
"[Edit Contact Name] - Old name: %s\n", context->edit->old_contact_name);
233 PRINTF(
"[Edit Contact Name] - New name: %s\n", context->edit->contact_name);
244static bool build_and_send_response(
void)
246 uint8_t hmac_proof[CX_SHA256_SIZE] = {0};
248 if (!address_book_compute_hmac_proof(&g_ab_payload.edit_contact_name.bip32_path,
249 g_ab_payload.edit_contact_name.gid,
250 g_ab_payload.edit_contact_name.contact_name,
252 PRINTF(
"[Edit Contact Name] Error: Failed to compute new HMAC_PROOF\n");
256 bool ok = address_book_send_hmac_proof(TYPE_EDIT_CONTACT_NAME, hmac_proof);
257 explicit_bzero(hmac_proof,
sizeof(hmac_proof));
266static void review_choice(
bool confirm)
269 bool ok = build_and_send_response();
271 on_edit_contact_name_applied(&g_ab_payload.edit_contact_name);
274 PRINTF(
"[Edit Contact Name] Error: Failed to build and send HMAC proof\n");
276 address_book_finalize_review(
277 ok,
"Contact name changed",
"Error during update", finalize_ui_edit_contact_name);
280 address_book_handle_review_rejected(finalize_ui_edit_contact_name);
287static void ui_display(
void)
290 memset(&g_ab_ui.list, 0,
sizeof(g_ab_ui.list));
291 memset(g_ab_ui.pairs, 0,
sizeof(g_ab_ui.pairs));
292 g_ab_ui.pairs[nbPairs].item =
"Old name";
293 g_ab_ui.pairs[nbPairs].value = g_ab_payload.edit_contact_name.old_contact_name;
295 g_ab_ui.pairs[nbPairs].item =
"New name";
296 g_ab_ui.pairs[nbPairs].value = g_ab_payload.edit_contact_name.contact_name;
298 g_ab_ui.list.pairs = g_ab_ui.pairs;
299 g_ab_ui.list.nbPairs = nbPairs;
301 "Review change to contact details",
302#ifdef SCREEN_SIZE_WALLET
319bolos_err_t edit_contact_name(uint8_t *buffer_in,
size_t buffer_in_length)
321 const buffer_t payload = {.
ptr = buffer_in, .size = buffer_in_length};
322 s_edit_contact_name_ctx ctx = {0};
325 ctx.edit = &g_ab_payload.edit_contact_name;
326 memset(&g_ab_payload.edit_contact_name, 0,
sizeof(g_ab_payload.edit_contact_name));
329 if (!edit_contact_name_tlv_parser(&payload, &ctx, &ctx.received_tags)) {
330 PRINTF(
"[Edit Contact Name] TLV parsing failed\n");
331 return SWO_INCORRECT_DATA;
333 if (!verify_fields(&ctx)) {
334 return SWO_INCORRECT_DATA;
339 if (!address_book_verify_group_handle(&g_ab_payload.edit_contact_name.bip32_path,
341 g_ab_payload.edit_contact_name.gid)) {
342 PRINTF(
"[Edit Contact Name] Group handle verification failed\n");
343 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
347 if (!address_book_verify_hmac_proof(&g_ab_payload.edit_contact_name.bip32_path,
348 g_ab_payload.edit_contact_name.gid,
349 g_ab_payload.edit_contact_name.old_contact_name,
351 PRINTF(
"[Edit Contact Name] HMAC_PROOF verification failed\n");
352 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
357 return SWO_NO_RESPONSE;
Register / Edit Contact Name / Edit Scope / Edit Identifier.
#define LARGE_ADDRESS_BOOK_ICON
API of the Advanced BOLOS Graphical Library, for typical application use-cases.