mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 09:58:37 -07:00
Merge branch 'pr/401' into 420
This commit is contained in:
@@ -49,6 +49,7 @@ 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_auth_save_name, PassportAuthSaveName)
|
||||
ADD_SCENE(nfc, passport_date, PassportDate)
|
||||
ADD_SCENE(nfc, passport_docnr, PassportDocNr)
|
||||
ADD_SCENE(nfc, passport_pace_todo, PassportPaceTodo)
|
||||
|
||||
@@ -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,
|
||||
@@ -17,6 +11,8 @@ typedef enum {
|
||||
NfcScenePassportAuthSelectDocNr,
|
||||
NfcScenePassportAuthSelectMethod,
|
||||
NfcScenePassportAuthSelectAuth,
|
||||
NfcScenePassportAuthSelectSave,
|
||||
NfcScenePassportAuthSelectLoad,
|
||||
} NfcScenePassportAuthSelect;
|
||||
|
||||
void nfc_scene_passport_auth_var_list_enter_callback(void* context, uint32_t index) {
|
||||
@@ -28,7 +24,42 @@ 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));
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_auth_load(Nfc* nfc) {
|
||||
const DialogsFileBrowserOptions browser_options = {
|
||||
.extension = MRTD_APP_EXTENSION,
|
||||
.skip_assets = true,
|
||||
.icon = &I_u2f_10px,
|
||||
.hide_ext = true,
|
||||
.item_loader_callback = NULL,
|
||||
.item_loader_context = NULL,
|
||||
};
|
||||
|
||||
FuriString* mrtd_app_folder;
|
||||
mrtd_app_folder = furi_string_alloc_set(MRTD_APP_FOLDER);
|
||||
|
||||
FuriString* file_path;
|
||||
file_path = furi_string_alloc();
|
||||
|
||||
bool res = dialog_file_browser_show(nfc->dev->dialogs, file_path, mrtd_app_folder, &browser_options);
|
||||
|
||||
furi_string_free(mrtd_app_folder);
|
||||
|
||||
if(res) {
|
||||
mrtd_auth_params_load(
|
||||
nfc->dev->storage,
|
||||
nfc->dev->dialogs,
|
||||
&nfc->dev->dev_data.mrtd_data.auth,
|
||||
furi_string_get_cstr(file_path),
|
||||
true);
|
||||
|
||||
nfc_scene_passport_auth_on_enter(nfc);
|
||||
variable_item_list_set_selected_item(nfc->variable_item_list, NfcScenePassportAuthSelectAuth);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
@@ -42,6 +73,7 @@ void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
}
|
||||
|
||||
VariableItemList* variable_item_list = nfc->variable_item_list;
|
||||
variable_item_list_reset(variable_item_list);
|
||||
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
@@ -91,10 +123,13 @@ 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);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Save parameters", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Load parameters", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, nfc_scene_passport_auth_var_list_enter_callback, nfc);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewVarItemList);
|
||||
@@ -107,6 +142,10 @@ bool nfc_scene_passport_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
FURI_LOG_D(TAG, "event.event: %ld", event.event);
|
||||
switch(event.event) {
|
||||
case NfcScenePassportAuthSelectLoad:
|
||||
nfc_scene_passport_auth_load(nfc);
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectDob:
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcScenePassportDate, 0);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDate);
|
||||
@@ -133,6 +172,10 @@ bool nfc_scene_passport_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectSave:
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportAuthSaveName);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include <gui/modules/validators.h>
|
||||
#include <toolbox/path.h>
|
||||
|
||||
void nfc_scene_passport_auth_save_name_text_input_callback(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventTextInputDone);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_save_name_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = nfc->text_input;
|
||||
bool docnr_empty = false;
|
||||
if(!strcmp(mrtd_data->auth.doc_number, "")) {
|
||||
set_random_name(nfc->text_store, sizeof(nfc->text_store));
|
||||
docnr_empty = true;
|
||||
} else {
|
||||
nfc_text_store_set(nfc, mrtd_data->auth.doc_number);
|
||||
}
|
||||
text_input_set_header_text(text_input, "Name the parameters");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
nfc_scene_passport_auth_save_name_text_input_callback,
|
||||
nfc,
|
||||
nfc->text_store,
|
||||
NFC_DEV_NAME_MAX_LEN,
|
||||
docnr_empty);
|
||||
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
if(furi_string_end_with(nfc->dev->load_path, NFC_APP_EXTENSION)) {
|
||||
path_extract_dirname(furi_string_get_cstr(nfc->dev->load_path), folder_path);
|
||||
} else {
|
||||
furi_string_set(folder_path, NFC_APP_FOLDER);
|
||||
}
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
furi_string_get_cstr(folder_path), NFC_APP_EXTENSION, NULL);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
|
||||
|
||||
furi_string_free(folder_path);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_auth_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventTextInputDone) {
|
||||
if(mrtd_auth_params_save(nfc->dev->storage, nfc->dev->dialogs, &mrtd_data->auth, nfc->text_store)) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcSceneStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_save_name_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
void* validator_context = text_input_get_validator_callback_context(nfc->text_input);
|
||||
text_input_set_validator(nfc->text_input, NULL, NULL);
|
||||
validator_is_file_free(validator_context);
|
||||
|
||||
text_input_reset(nfc->text_input);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ 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;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
|
||||
|
||||
@@ -40,7 +41,11 @@ void nfc_scene_passport_read_on_enter(void* context) {
|
||||
furi_string_cat_printf(temp_str, " %02X", data->uid[i]);
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]);
|
||||
furi_string_cat_printf(temp_str, " SAK: %02X", data->sak);
|
||||
furi_string_cat_printf(temp_str, " SAK: %02X\n", data->sak);
|
||||
|
||||
if(mrtd_data->auth.method != MrtdAuthMethodNone && !mrtd_data->auth_success) {
|
||||
furi_string_cat_printf(temp_str, "Auth failed. Wrong params?");
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
@@ -82,4 +87,4 @@ void nfc_scene_passport_read_on_exit(void* context) {
|
||||
|
||||
// Clear view
|
||||
widget_reset(nfc->widget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,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;
|
||||
@@ -115,6 +115,8 @@ bool nfc_scene_passport_read_auth_on_event(void* context, SceneManagerEvent even
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
nfc->dev->dev_data.mrtd_data.auth_success = false;
|
||||
nfc->dev->dev_data.mrtd_data.auth.method = MrtdAuthMethodNone;
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
|
||||
consumed = true;
|
||||
} else if(event.event == GuiButtonTypeCenter) {
|
||||
|
||||
@@ -92,10 +92,11 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventReadPassport) {
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
FURI_LOG_D("NFC", "Read passport, auth: %d, success: %d",
|
||||
nfc->dev->dev_data.mrtd_data.auth.method,
|
||||
nfc->dev->dev_data.mrtd_data.auth_success);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ bool nfc_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcSceneSavedMenu);
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcScenePassportAuth)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcScenePassportAuth);
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_another_scene(
|
||||
nfc->scene_manager, NfcSceneFileSelect);
|
||||
|
||||
Reference in New Issue
Block a user