30#define TYPE_DYNAMIC_TOKEN 0x90
98 X(0x01, TAG_STRUCTURE_TYPE, handle_structure_type, ENFORCE_UNIQUE_TAG) \
99 X(0x02, TAG_VERSION, handle_version, ENFORCE_UNIQUE_TAG) \
100 X(0x03, TAG_COIN_TYPE, handle_coin_type, ENFORCE_UNIQUE_TAG) \
101 X(0x04, TAG_APPLICATION_NAME, handle_application_name, ENFORCE_UNIQUE_TAG) \
102 X(0x05, TAG_TICKER, handle_ticker, ENFORCE_UNIQUE_TAG) \
103 X(0x06, TAG_MAGNITUDE, handle_magnitude, ENFORCE_UNIQUE_TAG) \
104 X(0x07, TAG_TUID, handle_tuid, ENFORCE_UNIQUE_TAG) \
105 X(0x08, TAG_SIGNATURE, handle_signature, ENFORCE_UNIQUE_TAG)
112 if (data->tag != TAG_SIGNATURE) {
114 cx_hash_update((cx_hash_t *) &tlv_extracted->hash_ctx, data->raw.ptr, data->raw.size));
124 tlv_extracted.
output = out;
127 cx_sha256_init(&tlv_extracted.
hash_ctx);
130 if (!parse_dynamic_token_tag(payload, &tlv_extracted, &tlv_extracted.
received_tags)) {
131 PRINTF(
"Failed to parse tlv payload\n");
136 PRINTF(
"Error: no struct type specified!\n");
141 PRINTF(
"Error: unexpected struct type %d\n", tlv_extracted.
structure_type);
148 TAG_APPLICATION_NAME,
153 PRINTF(
"Error: missing required fields in struct version 1\n");
158 PRINTF(
"Error: unsupported application name %s\n", tlv_extracted.
application_name);
163 PRINTF(
"Error: unsupported struct version %d\n", tlv_extracted.
output->
version);
168 uint8_t tlv_hash[CX_SHA256_SIZE] = {0};
169 CX_ASSERT(cx_hash_final((cx_hash_t *) &tlv_extracted.
hash_ctx, tlv_hash));
170 buffer_t hash = {.
ptr = tlv_hash, .size =
sizeof(tlv_hash)};
175 uint8_t expected_key_usage = CERTIFICATE_PUBLIC_KEY_USAGE_COIN_META;
176 cx_curve_t expected_curve = CX_CURVE_SECP256K1;
178 hash, &expected_key_usage, &expected_curve, tlv_extracted.
input_sig);
180 PRINTF(
"Failed to verify signature of dynamic token info\n");
check_signature_with_pki_status_t check_signature_with_pki(const buffer_t hash, const uint8_t *expected_key_usage, const cx_curve_t *expected_curve, const buffer_t signature)
Checks a signature using the PKI certificate.
@ CHECK_SIGNATURE_WITH_PKI_SUCCESS
enum check_signature_with_pki_status_e check_signature_with_pki_status_t
char ticker[MAX_TICKER_SIZE+1]
bool get_string_from_tlv_data(const tlv_data_t *data, char *out, uint16_t min_length, uint16_t out_size)
Copy a NUL-terminated string from TLV data.
bool get_uint8_t_from_tlv_data(const tlv_data_t *data, uint8_t *value)
Extract a uint8_t value from TLV data.
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).
bool get_uint32_t_from_tlv_data(const tlv_data_t *data, uint32_t *value)
Extract a uint32_t value from TLV data.
#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,...)
static bool handle_signature(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_coin_type(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_application_name(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
struct tlv_extracted_s tlv_extracted_t
#define TYPE_DYNAMIC_TOKEN
static bool handle_tuid(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_version(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_magnitude(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_ticker(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
static bool handle_structure_type(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
tlv_dynamic_descriptor_status_t tlv_use_case_dynamic_descriptor(const buffer_t *payload, tlv_dynamic_descriptor_out_t *out)
Processes a TLV dynamic descriptor use case.
static bool handle_common(const tlv_data_t *data, tlv_extracted_t *tlv_extracted)
@ TLV_DYNAMIC_DESCRIPTOR_MISSING_STRUCTURE_TAG
@ TLV_DYNAMIC_DESCRIPTOR_SIGNATURE_ERROR
@ TLV_DYNAMIC_DESCRIPTOR_SUCCESS
@ TLV_DYNAMIC_DESCRIPTOR_PARSING_ERROR
@ TLV_DYNAMIC_DESCRIPTOR_WRONG_APPLICATION_NAME
@ TLV_DYNAMIC_DESCRIPTOR_WRONG_TYPE
@ TLV_DYNAMIC_DESCRIPTOR_UNKNOWN_VERSION
@ TLV_DYNAMIC_DESCRIPTOR_MISSING_TAG
#define DER_SIGNATURE_MIN_SIZE
enum tlv_dynamic_descriptor_status_e tlv_dynamic_descriptor_status_t
#define DER_SIGNATURE_MAX_SIZE