diff --git a/applications/main/nfc/scenes/nfc_scene_passport_auth.c b/applications/main/nfc/scenes/nfc_scene_passport_auth.c index fe4bd056b..1af80cd62 100644 --- a/applications/main/nfc/scenes/nfc_scene_passport_auth.c +++ b/applications/main/nfc/scenes/nfc_scene_passport_auth.c @@ -3,13 +3,7 @@ #define TAG "PassportAuth" #define MRTD_AUTH_METHOD_COUNT 4 -// Indexes must match MrtdAuthMethod (lib/nfc/protocols/mrtd_helpers.h) -const char* const mrtd_auth_method_text[MRTD_AUTH_METHOD_COUNT] = { - "None", - "Any", - "BAC", - "PACE", -}; +// Must match MrtdAuthMethod size (lib/nfc/protocols/mrtd_helpers.h) typedef enum { NfcScenePassportAuthSelectDob, @@ -28,7 +22,7 @@ void nfc_scene_passport_auth_method_changed(VariableItem* item) { Nfc* nfc = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); nfc->dev->dev_data.mrtd_data.auth.method = index; - variable_item_set_current_value_text(item, mrtd_auth_method_text[index]); + variable_item_set_current_value_text(item, mrtd_auth_method_string(index)); } void nfc_scene_passport_auth_on_enter(void* context) { @@ -87,7 +81,7 @@ void nfc_scene_passport_auth_on_enter(void* context) { value_index = *auth_method; variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, mrtd_auth_method_text[value_index]); + variable_item_set_current_value_text(item, mrtd_auth_method_string(value_index)); variable_item_list_add(variable_item_list, "Authenticate and read", 1, NULL, NULL); diff --git a/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c b/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c index 0f0f82684..cc5c294d4 100644 --- a/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c +++ b/applications/main/nfc/scenes/nfc_scene_passport_read_auth.c @@ -34,7 +34,7 @@ void nfc_scene_passport_read_auth_on_enter(void* context) { FuriString* temp_str; temp_str = furi_string_alloc(); furi_string_set(temp_str, "\e#Passport\n"); - furi_string_cat_printf(temp_str, "Authenticated: %d\n", mrtd_data->auth_success); + furi_string_cat_printf(temp_str, "Auth.method: %s\n", mrtd_auth_method_string(mrtd_data->auth_method_used)); // TODO: indicate BAC / PACE used uint16_t lds_version = mrtd_data->files.EF_COM.lds_version; diff --git a/lib/nfc/protocols/mrtd.c b/lib/nfc/protocols/mrtd.c index ce4fa9177..102dd4a12 100644 --- a/lib/nfc/protocols/mrtd.c +++ b/lib/nfc/protocols/mrtd.c @@ -532,12 +532,14 @@ bool mrtd_bac(MrtdApplication* app, MrtdAuthData* auth) { bool mrtd_authenticate(MrtdApplication* app, MrtdData* mrtd_data) { MrtdAuthMethod method = mrtd_data->auth.method; mrtd_data->auth_success = false; + mrtd_data->auth_method_used = MrtdAuthMethodNone; FURI_LOG_D(TAG, "Auth method: %d", method); switch(method) { case MrtdAuthMethodAny: //TODO: try PACE, then BAC. For now, fall through to just BAC case MrtdAuthMethodBac: mrtd_data->auth_success = mrtd_bac(app, &mrtd_data->auth); + mrtd_data->auth_method_used = MrtdAuthMethodBac; break; case MrtdAuthMethodPace: FURI_LOG_E(TAG, "Auth method PACE not implemented"); @@ -553,45 +555,3 @@ bool mrtd_authenticate(MrtdApplication* app, MrtdData* mrtd_data) { return true; } - -//TODO: remove testing function -void mrtd_test(MrtdApplication* app, MrtdData* mrtd_data) { - FURI_LOG_D(TAG, "Mrtd Test"); - //mrtd_read_dump(app, EF.ATR); - //mrtd_read_dump(app, EF.COM); - //mrtd_read_dump(app, EF.DIR); - //mrtd_read_dump(app, EF.CardAccess); - //mrtd_read_dump(app, EF.CardSecurity); - - mrtd_select_app(app, AID.eMRTDApplication); - - 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_data->auth_success = mrtd_bac(app, &mrtd_data->auth); - break; - case MrtdAuthMethodPace: - FURI_LOG_E(TAG, "Auth method PACE not implemented"); - break; - case MrtdAuthMethodNone: - default: - break; - } - - if(!mrtd_data->auth_success) { - return; - } - - mrtd_read_parse_file(app, mrtd_data, EF.COM); - //mrtd_read_parse_file(app, mrtd_data, EF.DIR); - - mrtd_read_parse_file(app, mrtd_data, EF.DG1); - - //mrtd_read_dump(app, EF.DG2); - //mrtd_read_dump(app, EF.DG14); - //mrtd_read_dump(app, EF.DG15); -} diff --git a/lib/nfc/protocols/mrtd.h b/lib/nfc/protocols/mrtd.h index e4d032f88..57825994c 100644 --- a/lib/nfc/protocols/mrtd.h +++ b/lib/nfc/protocols/mrtd.h @@ -16,7 +16,8 @@ typedef struct { typedef struct { MrtdAuthData auth; - bool auth_success; //TODO: register (and display) method used BAC/PACE + bool auth_success; + MrtdAuthMethod auth_method_used; struct { EF_DIR_contents EF_DIR; diff --git a/lib/nfc/protocols/mrtd_helpers.h b/lib/nfc/protocols/mrtd_helpers.h index 83197d95e..d3310b0eb 100644 --- a/lib/nfc/protocols/mrtd_helpers.h +++ b/lib/nfc/protocols/mrtd_helpers.h @@ -25,6 +25,21 @@ typedef enum { MrtdAuthMethodPace, } MrtdAuthMethod; +inline const char* mrtd_auth_method_string(MrtdAuthMethod method) { + switch(method) { + case MrtdAuthMethodBac: + return "BAC"; + case MrtdAuthMethodPace: + return "PACE"; + case MrtdAuthMethodNone: + return "None"; + case MrtdAuthMethodAny: + return "Any"; + default: + return "Unknown"; + } +} + typedef enum { MrtdTypeUnknown, MrtdTypeTD1,