Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
transaction_check.h File Reference

Transaction Check: risk report from a security provider, displayed during the review. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "os_types.h"
#include "buffer.h"
#include "lcx_ecdsa.h"
#include "lcx_sha3.h"
#include "nbgl_use_case.h"
#include "tlv_use_case_transaction_check.h"
Include dependency graph for transaction_check.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tx_check_context_t

Macros

#define TRANSACTION_CHECK_MAX_PAYLOAD_SIZE

Enumerations

enum  tx_check_setting_t { TX_CHECK_SETTING_OPT_IN , TX_CHECK_SETTING_ENABLE }
enum  tx_check_status_t {
  TX_CHECK_SUCCESS , TX_CHECK_PENDING , TX_CHECK_DISABLED , TX_CHECK_NOT_ALLOWED ,
  TX_CHECK_INVALID_SIGNATURE , TX_CHECK_INVALID_DESCRIPTOR
}

Functions

bolos_err_t tx_check_handle_apdu (const uint8_t *buffer, size_t buffer_len, uint8_t p1, uint8_t p2, uint8_t *buffer_out, size_t *buffer_out_length)
 Handle the SDK default APDU (CLA 0xB0, INS DEFAULT_APDU_INS_TRANSACTION_CHECK).
tx_check_status_t tx_check_provide_descriptor (const buffer_t *payload)
 Parse, verify and store a Transaction Check descriptor.
tx_check_status_t tx_check_opt_in (bool response_expected)
 Display the opt-in screen if the user has not seen it yet.
uint16_t tx_check_status_to_sw (tx_check_status_t status)
 Standard status word of a Transaction Check status.
void tx_check_apply_report (nbgl_warning_t *warning, const tx_check_context_t *ctx)
 Bind the stored report to the operation being signed and fill the review warning.
void tx_check_clear (void)
 Erase the stored report.

Detailed Description

Transaction Check: risk report from a security provider, displayed during the review.

The descriptor is received either through the SDK default APDU (CLA 0xB0) or through an app-specific APDU calling tx_check_provide_descriptor() and tx_check_opt_in(). The coin app binds the report to the transaction being signed with tx_check_apply_report().

Definition in file transaction_check.h.

Macro Definition Documentation

◆ TRANSACTION_CHECK_MAX_PAYLOAD_SIZE

#define TRANSACTION_CHECK_MAX_PAYLOAD_SIZE
Value:
((1 + 1 + 1) /* STRUCTURE_TYPE */ \
+ (1 + 1 + 1) /* STRUCTURE_VERSION */ \
+ (1 + 1 + TRANSACTION_CHECK_MAX_ADDRESS_SIZE) /* ADDRESS */ \
+ (1 + 1 + 8) /* CHAIN_ID */ \
+ (1 + 1 + TRANSACTION_CHECK_HASH_SIZE) /* TX_HASH */ \
+ (1 + 1 + TRANSACTION_CHECK_HASH_SIZE) /* DOMAIN_HASH */ \
+ (2 + 1 + 1) /* NORMALIZED_RISK */ \
+ (2 + 1 + 1) /* NORMALIZED_CATEGORY */ \
+ (2 + 1 + TRANSACTION_CHECK_MSG_SIZE) /* PROVIDER_MSG */ \
+ (2 + 1 + TRANSACTION_CHECK_URL_SIZE) /* TINY_URL */ \
+ (2 + 1 + 1) /* SIMULATION_TYPE */ \
+ (1 + 1 + CX_ECDSA_SHA256_SIG_MAX_ASN1_LENGTH)) /* DER_SIGNATURE */
#define TRANSACTION_CHECK_HASH_SIZE
#define TRANSACTION_CHECK_URL_SIZE
#define TRANSACTION_CHECK_MAX_ADDRESS_SIZE
#define TRANSACTION_CHECK_MSG_SIZE

Largest descriptor, every tag at its max size. Each TLV is tag + length + value; tags from 0x80 are DER-encoded on 2 bytes, lengths on 1 byte.

Definition at line 77 of file transaction_check.h.

Enumeration Type Documentation

◆ tx_check_setting_t

Enumerator
TX_CHECK_SETTING_OPT_IN 

The user has seen the opt-in screen.

TX_CHECK_SETTING_ENABLE 

Transaction Check is enabled.

Definition at line 42 of file transaction_check.h.

◆ tx_check_status_t

Result of a descriptor or opt-in request, mapped to status words by tx_check_status_to_sw().

Enumerator
TX_CHECK_SUCCESS 

Descriptor stored, or opt-in already done.

TX_CHECK_PENDING 

Opt-in screen displayed, the choice comes later.

TX_CHECK_DISABLED 

Transaction Check disabled by the user.

TX_CHECK_NOT_ALLOWED 

Report bound to the review in progress, swap, or app busy.

TX_CHECK_INVALID_SIGNATURE 

Descriptor signature rejected.

TX_CHECK_INVALID_DESCRIPTOR 

Descriptor malformed or rejected by the app.

Definition at line 48 of file transaction_check.h.

Function Documentation

◆ tx_check_apply_report()

void tx_check_apply_report ( nbgl_warning_t * warning,
const tx_check_context_t * ctx )

Bind the stored report to the operation being signed and fill the review warning.

Clears the W3C warnings and the report fields of warning, then, when Transaction Check is enabled, sets W3C_ISSUE_WARN when no report matches the operation, otherwise the W3C warning of the report risk level. When the report or ctx holds a domain hash, both must hold the same one.

Parameters
[in,out]warningReview warning, other bits are kept
[in]ctxOperation being signed
[in,out]warningReview warning
[in]ctxOperation being signed

Definition at line 239 of file transaction_check.c.

◆ tx_check_clear()

void tx_check_clear ( void )

Erase the stored report.

Definition at line 156 of file transaction_check.c.

◆ tx_check_handle_apdu()

bolos_err_t tx_check_handle_apdu ( const uint8_t * buffer,
size_t buffer_len,
uint8_t p1,
uint8_t p2,
uint8_t * buffer_out,
size_t * buffer_out_length )

Handle the SDK default APDU (CLA 0xB0, INS DEFAULT_APDU_INS_TRANSACTION_CHECK).

P1 0x00: descriptor, chunked as described in apdu_chunks.h. P1 0x01: opt-in request; replies with 1 byte (enable state), after the user choice when the opt-in screen is displayed.

Parameters
[in]bufferAPDU data
[in]buffer_lenAPDU data length
[in]p1APDU P1
[in]p2APDU P2
[out]buffer_outResponse data
[in,out]buffer_out_lengthResponse capacity in, response length out
Returns
Status word, SWO_NO_RESPONSE when the reply is deferred

Handle the SDK default APDU (CLA 0xB0, INS DEFAULT_APDU_INS_TRANSACTION_CHECK).

Parameters
[in]bufferAPDU data
[in]buffer_lenAPDU data length
[in]p1APDU P1
[in]p2APDU P2
[out]buffer_outResponse data
[in,out]buffer_out_lengthResponse capacity in, response length out
Returns
Status word, SWO_NO_RESPONSE when the reply is deferred

Definition at line 315 of file transaction_check.c.

◆ tx_check_opt_in()

tx_check_status_t tx_check_opt_in ( bool response_expected)

Display the opt-in screen if the user has not seen it yet.

Used for an opt-in request received on an app APDU (response_expected set) or from the settings. No APDU reply is sent by the SDK: on TX_CHECK_SUCCESS the app replies at once, on TX_CHECK_PENDING it replies from handle_tx_check_opt_in_response().

Parameters
[in]response_expectedWhether an APDU reply is pending
Returns
TX_CHECK_PENDING if the opt-in screen is displayed, TX_CHECK_SUCCESS if the user has already opted in, TX_CHECK_NOT_ALLOWED during a swap, or when the screen would be displayed while a reply is expected and a flow is on screen

Display the opt-in screen if the user has not seen it yet.

Parameters
[in]response_expectedWhether an APDU reply is pending
Returns
Same as start_opt_in()

Definition at line 162 of file transaction_check_ui.c.

◆ tx_check_provide_descriptor()

tx_check_status_t tx_check_provide_descriptor ( const buffer_t * payload)

Parse, verify and store a Transaction Check descriptor.

The descriptor replaces the stored report, unless that report is bound to the review in progress (between tx_check_apply_report() and tx_check_clear()). Refused during a swap.

Parameters
[in]payloadComplete TLV descriptor
Returns
TX_CHECK_SUCCESS, TX_CHECK_DISABLED, TX_CHECK_NOT_ALLOWED, TX_CHECK_INVALID_SIGNATURE or TX_CHECK_INVALID_DESCRIPTOR

Parse, verify and store a Transaction Check descriptor.

Parameters
[in]payloadComplete TLV descriptor
Returns
Transaction Check status

Definition at line 167 of file transaction_check.c.

◆ tx_check_status_to_sw()

uint16_t tx_check_status_to_sw ( tx_check_status_t status)

Standard status word of a Transaction Check status.

Parameters
[in]statusStatus returned by tx_check_provide_descriptor() or tx_check_opt_in()
Returns
Status word of status_words.h, SWO_NO_RESPONSE for TX_CHECK_PENDING

Definition at line 283 of file transaction_check.c.