Skip to content

Commit

Permalink
[blind] remove the too many screen flow
Browse files Browse the repository at this point in the history
 - no more limit of screens (even in Blind mode ON)
 - no more warning screens for too many screen
 - large tx option acts like Blind mode OFF

Co-authored-by: Ajinkya <[email protected]>
  • Loading branch information
spalmer25 and ajinkyaraj-23 committed Oct 1, 2024
1 parent ec8c4c2 commit 5886bac
Show file tree
Hide file tree
Showing 62 changed files with 53 additions and 116 deletions.
13 changes: 2 additions & 11 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ static void init_summary_stream(void);
#define APDU_SIGN_ASSERT_STEP(x) \
APDU_SIGN_ASSERT(global.keys.apdu.sign.step == (x))

#ifdef HAVE_BAGL
#define SCREEN_DISPLAYED global.keys.apdu.sign.u.clear.screen_displayed
#endif

#ifdef HAVE_BAGL
void
Expand Down Expand Up @@ -271,17 +273,6 @@ refill_blo_im_full(void)
#elif HAVE_NBGL
PRINTF("[DEBUG] field=%s complex=%d\n", st->field_info.field_name,
st->field_info.is_field_complex);
if ((N_settings.blindsign_status != ST_BLINDSIGN_OFF)
&& (SCREEN_DISPLAYED >= NB_MAX_SCREEN_ALLOWED)) {
strncpy(global.error_code, "TOO_MANY_SCREENS", ERROR_CODE_SIZE);
tz_ui_stream_push_all(TZ_UI_STREAM_CB_CANCEL,
st->field_info.field_name, "TOO_MANY_SCREENS",
TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE);

global.blindsign_reason = REASON_TOO_MANY_SCREENS;

TZ_SUCCEED();
}
if (st->field_info.is_field_complex
&& !global.keys.apdu.sign.u.clear.displayed_expert_warning) {
global.keys.apdu.sign.u.clear.last_field_index
Expand Down
8 changes: 5 additions & 3 deletions app/src/apdu_sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ typedef struct {
tz_parser_state parser_state;
size_t total_length;
uint8_t last_field_index;
uint8_t screen_displayed;
bool received_msg;
bool displayed_expert_warning;
#ifdef HAVE_BAGL
uint8_t screen_displayed;
#endif
bool received_msg;
bool displayed_expert_warning;
} clear;
/// @brief blindsigning state info.
struct {
Expand Down
7 changes: 2 additions & 5 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ typedef enum {
#define NB_MAX_SCREEN_ALLOWED 20
#elif defined(HAVE_BAGL)
#define NB_MAX_SCREEN_ALLOWED 12
#else
#define NB_MAX_SCREEN_ALLOWED 8
#endif

#ifdef HAVE_NBGL
typedef enum {
REASON_NONE = 0,
REASON_PARSING_ERROR = 1,
REASON_TOO_MANY_SCREENS = 2
REASON_NONE = 0,
REASON_PARSING_ERROR = 1
} blindsign_reason_t;
#endif

Expand Down
13 changes: 2 additions & 11 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void drop_last_screen(void);
void push_str(const char *text, size_t len, char **out);
void switch_to_blindsigning_on_error(void);
static void ui_stream_init(void);
#define SCREEN_DISPLAYED global.keys.apdu.sign.u.clear.screen_displayed

void
tz_reject(void)
Expand Down Expand Up @@ -73,7 +72,6 @@ blindsign_skip_callback(void)
TZ_PREAMBLE(("Blindsign reason: %d", global.blindsign_reason));

if (global.blindsign_reason == REASON_NONE) {
global.blindsign_reason = REASON_TOO_MANY_SCREENS;
tz_ui_stream_close();
tz_ui_stream_t *s = &global.stream;
s->cb(TZ_UI_STREAM_CB_SUMMARY);
Expand All @@ -88,20 +86,14 @@ blindsign_choice(bool confirm)
{
TZ_PREAMBLE(("void"));
if (confirm) {
if (global.blindsign_reason != REASON_TOO_MANY_SCREENS) {
global.step = ST_BLIND_SIGN;
}
global.step = ST_BLIND_SIGN;
tz_reject_ui();
} else {
tz_ui_stream_t *s = &global.stream;

TZ_ASSERT(EXC_UNEXPECTED_STATE,
global.blindsign_reason != REASON_NONE);
if (global.blindsign_reason == REASON_TOO_MANY_SCREENS) {
s->cb(TZ_UI_STREAM_CB_SUMMARY);
} else {
s->cb(TZ_UI_STREAM_CB_BLINDSIGN);
}
s->cb(TZ_UI_STREAM_CB_BLINDSIGN);
}

TZ_POSTAMBLE;
Expand Down Expand Up @@ -531,7 +523,6 @@ tz_ui_stream_pushl(tz_ui_cb_type_t cb_type, const char *title,
|| (!append && (++(s->screens[bucket].nb_pairs) == max_pairs))
|| (append && (offset == 0))) {
s->total++;
SCREEN_DISPLAYED++;
if ((s->total > 0)
&& ((s->total % TZ_UI_STREAM_HISTORY_SCREENS)
== (s->last % TZ_UI_STREAM_HISTORY_SCREENS))) {
Expand Down
Binary file not shown.
Binary file not shown.
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.
Diff not rendered.
Diff not rendered.
Diff not rendered.
128 changes: 42 additions & 86 deletions tests/integration/touch/test_blindsign_different_modes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# Copyright 2023 Trilitech <[email protected]>
# Copyright 2024 Functori <[email protected]>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,39 +17,41 @@
from utils import (
tezos_app,
TezosAppScreen,
send_payload, BlindsigningStatus
send_payload,
BlindsigningStatus,
)

from ragger.firmware import Firmware
#Response: c9fc57555a59876454427adadeb62cf365bf936e346def12f0729e6a1c9d0eed81e1acced76fddb6ec90619a12d8904dd9ba07f64a9f2c4e05a692224ec7bdb1d357b90a03a0d8f441b048d0cff72e997aac00d657725f67afb68c76eacb79029000

def blindsign_common(app: TezosAppScreen):
def navigate_screens(app: TezosAppScreen, group: int, screen_count: int, suffix: str):
for i in range(screen_count):
app.assert_screen("tbdm_screen_" + suffix + str(group) + "_" + str(i+1))
app.review.next()


def navigate_common(app: TezosAppScreen, skip: bool =False, group_counts: list = []):
suffix = ""
if skip:
suffix = "skip_"
app.send_initialize_msg( "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f01ffeb0300000000000000000000000000000000000000000000000000000000000000006b00ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0b0104020320182716513907b6bab33f905396d031931c07e01bddd780780c1a56b9c086da6c00ffdd6102321bc251e4a5190ad5b12b251069d9b480897a0c0107c08db701000278eb8b6ab9a768579cd5146b480789650c83f28effff0d7570646174655f636f6e6669670000000607070005030a6e00ffdd6102321bc251e4a5190ad5b12b251069d9b4c08db7010d0105ff01ee572f02e5be5d097ba17369789582882e8abb87c900ffdd6102321bc2")
app.assert_screen("review_transaction")
app.review.next()
app.assert_screen("tbdm_op_0_screen_1")
app.review.next()
app.assert_screen("tbdm_op_0_screen_2")
app.review.next()
app.assert_screen("tbdm_op_0_screen_3")
app.review.next()
if(app.firmware == Firmware.FLEX):
app.assert_screen("tbdm_op_0_screen_3_flex_1")
app.review.next()
navigate_screens(app, group= 1, screen_count = group_counts[1 - 1 ], suffix=suffix)
app.assert_screen("expert_mode_splash")
app.review.next()
app.assert_screen("tbdm_op_0_screen_4")
app.review.next()
if(app.firmware == Firmware.FLEX):
app.assert_screen("tbdm_op_0_screen_4_flex_1")
app.review.next()
navigate_screens(app, group= 2, screen_count= group_counts[2 - 1 ], suffix=suffix)
app.expect_apdu_return("9000")
app.send_apdu("800f01ffeb51e4a5190ad5b12b251069d9b48092f4010e0106000000fa000000086d65737361676530000000086d65737361676531000000086d65737361676532000000086d65737361676533000000086d65737361676534000000086d65737361676535000000086d65737361676536000000086d65737361676537000000086d65737361676538000000086d65737361676539000000096d6573736167653130000000096d6573736167653131000000096d6573736167653132000000096d6573736167653133000000096d6573736167653134000000096d6573736167653135000000096d6573736167653136")
if app.firmware == Firmware.FLEX:
app.assert_screen("tbdm_op_0_screen_4_flex_2")
app.review.next()
app.assert_screen("tbdm_op_0_screen_5")
navigate_screens(app, group= 3, screen_count= group_counts[3 - 1 ], suffix=suffix)
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
navigate_screens(app, group= 4, screen_count= group_counts[4 - 1 ], suffix=suffix)
app.review.next()
expected_apdu = "a2ef5aec1ad8cc9b35dee48e8a47e418108dec7652159f3a4314c29d91f172f4645db9554b5a8a565307d9a9e65260957409efef54835573b8fc43d6162f99b8e17a557f7f82c46a53ca7c2be7aa540239d394cd5e9dbf14312c8e1e331a2b099000"
app.review_confirm_signing(expected_apdu)



def blindsign_review_sign(app: TezosAppScreen):
Expand All @@ -65,54 +68,31 @@ def blindsign_review_sign(app: TezosAppScreen):
if __name__ == "__main__":
app = tezos_app(__file__)

app.assert_home()
app.set_expert_mode(initial_status=False)

# Blindsign status OFF
app.assert_home()
app.set_expert_mode(initial_status= False) # need to know the current status of expert mode
app.set_blindsigning_status(BlindsigningStatus.OFF)
blindsign_common(app)
app.assert_screen("tbdm_op_0_screen_6")
app.review.next()
app.assert_screen("tbdm_op_0_screen_7")
app.review.next()
app.assert_screen("tbdm_op_0_screen_8")
app.review.next()
app.assert_screen("tbdm_op_0_screen_9")
app.review.next()
if app.firmware == Firmware.FLEX:
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
app.assert_screen("tbdm_op_0_screen_10")
app.review.next()
if app.firmware == Firmware.STAX:
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
app.assert_screen("tbdm_op_0_screen_11")
app.review.next()
app.assert_screen("tbdm_op_0_screen_12")
expected_apdu = "a2ef5aec1ad8cc9b35dee48e8a47e418108dec7652159f3a4314c29d91f172f4645db9554b5a8a565307d9a9e65260957409efef54835573b8fc43d6162f99b8e17a557f7f82c46a53ca7c2be7aa540239d394cd5e9dbf14312c8e1e331a2b099000"
app.review_confirm_signing(expected_apdu)
#

if(app.firmware == Firmware.STAX):
navigate_common(app, skip=False, group_counts=[3, 1, 6, 2])
else:
navigate_common(app, skip=False, group_counts=[4, 2, 5, 3])

# Blindsign status For Large Tx only
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.Large_Tx_only)

blindsign_common(app)
if app.firmware == Firmware.STAX:
app.assert_screen("tbdm_op_0_screen_6")
app.review.next()
app.assert_screen("tbdm_op_0_screen_7")
app.review.next()
app.assert_screen("tbdm_op_0_screen_8")
app.review.next()
app.assert_screen("blindsign_warning_too_many_screens")
app.review.back_to_safety.reject()
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
blindsign_review_sign(app)
if(app.firmware == Firmware.STAX):
navigate_common(app, skip=False, group_counts=[3, 1, 6, 2])
else:
navigate_common(app, skip=False, group_counts=[4, 2, 5, 3])

# Blindsign status ON
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.ON)

app.send_initialize_msg( "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f01ffeb0300000000000000000000000000000000000000000000000000000000000000006b00ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0b0104020320182716513907b6bab33f905396d031931c07e01bddd780780c1a56b9c086da6c00ffdd6102321bc251e4a5190ad5b12b251069d9b480897a0c0107c08db701000278eb8b6ab9a768579cd5146b480789650c83f28effff0d7570646174655f636f6e6669670000000607070005030a6e00ffdd6102321bc251e4a5190ad5b12b251069d9b4c08db7010d0105ff01ee572f02e5be5d097ba17369789582882e8abb87c900ffdd6102321bc2")
app.review.next()
Expand All @@ -126,35 +106,11 @@ def blindsign_review_sign(app: TezosAppScreen):
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
blindsign_review_sign(app)

# # Blindsign status ON but continue clear signing
# Blindsign status ON but continue clear signing
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.ON)
app.send_initialize_msg( "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f01ffeb0300000000000000000000000000000000000000000000000000000000000000006b00ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0b0104020320182716513907b6bab33f905396d031931c07e01bddd780780c1a56b9c086da6c00ffdd6102321bc251e4a5190ad5b12b251069d9b480897a0c0107c08db701000278eb8b6ab9a768579cd5146b480789650c83f28effff0d7570646174655f636f6e6669670000000607070005030a6e00ffdd6102321bc251e4a5190ad5b12b251069d9b4c08db7010d0105ff01ee572f02e5be5d097ba17369789582882e8abb87c900ffdd6102321bc2")
app.assert_screen("review_transaction")
app.review.next()
group_1_screen_count= app.firmware == Firmware.STAX and 3 or 4
for i in range(group_1_screen_count):
app.assert_screen("tbdm_skip_screen_1_" + str(i+1))
app.review.next()
app.assert_screen("expert_mode_splash")
group_2_screen_count= app.firmware == Firmware.STAX and 2 or 3
for i in range(group_2_screen_count):
app.review.next()
app.assert_screen("tbdm_skip_screen_2_" + str(i+1))
app.expect_apdu_return("9000")
app.send_apdu("800f01ffeb51e4a5190ad5b12b251069d9b48092f4010e0106000000fa000000086d65737361676530000000086d65737361676531000000086d65737361676532000000086d65737361676533000000086d65737361676534000000086d65737361676535000000086d65737361676536000000086d65737361676537000000086d65737361676538000000086d65737361676539000000096d6573736167653130000000096d6573736167653131000000096d6573736167653132000000096d6573736167653133000000096d6573736167653134000000096d6573736167653135000000096d6573736167653136")
group_3_screen_count= app.firmware == Firmware.STAX and 3 or 1
for i in range(group_3_screen_count):
app.review.next()
app.assert_screen("tbdm_skip_screen_3_" + str(i+1))
app.review.next()
app.assert_screen("blindsign_warning_too_many_screens")
app.review.back_to_safety.reject()
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
blindsign_review_sign(app)

app.set_expert_mode(initial_status=True)
app.set_blindsigning_status(BlindsigningStatus.Large_Tx_only)
app.assert_home()
if(app.firmware == Firmware.STAX):
navigate_common(app, skip=True, group_counts=[3, 1, 6, 2])
else:
navigate_common(app, skip=True, group_counts=[4, 2, 5, 3])

0 comments on commit 5886bac

Please sign in to comment.