config_migration_v1_to_v2.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "config_migration_v1_to_v2.h"
  2. #include <flipper_format/flipper_format.h>
  3. #include "../constants.h"
  4. #define NEW_VERSION 2
  5. bool totp_config_migrate_v1_to_v2(
  6. FlipperFormat* fff_data_file,
  7. FlipperFormat* fff_backup_data_file) {
  8. flipper_format_write_header_cstr(fff_data_file, CONFIG_FILE_HEADER, NEW_VERSION);
  9. FuriString* temp_str = furi_string_alloc();
  10. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str)) {
  11. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str);
  12. }
  13. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str)) {
  14. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str);
  15. }
  16. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str)) {
  17. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str);
  18. }
  19. while(true) {
  20. if(!flipper_format_read_string(
  21. fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
  22. break;
  23. }
  24. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str);
  25. flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  26. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  27. flipper_format_write_string_cstr(
  28. fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
  29. uint32_t default_digits = 6;
  30. flipper_format_write_uint32(
  31. fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
  32. }
  33. furi_string_free(temp_str);
  34. return true;
  35. }