Skip to content

Commit

Permalink
feat: confirm topt export on the device (#240) (#241)
Browse files Browse the repository at this point in the history
When `totp export` executed app will ask for user confirmation on the
device to make sure that user definitely wants it.
  • Loading branch information
akopachov authored Aug 29, 2024
1 parent 61fa43b commit 81cd652
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions totp/cli/plugins/export/export.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <lib/toolbox/args.h>
#include <dialogs/dialogs.h>
#include "../../../ui/constants.h"
#include <flipper_application/flipper_application.h>
#include "../../../lib/polyfills/memset_s.h"
#include "../../../services/config/config.h"
Expand Down Expand Up @@ -57,19 +59,29 @@ static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
TOTP_CLI_PRINTF_WARNING("WARNING!\r\n");
TOTP_CLI_PRINTF_WARNING(
"ALL THE INFORMATION (INCL. UNENCRYPTED SECRET) ABOUT ALL THE TOKENS WILL BE EXPORTED AND PRINTED TO THE CONSOLE.\r\n");
TOTP_CLI_PRINTF_WARNING("Confirm? [y/n]\r\n");
fflush(stdout);
char user_pick;
do {
user_pick = tolower(cli_getc(cli));
} while(user_pick != 'y' && user_pick != 'n' && user_pick != CliSymbolAsciiCR &&
user_pick != CliSymbolAsciiETX && user_pick != CliSymbolAsciiEsc);

if(user_pick != 'y' && user_pick != CliSymbolAsciiCR) {
TOTP_CLI_PRINTF_WARNING("Confirm this action on your Flipper\r\n");

DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "No", NULL, "Yes");
dialog_message_set_text(
message,
"Would you like to\nEXPORT TOKENS AND\nUNENCRYPTED SECRETS?",
SCREEN_WIDTH_CENTER,
SCREEN_HEIGHT_CENTER - 8,
AlignCenter,
AlignCenter);
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs_app, message);
dialog_message_free(message);

if(dialog_result != DialogMessageButtonRight) {
TOTP_CLI_PRINTF_INFO("User has not confirmed\r\n");
return;
}

if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
return;
}

TokenInfoIteratorContext* iterator_context =
totp_config_get_token_iterator_context(plugin_state);
size_t total_count = totp_token_info_iterator_get_total_count(iterator_context);
Expand Down

0 comments on commit 81cd652

Please sign in to comment.