diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index c5a334a45..a9560f31d 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 c0b29f922..b694e05f8 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 c153972b2..34d000543 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 36c958af5..16683ba74 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 35c506103..4624b589c 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 000000000..c08125c70 --- /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 bce9c09d1..7749a7e15 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,