mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
@@ -1,6 +1,7 @@
|
||||
#include "common_migration.h"
|
||||
#include "../constants.h"
|
||||
#include "../../../types/token_info.h"
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
bool totp_config_migrate_to_latest(
|
||||
FlipperFormat* fff_data_file,
|
||||
@@ -57,18 +58,12 @@ bool totp_config_migrate_to_latest(
|
||||
|
||||
flipper_format_rewind(fff_backup_data_file);
|
||||
|
||||
FuriString* comment_str = furi_string_alloc();
|
||||
|
||||
while(true) {
|
||||
if(!flipper_format_read_string(
|
||||
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_string_printf(
|
||||
comment_str, "=== BEGIN \"%s\" ===", furi_string_get_cstr(temp_str));
|
||||
flipper_format_write_comment(fff_data_file, comment_str);
|
||||
furi_string_printf(comment_str, "=== END \"%s\" ===", furi_string_get_cstr(temp_str));
|
||||
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str);
|
||||
|
||||
flipper_format_read_string(
|
||||
@@ -78,15 +73,32 @@ bool totp_config_migrate_to_latest(
|
||||
if(current_version > 1) {
|
||||
flipper_format_read_string(
|
||||
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
|
||||
flipper_format_write_string(fff_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;
|
||||
}
|
||||
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &algo_as_uint32t, 1);
|
||||
} else {
|
||||
flipper_format_write_string(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
|
||||
}
|
||||
|
||||
flipper_format_read_string(
|
||||
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 {
|
||||
flipper_format_write_string_cstr(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_TOKEN_ALGO_SHA1_NAME);
|
||||
const uint32_t default_digits = TOTP_6_DIGITS;
|
||||
const uint32_t default_algo = SHA1;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &default_algo, 1);
|
||||
const uint32_t default_digits = TotpSixDigitsCount;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
|
||||
}
|
||||
@@ -108,18 +120,21 @@ bool totp_config_migrate_to_latest(
|
||||
flipper_format_write_string(
|
||||
fff_data_file, TOTP_CONFIG_KEY_TOKEN_AUTOMATION_FEATURES, temp_str);
|
||||
} else {
|
||||
const uint32_t default_automation_features = TOKEN_AUTOMATION_FEATURE_NONE;
|
||||
const uint32_t default_automation_features = TokenAutomationFeatureNone;
|
||||
flipper_format_write_uint32(
|
||||
fff_data_file,
|
||||
TOTP_CONFIG_KEY_TOKEN_AUTOMATION_FEATURES,
|
||||
&default_automation_features,
|
||||
1);
|
||||
}
|
||||
|
||||
flipper_format_write_comment(fff_data_file, comment_str);
|
||||
}
|
||||
|
||||
furi_string_free(comment_str);
|
||||
Stream* stream = flipper_format_get_raw_stream(fff_data_file);
|
||||
size_t current_pos = stream_tell(stream);
|
||||
size_t total_size = stream_size(stream);
|
||||
if(current_pos < total_size) {
|
||||
stream_delete(stream, total_size - current_pos);
|
||||
}
|
||||
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
/**
|
||||
* @brief Migrates config file to the latest version
|
||||
* @param fff_data_file original config file to be migrated
|
||||
* @param fff_backup_data_file backup copy of original config file
|
||||
* @return \c true if operation succeeded; \c false otherwise
|
||||
*/
|
||||
bool totp_config_migrate_to_latest(
|
||||
FlipperFormat* fff_data_file,
|
||||
FlipperFormat* fff_backup_data_file);
|
||||
FlipperFormat* fff_backup_data_file);
|
||||
|
||||
Reference in New Issue
Block a user