config_migration_v1_to_v2.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "config_migration_v1_to_v2.h"
  2. #include <flipper_format/flipper_format.h>
  3. #include "../constants.h"
  4. #include "../../../types/token_info.h"
  5. #define NEW_VERSION 2
  6. bool totp_config_migrate_v1_to_v2(
  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. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str)) {
  15. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str);
  16. }
  17. if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str)) {
  18. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str);
  19. }
  20. while(true) {
  21. if(!flipper_format_read_string(
  22. fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
  23. break;
  24. }
  25. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str);
  26. flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  27. flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
  28. flipper_format_write_string_cstr(
  29. fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
  30. const uint32_t default_digits = TOTP_6_DIGITS;
  31. flipper_format_write_uint32(
  32. fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
  33. }
  34. furi_string_free(temp_str);
  35. return true;
  36. }