MX пре 8 месеци
родитељ
комит
49b92bcac4

+ 2 - 3
app_api_table_i.h

@@ -1,7 +1,6 @@
 #include <stdbool.h>
-#include <toolbox/cli/cli_command.h>
-#include <cli/cli_main_commands.h>
-#include <cli/cli_ansi.h>
+#include <cli/cli.h>
+
 #include <lib/print/wrappers.h>
 #include <lib/toolbox/args.h>
 #include <memset_s.h>

+ 1 - 1
application.fam

@@ -7,7 +7,7 @@ App(
     requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
     stack_size=2 * 1024,
     order=20,
-    fap_version="5.173",
+    fap_version="5.180",
     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",

+ 4 - 4
cli/cli.c

@@ -156,7 +156,7 @@ static void totp_cli_handler(PipeSide* pipe, FuriString* args, void* context) {
 }
 
 TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state) {
-    CliRegistry* registry = furi_record_open(RECORD_CLI);
+    CliRegistry* cli = furi_record_open(RECORD_CLI);
     TotpCliContext* context = malloc(sizeof(TotpCliContext));
     furi_check(context != NULL);
     context->plugin_state = plugin_state;
@@ -166,14 +166,14 @@ TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state) {
     composite_api_resolver_add(context->plugin_api_resolver, application_api_interface);
 
     cli_registry_add_command(
-        registry, TOTP_CLI_COMMAND_NAME, CliCommandFlagParallelSafe, totp_cli_handler, context);
+        cli, TOTP_CLI_COMMAND_NAME, CliCommandFlagParallelSafe, totp_cli_handler, context);
     furi_record_close(RECORD_CLI);
     return context;
 }
 
 void totp_cli_unregister_command_handler(TotpCliContext* context) {
-    CliRegistry* registry = furi_record_open(RECORD_CLI);
-    cli_registry_delete_command(registry, TOTP_CLI_COMMAND_NAME);
+    CliRegistry* cli = furi_record_open(RECORD_CLI);
+    cli_registry_delete_command(cli, TOTP_CLI_COMMAND_NAME);
 
     composite_api_resolver_free(context->plugin_api_resolver);
 

+ 3 - 1
cli/plugins/export/export.c

@@ -106,7 +106,9 @@ static void handle(PluginState* plugin_state, FuriString* args, PipeSide* pipe)
             token_info->token_length,
             &plugin_state->crypto_settings,
             &key_length);
-        print_as_base32(key, key_length);
+        size_t plain_key_length =
+            token_info->token_plain_length > 0 ? token_info->token_plain_length : key_length;
+        print_as_base32(key, plain_key_length);
         memset_s(key, key_length, 0, key_length);
         free(key);
         TOTP_CLI_PRINTF("&algorithm=%s", token_info_get_algo_as_cstr(token_info));

+ 2 - 1
services/config/constants.h

@@ -5,11 +5,12 @@
 
 #define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/totp")
 #define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
-#define CONFIG_FILE_ACTUAL_VERSION (13)
+#define CONFIG_FILE_ACTUAL_VERSION (14)
 
 #define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
 #define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"
 #define TOTP_CONFIG_KEY_TOKEN_SECRET "TokenSecret"
+#define TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH "TokenSecretLength"
 #define TOTP_CONFIG_KEY_TOKEN_ALGO "TokenAlgo"
 #define TOTP_CONFIG_KEY_TOKEN_DIGITS "TokenDigits"
 #define TOTP_CONFIG_KEY_TOKEN_DURATION "TokenDuration"

+ 11 - 0
services/config/migrations/common_migration.c

@@ -152,6 +152,17 @@ bool totp_config_migrate_to_latest(
                 fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
             flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
 
+            if(current_version > 13) {
+                flipper_format_read_string(
+                    fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, temp_str);
+                flipper_format_write_string(
+                    fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, temp_str);
+            } else {
+                const uint32_t default_secret_length = 0;
+                flipper_format_write_uint32(
+                    fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, &default_secret_length, 1);
+            }
+
             if(current_version > 1) {
                 flipper_format_read_string(
                     fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);

+ 17 - 2
services/config/token_info_iterator.c

@@ -178,7 +178,13 @@ static bool
             break;
         }
 
-        uint32_t tmp_uint32 = token_info->algo;
+        uint32_t tmp_uint32 = token_info->token_plain_length;
+        if(!flipper_format_write_uint32(
+               temp_ff, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, &tmp_uint32, 1)) {
+            break;
+        }
+
+        tmp_uint32 = token_info->algo;
         if(!flipper_format_write_uint32(temp_ff, TOTP_CONFIG_KEY_TOKEN_ALGO, &tmp_uint32, 1)) {
             break;
         }
@@ -507,6 +513,7 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
         tokenInfo->token_length = 0;
     }
 
+    uint32_t temp_data32;
     if(secret_bytes_count == 1) { // Plain secret key
         FuriString* temp_str = furi_string_alloc();
 
@@ -526,6 +533,7 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
             } else {
                 tokenInfo->token = NULL;
                 tokenInfo->token_length = 0;
+                tokenInfo->token_plain_length = 0;
                 FURI_LOG_W(
                     LOGGING_TAG,
                     "Token \"%s\" has invalid secret",
@@ -534,6 +542,7 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
         } else {
             tokenInfo->token = NULL;
             tokenInfo->token_length = 0;
+            tokenInfo->token_plain_length = 0;
         }
 
         furi_string_free(temp_str);
@@ -554,9 +563,15 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
         } else {
             tokenInfo->token = NULL;
         }
+
+        if(flipper_format_read_uint32(
+               context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, &temp_data32, 1)) {
+            tokenInfo->token_plain_length = temp_data32;
+        } else {
+            tokenInfo->token_plain_length = tokenInfo->token_length;
+        }
     }
 
-    uint32_t temp_data32;
     if(!flipper_format_read_uint32(
            context->config_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &temp_data32, 1) ||
        !token_info_set_algo_from_int(tokenInfo, temp_data32)) {

+ 1 - 0
types/token_info.c

@@ -59,6 +59,7 @@ bool token_info_set_secret(
     }
 
     bool result;
+    token_info->token_plain_length = plain_secret_length;
     if(plain_secret_length > 0) {
         if(token_info->token != NULL) {
             free(token_info->token);

+ 5 - 0
types/token_info.h

@@ -180,6 +180,11 @@ typedef struct {
      */
     size_t token_length;
 
+    /**
+     * @brief Plain token secret length 
+     */
+    size_t token_plain_length;
+
     /**
      * @brief User-friendly token name 
      */

+ 2 - 2
version.h

@@ -1,5 +1,5 @@
 #pragma once
 
 #define TOTP_APP_VERSION_MAJOR (5)
-#define TOTP_APP_VERSION_MINOR (17)
-#define TOTP_APP_VERSION_PATCH (3)
+#define TOTP_APP_VERSION_MINOR (18)
+#define TOTP_APP_VERSION_PATCH (0)

+ 4 - 3
workers/generate_totp_code/generate_totp_code.c

@@ -71,19 +71,20 @@ static void generate_totp_code(
         size_t key_length;
         uint8_t* key = totp_crypto_decrypt(
             token_info->token, token_info->token_length, context->crypto_settings, &key_length);
-
         uint64_t otp_code;
+        size_t plain_key_length =
+            token_info->token_plain_length > 0 ? token_info->token_plain_length : key_length;
         if(token_info->type == TokenTypeTOTP) {
             otp_code = totp_at(
                 get_totp_algo_impl(token_info->algo),
                 key,
-                key_length,
+                plain_key_length,
                 current_ts,
                 context->timezone_offset,
                 token_info->duration);
         } else if(token_info->type == TokenTypeHOTP) {
             otp_code = hotp_at(
-                get_totp_algo_impl(token_info->algo), key, key_length, token_info->counter);
+                get_totp_algo_impl(token_info->algo), key, plain_key_length, token_info->counter);
         } else {
             furi_crash("Unknown token type");
         }