diff --git a/.gitignore b/.gitignore index 38a31bf01..e5633531c 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ openocd.log # PVS Studio temporary files .PVS-Studio/ PVS-Studio.log + +#TODO: remove +applications/main/nfc/test_bac_creds.h diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index 76ce419c0..cb28a07f9 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -39,6 +39,7 @@ ADD_SCENE(nfc, mf_classic_dict_attack, MfClassicDictAttack) ADD_SCENE(nfc, emv_read_success, EmvReadSuccess) ADD_SCENE(nfc, emv_menu, EmvMenu) ADD_SCENE(nfc, passport_read, PassportReadSuccess) +ADD_SCENE(nfc, passport_read_auth, PassportReadAuthSuccess) ADD_SCENE(nfc, passport_menu, PassportMenu) ADD_SCENE(nfc, passport_auth, PassportAuth) ADD_SCENE(nfc, passport_date, PassportDate) diff --git a/applications/main/nfc/scenes/nfc_scene_passport_auth.c b/applications/main/nfc/scenes/nfc_scene_passport_auth.c index 6e7fd7525..05afad97d 100644 --- a/applications/main/nfc/scenes/nfc_scene_passport_auth.c +++ b/applications/main/nfc/scenes/nfc_scene_passport_auth.c @@ -1,5 +1,7 @@ #include "../nfc_i.h" +#include "../test_bac_creds.h" //TODO: remove + #define TAG "PassportAuth" #define MRTD_AUTH_METHOD_COUNT 4 @@ -33,11 +35,18 @@ void nfc_scene_passport_auth_method_changed(VariableItem* item) { void nfc_scene_passport_auth_on_enter(void* context) { Nfc* nfc = context; + MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data; // By entering the Auth menu, we default to Auth: Any - MrtdAuthMethod* auth_method = &nfc->dev->dev_data.mrtd_data.auth.method; + MrtdAuthMethod* auth_method = &mrtd_data->auth.method; if(*auth_method == MrtdAuthMethodNone) { *auth_method = MrtdAuthMethodAny; + + //TODO: remove testing credentials: + mrtd_data->auth.birth_date = TODO_REMOVE_ID_DOB; + mrtd_data->auth.expiry_date = TODO_REMOVE_ID_DOE; + memcpy(mrtd_data->auth.doc_number, TODO_REMOVE_ID_DOC, 9); + //TODO: remove testing credentials ^^ } VariableItemList* variable_item_list = nfc->variable_item_list; @@ -48,24 +57,24 @@ void nfc_scene_passport_auth_on_enter(void* context) { const size_t temp_str_size = 15; char temp_str[temp_str_size]; snprintf(temp_str, temp_str_size, "%02u%02u%02u", - nfc->dev->dev_data.mrtd_data.auth.birth_date.year, - nfc->dev->dev_data.mrtd_data.auth.birth_date.month, - nfc->dev->dev_data.mrtd_data.auth.birth_date.day); + mrtd_data->auth.birth_date.year, + mrtd_data->auth.birth_date.month, + mrtd_data->auth.birth_date.day); item = variable_item_list_add(variable_item_list, "Birth Date", 1, NULL, NULL); variable_item_set_current_value_text(item, temp_str); snprintf(temp_str, temp_str_size, "%02u%02u%02u", - nfc->dev->dev_data.mrtd_data.auth.expiry_date.year, - nfc->dev->dev_data.mrtd_data.auth.expiry_date.month, - nfc->dev->dev_data.mrtd_data.auth.expiry_date.day); + mrtd_data->auth.expiry_date.year, + mrtd_data->auth.expiry_date.month, + mrtd_data->auth.expiry_date.day); item = variable_item_list_add(variable_item_list, "Expiry Date", 1, NULL, NULL); variable_item_set_current_value_text(item, temp_str); item = variable_item_list_add(variable_item_list, "Document Nr.", 1, NULL, NULL); - strncpy(temp_str, nfc->dev->dev_data.mrtd_data.auth.doc_number, temp_str_size); + strncpy(temp_str, mrtd_data->auth.doc_number, temp_str_size); temp_str[temp_str_size] = '\x00'; if(strlen(temp_str) > 8) { temp_str[8] = '.'; diff --git a/applications/main/nfc/scenes/nfc_scene_passport_read.c b/applications/main/nfc/scenes/nfc_scene_passport_read.c index 55b9cae0b..441d34584 100644 --- a/applications/main/nfc/scenes/nfc_scene_passport_read.c +++ b/applications/main/nfc/scenes/nfc_scene_passport_read.c @@ -11,7 +11,6 @@ void nfc_scene_passport_read_widget_callback(GuiButtonType result, InputType typ void nfc_scene_passport_read_on_enter(void* context) { Nfc* nfc = context; FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data; - //MrtdBacDAta* bac_data = &nfc->dev->dev_data.mrtd_data.bac; DOLPHIN_DEED(DolphinDeedNfcReadSuccess); diff --git a/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c b/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c new file mode 100644 index 000000000..6bff4b00e --- /dev/null +++ b/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c @@ -0,0 +1,77 @@ +#include "../nfc_i.h" +#include + +void nfc_scene_passport_read_auth_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_passport_read_auth_on_enter(void* context) { + Nfc* nfc = context; + MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data; + + Widget* widget = nfc->widget; + + // Setup Custom Widget view + string_t temp_str; + string_init_printf(temp_str, "\e#Passport\n"); + string_cat_printf(temp_str, "Authenticated: %d", mrtd_data->auth_success); + // TODO: indicate BAC / PACE used + + /* + char iso_type = FURI_BIT(data->sak, 5) ? '4' : '3'; + //TODO: NFC-B? + string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type); + string_cat_printf(temp_str, "UID:"); + for(size_t i = 0; i < data->uid_len; i++) { + string_cat_printf(temp_str, " %02X", data->uid[i]); + } + string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]); + string_cat_printf(temp_str, " SAK: %02X", data->sak); + */ + + widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str)); + string_clear(temp_str); + + widget_add_button_element( + nfc->widget, GuiButtonTypeLeft, "Retry", nfc_scene_passport_read_auth_widget_callback, nfc); + /* + widget_add_button_element( + nfc->widget, GuiButtonTypeCenter, "Auth", nfc_scene_passport_read_auth_widget_callback, nfc); + widget_add_button_element( + nfc->widget, GuiButtonTypeRight, "More", nfc_scene_passport_read_auth_widget_callback, nfc); + */ + + view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); +} + +bool nfc_scene_passport_read_auth_on_event(void* context, SceneManagerEvent event) { + Nfc* nfc = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == GuiButtonTypeLeft) { + scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm); + consumed = true; + } else if(event.event == GuiButtonTypeCenter) { + //scene_manager_next_scene(nfc->scene_manager, NfcScenePassportAuth); + //consumed = true; + } else if(event.event == GuiButtonTypeRight) { + //scene_manager_next_scene(nfc->scene_manager, NfcScenePassportMenu); + //consumed = true; + } + } else if(event.type == SceneManagerEventTypeBack) { + scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm); + consumed = true; + } + return consumed; +} + +void nfc_scene_passport_read_auth_on_exit(void* context) { + Nfc* nfc = context; + + // Clear view + widget_reset(nfc->widget); +} diff --git a/applications/main/nfc/scenes/nfc_scene_read.c b/applications/main/nfc/scenes/nfc_scene_read.c index 48fef9ddc..6dd06e8f3 100644 --- a/applications/main/nfc/scenes/nfc_scene_read.c +++ b/applications/main/nfc/scenes/nfc_scene_read.c @@ -85,7 +85,13 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) { consumed = true; } else if(event.event == NfcWorkerEventReadPassport) { notification_message(nfc->notifications, &sequence_success); - scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadSuccess); + if(nfc->dev->dev_data.mrtd_data.auth_success) { + scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadAuthSuccess); + //TODO: } else if(nfc->dev->dev_data.mrtd_data.auth.method != MrtdAuthMethodNone) { + //scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadAuthFailed); + } else { + scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadSuccess); + } consumed = true; } else if(event.event == NfcWorkerEventReadMfClassicDictAttackRequired) { if(mf_classic_dict_check_presence(MfClassicDictTypeFlipper)) { diff --git a/lib/nfc/protocols/mrtd.c b/lib/nfc/protocols/mrtd.c index 712c829b8..323b0440c 100644 --- a/lib/nfc/protocols/mrtd.c +++ b/lib/nfc/protocols/mrtd.c @@ -279,12 +279,13 @@ void mrtd_test(MrtdApplication* app, MrtdData* mrtd_data) { */ MrtdAuthMethod method = mrtd_data->auth.method; + mrtd_data->auth_success = false; FURI_LOG_D(TAG, "Auth method: %d", method); switch(method) { case MrtdAuthMethodAny: //TODO: try PACE, then BAC case MrtdAuthMethodBac: - mrtd_bac(app, &mrtd_data->auth); + mrtd_data->auth_success = mrtd_bac(app, &mrtd_data->auth); break; case MrtdAuthMethodPace: FURI_LOG_E(TAG, "Auth method PACE not implemented"); diff --git a/lib/nfc/protocols/mrtd.h b/lib/nfc/protocols/mrtd.h index 81210c986..b44b26d99 100644 --- a/lib/nfc/protocols/mrtd.h +++ b/lib/nfc/protocols/mrtd.h @@ -36,6 +36,7 @@ typedef struct { typedef struct { MrtdAuthData auth; + bool auth_success; } MrtdData; typedef struct {