Просмотр исходного кода

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

Willy-JL 1 год назад
Родитель
Сommit
923988b801

+ 1 - 1
totp/application.fam

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

+ 35 - 36
totp/ui/scenes/authenticate/totp_scene_authenticate.c

@@ -122,42 +122,6 @@ bool totp_scene_authenticate_handle_event(
             }
             break;
         case InputKeyOk: {
-            CryptoSeedIVResult seed_result = totp_crypto_seed_iv(
-                &plugin_state->crypto_settings,
-                &scene_state->code_input[0],
-                scene_state->code_length);
-
-            if(seed_result & CryptoSeedIVResultFlagSuccess &&
-               seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) {
-                totp_config_file_update_crypto_signatures(plugin_state);
-            }
-
-            if(totp_crypto_verify_key(&plugin_state->crypto_settings)) {
-                totp_config_file_ensure_latest_encryption(
-                    plugin_state, &scene_state->code_input[0], scene_state->code_length);
-                totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
-            } else {
-                memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH);
-                memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH);
-                scene_state->code_length = 0;
-
-                DialogMessage* message = dialog_message_alloc();
-                dialog_message_set_buttons(message, "Try again", NULL, NULL);
-                dialog_message_set_header(
-                    message,
-                    "You entered\ninvalid PIN",
-                    SCREEN_WIDTH_CENTER - 25,
-                    SCREEN_HEIGHT_CENTER - 5,
-                    AlignCenter,
-                    AlignCenter);
-#if __has_include(<assets_icons.h>)
-                dialog_message_set_icon(message, &I_WarningDolphinFlip_45x42, 83, 22);
-#else
-                dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17);
-#endif
-                dialog_message_show(plugin_state->dialogs_app, message);
-                dialog_message_free(message);
-            }
             break;
         }
         case InputKeyBack:
@@ -165,6 +129,41 @@ bool totp_scene_authenticate_handle_event(
         default:
             break;
         }
+    } else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) {
+        CryptoSeedIVResult seed_result = totp_crypto_seed_iv(
+            &plugin_state->crypto_settings, &scene_state->code_input[0], scene_state->code_length);
+
+        if(seed_result & CryptoSeedIVResultFlagSuccess &&
+           seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) {
+            totp_config_file_update_crypto_signatures(plugin_state);
+        }
+
+        if(totp_crypto_verify_key(&plugin_state->crypto_settings)) {
+            totp_config_file_ensure_latest_encryption(
+                plugin_state, &scene_state->code_input[0], scene_state->code_length);
+            totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
+        } else {
+            memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH);
+            memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH);
+            scene_state->code_length = 0;
+
+            DialogMessage* message = dialog_message_alloc();
+            dialog_message_set_buttons(message, "Try again", NULL, NULL);
+            dialog_message_set_header(
+                message,
+                "You entered\ninvalid PIN",
+                SCREEN_WIDTH_CENTER - 25,
+                SCREEN_HEIGHT_CENTER - 5,
+                AlignCenter,
+                AlignCenter);
+#if __has_include(<assets_icons.h>)
+            dialog_message_set_icon(message, &I_WarningDolphinFlip_45x42, 83, 22);
+#else
+            dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17);
+#endif
+            dialog_message_show(plugin_state->dialogs_app, message);
+            dialog_message_free(message);
+        }
     }
 
     return true;

+ 5 - 3
totp/ui/scenes/generate_token/totp_scene_generate_token.c

@@ -373,7 +373,9 @@ bool totp_scene_generate_token_handle_event(
                 scene_state->notification_app,
                 get_notification_sequence_automation(plugin_state, scene_state));
             return true;
-        } else if(event->input.key == InputKeyOk) {
+        }
+#endif
+        else if(event->input.key == InputKeyOk) {
             TokenInfoIteratorContext* iterator_context =
                 totp_config_get_token_iterator_context(plugin_state);
             const TokenInfo* token_info =
@@ -389,7 +391,6 @@ bool totp_scene_generate_token_handle_event(
                     get_notification_sequence_new_token(plugin_state, scene_state));
             }
         }
-#endif
     } else if(event->input.type == InputTypePress || event->input.type == InputTypeRepeat) {
         switch(event->input.key) {
         case InputKeyUp:
@@ -427,13 +428,14 @@ bool totp_scene_generate_token_handle_event(
             break;
         }
         case InputKeyOk:
-            totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
             break;
         case InputKeyBack:
             break;
         default:
             break;
         }
+    } else if(event->input.type == InputTypeShort && event->input.key == InputKeyOk) {
+        totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
     }
 
     return true;

+ 1 - 1
totp/version.h

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