Skip to content

Commit c25fb0a

Browse files
Added handling of the new owner field in trusted name struct
1 parent eba8081 commit c25fb0a

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/features/provide_trusted_name/trusted_name.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "proxy_info.h"
1010
#include "ui_utils.h"
1111
#include "mem.h"
12+
#include "getPublicKey.h"
1213

1314
typedef enum { STRUCT_TYPE_TRUSTED_NAME = 0x03 } e_struct_type;
1415

@@ -34,6 +35,7 @@ typedef enum {
3435
TRUSTED_NAME_TYPE_RCV_BIT,
3536
TRUSTED_NAME_SOURCE_RCV_BIT,
3637
NFT_ID_RCV_BIT,
38+
OWNER_RCV_BIT,
3739
} e_tlv_rcv_bit;
3840

3941
typedef enum {
@@ -51,6 +53,7 @@ typedef enum {
5153
TRUSTED_NAME_TYPE = 0x70,
5254
TRUSTED_NAME_SOURCE = 0x71,
5355
NFT_ID = 0x72,
56+
OWNER = 0x74,
5457
} e_tlv_tag;
5558

5659
static s_trusted_name *g_trusted_name_list = NULL;
@@ -476,6 +479,22 @@ static bool handle_nft_id(const s_tlv_data *data, s_trusted_name_ctx *context) {
476479
return true; // unhandled for now
477480
}
478481

482+
/**
483+
* Handler for tag \ref OWNER
484+
*
485+
* @param[in] data the tlv data
486+
* @param[out] context the trusted name context
487+
* @return whether it was successful
488+
*/
489+
static bool handle_owner(const s_tlv_data *data, s_trusted_name_ctx *context) {
490+
if (data->length > sizeof(context->owner)) {
491+
return false;
492+
}
493+
buf_shrink_expand(data->value, data->length, context->owner, sizeof(context->owner));
494+
context->rcv_flags |= SET_BIT(OWNER_RCV_BIT);
495+
return true;
496+
}
497+
479498
bool handle_trusted_name_struct(const s_tlv_data *data, s_trusted_name_ctx *context) {
480499
bool ret;
481500

@@ -523,6 +542,9 @@ bool handle_trusted_name_struct(const s_tlv_data *data, s_trusted_name_ctx *cont
523542
case NFT_ID:
524543
ret = handle_nft_id(data, context);
525544
break;
545+
case OWNER:
546+
ret = handle_owner(data, context);
547+
break;
526548
default:
527549
PRINTF(TLV_TAG_ERROR_MSG, data->tag);
528550
ret = false;
@@ -586,6 +608,7 @@ bool verify_trusted_name_struct(const s_trusted_name_ctx *context) {
586608
return false;
587609
}
588610
break;
611+
589612
case 2:
590613
required_flags |= SET_BIT(CHAIN_ID_RCV_BIT) | SET_BIT(TRUSTED_NAME_TYPE_RCV_BIT) |
591614
SET_BIT(TRUSTED_NAME_SOURCE_RCV_BIT);
@@ -614,7 +637,22 @@ bool verify_trusted_name_struct(const s_trusted_name_ctx *context) {
614637
default:
615638
return false;
616639
}
640+
if (context->trusted_name.name_source == TN_SOURCE_MAB) {
641+
if (!(SET_BIT(OWNER_RCV_BIT) & context->rcv_flags)) {
642+
PRINTF("Error: did not receive an owner for MAB source!\n");
643+
return false;
644+
}
645+
uint8_t wallet_addr[ADDRESS_LENGTH];
646+
if (get_public_key(wallet_addr, sizeof(wallet_addr)) != SWO_SUCCESS) {
647+
return false;
648+
}
649+
if (memcmp(context->owner, wallet_addr, sizeof(wallet_addr)) != 0) {
650+
PRINTF("Error: mismatching owner received!\n");
651+
return false;
652+
}
653+
}
617654
break;
655+
618656
default:
619657
PRINTF("Error: unsupported trusted name struct version (%u) !\n",
620658
context->trusted_name.struct_version);

src/features/provide_trusted_name/trusted_name.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct {
5555
uint8_t input_sig_size;
5656
uint8_t input_sig[ECDSA_SIGNATURE_MAX_LENGTH];
5757
cx_sha256_t hash_ctx;
58+
uint8_t owner[ADDRESS_LENGTH];
5859
uint32_t rcv_flags;
5960
} s_trusted_name_ctx;
6061

0 commit comments

Comments
 (0)