@@ -375,7 +375,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
375
375
break ;
376
376
}
377
377
378
- plugin_state -> crypto_version = tmp_uint32 ;
378
+ plugin_state -> crypto_settings . crypto_version = tmp_uint32 ;
379
379
380
380
if (!flipper_format_rewind (fff_data_file )) {
381
381
break ;
@@ -388,7 +388,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
388
388
break ;
389
389
}
390
390
391
- plugin_state -> crypto_key_slot = tmp_uint32 ;
391
+ plugin_state -> crypto_settings . crypto_key_slot = tmp_uint32 ;
392
392
393
393
if (!flipper_format_rewind (fff_data_file )) {
394
394
break ;
@@ -397,7 +397,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
397
397
if (!flipper_format_read_hex (
398
398
fff_data_file ,
399
399
TOTP_CONFIG_KEY_BASE_IV ,
400
- & plugin_state -> base_iv [0 ],
400
+ & plugin_state -> crypto_settings . base_iv [0 ],
401
401
CRYPTO_IV_LENGTH )) {
402
402
FURI_LOG_D (LOGGING_TAG , "Missing base IV" );
403
403
}
@@ -410,22 +410,23 @@ bool totp_config_file_load(PluginState* const plugin_state) {
410
410
if (flipper_format_get_value_count (
411
411
fff_data_file , TOTP_CONFIG_KEY_CRYPTO_VERIFY , & crypto_size ) &&
412
412
crypto_size > 0 ) {
413
- plugin_state -> crypto_verify_data = malloc (sizeof (uint8_t ) * crypto_size );
414
- furi_check (plugin_state -> crypto_verify_data != NULL );
415
- plugin_state -> crypto_verify_data_length = crypto_size ;
413
+ plugin_state -> crypto_settings .crypto_verify_data =
414
+ malloc (sizeof (uint8_t ) * crypto_size );
415
+ furi_check (plugin_state -> crypto_settings .crypto_verify_data != NULL );
416
+ plugin_state -> crypto_settings .crypto_verify_data_length = crypto_size ;
416
417
if (!flipper_format_read_hex (
417
418
fff_data_file ,
418
419
TOTP_CONFIG_KEY_CRYPTO_VERIFY ,
419
- plugin_state -> crypto_verify_data ,
420
+ plugin_state -> crypto_settings . crypto_verify_data ,
420
421
crypto_size )) {
421
422
FURI_LOG_D (LOGGING_TAG , "Missing crypto verify token" );
422
- free (plugin_state -> crypto_verify_data );
423
- plugin_state -> crypto_verify_data = NULL ;
424
- plugin_state -> crypto_verify_data_length = 0 ;
423
+ free (plugin_state -> crypto_settings . crypto_verify_data );
424
+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
425
+ plugin_state -> crypto_settings . crypto_verify_data_length = 0 ;
425
426
}
426
427
} else {
427
- plugin_state -> crypto_verify_data = NULL ;
428
- plugin_state -> crypto_verify_data_length = 0 ;
428
+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
429
+ plugin_state -> crypto_settings . crypto_verify_data_length = 0 ;
429
430
}
430
431
431
432
if (!flipper_format_rewind (fff_data_file )) {
@@ -443,8 +444,11 @@ bool totp_config_file_load(PluginState* const plugin_state) {
443
444
}
444
445
445
446
if (!flipper_format_read_bool (
446
- fff_data_file , TOTP_CONFIG_KEY_PINSET , & plugin_state -> pin_set , 1 )) {
447
- plugin_state -> pin_set = true;
447
+ fff_data_file ,
448
+ TOTP_CONFIG_KEY_PINSET ,
449
+ & plugin_state -> crypto_settings .pin_required ,
450
+ 1 )) {
451
+ plugin_state -> crypto_settings .pin_required = true;
448
452
}
449
453
450
454
if (!flipper_format_rewind (fff_data_file )) {
@@ -498,9 +502,7 @@ bool totp_config_file_load(PluginState* const plugin_state) {
498
502
totp_token_info_iterator_alloc (
499
503
storage ,
500
504
plugin_state -> config_file_context -> config_file ,
501
- plugin_state -> iv ,
502
- plugin_state -> crypto_version ,
503
- plugin_state -> crypto_key_slot );
505
+ & plugin_state -> crypto_settings );
504
506
result = true;
505
507
} while (false);
506
508
@@ -513,33 +515,39 @@ bool totp_config_file_update_crypto_signatures(const PluginState* plugin_state)
513
515
flipper_format_rewind (config_file );
514
516
bool update_result = false;
515
517
do {
516
- uint32_t tmp_uint32 = plugin_state -> crypto_version ;
518
+ uint32_t tmp_uint32 = plugin_state -> crypto_settings . crypto_version ;
517
519
if (!flipper_format_insert_or_update_uint32 (
518
520
config_file , TOTP_CONFIG_KEY_CRYPTO_VERSION , & tmp_uint32 , 1 )) {
519
521
break ;
520
522
}
521
523
522
- tmp_uint32 = plugin_state -> crypto_key_slot ;
524
+ tmp_uint32 = plugin_state -> crypto_settings . crypto_key_slot ;
523
525
if (!flipper_format_insert_or_update_uint32 (
524
526
config_file , TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT , & tmp_uint32 , 1 )) {
525
527
break ;
526
528
}
527
529
528
530
if (!flipper_format_insert_or_update_hex (
529
- config_file , TOTP_CONFIG_KEY_BASE_IV , plugin_state -> base_iv , CRYPTO_IV_LENGTH )) {
531
+ config_file ,
532
+ TOTP_CONFIG_KEY_BASE_IV ,
533
+ plugin_state -> crypto_settings .base_iv ,
534
+ CRYPTO_IV_LENGTH )) {
530
535
break ;
531
536
}
532
537
533
538
if (!flipper_format_insert_or_update_hex (
534
539
config_file ,
535
540
TOTP_CONFIG_KEY_CRYPTO_VERIFY ,
536
- plugin_state -> crypto_verify_data ,
537
- plugin_state -> crypto_verify_data_length )) {
541
+ plugin_state -> crypto_settings . crypto_verify_data ,
542
+ plugin_state -> crypto_settings . crypto_verify_data_length )) {
538
543
break ;
539
544
}
540
545
541
546
if (!flipper_format_insert_or_update_bool (
542
- config_file , TOTP_CONFIG_KEY_PINSET , & plugin_state -> pin_set , 1 )) {
547
+ config_file ,
548
+ TOTP_CONFIG_KEY_PINSET ,
549
+ & plugin_state -> crypto_settings .pin_required ,
550
+ 1 )) {
543
551
break ;
544
552
}
545
553
@@ -581,24 +589,20 @@ bool totp_config_file_update_encryption(
581
589
return false;
582
590
}
583
591
584
- uint8_t old_iv [CRYPTO_IV_LENGTH ];
585
- memcpy (& old_iv [0 ], & plugin_state -> iv [0 ], CRYPTO_IV_LENGTH );
586
-
587
- uint8_t old_crypto_key_slot = plugin_state -> crypto_key_slot ;
588
- uint8_t old_crypto_version = plugin_state -> crypto_version ;
592
+ CryptoSettings old_crypto_settings = plugin_state -> crypto_settings ;
589
593
590
- memset (& plugin_state -> iv [0 ], 0 , CRYPTO_IV_LENGTH );
591
- memset (& plugin_state -> base_iv [0 ], 0 , CRYPTO_IV_LENGTH );
592
- if (plugin_state -> crypto_verify_data != NULL ) {
593
- free (plugin_state -> crypto_verify_data );
594
- plugin_state -> crypto_verify_data = NULL ;
594
+ memset (& plugin_state -> crypto_settings . iv [0 ], 0 , CRYPTO_IV_LENGTH );
595
+ memset (& plugin_state -> crypto_settings . base_iv [0 ], 0 , CRYPTO_IV_LENGTH );
596
+ if (plugin_state -> crypto_settings . crypto_verify_data != NULL ) {
597
+ free (plugin_state -> crypto_settings . crypto_verify_data );
598
+ plugin_state -> crypto_settings . crypto_verify_data = NULL ;
595
599
}
596
600
597
- plugin_state -> crypto_key_slot = new_crypto_key_slot ;
598
- plugin_state -> crypto_version = CRYPTO_LATEST_VERSION ;
601
+ plugin_state -> crypto_settings . crypto_key_slot = new_crypto_key_slot ;
602
+ plugin_state -> crypto_settings . crypto_version = CRYPTO_LATEST_VERSION ;
599
603
600
- CryptoSeedIVResult seed_result =
601
- totp_crypto_seed_iv ( plugin_state , new_pin_length > 0 ? new_pin : NULL , new_pin_length );
604
+ CryptoSeedIVResult seed_result = totp_crypto_seed_iv (
605
+ & plugin_state -> crypto_settings , new_pin_length > 0 ? new_pin : NULL , new_pin_length );
602
606
if (seed_result & CryptoSeedIVResultFlagSuccess &&
603
607
seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData &&
604
608
!totp_config_file_update_crypto_signatures (plugin_state )) {
@@ -649,21 +653,14 @@ bool totp_config_file_update_encryption(
649
653
650
654
size_t plain_token_length ;
651
655
uint8_t * plain_token = totp_crypto_decrypt (
652
- encrypted_token ,
653
- secret_bytes_count ,
654
- & old_iv [0 ],
655
- old_crypto_version ,
656
- old_crypto_key_slot ,
657
- & plain_token_length );
656
+ encrypted_token , secret_bytes_count , & old_crypto_settings , & plain_token_length );
658
657
659
658
free (encrypted_token );
660
659
size_t encrypted_token_length ;
661
660
encrypted_token = totp_crypto_encrypt (
662
661
plain_token ,
663
662
plain_token_length ,
664
- & plugin_state -> iv [0 ],
665
- plugin_state -> crypto_version ,
666
- plugin_state -> crypto_key_slot ,
663
+ & plugin_state -> crypto_settings ,
667
664
& encrypted_token_length );
668
665
669
666
memset_s (plain_token , plain_token_length , 0 , plain_token_length );
@@ -700,12 +697,12 @@ bool totp_config_file_ensure_latest_encryption(
700
697
const uint8_t * pin ,
701
698
uint8_t pin_length ) {
702
699
bool result = true;
703
- if (plugin_state -> crypto_version < CRYPTO_LATEST_VERSION ) {
700
+ if (plugin_state -> crypto_settings . crypto_version < CRYPTO_LATEST_VERSION ) {
704
701
FURI_LOG_I (LOGGING_TAG , "Migration to crypto v%d is needed" , CRYPTO_LATEST_VERSION );
705
702
char * backup_path = totp_config_file_backup (plugin_state );
706
703
if (backup_path != NULL ) {
707
704
free (backup_path );
708
- uint8_t crypto_key_slot = plugin_state -> crypto_key_slot ;
705
+ uint8_t crypto_key_slot = plugin_state -> crypto_settings . crypto_key_slot ;
709
706
if (!totp_crypto_check_key_slot (crypto_key_slot )) {
710
707
crypto_key_slot = DEFAULT_CRYPTO_KEY_SLOT ;
711
708
}
0 commit comments