Skip to content

Commit 471e8db

Browse files
bettseskotopes
andauthored
Picopass: enum to track auth method (#198)
Co-authored-by: あく <[email protected]>
1 parent 3768efe commit 471e8db

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

picopass_device.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ const char unknown_block[] = "?? ?? ?? ?? ?? ?? ?? ??";
2020

2121
PicopassDevice* picopass_device_alloc() {
2222
PicopassDevice* picopass_dev = malloc(sizeof(PicopassDevice));
23+
picopass_dev->dev_data.auth = PicopassDeviceAuthMethodUnset;
2324
picopass_dev->dev_data.pacs.legacy = false;
2425
picopass_dev->dev_data.pacs.se_enabled = false;
26+
picopass_dev->dev_data.pacs.sio = false;
27+
picopass_dev->dev_data.pacs.biometrics = false;
28+
memset(picopass_dev->dev_data.pacs.key, 0, sizeof(picopass_dev->dev_data.pacs.key));
2529
picopass_dev->dev_data.pacs.elite_kdf = false;
2630
picopass_dev->dev_data.pacs.pin_length = 0;
31+
picopass_dev->dev_data.pacs.bitLength = 0;
32+
memset(
33+
picopass_dev->dev_data.pacs.credential, 0, sizeof(picopass_dev->dev_data.pacs.credential));
2734
picopass_dev->storage = furi_record_open(RECORD_STORAGE);
2835
picopass_dev->dialogs = furi_record_open(RECORD_DIALOGS);
2936
picopass_dev->load_path = furi_string_alloc();
@@ -422,8 +429,8 @@ void picopass_device_data_clear(PicopassDeviceData* dev_data) {
422429
memset(dev_data->card_data[i].data, 0, sizeof(dev_data->card_data[i].data));
423430
dev_data->card_data[i].valid = false;
424431
}
425-
426432
memset(dev_data->pacs.credential, 0, sizeof(dev_data->pacs.credential));
433+
dev_data->auth = PicopassDeviceAuthMethodUnset;
427434
dev_data->pacs.legacy = false;
428435
dev_data->pacs.se_enabled = false;
429436
dev_data->pacs.elite_kdf = false;

picopass_device.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ typedef enum {
7474
PicopassDeviceSaveFormatPartial,
7575
} PicopassDeviceSaveFormat;
7676

77+
typedef enum {
78+
PicopassDeviceAuthMethodUnset,
79+
PicopassDeviceAuthMethodNone, // unsecured picopass
80+
PicopassDeviceAuthMethodKey,
81+
PicopassDeviceAuthMethodNrMac,
82+
PicopassDeviceAuthMethodFailed,
83+
} PicopassDeviceAuthMethod;
84+
7785
typedef enum {
7886
PicopassEmulatorStateHalt,
7987
PicopassEmulatorStateIdle,
@@ -105,6 +113,7 @@ typedef struct {
105113
typedef struct {
106114
PicopassBlock card_data[PICOPASS_MAX_APP_LIMIT];
107115
PicopassPacs pacs;
116+
PicopassDeviceAuthMethod auth;
108117
} PicopassDeviceData;
109118

110119
typedef struct {

protocol/picopass_poller.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ NfcCommand picopass_poller_check_security(PicopassPoller* instance) {
162162
case PICOPASS_FUSE_CRYPT0:
163163
FURI_LOG_D(TAG, "Non-secured page, skipping auth");
164164
instance->secured = false;
165+
instance->data->auth = PicopassDeviceAuthMethodNone;
165166
picopass_poller_prepare_read(instance);
166167
instance->state = PicopassPollerStateReadBlock;
167168
return command;
@@ -193,6 +194,8 @@ NfcCommand picopass_poller_check_security(PicopassPoller* instance) {
193194
FURI_LOG_D(TAG, "SE enabled");
194195
}
195196

197+
// Assume failure since we must auth, correct value will be set on success
198+
instance->data->auth = PicopassDeviceAuthMethodFailed;
196199
if(instance->mode == PicopassPollerModeRead) {
197200
// Always try the NR-MAC auth in case we have the file.
198201
instance->state = PicopassPollerStateNrMacAuth;
@@ -295,6 +298,7 @@ NfcCommand picopass_poller_nr_mac_auth(PicopassPoller* instance) {
295298
PicopassCheckResp check_resp = {};
296299
error = picopass_poller_check(instance, nr_mac, &mac, &check_resp);
297300
if(error == PicopassErrorNone) {
301+
instance->data->auth = PicopassDeviceAuthMethodNrMac;
298302
memcpy(instance->mac.data, mac.data, sizeof(PicopassMac));
299303
if(instance->mode == PicopassPollerModeRead) {
300304
picopass_poller_prepare_read(instance);
@@ -383,6 +387,7 @@ NfcCommand picopass_poller_auth_handler(PicopassPoller* instance) {
383387
error = picopass_poller_check(instance, NULL, &mac, &check_resp);
384388
if(error == PicopassErrorNone) {
385389
FURI_LOG_I(TAG, "Found key");
390+
instance->data->auth = PicopassDeviceAuthMethodKey;
386391
memcpy(instance->mac.data, mac.data, sizeof(PicopassMac));
387392
if(instance->mode == PicopassPollerModeRead) {
388393
memcpy(

scenes/picopass_scene_read_card_success.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <dolphin/dolphin.h>
33
#include <picopass_keys.h>
44

5+
#define TAG "PicopassSceneReadCardSuccess"
6+
57
void picopass_scene_read_card_success_widget_callback(
68
GuiButtonType result,
79
InputType type,
@@ -27,6 +29,28 @@ void picopass_scene_read_card_success_on_enter(void* context) {
2729
// Send notification
2830
notification_message(picopass->notifications, &sequence_success);
2931

32+
// For initial testing, print auth method
33+
switch(picopass->dev->dev_data.auth) {
34+
case PicopassDeviceAuthMethodUnset:
35+
FURI_LOG_D(TAG, "Auth: Unset");
36+
break;
37+
case PicopassDeviceAuthMethodNone:
38+
FURI_LOG_D(TAG, "Auth: None");
39+
break;
40+
case PicopassDeviceAuthMethodKey:
41+
FURI_LOG_D(TAG, "Auth: Key");
42+
break;
43+
case PicopassDeviceAuthMethodNrMac:
44+
FURI_LOG_D(TAG, "Auth: NR-MAC");
45+
break;
46+
case PicopassDeviceAuthMethodFailed:
47+
FURI_LOG_D(TAG, "Auth: Failed");
48+
break;
49+
default:
50+
FURI_LOG_D(TAG, "Auth: Unknown");
51+
break;
52+
};
53+
3054
// Setup view
3155
PicopassBlock* card_data = picopass->dev->dev_data.card_data;
3256
PicopassPacs* pacs = &picopass->dev->dev_data.pacs;

0 commit comments

Comments
 (0)