updated authenticator (totp)

This commit is contained in:
jbohack
2023-01-12 11:15:46 -05:00
parent ff7c3742c0
commit 5dbb39eb05
14 changed files with 158 additions and 56 deletions

View File

@@ -76,43 +76,6 @@ static void furi_string_secure_free(FuriString* str) {
furi_string_free(str);
}
static bool totp_cli_read_secret(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) {
TOTP_CLI_DELETE_CURRENT_LINE();
TOTP_CLI_PRINTF("Cancelled by user\r\n");
return false;
} else if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
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;
}
}
TOTP_CLI_DELETE_LAST_LINE();
return true;
}
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
FuriString* temp_str = furi_string_alloc();
TokenInfo* token_info = token_info_alloc();
@@ -178,13 +141,17 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
// Reading token secret
furi_string_reset(temp_str);
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n");
if(!totp_cli_read_secret(cli, temp_str, mask_user_input) ||
if(!totp_cli_read_line(cli, temp_str, mask_user_input) ||
!totp_cli_ensure_authenticated(plugin_state, cli)) {
TOTP_CLI_DELETE_LAST_LINE();
TOTP_CLI_PRINTF("Cancelled by user\r\n");
furi_string_secure_free(temp_str);
token_info_free(token_info);
return;
}
TOTP_CLI_DELETE_LAST_LINE();
if(!token_info_set_secret(
token_info,
furi_string_get_cstr(temp_str),

View File

@@ -7,6 +7,7 @@
#include "../move/move.h"
#include "../pin/pin.h"
#include "../notification/notification.h"
#include "../reset/reset.h"
void totp_cli_command_help_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_HELP ", " TOTP_CLI_COMMAND_HELP_ALT
@@ -29,6 +30,7 @@ void totp_cli_command_help_handle() {
totp_cli_command_move_docopt_usage();
totp_cli_command_pin_docopt_usage();
totp_cli_command_notification_docopt_usage();
totp_cli_command_reset_docopt_usage();
cli_nl();
TOTP_CLI_PRINTF("Commands:\r\n");
totp_cli_command_help_docopt_commands();
@@ -39,6 +41,7 @@ void totp_cli_command_help_handle() {
totp_cli_command_move_docopt_commands();
totp_cli_command_pin_docopt_commands();
totp_cli_command_notification_docopt_commands();
totp_cli_command_reset_docopt_commands();
cli_nl();
TOTP_CLI_PRINTF("Arguments:\r\n");
totp_cli_command_add_docopt_arguments();

View File

@@ -0,0 +1,37 @@
#include "reset.h"
#include <stdlib.h>
#include <furi/furi.h>
#include "../../cli_helpers.h"
#include "../../../services/config/config.h"
#define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"
void totp_cli_command_reset_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
" Reset application to default settings\r\n");
}
void totp_cli_command_reset_docopt_usage() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
}
void totp_cli_command_reset_handle(Cli* cli, FuriMessageQueue* event_queue) {
TOTP_CLI_PRINTF(
"As a result of reset all the settings and tokens will be permanently lost.\r\n");
TOTP_CLI_PRINTF("Do you really want to reset application?\r\n");
TOTP_CLI_PRINTF("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD
"\" and hit <ENTER> to confirm:\r\n");
FuriString* temp_str = furi_string_alloc();
bool is_confirmed = totp_cli_read_line(cli, temp_str, false) &&
furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0;
furi_string_free(temp_str);
if(is_confirmed) {
totp_config_file_reset();
TOTP_CLI_PRINTF("Application has been successfully reset to default.\r\n");
TOTP_CLI_PRINTF("Now application will be closed to apply all the changes.\r\n");
totp_cli_force_close_app(event_queue);
} else {
TOTP_CLI_PRINTF("Action was not confirmed by user\r\n");
}
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#define TOTP_CLI_COMMAND_RESET "reset"
void totp_cli_command_reset_handle(Cli* cli, FuriMessageQueue* event_queue);
void totp_cli_command_reset_docopt_commands();
void totp_cli_command_reset_docopt_usage();