Skip to content

Commit

Permalink
Picopass: update working with keys (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: あく <[email protected]>
  • Loading branch information
gornekich and skotopes authored Dec 20, 2023
1 parent fbfade5 commit 66a657f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .catalog/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions picopass_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <picopass_icons.h>

#include <nfc/nfc.h>
#include <nfc/helpers/nfc_dict.h>
#include <toolbox/keys_dict.h>
#include "protocol/picopass_poller.h"
#include "protocol/picopass_listener.h"

Expand Down Expand Up @@ -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;
Expand Down
40 changes: 21 additions & 19 deletions scenes/picopass_scene_elite_dict_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions scenes/picopass_scene_read_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 66a657f

Please sign in to comment.