Skip to content

Commit

Permalink
Add blindsigning in Settings for nano.
Browse files Browse the repository at this point in the history
Options are "For Large Tx", "ON", "OFF"
Update snapshots for nano
  • Loading branch information
ajinkyaraj-23 committed Sep 3, 2024
1 parent c6fd93e commit d268080
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 16 deletions.
9 changes: 9 additions & 0 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
25 changes: 20 additions & 5 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
45 changes: 41 additions & 4 deletions app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,29 @@ expert_mode_toggle()
FUNC_LEAVE();
}

static void
blindsign_toggle()

Check notice

Code scanning / CodeQL

Unused static function Note

Static function blindsign_toggle is unreachable
{
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",
Expand All @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/ui_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
16 changes: 12 additions & 4 deletions tests/integration/nano/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/nano/utils/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d268080

Please sign in to comment.