diff --git a/project/backend/manager.c b/project/backend/manager.c index 6516971..eb94376 100644 --- a/project/backend/manager.c +++ b/project/backend/manager.c @@ -85,12 +85,12 @@ void manager_loadnames(Manager* manager){ } // Constructors -Manager* manager_init() { +Manager* manager_init(char* key) { // Creating result in memory Manager* result = malloc(sizeof(Manager)); // Setting variables - result->secure_storage = secure_storage_init("password"); + result->secure_storage = secure_storage_init(key); result->count = 0; // Loading all names on start diff --git a/project/backend/manager.h b/project/backend/manager.h index 4630ca6..ad6a0af 100644 --- a/project/backend/manager.h +++ b/project/backend/manager.h @@ -20,7 +20,7 @@ typedef struct { } Manager; // Constructors -Manager* manager_init(); +Manager* manager_init(char* key); // Functions void manager_savepass(Manager* manager, Password* pass); diff --git a/project/backend/secure.c b/project/backend/secure.c index 463a707..be2f6a3 100644 --- a/project/backend/secure.c +++ b/project/backend/secure.c @@ -1,13 +1,19 @@ // Header #include "secure.h" +// Constants +#define KEYBOARD_STR_LEN 64 + // Constructors SecureStorage* secure_storage_init(char* key){ // Creating memory for secure storage SecureStorage* result = malloc(sizeof(SecureStorage)); // Setting key - result->key = key; + result->key = malloc(sizeof(char) * KEYBOARD_STR_LEN); + + // Copying key + strcpy(result->key, key); // Return result return result; diff --git a/project/ui/app.h b/project/ui/app.h index db9f620..3b1bb84 100644 --- a/project/ui/app.h +++ b/project/ui/app.h @@ -30,6 +30,7 @@ typedef enum { FP_View_VariableItemList, FP_View_Submenu, FP_View_TextBox, FP_Vi /* Scenes */ typedef enum { + FP_Scene_Auth, FP_Scene_MainMenu, FP_Scene_Overview, FP_Scene_View, @@ -55,6 +56,7 @@ typedef struct { void* usb_prev_mode; Manager* manager; + char* enterkey; char* keyboard; int selection; } FP_App; diff --git a/project/ui/scenes/auth.c b/project/ui/scenes/auth.c new file mode 100644 index 0000000..89eac36 --- /dev/null +++ b/project/ui/scenes/auth.c @@ -0,0 +1,59 @@ +// Header +#include "auth.h" + +// Constants +#define KEYBOARD_STR_LEN 64 + +// Functions +void FP_Scene_Callback_Auth(void* context) { + // Setting context + FP_App* app = context; + + // Loading manager with key + app->manager = manager_init(app->enterkey); + + // Freeing key + free(app->enterkey); + + // Going to main menu! + scene_manager_next_scene(app->scene_manager, FP_Scene_MainMenu); +} +void FP_Scene_Enter_Auth(void* context) { + // Set Context + FP_App* app = context; + + // Reset view + text_input_reset(app->textinput); + + // Creating keyboard string + app->enterkey = malloc(sizeof(char) * KEYBOARD_STR_LEN); + + // Setting stuff + text_input_set_header_text( + app->textinput, + "Enter Passphrase" + ); + text_input_set_result_callback( + app->textinput, + FP_Scene_Callback_Auth, + app, + app->enterkey, + KEYBOARD_STR_LEN, + true + ); + + // Send view to Flipper + view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_TextInput); +} +void FP_Scene_Exit_Auth(void* context) { + // Setting context + FP_App* app = context; + + // Reset menu + submenu_reset(app->submenu); +} +bool FP_Scene_Event_Auth(void* context, SceneManagerEvent event) { + // Return result + UNUSED(context); + return event.type == SceneManagerEventTypeCustom; +} \ No newline at end of file diff --git a/project/ui/scenes/auth.h b/project/ui/scenes/auth.h new file mode 100644 index 0000000..2e9da8e --- /dev/null +++ b/project/ui/scenes/auth.h @@ -0,0 +1,14 @@ +// Define once +#ifndef H_AUTH +#define H_AUTH + +// Libraries +#include "../app.h" + +// Functions +void FP_Scene_Callback_Auth(void* context); +void FP_Scene_Enter_Auth(void* context); +void FP_Scene_Exit_Auth(void* context); +bool FP_Scene_Event_Auth(void* context, SceneManagerEvent event); + +#endif \ No newline at end of file diff --git a/project/ui/scenes/create.c b/project/ui/scenes/create.c index fa6d200..34409c3 100644 --- a/project/ui/scenes/create.c +++ b/project/ui/scenes/create.c @@ -136,9 +136,16 @@ bool FP_Scene_Event_Create(void* context, SceneManagerEvent event) { // Save the password manager_savepass(app->manager, app->manager->new); + // Saving key + char* key = malloc(sizeof(char) * 64); + strcpy(key, app->manager->secure_storage->key); + // Reload manager manager_free(app->manager); - app->manager = manager_init(); + app->manager = manager_init(key); + + // Freeing key + free(key); // Switching scenes scene_manager_previous_scene(app->scene_manager); diff --git a/project/ui/ui.c b/project/ui/ui.c index d6604d8..2cc47a5 100644 --- a/project/ui/ui.c +++ b/project/ui/ui.c @@ -2,6 +2,7 @@ #include "app.h" // Scenes +#include "scenes/auth.h" #include "scenes/mainmenu.h" #include "scenes/overview.h" #include "scenes/view.h" @@ -12,6 +13,7 @@ // Handlers void (*const FP_Scene_Enter_Handlers[])(void*) = { + FP_Scene_Enter_Auth, FP_Scene_Enter_MainMenu, FP_Scene_Enter_Overview, FP_Scene_Enter_View, @@ -21,6 +23,7 @@ void (*const FP_Scene_Enter_Handlers[])(void*) = { FP_Scene_Enter_Type }; bool (*const FP_Scene_Event_Handlers[])(void*, SceneManagerEvent) = { + FP_Scene_Event_Auth, FP_Scene_Event_MainMenu, FP_Scene_Event_Overview, FP_Scene_Event_View, @@ -30,6 +33,7 @@ bool (*const FP_Scene_Event_Handlers[])(void*, SceneManagerEvent) = { FP_Scene_Event_Type }; void (*const FP_Scene_Exit_Handlers[])(void*) = { + FP_Scene_Exit_Auth, FP_Scene_Exit_MainMenu, FP_Scene_Exit_Overview, FP_Scene_Exit_View, @@ -74,9 +78,6 @@ FP_App* fp_app_init() { // Allocate memory for new app variable FP_App* result = malloc(sizeof(FP_App)); - // Initilize the manager - result->manager = manager_init(); - // Init Scene Manager result->scene_manager = scene_manager_alloc(&FP_SceneEventHandlers, result); @@ -118,7 +119,7 @@ void fp_app_run(FP_App* app) { view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen); // Starting scene - scene_manager_next_scene(app->scene_manager, FP_Scene_MainMenu); + scene_manager_next_scene(app->scene_manager, FP_Scene_Auth); // Start view dispatcher view_dispatcher_run(app->view_dispatcher);