mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 09:18:35 -07:00
Update totp
This commit is contained in:
@@ -15,9 +15,6 @@
|
||||
#define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
|
||||
#define CONFIG_FILE_BACKUP_DIR CONFIG_FILE_DIRECTORY_PATH "/backups"
|
||||
#define CONFIG_FILE_BACKUP_BASE_PATH CONFIG_FILE_BACKUP_DIR "/totp.conf"
|
||||
#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"
|
||||
|
||||
struct ConfigFileContext {
|
||||
/**
|
||||
@@ -120,26 +117,6 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
|
||||
totp_close_config_file(fff_data_file);
|
||||
return false;
|
||||
}
|
||||
} else if(storage_common_stat(storage, CONFIG_FILE_PATH_PREVIOUS, NULL) == FSE_OK) {
|
||||
FURI_LOG_D(LOGGING_TAG, "Old config file %s found", CONFIG_FILE_PATH_PREVIOUS);
|
||||
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
|
||||
FURI_LOG_D(
|
||||
LOGGING_TAG,
|
||||
"Directory %s doesn't exist. Will create new.",
|
||||
CONFIG_FILE_DIRECTORY_PATH);
|
||||
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
|
||||
FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
|
||||
totp_close_config_file(fff_data_file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(storage_common_rename(storage, CONFIG_FILE_PATH_PREVIOUS, CONFIG_FILE_PATH) != FSE_OK) {
|
||||
FURI_LOG_E(LOGGING_TAG, "Error moving config to %s", CONFIG_FILE_PATH);
|
||||
totp_close_config_file(fff_data_file);
|
||||
return false;
|
||||
}
|
||||
FURI_LOG_I(LOGGING_TAG, "Applied config file path migration");
|
||||
return totp_open_config_file(storage, file);
|
||||
} else {
|
||||
FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH);
|
||||
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
|
||||
@@ -177,9 +154,8 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_METHOD, &tmp_uint32, 1);
|
||||
|
||||
// Default Font = 0
|
||||
tmp_uint32 = 0;
|
||||
flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1);
|
||||
flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1);
|
||||
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
totp_close_config_file(fff_data_file);
|
||||
@@ -263,24 +239,6 @@ bool totp_config_file_update_automation_method(const PluginState* plugin_state)
|
||||
return update_result;
|
||||
}
|
||||
|
||||
bool totp_config_file_update_selected_font(const PluginState* plugin_state) {
|
||||
FlipperFormat* file = plugin_state->config_file_context->config_file;
|
||||
flipper_format_rewind(file);
|
||||
bool update_result = false;
|
||||
|
||||
do {
|
||||
uint32_t tmp_uint32 = plugin_state->selected_font;
|
||||
if(!flipper_format_insert_or_update_uint32(
|
||||
file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
update_result = true;
|
||||
} while(false);
|
||||
|
||||
return update_result;
|
||||
}
|
||||
|
||||
bool totp_config_file_update_user_settings(const PluginState* plugin_state) {
|
||||
FlipperFormat* file = plugin_state->config_file_context->config_file;
|
||||
flipper_format_rewind(file);
|
||||
@@ -302,9 +260,8 @@ bool totp_config_file_update_user_settings(const PluginState* plugin_state) {
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_uint32 = plugin_state->selected_font;
|
||||
if(!flipper_format_insert_or_update_uint32(
|
||||
file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
|
||||
tmp_uint32 = plugin_state->active_font_index;
|
||||
if(!flipper_format_insert_or_update_uint32(file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -456,15 +413,11 @@ bool totp_config_file_load(PluginState* const plugin_state) {
|
||||
|
||||
plugin_state->automation_method = tmp_uint32;
|
||||
|
||||
// Load selected font
|
||||
flipper_format_rewind(fff_data_file);
|
||||
|
||||
if(!flipper_format_read_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
|
||||
if(!flipper_format_read_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) {
|
||||
tmp_uint32 = 0;
|
||||
}
|
||||
|
||||
plugin_state->selected_font = tmp_uint32;
|
||||
plugin_state->active_font_index = tmp_uint32;
|
||||
|
||||
plugin_state->config_file_context = malloc(sizeof(ConfigFileContext));
|
||||
furi_check(plugin_state->config_file_context != NULL);
|
||||
|
||||
@@ -44,13 +44,6 @@ bool totp_config_file_update_notification_method(const PluginState* plugin_state
|
||||
*/
|
||||
bool totp_config_file_update_automation_method(const PluginState* plugin_state);
|
||||
|
||||
/**
|
||||
* @brief Updates selected font in an application config file
|
||||
* @param plugin_state application state
|
||||
* @return Config file update result
|
||||
*/
|
||||
bool totp_config_file_update_selected_font(const PluginState* plugin_state);
|
||||
|
||||
/**
|
||||
* @brief Updates application user settings
|
||||
* @param plugin_state application state
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator")
|
||||
#define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
|
||||
#define CONFIG_FILE_ACTUAL_VERSION (5)
|
||||
#define CONFIG_FILE_ACTUAL_VERSION (6)
|
||||
|
||||
#define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
|
||||
#define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"
|
||||
@@ -18,4 +18,4 @@
|
||||
#define TOTP_CONFIG_KEY_PINSET "PinIsSet"
|
||||
#define TOTP_CONFIG_KEY_NOTIFICATION_METHOD "NotificationMethod"
|
||||
#define TOTP_CONFIG_KEY_AUTOMATION_METHOD "AutomationMethod"
|
||||
#define TOTP_CONFIG_KEY_SELECTED_FONT "SelectedFont"
|
||||
#define TOTP_CONFIG_KEY_FONT "Font"
|
||||
|
||||
@@ -58,11 +58,12 @@ bool totp_config_migrate_to_latest(
|
||||
|
||||
flipper_format_rewind(fff_backup_data_file);
|
||||
|
||||
// Font
|
||||
|
||||
if(flipper_format_read_string(
|
||||
fff_backup_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, temp_str)) {
|
||||
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, temp_str);
|
||||
if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_FONT, temp_str)) {
|
||||
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_FONT, temp_str);
|
||||
} else {
|
||||
uint32_t default_font_index = 0;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_FONT, &default_font_index, 1);
|
||||
}
|
||||
|
||||
flipper_format_rewind(fff_backup_data_file);
|
||||
@@ -84,13 +85,13 @@ bool totp_config_migrate_to_latest(
|
||||
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
|
||||
|
||||
if(current_version < 5) {
|
||||
uint32_t algo_as_uint32t = SHA1;
|
||||
if(furi_string_cmpi_str(temp_str, TOTP_TOKEN_ALGO_SHA256_NAME) == 0) {
|
||||
algo_as_uint32t = SHA256;
|
||||
} else if(furi_string_cmpi_str(temp_str, TOTP_TOKEN_ALGO_SHA512_NAME) == 0) {
|
||||
algo_as_uint32t = SHA512;
|
||||
} else if(furi_string_cmpi_str(temp_str, TOTP_TOKEN_ALGO_STEAM_NAME) == 0) {
|
||||
algo_as_uint32t = STEAM;
|
||||
uint32_t algo_as_uint32t = TokenHashAlgoDefault;
|
||||
if(furi_string_cmpi_str(temp_str, TOKEN_HASH_ALGO_SHA256_NAME) == 0) {
|
||||
algo_as_uint32t = TokenHashAlgoSha256;
|
||||
} else if(furi_string_cmpi_str(temp_str, TOKEN_HASH_ALGO_SHA512_NAME) == 0) {
|
||||
algo_as_uint32t = TokenHashAlgoSha512;
|
||||
} else if(furi_string_cmpi_str(temp_str, TOKEN_HASH_ALGO_STEAM_NAME) == 0) {
|
||||
algo_as_uint32t = TokenHashAlgoSteam;
|
||||
}
|
||||
|
||||
flipper_format_write_uint32(
|
||||
@@ -104,10 +105,10 @@ bool totp_config_migrate_to_latest(
|
||||
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);
|
||||
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);
|
||||
} else {
|
||||
const uint32_t default_algo = SHA1;
|
||||
const uint32_t default_algo = TokenHashAlgoDefault;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &default_algo, 1);
|
||||
const uint32_t default_digits = TotpSixDigitsCount;
|
||||
const uint32_t default_digits = TokenDigitsCountSix;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
|
||||
}
|
||||
@@ -118,7 +119,7 @@ bool totp_config_migrate_to_latest(
|
||||
flipper_format_write_string(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DURATION, temp_str);
|
||||
} else {
|
||||
const uint32_t default_duration = TOTP_TOKEN_DURATION_DEFAULT;
|
||||
const uint32_t default_duration = TokenDurationDefault;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &default_duration, 1);
|
||||
}
|
||||
|
||||
@@ -496,19 +496,19 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
|
||||
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)) {
|
||||
tokenInfo->algo = SHA1;
|
||||
tokenInfo->algo = TokenHashAlgoDefault;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_uint32(
|
||||
context->config_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &temp_data32, 1) ||
|
||||
!token_info_set_digits_from_int(tokenInfo, temp_data32)) {
|
||||
tokenInfo->digits = TotpSixDigitsCount;
|
||||
tokenInfo->digits = TokenDigitsCountSix;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_uint32(
|
||||
context->config_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &temp_data32, 1) ||
|
||||
!token_info_set_duration_from_int(tokenInfo, temp_data32)) {
|
||||
tokenInfo->duration = TOTP_TOKEN_DURATION_DEFAULT;
|
||||
tokenInfo->duration = TokenDurationDefault;
|
||||
}
|
||||
|
||||
if(flipper_format_read_uint32(
|
||||
|
||||
@@ -90,11 +90,8 @@ CryptoSeedIVResult
|
||||
} else {
|
||||
max_i = uid_size;
|
||||
}
|
||||
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
|
||||
const uint8_t* uid = furi_hal_version_uid_default();
|
||||
#else
|
||||
const uint8_t* uid = furi_hal_version_uid();
|
||||
#endif
|
||||
|
||||
const uint8_t* uid = (const uint8_t*)UID64_BASE; //-V566
|
||||
for(uint8_t i = 0; i < max_i; i++) {
|
||||
plugin_state->iv[i] = plugin_state->iv[i] ^ uid[i];
|
||||
}
|
||||
@@ -137,4 +134,4 @@ bool totp_crypto_verify_key(const PluginState* plugin_state) {
|
||||
free(decrypted_key);
|
||||
|
||||
return key_valid;
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,4 @@ void idle_timeout_free(IdleTimeoutContext* context) {
|
||||
furi_timer_stop(context->timer);
|
||||
furi_timer_free(context->timer);
|
||||
free(context);
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,4 @@ void idle_timeout_report_activity(IdleTimeoutContext* context);
|
||||
* @brief Disposes IDLE timeout and releases all the resources
|
||||
* @param context IDLE timeout context
|
||||
*/
|
||||
void idle_timeout_free(IdleTimeoutContext* context);
|
||||
void idle_timeout_free(IdleTimeoutContext* context);
|
||||
Reference in New Issue
Block a user