config_migration_v2_to_v3.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "config_migration_v2_to_v3.h"
  2. #include <flipper_format/flipper_format.h>
  3. #include "../constants.h"
  4. #include "../../../types/token_info.h"
  5. #define NEW_VERSION 3
  6. bool totp_config_migrate_v2_to_v3(
  7. FlipperFormat* fff_data_file,
  8. FlipperFormat* fff_backup_data_file) {
  9. flipper_format_write_header_cstr(fff_data_file, CONFIG_FILE_HEADER, NEW_VERSION);
  10. FuriString* temp_str = furi_string_alloc();
  11. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str)) {
  12. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str);
  13. }
  14. flipper_format_rewind(fff_backup_data_file);
  15. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str)) {
  16. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str);
  17. }
  18. flipper_format_rewind(fff_backup_data_file);
  19. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str)) {
  20. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str);
  21. }
  22. flipper_format_rewind(fff_backup_data_file);
  23. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_PINSET, temp_str)) {
  24. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_PINSET, temp_str);
  25. }
  26. flipper_format_rewind(fff_backup_data_file);
  27. if(flipper_format_read_string(
  28. fff_backup_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, temp_str)) {
  29. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, temp_str);
  30. }
  31. flipper_format_rewind(fff_backup_data_file);
  32. while(true) {
  33. if(!flipper_format_read_string(
  34. fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
  35. break;
  36. }
  37. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str);
  38. flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  39. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  40. flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
  41. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
  42. flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);
  43. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);
  44. const uint32_t default_duration = TOTP_TOKEN_DURATION_DEFAULT;
  45. flipper_format_write_uint32(
  46. fff_data_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &default_duration, 1);
  47. }
  48. furi_string_free(temp_str);
  49. return true;
  50. }