Skip to content

Commit

Permalink
[blindsign] Show blindsign warning on nano when in "Blindsign on" mode
Browse files Browse the repository at this point in the history
* [sign-warning] uniform warning between nanos, nanos+ and nanox

* [blind] add warnings before going to blindsign flow
  • Loading branch information
spalmer25 authored Sep 26, 2024
1 parent ae51bfb commit bbaa799
Show file tree
Hide file tree
Showing 67 changed files with 50 additions and 27 deletions.
62 changes: 37 additions & 25 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void handle_data_apdu_blind(void);
static void pass_from_clear_to_summary(void);
#ifdef HAVE_BAGL
static void init_too_many_screens_stream(void);
static void init_blind_warning_stream(void);
#endif
#ifdef HAVE_NBGL
static void continue_blindsign_cb(void);
Expand Down Expand Up @@ -119,14 +120,9 @@ tz_ui_stream_push_risky_accept_reject(tz_ui_cb_type_t accept_cb_type,
FUNC_LEAVE();
}

void
tz_ui_stream_push_warning_not_trusted(
#ifdef TARGET_NANOS
void
#else
const char *title_reason, const char *value_reason
#endif
)
static void
tz_ui_stream_push_warning_not_trusted(const char *title_reason,
const char *value_reason)
{
FUNC_ENTER(("void"));
#ifdef TARGET_NANOS
Expand All @@ -137,8 +133,12 @@ tz_ui_stream_push_warning_not_trusted(
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "The transaction",
"cannot be trusted.", TZ_UI_LAYOUT_HOME_PB,
TZ_UI_ICON_WARNING);
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, title_reason, value_reason,
TZ_UI_LAYOUT_HOME_N, TZ_UI_ICON_NONE);
#endif
if ((title_reason != NULL) && (value_reason != NULL)) {
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, title_reason, value_reason,
TZ_UI_LAYOUT_HOME_N, TZ_UI_ICON_NONE);
}
#ifndef TARGET_NANOS
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "It may not be safe",
"to sign this\ntransaction.", TZ_UI_LAYOUT_HOME_N,
TZ_UI_ICON_NONE);
Expand Down Expand Up @@ -337,7 +337,7 @@ refill_blo_done(void)
if (global.blindsign_reason == REASON_TOO_MANY_SCREENS) {
init_too_many_screens_stream();
} else {
init_summary_stream();
init_blind_warning_stream();
}
TZ_SUCCEED();
}
Expand Down Expand Up @@ -373,11 +373,12 @@ refill_error(void)
#ifdef HAVE_BAGL
tz_ui_stream_init(stream_cb);

tz_ui_stream_push_warning_not_trusted(
#ifndef TARGET_NANOS
"This transaction", "could not be\ndecoded correctly."
#ifdef TARGET_NANOS
tz_ui_stream_push_warning_not_trusted(NULL, NULL);
#else
tz_ui_stream_push_warning_not_trusted("This transaction",
"could not be\ndecoded correctly.");
#endif
);

tz_ui_stream_push_all(TZ_UI_STREAM_CB_NOCB,
"Parsing error",
Expand Down Expand Up @@ -650,7 +651,7 @@ init_summary_stream(void)

#ifdef HAVE_BAGL
static void
too_many_screens_stream_cb(tz_ui_cb_type_t cb_type)
pass_to_summary_stream_cb(tz_ui_cb_type_t cb_type)
{
TZ_PREAMBLE(("cb_type=%u", cb_type));

Expand All @@ -668,17 +669,14 @@ too_many_screens_stream_cb(tz_ui_cb_type_t cb_type)
static void
init_too_many_screens_stream(void)
{
tz_ui_stream_init(too_many_screens_stream_cb);
tz_ui_stream_init(pass_to_summary_stream_cb);

tz_ui_stream_push_warning_not_trusted(
#ifndef TARGET_NANOS
"Operation too long", "Proceed to\nblindsign."
#endif
);
#ifdef TARGET_NANOS
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "Operation too long",
"Accept blindsign.", TZ_UI_LAYOUT_HOME_B,
TZ_UI_ICON_NONE);
tz_ui_stream_push_warning_not_trusted("Operation too long",
"Accept blindsign");
#else
tz_ui_stream_push_warning_not_trusted("Operation too long",
"Proceed to\nblindsign.");
#endif
tz_ui_stream_push_risky_accept_reject(TZ_UI_STREAM_CB_VALIDATE,
TZ_UI_STREAM_CB_REJECT);
Expand All @@ -688,6 +686,20 @@ init_too_many_screens_stream(void)
tz_ui_stream();
}

static void
init_blind_warning_stream(void)
{
tz_ui_stream_init(pass_to_summary_stream_cb);

tz_ui_stream_push_warning_not_trusted(NULL, NULL);
tz_ui_stream_push_risky_accept_reject(TZ_UI_STREAM_CB_VALIDATE,
TZ_UI_STREAM_CB_REJECT);

tz_ui_stream_close();

tz_ui_stream();
}

static void
bs_push_next(void)
{
Expand Down
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.
15 changes: 13 additions & 2 deletions tests/integration/nano/test_blindsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,26 @@ def test_blind_sign_basic_operation(app):

def navigate() -> None:
app.navigate_until_text(Screen_text.blindsign(app.backend), path / "clear")
app.navigate_until_text(Screen_text.Accept_risk, path / "blind_warning")
app.navigate_until_text(Screen_text.Sign_accept, path / "summary")

_blind_sign(app, basic_operation, navigate)

def test_blind_reject_basic_operation(app):
path = basic_test_path / "reject"
def test_blind_reject_basic_operation_at_blind_warning(app):
path = basic_test_path / "reject_at_blind_warning"

def navigate() -> None:
app.navigate_until_text(Screen_text.blindsign(app.backend), path / "clear")
app.navigate_until_text(Screen_text.Sign_reject, path / "blind_warning")

_blind_reject(app, basic_operation, StatusCode.REJECT, navigate)

def test_blind_reject_basic_operation_at_summary(app):
path = basic_test_path / "reject_at_summary"

def navigate() -> None:
app.navigate_until_text(Screen_text.blindsign(app.backend), path / "clear")
app.navigate_until_text(Screen_text.Accept_risk, path / "blind_warning")
app.navigate_until_text(Screen_text.Sign_reject, path / "summary")

_blind_reject(app, basic_operation, StatusCode.REJECT, navigate)
Expand Down

0 comments on commit bbaa799

Please sign in to comment.