Skip to content

Commit

Permalink
feat: add warning interface on Nano devices. (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 22, 2024
1 parent 6f23d33 commit 0ab3f55
Show file tree
Hide file tree
Showing 191 changed files with 385 additions and 88 deletions.
3 changes: 1 addition & 2 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
## v5.5.0

### Updated
- Give an alert when enabling hash signing in settings. (Ledger Stax and Ledger Flex)
- Default to prohibit signing unverified contracts, need to enable "Custom contracts" in settings.
- Optimize the signing process and add necessary alerts.
- Add support for more Soroban tokens.
- Bug fixes.

Expand Down
123 changes: 103 additions & 20 deletions src/ui/bagl_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "stellar/formatter.h"
#include "stellar/printer.h"

static void start_review_flow(void);

static action_validate_cb g_validate_callback;

// Validate/Invalidate transaction and go back to home
Expand All @@ -46,55 +48,135 @@ static void ui_action_validate_transaction(bool choice) {
}

// Step with icon and text
UX_STEP_NOCB(ux_tx_hash_signing_review_step,
UX_STEP_NOCB(ux_hash_signing_review_step,
pnn,
{
&C_icon_eye,
"Review",
"Hash Signing",
});
UX_STEP_NOCB(ux_tx_hash_signing_warning_step,
pbb,
{
&C_icon_warning,
"Dangerous",
"Operation",
});
UX_STEP_NOCB(ux_tx_hash_signing_display_hash_step,
UX_STEP_NOCB(ux_hash_signing_display_hash_step,
bnnn_paging,
{
.title = "Hash",
.text = G.ui.detail_value,
});
// Step with approve button
UX_STEP_CB(ux_tx_hash_display_approve_step,
UX_STEP_CB(ux_hash_display_approve_step,
pb,
(*g_validate_callback)(true),
{
&C_icon_validate_14,
"Sign Hash",
});
// Step with reject button
UX_STEP_CB(ux_tx_hash_display_reject_step,
UX_STEP_CB(ux_hash_display_reject_step,
pb,
(*g_validate_callback)(false),
{
&C_icon_crossmark,
"Reject",
});

UX_STEP_NOCB(ux_hash_approval_blind_signing_reminder_step,
pbb,
{
&C_icon_warning,
"You accepted",
"the risks",
});

// FLOW to display hash signing
// #1 screen: eye icon + "Review Transaction"
// #2 screen: warning icon + "Hash Signing"
// #3 screen: display hash
// #2 screen: display hash
// #3 screen: display warning
// #4 screen: approve button
// #5 screen: reject button
UX_FLOW(ux_tx_hash_signing_flow,
&ux_tx_hash_signing_review_step,
&ux_tx_hash_signing_warning_step,
&ux_tx_hash_signing_display_hash_step,
&ux_tx_hash_display_approve_step,
&ux_tx_hash_display_reject_step);
UX_FLOW(ux_hash_signing_flow,
&ux_hash_signing_review_step,
&ux_hash_signing_display_hash_step,
&ux_hash_approval_blind_signing_reminder_step,
&ux_hash_display_approve_step,
&ux_hash_display_reject_step);

// clang-format off
UX_STEP_NOCB(
ux_hash_blind_signing_warning_step,
pbb,
{
&C_icon_warning,
#ifdef TARGET_NANOS
"Transaction",
"not trusted",
#else
"This transaction",
"cannot be trusted",
#endif
});
#ifndef TARGET_NANOS
UX_STEP_NOCB(
ux_hash_blind_signing_text1_step,
nnnn,
{
"Your Ledger cannot",
"decode this",
"transaction. If you",
"sign it, you could",
});
UX_STEP_NOCB(
ux_hash_blind_signing_text2_step,
nnnn,
{
"be authorizing",
"malicious actions",
"that can drain your",
"wallet.",
});
#endif
UX_STEP_NOCB(
ux_hash_blind_signing_link_step,
nn,
{
"Learn more:",
"ledger.com/e8",
});
UX_STEP_CB(
ux_hash_blind_signing_accept_step,
pbb,
start_review_flow(),
{
&C_icon_validate_14,
#ifdef TARGET_NANOS
"Accept risk",
"and review",
#else
"Accept risk and",
"review transaction",
#endif
});
UX_STEP_CB(
ux_hash_blind_signing_reject_step,
pb,
ui_action_validate_transaction(false),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on

UX_FLOW(ux_hash_blind_signing_flow,
&ux_hash_blind_signing_warning_step,
#ifndef TARGET_NANOS
&ux_hash_blind_signing_text1_step,
&ux_hash_blind_signing_text2_step,
#endif
&ux_hash_blind_signing_link_step,
&ux_hash_blind_signing_accept_step,
&ux_hash_blind_signing_reject_step);

static void start_review_flow() {
ux_flow_init(0, ux_hash_signing_flow, NULL);
}

int ui_display_hash() {
if (G_context.req_type != CONFIRM_HASH || G_context.state != STATE_NONE) {
Expand All @@ -110,7 +192,8 @@ int ui_display_hash() {

g_validate_callback = &ui_action_validate_transaction;

ux_flow_init(0, ux_tx_hash_signing_flow, NULL);
ux_flow_init(0, ux_hash_blind_signing_flow, NULL);

return 0;
}
#endif
122 changes: 120 additions & 2 deletions src/ui/bagl_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "stellar/formatter.h"
#include "stellar/printer.h"

static void start_review_flow(void);

static action_validate_cb g_validate_callback;
static bool data_exists;
static formatter_data_t formatter_data;
Expand Down Expand Up @@ -187,6 +189,13 @@ UX_STEP_CB(ux_tx_reject_step,
"Reject",
});

UX_STEP_NOCB(ux_transaction_approval_blind_signing_reminder_step,
pbb,
{
&C_icon_warning,
"You accepted",
"the risks",
});
// FLOW to display transaction information:
// https://developers.ledger.com/docs/device-app/develop/ui/flows/advanced-display-management
UX_FLOW(ux_tx_flow,
Expand All @@ -205,6 +214,107 @@ UX_FLOW(ux_auth_flow,
&ux_auth_approve_step,
&ux_tx_reject_step);

UX_FLOW(ux_tx_flow_with_reminder,
&ux_tx_review_step,
&ux_tx_upper_delimiter,
&ux_tx_generic,
&ux_tx_lower_delimiter,
&ux_transaction_approval_blind_signing_reminder_step,
&ux_tx_approve_step,
&ux_tx_reject_step);

UX_FLOW(ux_auth_flow_with_reminder,
&ux_auth_review_step,
&ux_tx_upper_delimiter,
&ux_tx_generic,
&ux_tx_lower_delimiter,
&ux_transaction_approval_blind_signing_reminder_step,
&ux_auth_approve_step,
&ux_tx_reject_step);

// clang-format off
UX_STEP_NOCB(
ux_transaction_blind_signing_warning_step,
pbb,
{
&C_icon_warning,
#ifdef TARGET_NANOS
"Transaction",
"not trusted",
#else
"This transaction",
"cannot be trusted",
#endif
});
#ifndef TARGET_NANOS
UX_STEP_NOCB(
ux_transaction_blind_signing_text1_step,
nnnn,
{
"Your Ledger cannot",
"decode this",
"transaction. If you",
"sign it, you could",
});
UX_STEP_NOCB(
ux_transaction_blind_signing_text2_step,
nnnn,
{
"be authorizing",
"malicious actions",
"that can drain your",
"wallet.",
});
#endif
UX_STEP_NOCB(
ux_transaction_blind_signing_link_step,
nn,
{
"Learn more:",
"ledger.com/e8",
});
UX_STEP_CB(
ux_transaction_blind_signing_accept_step,
pbb,
start_review_flow(),
{
&C_icon_validate_14,
#ifdef TARGET_NANOS
"Accept risk",
"and review",
#else
"Accept risk and",
"review transaction",
#endif
});
UX_STEP_CB(
ux_transaction_blind_signing_reject_step,
pb,
ui_action_validate_transaction(false),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on

UX_FLOW(ux_transaction_blind_signing_flow,
&ux_transaction_blind_signing_warning_step,
#ifndef TARGET_NANOS
&ux_transaction_blind_signing_text1_step,
&ux_transaction_blind_signing_text2_step,
#endif
&ux_transaction_blind_signing_link_step,
&ux_transaction_blind_signing_accept_step,
&ux_transaction_blind_signing_reject_step);

static void start_review_flow() {
if (G_context.req_type == CONFIRM_TRANSACTION) {
ux_flow_init(0, ux_tx_flow_with_reminder, NULL);
} else {
ux_flow_init(0, ux_auth_flow_with_reminder, NULL);
}
}

void prepare_display() {
formatter_data_t fdata = {
.raw_data = G_context.raw,
Expand Down Expand Up @@ -236,7 +346,11 @@ int ui_display_transaction() {
return io_send_sw(SW_BAD_STATE);
}
prepare_display();
ux_flow_init(0, ux_tx_flow, NULL);
if (G_context.unverified_contracts) {
ux_flow_init(0, ux_transaction_blind_signing_flow, NULL);
} else {
ux_flow_init(0, ux_tx_flow, NULL);
}
return 0;
}

Expand All @@ -246,7 +360,11 @@ int ui_display_auth() {
return io_send_sw(SW_BAD_STATE);
}
prepare_display();
ux_flow_init(0, ux_auth_flow, NULL);
if (G_context.unverified_contracts) {
ux_flow_init(0, ux_transaction_blind_signing_flow, NULL);
} else {
ux_flow_init(0, ux_auth_flow, NULL);
}
return 0;
}
#endif
Binary file modified tests_zemu/snapshots/s-hash-signing-approve/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-approve/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-approve/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-approve/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-approve/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-reject/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-reject/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-reject/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-reject/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-hash-signing-reject/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-op-invoke-host-function-with-auth/00047.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-invoke-contract/00050.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-invoke-contract/00051.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-public/00018.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-public/00019.png
Binary file added tests_zemu/snapshots/s-soroban-auth-public/00020.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-reject/00050.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-reject/00051.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-reject/00052.png
Binary file added tests_zemu/snapshots/s-soroban-auth-reject/00053.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-testnet/00019.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-testnet/00020.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-unknown-network/00019.png
Binary file modified tests_zemu/snapshots/s-soroban-auth-unknown-network/00020.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-approve/00001.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-approve/00002.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-approve/00003.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-reject/00001.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-reject/00002.png
Binary file modified tests_zemu/snapshots/sp-hash-signing-reject/00003.png
Binary file modified tests_zemu/snapshots/sp-op-invoke-host-function-with-auth/00033.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-invoke-contract/00032.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-invoke-contract/00033.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-public/00012.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-public/00013.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-reject/00032.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-reject/00033.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-reject/00034.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-testnet/00013.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-testnet/00014.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-unknown-network/00013.png
Binary file modified tests_zemu/snapshots/sp-soroban-auth-unknown-network/00014.png
Binary file modified tests_zemu/snapshots/x-hash-signing-approve/00001.png
Binary file modified tests_zemu/snapshots/x-hash-signing-approve/00002.png
Binary file modified tests_zemu/snapshots/x-hash-signing-approve/00003.png
Binary file modified tests_zemu/snapshots/x-hash-signing-reject/00001.png
Binary file modified tests_zemu/snapshots/x-hash-signing-reject/00002.png
Binary file modified tests_zemu/snapshots/x-hash-signing-reject/00003.png
Binary file modified tests_zemu/snapshots/x-op-invoke-host-function-with-auth/00033.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-invoke-contract/00032.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-invoke-contract/00033.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-public/00012.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-public/00013.png
Binary file added tests_zemu/snapshots/x-soroban-auth-public/00014.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-reject/00032.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-reject/00033.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-reject/00034.png
Binary file added tests_zemu/snapshots/x-soroban-auth-reject/00035.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-testnet/00013.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-testnet/00014.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-unknown-network/00013.png
Binary file modified tests_zemu/snapshots/x-soroban-auth-unknown-network/00014.png
Loading

0 comments on commit 0ab3f55

Please sign in to comment.