token_info_iterator.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. #include "token_info_iterator.h"
  2. #include <flipper_format/flipper_format_i.h>
  3. #include <flipper_format/flipper_format_stream.h>
  4. #include <toolbox/stream/file_stream.h>
  5. #include "../../types/common.h"
  6. #include "../../types/crypto_settings.h"
  7. #define CONFIG_FILE_PART_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf.part"
  8. #define STREAM_COPY_BUFFER_SIZE (128)
  9. struct TokenInfoIteratorContext {
  10. size_t total_count;
  11. size_t current_index;
  12. size_t last_seek_offset;
  13. size_t last_seek_index;
  14. TokenInfo* current_token;
  15. FlipperFormat* config_file;
  16. CryptoSettings* crypto_settings;
  17. Storage* storage;
  18. };
  19. static bool
  20. flipper_format_seek_to_siblinig_token_start(Stream* stream, StreamDirection direction) {
  21. char buffer[sizeof(TOTP_CONFIG_KEY_TOKEN_NAME) + 1];
  22. bool found = false;
  23. while(!found) {
  24. if(!stream_seek_to_char(stream, '\n', direction)) {
  25. break;
  26. }
  27. size_t buffer_read_size;
  28. if((buffer_read_size = stream_read(stream, (uint8_t*)&buffer[0], sizeof(buffer))) == 0) {
  29. break;
  30. }
  31. if(!stream_seek(stream, -(int32_t)buffer_read_size, StreamOffsetFromCurrent)) {
  32. break;
  33. }
  34. if(strncmp(buffer, "\n" TOTP_CONFIG_KEY_TOKEN_NAME ":", sizeof(buffer)) == 0) {
  35. found = true;
  36. }
  37. }
  38. return found;
  39. }
  40. static bool seek_to_token(size_t token_index, TokenInfoIteratorContext* context) {
  41. furi_check(context != NULL && context->config_file != NULL);
  42. if(token_index >= context->total_count) {
  43. return false;
  44. }
  45. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  46. long token_index_diff = (long)token_index - (long)context->last_seek_index;
  47. size_t token_index_diff_weight = (size_t)labs(token_index_diff);
  48. StreamDirection direction = token_index_diff >= 0 ? StreamDirectionForward :
  49. StreamDirectionBackward;
  50. if(token_index_diff_weight > token_index || context->last_seek_offset == 0) {
  51. context->last_seek_offset = 0;
  52. context->last_seek_index = 0;
  53. token_index_diff = token_index + 1;
  54. direction = StreamDirectionForward;
  55. } else if(token_index_diff_weight > (context->total_count - token_index - 1)) {
  56. context->last_seek_offset = stream_size(stream);
  57. context->last_seek_index = context->total_count - 1;
  58. token_index_diff = -(long)(context->total_count - token_index);
  59. direction = StreamDirectionBackward;
  60. }
  61. if(!stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart)) {
  62. return false;
  63. }
  64. if(token_index_diff != 0) {
  65. long i = 0;
  66. long i_inc = token_index_diff >= 0 ? 1 : -1;
  67. do {
  68. if(!flipper_format_seek_to_siblinig_token_start(stream, direction)) {
  69. break;
  70. }
  71. i += i_inc;
  72. } while((i_inc > 0 && i < token_index_diff) || (i_inc < 0 && i > token_index_diff));
  73. if((i_inc > 0 && i < token_index_diff) || (i_inc < 0 && i > token_index_diff)) {
  74. context->last_seek_offset = 0;
  75. FURI_LOG_D(LOGGING_TAG, "Was not able to move");
  76. return false;
  77. }
  78. context->last_seek_offset = stream_tell(stream);
  79. context->last_seek_index = token_index;
  80. }
  81. return true;
  82. }
  83. static bool stream_insert_stream(Stream* dst, Stream* src) {
  84. uint8_t buffer[STREAM_COPY_BUFFER_SIZE];
  85. size_t buffer_read_size;
  86. while((buffer_read_size = stream_read(src, buffer, sizeof(buffer))) != 0) {
  87. if(!stream_insert(dst, buffer, buffer_read_size)) {
  88. return false;
  89. }
  90. }
  91. return true;
  92. }
  93. static bool ensure_stream_ends_with_lf(Stream* stream) {
  94. uint8_t last_char;
  95. size_t original_pos = stream_tell(stream);
  96. if(!stream_seek(stream, -1, StreamOffsetFromEnd) || stream_read(stream, &last_char, 1) < 1) {
  97. return false;
  98. }
  99. const uint8_t lf = '\n';
  100. if(last_char != lf && !stream_write(stream, &lf, 1)) {
  101. return false;
  102. }
  103. if(!stream_seek(stream, original_pos, StreamOffsetFromStart)) {
  104. return false;
  105. }
  106. return true;
  107. }
  108. static bool
  109. totp_token_info_iterator_save_current_token_info_changes(TokenInfoIteratorContext* context) {
  110. bool is_new_token = context->current_index >= context->total_count;
  111. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  112. if(is_new_token) {
  113. if(!ensure_stream_ends_with_lf(stream) ||
  114. !flipper_format_seek_to_end(context->config_file)) {
  115. return false;
  116. }
  117. } else {
  118. if(!seek_to_token(context->current_index, context)) {
  119. return false;
  120. }
  121. }
  122. size_t offset_start = stream_tell(stream);
  123. size_t offset_end;
  124. if(is_new_token) {
  125. offset_end = offset_start;
  126. } else if(context->current_index + 1 >= context->total_count) {
  127. offset_end = stream_size(stream);
  128. } else if(seek_to_token(context->current_index + 1, context)) {
  129. offset_end = stream_tell(stream);
  130. } else {
  131. return false;
  132. }
  133. FlipperFormat* temp_ff = flipper_format_file_alloc(context->storage);
  134. if(!flipper_format_file_open_always(temp_ff, CONFIG_FILE_PART_FILE_PATH)) {
  135. flipper_format_free(temp_ff);
  136. return false;
  137. }
  138. TokenInfo* token_info = context->current_token;
  139. bool result = false;
  140. do {
  141. if(!flipper_format_write_string(temp_ff, TOTP_CONFIG_KEY_TOKEN_NAME, token_info->name)) {
  142. break;
  143. }
  144. if(!flipper_format_write_hex(
  145. temp_ff,
  146. TOTP_CONFIG_KEY_TOKEN_SECRET,
  147. token_info->token,
  148. token_info->token_length)) {
  149. break;
  150. }
  151. uint32_t tmp_uint32 = token_info->token_plain_length;
  152. if(!flipper_format_write_uint32(
  153. temp_ff, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, &tmp_uint32, 1)) {
  154. break;
  155. }
  156. tmp_uint32 = token_info->algo;
  157. if(!flipper_format_write_uint32(temp_ff, TOTP_CONFIG_KEY_TOKEN_ALGO, &tmp_uint32, 1)) {
  158. break;
  159. }
  160. tmp_uint32 = token_info->digits;
  161. if(!flipper_format_write_uint32(temp_ff, TOTP_CONFIG_KEY_TOKEN_DIGITS, &tmp_uint32, 1)) {
  162. break;
  163. }
  164. tmp_uint32 = token_info->duration;
  165. if(!flipper_format_write_uint32(temp_ff, TOTP_CONFIG_KEY_TOKEN_DURATION, &tmp_uint32, 1)) {
  166. break;
  167. }
  168. tmp_uint32 = token_info->automation_features;
  169. if(!flipper_format_write_uint32(
  170. temp_ff, TOTP_CONFIG_KEY_TOKEN_AUTOMATION_FEATURES, &tmp_uint32, 1)) {
  171. break;
  172. }
  173. tmp_uint32 = token_info->type;
  174. if(!flipper_format_write_uint32(temp_ff, TOTP_CONFIG_KEY_TOKEN_TYPE, &tmp_uint32, 1)) {
  175. break;
  176. }
  177. if(!flipper_format_write_hex(
  178. temp_ff,
  179. TOTP_CONFIG_KEY_TOKEN_COUNTER,
  180. (uint8_t*)&token_info->counter,
  181. sizeof(token_info->counter))) {
  182. break;
  183. }
  184. Stream* temp_stream = flipper_format_get_raw_stream(temp_ff);
  185. if(!stream_rewind(temp_stream)) {
  186. break;
  187. }
  188. if(!stream_seek(stream, offset_start, StreamOffsetFromStart)) {
  189. break;
  190. }
  191. if(offset_end != offset_start && !stream_delete(stream, offset_end - offset_start)) {
  192. break;
  193. }
  194. if(!is_new_token && !stream_write_char(stream, '\n')) {
  195. break;
  196. }
  197. if(!stream_insert_stream(stream, temp_stream)) {
  198. break;
  199. }
  200. if(is_new_token) {
  201. context->total_count++;
  202. }
  203. result = true;
  204. } while(false);
  205. flipper_format_free(temp_ff);
  206. storage_common_remove(context->storage, CONFIG_FILE_PART_FILE_PATH);
  207. stream_seek(stream, offset_start, StreamOffsetFromStart);
  208. context->last_seek_offset = offset_start;
  209. context->last_seek_index = context->current_index;
  210. return result;
  211. }
  212. TokenInfoIteratorContext* totp_token_info_iterator_alloc(
  213. Storage* storage,
  214. FlipperFormat* config_file,
  215. CryptoSettings* crypto_settings) {
  216. Stream* stream = flipper_format_get_raw_stream(config_file);
  217. stream_rewind(stream);
  218. size_t tokens_count = 0;
  219. while(true) {
  220. if(!flipper_format_seek_to_siblinig_token_start(stream, StreamDirectionForward)) {
  221. break;
  222. }
  223. tokens_count++;
  224. }
  225. TokenInfoIteratorContext* context = malloc(sizeof(TokenInfoIteratorContext));
  226. furi_check(context != NULL);
  227. context->total_count = tokens_count;
  228. context->current_token = token_info_alloc();
  229. context->config_file = config_file;
  230. context->crypto_settings = crypto_settings;
  231. context->storage = storage;
  232. return context;
  233. }
  234. void totp_token_info_iterator_free(TokenInfoIteratorContext* context) {
  235. if(context == NULL) return;
  236. token_info_free(context->current_token);
  237. free(context);
  238. }
  239. bool totp_token_info_iterator_remove_current_token_info(TokenInfoIteratorContext* context) {
  240. if(!seek_to_token(context->current_index, context)) {
  241. return false;
  242. }
  243. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  244. size_t begin_offset = stream_tell(stream);
  245. size_t end_offset;
  246. if(!ensure_stream_ends_with_lf(stream)) {
  247. return false;
  248. }
  249. if(context->current_index >= context->total_count - 1) {
  250. end_offset = stream_size(stream) - 1;
  251. } else if(seek_to_token(context->current_index + 1, context)) {
  252. end_offset = stream_tell(stream);
  253. } else {
  254. return false;
  255. }
  256. if(!stream_seek(stream, begin_offset, StreamOffsetFromStart) ||
  257. !stream_delete(stream, end_offset - begin_offset)) {
  258. return false;
  259. }
  260. context->total_count--;
  261. if(context->current_index >= context->total_count) {
  262. context->current_index = context->total_count - 1;
  263. }
  264. return true;
  265. }
  266. bool totp_token_info_iterator_move_current_token_info(
  267. TokenInfoIteratorContext* context,
  268. size_t new_index) {
  269. if(context->current_index == new_index) return true;
  270. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  271. if(!ensure_stream_ends_with_lf(stream)) {
  272. return false;
  273. }
  274. if(!seek_to_token(context->current_index, context)) {
  275. return false;
  276. }
  277. size_t begin_offset = stream_tell(stream);
  278. size_t end_offset;
  279. if(context->current_index >= context->total_count - 1) {
  280. end_offset = stream_size(stream) - 1;
  281. } else if(seek_to_token(context->current_index + 1, context)) {
  282. end_offset = stream_tell(stream);
  283. } else {
  284. return false;
  285. }
  286. Stream* temp_stream = file_stream_alloc(context->storage);
  287. if(!file_stream_open(
  288. temp_stream, CONFIG_FILE_PART_FILE_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)) {
  289. stream_free(temp_stream);
  290. return false;
  291. }
  292. size_t moving_size = end_offset - begin_offset;
  293. bool result = false;
  294. do {
  295. if(!stream_seek(stream, begin_offset, StreamOffsetFromStart)) {
  296. break;
  297. }
  298. if(stream_copy(stream, temp_stream, moving_size) < moving_size) {
  299. break;
  300. }
  301. if(!stream_rewind(temp_stream)) {
  302. break;
  303. }
  304. if(!stream_seek(stream, begin_offset, StreamOffsetFromStart)) {
  305. break;
  306. }
  307. if(!stream_delete(stream, moving_size)) {
  308. break;
  309. }
  310. context->last_seek_offset = 0;
  311. context->last_seek_index = 0;
  312. if(new_index >= context->total_count - 1) {
  313. if(!stream_seek(stream, stream_size(stream) - 1, StreamOffsetFromStart)) {
  314. break;
  315. }
  316. } else if(!seek_to_token(new_index, context)) {
  317. break;
  318. }
  319. result = stream_insert_stream(stream, temp_stream);
  320. } while(false);
  321. stream_free(temp_stream);
  322. storage_common_remove(context->storage, CONFIG_FILE_PART_FILE_PATH);
  323. context->last_seek_offset = 0;
  324. context->last_seek_index = 0;
  325. return result;
  326. }
  327. TotpIteratorUpdateTokenResult totp_token_info_iterator_update_current_token(
  328. TokenInfoIteratorContext* context,
  329. TOTP_ITERATOR_UPDATE_TOKEN_ACTION update,
  330. const void* update_context) {
  331. TotpIteratorUpdateTokenResult result = update(context->current_token, update_context);
  332. if(result == TotpIteratorUpdateTokenResultSuccess) {
  333. if(!totp_token_info_iterator_save_current_token_info_changes(context)) {
  334. result = TotpIteratorUpdateTokenResultFileUpdateFailed;
  335. }
  336. return result;
  337. }
  338. totp_token_info_iterator_go_to(context, context->current_index);
  339. return result;
  340. }
  341. TotpIteratorUpdateTokenResult
  342. totp_token_info_iterator_current_token_inc_counter(TokenInfoIteratorContext* context) {
  343. if(!seek_to_token(context->current_index, context)) {
  344. return TotpIteratorUpdateTokenResultFileUpdateFailed;
  345. }
  346. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  347. size_t offset_start = stream_tell(stream);
  348. TokenInfo* token_info = context->current_token;
  349. token_info->counter++;
  350. char buffer[sizeof(TOTP_CONFIG_KEY_TOKEN_COUNTER) + 1];
  351. bool found = false;
  352. while(!found) {
  353. if(!stream_seek_to_char(stream, '\n', StreamDirectionForward)) {
  354. break;
  355. }
  356. size_t buffer_read_size;
  357. if((buffer_read_size = stream_read(stream, (uint8_t*)&buffer[0], sizeof(buffer))) == 0) {
  358. break;
  359. }
  360. if(!stream_seek(stream, -(int32_t)buffer_read_size, StreamOffsetFromCurrent)) {
  361. break;
  362. }
  363. if(strncmp(buffer, "\n" TOTP_CONFIG_KEY_TOKEN_COUNTER ":", sizeof(buffer)) == 0) {
  364. found = true;
  365. }
  366. }
  367. TotpIteratorUpdateTokenResult result = TotpIteratorUpdateTokenResultFileUpdateFailed;
  368. if(found && stream_seek(stream, 1, StreamOffsetFromCurrent) &&
  369. flipper_format_write_hex(
  370. context->config_file,
  371. TOTP_CONFIG_KEY_TOKEN_COUNTER,
  372. (uint8_t*)&token_info->counter,
  373. sizeof(token_info->counter))) {
  374. result = TotpIteratorUpdateTokenResultSuccess;
  375. }
  376. stream_seek(stream, offset_start, StreamOffsetFromStart);
  377. return result;
  378. }
  379. TotpIteratorUpdateTokenResult totp_token_info_iterator_add_new_token(
  380. TokenInfoIteratorContext* context,
  381. TOTP_ITERATOR_UPDATE_TOKEN_ACTION update,
  382. const void* update_context) {
  383. size_t previous_index = context->current_index;
  384. context->current_index = context->total_count;
  385. token_info_set_defaults(context->current_token);
  386. TotpIteratorUpdateTokenResult result = update(context->current_token, update_context);
  387. if(result == TotpIteratorUpdateTokenResultSuccess &&
  388. !totp_token_info_iterator_save_current_token_info_changes(context)) {
  389. result = TotpIteratorUpdateTokenResultFileUpdateFailed;
  390. }
  391. if(result != TotpIteratorUpdateTokenResultSuccess) {
  392. totp_token_info_iterator_go_to(context, previous_index);
  393. }
  394. return result;
  395. }
  396. bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t token_index) {
  397. furi_check(context != NULL);
  398. context->current_index = token_index;
  399. if(!seek_to_token(context->current_index, context)) {
  400. return false;
  401. }
  402. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  403. size_t original_offset = stream_tell(stream);
  404. if(!flipper_format_read_string(
  405. context->config_file, TOTP_CONFIG_KEY_TOKEN_NAME, context->current_token->name)) {
  406. stream_seek(stream, original_offset, StreamOffsetFromStart);
  407. return false;
  408. }
  409. uint32_t secret_bytes_count;
  410. if(!flipper_format_get_value_count(
  411. context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET, &secret_bytes_count)) {
  412. secret_bytes_count = 0;
  413. }
  414. TokenInfo* tokenInfo = context->current_token;
  415. bool token_update_needed = false;
  416. if(tokenInfo->token != NULL) {
  417. free(tokenInfo->token);
  418. tokenInfo->token_length = 0;
  419. }
  420. uint32_t temp_data32;
  421. if(secret_bytes_count == 1) { // Plain secret key
  422. FuriString* temp_str = furi_string_alloc();
  423. if(flipper_format_read_string(
  424. context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
  425. if(token_info_set_secret(
  426. tokenInfo,
  427. furi_string_get_cstr(temp_str),
  428. furi_string_size(temp_str),
  429. PlainTokenSecretEncodingBase32,
  430. context->crypto_settings)) {
  431. FURI_LOG_W(
  432. LOGGING_TAG,
  433. "Token \"%s\" has plain secret",
  434. furi_string_get_cstr(tokenInfo->name));
  435. token_update_needed = true;
  436. } else {
  437. tokenInfo->token = NULL;
  438. tokenInfo->token_length = 0;
  439. tokenInfo->token_plain_length = 0;
  440. FURI_LOG_W(
  441. LOGGING_TAG,
  442. "Token \"%s\" has invalid secret",
  443. furi_string_get_cstr(tokenInfo->name));
  444. }
  445. } else {
  446. tokenInfo->token = NULL;
  447. tokenInfo->token_length = 0;
  448. tokenInfo->token_plain_length = 0;
  449. }
  450. furi_string_free(temp_str);
  451. } else { // encrypted
  452. tokenInfo->token_length = secret_bytes_count;
  453. if(secret_bytes_count > 0) {
  454. tokenInfo->token = malloc(tokenInfo->token_length);
  455. furi_check(tokenInfo->token != NULL);
  456. if(!flipper_format_read_hex(
  457. context->config_file,
  458. TOTP_CONFIG_KEY_TOKEN_SECRET,
  459. tokenInfo->token,
  460. tokenInfo->token_length)) {
  461. free(tokenInfo->token);
  462. tokenInfo->token = NULL;
  463. tokenInfo->token_length = 0;
  464. }
  465. } else {
  466. tokenInfo->token = NULL;
  467. }
  468. if(flipper_format_read_uint32(
  469. context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET_LENGTH, &temp_data32, 1)) {
  470. tokenInfo->token_plain_length = temp_data32;
  471. } else {
  472. tokenInfo->token_plain_length = tokenInfo->token_length;
  473. }
  474. }
  475. if(!flipper_format_read_uint32(
  476. context->config_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &temp_data32, 1) ||
  477. !token_info_set_algo_from_int(tokenInfo, temp_data32)) {
  478. tokenInfo->algo = TokenHashAlgoDefault;
  479. }
  480. if(!flipper_format_read_uint32(
  481. context->config_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &temp_data32, 1) ||
  482. !token_info_set_digits_from_int(tokenInfo, temp_data32)) {
  483. tokenInfo->digits = TokenDigitsCountSix;
  484. }
  485. if(!flipper_format_read_uint32(
  486. context->config_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &temp_data32, 1) ||
  487. !token_info_set_duration_from_int(tokenInfo, temp_data32)) {
  488. tokenInfo->duration = TokenDurationDefault;
  489. }
  490. if(flipper_format_read_uint32(
  491. context->config_file, TOTP_CONFIG_KEY_TOKEN_AUTOMATION_FEATURES, &temp_data32, 1)) {
  492. tokenInfo->automation_features = temp_data32;
  493. } else {
  494. tokenInfo->automation_features = TokenAutomationFeatureNone;
  495. }
  496. if(flipper_format_read_uint32(
  497. context->config_file, TOTP_CONFIG_KEY_TOKEN_TYPE, &temp_data32, 1)) {
  498. tokenInfo->type = temp_data32;
  499. } else {
  500. tokenInfo->type = TokenTypeTOTP;
  501. }
  502. if(!flipper_format_read_hex(
  503. context->config_file,
  504. TOTP_CONFIG_KEY_TOKEN_COUNTER,
  505. (uint8_t*)&tokenInfo->counter,
  506. sizeof(tokenInfo->counter))) {
  507. tokenInfo->counter = 0;
  508. }
  509. stream_seek(stream, original_offset, StreamOffsetFromStart);
  510. if(token_update_needed && !totp_token_info_iterator_save_current_token_info_changes(context)) {
  511. return false;
  512. }
  513. return true;
  514. }
  515. const TokenInfo*
  516. totp_token_info_iterator_get_current_token(const TokenInfoIteratorContext* context) {
  517. return context->current_token;
  518. }
  519. size_t totp_token_info_iterator_get_current_token_index(const TokenInfoIteratorContext* context) {
  520. return context->current_index;
  521. }
  522. size_t totp_token_info_iterator_get_total_count(const TokenInfoIteratorContext* context) {
  523. return context->total_count;
  524. }
  525. void totp_token_info_iterator_attach_to_config_file(
  526. TokenInfoIteratorContext* context,
  527. FlipperFormat* config_file) {
  528. context->config_file = config_file;
  529. Stream* stream = flipper_format_get_raw_stream(context->config_file);
  530. stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart);
  531. }