Update totp

This commit is contained in:
Willy-JL
2023-08-13 03:02:22 +02:00
parent 1d3228768f
commit 7504e58244
81 changed files with 655 additions and 1518 deletions

View File

@@ -8,7 +8,7 @@
#include <memset_s.h>
#include "../../types/common.h"
#include "../../types/token_info.h"
#include "../../features_config.h"
#include "../../config/app/config.h"
#include "../crypto/crypto_facade.h"
#include "../crypto/constants.h"
#include "migrations/common_migration.h"
@@ -112,7 +112,8 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
bool conf_file_exists = storage_common_stat(storage, CONFIG_FILE_PATH, NULL) == FSE_OK;
if(!conf_file_exists) {
if(!conf_file_exists &&
storage_common_stat(storage, EXT_PATH("authenticator"), NULL) == FSE_OK) {
FURI_LOG_I(LOGGING_TAG, "Application catalog needs to be migrated");
FS_Error migration_result =
storage_common_migrate(storage, EXT_PATH("authenticator"), CONFIG_FILE_DIRECTORY_PATH);
@@ -148,7 +149,7 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
flipper_format_write_comment_cstr(
fff_data_file,
"Config file format specification can be found here: https://github.com/akopachov/flipper-zero_authenticator/blob/master/docs/conf-file_description.md");
"Config file format specification can be found here: https://t.ly/zwQjE");
float tmp_tz = 0;
flipper_format_write_float(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &tmp_tz, 1);
@@ -396,10 +397,10 @@ bool totp_config_file_load(PluginState* const plugin_state) {
if(!flipper_format_read_hex(
fff_data_file,
TOTP_CONFIG_KEY_BASE_IV,
&plugin_state->crypto_settings.base_iv[0],
CRYPTO_IV_LENGTH)) {
FURI_LOG_D(LOGGING_TAG, "Missing base IV");
TOTP_CONFIG_KEY_SALT,
&plugin_state->crypto_settings.salt[0],
CRYPTO_SALT_LENGTH)) {
FURI_LOG_D(LOGGING_TAG, "Missing salt");
}
if(!flipper_format_rewind(fff_data_file)) {
@@ -529,9 +530,9 @@ bool totp_config_file_update_crypto_signatures(const PluginState* plugin_state)
if(!flipper_format_insert_or_update_hex(
config_file,
TOTP_CONFIG_KEY_BASE_IV,
plugin_state->crypto_settings.base_iv,
CRYPTO_IV_LENGTH)) {
TOTP_CONFIG_KEY_SALT,
&plugin_state->crypto_settings.salt[0],
CRYPTO_SALT_LENGTH)) {
break;
}
@@ -592,7 +593,7 @@ bool totp_config_file_update_encryption(
CryptoSettings old_crypto_settings = plugin_state->crypto_settings;
memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH);
memset(&plugin_state->crypto_settings.base_iv[0], 0, CRYPTO_IV_LENGTH);
memset(&plugin_state->crypto_settings.salt[0], 0, CRYPTO_SALT_LENGTH);
if(plugin_state->crypto_settings.crypto_verify_data != NULL) {
free(plugin_state->crypto_settings.crypto_verify_data);
plugin_state->crypto_settings.crypto_verify_data = NULL;
@@ -724,4 +725,4 @@ bool totp_config_file_ensure_latest_encryption(
TokenInfoIteratorContext* totp_config_get_token_iterator_context(const PluginState* plugin_state) {
return plugin_state->config_file_context->token_info_iterator_context;
}
}

View File

@@ -2,9 +2,9 @@
#include <storage/storage.h>
#define CONFIG_FILE_DIRECTORY_PATH STORAGE_APP_DATA_PATH_PREFIX
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/totp")
#define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
#define CONFIG_FILE_ACTUAL_VERSION (8)
#define CONFIG_FILE_ACTUAL_VERSION (9)
#define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
#define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"
@@ -14,7 +14,7 @@
#define TOTP_CONFIG_KEY_TOKEN_DURATION "TokenDuration"
#define TOTP_CONFIG_KEY_TOKEN_AUTOMATION_FEATURES "TokenAutomationFeatures"
#define TOTP_CONFIG_KEY_CRYPTO_VERIFY "Crypto"
#define TOTP_CONFIG_KEY_BASE_IV "BaseIV"
#define TOTP_CONFIG_KEY_SALT "Salt"
#define TOTP_CONFIG_KEY_PINSET "PinIsSet"
#define TOTP_CONFIG_KEY_NOTIFICATION_METHOD "NotificationMethod"
#define TOTP_CONFIG_KEY_AUTOMATION_METHOD "AutomationMethod"

View File

@@ -4,6 +4,8 @@
#include "../../../types/automation_kb_layout.h"
#include <flipper_format/flipper_format_i.h>
#define TOTP_OLD_CONFIG_KEY_BASE_IV "BaseIV"
bool totp_config_migrate_to_latest(
FlipperFormat* fff_data_file,
FlipperFormat* fff_backup_data_file) {
@@ -40,8 +42,13 @@ bool totp_config_migrate_to_latest(
flipper_format_rewind(fff_backup_data_file);
if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str);
if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_SALT, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_SALT, temp_str);
} else if(
flipper_format_rewind(fff_backup_data_file) &&
flipper_format_read_string(
fff_backup_data_file, TOTP_OLD_CONFIG_KEY_BASE_IV, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_SALT, temp_str);
}
flipper_format_rewind(fff_backup_data_file);

View File

@@ -7,7 +7,7 @@
#include "../../types/crypto_settings.h"
#define CONFIG_FILE_PART_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf.part"
#define STREAM_COPY_BUFFER_SIZE 128
#define STREAM_COPY_BUFFER_SIZE (128)
struct TokenInfoIteratorContext {
size_t total_count;
@@ -547,4 +547,6 @@ void totp_token_info_iterator_attach_to_config_file(
TokenInfoIteratorContext* context,
FlipperFormat* config_file) {
context->config_file = config_file;
Stream* stream = flipper_format_get_raw_stream(context->config_file);
stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart);
}