Skip to content

Commit

Permalink
upd totp
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Feb 20, 2024
1 parent 3d5cbb3 commit 94ec628
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 192 deletions.
2 changes: 1 addition & 1 deletion base_pack/totp/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ App(
requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
stack_size=2 * 1024,
order=20,
fap_version="5.110",
fap_version="5.120",
fap_author="Alexander Kopachov (@akopachov)",
fap_description="Software-based TOTP/HOTP authenticator for Flipper Zero device",
fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",
Expand Down
118 changes: 59 additions & 59 deletions base_pack/totp/assets/cli/cli_help.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
Usage:
totp (help | h | ?)
totp version
totp (list | ls)
totp (lsattr | cat) <index>
totp (add | mk | new) <name> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-d <digits>] [-l <duration>] [-u] [-b <feature>]...
totp (update) <index> [-t <type>] [-i <counter>] [-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>] [-w <delay>] [<automation>...]
totp export
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
export Exports and prints all the tokens into URI-list format
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:
-t <type> Token type. Must be one of: totp, hotp [default: totp]
-i <counter> Token initial counter. Applicable for HOTP tokens only. Must be positive integer number [default: 0]
-a <algo> Token hashing algorithm. Must be one of: sha1, sha256, sha512, steam [default: sha1]
-d <digits> Token digits count. Must be 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. Applicable for TOTP tokens only. Must be 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, Czech, Dvorak, Hungarian, Slovak
-w <delay> Automation initial delay in seconds. Must be positive float value [default: 0.5]
Usage:
totp (help | h | ?)
totp version
totp (list | ls)
totp (lsattr | cat) <index>
totp (add | mk | new) <name> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-d <digits>] [-l <duration>] [-u] [-b <feature>]...
totp (update) <index> [-t <type>] [-i <counter>] [-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>] [-w <delay>] [<automation>...]
totp export

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
export Exports and prints all the tokens into URI-list format

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:
-t <type> Token type. Must be one of: totp, hotp [default: totp]
-i <counter> Token initial counter. Applicable for HOTP tokens only. Must be positive integer number [default: 0]
-a <algo> Token hashing algorithm. Must be one of: sha1, sha256, sha512, steam [default: sha1]
-d <digits> Token digits count. Must be 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. Applicable for TOTP tokens only. Must be 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, Czech, Dvorak, Hungarian, Slovak
-w <delay> Automation initial delay in seconds. Must be positive float value [default: 0.5]
12 changes: 8 additions & 4 deletions base_pack/totp/services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,19 @@ bool totp_config_file_ensure_latest_encryption(
uint8_t pin_length) {
bool result = true;
if(plugin_state->crypto_settings.crypto_version < CRYPTO_LATEST_VERSION) {
FURI_LOG_I(LOGGING_TAG, "Migration crypto from v%" PRIu8 " to v%" PRIu8 " is needed", plugin_state->crypto_settings.crypto_version, CRYPTO_LATEST_VERSION);

FURI_LOG_I(
LOGGING_TAG,
"Migration crypto from v%" PRIu8 " to v%" PRIu8 " is needed",
plugin_state->crypto_settings.crypto_version,
CRYPTO_LATEST_VERSION);

#ifndef TOTP_OBSOLETE_CRYPTO_V1_COMPATIBILITY_ENABLED
if (plugin_state->crypto_settings.crypto_version == 1) {
if(plugin_state->crypto_settings.crypto_version == 1) {
furi_crash("Authenticator: Crypto v1 is not supported");
}
#endif
#ifndef TOTP_OBSOLETE_CRYPTO_V2_COMPATIBILITY_ENABLED
if (plugin_state->crypto_settings.crypto_version == 2) {
if(plugin_state->crypto_settings.crypto_version == 2) {
furi_crash("Authenticator: Crypto v2 is not supported");
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion base_pack/totp/services/idle_timeout/idle_timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <furi/core/timer.h>

#define IDLE_TIMER_CHECK_PERIODICITY_SEC (1)
#define SEC_TO_TICKS(sec) ((sec)*1000)
#define SEC_TO_TICKS(sec) ((sec) * 1000)

struct IdleTimeoutContext {
FuriTimer* timer;
Expand Down
3 changes: 2 additions & 1 deletion base_pack/totp/totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {

#ifdef TOTP_BADBT_AUTOMATION_ENABLED
if(plugin_state->automation_method & AutomationMethodBadBt) {
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init();
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init(
*((uint16_t*)plugin_state->crypto_settings.crypto_verify_data));
} else {
plugin_state->bt_type_code_worker_context = NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions base_pack/totp/types/token_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "common.h"
#include "../services/crypto/crypto_facade.h"

#define ESTIMATE_BASE32_PLAIN_LENGTH(base32_length) ((base32_length)*0.625f)
#define ESTIMATE_BASE64_PLAIN_LENGTH(base64_length) ((base64_length)*0.75f)
#define ESTIMATE_BASE32_PLAIN_LENGTH(base32_length) ((base32_length) * 0.625f)
#define ESTIMATE_BASE64_PLAIN_LENGTH(base64_length) ((base64_length) * 0.75f)

TokenInfo* token_info_alloc() {
TokenInfo* tokenInfo = malloc(sizeof(TokenInfo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) {

if(plugin_state->automation_method & AutomationMethodBadBt) {
if(plugin_state->bt_type_code_worker_context == NULL) {
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init();
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init(
*((uint16_t*)plugin_state->crypto_settings.crypto_verify_data));
}
totp_bt_type_code_worker_start(
plugin_state->bt_type_code_worker_context,
Expand Down
2 changes: 1 addition & 1 deletion base_pack/totp/version.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#define TOTP_APP_VERSION_MAJOR (5)
#define TOTP_APP_VERSION_MINOR (11)
#define TOTP_APP_VERSION_MINOR (12)
#define TOTP_APP_VERSION_PATCH (0)
49 changes: 21 additions & 28 deletions base_pack/totp/workers/bt_type_code/bt_type_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ struct TotpBtTypeCodeWorkerContext {
FuriThread* thread;
FuriMutex* code_buffer_sync;
Bt* bt;
FuriHalBleProfileBase* ble_hid_profile;
bool is_advertising;
bool is_connected;
FuriHalBleProfileBase* ble_hid_profile;
AutomationKeyboardLayout keyboard_layout;
uint16_t initial_delay;
};
Expand All @@ -34,23 +34,15 @@ static inline bool totp_type_code_worker_stop_requested() {
return furi_thread_flags_get() & TotpBtTypeCodeWorkerEventStop;
}

// static void totp_type_code_worker_bt_set_app_mac(uint8_t* mac) {
// uint8_t max_i;
// size_t uid_size = furi_hal_version_uid_size();
// if(uid_size < TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN) {
// max_i = uid_size;
// } else {
// max_i = TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN;
// }

// const uint8_t* uid = (const uint8_t*)UID64_BASE; //-V566
// memcpy(mac, uid, max_i);
// for(uint8_t i = max_i; i < TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN; i++) {
// mac[i] = 0;
// }
static bool hid_key_press(uint16_t button, void* context) {
FuriHalBleProfileBase* profile = context;
return ble_profile_hid_kb_press(profile, button);
}

// mac[0] = 0b10;
// }
static bool hid_key_release(uint16_t button, void* context) {
FuriHalBleProfileBase* profile = context;
return ble_profile_hid_kb_release(profile, button);
}

static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context) {
uint8_t i = 0;
Expand All @@ -61,15 +53,15 @@ static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context

if(context->is_connected &&
furi_mutex_acquire(context->code_buffer_sync, 500) == FuriStatusOk) {
totp_type_code_worker_execute_automation_ctx(
(TOTP_AUTOMATION_KEY_HANDLER_CTX)&ble_profile_hid_kb_press,
(TOTP_AUTOMATION_KEY_HANDLER_CTX)&ble_profile_hid_kb_release,
context->ble_hid_profile,
totp_type_code_worker_execute_automation(
&hid_key_press,
&hid_key_release,
context->code_buffer,
context->code_buffer_size,
context->flags,
context->keyboard_layout,
context->initial_delay);
context->initial_delay,
context->ble_hid_profile);
furi_mutex_release(context->code_buffer_sync);
}
}
Expand Down Expand Up @@ -149,7 +141,7 @@ void totp_bt_type_code_worker_notify(
furi_thread_flags_set(furi_thread_get_id(context->thread), event);
}

TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init(uint16_t mac_xor) {
TotpBtTypeCodeWorkerContext* context = malloc(sizeof(TotpBtTypeCodeWorkerContext));
furi_check(context != NULL);

Expand All @@ -160,10 +152,8 @@ TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
furi_delay_ms(200);
bt_keys_storage_set_storage_path(context->bt, HID_BT_KEYS_STORAGE_PATH);

BleProfileHidParams params = {
.device_name_prefix = "TOTP",
};
context->ble_hid_profile = bt_profile_start(context->bt, ble_profile_hid, &params);
BleProfileHidParams ble_params = {.device_name_prefix = "TOTP", .mac_xor = mac_xor};
context->ble_hid_profile = bt_profile_start(context->bt, ble_profile_hid, &ble_params);
furi_check(context->ble_hid_profile);

furi_hal_bt_start_advertising();
Expand All @@ -183,14 +173,17 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {

bt_set_status_changed_callback(context->bt, NULL, NULL);

furi_hal_bt_stop_advertising();
context->is_advertising = false;
context->is_connected = false;

bt_disconnect(context->bt);
furi_delay_ms(200);
bt_keys_storage_set_default_path(context->bt);
if(!bt_profile_restore_default(context->bt)) {
FURI_LOG_E(LOGGING_TAG, "Failed to restore to default BT profile");
}

furi_check(bt_profile_restore_default(context->bt));
furi_record_close(RECORD_BT);
context->bt = NULL;

Expand Down
3 changes: 2 additions & 1 deletion base_pack/totp/workers/bt_type_code/bt_type_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ enum TotpBtTypeCodeWorkerEvents {

/**
* @brief Initializes bluetooth token input automation worker
* @param mac_xor value to be used to XOR BT MAC address to make it unique
* @return worker context
*/
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init();
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init(uint16_t mac_xor);

/**
* @brief Disposes bluetooth token input automation worker and releases all the allocated resources
Expand Down
Loading

0 comments on commit 94ec628

Please sign in to comment.