MRTD show auth method used

This commit is contained in:
Chris van Marle
2022-10-26 13:04:53 +02:00
parent c3d7417c25
commit 46878d1526
5 changed files with 23 additions and 53 deletions

View File

@@ -3,13 +3,7 @@
#define TAG "PassportAuth" #define TAG "PassportAuth"
#define MRTD_AUTH_METHOD_COUNT 4 #define MRTD_AUTH_METHOD_COUNT 4
// Indexes must match MrtdAuthMethod (lib/nfc/protocols/mrtd_helpers.h) // Must match MrtdAuthMethod size (lib/nfc/protocols/mrtd_helpers.h)
const char* const mrtd_auth_method_text[MRTD_AUTH_METHOD_COUNT] = {
"None",
"Any",
"BAC",
"PACE",
};
typedef enum { typedef enum {
NfcScenePassportAuthSelectDob, NfcScenePassportAuthSelectDob,
@@ -28,7 +22,7 @@ void nfc_scene_passport_auth_method_changed(VariableItem* item) {
Nfc* nfc = variable_item_get_context(item); Nfc* nfc = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
nfc->dev->dev_data.mrtd_data.auth.method = index; 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) { 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; value_index = *auth_method;
variable_item_set_current_value_index(item, value_index); 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); variable_item_list_add(variable_item_list, "Authenticate and read", 1, NULL, NULL);

View File

@@ -34,7 +34,7 @@ void nfc_scene_passport_read_auth_on_enter(void* context) {
FuriString* temp_str; FuriString* temp_str;
temp_str = furi_string_alloc(); temp_str = furi_string_alloc();
furi_string_set(temp_str, "\e#Passport\n"); 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 // TODO: indicate BAC / PACE used
uint16_t lds_version = mrtd_data->files.EF_COM.lds_version; uint16_t lds_version = mrtd_data->files.EF_COM.lds_version;

View File

@@ -532,12 +532,14 @@ bool mrtd_bac(MrtdApplication* app, MrtdAuthData* auth) {
bool mrtd_authenticate(MrtdApplication* app, MrtdData* mrtd_data) { bool mrtd_authenticate(MrtdApplication* app, MrtdData* mrtd_data) {
MrtdAuthMethod method = mrtd_data->auth.method; MrtdAuthMethod method = mrtd_data->auth.method;
mrtd_data->auth_success = false; mrtd_data->auth_success = false;
mrtd_data->auth_method_used = MrtdAuthMethodNone;
FURI_LOG_D(TAG, "Auth method: %d", method); FURI_LOG_D(TAG, "Auth method: %d", method);
switch(method) { switch(method) {
case MrtdAuthMethodAny: case MrtdAuthMethodAny:
//TODO: try PACE, then BAC. For now, fall through to just BAC //TODO: try PACE, then BAC. For now, fall through to just BAC
case MrtdAuthMethodBac: case MrtdAuthMethodBac:
mrtd_data->auth_success = mrtd_bac(app, &mrtd_data->auth); mrtd_data->auth_success = mrtd_bac(app, &mrtd_data->auth);
mrtd_data->auth_method_used = MrtdAuthMethodBac;
break; break;
case MrtdAuthMethodPace: case MrtdAuthMethodPace:
FURI_LOG_E(TAG, "Auth method PACE not implemented"); FURI_LOG_E(TAG, "Auth method PACE not implemented");
@@ -553,45 +555,3 @@ bool mrtd_authenticate(MrtdApplication* app, MrtdData* mrtd_data) {
return true; 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);
}

View File

@@ -16,7 +16,8 @@ typedef struct {
typedef struct { typedef struct {
MrtdAuthData auth; MrtdAuthData auth;
bool auth_success; //TODO: register (and display) method used BAC/PACE bool auth_success;
MrtdAuthMethod auth_method_used;
struct { struct {
EF_DIR_contents EF_DIR; EF_DIR_contents EF_DIR;

View File

@@ -25,6 +25,21 @@ typedef enum {
MrtdAuthMethodPace, MrtdAuthMethodPace,
} MrtdAuthMethod; } 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 { typedef enum {
MrtdTypeUnknown, MrtdTypeUnknown,
MrtdTypeTD1, MrtdTypeTD1,