Skip to content

Commit

Permalink
[blind] use boolean for blindsigning mode instead of enum
Browse files Browse the repository at this point in the history
 - change blindsining mode settings from ChoiceList to Switch for stax

Co-authored-by: Ajinkya <[email protected]>
  • Loading branch information
spalmer25 and ajinkyaraj-23 committed Oct 1, 2024
1 parent c054190 commit 40ea53f
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 175 deletions.
2 changes: 1 addition & 1 deletion app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ refill_blo_im_full(void)

global.keys.apdu.sign.step = SIGN_ST_WAIT_USER_INPUT;
#ifdef HAVE_BAGL
if ((N_settings.blindsign_status != ST_BLINDSIGN_OFF)
if (N_settings.blindsigning
&& (SCREEN_DISPLAYED >= NB_MAX_SCREEN_ALLOWED)) {
pass_from_clear_to_summary();
TZ_SUCCEED();
Expand Down
11 changes: 2 additions & 9 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ toggle_expert_mode(void)
}

void
set_blindsign_status(blindsign_state_t status)
toggle_blindsigning(void)
{
settings_t tmp;
memcpy(&tmp, (void *)&N_settings, sizeof(tmp));
tmp.blindsign_status = status;
tmp.blindsigning = !N_settings.blindsigning;
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));
}

void
toggle_blindsign_status(void)
{
blindsign_state_t status = (N_settings.blindsign_status + 1) % 2;
set_blindsign_status(status);
}
19 changes: 6 additions & 13 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ typedef enum {
ST_ERROR /// In error state.
} main_step_t;

typedef enum {
ST_BLINDSIGN_OFF = 0,
ST_BLINDSIGN_ON
} blindsign_state_t;

#ifdef TARGET_NANOS
#define NB_MAX_SCREEN_ALLOWED 20
#elif defined(HAVE_BAGL)
Expand Down Expand Up @@ -122,9 +117,9 @@ typedef struct {

/* Settings */
typedef struct {
bool expert_mode; /// enable expert mode
blindsign_state_t blindsign_status; /// Blindsign status
} settings_t; /// Special settings available in the app.
bool expert_mode; /// enable expert mode
bool blindsigning; /// Blindsign status
} settings_t; /// Special settings available in the app.

extern globals_t global;

Expand All @@ -147,8 +142,6 @@ void init_globals(void);
/// Toggles the persisted expert_mode setting
void toggle_expert_mode(void);

/// Toggles the persisted blindsign setting between "OFF", "ON".
void toggle_blindsign_status(void);

/// set the blindsign setting between "OFF", "ON".
void set_blindsign_status(blindsign_state_t status);
/// Toggles the persisted blindsign setting between "ON",
/// "OFF".
void toggle_blindsigning(void);
116 changes: 48 additions & 68 deletions app/src/ui_home_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,115 +28,95 @@
#include "globals.h"
#include "nbgl_use_case.h"

static void controls_callback(int token,
__attribute__((unused)) uint8_t index,
__attribute__((unused)) int page);
void tz_ui_home_redisplay(uint8_t page);
void tz_ui_home_redisplay(void);

// -----------------------------------------------------------
// --------------------- SETTINGS MENU -----------------------
// -----------------------------------------------------------
#define SETTING_INFO_NB 3
#define SETTINGS_SWITCHES_NB 1
#define SETTINGS_RADIO_NB 2
#define SETTING_INFO_NB 3

static const char *const infoTypes[] = {"Version", "Developer", "Contact"};
static const char *const infoContents[] = {
APPVERSION, "Trilitech Kanvas Limited et al.", "[email protected]"};

enum {
EXPERT_MODE_TOKEN = FIRST_USER_TOKEN,
BLINDSIGN_MODE_TOKEN
BLIND_SIGNING_TOKEN
};
enum {
EXPERT_MODE_TOKEN_ID = 0,
BLINDSIGN_MODE_TOKEN_ID,
SETTINGS_CONTENTS_NB
};
enum {
EXPERT_MODE_PAGE = 0,
BLINDSIGN_PAGE = 1
BLIND_SIGNING_TOKEN_ID,
SETTINGS_SWITCHES_NB
};

static nbgl_contentSwitch_t expert_mode_switch = {0};
static nbgl_layoutSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};

static const nbgl_contentInfoList_t infoList = {.nbInfos = SETTING_INFO_NB,
.infoTypes = infoTypes,
.infoContents = infoContents};

static const char *const blindsign_choices_text[]
= {"Blindsigning OFF", "Blindsigning ON"};

static void
get_contents(uint8_t index, nbgl_content_t *content)
{
FUNC_ENTER(("Index: %d", index));
if (index == EXPERT_MODE_TOKEN_ID) {
content->content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
content->content.switchesList.switches = &expert_mode_switch;
content->type = SWITCHES_LIST;
content->contentActionCallback = controls_callback;
} else {
content->content.choicesList.nbChoices = SETTINGS_RADIO_NB;
content->content.choicesList.names = blindsign_choices_text;
content->content.choicesList.token = BLINDSIGN_MODE_TOKEN;
content->content.choicesList.initChoice = N_settings.blindsign_status;
content->type = CHOICES_LIST;
content->contentActionCallback = controls_callback;
}
FUNC_LEAVE();
}

static void
controls_callback(int token, __attribute__((unused)) uint8_t index,
__attribute__((unused)) int page)
{
FUNC_ENTER(("Token : %d, Index: %d, Page: %d", token, index, page));
uint8_t switch_value;
if (token == EXPERT_MODE_TOKEN) {
if (token == BLIND_SIGNING_TOKEN) {
switch_value = !N_settings.blindsigning;
toggle_blindsigning();
switches[BLIND_SIGNING_TOKEN_ID].initState
= (nbgl_state_t)(switch_value);
} else if (token == EXPERT_MODE_TOKEN) {
switch_value = !N_settings.expert_mode;
toggle_expert_mode();
expert_mode_switch.initState = (nbgl_state_t)(switch_value);
}
if (token == BLINDSIGN_MODE_TOKEN) {
blindsign_state_t blindsign_status = (blindsign_state_t)(index % 2);
set_blindsign_status(blindsign_status);
tz_ui_home_redisplay(BLINDSIGN_PAGE);
switches[EXPERT_MODE_TOKEN_ID].initState
= (nbgl_state_t)(switch_value);
}
FUNC_LEAVE();
}

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"
#define SETTINGS_CONTENTS_NB 1
static const nbgl_content_t contentsList[SETTINGS_CONTENTS_NB] = {
{.content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB,
.content.switchesList.switches = switches,
.type = SWITCHES_LIST,
.contentActionCallback = controls_callback}
};

static const nbgl_genericContents_t tezos_settingContents
= {.callbackCallNeeded = false,
.contentsList = contentsList,
.nbContents = SETTINGS_CONTENTS_NB};
;

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"
void
initSettings(void)
{
expert_mode_switch.initState = (nbgl_state_t)(N_settings.expert_mode);
expert_mode_switch.text = "Expert mode";
expert_mode_switch.subText = "Enable expert mode signing";
expert_mode_switch.token = EXPERT_MODE_TOKEN;
expert_mode_switch.tuneId = TUNE_TAP_CASUAL;
switches[EXPERT_MODE_TOKEN_ID].initState
= (nbgl_state_t)(N_settings.expert_mode);
switches[EXPERT_MODE_TOKEN_ID].text = "Expert mode";
switches[EXPERT_MODE_TOKEN_ID].subText = "Enable expert mode signing";
switches[EXPERT_MODE_TOKEN_ID].token = EXPERT_MODE_TOKEN;
switches[EXPERT_MODE_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;

switches[BLIND_SIGNING_TOKEN_ID].initState
= (nbgl_state_t)(N_settings.blindsigning);
switches[BLIND_SIGNING_TOKEN_ID].text = "Blind signing";
switches[BLIND_SIGNING_TOKEN_ID].subText
= "Enable transaction blind signing";
switches[BLIND_SIGNING_TOKEN_ID].token = BLIND_SIGNING_TOKEN;
switches[BLIND_SIGNING_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;
}

void
tz_ui_home_redisplay(uint8_t page)
tz_ui_home_redisplay(void)
{
FUNC_ENTER(("void"));

initSettings();
static nbgl_genericContents_t tezos_settingContents = {0};
tezos_settingContents.callbackCallNeeded = false;
tezos_settingContents.nbContents = SETTINGS_CONTENTS_NB;

static nbgl_content_t contents[SETTINGS_CONTENTS_NB] = {0};
get_contents(EXPERT_MODE_TOKEN_ID, &contents[EXPERT_MODE_TOKEN_ID]);
get_contents(BLINDSIGN_MODE_TOKEN_ID, &contents[BLINDSIGN_MODE_TOKEN_ID]);

tezos_settingContents.contentsList = contents;

PRINTF("Entered settings and initialized\n");

nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT, page,
&tezos_settingContents, &infoList, NULL,
app_exit);
nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT,
INIT_HOME_PAGE, &tezos_settingContents,
&infoList, NULL, app_exit);

FUNC_LEAVE();
}
Expand Down
15 changes: 6 additions & 9 deletions app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void
blindsign_toggle()
{
FUNC_ENTER();
toggle_blindsign_status();
toggle_blindsigning();
ui_settings_init(SETTINGS_BLINDSIGN_PAGE);
FUNC_LEAVE();
}
Expand All @@ -52,8 +52,8 @@ UX_FLOW(ux_expert_mode_flow, &ux_expert_mode_step, &ux_blindsign_step,
void
ui_settings_init(int16_t page)
{
FUNC_ENTER(("%d, Expert Mode: %d, Max_Screen: ", page,
N_settings.expert_mode, N_settings.blindsign_status));
FUNC_ENTER(("%d, Expert Mode: %d, BlindSigning Mode: %d", page,
N_settings.expert_mode, N_settings.blindsigning));

if (N_settings.expert_mode) {
strncpy(global.expert_mode_state, "ENABLED",
Expand All @@ -63,17 +63,14 @@ ui_settings_init(int16_t page)
sizeof(global.expert_mode_state));
}

switch (N_settings.blindsign_status) {
case ST_BLINDSIGN_ON:
if (N_settings.blindsigning) {
strncpy(global.blindsign_state_desc, "ON",
sizeof(global.blindsign_state_desc));
break;
case ST_BLINDSIGN_OFF:
default:
} else {
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) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ tz_ui_stream_cb(void)
tz_ui_stream_t *s = &global.stream;
tz_ui_stream_display_t *c = &s->current_screen;

if (N_settings.blindsign_status == ST_BLINDSIGN_ON) {
if (N_settings.blindsigning) {
nbgl_useCaseReviewStreamingContinueExt(
&c->list, tz_transaction_choice, blindsign_skip_callback);
} else {
Expand Down Expand Up @@ -292,7 +292,7 @@ tz_ui_stream_init(void (*cb)(tz_ui_cb_type_t cb_type))
global.blindsign_reason = REASON_NONE;
memset(&global.error_code, '\0', ERROR_CODE_SIZE);
nbgl_operationType_t op_type = TYPE_TRANSACTION;
if (N_settings.blindsign_status == ST_BLINDSIGN_ON) {
if (N_settings.blindsigning) {
op_type |= SKIPPABLE_OPERATION;
}
nbgl_useCaseReviewStreamingStart(op_type, &C_tezos,
Expand Down
Binary file not shown.
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.
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.
Binary file not shown.
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.
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.
25 changes: 17 additions & 8 deletions tests/integration/touch/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from utils import tezos_app, BlindsigningStatus
from utils import tezos_app

if __name__ == "__main__":
app = tezos_app(__file__)

app.assert_home()

app.set_expert_mode(initial_status=False)
app.set_expert_mode(initial_status=True)
app.set_blindsigning_status(BlindsigningStatus.ON)
app.set_blindsigning_status(BlindsigningStatus.OFF)
app.remove_settings_and_info()

app.welcome.settings()
app.settings.next()
app.assert_settings()

app.settings.toggle_blindsigning()
app.assert_settings(blindsigning=True)

app.settings.toggle_expert_mode()
app.assert_settings(blindsigning=True, expert_mode=True)

app.settings.toggle_blindsigning()
app.assert_settings(expert_mode=True)

app.settings.toggle_expert_mode()
app.assert_settings()

app.settings.next()
app.assert_info()

app.settings.multi_page_exit()
app.settings.exit()
app.assert_home()

app.quit()
32 changes: 26 additions & 6 deletions tests/integration/touch/test_blindsign_different_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from utils import (
tezos_app,
TezosAppScreen,
send_payload,
BlindsigningStatus,
send_payload
)

from ragger.firmware import Firmware
Expand Down Expand Up @@ -69,11 +68,17 @@ def blindsign_review_sign(app: TezosAppScreen):
app = tezos_app(__file__)

app.assert_home()
app.set_expert_mode(initial_status=False)
app.welcome.settings()
app.assert_settings()
app.settings.toggle_expert_mode()
app.assert_settings(expert_mode=True)
app.settings.exit()

# Blindsign status OFF
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.OFF)
app.welcome.settings()
app.assert_settings(blindsigning=False, expert_mode=True)
app.settings.exit()

if(app.firmware == Firmware.STAX):
navigate_common(app, skip=False, group_counts=[3, 1, 6, 2])
Expand All @@ -82,7 +87,11 @@ def blindsign_review_sign(app: TezosAppScreen):

# Blindsign status ON
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.ON)
app.welcome.settings()
app.assert_settings(expert_mode=True)
app.settings.toggle_blindsigning()
app.assert_settings(blindsigning=True, expert_mode=True)
app.settings.exit()

app.send_initialize_msg( "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f01ffeb0300000000000000000000000000000000000000000000000000000000000000006b00ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0b0104020320182716513907b6bab33f905396d031931c07e01bddd780780c1a56b9c086da6c00ffdd6102321bc251e4a5190ad5b12b251069d9b480897a0c0107c08db701000278eb8b6ab9a768579cd5146b480789650c83f28effff0d7570646174655f636f6e6669670000000607070005030a6e00ffdd6102321bc251e4a5190ad5b12b251069d9b4c08db7010d0105ff01ee572f02e5be5d097ba17369789582882e8abb87c900ffdd6102321bc2")
Expand All @@ -99,9 +108,20 @@ def blindsign_review_sign(app: TezosAppScreen):

# Blindsign status ON but continue clear signing
app.assert_home()
app.set_blindsigning_status(BlindsigningStatus.ON)
app.welcome.settings()
app.assert_settings(blindsigning=True, expert_mode=True)
app.settings.exit()

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])

app.assert_home()
app.welcome.settings()
app.assert_settings(blindsigning=True, expert_mode=True)
app.settings.toggle_blindsigning()
app.settings.toggle_expert_mode()
app.assert_settings()
app.settings.exit()
app.assert_home()
Loading

0 comments on commit 40ea53f

Please sign in to comment.