Skip to content

Commit 018aa7e

Browse files
authored
Implemented #30 (#31)
1 parent ee4252c commit 018aa7e

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

services/cli/cli_helpers.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@
3737
TOTP_CLI_PRINTF( \
3838
"Invalid command arguments. use \"help\" command to get list of available commands")
3939

40+
/**
41+
* @brief Checks whether user is authenticated and entered correct PIN.
42+
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
43+
* @param plugin_state application state
44+
* @param cli reference to the firmware CLI subsystem
45+
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
46+
*/
4047
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);

totp_app.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
static void render_callback(Canvas* const canvas, void* ctx) {
2626
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
27-
if (plugin_state != NULL && !plugin_state->changing_scene) {
27+
if(plugin_state != NULL && !plugin_state->changing_scene) {
2828
totp_scene_director_render(canvas, plugin_state);
2929
}
3030

@@ -49,29 +49,43 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
4949

5050
totp_scene_director_init_scenes(plugin_state);
5151

52-
if (plugin_state->crypto_verify_data == NULL) {
52+
if(plugin_state->crypto_verify_data == NULL) {
5353
DialogMessage* message = dialog_message_alloc();
5454
dialog_message_set_buttons(message, "No", NULL, "Yes");
55-
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
55+
dialog_message_set_text(
56+
message,
57+
"Would you like to setup PIN?",
58+
SCREEN_WIDTH_CENTER,
59+
SCREEN_HEIGHT_CENTER,
60+
AlignCenter,
61+
AlignCenter);
5662
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
5763
dialog_message_free(message);
58-
if (dialog_result == DialogMessageButtonRight) {
64+
if(dialog_result == DialogMessageButtonRight) {
5965
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
6066
} else {
6167
totp_crypto_seed_iv(plugin_state, NULL, 0);
6268
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
6369
}
64-
} else if (plugin_state->pin_set) {
70+
} else if(plugin_state->pin_set) {
6571
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
6672
} else {
6773
totp_crypto_seed_iv(plugin_state, NULL, 0);
68-
if (totp_crypto_verify_key(plugin_state)) {
74+
if(totp_crypto_verify_key(plugin_state)) {
6975
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
7076
} else {
71-
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
77+
FURI_LOG_E(
78+
LOGGING_TAG,
79+
"Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
7280
DialogMessage* message = dialog_message_alloc();
7381
dialog_message_set_buttons(message, "Exit", NULL, NULL);
74-
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
82+
dialog_message_set_text(
83+
message,
84+
"Digital signature verification failed",
85+
SCREEN_WIDTH_CENTER,
86+
SCREEN_HEIGHT_CENTER,
87+
AlignCenter,
88+
AlignCenter);
7589
dialog_message_show(plugin_state->dialogs, message);
7690
dialog_message_free(message);
7791
return false;
@@ -94,15 +108,15 @@ static void totp_plugin_state_free(PluginState* plugin_state) {
94108

95109
ListNode* node = plugin_state->tokens_list;
96110
ListNode* tmp;
97-
while (node != NULL) {
111+
while(node != NULL) {
98112
tmp = node->next;
99113
TokenInfo* tokenInfo = node->data;
100114
token_info_free(tokenInfo);
101115
free(node);
102116
node = tmp;
103117
}
104118

105-
if (plugin_state->crypto_verify_data != NULL) {
119+
if(plugin_state->crypto_verify_data != NULL) {
106120
free(plugin_state->crypto_verify_data);
107121
}
108122
free(plugin_state);
@@ -113,7 +127,7 @@ int32_t totp_app() {
113127
PluginState* plugin_state = malloc(sizeof(PluginState));
114128
furi_check(plugin_state != NULL);
115129

116-
if (!totp_plugin_state_init(plugin_state)) {
130+
if(!totp_plugin_state_init(plugin_state)) {
117131
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
118132
totp_plugin_state_free(plugin_state);
119133
return 254;
@@ -138,18 +152,20 @@ int32_t totp_app() {
138152
bool processing = true;
139153
uint32_t last_user_interaction_time = furi_get_tick();
140154
while(processing) {
141-
if (plugin_state->changing_scene) continue;
155+
if(plugin_state->changing_scene) continue;
142156
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
143157

144158
PluginState* plugin_state_m = acquire_mutex_block(&state_mutex);
145159

146160
if(event_status == FuriStatusOk) {
147-
if (event.type == EventTypeKey) {
161+
if(event.type == EventTypeKey) {
148162
last_user_interaction_time = furi_get_tick();
149163
}
150164

151165
processing = totp_scene_director_handle_event(&event, plugin_state_m);
152-
} else if (plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
166+
} else if(
167+
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication &&
168+
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
153169
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL);
154170
}
155171

0 commit comments

Comments
 (0)