From 34abaa7e27017f7d65a5e2a0d9834982293fd5e4 Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:35:15 +0900 Subject: [PATCH 1/3] [FL-3815] Fix the retry/exit confirmation prompts in iButton (#3613) --- .../ibutton/scenes/ibutton_scene_config.h | 1 - .../scenes/ibutton_scene_read_exit_confirm.c | 59 ------------------- .../scenes/ibutton_scene_read_success.c | 2 +- .../scenes/ibutton_scene_retry_confirm.c | 2 +- 4 files changed, 2 insertions(+), 62 deletions(-) delete mode 100644 applications/main/ibutton/scenes/ibutton_scene_read_exit_confirm.c diff --git a/applications/main/ibutton/scenes/ibutton_scene_config.h b/applications/main/ibutton/scenes/ibutton_scene_config.h index f3fd0fff77..79f6791b3b 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_config.h +++ b/applications/main/ibutton/scenes/ibutton_scene_config.h @@ -17,6 +17,5 @@ ADD_SCENE(ibutton, delete_confirm, DeleteConfirm) ADD_SCENE(ibutton, delete_success, DeleteSuccess) ADD_SCENE(ibutton, retry_confirm, RetryConfirm) ADD_SCENE(ibutton, exit_confirm, ExitConfirm) -ADD_SCENE(ibutton, read_exit_confirm, ReadExitConfirm) ADD_SCENE(ibutton, view_data, ViewData) ADD_SCENE(ibutton, rpc, Rpc) diff --git a/applications/main/ibutton/scenes/ibutton_scene_read_exit_confirm.c b/applications/main/ibutton/scenes/ibutton_scene_read_exit_confirm.c deleted file mode 100644 index 4077de9a63..0000000000 --- a/applications/main/ibutton/scenes/ibutton_scene_read_exit_confirm.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "../ibutton_i.h" - -static void ibutton_scene_read_exit_confirm_widget_callback( - GuiButtonType result, - InputType type, - void* context) { - iButton* ibutton = context; - if(type == InputTypeShort) { - view_dispatcher_send_custom_event(ibutton->view_dispatcher, result); - } -} - -void ibutton_scene_read_exit_confirm_on_enter(void* context) { - iButton* ibutton = context; - Widget* widget = ibutton->widget; - - widget_add_button_element( - widget, - GuiButtonTypeLeft, - "Exit", - ibutton_scene_read_exit_confirm_widget_callback, - ibutton); - widget_add_button_element( - widget, - GuiButtonTypeRight, - "Stay", - ibutton_scene_read_exit_confirm_widget_callback, - ibutton); - widget_add_string_element( - widget, 64, 19, AlignCenter, AlignBottom, FontPrimary, "Retry Reading?"); - widget_add_string_element( - widget, 64, 31, AlignCenter, AlignBottom, FontSecondary, "All unsaved data will be lost!"); - - view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget); -} - -bool ibutton_scene_read_exit_confirm_on_event(void* context, SceneManagerEvent event) { - iButton* ibutton = context; - SceneManager* scene_manager = ibutton->scene_manager; - bool consumed = false; - - if(event.type == SceneManagerEventTypeBack) { - consumed = true; // Ignore Back button presses - } else if(event.type == SceneManagerEventTypeCustom) { - consumed = true; - if(event.event == GuiButtonTypeLeft) { - scene_manager_search_and_switch_to_previous_scene(scene_manager, iButtonSceneRead); - } else if(event.event == GuiButtonTypeRight) { - scene_manager_previous_scene(scene_manager); - } - } - - return consumed; -} - -void ibutton_scene_read_exit_confirm_on_exit(void* context) { - iButton* ibutton = context; - widget_reset(ibutton->widget); -} diff --git a/applications/main/ibutton/scenes/ibutton_scene_read_success.c b/applications/main/ibutton/scenes/ibutton_scene_read_success.c index 6dd06ca526..a6c4db12a9 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_read_success.c +++ b/applications/main/ibutton/scenes/ibutton_scene_read_success.c @@ -44,7 +44,7 @@ bool ibutton_scene_read_success_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeBack) { consumed = true; - scene_manager_next_scene(scene_manager, iButtonSceneReadExitConfirm); + scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm); } else if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == GuiButtonTypeRight) { diff --git a/applications/main/ibutton/scenes/ibutton_scene_retry_confirm.c b/applications/main/ibutton/scenes/ibutton_scene_retry_confirm.c index 34de5b8778..75ae84a146 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_retry_confirm.c +++ b/applications/main/ibutton/scenes/ibutton_scene_retry_confirm.c @@ -15,7 +15,7 @@ void ibutton_scene_retry_confirm_on_enter(void* context) { Widget* widget = ibutton->widget; widget_add_button_element( - widget, GuiButtonTypeLeft, "Exit", ibutton_scene_retry_confirm_widget_callback, ibutton); + widget, GuiButtonTypeLeft, "Retry", ibutton_scene_retry_confirm_widget_callback, ibutton); widget_add_button_element( widget, GuiButtonTypeRight, "Stay", ibutton_scene_retry_confirm_widget_callback, ibutton); widget_add_string_element( From 1559ee6293dbadfaebf22fd4d18fe820db65d638 Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:47:40 +0900 Subject: [PATCH 2/3] [Fl-3809] Troika parser visual fixes (#3614) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- .../nfc/api/mosgortrans/mosgortrans_util.c | 2 +- .../main/nfc/plugins/supported_cards/troika.c | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/applications/main/nfc/api/mosgortrans/mosgortrans_util.c b/applications/main/nfc/api/mosgortrans/mosgortrans_util.c index 8844ee4afe..3138d790b3 100644 --- a/applications/main/nfc/api/mosgortrans/mosgortrans_util.c +++ b/applications/main/nfc/api/mosgortrans/mosgortrans_util.c @@ -506,7 +506,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString* if(data_block.valid_from_date == 0 || data_block.valid_to_date == 0) { furi_string_cat(result, "\e#No ticket"); - return true; + return false; } //remaining_trips furi_string_cat_printf(result, "Trips: %d\n", data_block.total_trips); diff --git a/applications/main/nfc/plugins/supported_cards/troika.c b/applications/main/nfc/plugins/supported_cards/troika.c index cccee769fe..64a9ac5dc6 100644 --- a/applications/main/nfc/plugins/supported_cards/troika.c +++ b/applications/main/nfc/plugins/supported_cards/troika.c @@ -83,6 +83,20 @@ static const MfClassicKeyPair troika_4k_keys[] = { {.a = 0xBB52F8CCE07F, .b = 0x6B6119752C70}, //40 }; +static void troika_render_section_header( + FuriString* str, + const char* name, + uint8_t prefix_separator_cnt, + uint8_t suffix_separator_cnt) { + for(uint8_t i = 0; i < prefix_separator_cnt; i++) { + furi_string_cat_printf(str, ":"); + } + furi_string_cat_printf(str, "[ %s ]", name); + for(uint8_t i = 0; i < suffix_separator_cnt; i++) { + furi_string_cat_printf(str, ":"); + } +} + static bool troika_get_card_config(TroikaCardConfig* config, MfClassicType type) { bool success = true; @@ -204,18 +218,19 @@ static bool troika_parse(const NfcDevice* device, FuriString* parsed_data) { bool result3 = mosgortrans_parse_transport_block(&data->block[16], tat_result); furi_string_cat_printf(parsed_data, "\e#Troyka card\n"); - if(result1) { - furi_string_cat_printf( - parsed_data, "\e#Metro\n%s\n", furi_string_get_cstr(metro_result)); + if(result1 && !furi_string_empty(metro_result)) { + troika_render_section_header(parsed_data, "Metro", 22, 21); + furi_string_cat_printf(parsed_data, "%s\n", furi_string_get_cstr(metro_result)); } - if(result2) { - furi_string_cat_printf( - parsed_data, "\n\e#Ediniy\n%s\n", furi_string_get_cstr(ground_result)); + if(result2 && !furi_string_empty(ground_result)) { + troika_render_section_header(parsed_data, "Ediny", 22, 22); + furi_string_cat_printf(parsed_data, "%s\n", furi_string_get_cstr(ground_result)); } - if(result3) { - furi_string_cat_printf(parsed_data, "\n\e#TAT\n%s", furi_string_get_cstr(tat_result)); + if(result3 && !furi_string_empty(tat_result)) { + troika_render_section_header(parsed_data, "TAT", 24, 23); + furi_string_cat_printf(parsed_data, "%s\n", furi_string_get_cstr(tat_result)); } furi_string_free(tat_result); From 43c4381820175d73b2ee3b39d7c6b7bee63b9cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Thu, 25 Apr 2024 08:39:38 +0900 Subject: [PATCH 3/3] [FL-3814] Desktop: cleanup error popups (#3615) * Desktop: cleanup error popups, add missing factory keys notification * Desktop: enclave warning wording --- applications/services/desktop/desktop.c | 17 ++++-- applications/services/desktop/desktop_i.h | 4 +- .../desktop/scenes/desktop_scene_config.h | 1 + .../desktop/scenes/desktop_scene_fault.c | 16 ++++-- .../scenes/desktop_scene_hw_mismatch.c | 24 ++++---- .../scenes/desktop_scene_secure_enclave.c | 57 +++++++++++++++++++ .../services/desktop/views/desktop_events.h | 4 ++ 7 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 applications/services/desktop/scenes/desktop_scene_secure_enclave.c diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index c5a334a450..a9560f31de 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -298,7 +298,7 @@ Desktop* desktop_alloc(void) { desktop->lock_menu = desktop_lock_menu_alloc(); desktop->debug_view = desktop_debug_alloc(); - desktop->hw_mismatch_popup = popup_alloc(); + desktop->popup = popup_alloc(); desktop->locked_view = desktop_view_locked_alloc(); desktop->pin_input_view = desktop_view_pin_input_alloc(); desktop->pin_timeout_view = desktop_view_pin_timeout_alloc(); @@ -334,9 +334,7 @@ Desktop* desktop_alloc(void) { view_dispatcher_add_view( desktop->view_dispatcher, DesktopViewIdDebug, desktop_debug_get_view(desktop->debug_view)); view_dispatcher_add_view( - desktop->view_dispatcher, - DesktopViewIdHwMismatch, - popup_get_view(desktop->hw_mismatch_popup)); + desktop->view_dispatcher, DesktopViewIdPopup, popup_get_view(desktop->popup)); view_dispatcher_add_view( desktop->view_dispatcher, DesktopViewIdPinTimeout, @@ -476,6 +474,17 @@ int32_t desktop_srv(void* p) { scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault); } + uint8_t keys_total, keys_valid; + if(!furi_hal_crypto_enclave_verify(&keys_total, &keys_valid)) { + FURI_LOG_E( + TAG, + "Secure Enclave verification failed: total %hhu, valid %hhu", + keys_total, + keys_valid); + + scene_manager_next_scene(desktop->scene_manager, DesktopSceneSecureEnclave); + } + // Special case: autostart application is already running if(loader_is_locked(desktop->loader) && animation_manager_is_animation_loaded(desktop->animation_manager)) { diff --git a/applications/services/desktop/desktop_i.h b/applications/services/desktop/desktop_i.h index c0b29f922d..b694e05f83 100644 --- a/applications/services/desktop/desktop_i.h +++ b/applications/services/desktop/desktop_i.h @@ -28,7 +28,7 @@ typedef enum { DesktopViewIdLockMenu, DesktopViewIdLocked, DesktopViewIdDebug, - DesktopViewIdHwMismatch, + DesktopViewIdPopup, DesktopViewIdPinInput, DesktopViewIdPinTimeout, DesktopViewIdSlideshow, @@ -43,7 +43,7 @@ struct Desktop { ViewDispatcher* view_dispatcher; SceneManager* scene_manager; - Popup* hw_mismatch_popup; + Popup* popup; DesktopLockMenuView* lock_menu; DesktopDebugView* debug_view; DesktopViewLocked* locked_view; diff --git a/applications/services/desktop/scenes/desktop_scene_config.h b/applications/services/desktop/scenes/desktop_scene_config.h index c153972b29..34d0005433 100644 --- a/applications/services/desktop/scenes/desktop_scene_config.h +++ b/applications/services/desktop/scenes/desktop_scene_config.h @@ -7,3 +7,4 @@ ADD_SCENE(desktop, locked, Locked) ADD_SCENE(desktop, pin_input, PinInput) ADD_SCENE(desktop, pin_timeout, PinTimeout) ADD_SCENE(desktop, slideshow, Slideshow) +ADD_SCENE(desktop, secure_enclave, SecureEnclave) \ No newline at end of file diff --git a/applications/services/desktop/scenes/desktop_scene_fault.c b/applications/services/desktop/scenes/desktop_scene_fault.c index 36c958af58..16683ba745 100644 --- a/applications/services/desktop/scenes/desktop_scene_fault.c +++ b/applications/services/desktop/scenes/desktop_scene_fault.c @@ -12,20 +12,21 @@ void desktop_scene_fault_callback(void* context) { void desktop_scene_fault_on_enter(void* context) { Desktop* desktop = (Desktop*)context; - Popup* popup = desktop->hw_mismatch_popup; + Popup* popup = desktop->popup; popup_set_context(popup, desktop); popup_set_header( popup, "Flipper crashed\n and was rebooted", - 60, + 64, 14 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); char* message = (char*)furi_hal_rtc_get_fault_data(); - popup_set_text(popup, message, 60, 37 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); + popup_set_text(popup, message, 64, 37 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); popup_set_callback(popup, desktop_scene_fault_callback); - view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdHwMismatch); + + view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdPopup); } bool desktop_scene_fault_on_event(void* context, SceneManagerEvent event) { @@ -47,6 +48,11 @@ bool desktop_scene_fault_on_event(void* context, SceneManagerEvent event) { } void desktop_scene_fault_on_exit(void* context) { - UNUSED(context); + Desktop* desktop = (Desktop*)context; + furi_assert(desktop); + + Popup* popup = desktop->popup; + popup_reset(popup); + furi_hal_rtc_set_fault_data(0); } diff --git a/applications/services/desktop/scenes/desktop_scene_hw_mismatch.c b/applications/services/desktop/scenes/desktop_scene_hw_mismatch.c index 35c5061035..4624b589c4 100644 --- a/applications/services/desktop/scenes/desktop_scene_hw_mismatch.c +++ b/applications/services/desktop/scenes/desktop_scene_hw_mismatch.c @@ -4,17 +4,15 @@ #include "desktop_scene.h" #include "../desktop_i.h" -#define HW_MISMATCH_BACK_EVENT (0UL) - void desktop_scene_hw_mismatch_callback(void* context) { Desktop* desktop = (Desktop*)context; - view_dispatcher_send_custom_event(desktop->view_dispatcher, HW_MISMATCH_BACK_EVENT); + view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopHwMismatchExit); } void desktop_scene_hw_mismatch_on_enter(void* context) { Desktop* desktop = (Desktop*)context; furi_assert(desktop); - Popup* popup = desktop->hw_mismatch_popup; + Popup* popup = desktop->popup; char* text_buffer = malloc(256); scene_manager_set_scene_state( @@ -28,10 +26,10 @@ void desktop_scene_hw_mismatch_on_enter(void* context) { version_get_target(NULL)); popup_set_context(popup, desktop); popup_set_header( - popup, "!!!! HW Mismatch !!!!", 60, 14 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); - popup_set_text(popup, text_buffer, 60, 37 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); + popup, "!!!! HW Mismatch !!!!", 64, 12 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignBottom); + popup_set_text(popup, text_buffer, 64, 33 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter); popup_set_callback(popup, desktop_scene_hw_mismatch_callback); - view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdHwMismatch); + view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdPopup); } bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) { @@ -40,11 +38,10 @@ bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { - case HW_MISMATCH_BACK_EVENT: + case DesktopHwMismatchExit: scene_manager_previous_scene(desktop->scene_manager); consumed = true; break; - default: break; } @@ -55,11 +52,10 @@ bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) void desktop_scene_hw_mismatch_on_exit(void* context) { Desktop* desktop = (Desktop*)context; furi_assert(desktop); - Popup* popup = desktop->hw_mismatch_popup; - popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); - popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); - popup_set_callback(popup, NULL); - popup_set_context(popup, NULL); + + Popup* popup = desktop->popup; + popup_reset(popup); + char* text_buffer = (char*)scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneHwMismatch); free(text_buffer); diff --git a/applications/services/desktop/scenes/desktop_scene_secure_enclave.c b/applications/services/desktop/scenes/desktop_scene_secure_enclave.c new file mode 100644 index 0000000000..c08125c709 --- /dev/null +++ b/applications/services/desktop/scenes/desktop_scene_secure_enclave.c @@ -0,0 +1,57 @@ +#include +#include + +#include "desktop_scene.h" +#include "../desktop_i.h" + +void desktop_scene_secure_enclave_callback(void* context) { + Desktop* desktop = (Desktop*)context; + view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopEnclaveExit); +} + +void desktop_scene_secure_enclave_on_enter(void* context) { + Desktop* desktop = (Desktop*)context; + furi_assert(desktop); + + Popup* popup = desktop->popup; + popup_set_context(popup, desktop); + popup_set_header( + popup, "No Factory Keys Found", 64, 12 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignBottom); + popup_set_text( + popup, + "Secure Enclave is damaged.\n" + "Some apps will not work.", + 64, + 33 + STATUS_BAR_Y_SHIFT, + AlignCenter, + AlignCenter); + popup_set_callback(popup, desktop_scene_secure_enclave_callback); + + view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdPopup); +} + +bool desktop_scene_secure_enclave_on_event(void* context, SceneManagerEvent event) { + Desktop* desktop = (Desktop*)context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case DesktopEnclaveExit: + scene_manager_previous_scene(desktop->scene_manager); + consumed = true; + break; + + default: + break; + } + } + return consumed; +} + +void desktop_scene_secure_enclave_on_exit(void* context) { + Desktop* desktop = (Desktop*)context; + furi_assert(desktop); + + Popup* popup = desktop->popup; + popup_reset(popup); +} diff --git a/applications/services/desktop/views/desktop_events.h b/applications/services/desktop/views/desktop_events.h index bce9c09d1a..7749a7e153 100644 --- a/applications/services/desktop/views/desktop_events.h +++ b/applications/services/desktop/views/desktop_events.h @@ -46,6 +46,10 @@ typedef enum { DesktopSlideshowCompleted, DesktopSlideshowPoweroff, + DesktopHwMismatchExit, + + DesktopEnclaveExit, + // Global events DesktopGlobalBeforeAppStarted, DesktopGlobalAfterAppFinished,