From 66a657f45f2d3b70a2aad0c09d264eed1d212d28 Mon Sep 17 00:00:00 2001 From: gornekich Date: Wed, 20 Dec 2023 13:33:23 +0400 Subject: [PATCH] Picopass: update working with keys (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- .catalog/changelog.md | 3 ++ application.fam | 2 +- picopass_i.h | 4 +-- scenes/picopass_scene_elite_dict_attack.c | 40 ++++++++++++----------- scenes/picopass_scene_read_card.c | 18 +++++----- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/.catalog/changelog.md b/.catalog/changelog.md index b6d69225866..7be86605cba 100644 --- a/.catalog/changelog.md +++ b/.catalog/changelog.md @@ -1,3 +1,6 @@ +## 1.11 + - Update working with keys with new API + - Display more tag information ## 1.10 - Fix missing folder in readme - Allow partial save for any read failure diff --git a/application.fam b/application.fam index 85eadce2a8b..f6d0b97bb4a 100644 --- a/application.fam +++ b/application.fam @@ -10,7 +10,7 @@ App( ], stack_size=4 * 1024, fap_description="App to communicate with NFC tags using the PicoPass(iClass) format", - fap_version="1.10", + fap_version="1.11", fap_icon="125_10px.png", fap_category="NFC", fap_libs=["mbedtls"], diff --git a/picopass_i.h b/picopass_i.h index dbb1a5d09af..358bb8f6c14 100644 --- a/picopass_i.h +++ b/picopass_i.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include "protocol/picopass_poller.h" #include "protocol/picopass_listener.h" @@ -89,7 +89,7 @@ struct Picopass { Nfc* nfc; PicopassPoller* poller; PicopassListener* listener; - NfcDict* dict; + KeysDict* dict; char text_store[PICOPASS_TEXT_STORE_SIZE]; FuriString* text_box_store; diff --git a/scenes/picopass_scene_elite_dict_attack.c b/scenes/picopass_scene_elite_dict_attack.c index 5284e1b2700..08f4995de2c 100644 --- a/scenes/picopass_scene_elite_dict_attack.c +++ b/scenes/picopass_scene_elite_dict_attack.c @@ -22,26 +22,26 @@ static bool picopass_elite_dict_attack_change_dict(Picopass* picopass) { do { uint32_t scene_state = scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneEliteDictAttack); - nfc_dict_free(picopass->dict); + keys_dict_free(picopass->dict); picopass->dict = NULL; if(scene_state == PicopassSceneEliteDictAttackDictElite) break; if(scene_state == PicopassSceneEliteDictAttackDictEliteUser) { - if(!nfc_dict_check_presence(PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME)) break; - picopass->dict = nfc_dict_alloc( + if(!keys_dict_check_presence(PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME)) break; + picopass->dict = keys_dict_alloc( PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME, - NfcDictModeOpenExisting, + KeysDictModeOpenExisting, PICOPASS_KEY_LEN); scene_state = PicopassSceneEliteDictAttackDictStandard; } else if(scene_state == PicopassSceneEliteDictAttackDictStandard) { - if(!nfc_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME)) break; - picopass->dict = nfc_dict_alloc( + if(!keys_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME)) break; + picopass->dict = keys_dict_alloc( PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME, - NfcDictModeOpenExisting, + KeysDictModeOpenExisting, PICOPASS_KEY_LEN); scene_state = PicopassSceneEliteDictAttackDictElite; } picopass->dict_attack_ctx.card_detected = true; - picopass->dict_attack_ctx.total_keys = nfc_dict_get_total_keys(picopass->dict); + picopass->dict_attack_ctx.total_keys = keys_dict_get_total_keys(picopass->dict); picopass->dict_attack_ctx.current_key = 0; picopass->dict_attack_ctx.name = picopass_dict_name[scene_state]; scene_manager_set_scene_state( @@ -63,9 +63,9 @@ NfcCommand picopass_elite_dict_attack_worker_callback(PicopassPollerEvent event, } else if(event.type == PicopassPollerEventTypeRequestKey) { uint8_t key[PICOPASS_KEY_LEN] = {}; bool is_key_provided = true; - if(!nfc_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN)) { + if(!keys_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN)) { if(picopass_elite_dict_attack_change_dict(picopass)) { - is_key_provided = nfc_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN); + is_key_provided = keys_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN); view_dispatcher_send_custom_event( picopass->view_dispatcher, PicopassCustomEventDictAttackUpdateView); } else { @@ -137,24 +137,26 @@ void picopass_scene_elite_dict_attack_on_enter(void* context) { // Setup dict attack context uint32_t state = PicopassSceneEliteDictAttackDictEliteUser; - bool use_user_dict = nfc_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_USER_NAME); + bool use_user_dict = keys_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_USER_NAME); if(use_user_dict) { - picopass->dict = nfc_dict_alloc( - PICOPASS_ICLASS_ELITE_DICT_USER_NAME, NfcDictModeOpenExisting, PICOPASS_KEY_LEN); - if(nfc_dict_get_total_keys(picopass->dict) == 0) { - nfc_dict_free(picopass->dict); + picopass->dict = keys_dict_alloc( + PICOPASS_ICLASS_ELITE_DICT_USER_NAME, KeysDictModeOpenExisting, PICOPASS_KEY_LEN); + if(keys_dict_get_total_keys(picopass->dict) == 0) { + keys_dict_free(picopass->dict); use_user_dict = false; } } if(use_user_dict) { state = PicopassSceneEliteDictAttackDictEliteUser; } else { - picopass->dict = nfc_dict_alloc( - PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME, NfcDictModeOpenExisting, PICOPASS_KEY_LEN); + picopass->dict = keys_dict_alloc( + PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME, + KeysDictModeOpenExisting, + PICOPASS_KEY_LEN); state = PicopassSceneEliteDictAttackDictStandard; } picopass->dict_attack_ctx.card_detected = true; - picopass->dict_attack_ctx.total_keys = nfc_dict_get_total_keys(picopass->dict); + picopass->dict_attack_ctx.total_keys = keys_dict_get_total_keys(picopass->dict); picopass->dict_attack_ctx.current_key = 0; picopass->dict_attack_ctx.name = picopass_dict_name[state]; scene_manager_set_scene_state(picopass->scene_manager, PicopassSceneEliteDictAttack, state); @@ -218,7 +220,7 @@ void picopass_scene_elite_dict_attack_on_exit(void* context) { Picopass* picopass = context; if(picopass->dict) { - nfc_dict_free(picopass->dict); + keys_dict_free(picopass->dict); picopass->dict = NULL; } picopass->dict_attack_ctx.current_key = 0; diff --git a/scenes/picopass_scene_read_card.c b/scenes/picopass_scene_read_card.c index cdf4d0383d6..2621b429194 100644 --- a/scenes/picopass_scene_read_card.c +++ b/scenes/picopass_scene_read_card.c @@ -13,13 +13,13 @@ static bool picopass_read_card_change_dict(Picopass* picopass) { do { uint32_t scene_state = scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneReadCard); - nfc_dict_free(picopass->dict); + keys_dict_free(picopass->dict); picopass->dict = NULL; if(scene_state == PicopassSceneReadCardDictElite) break; - if(!nfc_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME)) break; + if(!keys_dict_check_presence(PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME)) break; - picopass->dict = nfc_dict_alloc( - PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME, NfcDictModeOpenExisting, PICOPASS_KEY_LEN); + picopass->dict = keys_dict_alloc( + PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME, KeysDictModeOpenExisting, PICOPASS_KEY_LEN); scene_manager_set_scene_state( picopass->scene_manager, PicopassSceneReadCard, PicopassSceneReadCardDictElite); success = true; @@ -39,9 +39,9 @@ NfcCommand picopass_read_card_worker_callback(PicopassPollerEvent event, void* c } else if(event.type == PicopassPollerEventTypeRequestKey) { uint8_t key[PICOPASS_KEY_LEN] = {}; bool is_key_provided = true; - if(!nfc_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN)) { + if(!keys_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN)) { if(picopass_read_card_change_dict(picopass)) { - is_key_provided = nfc_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN); + is_key_provided = keys_dict_get_next_key(picopass->dict, key, PICOPASS_KEY_LEN); } else { is_key_provided = false; } @@ -75,8 +75,8 @@ void picopass_scene_read_card_on_enter(void* context) { popup_set_header(popup, "Detecting\npicopass\ncard", 68, 30, AlignLeft, AlignTop); popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61); - picopass->dict = nfc_dict_alloc( - PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME, NfcDictModeOpenExisting, PICOPASS_KEY_LEN); + picopass->dict = keys_dict_alloc( + PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME, KeysDictModeOpenExisting, PICOPASS_KEY_LEN); scene_manager_set_scene_state( picopass->scene_manager, PicopassSceneReadCard, PicopassSceneReadCardDictStandard); // Start worker @@ -111,7 +111,7 @@ void picopass_scene_read_card_on_exit(void* context) { Picopass* picopass = context; if(picopass->dict) { - nfc_dict_free(picopass->dict); + keys_dict_free(picopass->dict); picopass->dict = NULL; } picopass_poller_stop(picopass->poller);