Revert TOTP changes

"Preload failed, invalid file"
This commit is contained in:
MX
2022-11-03 00:41:17 +03:00
parent 5ac2431cd1
commit 677de32026
40 changed files with 640 additions and 789 deletions

View File

@@ -1,7 +1,7 @@
#include "totp_scene_authenticate.h"
#include <dialogs/dialogs.h>
#include <totp_icons.h>
#include "../../types/common.h"
#include "../../services/ui/icons.h"
#include "../../services/ui/constants.h"
#include "../../services/config/config.h"
#include "../scene_director.h"
@@ -9,10 +9,6 @@
#include "../../services/crypto/crypto.h"
#define MAX_CODE_LENGTH TOTP_IV_SIZE
#define ARROW_UP_CODE 2
#define ARROW_RIGHT_CODE 8
#define ARROW_DOWN_CODE 11
#define ARROW_LEFT_CODE 5
typedef struct {
uint8_t code_input[MAX_CODE_LENGTH];
@@ -32,7 +28,7 @@ void totp_scene_authenticate_activate(PluginState* plugin_state) {
}
void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_state) {
const SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
int v_shift = 0;
if(scene_state->code_length > 0) {
@@ -77,82 +73,80 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st
}
}
bool totp_scene_authenticate_handle_event(
const PluginEvent* const event,
PluginState* plugin_state) {
if(event->type != EventTypeKey) {
return true;
}
bool totp_scene_authenticate_handle_event(PluginEvent* const event, PluginState* plugin_state) {
if(event->type == EventTypeKey) {
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
return false;
} else if(event->input.type == InputTypePress) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
return false;
}
const uint8_t ARROW_UP_CODE = 2;
const uint8_t ARROW_RIGHT_CODE = 8;
const uint8_t ARROW_DOWN_CODE = 11;
const uint8_t ARROW_LEFT_CODE = 5;
if(event->input.type != InputTypePress) {
return true;
}
switch(event->input.key) {
case InputKeyUp:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_UP_CODE;
scene_state->code_length++;
}
break;
case InputKeyDown:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_DOWN_CODE;
scene_state->code_length++;
}
break;
case InputKeyRight:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_RIGHT_CODE;
scene_state->code_length++;
}
break;
case InputKeyLeft:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_LEFT_CODE;
scene_state->code_length++;
}
break;
case InputKeyOk:
totp_crypto_seed_iv(
plugin_state, &scene_state->code_input[0], scene_state->code_length);
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
if(totp_crypto_verify_key(plugin_state)) {
FURI_LOG_D(LOGGING_TAG, "PIN is valid");
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
} else {
FURI_LOG_D(LOGGING_TAG, "PIN is NOT valid");
memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH);
memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE);
scene_state->code_length = 0;
switch(event->input.key) {
case InputKeyUp:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_UP_CODE;
scene_state->code_length++;
DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "Try again", NULL, NULL);
dialog_message_set_header(
message,
"You entered\ninvalid PIN",
SCREEN_WIDTH_CENTER - 25,
SCREEN_HEIGHT_CENTER - 5,
AlignCenter,
AlignCenter);
dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17);
dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message);
}
break;
case InputKeyBack:
if(scene_state->code_length > 0) {
scene_state->code_input[scene_state->code_length - 1] = 0;
scene_state->code_length--;
}
break;
default:
break;
}
}
break;
case InputKeyDown:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_DOWN_CODE;
scene_state->code_length++;
}
break;
case InputKeyRight:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_RIGHT_CODE;
scene_state->code_length++;
}
break;
case InputKeyLeft:
if(scene_state->code_length < MAX_CODE_LENGTH) {
scene_state->code_input[scene_state->code_length] = ARROW_LEFT_CODE;
scene_state->code_length++;
}
break;
case InputKeyOk:
totp_crypto_seed_iv(plugin_state, &scene_state->code_input[0], scene_state->code_length);
if(totp_crypto_verify_key(plugin_state)) {
FURI_LOG_D(LOGGING_TAG, "PIN is valid");
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
} else {
FURI_LOG_D(LOGGING_TAG, "PIN is NOT valid");
memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH);
memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE);
scene_state->code_length = 0;
DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "Try again", NULL, NULL);
dialog_message_set_header(
message,
"You entered\ninvalid PIN",
SCREEN_WIDTH_CENTER - 25,
SCREEN_HEIGHT_CENTER - 5,
AlignCenter,
AlignCenter);
dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17);
dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message);
}
break;
case InputKeyBack:
if(scene_state->code_length > 0) {
scene_state->code_input[scene_state->code_length - 1] = 0;
scene_state->code_length--;
}
break;
default:
break;
}
return true;
@@ -164,6 +158,6 @@ void totp_scene_authenticate_deactivate(PluginState* plugin_state) {
plugin_state->current_scene_state = NULL;
}
void totp_scene_authenticate_free(const PluginState* plugin_state) {
void totp_scene_authenticate_free(PluginState* plugin_state) {
UNUSED(plugin_state);
}