Prechádzať zdrojové kódy

Merge totp from https://github.com/akopachov/flipper-zero_authenticator

Willy-JL 1 rok pred
rodič
commit
6da8fe65ab

+ 1 - 1
totp/application.fam

@@ -7,7 +7,7 @@ App(
     requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
     requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
     stack_size=2 * 1024,
     stack_size=2 * 1024,
     order=20,
     order=20,
-    fap_version="5.130",
+    fap_version="5.140",
     fap_author="Alexander Kopachov (@akopachov)",
     fap_author="Alexander Kopachov (@akopachov)",
     fap_description="Software-based TOTP/HOTP authenticator for Flipper Zero device",
     fap_description="Software-based TOTP/HOTP authenticator for Flipper Zero device",
     fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",
     fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",

+ 12 - 1
totp/services/idle_timeout/idle_timeout.c

@@ -13,10 +13,12 @@ struct IdleTimeoutContext {
     uint16_t timeout_sec;
     uint16_t timeout_sec;
     uint16_t idle_period_sec;
     uint16_t idle_period_sec;
     bool idle_handled;
     bool idle_handled;
+    bool is_paused;
 };
 };
 
 
 static void idle_timer_callback(void* context) {
 static void idle_timer_callback(void* context) {
     IdleTimeoutContext* instance = context;
     IdleTimeoutContext* instance = context;
+    if(instance->is_paused) return;
     if(instance->activity_reported) {
     if(instance->activity_reported) {
         instance->idle_period_sec = 0;
         instance->idle_period_sec = 0;
         instance->idle_handled = false;
         instance->idle_handled = false;
@@ -44,6 +46,7 @@ IdleTimeoutContext* idle_timeout_alloc(
     instance->timeout_sec = timeout_sec;
     instance->timeout_sec = timeout_sec;
     instance->on_idle_callback = on_idle_callback;
     instance->on_idle_callback = on_idle_callback;
     instance->on_idle_callback_context = on_idle_callback_context;
     instance->on_idle_callback_context = on_idle_callback_context;
+    instance->is_paused = false;
     return instance;
     return instance;
 }
 }
 
 
@@ -55,6 +58,14 @@ void idle_timeout_stop(IdleTimeoutContext* context) {
     furi_timer_stop(context->timer);
     furi_timer_stop(context->timer);
 }
 }
 
 
+void idle_timeout_pause(IdleTimeoutContext* context) {
+    context->is_paused = true;
+}
+
+void idle_timeout_resume(IdleTimeoutContext* context) {
+    context->is_paused = false;
+}
+
 void idle_timeout_report_activity(IdleTimeoutContext* context) {
 void idle_timeout_report_activity(IdleTimeoutContext* context) {
     context->activity_reported = true;
     context->activity_reported = true;
 }
 }
@@ -63,4 +74,4 @@ void idle_timeout_free(IdleTimeoutContext* context) {
     furi_timer_stop(context->timer);
     furi_timer_stop(context->timer);
     furi_timer_free(context->timer);
     furi_timer_free(context->timer);
     free(context);
     free(context);
-}
+}

+ 13 - 1
totp/services/idle_timeout/idle_timeout.h

@@ -31,6 +31,18 @@ void idle_timeout_start(IdleTimeoutContext* context);
  */
  */
 void idle_timeout_stop(IdleTimeoutContext* context);
 void idle_timeout_stop(IdleTimeoutContext* context);
 
 
+/**
+ * @brief Pauses IDLE timeout
+ * @param context IDLE timeout context
+ */
+void idle_timeout_pause(IdleTimeoutContext* context);
+
+/**
+ * @brief Resumes paused IDLE timeout
+ * @param context IDLE timeout context
+ */
+void idle_timeout_resume(IdleTimeoutContext* context);
+
 /**
 /**
  * @brief Reports activity to IDLE timeout
  * @brief Reports activity to IDLE timeout
  * @param context IDLE timeout context
  * @param context IDLE timeout context
@@ -41,4 +53,4 @@ void idle_timeout_report_activity(IdleTimeoutContext* context);
  * @brief Disposes IDLE timeout and releases all the resources
  * @brief Disposes IDLE timeout and releases all the resources
  * @param context IDLE timeout context
  * @param context IDLE timeout context
  */
  */
-void idle_timeout_free(IdleTimeoutContext* context);
+void idle_timeout_free(IdleTimeoutContext* context);

+ 15 - 6
totp/ui/scenes/add_new_token/totp_scene_add_new_token.c

@@ -34,7 +34,6 @@ typedef struct {
     size_t token_name_length;
     size_t token_name_length;
     char* token_secret;
     char* token_secret;
     size_t token_secret_length;
     size_t token_secret_length;
-    bool saved;
     Control selected_control;
     Control selected_control;
     int16_t screen_y_offset;
     int16_t screen_y_offset;
     TokenHashAlgo algo;
     TokenHashAlgo algo;
@@ -98,7 +97,14 @@ static void ask_user_input(
         strlcpy(input_result.user_input, *user_input, INPUT_BUFFER_SIZE);
         strlcpy(input_result.user_input, *user_input, INPUT_BUFFER_SIZE);
     }
     }
 
 
+    if(plugin_state->idle_timeout_context != NULL) {
+        idle_timeout_pause(plugin_state->idle_timeout_context);
+    }
     totp_input_text(plugin_state->gui, header, &input_result);
     totp_input_text(plugin_state->gui, header, &input_result);
+    if(plugin_state->idle_timeout_context != NULL) {
+        idle_timeout_report_activity(plugin_state->idle_timeout_context);
+        idle_timeout_resume(plugin_state->idle_timeout_context);
+    }
     if(input_result.success) {
     if(input_result.success) {
         if(*user_input != NULL) {
         if(*user_input != NULL) {
             free(*user_input);
             free(*user_input);
@@ -139,11 +145,14 @@ void totp_scene_add_new_token_activate(PluginState* plugin_state) {
     SceneState* scene_state = malloc(sizeof(SceneState));
     SceneState* scene_state = malloc(sizeof(SceneState));
     furi_check(scene_state != NULL);
     furi_check(scene_state != NULL);
     plugin_state->current_scene_state = scene_state;
     plugin_state->current_scene_state = scene_state;
-    scene_state->token_name = "Name";
+    scene_state->token_name = strdup("Name");
+    furi_check(scene_state->token_name != NULL);
     scene_state->token_name_length = strlen(scene_state->token_name);
     scene_state->token_name_length = strlen(scene_state->token_name);
-    scene_state->token_secret = "Secret";
+    scene_state->token_secret = strdup("Secret");
+    furi_check(scene_state->token_secret != NULL);
     scene_state->token_secret_length = strlen(scene_state->token_secret);
     scene_state->token_secret_length = strlen(scene_state->token_secret);
-    scene_state->initial_counter = "Counter";
+    scene_state->initial_counter = strdup("Counter");
+    furi_check(scene_state->initial_counter != NULL);
     scene_state->initial_counter_length = strlen(scene_state->initial_counter);
     scene_state->initial_counter_length = strlen(scene_state->initial_counter);
 
 
     scene_state->screen_y_offset = 0;
     scene_state->screen_y_offset = 0;
@@ -372,7 +381,7 @@ bool totp_scene_add_new_token_handle_event(
             break;
             break;
         }
         }
         case InputKeyBack:
         case InputKeyBack:
-            totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
+            totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
             break;
             break;
         default:
         default:
             break;
             break;
@@ -384,7 +393,7 @@ bool totp_scene_add_new_token_handle_event(
 
 
 void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
 void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
     if(plugin_state->current_scene_state == NULL) return;
     if(plugin_state->current_scene_state == NULL) return;
-    SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
+    SceneState* scene_state = plugin_state->current_scene_state;
     free(scene_state->token_name);
     free(scene_state->token_name);
     free(scene_state->token_secret);
     free(scene_state->token_secret);
 
 

+ 1 - 2
totp/ui/scenes/generate_token/totp_scene_generate_token.c

@@ -428,14 +428,13 @@ bool totp_scene_generate_token_handle_event(
             break;
             break;
         }
         }
         case InputKeyOk:
         case InputKeyOk:
+            totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
             break;
             break;
         case InputKeyBack:
         case InputKeyBack:
             break;
             break;
         default:
         default:
             break;
             break;
         }
         }
-    } else if(event->input.type == InputTypeShort && event->input.key == InputKeyOk) {
-        totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
     }
     }
 
 
     return true;
     return true;

+ 4 - 2
totp/ui/ui_controls.c

@@ -41,8 +41,10 @@ void ui_control_text_box_render(
             1);
             1);
     }
     }
 
 
-    canvas_draw_str_aligned(
-        canvas, TEXT_BOX_MARGIN + 2, TEXT_BOX_MARGIN + 3 + y, AlignLeft, AlignTop, text);
+    if(text != NULL) {
+        canvas_draw_str_aligned(
+            canvas, TEXT_BOX_MARGIN + 2, TEXT_BOX_MARGIN + 3 + y, AlignLeft, AlignTop, text);
+    }
 }
 }
 
 
 void ui_control_select_render(
 void ui_control_select_render(

+ 1 - 1
totp/version.h

@@ -1,5 +1,5 @@
 #pragma once
 #pragma once
 
 
 #define TOTP_APP_VERSION_MAJOR (5)
 #define TOTP_APP_VERSION_MAJOR (5)
-#define TOTP_APP_VERSION_MINOR (13)
+#define TOTP_APP_VERSION_MINOR (14)
 #define TOTP_APP_VERSION_PATCH (0)
 #define TOTP_APP_VERSION_PATCH (0)