Alexander Kopachov 2 лет назад
Родитель
Сommit
0604b90cad
5 измененных файлов с 30 добавлено и 20 удалено
  1. 1 1
      application.fam
  2. 8 6
      cli/cli_helpers.h
  3. 4 0
      services/config/config.c
  4. 16 13
      services/crypto/crypto_v2.c
  5. 1 0
      totp_app.c

+ 1 - 1
application.fam

@@ -15,7 +15,7 @@ App(
     ],
     stack_size=2 * 1024,
     order=20,
-    fap_version="3.0",
+    fap_version="3.2",
     fap_author="Alexander Kopachov (@akopachov)",
     fap_description="Software-based TOTP authenticator for Flipper Zero device",
     fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",

+ 8 - 6
cli/cli_helpers.h

@@ -33,12 +33,14 @@ extern const char* TOTP_CLI_COLOR_INFO;
 #define TOTP_CLI_PRINTF_INFO(format, ...) \
     TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__)
 
-#define TOTP_CLI_LOCK_UI(plugin_state)                    \
-    Scene __previous_scene = plugin_state->current_scene; \
-    totp_scene_director_activate_scene(plugin_state, TotpSceneStandby)
-
-#define TOTP_CLI_UNLOCK_UI(plugin_state) \
-    totp_scene_director_activate_scene(plugin_state, __previous_scene)
+#define TOTP_CLI_LOCK_UI(plugin_state)                                  \
+    Scene __previous_scene = plugin_state->current_scene;               \
+    totp_scene_director_activate_scene(plugin_state, TotpSceneStandby); \
+    totp_scene_director_force_redraw(plugin_state)
+
+#define TOTP_CLI_UNLOCK_UI(plugin_state)                                \
+    totp_scene_director_activate_scene(plugin_state, __previous_scene); \
+    totp_scene_director_force_redraw(plugin_state)
 
 /**
  * @brief Checks whether user is authenticated and entered correct PIN.

+ 4 - 0
services/config/config.c

@@ -551,6 +551,10 @@ bool totp_config_file_update_encryption(
         return false;
     }
 
+    if(!totp_crypto_check_key_slot(new_crypto_key_slot)) {
+        return false;
+    }
+
     uint8_t old_iv[CRYPTO_IV_LENGTH];
     memcpy(&old_iv[0], &plugin_state->iv[0], CRYPTO_IV_LENGTH);
 

+ 16 - 13
services/crypto/crypto_v2.c

@@ -45,11 +45,12 @@ uint8_t* totp_crypto_encrypt_v2(
         *encrypted_data_length = plain_data_aligned_length;
 
         furi_check(
-            furi_hal_crypto_store_load_key(key_slot, iv) &&
-                furi_hal_crypto_encrypt(
-                    plain_data_aligned, encrypted_data, plain_data_aligned_length) &&
-                furi_hal_crypto_store_unload_key(key_slot),
-            "Encryption failed");
+            furi_hal_crypto_store_load_key(key_slot, iv), "Encryption failed: store_load_key");
+        furi_check(
+            furi_hal_crypto_encrypt(plain_data_aligned, encrypted_data, plain_data_aligned_length),
+            "Encryption failed: encrypt");
+        furi_check(
+            furi_hal_crypto_store_unload_key(key_slot), "Encryption failed: store_unload_key");
 
         memset_s(plain_data_aligned, plain_data_aligned_length, 0, plain_data_aligned_length);
         free(plain_data_aligned);
@@ -59,10 +60,12 @@ uint8_t* totp_crypto_encrypt_v2(
         *encrypted_data_length = plain_data_length;
 
         furi_check(
-            furi_hal_crypto_store_load_key(key_slot, iv) &&
-                furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length) &&
-                furi_hal_crypto_store_unload_key(key_slot),
-            "Encryption failed");
+            furi_hal_crypto_store_load_key(key_slot, iv), "Encryption failed: store_load_key");
+        furi_check(
+            furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length),
+            "Encryption failed: encrypt");
+        furi_check(
+            furi_hal_crypto_store_unload_key(key_slot), "Encryption failed: store_unload_key");
     }
 
     return encrypted_data;
@@ -77,11 +80,11 @@ uint8_t* totp_crypto_decrypt_v2(
     *decrypted_data_length = encrypted_data_length;
     uint8_t* decrypted_data = malloc(*decrypted_data_length);
     furi_check(decrypted_data != NULL);
+    furi_check(furi_hal_crypto_store_load_key(key_slot, iv), "Decryption failed: store_load_key");
     furi_check(
-        furi_hal_crypto_store_load_key(key_slot, iv) &&
-            furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length) &&
-            furi_hal_crypto_store_unload_key(key_slot),
-        "Decryption failed");
+        furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length),
+        "Decryption failed: decrypt");
+    furi_check(furi_hal_crypto_store_unload_key(key_slot), "Decryption failed: store_unload_key");
     return decrypted_data;
 }
 

+ 1 - 0
totp_app.c

@@ -115,6 +115,7 @@ static bool on_user_idle(void* context) {
     if(plugin_state->current_scene != TotpSceneAuthentication &&
        plugin_state->current_scene != TotpSceneStandby) {
         totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication);
+        totp_scene_director_force_redraw(plugin_state);
         return true;
     }