Skip to content

Commit

Permalink
Simplify account prefix handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Nov 23, 2023
1 parent fd9b980 commit 0a56ab5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
12 changes: 1 addition & 11 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,9 @@ extern uint8_t G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
#define MAX_PARTNER_NAME_LENGHT 15

#define PARTNER_NAME_PREFIX_FOR_FUND "To "
#define PARTNER_NAME_PREFIX_SIZE (sizeof(PARTNER_NAME_PREFIX_FOR_FUND) - 1) // Remove trailing '\0'

typedef struct partner_data_s {
uint8_t name_length;
union {
// SELL and SWAP flows display nothing
// FUND flow displays "To xyz"
struct {
char prefix[PARTNER_NAME_PREFIX_SIZE];
char name[MAX_PARTNER_NAME_LENGHT + 1];
} __attribute__((packed));
char prefixed_name[PARTNER_NAME_PREFIX_SIZE + MAX_PARTNER_NAME_LENGHT + 1];
};
char prefixed_name[sizeof(PARTNER_NAME_PREFIX_FOR_FUND) - 1 + MAX_PARTNER_NAME_LENGHT + 1];
cx_ecfp_256_public_key_t public_key;
} partner_data_t;

Expand Down
6 changes: 1 addition & 5 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ int init_application_context(void) {

#endif
memset(&G_swap_ctx, 0, sizeof(G_swap_ctx));
// Prepare the prefixed name for FUND display, don't copy the trailing '\0' on purpose
// as we want the second part of the string to be concatenated automatically
memcpy(&G_swap_ctx.partner.prefix,
PARTNER_NAME_PREFIX_FOR_FUND,
sizeof(G_swap_ctx.partner.prefix));

if (cx_ecfp_init_public_key_no_throw(CX_CURVE_SECP256K1,
LedgerPubKey,
sizeof(LedgerPubKey),
Expand Down
13 changes: 8 additions & 5 deletions src/set_partner_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ int set_partner_key(const command_t *cmd) {
return reply_error(err);
}

// The incoming partner name is NOT NULL terminated, so we use memcpy and
// manually NULL terminate the buffer
memset(G_swap_ctx.partner.name, 0, sizeof(G_swap_ctx.partner.name));
memcpy(G_swap_ctx.partner.name, partner.bytes, partner.size);
G_swap_ctx.partner.name_length = partner.size;
memset(G_swap_ctx.partner.prefixed_name, 0, sizeof(G_swap_ctx.partner.prefixed_name));
// Prepare the prefix for FUND display
strlcpy(G_swap_ctx.partner.prefixed_name,
PARTNER_NAME_PREFIX_FOR_FUND,
sizeof(G_swap_ctx.partner.prefixed_name));
// The incoming partner name is NOT NULL terminated, so we use strncat
// Don't erase the prefix copied above
strncat(G_swap_ctx.partner.prefixed_name, (char *) partner.bytes, partner.size);

// Create the verifying key from the raw public key
if (cx_ecfp_init_public_key_no_throw(curve,
Expand Down

0 comments on commit 0a56ab5

Please sign in to comment.