Update apps

This commit is contained in:
Willy-JL
2023-08-30 18:59:32 +02:00
parent 160ab755a2
commit ee37769ee2
308 changed files with 2314 additions and 801 deletions

View File

@@ -6,8 +6,7 @@ App(
cdefines=["APP_TOTP"],
requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
stack_size=2 * 1024,
order=20,
fap_version="4.01",
fap_version="4.03",
fap_author="Alexander Kopachov (@akopachov)",
fap_description="Software-based TOTP authenticator for Flipper Zero device",
fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",

View File

@@ -47,7 +47,7 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) {
} else if(
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_LIST) == 0 ||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_LIST_ALT) == 0) {
totp_cli_command_list_handle(plugin_state, cli);
totp_cli_command_list_handle(plugin_state, args, cli);
} else if(
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DELETE) == 0 ||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DELETE_ALT) == 0) {

View File

@@ -7,33 +7,68 @@
#include "../../../ui/scene_director.h"
#include "../../cli_helpers.h"
#include "../../common_command_arguments.h"
#include "formatters/table/details_output_formatter_table.h"
#include "formatters/tsv/details_output_formatter_tsv.h"
#define TOTP_CLI_PRINTF_AUTOMATION_FEATURE(description, header_printed) \
do { \
TOTP_CLI_PRINTF( \
"| %-20s | %-28.28s |\r\n", \
header_printed ? "" : "Automation features", \
description); \
header_printed = true; \
} while(false)
typedef void (*TOTP_CLI_DETAILS_HEADER_FORMATTER)();
typedef void (*TOTP_CLI_DETAILS_FOOTER_FORMATTER)();
typedef void (*TOTP_CLI_DETAILS_AUTOMATION_FEATURE_ITEM_FORMATTER)(
const char* key,
const char* feature,
bool* header_printed);
typedef void (*TOTP_CLI_DETAILS_CSTR_FORMATTER)(const char* key, const char* value);
typedef void (*TOTP_CLI_DETAILS_UINT8T_FORMATTER)(const char* key, uint8_t value);
typedef void (*TOTP_CLI_DETAILS_SIZET_FORMATTER)(const char* key, size_t value);
static void print_automation_features(const TokenInfo* token_info) {
typedef struct {
const TOTP_CLI_DETAILS_HEADER_FORMATTER header_formatter;
const TOTP_CLI_DETAILS_FOOTER_FORMATTER footer_formatter;
const TOTP_CLI_DETAILS_AUTOMATION_FEATURE_ITEM_FORMATTER automation_feature_item_formatter;
const TOTP_CLI_DETAILS_CSTR_FORMATTER cstr_formatter;
const TOTP_CLI_DETAILS_UINT8T_FORMATTER uint8t_formatter;
const TOTP_CLI_DETAILS_SIZET_FORMATTER sizet_formatter;
} TotpCliDetailsFormatter;
static const TotpCliDetailsFormatter available_formatters[] = {
{.header_formatter = &details_output_formatter_print_header_table,
.footer_formatter = &details_output_formatter_print_footer_table,
.automation_feature_item_formatter = &details_output_formatter_print_automation_feature_table,
.cstr_formatter = &details_output_formatter_print_cstr_table,
.uint8t_formatter = &details_output_formatter_print_uint8t_table,
.sizet_formatter = &details_output_formatter_print_sizet_table},
{.header_formatter = &details_output_formatter_print_header_tsv,
.footer_formatter = &details_output_formatter_print_footer_tsv,
.automation_feature_item_formatter = &details_output_formatter_print_automation_feature_tsv,
.cstr_formatter = &details_output_formatter_print_cstr_tsv,
.uint8t_formatter = &details_output_formatter_print_uint8t_tsv,
.sizet_formatter = &details_output_formatter_print_sizet_tsv},
};
static void print_automation_features(
const TokenInfo* token_info,
const TotpCliDetailsFormatter* formatter) {
bool header_printed = false;
const char* AUTOMATION_FEATURES_PRINT_KEY = "Automation features";
if(token_info->automation_features == TokenAutomationFeatureNone) {
TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", "Automation features", "None");
(*formatter->automation_feature_item_formatter)(
AUTOMATION_FEATURES_PRINT_KEY, "None", &header_printed);
return;
}
bool header_printed = false;
if(token_info->automation_features & TokenAutomationFeatureEnterAtTheEnd) {
TOTP_CLI_PRINTF_AUTOMATION_FEATURE("Type <Enter> key at the end", header_printed);
(*formatter->automation_feature_item_formatter)(
AUTOMATION_FEATURES_PRINT_KEY, "Type <Enter> key at the end", &header_printed);
}
if(token_info->automation_features & TokenAutomationFeatureTabAtTheEnd) {
TOTP_CLI_PRINTF_AUTOMATION_FEATURE("Type <Tab> key at the end", header_printed);
(*formatter->automation_feature_item_formatter)(
AUTOMATION_FEATURES_PRINT_KEY, "Type <Tab> key at the end", &header_printed);
}
if(token_info->automation_features & TokenAutomationFeatureTypeSlower) {
TOTP_CLI_PRINTF_AUTOMATION_FEATURE("Type slower", header_printed);
(*formatter->automation_feature_item_formatter)(
AUTOMATION_FEATURES_PRINT_KEY, "Type slower", &header_printed);
}
}
@@ -64,6 +99,14 @@ void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args
return;
}
const TotpCliDetailsFormatter* formatter = &available_formatters[0];
FuriString* arg = furi_string_alloc();
if(args_read_string_and_trim(args, arg) && furi_string_cmpi_str(arg, "--tsv") == 0) {
formatter = &available_formatters[1];
}
furi_string_free(arg);
TOTP_CLI_LOCK_UI(plugin_state);
size_t original_token_index =
@@ -71,19 +114,14 @@ void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args
if(totp_token_info_iterator_go_to(iterator_context, token_number - 1)) {
const TokenInfo* token_info = totp_token_info_iterator_get_current_token(iterator_context);
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
TOTP_CLI_PRINTF("| %-20s | %-28s |\r\n", "Property", "Value");
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
TOTP_CLI_PRINTF("| %-20s | %-28d |\r\n", "Index", token_number);
TOTP_CLI_PRINTF(
"| %-20s | %-28.28s |\r\n", "Name", furi_string_get_cstr(token_info->name));
TOTP_CLI_PRINTF(
"| %-20s | %-28s |\r\n", "Hashing algorithm", token_info_get_algo_as_cstr(token_info));
TOTP_CLI_PRINTF("| %-20s | %-28" PRIu8 " |\r\n", "Number of digits", token_info->digits);
TOTP_CLI_PRINTF(
"| %-20s | %" PRIu8 " sec.%-21s |\r\n", "Token lifetime", token_info->duration, " ");
print_automation_features(token_info);
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
(*formatter->header_formatter)();
(*formatter->sizet_formatter)("Index", token_number);
(*formatter->cstr_formatter)("Name", furi_string_get_cstr(token_info->name));
(*formatter->cstr_formatter)("Hashing algorithm", token_info_get_algo_as_cstr(token_info));
(*formatter->uint8t_formatter)("Number of digits", token_info->digits);
(*formatter->uint8t_formatter)("Token lifetime", token_info->duration);
print_automation_features(token_info, formatter);
(*formatter->footer_formatter)();
} else {
totp_cli_print_error_loading_token_info();
}

View File

@@ -0,0 +1,32 @@
#include "details_output_formatter_table.h"
#include "../../../../cli_helpers.h"
void details_output_formatter_print_header_table() {
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
TOTP_CLI_PRINTF("| %-20s | %-28s |\r\n", "Property", "Value");
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
}
void details_output_formatter_print_footer_table() {
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
}
void details_output_formatter_print_automation_feature_table(
const char* key,
const char* feature,
bool* header_printed) {
TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", *header_printed ? "" : key, feature);
*header_printed = true;
}
void details_output_formatter_print_cstr_table(const char* key, const char* value) {
TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", key, value);
}
void details_output_formatter_print_uint8t_table(const char* key, uint8_t value) {
TOTP_CLI_PRINTF("| %-20s | %-28" PRIu8 " |\r\n", key, value);
}
void details_output_formatter_print_sizet_table(const char* key, size_t value) {
TOTP_CLI_PRINTF("| %-20s | %-28" PRIu16 " |\r\n", key, value);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
void details_output_formatter_print_header_table();
void details_output_formatter_print_footer_table();
void details_output_formatter_print_automation_feature_table(
const char* key,
const char* feature,
bool* header_printed);
void details_output_formatter_print_cstr_table(const char* key, const char* value);
void details_output_formatter_print_uint8t_table(const char* key, uint8_t value);
void details_output_formatter_print_sizet_table(const char* key, size_t value);

View File

@@ -0,0 +1,29 @@
#include "details_output_formatter_tsv.h"
#include "../../../../cli_helpers.h"
void details_output_formatter_print_header_tsv() {
TOTP_CLI_PRINTF("%s\t%s\r\n", "Property", "Value");
}
void details_output_formatter_print_footer_tsv() {
}
void details_output_formatter_print_automation_feature_tsv(
const char* key,
const char* feature,
bool* header_printed) {
TOTP_CLI_PRINTF("%s\t%s\r\n", *header_printed ? "" : key, feature);
*header_printed = true;
}
void details_output_formatter_print_cstr_tsv(const char* key, const char* value) {
TOTP_CLI_PRINTF("%s\t%s\r\n", key, value);
}
void details_output_formatter_print_uint8t_tsv(const char* key, uint8_t value) {
TOTP_CLI_PRINTF("%s\t%" PRIu8 "\r\n", key, value);
}
void details_output_formatter_print_sizet_tsv(const char* key, size_t value) {
TOTP_CLI_PRINTF("%s\t%" PRIu16 "\r\n", key, value);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
void details_output_formatter_print_header_tsv();
void details_output_formatter_print_footer_tsv();
void details_output_formatter_print_automation_feature_tsv(
const char* key,
const char* feature,
bool* header_printed);
void details_output_formatter_print_cstr_tsv(const char* key, const char* value);
void details_output_formatter_print_uint8t_tsv(const char* key, uint8_t value);
void details_output_formatter_print_sizet_tsv(const char* key, size_t value);

View File

@@ -0,0 +1,22 @@
#include "list_output_formatter_table.h"
#include "../../../../cli_helpers.h"
void list_output_formatter_print_header_table() {
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
TOTP_CLI_PRINTF("| %-3s | %-25s | %-6s | %-s | %-s |\r\n", "#", "Name", "Algo", "Ln", "Dur");
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
}
void list_output_formatter_print_body_item_table(size_t index, const TokenInfo* token_info) {
TOTP_CLI_PRINTF(
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-3" PRIu8 " |\r\n",
index + 1,
furi_string_get_cstr(token_info->name),
token_info_get_algo_as_cstr(token_info),
token_info->digits,
token_info->duration);
}
void list_output_formatter_print_footer_table() {
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../../../../../types/token_info.h"
void list_output_formatter_print_header_table();
void list_output_formatter_print_body_item_table(size_t index, const TokenInfo* token_info);
void list_output_formatter_print_footer_table();

View File

@@ -0,0 +1,19 @@
#include "list_output_formatter_tsv.h"
#include "../../../../cli_helpers.h"
void list_output_formatter_print_header_tsv() {
TOTP_CLI_PRINTF("%s\t%s\t%s\t%s\t%s\r\n", "#", "Name", "Algo", "Ln", "Dur");
}
void list_output_formatter_print_body_item_tsv(size_t index, const TokenInfo* token_info) {
TOTP_CLI_PRINTF(
"%" PRIu16 "\t%s\t%s\t%" PRIu8 "\t%" PRIu8 "\r\n",
index + 1,
furi_string_get_cstr(token_info->name),
token_info_get_algo_as_cstr(token_info),
token_info->digits,
token_info->duration);
}
void list_output_formatter_print_footer_tsv() {
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../../../../../types/token_info.h"
void list_output_formatter_print_header_tsv();
void list_output_formatter_print_body_item_tsv(size_t index, const TokenInfo* token_info);
void list_output_formatter_print_footer_tsv();

View File

@@ -1,10 +1,32 @@
#include "list.h"
#include <stdlib.h>
#include <lib/toolbox/args.h>
#include "../../../types/token_info.h"
#include "../../../services/config/constants.h"
#include "../../../services/config/config.h"
#include "../../../ui/scene_director.h"
#include "../../cli_helpers.h"
#include "formatters/table/list_output_formatter_table.h"
#include "formatters/tsv/list_output_formatter_tsv.h"
typedef void (*TOTP_CLI_LIST_HEADER_FORMATTER)();
typedef void (*TOTP_CLI_LIST_FOOTER_FORMATTER)();
typedef void (*TOTP_CLI_LIST_BODY_ITEM_FORMATTER)(size_t index, const TokenInfo* token_info);
typedef struct {
const TOTP_CLI_LIST_HEADER_FORMATTER header_formatter;
const TOTP_CLI_LIST_FOOTER_FORMATTER footer_formatter;
const TOTP_CLI_LIST_BODY_ITEM_FORMATTER body_item_formatter;
} TotpCliListFormatter;
static const TotpCliListFormatter available_formatters[] = {
{.header_formatter = &list_output_formatter_print_header_table,
.body_item_formatter = &list_output_formatter_print_body_item_table,
.footer_formatter = &list_output_formatter_print_footer_table},
{.header_formatter = &list_output_formatter_print_header_tsv,
.body_item_formatter = &list_output_formatter_print_body_item_tsv,
.footer_formatter = &list_output_formatter_print_footer_tsv}};
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_list_docopt_commands() {
@@ -18,7 +40,7 @@ void totp_cli_command_list_docopt_usage() {
}
#endif
void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
void totp_cli_command_list_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
return;
}
@@ -31,26 +53,26 @@ void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
return;
}
const TotpCliListFormatter* formatter = &available_formatters[0];
FuriString* arg = furi_string_alloc();
if(args_read_string_and_trim(args, arg) && furi_string_cmpi_str(arg, "--tsv") == 0) {
formatter = &available_formatters[1];
}
furi_string_free(arg);
TOTP_CLI_LOCK_UI(plugin_state);
size_t original_index = totp_token_info_iterator_get_current_token_index(iterator_context);
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
TOTP_CLI_PRINTF("| %-3s | %-25s | %-6s | %-s | %-s |\r\n", "#", "Name", "Algo", "Ln", "Dur");
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
(*formatter->header_formatter)();
for(size_t i = 0; i < total_count; i++) {
totp_token_info_iterator_go_to(iterator_context, i);
const TokenInfo* token_info = totp_token_info_iterator_get_current_token(iterator_context);
TOTP_CLI_PRINTF(
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-3" PRIu8 " |\r\n",
i + 1,
furi_string_get_cstr(token_info->name),
token_info_get_algo_as_cstr(token_info),
token_info->digits,
token_info->duration);
(*formatter->body_item_formatter)(i, token_info);
}
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
(*formatter->footer_formatter)();
totp_token_info_iterator_go_to(iterator_context, original_index);

View File

@@ -7,7 +7,7 @@
#define TOTP_CLI_COMMAND_LIST "list"
#define TOTP_CLI_COMMAND_LIST_ALT "ls"
void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli);
void totp_cli_command_list_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_list_docopt_commands();
void totp_cli_command_list_docopt_usage();

View File

@@ -129,6 +129,17 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
return false;
}
} else {
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
FURI_LOG_D(LOGGING_TAG, "Config file directory doesn't exist. Will create new");
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
FURI_LOG_E(
LOGGING_TAG,
"Error creating config file directory %s",
CONFIG_FILE_DIRECTORY_PATH);
return false;
}
}
FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH);
if(!flipper_format_file_open_new(fff_data_file, CONFIG_FILE_PATH)) {

View File

@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <dolphin/dolphin.h>
#include "config/app/config.h"
#include "services/config/config.h"
#include "types/plugin_state.h"
@@ -237,6 +238,9 @@ int32_t totp_app() {
return 253;
}
// Affecting dolphin level
dolphin_deed(DolphinDeedPluginStart);
FuriMutex* main_loop_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
struct TotpRenderCallbackContext render_context = {
.plugin_state = plugin_state, .mutex = main_loop_mutex};

View File

@@ -1,6 +1,7 @@
#include "totp_app_settings.h"
#include <math.h>
#include <totp_icons.h>
#include "totp_icons.h"
#include <assets_icons.h>
#include <available_fonts.h>
#include "../../canvas_extensions.h"
#include "../../ui_controls.h"

View File

@@ -1,6 +1,6 @@
#include "totp_scene_authenticate.h"
#include <dialogs/dialogs.h>
#include <totp_icons.h>
#include "totp_icons.h"
#include <assets_icons.h>
#include "../../../types/common.h"
#include "../../constants.h"

View File

@@ -2,7 +2,7 @@
#include <gui/gui.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <totp_icons.h>
#include "totp_icons.h"
#include <assets_icons.h>
#include <roll_value.h>
#include <available_fonts.h>
@@ -246,7 +246,7 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_
SCREEN_HEIGHT_CENTER + 10,
AlignCenter,
AlignCenter,
"Press OK button to access menu");
"Press OK button to open menu");
return;
}

View File

@@ -1,5 +1,5 @@
#include "standby.h"
#include <totp_icons.h>
#include "totp_icons.h"
#include <assets_icons.h>
#include "../../constants.h"
@@ -10,4 +10,4 @@ void totp_scene_standby_render(Canvas* const canvas) {
canvas_draw_str_aligned(canvas, 5, 10, AlignLeft, AlignTop, "CLI command");
canvas_draw_str_aligned(canvas, 5, 24, AlignLeft, AlignTop, "is running now");
}
}

View File

@@ -1,5 +1,5 @@
#include "ui_controls.h"
#include <totp_icons.h>
#include "totp_icons.h"
#include <assets_icons.h>
#include "constants.h"

View File

@@ -2,4 +2,4 @@
#define TOTP_APP_VERSION_MAJOR (4)
#define TOTP_APP_VERSION_MINOR (0)
#define TOTP_APP_VERSION_PATCH (1)
#define TOTP_APP_VERSION_PATCH (3)

View File

@@ -230,4 +230,4 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {
bool totp_bt_type_code_worker_is_advertising(const TotpBtTypeCodeWorkerContext* context) {
return context->is_advertising;
}
}