Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
identity_edit_scope.c File Reference

Edit Scope flow (P1=0x04, struct type 0x32). More...

#include <string.h>
#include "os_apdu.h"
#include "status_words.h"
#include "tlv_library.h"
#include "buffer.h"
#include "bip32.h"
#include "address_book.h"
#include "address_book_entrypoints.h"
#include "address_book_crypto.h"
#include "address_book_common.h"
#include "identity.h"
#include "io.h"
#include "nbgl_use_case.h"
Include dependency graph for identity_edit_scope.c:

Go to the source code of this file.

Classes

struct  s_edit_scope_ctx

Macros

#define STRUCT_VERSION   0x01
#define EDIT_SCOPE_TAGS(X)

Functions

static bool handle_struct_type (const tlv_data_t *data, void *context_ptr)
 Handler for tag STRUCTURE_TYPE.
static bool handle_struct_version (const tlv_data_t *data, void *context_ptr)
 Handler for tag STRUCTURE_VERSION.
static bool handle_contact_name (const tlv_data_t *data, void *context_ptr)
 Handler for tag CONTACT_NAME.
static bool handle_scope (const tlv_data_t *data, void *context_ptr)
 Handler for tag SCOPE.
static bool handle_identifier (const tlv_data_t *data, void *context_ptr)
 Handler for tag ACCOUNT_IDENTIFIER.
static bool handle_previous_scope (const tlv_data_t *data, void *context_ptr)
 Handler for tag PREVIOUS_SCOPE.
static bool handle_group_handle (const tlv_data_t *data, void *context_ptr)
 Handler for tag GROUP_HANDLE.
static bool handle_chain_id (const tlv_data_t *data, void *context_ptr)
 Handler for tag CHAIN_ID.
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 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.
static void print_payload (const s_edit_scope_ctx *context)
 Print the received descriptor.
static bool build_and_send_response (void)
 Build and send response.
static void review_choice (bool confirm)
 NBGL callback invoked after the user confirms or rejects the edit.
static void ui_display (void)
 Display the Edit Scope review screen.
bolos_err_t edit_scope (uint8_t *buffer_in, size_t buffer_in_length)
 Edit the SCOPE of an existing Identity contact.

Detailed Description

Edit Scope flow (P1=0x04, struct type 0x32).

Allows changing the SCOPE of an existing Identity contact while keeping the same contact_name and identifier.

Flow:

  1. Receive fully assembled payload (multi-chunk reassembly handled by address_book.c)
  2. Parse TLV payload (contact_name + new_scope + old_scope + identifier + gid [+ derivation_path] + chain_id + blockchain_family + hmac_proof + hmac_rest)
  3. Verify HMAC_PROOF over (gid, contact_name)
  4. Verify HMAC_REST over (gid, old_scope, identifier, family[, chain_id])
  5. Display UI: old scope → new scope
  6. On confirm: compute new HMAC_REST over (gid, new_scope, identifier, family[, chain_id]) and send to host

Active under HAVE_ADDRESS_BOOK.

Definition in file identity_edit_scope.c.

Macro Definition Documentation

◆ EDIT_SCOPE_TAGS

#define EDIT_SCOPE_TAGS ( X)
Value:
X(0x01, TAG_STRUCTURE_TYPE, handle_struct_type, ENFORCE_UNIQUE_TAG) \
X(0x02, TAG_STRUCTURE_VERSION, handle_struct_version, ENFORCE_UNIQUE_TAG) \
X(0xf0, TAG_CONTACT_NAME, handle_contact_name, ENFORCE_UNIQUE_TAG) \
X(0xf1, TAG_SCOPE, handle_scope, ENFORCE_UNIQUE_TAG) \
X(0xf2, TAG_ACCOUNT_IDENTIFIER, handle_identifier, ENFORCE_UNIQUE_TAG) \
X(0xf5, TAG_PREVIOUS_SCOPE, handle_previous_scope, ENFORCE_UNIQUE_TAG) \
X(0xf6, TAG_GROUP_HANDLE, handle_group_handle, ENFORCE_UNIQUE_TAG) \
X(0x23, TAG_CHAIN_ID, handle_chain_id, ENFORCE_UNIQUE_TAG) \
X(0x29, TAG_HMAC_PROOF, handle_hmac_proof, ENFORCE_UNIQUE_TAG) \
X(0xf7, TAG_HMAC_REST, handle_hmac_rest, ENFORCE_UNIQUE_TAG) \
X(0x51, TAG_BLOCKCHAIN_FAMILY, handle_blockchain_family, ENFORCE_UNIQUE_TAG)
static bool handle_contact_name(const tlv_data_t *data, void *context_ptr)
Handler for tag CONTACT_NAME.
static bool handle_hmac_proof(const tlv_data_t *data, void *context_ptr)
Handler for tag HMAC_PROOF.
static bool handle_struct_type(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_TYPE.
static bool handle_struct_version(const tlv_data_t *data, void *context_ptr)
Handler for tag STRUCTURE_VERSION.
static bool handle_group_handle(const tlv_data_t *data, void *context_ptr)
Handler for tag GROUP_HANDLE.
static bool handle_blockchain_family(const tlv_data_t *data, void *context_ptr)
Handler for tag BLOCKCHAIN_FAMILY.
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 handle_identifier(const tlv_data_t *data, void *context_ptr)
Handler for tag ACCOUNT_IDENTIFIER.
static bool handle_hmac_rest(const tlv_data_t *data, void *context_ptr)
Handler for tag HMAC_REST.
static bool handle_previous_scope(const tlv_data_t *data, void *context_ptr)
Handler for tag PREVIOUS_SCOPE.
@ ENFORCE_UNIQUE_TAG

Definition at line 69 of file identity_edit_scope.c.

◆ STRUCT_VERSION

#define STRUCT_VERSION   0x01

Definition at line 57 of file identity_edit_scope.c.

Function Documentation

◆ build_and_send_response()

bool build_and_send_response ( void )
static

Build and send response.

Compute HMAC Proof of Registration and send it to the host Response format: type(1) | hmac_proof(32).

Returns
true if successful, false otherwise

Definition at line 360 of file identity_edit_scope.c.

◆ edit_scope()

bolos_err_t edit_scope ( uint8_t * buffer_in,
size_t buffer_in_length )

Edit the SCOPE of an existing Identity contact.

Parameters
[in]buffer_inthe fully assembled TLV payload
[in]buffer_in_lengththe length of the payload
Returns
bolos_err_t the result of the edit

Definition at line 446 of file identity_edit_scope.c.

◆ handle_blockchain_family()

bool handle_blockchain_family ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag BLOCKCHAIN_FAMILY.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 249 of file identity_edit_scope.c.

◆ handle_chain_id()

bool handle_chain_id ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag CHAIN_ID.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 235 of file identity_edit_scope.c.

◆ handle_contact_name()

bool handle_contact_name ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag CONTACT_NAME.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 131 of file identity_edit_scope.c.

◆ handle_group_handle()

bool handle_group_handle ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag GROUP_HANDLE.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 214 of file identity_edit_scope.c.

◆ handle_hmac_proof()

bool handle_hmac_proof ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag HMAC_PROOF.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 263 of file identity_edit_scope.c.

◆ handle_hmac_rest()

bool handle_hmac_rest ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag HMAC_REST.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 283 of file identity_edit_scope.c.

◆ handle_identifier()

bool handle_identifier ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag ACCOUNT_IDENTIFIER.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 172 of file identity_edit_scope.c.

◆ handle_previous_scope()

bool handle_previous_scope ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag PREVIOUS_SCOPE.

Used to verify the HMAC proof of the previous registration.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 195 of file identity_edit_scope.c.

◆ handle_scope()

bool handle_scope ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag SCOPE.

Stores the new scope.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 153 of file identity_edit_scope.c.

◆ handle_struct_type()

bool handle_struct_type ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag STRUCTURE_TYPE.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 93 of file identity_edit_scope.c.

◆ handle_struct_version()

bool handle_struct_version ( const tlv_data_t * data,
void * context_ptr )
static

Handler for tag STRUCTURE_VERSION.

Parameters
[in]datathe tlv data
[in]context_ptrthe received payload
Returns
whether the handling was successful

Definition at line 112 of file identity_edit_scope.c.

◆ print_payload()

void print_payload ( const s_edit_scope_ctx * context)
static

Print the received descriptor.

Parameters
[in]contextthe received payload Only for debug purpose.

Definition at line 337 of file identity_edit_scope.c.

◆ review_choice()

void review_choice ( bool confirm)
static

NBGL callback invoked after the user confirms or rejects the edit.

Parameters
[in]confirmtrue if user confirmed, false if rejected

Definition at line 385 of file identity_edit_scope.c.

◆ ui_display()

void ui_display ( void )
static

Display the Edit Scope review screen.

Definition at line 409 of file identity_edit_scope.c.

◆ verify_fields()

bool verify_fields ( const s_edit_scope_ctx * context)
static

Check that all mandatory TLV tags were received.

Parameters
[in]contextthe received payload
Returns
whether all mandatory fields are present

Definition at line 304 of file identity_edit_scope.c.