config.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. #include "config.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../list/list.h"
  5. #include "../../types/common.h"
  6. #include "../../types/token_info.h"
  7. #include "migrations/config_migration_v1_to_v2.h"
  8. #define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator")
  9. #define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
  10. #define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup"
  11. #define CONFIG_FILE_PATH_PREVIOUS EXT_PATH("apps/Misc") "/totp.conf"
  12. static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) {
  13. switch(token_info->algo) {
  14. case SHA1:
  15. return TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME;
  16. case SHA256:
  17. return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME;
  18. case SHA512:
  19. return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
  20. default:
  21. break;
  22. }
  23. return NULL;
  24. }
  25. static void token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) {
  26. if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
  27. token_info->algo = SHA1;
  28. } else if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME) == 0) {
  29. token_info->algo = SHA256;
  30. } else if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME) == 0) {
  31. token_info->algo = SHA512;
  32. }
  33. }
  34. Storage* totp_open_storage() {
  35. return furi_record_open(RECORD_STORAGE);
  36. }
  37. void totp_close_storage() {
  38. furi_record_close(RECORD_STORAGE);
  39. }
  40. FlipperFormat* totp_open_config_file(Storage* storage) {
  41. FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
  42. if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) == FSE_OK) {
  43. FURI_LOG_D(LOGGING_TAG, "Config file %s found", CONFIG_FILE_PATH);
  44. if(!flipper_format_file_open_existing(fff_data_file, CONFIG_FILE_PATH)) {
  45. FURI_LOG_E(LOGGING_TAG, "Error opening existing file %s", CONFIG_FILE_PATH);
  46. totp_close_config_file(fff_data_file);
  47. return NULL;
  48. }
  49. } else if(storage_common_stat(storage, CONFIG_FILE_PATH_PREVIOUS, NULL) == FSE_OK) {
  50. FURI_LOG_D(LOGGING_TAG, "Old config file %s found", CONFIG_FILE_PATH_PREVIOUS);
  51. if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
  52. FURI_LOG_D(
  53. LOGGING_TAG,
  54. "Directory %s doesn't exist. Will create new.",
  55. CONFIG_FILE_DIRECTORY_PATH);
  56. if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
  57. FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
  58. return NULL;
  59. }
  60. }
  61. if(storage_common_rename(storage, CONFIG_FILE_PATH_PREVIOUS, CONFIG_FILE_PATH) != FSE_OK) {
  62. FURI_LOG_E(LOGGING_TAG, "Error moving config to %s", CONFIG_FILE_PATH);
  63. return NULL;
  64. }
  65. FURI_LOG_I(LOGGING_TAG, "Applied config file path migration");
  66. return totp_open_config_file(storage);
  67. } else {
  68. FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH);
  69. if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
  70. FURI_LOG_D(
  71. LOGGING_TAG,
  72. "Directory %s doesn't exist. Will create new.",
  73. CONFIG_FILE_DIRECTORY_PATH);
  74. if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
  75. FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
  76. return NULL;
  77. }
  78. }
  79. if(!flipper_format_file_open_new(fff_data_file, CONFIG_FILE_PATH)) {
  80. totp_close_config_file(fff_data_file);
  81. FURI_LOG_E(LOGGING_TAG, "Error creating new file %s", CONFIG_FILE_PATH);
  82. return NULL;
  83. }
  84. flipper_format_write_header_cstr(
  85. fff_data_file, CONFIG_FILE_HEADER, CONFIG_FILE_ACTUAL_VERSION);
  86. float tmp_tz = 0;
  87. flipper_format_write_comment_cstr(fff_data_file, " ");
  88. flipper_format_write_comment_cstr(
  89. fff_data_file,
  90. "Timezone offset in hours. Important note: do not put '+' sign for positive values");
  91. flipper_format_write_float(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &tmp_tz, 1);
  92. uint32_t tmp_uint32 = NotificationMethodSound | NotificationMethodVibro;
  93. flipper_format_write_comment_cstr(fff_data_file, " ");
  94. flipper_format_write_comment_cstr(
  95. fff_data_file,
  96. "How to notify user when new token is generated or badusb mode is activated (possible values: 0 - do not notify, 1 - sound, 2 - vibro, 3 sound and vibro)");
  97. flipper_format_write_uint32(
  98. fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1);
  99. FuriString* temp_str = furi_string_alloc();
  100. flipper_format_write_comment_cstr(fff_data_file, " ");
  101. flipper_format_write_comment_cstr(fff_data_file, "=== TOKEN SAMPLE BEGIN ===");
  102. flipper_format_write_comment_cstr(fff_data_file, " ");
  103. flipper_format_write_comment_cstr(
  104. fff_data_file, "# Token name which will be visible in the UI.");
  105. furi_string_printf(temp_str, "%s: Sample token name", TOTP_CONFIG_KEY_TOKEN_NAME);
  106. flipper_format_write_comment(fff_data_file, temp_str);
  107. flipper_format_write_comment_cstr(fff_data_file, " ");
  108. flipper_format_write_comment_cstr(
  109. fff_data_file,
  110. "# Plain token secret without spaces, dashes and etc, just pure alpha-numeric characters. Important note: plain token will be encrypted and replaced by TOTP app");
  111. furi_string_printf(temp_str, "%s: plaintokensecret", TOTP_CONFIG_KEY_TOKEN_SECRET);
  112. flipper_format_write_comment(fff_data_file, temp_str);
  113. flipper_format_write_comment_cstr(fff_data_file, " ");
  114. furi_string_printf(
  115. temp_str,
  116. " # Token hashing algorithm to use during code generation. Supported options are %s, %s and %s. If you are not use which one to use - use %s",
  117. TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME,
  118. TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME,
  119. TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME,
  120. TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
  121. flipper_format_write_comment(fff_data_file, temp_str);
  122. furi_string_printf(
  123. temp_str, "%s: %s", TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
  124. flipper_format_write_comment(fff_data_file, temp_str);
  125. flipper_format_write_comment_cstr(fff_data_file, " ");
  126. flipper_format_write_comment_cstr(
  127. fff_data_file,
  128. "# How many digits there should be in generated code. Available options are 6 and 8. Majority websites requires 6 digits code, however some rare websites wants to get 8 digits code. If you are not sure which one to use - use 6");
  129. furi_string_printf(temp_str, "%s: 6", TOTP_CONFIG_KEY_TOKEN_DIGITS);
  130. flipper_format_write_comment(fff_data_file, temp_str);
  131. flipper_format_write_comment_cstr(fff_data_file, " ");
  132. flipper_format_write_comment_cstr(fff_data_file, "=== TOKEN SAMPLE END ===");
  133. flipper_format_write_comment_cstr(fff_data_file, " ");
  134. furi_string_free(temp_str);
  135. if(!flipper_format_rewind(fff_data_file)) {
  136. totp_close_config_file(fff_data_file);
  137. FURI_LOG_E(LOGGING_TAG, "Rewind error");
  138. return NULL;
  139. }
  140. }
  141. return fff_data_file;
  142. }
  143. void totp_config_file_save_new_token_i(FlipperFormat* file, const TokenInfo* token_info) {
  144. flipper_format_seek_to_end(file);
  145. flipper_format_write_string_cstr(file, TOTP_CONFIG_KEY_TOKEN_NAME, token_info->name);
  146. bool token_is_valid = token_info->token != NULL && token_info->token_length > 0;
  147. if(!token_is_valid) {
  148. flipper_format_write_comment_cstr(file, "!!! WARNING BEGIN: INVALID TOKEN !!!");
  149. }
  150. flipper_format_write_hex(
  151. file, TOTP_CONFIG_KEY_TOKEN_SECRET, token_info->token, token_info->token_length);
  152. if(!token_is_valid) {
  153. flipper_format_write_comment_cstr(file, "!!! WARNING END !!!");
  154. }
  155. flipper_format_write_string_cstr(
  156. file, TOTP_CONFIG_KEY_TOKEN_ALGO, token_info_get_algo_as_cstr(token_info));
  157. uint32_t tmp_uint32 = token_info->digits;
  158. flipper_format_write_uint32(file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &tmp_uint32, 1);
  159. }
  160. void totp_config_file_save_new_token(const TokenInfo* token_info) {
  161. Storage* cfg_storage = totp_open_storage();
  162. FlipperFormat* file = totp_open_config_file(cfg_storage);
  163. totp_config_file_save_new_token_i(file, token_info);
  164. totp_close_config_file(file);
  165. totp_close_storage();
  166. }
  167. void totp_config_file_update_timezone_offset(float new_timezone_offset) {
  168. Storage* cfg_storage = totp_open_storage();
  169. FlipperFormat* file = totp_open_config_file(cfg_storage);
  170. flipper_format_insert_or_update_float(file, TOTP_CONFIG_KEY_TIMEZONE, &new_timezone_offset, 1);
  171. totp_close_config_file(file);
  172. totp_close_storage();
  173. }
  174. void totp_config_file_update_notification_method(NotificationMethod new_notification_method) {
  175. Storage* cfg_storage = totp_open_storage();
  176. FlipperFormat* file = totp_open_config_file(cfg_storage);
  177. uint32_t tmp_uint32 = new_notification_method;
  178. flipper_format_insert_or_update_uint32(
  179. file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1);
  180. totp_close_config_file(file);
  181. totp_close_storage();
  182. }
  183. void totp_config_file_update_user_settings(const PluginState* plugin_state) {
  184. Storage* cfg_storage = totp_open_storage();
  185. FlipperFormat* file = totp_open_config_file(cfg_storage);
  186. flipper_format_insert_or_update_float(
  187. file, TOTP_CONFIG_KEY_TIMEZONE, &plugin_state->timezone_offset, 1);
  188. uint32_t tmp_uint32 = plugin_state->notification_method;
  189. flipper_format_insert_or_update_uint32(
  190. file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1);
  191. totp_close_config_file(file);
  192. totp_close_storage();
  193. }
  194. void totp_full_save_config_file(const PluginState* const plugin_state) {
  195. Storage* storage = totp_open_storage();
  196. FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
  197. flipper_format_file_open_always(fff_data_file, CONFIG_FILE_PATH);
  198. flipper_format_write_header_cstr(
  199. fff_data_file, CONFIG_FILE_HEADER, CONFIG_FILE_ACTUAL_VERSION);
  200. flipper_format_write_hex(
  201. fff_data_file, TOTP_CONFIG_KEY_BASE_IV, &plugin_state->base_iv[0], TOTP_IV_SIZE);
  202. flipper_format_write_hex(
  203. fff_data_file,
  204. TOTP_CONFIG_KEY_CRYPTO_VERIFY,
  205. plugin_state->crypto_verify_data,
  206. plugin_state->crypto_verify_data_length);
  207. flipper_format_write_float(
  208. fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &plugin_state->timezone_offset, 1);
  209. flipper_format_write_bool(fff_data_file, TOTP_CONFIG_KEY_PINSET, &plugin_state->pin_set, 1);
  210. uint32_t tmp_uint32 = plugin_state->notification_method;
  211. flipper_format_write_uint32(
  212. fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1);
  213. TOTP_LIST_FOREACH(plugin_state->tokens_list, node, {
  214. const TokenInfo* token_info = node->data;
  215. totp_config_file_save_new_token_i(fff_data_file, token_info);
  216. });
  217. totp_close_config_file(fff_data_file);
  218. totp_close_storage();
  219. }
  220. void totp_config_file_load_base(PluginState* const plugin_state) {
  221. Storage* storage = totp_open_storage();
  222. FlipperFormat* fff_data_file = totp_open_config_file(storage);
  223. plugin_state->timezone_offset = 0;
  224. FuriString* temp_str = furi_string_alloc();
  225. uint32_t file_version;
  226. if(!flipper_format_read_header(fff_data_file, temp_str, &file_version)) {
  227. FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
  228. furi_string_free(temp_str);
  229. return;
  230. }
  231. if(file_version < CONFIG_FILE_ACTUAL_VERSION) {
  232. FURI_LOG_I(
  233. LOGGING_TAG,
  234. "Obsolete config file version detected. Current version: %" PRIu32
  235. "; Actual version: %" PRId16,
  236. file_version,
  237. CONFIG_FILE_ACTUAL_VERSION);
  238. totp_close_config_file(fff_data_file);
  239. if(storage_common_stat(storage, CONFIG_FILE_BACKUP_PATH, NULL) == FSE_OK) {
  240. storage_simply_remove(storage, CONFIG_FILE_BACKUP_PATH);
  241. }
  242. if(storage_common_copy(storage, CONFIG_FILE_PATH, CONFIG_FILE_BACKUP_PATH) == FSE_OK) {
  243. FURI_LOG_I(LOGGING_TAG, "Took config file backup to %s", CONFIG_FILE_BACKUP_PATH);
  244. fff_data_file = totp_open_config_file(storage);
  245. FlipperFormat* fff_backup_data_file = flipper_format_file_alloc(storage);
  246. flipper_format_file_open_existing(fff_backup_data_file, CONFIG_FILE_BACKUP_PATH);
  247. if(file_version == 1) {
  248. if(totp_config_migrate_v1_to_v2(fff_data_file, fff_backup_data_file)) {
  249. FURI_LOG_I(LOGGING_TAG, "Applied migration from v1 to v2");
  250. } else {
  251. FURI_LOG_W(LOGGING_TAG, "An error occurred during migration from v1 to v2");
  252. }
  253. }
  254. flipper_format_file_close(fff_backup_data_file);
  255. flipper_format_free(fff_backup_data_file);
  256. flipper_format_rewind(fff_data_file);
  257. } else {
  258. FURI_LOG_E(
  259. LOGGING_TAG,
  260. "An error occurred during taking backup of %s into %s before migration",
  261. CONFIG_FILE_PATH,
  262. CONFIG_FILE_BACKUP_PATH);
  263. }
  264. }
  265. if(!flipper_format_read_hex(
  266. fff_data_file, TOTP_CONFIG_KEY_BASE_IV, &plugin_state->base_iv[0], TOTP_IV_SIZE)) {
  267. FURI_LOG_D(LOGGING_TAG, "Missing base IV");
  268. }
  269. flipper_format_rewind(fff_data_file);
  270. uint32_t crypto_size;
  271. if(flipper_format_get_value_count(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, &crypto_size) &&
  272. crypto_size > 0) {
  273. plugin_state->crypto_verify_data = malloc(sizeof(uint8_t) * crypto_size);
  274. furi_check(plugin_state->crypto_verify_data != NULL);
  275. plugin_state->crypto_verify_data_length = crypto_size;
  276. if(!flipper_format_read_hex(
  277. fff_data_file,
  278. TOTP_CONFIG_KEY_CRYPTO_VERIFY,
  279. plugin_state->crypto_verify_data,
  280. crypto_size)) {
  281. FURI_LOG_D(LOGGING_TAG, "Missing crypto verify token");
  282. free(plugin_state->crypto_verify_data);
  283. plugin_state->crypto_verify_data = NULL;
  284. plugin_state->crypto_verify_data_length = 0;
  285. }
  286. } else {
  287. plugin_state->crypto_verify_data = NULL;
  288. plugin_state->crypto_verify_data_length = 0;
  289. }
  290. flipper_format_rewind(fff_data_file);
  291. if(!flipper_format_read_float(
  292. fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &plugin_state->timezone_offset, 1)) {
  293. plugin_state->timezone_offset = 0;
  294. FURI_LOG_D(LOGGING_TAG, "Missing timezone offset information, defaulting to 0");
  295. }
  296. flipper_format_rewind(fff_data_file);
  297. if(!flipper_format_read_bool(
  298. fff_data_file, TOTP_CONFIG_KEY_PINSET, &plugin_state->pin_set, 1)) {
  299. plugin_state->pin_set = true;
  300. }
  301. flipper_format_rewind(fff_data_file);
  302. uint32_t tmp_uint32;
  303. if(!flipper_format_read_uint32(
  304. fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1)) {
  305. tmp_uint32 = NotificationMethodSound | NotificationMethodVibro;
  306. }
  307. plugin_state->notification_method = tmp_uint32;
  308. furi_string_free(temp_str);
  309. totp_close_config_file(fff_data_file);
  310. totp_close_storage();
  311. }
  312. TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state) {
  313. Storage* storage = totp_open_storage();
  314. FlipperFormat* fff_data_file = totp_open_config_file(storage);
  315. FuriString* temp_str = furi_string_alloc();
  316. uint32_t temp_data32;
  317. if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
  318. FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
  319. furi_string_free(temp_str);
  320. return TokenLoadingResultError;
  321. }
  322. TokenLoadingResult result = TokenLoadingResultSuccess;
  323. uint16_t index = 0;
  324. bool has_any_plain_secret = false;
  325. while(true) {
  326. if(!flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
  327. break;
  328. }
  329. TokenInfo* tokenInfo = token_info_alloc();
  330. size_t temp_cstr_len = furi_string_size(temp_str);
  331. tokenInfo->name = malloc(temp_cstr_len + 1);
  332. furi_check(tokenInfo->name != NULL);
  333. strlcpy(tokenInfo->name, furi_string_get_cstr(temp_str), temp_cstr_len + 1);
  334. uint32_t secret_bytes_count;
  335. if(!flipper_format_get_value_count(
  336. fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, &secret_bytes_count)) {
  337. secret_bytes_count = 0;
  338. }
  339. if(secret_bytes_count == 1) { // Plain secret key
  340. if(flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
  341. if(token_info_set_secret(
  342. tokenInfo,
  343. furi_string_get_cstr(temp_str),
  344. furi_string_size(temp_str),
  345. &plugin_state->iv[0])) {
  346. FURI_LOG_W(LOGGING_TAG, "Token \"%s\" has plain secret", tokenInfo->name);
  347. } else {
  348. tokenInfo->token = NULL;
  349. tokenInfo->token_length = 0;
  350. FURI_LOG_W(LOGGING_TAG, "Token \"%s\" has invalid secret", tokenInfo->name);
  351. result = TokenLoadingResultWarning;
  352. }
  353. } else {
  354. tokenInfo->token = NULL;
  355. tokenInfo->token_length = 0;
  356. result = TokenLoadingResultWarning;
  357. }
  358. has_any_plain_secret = true;
  359. } else { // encrypted
  360. tokenInfo->token_length = secret_bytes_count;
  361. if(secret_bytes_count > 0) {
  362. tokenInfo->token = malloc(tokenInfo->token_length);
  363. furi_check(tokenInfo->token != NULL);
  364. if(!flipper_format_read_hex(
  365. fff_data_file,
  366. TOTP_CONFIG_KEY_TOKEN_SECRET,
  367. tokenInfo->token,
  368. tokenInfo->token_length)) {
  369. free(tokenInfo->token);
  370. tokenInfo->token = NULL;
  371. tokenInfo->token_length = 0;
  372. result = TokenLoadingResultWarning;
  373. }
  374. } else {
  375. tokenInfo->token = NULL;
  376. result = TokenLoadingResultWarning;
  377. }
  378. }
  379. if(flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str)) {
  380. token_info_set_algo_from_str(tokenInfo, temp_str);
  381. } else {
  382. tokenInfo->algo = SHA1;
  383. }
  384. if(!flipper_format_read_uint32(
  385. fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &temp_data32, 1) ||
  386. !token_info_set_digits_from_int(tokenInfo, temp_data32)) {
  387. tokenInfo->digits = TOTP_6_DIGITS;
  388. }
  389. FURI_LOG_D(LOGGING_TAG, "Found token \"%s\"", tokenInfo->name);
  390. TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, tokenInfo, furi_check);
  391. index++;
  392. }
  393. plugin_state->tokens_count = index;
  394. plugin_state->token_list_loaded = true;
  395. FURI_LOG_D(LOGGING_TAG, "Found %" PRIu16 " tokens", index);
  396. furi_string_free(temp_str);
  397. totp_close_config_file(fff_data_file);
  398. totp_close_storage();
  399. if(has_any_plain_secret) {
  400. totp_full_save_config_file(plugin_state);
  401. }
  402. return result;
  403. }
  404. void totp_close_config_file(FlipperFormat* file) {
  405. if(file == NULL) return;
  406. flipper_format_file_close(file);
  407. flipper_format_free(file);
  408. }