From 769d44d793acb24903c05821a76dc57920f30769 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:52:56 +0100 Subject: [PATCH] Update TOTP --- applications/external/totp/application.fam | 15 +++++- .../external/totp/cli/commands/pin/pin.c | 13 +++++ applications/external/totp/features_config.h | 8 +-- .../external/totp/lib/base32/base32.h | 2 +- .../external/totp/lib/base64/base64.c | 6 +-- .../external/totp/services/config/config.c | 53 +++++++++++++++---- .../external/totp/services/config/config.h | 6 +++ .../external/totp/services/config/constants.h | 2 +- .../external/totp/services/crypto/crypto.c | 6 +-- .../external/totp/services/hmac/hmac_common.h | 4 -- applications/external/totp/totp_app.c | 6 +-- .../external/totp/types/plugin_state.h | 2 +- applications/external/totp/types/token_info.h | 17 ++++-- applications/external/totp/ui/constants.h | 4 +- .../ui/fonts/{font_info.h => font-info.h} | 0 .../mode-nine/{mode_nine.c => mode-nine.c} | 3 +- .../mode-nine/{mode_nine.h => mode-nine.h} | 3 +- .../external/totp/ui/scene_director.c | 16 ------ .../external/totp/ui/scene_director.h | 12 ----- .../ui/scenes/add_new_token/totp_input_text.h | 4 +- .../add_new_token/totp_scene_add_new_token.c | 8 --- .../add_new_token/totp_scene_add_new_token.h | 2 - .../scenes/app_settings/totp_app_settings.c | 8 --- .../scenes/app_settings/totp_app_settings.h | 4 +- .../authenticate/totp_scene_authenticate.c | 8 --- .../authenticate/totp_scene_authenticate.h | 2 - .../totp_scene_generate_token.c | 17 ++---- .../totp_scene_generate_token.h | 2 - .../scenes/token_menu/totp_scene_token_menu.c | 8 --- .../scenes/token_menu/totp_scene_token_menu.h | 2 - applications/external/totp/ui/ui_controls.c | 4 +- .../totp/workers/bt_type_code/bt_type_code.h | 2 +- 32 files changed, 121 insertions(+), 128 deletions(-) rename applications/external/totp/ui/fonts/{font_info.h => font-info.h} (100%) rename applications/external/totp/ui/fonts/mode-nine/{mode_nine.c => mode-nine.c} (99%) rename applications/external/totp/ui/fonts/mode-nine/{mode_nine.h => mode-nine.h} (77%) diff --git a/applications/external/totp/application.fam b/applications/external/totp/application.fam index 653e0d61a..8ebf19820 100644 --- a/applications/external/totp/application.fam +++ b/applications/external/totp/application.fam @@ -3,7 +3,16 @@ App( name="Authenticator", apptype=FlipperAppType.EXTERNAL, entry_point="totp_app", - requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"], + cdefines=["APP_TOTP"], + requires=[ + "gui", + "cli", + "dialogs", + "storage", + "input", + "notification", + "bt" + ], stack_size=2 * 1024, order=20, fap_author="Alexander Kopachov (@akopachov)", @@ -19,7 +28,9 @@ App( Lib( name="base64", ), - Lib(name="linked_list"), + Lib( + name="linked_list" + ), Lib( name="timezone_utils", ), diff --git a/applications/external/totp/cli/commands/pin/pin.c b/applications/external/totp/cli/commands/pin/pin.c index 92c9c59c4..9b9038ae7 100644 --- a/applications/external/totp/cli/commands/pin/pin.c +++ b/applications/external/totp/cli/commands/pin/pin.c @@ -121,6 +121,19 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl memset(&new_pin[0], 0, TOTP_IV_SIZE); } + char* backup_path = totp_config_file_backup(); + if(backup_path != NULL) { + TOTP_CLI_PRINTF_WARNING("Backup conf file %s has been created\r\n", backup_path); + TOTP_CLI_PRINTF_WARNING( + "Once you make sure everything is fine and works as expected, please delete this backup file\r\n"); + free(backup_path); + } else { + memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE); + TOTP_CLI_PRINTF_ERROR( + "An error has occurred during taking backup of config file\r\n"); + break; + } + if(plugin_state->current_scene == TotpSceneGenerateToken) { totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL); load_generate_token_scene = true; diff --git a/applications/external/totp/features_config.h b/applications/external/totp/features_config.h index 68f976e96..3489950bf 100644 --- a/applications/external/totp/features_config.h +++ b/applications/external/totp/features_config.h @@ -5,10 +5,12 @@ #define TOTP_AUTOMATION_ICONS_ENABLED // List of compatible firmwares -#define TOTP_FIRMWARE_OFFICIAL_STABLE 1 -#define TOTP_FIRMWARE_OFFICIAL_DEV 2 -#define TOTP_FIRMWARE_XTREME 3 +#define TOTP_FIRMWARE_OFFICIAL_STABLE (1) +#define TOTP_FIRMWARE_OFFICIAL_DEV (2) +#define TOTP_FIRMWARE_XTREME (3) // End of list // Target firmware to build for +#ifndef TOTP_TARGET_FIRMWARE #define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_XTREME +#endif \ No newline at end of file diff --git a/applications/external/totp/lib/base32/base32.h b/applications/external/totp/lib/base32/base32.h index 8cb9bddcb..a0ec86e82 100644 --- a/applications/external/totp/lib/base32/base32.h +++ b/applications/external/totp/lib/base32/base32.h @@ -27,7 +27,7 @@ #pragma once -#include +#include #include /** diff --git a/applications/external/totp/lib/base64/base64.c b/applications/external/totp/lib/base64/base64.c index 1dfcf8814..dd0a12b5e 100644 --- a/applications/external/totp/lib/base64/base64.c +++ b/applications/external/totp/lib/base64/base64.c @@ -22,14 +22,14 @@ static const uint8_t dtable[] = {0x3e, 0x80, 0x80, 0x80, 0x3f, 0x34, 0x35, 0x36, 0x80, 0x80, 0x80, 0x80, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33}; -// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static uint8_t get_dtable_value(uint8_t index) { return (index < 43 || index > 122) ? 0x80 : dtable[index - 43]; } uint8_t* base64_decode(const uint8_t* src, size_t len, size_t* out_len, size_t* out_size) { - uint8_t *out; - uint8_t *pos; + uint8_t* out; + uint8_t* pos; uint8_t in[4]; uint8_t block[4]; uint8_t tmp; diff --git a/applications/external/totp/services/config/config.c b/applications/external/totp/services/config/config.c index fca83942e..6d5838b28 100644 --- a/applications/external/totp/services/config/config.c +++ b/applications/external/totp/services/config/config.c @@ -9,7 +9,7 @@ #define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/authenticator") #define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf" -#define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup" +#define CONFIG_FILE_BACKUP_BASE_PATH CONFIG_FILE_PATH ".backup" #define CONFIG_FILE_TEMP_PATH CONFIG_FILE_PATH ".tmp" #define CONFIG_FILE_ORIG_PATH CONFIG_FILE_PATH ".orig" #define CONFIG_FILE_PATH_PREVIOUS EXT_PATH("apps/Misc") "/totp.conf" @@ -39,6 +39,34 @@ static void totp_close_config_file(FlipperFormat* file) { flipper_format_free(file); } +/** + * @brief Tries to take a config file backup + * @param storage storage record + * @return backup path if backup successfully taken; \c NULL otherwise + */ +static char* totp_config_file_backup_i(Storage* storage) { + uint8_t backup_path_size = sizeof(CONFIG_FILE_BACKUP_BASE_PATH) + 5; + char* backup_path = malloc(backup_path_size); + furi_check(backup_path != NULL); + memcpy(backup_path, CONFIG_FILE_BACKUP_BASE_PATH, sizeof(CONFIG_FILE_BACKUP_BASE_PATH)); + uint16_t i = 1; + bool backup_file_exists; + while((backup_file_exists = storage_common_exists(storage, backup_path)) && i <= 9999) { + snprintf(backup_path, backup_path_size, CONFIG_FILE_BACKUP_BASE_PATH ".%" PRIu16, i); + i++; + } + + if(backup_file_exists || + !storage_common_copy(storage, CONFIG_FILE_PATH, backup_path) == FSE_OK) { + FURI_LOG_E(LOGGING_TAG, "Unable to take a backup"); + free(backup_path); + return NULL; + } + + FURI_LOG_I(LOGGING_TAG, "Took config file backup to %s", backup_path); + return backup_path; +} + /** * @brief Opens or creates TOTP application standard config file * @param storage storage record to use @@ -250,6 +278,13 @@ static TotpConfigFileUpdateResult return update_result; } +char* totp_config_file_backup() { + Storage* storage = totp_open_storage(); + char* result = totp_config_file_backup_i(storage); + totp_close_storage(); + return result; +} + TotpConfigFileUpdateResult totp_config_file_save_new_token(const TokenInfo* token_info) { Storage* cfg_storage = totp_open_storage(); FlipperFormat* file; @@ -513,20 +548,16 @@ TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_st CONFIG_FILE_ACTUAL_VERSION); totp_close_config_file(fff_data_file); - if(storage_common_stat(storage, CONFIG_FILE_BACKUP_PATH, NULL) == FSE_OK) { - storage_simply_remove(storage, CONFIG_FILE_BACKUP_PATH); - } + char* backup_path = totp_config_file_backup_i(storage); - if(storage_common_copy(storage, CONFIG_FILE_PATH, CONFIG_FILE_BACKUP_PATH) == FSE_OK) { - FURI_LOG_I(LOGGING_TAG, "Took config file backup to %s", CONFIG_FILE_BACKUP_PATH); + if(backup_path != NULL) { if(totp_open_config_file(storage, &fff_data_file) != TotpConfigFileOpenSuccess) { result = TotpConfigFileOpenError; break; } FlipperFormat* fff_backup_data_file = flipper_format_file_alloc(storage); - if(!flipper_format_file_open_existing( - fff_backup_data_file, CONFIG_FILE_BACKUP_PATH)) { + if(!flipper_format_file_open_existing(fff_backup_data_file, backup_path)) { flipper_format_file_close(fff_backup_data_file); flipper_format_free(fff_backup_data_file); result = TotpConfigFileOpenError; @@ -551,12 +582,12 @@ TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_st flipper_format_file_close(fff_backup_data_file); flipper_format_free(fff_backup_data_file); flipper_format_rewind(fff_data_file); + free(backup_path); } else { FURI_LOG_E( LOGGING_TAG, - "An error occurred during taking backup of %s into %s before migration", - CONFIG_FILE_PATH, - CONFIG_FILE_BACKUP_PATH); + "An error occurred during taking backup of %s before migration", + CONFIG_FILE_PATH); result = TotpConfigFileOpenError; break; } diff --git a/applications/external/totp/services/config/config.h b/applications/external/totp/services/config/config.h index 3d325368d..dabeb373a 100644 --- a/applications/external/totp/services/config/config.h +++ b/applications/external/totp/services/config/config.h @@ -60,6 +60,12 @@ enum TotpConfigFileUpdateResults { TotpConfigFileUpdateError }; +/** + * @brief Tries to take a config file backup + * @return backup path if backup successfully taken; \c NULL otherwise + */ +char* totp_config_file_backup(); + /** * @brief Saves all the settings and tokens to an application config file * @param plugin_state application state diff --git a/applications/external/totp/services/config/constants.h b/applications/external/totp/services/config/constants.h index 9924aefe2..7137e2374 100644 --- a/applications/external/totp/services/config/constants.h +++ b/applications/external/totp/services/config/constants.h @@ -1,7 +1,7 @@ #pragma once #define CONFIG_FILE_HEADER "Flipper TOTP plugin config file" -#define CONFIG_FILE_ACTUAL_VERSION 4 +#define CONFIG_FILE_ACTUAL_VERSION (4) #define TOTP_CONFIG_KEY_TIMEZONE "Timezone" #define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName" diff --git a/applications/external/totp/services/crypto/crypto.c b/applications/external/totp/services/crypto/crypto.c index ed4775dfb..55fb1df6a 100644 --- a/applications/external/totp/services/crypto/crypto.c +++ b/applications/external/totp/services/crypto/crypto.c @@ -5,10 +5,10 @@ #include "../../types/common.h" #include "memset_s.h" -#define CRYPTO_KEY_SLOT 2 +#define CRYPTO_KEY_SLOT (2) #define CRYPTO_VERIFY_KEY "FFF_Crypto_pass" -#define CRYPTO_VERIFY_KEY_LENGTH 16 -#define CRYPTO_ALIGNMENT_FACTOR 16 +#define CRYPTO_VERIFY_KEY_LENGTH (16) +#define CRYPTO_ALIGNMENT_FACTOR (16) uint8_t* totp_crypto_encrypt( const uint8_t* plain_data, diff --git a/applications/external/totp/services/hmac/hmac_common.h b/applications/external/totp/services/hmac/hmac_common.h index 9c5b5828f..0cd56ed99 100644 --- a/applications/external/totp/services/hmac/hmac_common.h +++ b/applications/external/totp/services/hmac/hmac_common.h @@ -9,11 +9,7 @@ #define _GLHMAC_CONCAT_(prefix, suffix) prefix##suffix #define _GLHMAC_CONCAT(prefix, suffix) _GLHMAC_CONCAT_(prefix, suffix) -#if GL_HMAC_NAME == 5 -#define HMAC_ALG md5 -#else #define HMAC_ALG _GLHMAC_CONCAT(sha, GL_HMAC_NAME) -#endif #define GL_HMAC_CTX _GLHMAC_CONCAT(HMAC_ALG, _ctx) #define GL_HMAC_FN _GLHMAC_CONCAT(hmac_, HMAC_ALG) diff --git a/applications/external/totp/totp_app.c b/applications/external/totp/totp_app.c index e5c101e5f..8a014628d 100644 --- a/applications/external/totp/totp_app.c +++ b/applications/external/totp/totp_app.c @@ -20,7 +20,7 @@ #include "services/crypto/crypto.h" #include "cli/cli.h" -#define IDLE_TIMEOUT 60000 +#define IDLE_TIMEOUT (60000) static void render_callback(Canvas* const canvas, void* ctx) { furi_assert(ctx); @@ -96,6 +96,7 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) { plugin_state->gui = furi_record_open(RECORD_GUI); plugin_state->notification_app = furi_record_open(RECORD_NOTIFICATION); plugin_state->dialogs_app = furi_record_open(RECORD_DIALOGS); + memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); if(totp_config_file_load_base(plugin_state) != TotpConfigFileOpenSuccess) { totp_dialogs_config_loading_error(plugin_state); @@ -161,7 +162,7 @@ int32_t totp_app() { } TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state, event_queue); - totp_scene_director_init_scenes(plugin_state); + if(!totp_activate_initial_scene(plugin_state)) { FURI_LOG_E(LOGGING_TAG, "An error ocurred during activating initial scene\r\n"); totp_plugin_state_free(plugin_state); @@ -206,7 +207,6 @@ int32_t totp_app() { totp_cli_unregister_command_handler(cli_context); totp_scene_director_deactivate_active_scene(plugin_state); - totp_scene_director_dispose(plugin_state); view_port_enabled_set(view_port, false); gui_remove_view_port(plugin_state->gui, view_port); diff --git a/applications/external/totp/types/plugin_state.h b/applications/external/totp/types/plugin_state.h index b1d34a662..cacf68426 100644 --- a/applications/external/totp/types/plugin_state.h +++ b/applications/external/totp/types/plugin_state.h @@ -12,7 +12,7 @@ #include "../workers/bt_type_code/bt_type_code.h" #endif -#define TOTP_IV_SIZE 16 +#define TOTP_IV_SIZE (16) /** * @brief Application state structure diff --git a/applications/external/totp/types/token_info.h b/applications/external/totp/types/token_info.h index 688e8028d..9ca3528dc 100644 --- a/applications/external/totp/types/token_info.h +++ b/applications/external/totp/types/token_info.h @@ -4,13 +4,13 @@ #include #include -#define TOTP_TOKEN_DURATION_DEFAULT 30 +#define TOTP_TOKEN_DURATION_DEFAULT (30) #define TOTP_TOKEN_ALGO_SHA1_NAME "sha1" #define TOTP_TOKEN_ALGO_STEAM_NAME "steam" #define TOTP_TOKEN_ALGO_SHA256_NAME "sha256" #define TOTP_TOKEN_ALGO_SHA512_NAME "sha512" -#define TOTP_TOKEN_MAX_LENGTH 255 +#define TOTP_TOKEN_MAX_LENGTH (255) #define PLAIN_TOKEN_ENCODING_BASE32_NAME "base32" #define PLAIN_TOKEN_ENCODING_BASE64_NAME "base64" @@ -95,12 +95,23 @@ enum TokenAutomationFeatures { TOKEN_AUTOMATION_FEATURE_TYPE_SLOWER = 0b100 }; +/** + * @brief Plain token secret encodings. + */ enum PlainTokenSecretEncodings { + + /** + * @brief Base32 encoding + */ PLAIN_TOKEN_ENCODING_BASE32 = 0, + + /** + * @brief Base64 encoding + */ PLAIN_TOKEN_ENCODING_BASE64 = 1 }; -#define TOTP_TOKEN_DIGITS_MAX_COUNT 8 +#define TOTP_TOKEN_DIGITS_MAX_COUNT (8) /** * @brief TOTP token information diff --git a/applications/external/totp/ui/constants.h b/applications/external/totp/ui/constants.h index 9caf90c4e..81c2edf92 100644 --- a/applications/external/totp/ui/constants.h +++ b/applications/external/totp/ui/constants.h @@ -1,6 +1,6 @@ #pragma once -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 64 +#define SCREEN_WIDTH (128) +#define SCREEN_HEIGHT (64) #define SCREEN_WIDTH_CENTER (SCREEN_WIDTH >> 1) #define SCREEN_HEIGHT_CENTER (SCREEN_HEIGHT >> 1) diff --git a/applications/external/totp/ui/fonts/font_info.h b/applications/external/totp/ui/fonts/font-info.h similarity index 100% rename from applications/external/totp/ui/fonts/font_info.h rename to applications/external/totp/ui/fonts/font-info.h diff --git a/applications/external/totp/ui/fonts/mode-nine/mode_nine.c b/applications/external/totp/ui/fonts/mode-nine/mode-nine.c similarity index 99% rename from applications/external/totp/ui/fonts/mode-nine/mode_nine.c rename to applications/external/totp/ui/fonts/mode-nine/mode-nine.c index add4f47ef..a0befe77c 100644 --- a/applications/external/totp/ui/fonts/mode-nine/mode_nine.c +++ b/applications/external/totp/ui/fonts/mode-nine/mode-nine.c @@ -1,4 +1,5 @@ -#include "mode_nine.h" +#include "mode-nine.h" +#include /* GENERATED BY https://github.com/pavius/the-dot-factory */ diff --git a/applications/external/totp/ui/fonts/mode-nine/mode_nine.h b/applications/external/totp/ui/fonts/mode-nine/mode-nine.h similarity index 77% rename from applications/external/totp/ui/fonts/mode-nine/mode_nine.h rename to applications/external/totp/ui/fonts/mode-nine/mode-nine.h index 67fa33afe..50bd5cf1c 100644 --- a/applications/external/totp/ui/fonts/mode-nine/mode_nine.h +++ b/applications/external/totp/ui/fonts/mode-nine/mode-nine.h @@ -2,8 +2,7 @@ /* GENERATED BY https://github.com/pavius/the-dot-factory */ -#include "../font_info.h" -#include +#include "../font-info.h" /* Font data for ModeNine 15pt */ extern const FONT_INFO modeNine_15ptFontInfo; diff --git a/applications/external/totp/ui/scene_director.c b/applications/external/totp/ui/scene_director.c index c77e88ab4..c6f709006 100644 --- a/applications/external/totp/ui/scene_director.c +++ b/applications/external/totp/ui/scene_director.c @@ -62,14 +62,6 @@ void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state } } -void totp_scene_director_init_scenes(PluginState* const plugin_state) { - totp_scene_authenticate_init(plugin_state); - totp_scene_generate_token_init(plugin_state); - totp_scene_add_new_token_init(plugin_state); - totp_scene_token_menu_init(plugin_state); - totp_scene_app_settings_init(plugin_state); -} - void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state) { switch(plugin_state->current_scene) { case TotpSceneGenerateToken: @@ -94,14 +86,6 @@ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_ } } -void totp_scene_director_dispose(const PluginState* const plugin_state) { - totp_scene_generate_token_free(plugin_state); - totp_scene_authenticate_free(plugin_state); - totp_scene_add_new_token_free(plugin_state); - totp_scene_token_menu_free(plugin_state); - totp_scene_app_settings_free(plugin_state); -} - bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state) { bool processing = true; switch(plugin_state->current_scene) { diff --git a/applications/external/totp/ui/scene_director.h b/applications/external/totp/ui/scene_director.h index 541a63f1c..71709978f 100644 --- a/applications/external/totp/ui/scene_director.h +++ b/applications/external/totp/ui/scene_director.h @@ -22,12 +22,6 @@ void totp_scene_director_activate_scene( */ void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state); -/** - * @brief Initializes all the available scenes - * @param plugin_state application state - */ -void totp_scene_director_init_scenes(PluginState* const plugin_state); - /** * @brief Renders current scene * @param canvas canvas to render at @@ -35,12 +29,6 @@ void totp_scene_director_init_scenes(PluginState* const plugin_state); */ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state); -/** - * @brief Disposes all the available scenes - * @param plugin_state application state - */ -void totp_scene_director_dispose(const PluginState* const plugin_state); - /** * @brief Handles application event for the current scene * @param event event to be handled diff --git a/applications/external/totp/ui/scenes/add_new_token/totp_input_text.h b/applications/external/totp/ui/scenes/add_new_token/totp_input_text.h index 145e8904d..ffbfde692 100644 --- a/applications/external/totp/ui/scenes/add_new_token/totp_input_text.h +++ b/applications/external/totp/ui/scenes/add_new_token/totp_input_text.h @@ -6,6 +6,8 @@ #include "../../../types/plugin_state.h" #include "../../../types/plugin_event.h" +#define INPUT_BUFFER_SIZE (255) + typedef struct { char* user_input; size_t user_input_length; @@ -20,8 +22,6 @@ typedef struct { void* callback_data; } InputTextSceneContext; -#define INPUT_BUFFER_SIZE 255 - typedef struct { TextInput* text_input; View* text_input_view; diff --git a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c index 800d7e672..3f8e4fd93 100644 --- a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c +++ b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c @@ -44,10 +44,6 @@ typedef struct { FuriString* duration_text; } SceneState; -void totp_scene_add_new_token_init(const PluginState* plugin_state) { - UNUSED(plugin_state); -} - static void on_token_name_user_comitted(InputTextSceneCallbackResult* result) { SceneState* scene_state = result->callback_data; free(scene_state->token_name); @@ -354,7 +350,3 @@ void totp_scene_add_new_token_deactivate(PluginState* plugin_state) { free(plugin_state->current_scene_state); plugin_state->current_scene_state = NULL; } - -void totp_scene_add_new_token_free(const PluginState* plugin_state) { - UNUSED(plugin_state); -} diff --git a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.h b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.h index c412e5f0f..07098111a 100644 --- a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.h +++ b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.h @@ -10,11 +10,9 @@ typedef struct { uint16_t current_token_index; } TokenAddEditSceneContext; -void totp_scene_add_new_token_init(const PluginState* plugin_state); void totp_scene_add_new_token_activate( PluginState* plugin_state, const TokenAddEditSceneContext* context); void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_state); bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState* plugin_state); void totp_scene_add_new_token_deactivate(PluginState* plugin_state); -void totp_scene_add_new_token_free(const PluginState* plugin_state); diff --git a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c index 93fd3d915..d2cf629d2 100644 --- a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c +++ b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c @@ -44,10 +44,6 @@ typedef struct { Control selected_control; } SceneState; -void totp_scene_app_settings_init(const PluginState* plugin_state) { - UNUSED(plugin_state); -} - void totp_scene_app_settings_activate( PluginState* plugin_state, const AppSettingsSceneContext* context) { @@ -332,7 +328,3 @@ void totp_scene_app_settings_deactivate(PluginState* plugin_state) { free(plugin_state->current_scene_state); plugin_state->current_scene_state = NULL; } - -void totp_scene_app_settings_free(const PluginState* plugin_state) { - UNUSED(plugin_state); -} \ No newline at end of file diff --git a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.h b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.h index 1721186ed..a0e408b00 100644 --- a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.h +++ b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.h @@ -8,7 +8,6 @@ typedef struct { uint16_t current_token_index; } AppSettingsSceneContext; -void totp_scene_app_settings_init(const PluginState* plugin_state); void totp_scene_app_settings_activate( PluginState* plugin_state, const AppSettingsSceneContext* context); @@ -16,5 +15,4 @@ void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plu bool totp_scene_app_settings_handle_event( const PluginEvent* const event, PluginState* plugin_state); -void totp_scene_app_settings_deactivate(PluginState* plugin_state); -void totp_scene_app_settings_free(const PluginState* plugin_state); \ No newline at end of file +void totp_scene_app_settings_deactivate(PluginState* plugin_state); \ No newline at end of file diff --git a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c index 17beb64c6..c0a0b5744 100644 --- a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c +++ b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c @@ -18,10 +18,6 @@ typedef struct { uint8_t code_length; } SceneState; -void totp_scene_authenticate_init(PluginState* plugin_state) { - memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); -} - void totp_scene_authenticate_activate(PluginState* plugin_state) { SceneState* scene_state = malloc(sizeof(SceneState)); furi_check(scene_state != NULL); @@ -162,7 +158,3 @@ void totp_scene_authenticate_deactivate(PluginState* plugin_state) { free(plugin_state->current_scene_state); plugin_state->current_scene_state = NULL; } - -void totp_scene_authenticate_free(const PluginState* plugin_state) { - UNUSED(plugin_state); -} diff --git a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.h b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.h index b8fe174ae..5ddd44a4a 100644 --- a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.h +++ b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.h @@ -4,11 +4,9 @@ #include "../../../types/plugin_state.h" #include "../../../types/plugin_event.h" -void totp_scene_authenticate_init(PluginState* plugin_state); void totp_scene_authenticate_activate(PluginState* plugin_state); void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_state); bool totp_scene_authenticate_handle_event( const PluginEvent* const event, PluginState* plugin_state); void totp_scene_authenticate_deactivate(PluginState* plugin_state); -void totp_scene_authenticate_free(const PluginState* plugin_state); diff --git a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c index f27b24835..d8de42cdf 100644 --- a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c +++ b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c @@ -19,11 +19,11 @@ #ifdef TOTP_BADBT_TYPE_ENABLED #include "../../../workers/bt_type_code/bt_type_code.h" #endif -#include "../../fonts/mode-nine/mode_nine.h" +#include "../../fonts/mode-nine/mode-nine.h" +#define PROGRESS_BAR_MARGIN (3) +#define PROGRESS_BAR_HEIGHT (4) static const char* STEAM_ALGO_ALPHABET = "23456789BCDFGHJKMNPQRTVWXY"; -static const uint8_t PROGRESS_BAR_MARGIN = 3; -static const uint8_t PROGRESS_BAR_HEIGHT = 4; typedef struct { uint16_t current_token_index; @@ -177,6 +177,7 @@ static void draw_totp_code(Canvas* const canvas, const SceneState* const scene_s uint8_t char_width = modeNine_15ptFontInfo.charInfo[0].width; uint8_t total_length = code_length * (char_width + modeNine_15ptFontInfo.spacePixels); uint8_t offset_x = (SCREEN_WIDTH - total_length) >> 1; + uint8_t offset_x_inc = char_width + modeNine_15ptFontInfo.spacePixels; uint8_t offset_y = SCREEN_HEIGHT_CENTER - (modeNine_15ptFontInfo.height >> 1); for(uint8_t i = 0; i < code_length; i++) { char ch = scene_state->last_code[i]; @@ -189,14 +190,10 @@ static void draw_totp_code(Canvas* const canvas, const SceneState* const scene_s modeNine_15ptFontInfo.height, &modeNine_15ptFontInfo.data[modeNine_15ptFontInfo.charInfo[char_index].offset]); - offset_x += char_width + modeNine_15ptFontInfo.spacePixels; + offset_x += offset_x_inc; } } -void totp_scene_generate_token_init(const PluginState* plugin_state) { - UNUSED(plugin_state); -} - void totp_scene_generate_token_activate( PluginState* plugin_state, const GenerateTokenSceneContext* context) { @@ -518,7 +515,3 @@ void totp_scene_generate_token_deactivate(PluginState* plugin_state) { free(scene_state); plugin_state->current_scene_state = NULL; } - -void totp_scene_generate_token_free(const PluginState* plugin_state) { - UNUSED(plugin_state); -} diff --git a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.h b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.h index 44a3b1c0f..e183f53d2 100644 --- a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.h +++ b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.h @@ -8,7 +8,6 @@ typedef struct { uint16_t current_token_index; } GenerateTokenSceneContext; -void totp_scene_generate_token_init(const PluginState* plugin_state); void totp_scene_generate_token_activate( PluginState* plugin_state, const GenerateTokenSceneContext* context); @@ -17,4 +16,3 @@ bool totp_scene_generate_token_handle_event( const PluginEvent* const event, PluginState* plugin_state); void totp_scene_generate_token_deactivate(PluginState* plugin_state); -void totp_scene_generate_token_free(const PluginState* plugin_state); diff --git a/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.c b/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.c index 6c6986c65..7b00f0a1b 100644 --- a/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.c +++ b/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.c @@ -24,10 +24,6 @@ typedef struct { TotpNullable_uint16_t current_token_index; } SceneState; -void totp_scene_token_menu_init(const PluginState* plugin_state) { - UNUSED(plugin_state); -} - void totp_scene_token_menu_activate( PluginState* plugin_state, const TokenMenuSceneContext* context) { @@ -204,7 +200,3 @@ void totp_scene_token_menu_deactivate(PluginState* plugin_state) { free(plugin_state->current_scene_state); plugin_state->current_scene_state = NULL; } - -void totp_scene_token_menu_free(const PluginState* plugin_state) { - UNUSED(plugin_state); -} diff --git a/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.h b/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.h index 059b8e571..f9d4b4cbf 100644 --- a/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.h +++ b/applications/external/totp/ui/scenes/token_menu/totp_scene_token_menu.h @@ -8,11 +8,9 @@ typedef struct { uint16_t current_token_index; } TokenMenuSceneContext; -void totp_scene_token_menu_init(const PluginState* plugin_state); void totp_scene_token_menu_activate( PluginState* plugin_state, const TokenMenuSceneContext* context); void totp_scene_token_menu_render(Canvas* const canvas, PluginState* plugin_state); bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginState* plugin_state); void totp_scene_token_menu_deactivate(PluginState* plugin_state); -void totp_scene_token_menu_free(const PluginState* plugin_state); diff --git a/applications/external/totp/ui/ui_controls.c b/applications/external/totp/ui/ui_controls.c index af029dd9f..d5e86aa58 100644 --- a/applications/external/totp/ui/ui_controls.c +++ b/applications/external/totp/ui/ui_controls.c @@ -2,8 +2,8 @@ #include #include "constants.h" -#define TEXT_BOX_HEIGHT 13 -#define TEXT_BOX_MARGIN 4 +#define TEXT_BOX_HEIGHT (13) +#define TEXT_BOX_MARGIN (4) void ui_control_text_box_render( Canvas* const canvas, diff --git a/applications/external/totp/workers/bt_type_code/bt_type_code.h b/applications/external/totp/workers/bt_type_code/bt_type_code.h index 3b25c03f4..1c59ea3e9 100644 --- a/applications/external/totp/workers/bt_type_code/bt_type_code.h +++ b/applications/external/totp/workers/bt_type_code/bt_type_code.h @@ -24,7 +24,7 @@ typedef struct { bool is_connected; #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME uint8_t bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN]; - char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN + 1]; + char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN]; uint8_t previous_bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN]; #endif } TotpBtTypeCodeWorkerContext;