39#include "status_words.h"
51#if defined(HAVE_ADDRESS_BOOK)
54#define STRUCT_VERSION 0x01
59 edit_contact_name_t *edit;
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(0x29, TAG_HMAC_PROOF, handle_hmac_proof, ENFORCE_UNIQUE_TAG)
85static bool handle_struct_type(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
89 PRINTF(
"[Edit Contact Name] Invalid STRUCTURE_TYPE value\n");
102static bool handle_struct_version(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
106 PRINTF(
"[Edit Contact Name] Invalid STRUCTURE_VERSION value\n");
119static bool handle_contact_name(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
121 if (!address_book_handle_printable_string(
122 data, context->edit->contact_name,
sizeof(context->edit->contact_name))) {
123 PRINTF(
"[Edit Contact Name] CONTACT_NAME: failed to parse\n");
136static bool handle_previous_name(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
138 if (!address_book_handle_printable_string(
139 data, context->edit->old_contact_name,
sizeof(context->edit->old_contact_name))) {
140 PRINTF(
"[Edit Contact Name] PREVIOUS_CONTACT_NAME: failed to parse\n");
153static bool handle_group_handle(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
157 PRINTF(
"[Edit Contact Name] GROUP_HANDLE: invalid length (expected %d bytes)\n",
161 memmove(context->group_handle, buf.
ptr, GROUP_HANDLE_SIZE);
172static bool handle_hmac_proof(
const tlv_data_t *data, s_edit_contact_name_ctx *context)
176 PRINTF(
"[Edit Contact Name] HMAC_PROOF: invalid length (expected %d bytes)\n",
180 memmove(context->hmac_proof, buf.
ptr, CX_SHA256_SIZE);
192static bool verify_fields(
const s_edit_contact_name_ctx *context)
196 TAG_STRUCTURE_VERSION,
202 PRINTF(
"[Edit Contact Name] Missing mandatory fields!\n");
213static void print_payload(
const s_edit_contact_name_ctx *context)
216 PRINTF(
"****************************************************************************\n");
217 PRINTF(
"[Edit Contact Name] - Retrieved Descriptor:\n");
218 PRINTF(
"[Edit Contact Name] - Old name: %s\n", context->edit->old_contact_name);
219 PRINTF(
"[Edit Contact Name] - New name: %s\n", context->edit->contact_name);
230static bool build_and_send_response(
void)
232 uint8_t hmac_proof[CX_SHA256_SIZE] = {0};
234 if (!address_book_compute_hmac_proof(g_ab_payload.edit_contact_name.gid,
235 g_ab_payload.edit_contact_name.contact_name,
237 PRINTF(
"[Edit Contact Name] Error: Failed to compute new HMAC_PROOF\n");
238 explicit_bzero(hmac_proof,
sizeof(hmac_proof));
242 bool ok = address_book_send_hmac_proof(TYPE_EDIT_CONTACT_NAME, hmac_proof);
243 explicit_bzero(hmac_proof,
sizeof(hmac_proof));
252static void review_choice(
bool confirm)
255 bool ok = build_and_send_response();
257 on_edit_contact_name_applied(&g_ab_payload.edit_contact_name);
260 PRINTF(
"[Edit Contact Name] Error: Failed to build and send HMAC proof\n");
262 address_book_finalize_review(
263 ok,
"Contact name changed",
"Error during update", finalize_ui_edit_contact_name);
266 address_book_handle_review_rejected(finalize_ui_edit_contact_name);
273static void ui_display(
void)
276 memset(&g_ab_ui.list, 0,
sizeof(g_ab_ui.list));
277 memset(g_ab_ui.pairs, 0,
sizeof(g_ab_ui.pairs));
278 g_ab_ui.pairs[nbPairs].item =
"Old name";
279 g_ab_ui.pairs[nbPairs].value = g_ab_payload.edit_contact_name.old_contact_name;
281 g_ab_ui.pairs[nbPairs].item =
"New name";
282 g_ab_ui.pairs[nbPairs].value = g_ab_payload.edit_contact_name.contact_name;
284 g_ab_ui.list.pairs = g_ab_ui.pairs;
285 g_ab_ui.list.nbPairs = nbPairs;
287 "Review change to contact details",
288#ifdef SCREEN_SIZE_WALLET
305bolos_err_t edit_contact_name(uint8_t *buffer_in,
size_t buffer_in_length)
307 const buffer_t payload = {.
ptr = buffer_in, .size = buffer_in_length};
308 s_edit_contact_name_ctx ctx = {0};
311 ctx.edit = &g_ab_payload.edit_contact_name;
312 memset(&g_ab_payload.edit_contact_name, 0,
sizeof(g_ab_payload.edit_contact_name));
315 if (!edit_contact_name_tlv_parser(&payload, &ctx, &ctx.received_tags)) {
316 PRINTF(
"[Edit Contact Name] TLV parsing failed\n");
317 return SWO_INCORRECT_DATA;
319 if (!verify_fields(&ctx)) {
320 return SWO_INCORRECT_DATA;
325 if (!address_book_verify_group_handle(ctx.group_handle, g_ab_payload.edit_contact_name.gid)) {
326 PRINTF(
"[Edit Contact Name] Group handle verification failed\n");
327 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
331 if (!address_book_verify_hmac_proof(g_ab_payload.edit_contact_name.gid,
332 g_ab_payload.edit_contact_name.old_contact_name,
334 PRINTF(
"[Edit Contact Name] HMAC_PROOF verification failed\n");
335 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
340 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.
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).
#define DEFINE_TLV_PARSER(TAG_LIST, COMMON_HANDLER, PARSE_FUNCTION_NAME)
Creates a parser function for a given TLV use case.
#define TLV_CHECK_RECEIVED_TAGS(received,...)