Skip to content

Commit

Permalink
Removed duplicated nano code
Browse files Browse the repository at this point in the history
  • Loading branch information
aido committed Apr 27, 2023
1 parent 0a3dee2 commit 96f8ada
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 736 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Change log

## [1.2.0] - 2023-04-21
## [1.3.0] - 2023-04-27
### Added
-

### Changed
- Removed duplicated Nano code
- Simplified flow code

### Fixed
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Done ✓

- [x] Remove duplicated Nano code
- [x] Simplified flow code
- [x] Add flow to set SSKR threshold values
- [x] Add automated tests
Expand Down
88 changes: 80 additions & 8 deletions src/nanos_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,78 @@
// allow to edit back any entered word
#define RESTORE_WORD_MAX_BACKWARD_STEPS 24

const bagl_element_t screen_onboarding_word_list_elements[] = {
// erase
{{BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, NULL},

{{BAGL_LABELINE,
0x01,
0,
12,
128,
32,
0,
0,
0,
0xFFFFFF,
0x000000,
BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER,
0},
G_ux.string_buffer},
{{BAGL_RECTANGLE, 0x02, 32, 16, 64, 14, 0, 4, BAGL_FILL, 0xFFFFFF, 0x000000, 0, 0}, NULL},
{{BAGL_LABELINE,
0x02,
0,
26,
128,
32,
0,
0,
0,
0x000000,
0xFFFFFF,
BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER,
0},
G_ux.string_buffer},

// left/rights icons
{{BAGL_ICON, 0x03, 3, 12, 4, 7, 0, 0, 0, 0xFFFFFF, 0x000000, 0, 0}, (const char*) &C_icon_left},
{{BAGL_ICON, 0x04, 121, 12, 4, 7, 0, 0, 0, 0xFFFFFF, 0x000000, 0, 0},
(const char*) &C_icon_right},

// supplementary static entry
{{BAGL_ICON, 0x05, 16, 9, 14, 14, 0, 0, 0, 0xFFFFFF, 0x000000, 0, 0},
(const char*) &C_icon_back},
{{BAGL_LABELINE,
0x05,
41,
12,
128,
32,
0,
0,
0,
0xFFFFFF,
0x000000,
BAGL_FONT_OPEN_SANS_EXTRABOLD_11px,
0},
"Restart from"},
{{BAGL_LABELINE,
0x06,
41,
26,
128,
32,
0,
0,
0,
0xFFFFFF,
0x000000,
BAGL_FONT_OPEN_SANS_EXTRABOLD_11px,
0},
G_ux.string_buffer},
};

const bagl_element_t* screen_onboarding_restore_word_before_element_display_callback(
const bagl_element_t* element);

Expand All @@ -45,7 +117,7 @@ UX_STEP_NOCB(ux_bip39_nomatch_step_2,
});
UX_STEP_VALID(ux_bip39_nomatch_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});

UX_FLOW(flow_final_bip39_nomatch,
UX_FLOW(ux_bip39_nomatch_flow,
&ux_bip39_nomatch_step_1,
&ux_bip39_nomatch_step_2,
&ux_bip39_nomatch_step_3);
Expand All @@ -60,7 +132,7 @@ UX_STEP_CB(ux_bip39_match_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Q
UX_STEP_CB(ux_bip39_match_step_3, pbb, set_sskr_descriptor_values();
, {&SSKR_ICON, "Generate", "SSKR phrases"});

UX_FLOW(flow_final_bip39_match,
UX_FLOW(ux_bip39_match_flow,
&ux_bip39_match_step_1,
&ux_bip39_match_step_2,
&ux_bip39_match_step_3);
Expand All @@ -79,7 +151,7 @@ UX_STEP_NOCB(ux_sskr_nomatch_step_2,
});
UX_STEP_VALID(ux_sskr_nomatch_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});

UX_FLOW(flow_final_sskr_nomatch,
UX_FLOW(ux_sskr_nomatch_flow,
&ux_sskr_nomatch_step_1,
&ux_sskr_nomatch_step_2,
&ux_sskr_nomatch_step_3);
Expand All @@ -93,7 +165,7 @@ UX_STEP_CB(ux_sskr_match_step_1, pbb, os_sched_exit(0);,
UX_STEP_CB(ux_sskr_match_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit"});
UX_STEP_CB(ux_sskr_match_step_3, pbb, generate_bip39();, {&BIP39_ICON, "Generate", "BIP39 phrase"});

UX_FLOW(flow_final_sskr_match, &ux_sskr_match_step_1, &ux_sskr_match_step_2, &ux_sskr_match_step_3);
UX_FLOW(ux_sskr_match_flow, &ux_sskr_match_step_1, &ux_sskr_match_step_2, &ux_sskr_match_step_3);

void screen_processing_postinit(unsigned int stack_slot) {
// ensure when pin is modal over the processing screen( at end of install) the processing screen
Expand Down Expand Up @@ -319,12 +391,12 @@ void compare_recovery_phrase(void) {
if (os_secure_memcmp(buffer, buffer_device, 64)) {
memset(G_bolos_ux_context.words_buffer, 0, G_bolos_ux_context.words_buffer_length);
(G_bolos_ux_context.onboarding_type == BOLOS_UX_ONBOARDING_BIP39)
? ux_flow_init(0, flow_final_bip39_nomatch, NULL)
: ux_flow_init(0, flow_final_sskr_nomatch, NULL);
? ux_flow_init(0, ux_bip39_nomatch_flow, NULL)
: ux_flow_init(0, ux_sskr_nomatch_flow, NULL);
} else {
(G_bolos_ux_context.onboarding_type == BOLOS_UX_ONBOARDING_BIP39)
? ux_flow_init(0, flow_final_bip39_match, NULL)
: ux_flow_init(0, flow_final_sskr_match, NULL);
? ux_flow_init(0, ux_bip39_match_flow, NULL)
: ux_flow_init(0, ux_sskr_match_flow, NULL);
}
}

Expand Down
62 changes: 30 additions & 32 deletions src/nanox_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,56 +154,54 @@ UX_STEP_VALID(ux_wrong_seed_step,
});
UX_FLOW(ux_wrong_seed_flow, &ux_wrong_seed_step);

UX_STEP_NOCB(ux_bip39_failed_check_step_1, pbb, {&C_icon_warning, "BIP39 Phrase", "doesn't match"});
UX_STEP_NOCB(ux_bip39_failed_check_step_2,
UX_STEP_NOCB(ux_bip39_nomatch_step_1, pbb, {&C_icon_warning, "BIP39 Phrase", "doesn't match"});
UX_STEP_NOCB(ux_bip39_nomatch_step_2,
nn,
{
"Check length",
"order and spelling",
});
UX_STEP_VALID(ux_bip39_failed_check_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});
UX_FLOW(ux_bip39_failed_check_flow,
&ux_bip39_failed_check_step_1,
&ux_bip39_failed_check_step_2,
&ux_bip39_failed_check_step_3);
UX_STEP_VALID(ux_bip39_nomatch_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});
UX_FLOW(ux_bip39_nomatch_flow,
&ux_bip39_nomatch_step_1,
&ux_bip39_nomatch_step_2,
&ux_bip39_nomatch_step_3);

UX_STEP_VALID(ux_bip39_success_step_1,
UX_STEP_VALID(ux_bip39_match_step_1,
pbb,
os_sched_exit(-1),
{&C_icon_validate_14, "BIP39 Phrase", "is correct"});
UX_STEP_CB(ux_bip39_success_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit"});
UX_STEP_CB(ux_bip39_success_step_3, pbb, set_sskr_descriptor_values();
UX_STEP_CB(ux_bip39_match_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit"});
UX_STEP_CB(ux_bip39_match_step_3, pbb, set_sskr_descriptor_values();
, {&SSKR_ICON, "Generate", "SSKR phrases"});

UX_FLOW(ux_bip39_succesful_check_flow,
&ux_bip39_success_step_1,
&ux_bip39_success_step_2,
&ux_bip39_success_step_3);
UX_FLOW(ux_bip39_match_flow,
&ux_bip39_match_step_1,
&ux_bip39_match_step_2,
&ux_bip39_match_step_3);

UX_STEP_NOCB(ux_sskr_failed_check_step_1, pbb, {&C_icon_warning, "SSKR Phrase", "doesn't match"});
UX_STEP_NOCB(ux_sskr_failed_check_step_2,
UX_STEP_NOCB(ux_sskr_nomatch_step_1, pbb, {&C_icon_warning, "SSKR Phrase", "doesn't match"});
UX_STEP_NOCB(ux_sskr_nomatch_step_2,
nn,
{
"Check length",
"order and spelling",
});
UX_STEP_VALID(ux_sskr_failed_check_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});
UX_FLOW(ux_sskr_failed_check_flow,
&ux_sskr_failed_check_step_1,
&ux_sskr_failed_check_step_2,
&ux_sskr_failed_check_step_3);
UX_STEP_VALID(ux_sskr_nomatch_step_3, pb, ui_idle_init(), {&C_icon_back_x, "Return to menu"});
UX_FLOW(ux_sskr_nomatch_flow,
&ux_sskr_nomatch_step_1,
&ux_sskr_nomatch_step_2,
&ux_sskr_nomatch_step_3);

UX_STEP_VALID(ux_sskr_success_step_1,
UX_STEP_VALID(ux_sskr_match_step_1,
pbb,
os_sched_exit(-1),
{&C_icon_validate_14, "SSKR Phrase", "is correct"});
UX_STEP_CB(ux_sskr_success_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit"});
UX_STEP_CB(ux_sskr_success_step_3, pbb, generate_bip39();, {&BIP39_ICON, "Generate", "BIP39 phrases"});
UX_STEP_CB(ux_sskr_match_step_2, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit"});
UX_STEP_CB(ux_sskr_match_step_3, pbb, generate_bip39();
, {&BIP39_ICON, "Generate", "BIP39 phrases"});

UX_FLOW(ux_sskr_succesful_check_flow,
&ux_sskr_success_step_1,
&ux_sskr_success_step_2,
&ux_sskr_success_step_3);
UX_FLOW(ux_sskr_match_flow, &ux_sskr_match_step_1, &ux_sskr_match_step_2, &ux_sskr_match_step_3);

unsigned int screen_onboarding_restore_word_select_button(unsigned int button_mask,
unsigned int button_mask_counter);
Expand Down Expand Up @@ -578,12 +576,12 @@ void screen_onboarding_restore_word_validate(void) {
// Display loading icon to user
ux_flow_init(0, ux_load_flow, NULL);
if (compare_recovery_phrase()) {
ux_flow_init(0, ux_bip39_succesful_check_flow, NULL);
ux_flow_init(0, ux_bip39_match_flow, NULL);
} else {
memset(G_bolos_ux_context.words_buffer,
0,
G_bolos_ux_context.words_buffer_length);
ux_flow_init(0, ux_bip39_failed_check_flow, NULL);
ux_flow_init(0, ux_bip39_nomatch_flow, NULL);
}
}
} else {
Expand Down Expand Up @@ -617,12 +615,12 @@ void screen_onboarding_restore_word_validate(void) {
// Display loading icon to user
ux_flow_init(0, ux_load_flow, NULL);
if (compare_recovery_phrase()) {
ux_flow_init(0, ux_sskr_succesful_check_flow, NULL);
ux_flow_init(0, ux_sskr_match_flow, NULL);
} else {
memset(G_bolos_ux_context.words_buffer,
0,
G_bolos_ux_context.words_buffer_length);
ux_flow_init(0, ux_sskr_failed_check_flow, NULL);
ux_flow_init(0, ux_sskr_nomatch_flow, NULL);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
#include <cx.h>

#include "glyphs.h"
#include "ux_nano.h"

#if defined(TARGET_NANOS)
#include "ux_nanos.h"
#define ARRAYLEN(array) (sizeof(array) / sizeof(array[0]))
#define BIP39_ICON C_bip39_nanos
#define SSKR_ICON C_sskr_nanos
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#include "ux_nanox.h"
#define BIP39_ICON C_bip39_nanox
#define SSKR_ICON C_sskr_nanox
#endif
Expand Down
13 changes: 5 additions & 8 deletions src/ux_nanox.c → src/ux_nano.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*******************************************************************************
* (c) 2016-2022 Ledger SAS
* Ledger Blue - Secure firmware
* (c) 2016, 2017 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +15,7 @@
* limitations under the License.
********************************************************************************/

#include "ux_nanox.h"

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#include "ux_nano.h"

#ifdef OS_IO_SEPROXYHAL

Expand All @@ -28,8 +27,8 @@ unsigned short io_timeout(unsigned short last_timeout) {
return 1;
}

void io_seproxyhal_display(const bagl_element_t* element) {
io_seproxyhal_display_default((bagl_element_t*) element);
void io_seproxyhal_display(const bagl_element_t *element) {
io_seproxyhal_display_default((bagl_element_t *) element);
}

void bolos_ux_hslider3_init(unsigned int total_count) {
Expand Down Expand Up @@ -127,5 +126,3 @@ void bolos_ux_hslider3_previous(void) {
}

#endif // OS_IO_SEPROXYHAL

#endif
41 changes: 26 additions & 15 deletions src/ux_nanox.h → src/ux_nano.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

#include "ux_common/common.h"

#if defined(HAVE_BOLOS_UX) && (defined(TARGET_NANOX) || defined(TARGET_NANOS2))
#if defined(HAVE_BOLOS_UX)

#if defined(TARGET_NANOS)
typedef unsigned int (*callback_t)(unsigned int);
#endif

// bolos ux context (not mandatory if redesigning a bolos ux)
typedef struct bolos_ux_context {
Expand Down Expand Up @@ -52,28 +56,22 @@ typedef struct bolos_ux_context {

unsigned int words_buffer_length;
// after an int to make sure it's aligned
char string_buffer[MAX(64, sizeof(bagl_icon_details_t) + BOLOS_APP_ICON_SIZE_B - 1)];
char string_buffer[MAX(
64,
sizeof(bagl_icon_details_t) + BOLOS_APP_ICON_SIZE_B - 1)]; // to store the seed wholly

// 128 of words (215 => hashed to 64, or 128) + HMAC_LENGTH*2 = 256
#define WORDS_BUFFER_MAX_SIZE_B 257
char words_buffer[WORDS_BUFFER_MAX_SIZE_B];
#define MAX_PIN_LENGTH 8
#define MIN_PIN_LENGTH 4

char pin_digit_buffer; // digit to be displayed

appmain_t flow_end_callback;

// label line for common PIN and common keyboard screen (displayed over the entry)
const char* common_label;

// slider management / menu list management
unsigned int hslider3_before;
unsigned int hslider3_current;
unsigned int hslider3_after;
unsigned int hslider3_total;

keyboard_callback_t keyboard_callback;

#if (defined(TARGET_NANOX) || defined(TARGET_NANOS2))
unsigned int overlay_refresh;
unsigned int battery_percentage;
unsigned int status_batt_level;
Expand All @@ -92,6 +90,18 @@ typedef struct bolos_ux_context {
#define BATTERY_LOW_LEVEL_PERCENT 25
#define BATTERY_CRITICAL_LEVEL_PERCENT 10
#define BATTERY_AUTO_POWER_OFF_LEVEL_PERCENT 2
#endif

#define MAX_PIN_LENGTH 8
#define MIN_PIN_LENGTH 4

// slider management / menu list management
unsigned int hslider3_before;
unsigned int hslider3_current;
unsigned int hslider3_after;
unsigned int hslider3_total;

keyboard_callback_t keyboard_callback;

// detect stack/global variable overlap
// have a zero byte to avoid buffer overflow from strings in the ux (we never know)
Expand Down Expand Up @@ -125,7 +135,8 @@ void generate_bip39(void);
#include "ux_common/common_bip39.h"
#include "ux_common/common_sskr.h"

// to be included into all flow that needs to go back to the dashboard
extern const ux_flow_step_t ux_ob_goto_dashboard_step;
#if defined(TARGET_NANOS)
void screen_processing_init(void);
#endif

#endif // HAVE_BOLOS_UX_H && (TARGET_NANOX || TARGET_NANOS2)
#endif // HAVE_BOLOS_UX_H
Loading

0 comments on commit 96f8ada

Please sign in to comment.