diff --git a/app/src/globals.c b/app/src/globals.c index 5f19ac788..5e8056d08 100644 --- a/app/src/globals.c +++ b/app/src/globals.c @@ -45,3 +45,12 @@ toggle_expert_mode(void) tmp.expert_mode = !N_settings.expert_mode; nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings)); } + +void +toggle_blindsign_status(void) +{ + settings_t tmp; + memcpy(&tmp, (void *)&N_settings, sizeof(tmp)); + tmp.blindsign_status = (tmp.blindsign_status + 1) % 3; + nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings)); +} diff --git a/app/src/globals.h b/app/src/globals.h index 3bb6954f3..3d13c300a 100644 --- a/app/src/globals.h +++ b/app/src/globals.h @@ -52,6 +52,9 @@ void init_globals(void); /// Toggles the persisted expert_mode setting void toggle_expert_mode(void); +/// toggles the blindsign setting between "For large tx", "ON", "OFF". +void toggle_blindsign_status(void); + #define MAX_APDU_SIZE 235 #define MAX_SIGNATURE_SIZE 100 #define ERROR_CODE_SIZE 15 @@ -78,12 +81,18 @@ typedef enum { typedef enum { ST_IDLE, /// Idle state ST_CLEAR_SIGN, /// Clearsigning an operation - ST_BLIND_SIGN, /// blindisigning an operation + ST_BLIND_SIGN, /// blindsigning an operation ST_PROMPT, /// Waiting for user prompt ST_SWAP_SIGN, /// Performing swap operations ST_ERROR /// In error state. } main_step_t; +typedef enum { + ST_BLINDSIGN_LARGE_TX = 0, + ST_BLINDSIGN_ON = 1, + ST_BLINDSIGN_OFF = 2 +} blindsign_state_t; + /** * @brief Global structure holding state of operations and buffer of the data * to be processed. @@ -112,8 +121,13 @@ typedef struct { struct { bagl_element_t bagls[4 + TZ_SCREEN_LINES_11PX]; } ux; /// Config for history screens for nano devices. - char expert_mode_state[10]; /// Expert mode state to be displayed in - /// settings.ENAELED/DISABLED. + char expert_mode_state[10]; /// Expert mode text: "ENAELED", "DISABLED" +#ifdef TARGET_NANOS + char blindsign_state_desc[5]; /// Blindsigning text: "Part", "ON" , "OFF" +#else + char blindsign_state_desc[14]; /// Blindsigning text: "For Large Tx", + /// "ON" , "OFF" +#endif #endif #ifdef HAVE_NBGL @@ -124,8 +138,9 @@ typedef struct { /* Settings */ typedef struct { - bool expert_mode; /// enable expert mode -} settings_t; /// Special settings available in the app. + bool expert_mode; /// enable expert mode + blindsign_state_t blindsign_status; /// Blindsign status +} settings_t; /// Special settings available in the app. extern globals_t global; diff --git a/app/src/ui_settings.c b/app/src/ui_settings.c index 5b8624c31..1dd54cf0a 100644 --- a/app/src/ui_settings.c +++ b/app/src/ui_settings.c @@ -31,16 +31,29 @@ expert_mode_toggle() FUNC_LEAVE(); } +static void +blindsign_toggle() +{ + FUNC_ENTER(); + toggle_blindsign_status(); + ui_settings_init(SETTINGS_BLINDSIGN_PAGE); + FUNC_LEAVE(); +} + UX_STEP_CB(ux_expert_mode_step, bn, expert_mode_toggle(), {"Expert mode", global.expert_mode_state}); +UX_STEP_CB(ux_blindsign_step, bn, blindsign_toggle(), + {"Allow Blindsigning", global.blindsign_state_desc}); UX_STEP_CB(ux_back_step, pb, ui_home_init(), {&C_icon_back, "Back"}); -UX_FLOW(ux_expert_mode_flow, &ux_expert_mode_step, &ux_back_step, FLOW_LOOP); +UX_FLOW(ux_expert_mode_flow, &ux_expert_mode_step, &ux_blindsign_step, + &ux_back_step, FLOW_LOOP); void -ui_settings_init(__attribute__((unused)) int16_t page) +ui_settings_init(int16_t page) { - FUNC_ENTER(("Page number: %d", page)); + FUNC_ENTER(("%d, Expert Mode: %d, Max_Screen: ", page, + N_settings.expert_mode, N_settings.blindsign_status)); if (N_settings.expert_mode) { strncpy(global.expert_mode_state, "ENABLED", @@ -50,7 +63,31 @@ ui_settings_init(__attribute__((unused)) int16_t page) sizeof(global.expert_mode_state)); } - ux_flow_init(0, ux_expert_mode_flow, NULL); + switch (N_settings.blindsign_status) { + case ST_BLINDSIGN_LARGE_TX: + default: +#ifdef TARGET_NANOS + strncpy(global.blindsign_state_desc, "Part", + sizeof(global.blindsign_state_desc)); +#else + strncpy(global.blindsign_state_desc, "For Large Tx", + sizeof(global.blindsign_state_desc)); +#endif + break; + case ST_BLINDSIGN_ON: + strncpy(global.blindsign_state_desc, "ON", + sizeof(global.blindsign_state_desc)); + break; + case ST_BLINDSIGN_OFF: + strncpy(global.blindsign_state_desc, "OFF", + sizeof(global.blindsign_state_desc)); + break; + } + if (page == SETTINGS_HOME_PAGE) { + ux_flow_init(0, ux_expert_mode_flow, &ux_expert_mode_step); + } else if (page == SETTINGS_BLINDSIGN_PAGE) { + ux_flow_init(0, ux_expert_mode_flow, &ux_blindsign_step); + } FUNC_LEAVE(); } diff --git a/app/src/ui_settings.h b/app/src/ui_settings.h index 97efc6d64..e0453eba7 100644 --- a/app/src/ui_settings.h +++ b/app/src/ui_settings.h @@ -4,7 +4,8 @@ #pragma once -#define SETTINGS_HOME_PAGE 0 +#define SETTINGS_HOME_PAGE 0 +#define SETTINGS_BLINDSIGN_PAGE 1 /** * @brief Initialize settings screen for nano devices. Displays status of diff --git a/tests/integration/nano/snapshots/nanos/settings_blindsign_large_tx.png b/tests/integration/nano/snapshots/nanos/settings_blindsign_large_tx.png new file mode 100644 index 000000000..54d455c97 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/settings_blindsign_large_tx.png differ diff --git a/tests/integration/nano/snapshots/nanos/settings_blindsign_off.png b/tests/integration/nano/snapshots/nanos/settings_blindsign_off.png new file mode 100644 index 000000000..834142cf8 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/settings_blindsign_off.png differ diff --git a/tests/integration/nano/snapshots/nanos/settings_blindsign_on.png b/tests/integration/nano/snapshots/nanos/settings_blindsign_on.png new file mode 100644 index 000000000..1e5bfd2a1 Binary files /dev/null and b/tests/integration/nano/snapshots/nanos/settings_blindsign_on.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_blindsign_large_tx.png b/tests/integration/nano/snapshots/nanosp/settings_blindsign_large_tx.png new file mode 100644 index 000000000..00719b348 Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_blindsign_large_tx.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_blindsign_off.png b/tests/integration/nano/snapshots/nanosp/settings_blindsign_off.png new file mode 100644 index 000000000..3ea6ff33a Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_blindsign_off.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_blindsign_on.png b/tests/integration/nano/snapshots/nanosp/settings_blindsign_on.png new file mode 100644 index 000000000..94d6d85b3 Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_blindsign_on.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_max_screen_30.png b/tests/integration/nano/snapshots/nanosp/settings_max_screen_30.png new file mode 100644 index 000000000..bb824d1e0 Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_max_screen_30.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_max_screen_60.png b/tests/integration/nano/snapshots/nanosp/settings_max_screen_60.png new file mode 100644 index 000000000..922a8c31a Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_max_screen_60.png differ diff --git a/tests/integration/nano/snapshots/nanosp/settings_max_screen_inf.png b/tests/integration/nano/snapshots/nanosp/settings_max_screen_inf.png new file mode 100644 index 000000000..c4db1bbcd Binary files /dev/null and b/tests/integration/nano/snapshots/nanosp/settings_max_screen_inf.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_blindsign_large_tx.png b/tests/integration/nano/snapshots/nanox/settings_blindsign_large_tx.png new file mode 100644 index 000000000..00719b348 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_blindsign_large_tx.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_blindsign_off.png b/tests/integration/nano/snapshots/nanox/settings_blindsign_off.png new file mode 100644 index 000000000..3ea6ff33a Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_blindsign_off.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_blindsign_on.png b/tests/integration/nano/snapshots/nanox/settings_blindsign_on.png new file mode 100644 index 000000000..94d6d85b3 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_blindsign_on.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_max_screen_30.png b/tests/integration/nano/snapshots/nanox/settings_max_screen_30.png new file mode 100644 index 000000000..bb824d1e0 Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_max_screen_30.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_max_screen_60.png b/tests/integration/nano/snapshots/nanox/settings_max_screen_60.png new file mode 100644 index 000000000..922a8c31a Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_max_screen_60.png differ diff --git a/tests/integration/nano/snapshots/nanox/settings_max_screen_inf.png b/tests/integration/nano/snapshots/nanox/settings_max_screen_inf.png new file mode 100644 index 000000000..c4db1bbcd Binary files /dev/null and b/tests/integration/nano/snapshots/nanox/settings_max_screen_inf.png differ diff --git a/tests/integration/nano/test_basic.py b/tests/integration/nano/test_basic.py index d0d990837..8ee9d003a 100755 --- a/tests/integration/nano/test_basic.py +++ b/tests/integration/nano/test_basic.py @@ -57,15 +57,23 @@ def test_basic(app): app.backend.both_click() app.assert_screen(Screen.Settings_expert_mode_enabled) app.backend.right_click() + app.assert_screen(Screen.Settings_blindsign_large_tx) + app.backend.both_click() + app.assert_screen(Screen.Settings_blindsign_on) + app.backend.both_click() + app.assert_screen(Screen.Settings_blindsign_off) + app.backend.both_click() + app.assert_screen(Screen.Settings_blindsign_large_tx) + app.backend.right_click() app.assert_screen(Screen.Settings_back) app.backend.left_click() + app.assert_screen(Screen.Settings_blindsign_large_tx) + app.backend.left_click() app.assert_screen(Screen.Settings_expert_mode_enabled) - app.backend.both_click() - app.assert_screen(Screen.Settings_expert_mode_disabled) - app.backend.right_click() + app.backend.left_click() app.assert_screen(Screen.Settings_back) app.backend.right_click() - app.assert_screen(Screen.Settings_expert_mode_disabled) + app.assert_screen(Screen.Settings_expert_mode_enabled) app.backend.left_click() app.assert_screen(Screen.Settings_back) app.backend.both_click() diff --git a/tests/integration/nano/utils/app.py b/tests/integration/nano/utils/app.py index a9d8e24e3..b69f0d9bc 100644 --- a/tests/integration/nano/utils/app.py +++ b/tests/integration/nano/utils/app.py @@ -144,6 +144,9 @@ class Screen(str, Enum): Settings = "settings" Settings_expert_mode_disabled = "settings_expert_mode_disabled" Settings_expert_mode_enabled = "settings_expert_mode_enabled" + Settings_blindsign_large_tx = "settings_blindsign_large_tx" + Settings_blindsign_on = "settings_blindsign_on" + Settings_blindsign_off = "settings_blindsign_off" Settings_back = "back" Quit = "quit" @@ -220,7 +223,7 @@ def setup_expert_mode(self) -> None: self.assert_screen(Screen.Settings_expert_mode_disabled) self.backend.both_click() self.assert_screen(Screen.Settings_expert_mode_enabled) - self.backend.right_click() + self.backend.left_click() self.assert_screen(Screen.Settings_back) self.backend.both_click() self.assert_screen(Screen.Home) diff --git a/tests/integration/test_runtime.sh b/tests/integration/test_runtime.sh index 662f5b563..591d7f922 100644 --- a/tests/integration/test_runtime.sh +++ b/tests/integration/test_runtime.sh @@ -179,7 +179,7 @@ set_expert_mode() { expect_section_content 'Expert mode' 'DISABLED' press_button both expect_section_content 'Expert mode' 'ENABLED' - press_button right + press_button left expect_section_content 'Back' press_button both expected_home