Skip to content

Commit

Permalink
Implemented #198 (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Sep 12, 2023
1 parent b106c91 commit 6513672
Show file tree
Hide file tree
Showing 70 changed files with 1,049 additions and 953 deletions.
13 changes: 13 additions & 0 deletions app_api_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <flipper_application/api_hashtable/api_hashtable.h>

/*
* Resolver interface with private application's symbols.
* Implementation is contained in app_api_table.c
*/
#ifdef __cplusplus
extern "C" const ElfApiInterface* const application_api_interface;
#else
extern const ElfApiInterface* const application_api_interface;
#endif
19 changes: 19 additions & 0 deletions app_api_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <flipper_application/api_hashtable/api_hashtable.h>
#include <flipper_application/api_hashtable/compilesort.hpp>
#include "app_api_interface.h"
#include "app_api_table_i.h"

static_assert(!has_hash_collisions(app_api_table), "Detected API method hash collision!");

constexpr HashtableApiInterface applicaton_hashtable_api_interface{
{
.api_version_major = 0,
.api_version_minor = 0,
.resolver_callback = &elf_resolve_from_hashtable,
},
.table_cbegin = app_api_table.cbegin(),
.table_cend = app_api_table.cend(),
};

extern "C" const ElfApiInterface* const application_api_interface =
&applicaton_hashtable_api_interface;
65 changes: 65 additions & 0 deletions app_api_table_i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdbool.h>
#include <cli/cli.h>
#include <lib/print/wrappers.h>
#include <lib/toolbox/args.h>
#include <memset_s.h>
#include "services/crypto/crypto_facade.h"
#include "ui/scene_director.h"
#include "services/config/config.h"
#include "cli/cli_helpers.h"
#include "workers/bt_type_code/bt_type_code.h"

static constexpr auto app_api_table = sort(create_array_t<sym_entry>(
API_METHOD(memset_s, errno_t, (void*, rsize_t, int, rsize_t)),
API_METHOD(totp_scene_director_activate_scene, void, (PluginState* const, Scene)),
API_METHOD(totp_scene_director_force_redraw, void, (PluginState* const)),
API_METHOD(totp_config_file_update_timezone_offset, bool, (const PluginState*)),
API_METHOD(totp_config_file_reset, void, (PluginState* const)),
API_METHOD(
totp_config_get_token_iterator_context,
TokenInfoIteratorContext*,
(const PluginState*)),
API_METHOD(totp_config_file_backup, char*, (const PluginState*)),
API_METHOD(
totp_config_file_update_encryption,
bool,
(PluginState*, uint8_t, const uint8_t*, uint8_t)),
API_METHOD(totp_config_file_update_automation_method, bool, (const PluginState*)),
API_METHOD(totp_config_file_update_notification_method, bool, (const PluginState*)),
API_METHOD(totp_token_info_iterator_get_total_count, size_t, (const TokenInfoIteratorContext*)),
API_METHOD(
totp_token_info_iterator_get_current_token_index,
size_t,
(const TokenInfoIteratorContext*)),
API_METHOD(totp_token_info_iterator_go_to, bool, (TokenInfoIteratorContext*, size_t)),
API_METHOD(
totp_token_info_iterator_get_current_token,
const TokenInfo*,
(const TokenInfoIteratorContext*)),
API_METHOD(
totp_token_info_iterator_add_new_token,
TotpIteratorUpdateTokenResult,
(TokenInfoIteratorContext*, TOTP_ITERATOR_UPDATE_TOKEN_ACTION, const void*)),
API_METHOD(
totp_token_info_iterator_update_current_token,
TotpIteratorUpdateTokenResult,
(TokenInfoIteratorContext*, TOTP_ITERATOR_UPDATE_TOKEN_ACTION, const void*)),
API_METHOD(
totp_token_info_iterator_move_current_token_info,
bool,
(TokenInfoIteratorContext*, size_t)),
API_METHOD(
totp_token_info_iterator_remove_current_token_info,
bool,
(TokenInfoIteratorContext*)),
API_METHOD(token_info_get_algo_as_cstr, const char*, (const TokenInfo*)),
API_METHOD(token_info_set_algo_from_str, bool, (TokenInfo*, const FuriString*)),
API_METHOD(token_info_set_digits_from_int, bool, (TokenInfo*, uint8_t)),
API_METHOD(token_info_set_duration_from_int, bool, (TokenInfo*, uint8_t)),
API_METHOD(token_info_set_automation_feature_from_str, bool, (TokenInfo*, const FuriString*)),
API_METHOD(
token_info_set_secret,
bool,
(TokenInfo*, const char*, size_t, PlainTokenSecretEncoding, const CryptoSettings*)),
API_METHOD(totp_crypto_check_key_slot, bool, (uint8_t)),
API_METHOD(totp_bt_type_code_worker_free, void, (TotpBtTypeCodeWorkerContext*))));
133 changes: 133 additions & 0 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ App(
fap_category="Tools",
fap_icon_assets="images",
fap_icon="totp_10px.png",
fap_file_assets="assets",
fap_private_libs=[
Lib(
name="base32",
Expand Down Expand Up @@ -57,3 +58,135 @@ App(
),
],
)

App(
appid="totp_cli_timezone_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_timezone_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/timezone/timezone.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_version_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_version_plugin_ep",
requires=["totp"],
sources=["cli/plugins/version/version.c"],
)

App(
appid="totp_cli_help_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_help_plugin_ep",
requires=["totp"],
sources=["cli/plugins/help/help.c"],
)

App(
appid="totp_cli_list_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_list_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/list/list.c",
"cli/cli_shared_methods.c",
"cli/plugins/list/formatters/table/list_output_formatter_table.c",
"cli/plugins/list/formatters/tsv/list_output_formatter_tsv.c"],
)

App(
appid="totp_cli_details_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_details_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/details/details.c",
"cli/cli_shared_methods.c",
"cli/plugins/details/formatters/table/details_output_formatter_table.c",
"cli/plugins/details/formatters/tsv/details_output_formatter_tsv.c"],
)

App(
appid="totp_cli_add_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_add_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/modify/add/add.c",
"cli/plugins/modify/common.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_update_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_update_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/modify/update/update.c",
"cli/plugins/modify/common.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_delete_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_delete_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/delete/delete.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_move_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_move_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/move/move.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_reset_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_reset_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/reset/reset.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_pin_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_pin_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/pin/pin.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_automation_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_automation_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/automation/automation.c",
"cli/cli_shared_methods.c"],
)

App(
appid="totp_cli_notification_plugin",
apptype=FlipperAppType.PLUGIN,
entry_point="totp_cli_notification_plugin_ep",
requires=["totp"],
sources=[
"cli/plugins/notification/notification.c",
"cli/cli_shared_methods.c"],
)
55 changes: 55 additions & 0 deletions assets/cli/cli_help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Usage:
totp (help | h | ?)
totp version
totp (list | ls)
totp (lsattr | cat) <index>
totp (add | mk | new) <name> [-a <algo>] [-e <encoding>] [-d <digits>] [-l <duration>] [-u] [-b <feature>]...
totp (update) <index> [-a <algo>] [-e <encoding>] [-n <name>] [-d <digits>] [-l <duration>] [-u] [-s] [-b <feature>]...
totp (delete | rm) <index> [-f]
totp (move | mv) <index> <new_index>
totp pin (set | remove) [-c <slot>]
totp notify [<notification>...]
totp (timezone | tz) [<timezone>]
totp reset
totp automation [-k <layout>] [<automation>...]

Commands:
help, h, ? Show command usage help
version Get application version
list, ls List all available tokens
lsattr, cat Displays token details
add, mk, new Add new token
update Update existing token
delete, rm Delete existing token
move, mv Move token
pin Set\change\remove PIN
notify Get or set notification method
timezone, tz Get or set current timezone
reset Reset application to default settings
automation Get or set automation settings

Arguments:
name Token name
index Token index in the list
new_index New token index in the list
notification Notification method to be set. Must be one of: none, sound, vibro
timezone Timezone offset in hours to be set
automation Automation method to be set. Must be one of: none, usb, bt

Options:
-a <algo> Token hashing algorithm. Must be one of: sha1, sha256, sha512, steam [default: sha1]
-d <digits> Number of digits to generate, one of: 5, 6, 8 [default: 6]
-e <encoding> Token secret encoding, one of base32, base64 [default: base32]
-l <duration> Token lifetime duration in seconds, between: 15 and 255 [default: 30]
-u Show console user input as-is without masking
-b <feature> Token automation features to be enabled. Must be one of: none, enter, tab [default: none]
# none - No features
# enter - Type <Enter> key at the end of token input automation
# tab - Type <Tab> key at the end of token input automation
# slower - Type slower
-n <name> Token name
-s Update token secret
-f Force command to do not ask user for interactive confirmation
-c <slot> New crypto key slot. Must be between 12 and 100
-k <layout> Automation keyboard layout. Must be one of: QWERTY, AZERTY, QWERTZ

Loading

0 comments on commit 6513672

Please sign in to comment.