2022-10-28 15:34:35 +00:00
|
|
|
#include "cli_helpers.h"
|
|
|
|
#include <cli/cli.h>
|
2023-04-01 14:45:52 +00:00
|
|
|
#include <lib/toolbox/args.h>
|
2023-01-06 23:07:26 +00:00
|
|
|
#include "../types/plugin_event.h"
|
2022-10-28 15:34:35 +00:00
|
|
|
|
2022-11-10 05:32:21 +00:00
|
|
|
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli) {
|
2022-10-28 15:34:35 +00:00
|
|
|
if(plugin_state->current_scene == TotpSceneAuthentication) {
|
|
|
|
TOTP_CLI_PRINTF("Pleases enter PIN on your flipper device\r\n");
|
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
while((plugin_state->current_scene == TotpSceneAuthentication ||
|
|
|
|
plugin_state->current_scene == TotpSceneNone) &&
|
2022-10-28 15:34:35 +00:00
|
|
|
!cli_cmd_interrupt_received(cli)) {
|
|
|
|
furi_delay_ms(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOTP_CLI_DELETE_LAST_LINE();
|
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
if(plugin_state->current_scene == TotpSceneAuthentication || //-V560
|
|
|
|
plugin_state->current_scene == TotpSceneNone) { //-V560
|
2022-10-28 15:34:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 23:07:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_force_close_app(FuriMessageQueue* event_queue) {
|
|
|
|
PluginEvent event = {.type = EventForceCloseApp};
|
|
|
|
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool totp_cli_read_line(Cli* cli, FuriString* out_str, bool mask_user_input) {
|
|
|
|
uint8_t c;
|
|
|
|
while(cli_read(cli, &c, 1) == 1) {
|
|
|
|
if(c == CliSymbolAsciiEsc) {
|
|
|
|
// Some keys generating escape-sequences
|
|
|
|
// We need to ignore them as we care about alpha-numerics only
|
|
|
|
uint8_t c2;
|
|
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
|
|
} else if(c == CliSymbolAsciiETX) {
|
|
|
|
cli_nl();
|
|
|
|
return false;
|
2023-04-05 19:45:27 +00:00
|
|
|
} else if(
|
|
|
|
(c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
|
|
c == '/' || c == '=' || c == '+') {
|
2023-01-06 23:07:26 +00:00
|
|
|
if(mask_user_input) {
|
|
|
|
putc('*', stdout);
|
|
|
|
} else {
|
|
|
|
putc(c, stdout);
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
furi_string_push_back(out_str, c);
|
|
|
|
} else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
|
|
|
|
size_t out_str_size = furi_string_size(out_str);
|
|
|
|
if(out_str_size > 0) {
|
|
|
|
TOTP_CLI_DELETE_LAST_CHAR();
|
|
|
|
furi_string_left(out_str, out_str_size - 1);
|
|
|
|
}
|
|
|
|
} else if(c == CliSymbolAsciiCR) {
|
|
|
|
cli_nl();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:34:35 +00:00
|
|
|
return true;
|
2023-04-01 14:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool args_read_uint8_and_trim(FuriString* args, uint8_t* value) {
|
|
|
|
int int_value;
|
|
|
|
if(!args_read_int_and_trim(args, &int_value) || int_value < 0 || int_value > UINT8_MAX) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = (uint8_t)int_value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void furi_string_secure_free(FuriString* str) {
|
|
|
|
for(long i = furi_string_size(str) - 1; i >= 0; i--) {
|
|
|
|
furi_string_set_char(str, i, '\0');
|
|
|
|
}
|
|
|
|
|
|
|
|
furi_string_free(str);
|
|
|
|
}
|