-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mifare Ultralight authentication (#1365)
* mifare ultralight auth prototype * it works! * Reference source * use countof * rework everything * oops forgot scenes * build: revert changes in manifest, stack size * build: fix buid, format sources * nfc: update unlock ultralight GUI * nfc: fix byte input header * nfc: add new scenes for locked ultralight * nfc: add data read to ultralights * nfc: add unlock option in mf ultralight menu * nfc: add data read init in ultralight generation * nfc: lin sources, fix unlocked save * nfc: format python sources * nfc: clean up Co-authored-by: gornekich <[email protected]>
- Loading branch information
Showing
22 changed files
with
717 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
applications/nfc/scenes/nfc_scene_mf_ultralight_key_input.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "../nfc_i.h" | ||
|
||
void nfc_scene_mf_ultralight_key_input_byte_input_callback(void* context) { | ||
Nfc* nfc = context; | ||
|
||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventByteInputDone); | ||
} | ||
|
||
void nfc_scene_mf_ultralight_key_input_on_enter(void* context) { | ||
Nfc* nfc = context; | ||
|
||
// Setup view | ||
ByteInput* byte_input = nfc->byte_input; | ||
byte_input_set_header_text(byte_input, "Enter the password in hex"); | ||
byte_input_set_result_callback( | ||
byte_input, | ||
nfc_scene_mf_ultralight_key_input_byte_input_callback, | ||
NULL, | ||
nfc, | ||
nfc->byte_input_store, | ||
4); | ||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewByteInput); | ||
} | ||
|
||
bool nfc_scene_mf_ultralight_key_input_on_event(void* context, SceneManagerEvent event) { | ||
Nfc* nfc = context; | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if(event.event == NfcCustomEventByteInputDone) { | ||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightUnlockWarn); | ||
consumed = true; | ||
} | ||
} | ||
return consumed; | ||
} | ||
|
||
void nfc_scene_mf_ultralight_key_input_on_exit(void* context) { | ||
Nfc* nfc = context; | ||
|
||
// Clear view | ||
byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0); | ||
byte_input_set_header_text(nfc->byte_input, ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
applications/nfc/scenes/nfc_scene_mf_ultralight_read_auth.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include "../nfc_i.h" | ||
#include <dolphin/dolphin.h> | ||
|
||
typedef enum { | ||
NfcSceneMfUlReadStateIdle, | ||
NfcSceneMfUlReadStateDetecting, | ||
NfcSceneMfUlReadStateReading, | ||
NfcSceneMfUlReadStateNotSupportedCard, | ||
} NfcSceneMfUlReadState; | ||
|
||
bool nfc_scene_mf_ultralight_read_auth_worker_callback(NfcWorkerEvent event, void* context) { | ||
Nfc* nfc = context; | ||
|
||
if(event == NfcWorkerEventMfUltralightPassKey) { | ||
memcpy(nfc->dev->dev_data.mf_ul_data.auth_key, nfc->byte_input_store, 4); | ||
} else { | ||
view_dispatcher_send_custom_event(nfc->view_dispatcher, event); | ||
} | ||
return true; | ||
} | ||
|
||
void nfc_scene_mf_ultralight_read_auth_set_state(Nfc* nfc, NfcSceneMfUlReadState state) { | ||
uint32_t curr_state = | ||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightReadAuth); | ||
if(curr_state != state) { | ||
if(state == NfcSceneMfUlReadStateDetecting) { | ||
popup_reset(nfc->popup); | ||
popup_set_text( | ||
nfc->popup, "Apply card to\nFlipper's back", 97, 24, AlignCenter, AlignTop); | ||
popup_set_icon(nfc->popup, 0, 8, &I_NFC_manual); | ||
} else if(state == NfcSceneMfUlReadStateReading) { | ||
popup_reset(nfc->popup); | ||
popup_set_header( | ||
nfc->popup, "Reading card\nDon't move...", 85, 24, AlignCenter, AlignTop); | ||
popup_set_icon(nfc->popup, 12, 23, &A_Loading_24); | ||
} else if(state == NfcSceneMfUlReadStateNotSupportedCard) { | ||
popup_reset(nfc->popup); | ||
popup_set_header(nfc->popup, "Wrong type of card!", 64, 3, AlignCenter, AlignTop); | ||
popup_set_text( | ||
nfc->popup, | ||
"Only MIFARE\nUltralight & NTAG\n are supported", | ||
4, | ||
22, | ||
AlignLeft, | ||
AlignTop); | ||
popup_set_icon(nfc->popup, 73, 17, &I_DolphinFirstStart8_56x51); | ||
} | ||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightReadAuth, state); | ||
} | ||
} | ||
|
||
void nfc_scene_mf_ultralight_read_auth_on_enter(void* context) { | ||
Nfc* nfc = context; | ||
DOLPHIN_DEED(DolphinDeedNfcRead); | ||
|
||
nfc_device_clear(nfc->dev); | ||
// Setup view | ||
nfc_scene_mf_ultralight_read_auth_set_state(nfc, NfcSceneMfUlReadStateDetecting); | ||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); | ||
// Start worker | ||
nfc_worker_start( | ||
nfc->worker, | ||
NfcWorkerStateReadMfUltralightReadAuth, | ||
&nfc->dev->dev_data, | ||
nfc_scene_mf_ultralight_read_auth_worker_callback, | ||
nfc); | ||
|
||
nfc_blink_start(nfc); | ||
} | ||
|
||
bool nfc_scene_mf_ultralight_read_auth_on_event(void* context, SceneManagerEvent event) { | ||
Nfc* nfc = context; | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if((event.event == NfcWorkerEventSuccess) || (event.event == NfcWorkerEventFail)) { | ||
notification_message(nfc->notifications, &sequence_success); | ||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightReadAuthResult); | ||
consumed = true; | ||
} else if(event.event == NfcWorkerEventCardDetected) { | ||
nfc_scene_mf_ultralight_read_auth_set_state(nfc, NfcSceneMfUlReadStateReading); | ||
consumed = true; | ||
} else if(event.event == NfcWorkerEventNoCardDetected) { | ||
nfc_scene_mf_ultralight_read_auth_set_state(nfc, NfcSceneMfUlReadStateDetecting); | ||
consumed = true; | ||
} else if(event.event == NfcWorkerEventWrongCardDetected) { | ||
nfc_scene_mf_ultralight_read_auth_set_state( | ||
nfc, NfcSceneMfUlReadStateNotSupportedCard); | ||
} | ||
} else if(event.type == SceneManagerEventTypeBack) { | ||
consumed = scene_manager_search_and_switch_to_previous_scene( | ||
nfc->scene_manager, NfcSceneMfUltralightUnlockMenu); | ||
} | ||
return consumed; | ||
} | ||
|
||
void nfc_scene_mf_ultralight_read_auth_on_exit(void* context) { | ||
Nfc* nfc = context; | ||
|
||
// Stop worker | ||
nfc_worker_stop(nfc->worker); | ||
// Clear view | ||
popup_reset(nfc->popup); | ||
nfc_blink_stop(nfc); | ||
scene_manager_set_scene_state( | ||
nfc->scene_manager, NfcSceneMfUltralightReadAuth, NfcSceneMfUlReadStateIdle); | ||
} |
98 changes: 98 additions & 0 deletions
98
applications/nfc/scenes/nfc_scene_mf_ultralight_read_auth_result.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "../nfc_i.h" | ||
#include <dolphin/dolphin.h> | ||
|
||
void nfc_scene_mf_ultralight_read_auth_result_widget_callback( | ||
GuiButtonType result, | ||
InputType type, | ||
void* context) { | ||
Nfc* nfc = context; | ||
|
||
if(type == InputTypeShort) { | ||
view_dispatcher_send_custom_event(nfc->view_dispatcher, result); | ||
} | ||
} | ||
|
||
void nfc_scene_mf_ultralight_read_auth_result_on_enter(void* context) { | ||
Nfc* nfc = context; | ||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess); | ||
|
||
// Setup dialog view | ||
FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data; | ||
MfUltralightData* mf_ul_data = &nfc->dev->dev_data.mf_ul_data; | ||
MfUltralightConfigPages* config_pages = mf_ultralight_get_config_pages(mf_ul_data); | ||
Widget* widget = nfc->widget; | ||
string_t temp_str; | ||
string_init(temp_str); | ||
|
||
if((mf_ul_data->data_read == mf_ul_data->data_size) && (mf_ul_data->data_read > 0)) { | ||
widget_add_string_element( | ||
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "All pages are unlocked!"); | ||
} else { | ||
widget_add_string_element( | ||
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Not all pages unlocked!"); | ||
} | ||
string_set_str(temp_str, "UID:"); | ||
for(size_t i = 0; i < nfc_data->uid_len; i++) { | ||
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]); | ||
} | ||
widget_add_string_element( | ||
widget, 0, 17, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str)); | ||
if(mf_ul_data->auth_success) { | ||
string_printf( | ||
temp_str, | ||
"Password: %02X %02X %02X %02X", | ||
config_pages->auth_data.pwd.raw[0], | ||
config_pages->auth_data.pwd.raw[1], | ||
config_pages->auth_data.pwd.raw[2], | ||
config_pages->auth_data.pwd.raw[3]); | ||
widget_add_string_element( | ||
widget, 0, 28, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str)); | ||
string_printf( | ||
temp_str, | ||
"PACK: %02X %02X", | ||
config_pages->auth_data.pack.raw[0], | ||
config_pages->auth_data.pack.raw[1]); | ||
widget_add_string_element( | ||
widget, 0, 39, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str)); | ||
} | ||
string_printf( | ||
temp_str, "Pages Read: %d/%d", mf_ul_data->data_read / 4, mf_ul_data->data_size / 4); | ||
widget_add_string_element( | ||
widget, 0, 50, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str)); | ||
widget_add_button_element( | ||
widget, | ||
GuiButtonTypeRight, | ||
"Save", | ||
nfc_scene_mf_ultralight_read_auth_result_widget_callback, | ||
nfc); | ||
|
||
string_clear(temp_str); | ||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); | ||
} | ||
|
||
bool nfc_scene_mf_ultralight_read_auth_result_on_event(void* context, SceneManagerEvent event) { | ||
Nfc* nfc = context; | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if(event.event == GuiButtonTypeRight) { | ||
nfc->dev->format = NfcDeviceSaveFormatMifareUl; | ||
// Clear device name | ||
nfc_device_set_name(nfc->dev, ""); | ||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName); | ||
consumed = true; | ||
} | ||
} else if(event.type == SceneManagerEventTypeBack) { | ||
consumed = scene_manager_search_and_switch_to_previous_scene( | ||
nfc->scene_manager, NfcSceneMfUltralightUnlockMenu); | ||
} | ||
|
||
return consumed; | ||
} | ||
|
||
void nfc_scene_mf_ultralight_read_auth_result_on_exit(void* context) { | ||
Nfc* nfc = context; | ||
|
||
// Clean views | ||
widget_reset(nfc->widget); | ||
} |
Oops, something went wrong.