|
|
@@ -13,19 +13,21 @@
|
|
|
#include "../../services/roll_value/roll_value.h"
|
|
|
#include "../scene_director.h"
|
|
|
#include "../token_menu/totp_scene_token_menu.h"
|
|
|
+#include "../../services/hid_worker/hid_worker.h"
|
|
|
|
|
|
#define TOKEN_LIFETIME 30
|
|
|
#define DIGIT_TO_CHAR(digit) ((digit) + '0')
|
|
|
|
|
|
typedef struct {
|
|
|
uint16_t current_token_index;
|
|
|
- char last_code[9];
|
|
|
+ char last_code[TOTP_TOKEN_DIGITS_MAX_COUNT + 1];
|
|
|
char* last_code_name;
|
|
|
bool need_token_update;
|
|
|
uint32_t last_token_gen_time;
|
|
|
+ TotpHidWorkerTypeContext* hid_worker_context;
|
|
|
} SceneState;
|
|
|
|
|
|
-static const NotificationSequence sequence_short_vibro_and_sound = {
|
|
|
+static const NotificationSequence notification_sequence_new_token = {
|
|
|
&message_display_backlight_on,
|
|
|
&message_green_255,
|
|
|
&message_vibro_on,
|
|
|
@@ -36,6 +38,19 @@ static const NotificationSequence sequence_short_vibro_and_sound = {
|
|
|
NULL,
|
|
|
};
|
|
|
|
|
|
+static const NotificationSequence notification_sequence_badusb = {
|
|
|
+ &message_vibro_on,
|
|
|
+ &message_note_d5,
|
|
|
+ &message_delay_50,
|
|
|
+ &message_note_e4,
|
|
|
+ &message_delay_50,
|
|
|
+ &message_note_f3,
|
|
|
+ &message_delay_50,
|
|
|
+ &message_vibro_off,
|
|
|
+ &message_sound_off,
|
|
|
+ NULL,
|
|
|
+};
|
|
|
+
|
|
|
static void i_token_to_str(uint32_t i_token_code, char* str, TokenDigitsCount len) {
|
|
|
uint8_t str_token_length = 0;
|
|
|
if(len == TOTP_8_DIGITS) {
|
|
|
@@ -137,6 +152,9 @@ void totp_scene_generate_token_activate(
|
|
|
plugin_state->current_scene_state = scene_state;
|
|
|
FURI_LOG_D(LOGGING_TAG, "Timezone set to: %f", (double)plugin_state->timezone_offset);
|
|
|
update_totp_params(plugin_state);
|
|
|
+ scene_state->hid_worker_context = totp_hid_worker_start();
|
|
|
+ scene_state->hid_worker_context->string = &scene_state->last_code[0];
|
|
|
+ scene_state->hid_worker_context->string_length = TOTP_TOKEN_DIGITS_MAX_COUNT + 1;
|
|
|
}
|
|
|
|
|
|
void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_state) {
|
|
|
@@ -172,12 +190,13 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_
|
|
|
scene_state->need_token_update = false;
|
|
|
scene_state->last_token_gen_time = curr_ts;
|
|
|
|
|
|
- TokenInfo* tokenInfo =
|
|
|
+ const TokenInfo* tokenInfo =
|
|
|
(TokenInfo*)(list_element_at(
|
|
|
plugin_state->tokens_list, scene_state->current_token_index)
|
|
|
->data);
|
|
|
|
|
|
if(tokenInfo->token != NULL && tokenInfo->token_length > 0) {
|
|
|
+ furi_mutex_acquire(scene_state->hid_worker_context->string_sync, FuriWaitForever);
|
|
|
size_t key_length;
|
|
|
uint8_t* key = totp_crypto_decrypt(
|
|
|
tokenInfo->token, tokenInfo->token_length, &plugin_state->iv[0], &key_length);
|
|
|
@@ -196,11 +215,14 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_
|
|
|
memset_s(key, key_length, 0, key_length);
|
|
|
free(key);
|
|
|
} else {
|
|
|
+ furi_mutex_acquire(scene_state->hid_worker_context->string_sync, FuriWaitForever);
|
|
|
i_token_to_str(0, scene_state->last_code, tokenInfo->digits);
|
|
|
}
|
|
|
|
|
|
+ furi_mutex_release(scene_state->hid_worker_context->string_sync);
|
|
|
+
|
|
|
if(is_new_token_time) {
|
|
|
- notification_message(plugin_state->notification, &sequence_short_vibro_and_sound);
|
|
|
+ notification_message(plugin_state->notification, ¬ification_sequence_new_token);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -263,11 +285,19 @@ bool totp_scene_generate_token_handle_event(
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ SceneState* scene_state;
|
|
|
+ if(event->input.type == InputTypeLong && event->input.key == InputKeyDown) {
|
|
|
+ scene_state = (SceneState*)plugin_state->current_scene_state;
|
|
|
+ totp_hid_worker_notify(scene_state->hid_worker_context, TotpHidWorkerEvtType);
|
|
|
+ notification_message(plugin_state->notification, ¬ification_sequence_badusb);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
if(event->input.type != InputTypePress) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
|
|
+ scene_state = (SceneState*)plugin_state->current_scene_state;
|
|
|
switch(event->input.key) {
|
|
|
case InputKeyUp:
|
|
|
break;
|
|
|
@@ -312,6 +342,8 @@ void totp_scene_generate_token_deactivate(PluginState* plugin_state) {
|
|
|
if(plugin_state->current_scene_state == NULL) return;
|
|
|
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
|
|
|
|
|
+ totp_hid_worker_stop(scene_state->hid_worker_context);
|
|
|
+
|
|
|
free(scene_state);
|
|
|
plugin_state->current_scene_state = NULL;
|
|
|
}
|