19#include "os_helpers.h"
22#include "status_words.h"
28#if defined(HAVE_TX_CHECK)
31#define P1_DESCRIPTOR 0x00
35#define TX_CHECK_WARNINGS \
36 ((1 << W3C_ISSUE_WARN) | (1 << W3C_RISK_DETECTED_WARN) | (1 << W3C_THREAT_DETECTED_WARN) \
37 | (1 << W3C_NO_THREAT_WARN))
71 PRINTF(
"[TX CHECK] No report received\n");
74 if ((ctx == NULL) || (ctx->
tx_hash == NULL)) {
75 PRINTF(
"[TX CHECK] No operation to bind the report to\n");
79 PRINTF(
"[TX CHECK] Type mismatch: %d != %d\n",
s_report.type, ctx->
type);
83 PRINTF(
"[TX CHECK] Chain ID rejected\n");
87 PRINTF(
"[TX CHECK] Signer address mismatch\n");
91 PRINTF(
"[TX CHECK] TX_HASH mismatch: %.*H != %.*H\n",
102 PRINTF(
"[TX CHECK] DOMAIN_HASH mismatch\n");
120 return "This transaction involves a suspicious address. "
121 "It might not be safe to continue.";
123 return "This transaction involves a suspicious dApp. "
124 "It might not be safe to continue.";
126 return "This transaction could end in a loss. "
127 "Check transaction details carefully before signing.";
129 return "This transaction might be malicious. It might not be safe to "
130 "continue. Tap the QR code icon for more details.";
135 return "This transaction involves a malicious address. "
136 "Your assets will most likely be stolen.";
138 return "This dApp is linked to a scammer. "
139 "Your assets will most likely be stolen.";
141 return "This request is malicious. Your assets will most likely be stolen. "
142 "View full report for details.";
172 PRINTF(
"[TX CHECK] Transaction Check is disabled\n");
176 PRINTF(
"[TX CHECK] Not available in a swap\n");
181 PRINTF(
"[TX CHECK] Report bound to the review in progress\n");
188 PRINTF(
"[TX CHECK] Descriptor signature rejected with status 0x%x\n", status);
192 PRINTF(
"[TX CHECK] Descriptor parsing failed with status %d\n", status);
196 PRINTF(
"[TX CHECK] Unsupported ADDITIONAL_DATA tag\n");
200 PRINTF(
"[TX CHECK] Address too long: %u\n", out.
address.
size);
204 PRINTF(
"[TX CHECK] Descriptor rejected by the app\n");
224 PRINTF(
"[TX CHECK] Report: partner=%s risk=%d category=%d type=%d url=%s\n",
248 PRINTF(
"[TX CHECK] Transaction Check is disabled\n");
289 return SWO_NO_RESPONSE;
291 return SWO_COMMAND_CODE_NOT_SUPPORTED;
293 return SWO_COMMAND_NOT_ALLOWED;
295 return SWO_SECURITY_CONDITION_NOT_SATISFIED;
297 return SWO_INCORRECT_DATA;
299 return SWO_INCORRECT_DATA;
303#if defined(HAVE_TX_CHECK_APDU)
320 size_t *buffer_out_length)
322 size_t out_capacity = *buffer_out_length;
323 uint8_t *payload = NULL;
324 size_t payload_len = 0;
326 *buffer_out_length = 0;
336 return SWO_INCORRECT_DATA;
343 &(
const buffer_t){.ptr = payload, .size = payload_len, .offset = 0}));
346 if ((p2 != 0) || (buffer_len != 0)) {
347 return SWO_WRONG_P1_P2;
353 if (out_capacity < 1) {
354 return SWO_INCORRECT_DATA;
357 *buffer_out_length = 1;
361 PRINTF(
"[TX CHECK] Unexpected P1 0x%02x\n", p1);
362 return SWO_WRONG_P1_P2;
Chunked APDU payload reassembly shared by the SDK app features.
@ APDU_CHUNKS_OWNER_TRANSACTION_CHECK
@ APDU_CHUNKS_ERROR
Protocol error; the payload in progress is dropped.
@ APDU_CHUNKS_PENDING
More chunks needed.
@ APDU_CHUNKS_COMPLETE
Full payload assembled; out_buf/out_len are valid.
apdu_chunks_status_t apdu_chunks_reassemble(apdu_chunks_owner_t owner, const uint8_t *data, size_t len, uint8_t p2, uint8_t **out_buf, size_t *out_len)
Reassemble a multi-chunk APDU payload.
@ W3C_THREAT_DETECTED_WARN
Web3 Checks: Threat detected (see reportRisk field).
@ W3C_ISSUE_WARN
Web3 Checks issue (not available).
@ W3C_NO_THREAT_WARN
Web3 Checks: No Threat detected.
@ W3C_RISK_DETECTED_WARN
Web3 Checks: Risk detected (see reportRisk field).
size_t strlcpy(char *dst, const char *src, size_t size)
size_t size
Pointer to byte buffer.
The necessary parameters to build a warning page preceding a review. One can either use predefinedSet...
const char * providerMessage
Dedicated provider message. Default one will be used if NULL.
const char * reportProvider
name of the security report provider, used in some strings
const char * reportUrl
URL of the report, used in some strings.
char partner[TRANSACTION_CHECK_PARTNER_SIZE+1]
transaction_check_category_t category
bool domain_hash_received
transaction_check_risk_t risk
transaction_check_type_t type
char tiny_url[TRANSACTION_CHECK_URL_SIZE+1]
bool additional_data_received
transaction_check_type_t type
const uint8_t * domain_hash
transaction_check_category_t category
uint8_t address[TRANSACTION_CHECK_MAX_ADDRESS_SIZE]
uint8_t domain_hash[TRANSACTION_CHECK_HASH_SIZE]
char tiny_url[TRANSACTION_CHECK_URL_SIZE+1]
bool domain_hash_received
transaction_check_type_t type
transaction_check_risk_t risk
bool bound
Bound to the review in progress, until cleared.
uint8_t tx_hash[TRANSACTION_CHECK_HASH_SIZE]
char partner[TRANSACTION_CHECK_PARTNER_SIZE+1]
tlv_transaction_check_status_t tlv_use_case_transaction_check(const buffer_t *payload, tlv_transaction_check_out_t *out)
Parse a Transaction Check TLV payload.
#define TRANSACTION_CHECK_HASH_SIZE
#define TRANSACTION_CHECK_URL_SIZE
#define TRANSACTION_CHECK_PARTNER_SIZE
enum transaction_check_risk_e transaction_check_risk_t
#define TRANSACTION_CHECK_MAX_ADDRESS_SIZE
enum tlv_transaction_check_status_e tlv_transaction_check_status_t
enum transaction_check_type_e transaction_check_type_t
@ TRANSACTION_CHECK_CATEGORY_LOSING_OPERATION
@ TRANSACTION_CHECK_CATEGORY_ADDRESS
@ TRANSACTION_CHECK_CATEGORY_DAPP
struct tlv_transaction_check_out_s tlv_transaction_check_out_t
@ TRANSACTION_CHECK_RISK_BENIGN
@ TRANSACTION_CHECK_RISK_MALICIOUS
@ TRANSACTION_CHECK_RISK_WARNING
@ TLV_TRANSACTION_CHECK_SUCCESS
@ TLV_TRANSACTION_CHECK_SIGNATURE_ERROR
enum transaction_check_category_e transaction_check_category_t
tx_check_status_t tx_check_provide_descriptor(const buffer_t *payload)
Parse, verify and store a descriptor, replacing a report not bound to a review.
static tx_check_report_t s_report
#define TX_CHECK_WARNINGS
static const char * warning_text(void)
Text displayed in the warning, from the report risk and category.
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.
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 APDU: chunked descriptor (P1 0x00) or opt-in request (P1 0x01).
static bool report_matches(const tx_check_context_t *ctx)
Check that the stored report applies to the operation being signed.
Transaction Check: risk report from a security provider, displayed during the review.
@ TX_CHECK_SETTING_ENABLE
Transaction Check is enabled.
@ TX_CHECK_PENDING
Opt-in screen displayed, the choice comes later.
@ TX_CHECK_NOT_ALLOWED
Report bound to the review in progress, swap, or app busy.
@ TX_CHECK_DISABLED
Transaction Check disabled by the user.
@ TX_CHECK_INVALID_DESCRIPTOR
Descriptor malformed or rejected by the app.
@ TX_CHECK_SUCCESS
Descriptor stored, or opt-in already done.
@ TX_CHECK_INVALID_SIGNATURE
Descriptor signature rejected.
bool handle_check_tx_report_chain_id(bool chain_id_received, uint64_t chain_id, const tx_check_context_t *ctx)
Check the report chain ID against the operation being signed.
bool handle_check_tx_report(const tlv_transaction_check_out_t *descriptor)
Validate the chain-specific fields of a received descriptor.
bool handle_tx_check_get_setting(tx_check_setting_t setting)
Read a persistent Transaction Check setting.
bool handle_check_tx_report_signer(const uint8_t *address, size_t address_len, const tx_check_context_t *ctx)
Check that the report address is the signer of the operation.
Transaction Check functions shared between the SDK sources, not exposed to the apps.
static bool tx_check_in_swap(void)
Tell whether the app runs a swap started by the Exchange app.
tx_check_status_t tx_check_opt_in_sdk_apdu(void)
Opt-in request received on the SDK APDU, whose reply is sent by the SDK.