u2f: check files before register/login (#980)
This commit is contained in:
parent
8cfd0eab9e
commit
40479e1761
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -13,6 +13,7 @@ typedef enum {
|
||||
U2fNotifyWink,
|
||||
U2fNotifyConnect,
|
||||
U2fNotifyDisconnect,
|
||||
U2fNotifyError,
|
||||
} U2fNotifyEvent;
|
||||
|
||||
typedef struct U2fData U2fData;
|
||||
|
@ -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);
|
||||
|
@ -20,6 +20,7 @@ typedef enum {
|
||||
|
||||
U2fCustomEventConnect,
|
||||
U2fCustomEventDisconnect,
|
||||
U2fCustomEventDataError,
|
||||
|
||||
U2fCustomEventRegister,
|
||||
U2fCustomEventAuth,
|
||||
|
@ -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);
|
||||
|
@ -6,7 +6,7 @@ extern "C" {
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
bool u2f_data_check();
|
||||
bool u2f_data_check(bool cert_only);
|
||||
|
||||
bool u2f_data_cert_check();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user