Procházet zdrojové kódy

fix: HOTP counter increment is not working (#226) (#227)

* fix: HOTP counter increment is not working

* ci: continue with the release if build for some firmware fails

* chore: CLang format changes

---------

Co-authored-by: akopachov <akopachov@users.noreply.github.com>
Alexander Kopachov před 1 rokem
rodič
revize
24a4a90845

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

@@ -120,42 +120,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:
@@ -163,6 +127,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
ui/scenes/generate_token/totp_scene_generate_token.c

@@ -371,7 +371,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 =
@@ -387,7 +389,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:
@@ -425,13 +426,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;