From 3c913cace83b62b4e963c91c04b6b0e52af555a2 Mon Sep 17 00:00:00 2001 From: cryi Date: Sat, 22 Apr 2023 12:50:26 +0200 Subject: [PATCH 1/2] protect ledger screen when baking --- src/apdu_sign.c | 1 + src/ui.h | 4 +++- src/ui_empty.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ui_nano_x.c | 10 +++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/ui_empty.c diff --git a/src/apdu_sign.c b/src/apdu_sign.c index ac3071a0..300cdda6 100644 --- a/src/apdu_sign.c +++ b/src/apdu_sign.c @@ -563,6 +563,7 @@ size_t handle_apdu_sign_with_hash(uint8_t instruction) { static int perform_signature(bool const on_hash, bool const send_hash) { #ifdef BAKING_APP write_high_water_mark(&G.parsed_baking_data); + ux_empty_screen(); #else if (on_hash && G.hash_only) { memcpy(G_io_apdu_buffer, G.final_hash, sizeof(G.final_hash)); diff --git a/src/ui.h b/src/ui.h index 57319e69..096a380e 100644 --- a/src/ui.h +++ b/src/ui.h @@ -17,7 +17,9 @@ __attribute__((noreturn)) bool exit_app( __attribute__((noreturn)) void ux_confirm_screen(ui_callback_t ok_c, ui_callback_t cxl_c); void ux_idle_screen(ui_callback_t ok_c, ui_callback_t cxl_c); - +#ifdef BAKING_APP +void ux_empty_screen(); +#endif /* Initializes the formatter stack. Should be called once before calling `push_ui_callback()`. */ void init_screen_stack(); /* User MUST call `init_screen_stack()` before calling this function for the first time. */ diff --git a/src/ui_empty.c b/src/ui_empty.c new file mode 100644 index 00000000..055b9ccf --- /dev/null +++ b/src/ui_empty.c @@ -0,0 +1,60 @@ +#ifdef BAKING_APP +#include "bolos_target.h" + +#include "ui.h" + +const bagl_element_t empty_screen_elements[] = { +#if (BAGL_WIDTH == 128 && BAGL_HEIGHT == 64) + {{BAGL_RECTANGLE, 0x00, 0, 0, 128, 64, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, + .text = NULL}, +#elif (BAGL_WIDTH == 128 && BAGL_HEIGHT == 32) + {{BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, + .text = NULL}, +#else +#error "BAGL_WIDTH/BAGL_HEIGHT not defined" +#endif + {{BAGL_LABELINE, + 0x10, + 6, + 12, + 116, + 32, + 0, + 0, + 0, + 0xFFFFFF, + 0x000000, + BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, + 0}, + .text = NULL}}; + +typedef struct ux_layout_empty_params_s { + const char *line1; +} ux_layout_empty_params_t; + +void ux_layout_empty_init(unsigned int stack_slot) { + ux_stack_init(stack_slot); + G_ux.stack[stack_slot].element_arrays[0].element_array = empty_screen_elements; + G_ux.stack[stack_slot].element_arrays[0].element_array_count = ARRAYLEN(empty_screen_elements); + G_ux.stack[stack_slot].element_arrays_count = 1; + G_ux.stack[stack_slot].button_push_callback = ux_flow_button_callback; + G_ux.stack[stack_slot].screen_before_element_display_callback = ux_layout_strings_prepro; + ux_stack_display(stack_slot); +} + +void ux_layout_empty_screen_init(unsigned int whatever) { +} + +void return_to_idle() { + ux_idle_screen(NULL, NULL); +} + +UX_STEP_CB(empty_screen_step, empty, return_to_idle(), {" "}); +UX_STEP_INIT(empty_screen_border, NULL, NULL, { return_to_idle(); }); +UX_FLOW(ux_empty_flow, &empty_screen_step, &empty_screen_border, FLOW_LOOP); + +void ux_empty_screen() { + ux_flow_init(0, ux_empty_flow, NULL); +} + +#endif \ No newline at end of file diff --git a/src/ui_nano_x.c b/src/ui_nano_x.c index 6d0d881a..63d196be 100644 --- a/src/ui_nano_x.c +++ b/src/ui_nano_x.c @@ -82,12 +82,22 @@ UX_STEP_NOCB(ux_variable_display, }); UX_STEP_INIT(ux_init_lower_border, NULL, NULL, { display_next_state(false); }); +#if BAKING_APP +UX_STEP_CB(ux_app_is_ready_step, + nn, + ux_empty_screen(), + { + "Application", + "is ready", + }); +#else UX_STEP_NOCB(ux_app_is_ready_step, nn, { "Application", "is ready", }); +#endif UX_STEP_CB(ux_idle_quit_step, pb, From 906082ce3f91b22d0388001fba662221aebd65ef Mon Sep 17 00:00:00 2001 From: V <36897290+cryi@users.noreply.github.com> Date: Wed, 5 Jul 2023 21:20:32 +0200 Subject: [PATCH 2/2] Update version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f1a63413..9b8bf4ee 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2 VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-) APPVERSION_M=2 APPVERSION_N=3 -APPVERSION_P=2 +APPVERSION_P=3 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) # Only warn about version tags if specified/inferred