13
13
#include "../../services/roll_value/roll_value.h"
14
14
#include "../scene_director.h"
15
15
#include "../token_menu/totp_scene_token_menu.h"
16
+ #include "../../services/hid_worker/hid_worker.h"
16
17
17
18
#define TOKEN_LIFETIME 30
18
19
#define DIGIT_TO_CHAR (digit ) ((digit) + '0')
19
20
20
21
typedef struct {
21
22
uint16_t current_token_index ;
22
- char last_code [9 ];
23
+ char last_code [TOTP_TOKEN_DIGITS_MAX_COUNT + 1 ];
23
24
char * last_code_name ;
24
25
bool need_token_update ;
25
26
uint32_t last_token_gen_time ;
27
+ TotpHidWorkerTypeContext * hid_worker_context ;
26
28
} SceneState ;
27
29
28
- static const NotificationSequence sequence_short_vibro_and_sound = {
30
+ static const NotificationSequence notification_sequence_new_token = {
29
31
& message_display_backlight_on ,
30
32
& message_green_255 ,
31
33
& message_vibro_on ,
@@ -36,6 +38,19 @@ static const NotificationSequence sequence_short_vibro_and_sound = {
36
38
NULL ,
37
39
};
38
40
41
+ static const NotificationSequence notification_sequence_badusb = {
42
+ & message_vibro_on ,
43
+ & message_note_d5 ,
44
+ & message_delay_50 ,
45
+ & message_note_e4 ,
46
+ & message_delay_50 ,
47
+ & message_note_f3 ,
48
+ & message_delay_50 ,
49
+ & message_vibro_off ,
50
+ & message_sound_off ,
51
+ NULL ,
52
+ };
53
+
39
54
static void i_token_to_str (uint32_t i_token_code , char * str , TokenDigitsCount len ) {
40
55
uint8_t str_token_length = 0 ;
41
56
if (len == TOTP_8_DIGITS ) {
@@ -137,6 +152,9 @@ void totp_scene_generate_token_activate(
137
152
plugin_state -> current_scene_state = scene_state ;
138
153
FURI_LOG_D (LOGGING_TAG , "Timezone set to: %f" , (double )plugin_state -> timezone_offset );
139
154
update_totp_params (plugin_state );
155
+ scene_state -> hid_worker_context = totp_hid_worker_start ();
156
+ scene_state -> hid_worker_context -> string = & scene_state -> last_code [0 ];
157
+ scene_state -> hid_worker_context -> string_length = TOTP_TOKEN_DIGITS_MAX_COUNT + 1 ;
140
158
}
141
159
142
160
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_
172
190
scene_state -> need_token_update = false;
173
191
scene_state -> last_token_gen_time = curr_ts ;
174
192
175
- TokenInfo * tokenInfo =
193
+ const TokenInfo * tokenInfo =
176
194
(TokenInfo * )(list_element_at (
177
195
plugin_state -> tokens_list , scene_state -> current_token_index )
178
196
-> data );
179
197
180
198
if (tokenInfo -> token != NULL && tokenInfo -> token_length > 0 ) {
199
+ furi_mutex_acquire (scene_state -> hid_worker_context -> string_sync , FuriWaitForever );
181
200
size_t key_length ;
182
201
uint8_t * key = totp_crypto_decrypt (
183
202
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_
196
215
memset_s (key , key_length , 0 , key_length );
197
216
free (key );
198
217
} else {
218
+ furi_mutex_acquire (scene_state -> hid_worker_context -> string_sync , FuriWaitForever );
199
219
i_token_to_str (0 , scene_state -> last_code , tokenInfo -> digits );
200
220
}
201
221
222
+ furi_mutex_release (scene_state -> hid_worker_context -> string_sync );
223
+
202
224
if (is_new_token_time ) {
203
- notification_message (plugin_state -> notification , & sequence_short_vibro_and_sound );
225
+ notification_message (plugin_state -> notification , & notification_sequence_new_token );
204
226
}
205
227
}
206
228
@@ -263,11 +285,19 @@ bool totp_scene_generate_token_handle_event(
263
285
return false;
264
286
}
265
287
288
+ SceneState * scene_state ;
289
+ if (event -> input .type == InputTypeLong && event -> input .key == InputKeyDown ) {
290
+ scene_state = (SceneState * )plugin_state -> current_scene_state ;
291
+ totp_hid_worker_notify (scene_state -> hid_worker_context , TotpHidWorkerEvtType );
292
+ notification_message (plugin_state -> notification , & notification_sequence_badusb );
293
+ return true;
294
+ }
295
+
266
296
if (event -> input .type != InputTypePress ) {
267
297
return true;
268
298
}
269
299
270
- SceneState * scene_state = (SceneState * )plugin_state -> current_scene_state ;
300
+ scene_state = (SceneState * )plugin_state -> current_scene_state ;
271
301
switch (event -> input .key ) {
272
302
case InputKeyUp :
273
303
break ;
@@ -312,6 +342,8 @@ void totp_scene_generate_token_deactivate(PluginState* plugin_state) {
312
342
if (plugin_state -> current_scene_state == NULL ) return ;
313
343
SceneState * scene_state = (SceneState * )plugin_state -> current_scene_state ;
314
344
345
+ totp_hid_worker_stop (scene_state -> hid_worker_context );
346
+
315
347
free (scene_state );
316
348
plugin_state -> current_scene_state = NULL ;
317
349
}
0 commit comments