diff --git a/applications/u2f/scenes/u2f_scene_main.c b/applications/u2f/scenes/u2f_scene_main.c index 4ff5e6013..ede8e305f 100644 --- a/applications/u2f/scenes/u2f_scene_main.c +++ b/applications/u2f/scenes/u2f_scene_main.c @@ -28,6 +28,8 @@ static void u2f_scene_main_event_callback(U2fNotifyEvent evt, void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventConnect); else if(evt == U2fNotifyDisconnect) view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDisconnect); + else if(evt == U2fNotifyError) + view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDataError); } static void u2f_scene_main_timer_callback(void* context) { @@ -75,10 +77,13 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { if(app->event_cur != U2fCustomEventNone) { u2f_confirm_user_present(app->u2f_instance); } + } else if(event.event == U2fCustomEventDataError) { + osTimerStop(app->timer); + u2f_view_set_state(app->u2f_view, U2fMsgError); } consumed = true; - } else if(event.type == SceneManagerEventTypeTick) { } + return consumed; } diff --git a/applications/u2f/u2f.c b/applications/u2f/u2f.c index 4f952e680..2a1286ef4 100644 --- a/applications/u2f/u2f.c +++ b/applications/u2f/u2f.c @@ -186,6 +186,13 @@ static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { uint8_t hash[32]; uint8_t signature[64]; + if(u2f_data_check(false) == false) { + U2F->ready = false; + if(U2F->callback != NULL) U2F->callback(U2fNotifyError, U2F->context); + memcpy(&buf[0], state_not_supported, 2); + return 2; + } + if(U2F->callback != NULL) U2F->callback(U2fNotifyRegister, U2F->context); if(U2F->user_present == false) { memcpy(&buf[0], state_user_missing, 2); @@ -250,6 +257,13 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { uint8_t hash[32]; uint8_t signature[64]; + if(u2f_data_check(false) == false) { + U2F->ready = false; + if(U2F->callback != NULL) U2F->callback(U2fNotifyError, U2F->context); + memcpy(&buf[0], state_not_supported, 2); + return 2; + } + if(U2F->callback != NULL) U2F->callback(U2fNotifyAuth, U2F->context); if(U2F->user_present == true) { flags |= 1; diff --git a/applications/u2f/u2f.h b/applications/u2f/u2f.h index 4e10a3ea7..dcd7c3ff2 100644 --- a/applications/u2f/u2f.h +++ b/applications/u2f/u2f.h @@ -13,6 +13,7 @@ typedef enum { U2fNotifyWink, U2fNotifyConnect, U2fNotifyDisconnect, + U2fNotifyError, } U2fNotifyEvent; typedef struct U2fData U2fData; diff --git a/applications/u2f/u2f_app.c b/applications/u2f/u2f_app.c index f2e557304..9dde0f0db 100644 --- a/applications/u2f/u2f_app.c +++ b/applications/u2f/u2f_app.c @@ -48,7 +48,7 @@ U2fApp* u2f_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, U2fAppViewMain, u2f_view_get_view(app->u2f_view)); - if(u2f_data_check()) { + if(u2f_data_check(true)) { scene_manager_next_scene(app->scene_manager, U2fSceneMain); } else { scene_manager_next_scene(app->scene_manager, U2fSceneError); diff --git a/applications/u2f/u2f_app_i.h b/applications/u2f/u2f_app_i.h index 33092ba3c..41048b317 100644 --- a/applications/u2f/u2f_app_i.h +++ b/applications/u2f/u2f_app_i.h @@ -20,6 +20,7 @@ typedef enum { U2fCustomEventConnect, U2fCustomEventDisconnect, + U2fCustomEventDataError, U2fCustomEventRegister, U2fCustomEventAuth, diff --git a/applications/u2f/u2f_data.c b/applications/u2f/u2f_data.c index f517d2226..e39eb95ce 100644 --- a/applications/u2f/u2f_data.c +++ b/applications/u2f/u2f_data.c @@ -38,17 +38,25 @@ typedef struct { uint32_t control; } __attribute__((packed)) U2fCounterData; -bool u2f_data_check() { +bool u2f_data_check(bool cert_only) { bool state = false; Storage* fs_api = furi_record_open("storage"); File* file = storage_file_alloc(fs_api); - if(storage_file_open(file, U2F_CERT_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) { + do { + if(!storage_file_open(file, U2F_CERT_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) break; storage_file_close(file); - if(storage_file_open(file, U2F_CERT_KEY_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) { + if(!storage_file_open(file, U2F_CERT_KEY_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) break; + if(cert_only) { state = true; + break; } - } + storage_file_close(file); + if(!storage_file_open(file, U2F_KEY_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) break; + storage_file_close(file); + if(!storage_file_open(file, U2F_CNT_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) break; + state = true; + } while(0); storage_file_close(file); storage_file_free(file); diff --git a/applications/u2f/u2f_data.h b/applications/u2f/u2f_data.h index a96704eb2..8d3923464 100644 --- a/applications/u2f/u2f_data.h +++ b/applications/u2f/u2f_data.h @@ -6,7 +6,7 @@ extern "C" { #include -bool u2f_data_check(); +bool u2f_data_check(bool cert_only); bool u2f_data_cert_check();