Skip to content

Commit 94ec628

Browse files
committed
upd totp
1 parent 3d5cbb3 commit 94ec628

File tree

13 files changed

+128
-192
lines changed

13 files changed

+128
-192
lines changed

base_pack/totp/application.fam

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ App(
77
requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
88
stack_size=2 * 1024,
99
order=20,
10-
fap_version="5.110",
10+
fap_version="5.120",
1111
fap_author="Alexander Kopachov (@akopachov)",
1212
fap_description="Software-based TOTP/HOTP authenticator for Flipper Zero device",
1313
fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",
+59-59
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
Usage:
2-
totp (help | h | ?)
3-
totp version
4-
totp (list | ls)
5-
totp (lsattr | cat) <index>
6-
totp (add | mk | new) <name> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-d <digits>] [-l <duration>] [-u] [-b <feature>]...
7-
totp (update) <index> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-n <name>] [-d <digits>] [-l <duration>] [-u] [-s] [-b <feature>]...
8-
totp (delete | rm) <index> [-f]
9-
totp (move | mv) <index> <new_index>
10-
totp pin (set | remove) [-c <slot>]
11-
totp notify [<notification>...]
12-
totp (timezone | tz) [<timezone>]
13-
totp reset
14-
totp automation [-k <layout>] [-w <delay>] [<automation>...]
15-
totp export
16-
17-
Commands:
18-
help, h, ? Show command usage help
19-
version Get application version
20-
list, ls List all available tokens
21-
lsattr, cat Displays token details
22-
add, mk, new Add new token
23-
update Update existing token
24-
delete, rm Delete existing token
25-
move, mv Move token
26-
pin Set\change\remove PIN
27-
notify Get or set notification method
28-
timezone, tz Get or set current timezone
29-
reset Reset application to default settings
30-
automation Get or set automation settings
31-
export Exports and prints all the tokens into URI-list format
32-
33-
Arguments:
34-
name Token name
35-
index Token index in the list
36-
new_index New token index in the list
37-
notification Notification method to be set. Must be one of: none, sound, vibro
38-
timezone Timezone offset in hours to be set
39-
automation Automation method to be set. Must be one of: none, usb, bt
40-
41-
Options:
42-
-t <type> Token type. Must be one of: totp, hotp [default: totp]
43-
-i <counter> Token initial counter. Applicable for HOTP tokens only. Must be positive integer number [default: 0]
44-
-a <algo> Token hashing algorithm. Must be one of: sha1, sha256, sha512, steam [default: sha1]
45-
-d <digits> Token digits count. Must be one of: 5, 6, 8 [default: 6]
46-
-e <encoding> Token secret encoding, one of base32, base64 [default: base32]
47-
-l <duration> Token lifetime duration in seconds. Applicable for TOTP tokens only. Must be between: 15 and 255 [default: 30]
48-
-u Show console user input as-is without masking
49-
-b <feature> Token automation features to be enabled. Must be one of: none, enter, tab [default: none]
50-
# none - No features
51-
# enter - Type <Enter> key at the end of token input automation
52-
# tab - Type <Tab> key at the end of token input automation
53-
# slower - Type slower
54-
-n <name> Token name
55-
-s Update token secret
56-
-f Force command to do not ask user for interactive confirmation
57-
-c <slot> New crypto key slot. Must be between 12 and 100
58-
-k <layout> Automation keyboard layout. Must be one of: QWERTY, AZERTY, QWERTZ, Czech, Dvorak, Hungarian, Slovak
59-
-w <delay> Automation initial delay in seconds. Must be positive float value [default: 0.5]
1+
Usage:
2+
totp (help | h | ?)
3+
totp version
4+
totp (list | ls)
5+
totp (lsattr | cat) <index>
6+
totp (add | mk | new) <name> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-d <digits>] [-l <duration>] [-u] [-b <feature>]...
7+
totp (update) <index> [-t <type>] [-i <counter>] [-a <algo>] [-e <encoding>] [-n <name>] [-d <digits>] [-l <duration>] [-u] [-s] [-b <feature>]...
8+
totp (delete | rm) <index> [-f]
9+
totp (move | mv) <index> <new_index>
10+
totp pin (set | remove) [-c <slot>]
11+
totp notify [<notification>...]
12+
totp (timezone | tz) [<timezone>]
13+
totp reset
14+
totp automation [-k <layout>] [-w <delay>] [<automation>...]
15+
totp export
16+
17+
Commands:
18+
help, h, ? Show command usage help
19+
version Get application version
20+
list, ls List all available tokens
21+
lsattr, cat Displays token details
22+
add, mk, new Add new token
23+
update Update existing token
24+
delete, rm Delete existing token
25+
move, mv Move token
26+
pin Set\change\remove PIN
27+
notify Get or set notification method
28+
timezone, tz Get or set current timezone
29+
reset Reset application to default settings
30+
automation Get or set automation settings
31+
export Exports and prints all the tokens into URI-list format
32+
33+
Arguments:
34+
name Token name
35+
index Token index in the list
36+
new_index New token index in the list
37+
notification Notification method to be set. Must be one of: none, sound, vibro
38+
timezone Timezone offset in hours to be set
39+
automation Automation method to be set. Must be one of: none, usb, bt
40+
41+
Options:
42+
-t <type> Token type. Must be one of: totp, hotp [default: totp]
43+
-i <counter> Token initial counter. Applicable for HOTP tokens only. Must be positive integer number [default: 0]
44+
-a <algo> Token hashing algorithm. Must be one of: sha1, sha256, sha512, steam [default: sha1]
45+
-d <digits> Token digits count. Must be one of: 5, 6, 8 [default: 6]
46+
-e <encoding> Token secret encoding, one of base32, base64 [default: base32]
47+
-l <duration> Token lifetime duration in seconds. Applicable for TOTP tokens only. Must be between: 15 and 255 [default: 30]
48+
-u Show console user input as-is without masking
49+
-b <feature> Token automation features to be enabled. Must be one of: none, enter, tab [default: none]
50+
# none - No features
51+
# enter - Type <Enter> key at the end of token input automation
52+
# tab - Type <Tab> key at the end of token input automation
53+
# slower - Type slower
54+
-n <name> Token name
55+
-s Update token secret
56+
-f Force command to do not ask user for interactive confirmation
57+
-c <slot> New crypto key slot. Must be between 12 and 100
58+
-k <layout> Automation keyboard layout. Must be one of: QWERTY, AZERTY, QWERTZ, Czech, Dvorak, Hungarian, Slovak
59+
-w <delay> Automation initial delay in seconds. Must be positive float value [default: 0.5]

base_pack/totp/services/config/config.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,19 @@ bool totp_config_file_ensure_latest_encryption(
738738
uint8_t pin_length) {
739739
bool result = true;
740740
if(plugin_state->crypto_settings.crypto_version < CRYPTO_LATEST_VERSION) {
741-
FURI_LOG_I(LOGGING_TAG, "Migration crypto from v%" PRIu8 " to v%" PRIu8 " is needed", plugin_state->crypto_settings.crypto_version, CRYPTO_LATEST_VERSION);
742-
741+
FURI_LOG_I(
742+
LOGGING_TAG,
743+
"Migration crypto from v%" PRIu8 " to v%" PRIu8 " is needed",
744+
plugin_state->crypto_settings.crypto_version,
745+
CRYPTO_LATEST_VERSION);
746+
743747
#ifndef TOTP_OBSOLETE_CRYPTO_V1_COMPATIBILITY_ENABLED
744-
if (plugin_state->crypto_settings.crypto_version == 1) {
748+
if(plugin_state->crypto_settings.crypto_version == 1) {
745749
furi_crash("Authenticator: Crypto v1 is not supported");
746750
}
747751
#endif
748752
#ifndef TOTP_OBSOLETE_CRYPTO_V2_COMPATIBILITY_ENABLED
749-
if (plugin_state->crypto_settings.crypto_version == 2) {
753+
if(plugin_state->crypto_settings.crypto_version == 2) {
750754
furi_crash("Authenticator: Crypto v2 is not supported");
751755
}
752756
#endif

base_pack/totp/services/idle_timeout/idle_timeout.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <furi/core/timer.h>
44

55
#define IDLE_TIMER_CHECK_PERIODICITY_SEC (1)
6-
#define SEC_TO_TICKS(sec) ((sec)*1000)
6+
#define SEC_TO_TICKS(sec) ((sec) * 1000)
77

88
struct IdleTimeoutContext {
99
FuriTimer* timer;

base_pack/totp/totp_app.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
166166

167167
#ifdef TOTP_BADBT_AUTOMATION_ENABLED
168168
if(plugin_state->automation_method & AutomationMethodBadBt) {
169-
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init();
169+
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init(
170+
*((uint16_t*)plugin_state->crypto_settings.crypto_verify_data));
170171
} else {
171172
plugin_state->bt_type_code_worker_context = NULL;
172173
}

base_pack/totp/types/token_info.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include "common.h"
99
#include "../services/crypto/crypto_facade.h"
1010

11-
#define ESTIMATE_BASE32_PLAIN_LENGTH(base32_length) ((base32_length)*0.625f)
12-
#define ESTIMATE_BASE64_PLAIN_LENGTH(base64_length) ((base64_length)*0.75f)
11+
#define ESTIMATE_BASE32_PLAIN_LENGTH(base32_length) ((base32_length) * 0.625f)
12+
#define ESTIMATE_BASE64_PLAIN_LENGTH(base64_length) ((base64_length) * 0.75f)
1313

1414
TokenInfo* token_info_alloc() {
1515
TokenInfo* tokenInfo = malloc(sizeof(TokenInfo));

base_pack/totp/ui/scenes/generate_token/totp_scene_generate_token.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) {
201201

202202
if(plugin_state->automation_method & AutomationMethodBadBt) {
203203
if(plugin_state->bt_type_code_worker_context == NULL) {
204-
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init();
204+
plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init(
205+
*((uint16_t*)plugin_state->crypto_settings.crypto_verify_data));
205206
}
206207
totp_bt_type_code_worker_start(
207208
plugin_state->bt_type_code_worker_context,

base_pack/totp/version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
22

33
#define TOTP_APP_VERSION_MAJOR (5)
4-
#define TOTP_APP_VERSION_MINOR (11)
4+
#define TOTP_APP_VERSION_MINOR (12)
55
#define TOTP_APP_VERSION_PATCH (0)

base_pack/totp/workers/bt_type_code/bt_type_code.c

+21-28
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ struct TotpBtTypeCodeWorkerContext {
2323
FuriThread* thread;
2424
FuriMutex* code_buffer_sync;
2525
Bt* bt;
26+
FuriHalBleProfileBase* ble_hid_profile;
2627
bool is_advertising;
2728
bool is_connected;
28-
FuriHalBleProfileBase* ble_hid_profile;
2929
AutomationKeyboardLayout keyboard_layout;
3030
uint16_t initial_delay;
3131
};
@@ -34,23 +34,15 @@ static inline bool totp_type_code_worker_stop_requested() {
3434
return furi_thread_flags_get() & TotpBtTypeCodeWorkerEventStop;
3535
}
3636

37-
// static void totp_type_code_worker_bt_set_app_mac(uint8_t* mac) {
38-
// uint8_t max_i;
39-
// size_t uid_size = furi_hal_version_uid_size();
40-
// if(uid_size < TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN) {
41-
// max_i = uid_size;
42-
// } else {
43-
// max_i = TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN;
44-
// }
45-
46-
// const uint8_t* uid = (const uint8_t*)UID64_BASE; //-V566
47-
// memcpy(mac, uid, max_i);
48-
// for(uint8_t i = max_i; i < TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN; i++) {
49-
// mac[i] = 0;
50-
// }
37+
static bool hid_key_press(uint16_t button, void* context) {
38+
FuriHalBleProfileBase* profile = context;
39+
return ble_profile_hid_kb_press(profile, button);
40+
}
5141

52-
// mac[0] = 0b10;
53-
// }
42+
static bool hid_key_release(uint16_t button, void* context) {
43+
FuriHalBleProfileBase* profile = context;
44+
return ble_profile_hid_kb_release(profile, button);
45+
}
5446

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

6254
if(context->is_connected &&
6355
furi_mutex_acquire(context->code_buffer_sync, 500) == FuriStatusOk) {
64-
totp_type_code_worker_execute_automation_ctx(
65-
(TOTP_AUTOMATION_KEY_HANDLER_CTX)&ble_profile_hid_kb_press,
66-
(TOTP_AUTOMATION_KEY_HANDLER_CTX)&ble_profile_hid_kb_release,
67-
context->ble_hid_profile,
56+
totp_type_code_worker_execute_automation(
57+
&hid_key_press,
58+
&hid_key_release,
6859
context->code_buffer,
6960
context->code_buffer_size,
7061
context->flags,
7162
context->keyboard_layout,
72-
context->initial_delay);
63+
context->initial_delay,
64+
context->ble_hid_profile);
7365
furi_mutex_release(context->code_buffer_sync);
7466
}
7567
}
@@ -149,7 +141,7 @@ void totp_bt_type_code_worker_notify(
149141
furi_thread_flags_set(furi_thread_get_id(context->thread), event);
150142
}
151143

152-
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
144+
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init(uint16_t mac_xor) {
153145
TotpBtTypeCodeWorkerContext* context = malloc(sizeof(TotpBtTypeCodeWorkerContext));
154146
furi_check(context != NULL);
155147

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

163-
BleProfileHidParams params = {
164-
.device_name_prefix = "TOTP",
165-
};
166-
context->ble_hid_profile = bt_profile_start(context->bt, ble_profile_hid, &params);
155+
BleProfileHidParams ble_params = {.device_name_prefix = "TOTP", .mac_xor = mac_xor};
156+
context->ble_hid_profile = bt_profile_start(context->bt, ble_profile_hid, &ble_params);
167157
furi_check(context->ble_hid_profile);
168158

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

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

176+
furi_hal_bt_stop_advertising();
186177
context->is_advertising = false;
187178
context->is_connected = false;
188179

189180
bt_disconnect(context->bt);
190181
furi_delay_ms(200);
191182
bt_keys_storage_set_default_path(context->bt);
183+
if(!bt_profile_restore_default(context->bt)) {
184+
FURI_LOG_E(LOGGING_TAG, "Failed to restore to default BT profile");
185+
}
192186

193-
furi_check(bt_profile_restore_default(context->bt));
194187
furi_record_close(RECORD_BT);
195188
context->bt = NULL;
196189

base_pack/totp/workers/bt_type_code/bt_type_code.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ enum TotpBtTypeCodeWorkerEvents {
3636

3737
/**
3838
* @brief Initializes bluetooth token input automation worker
39+
* @param mac_xor value to be used to XOR BT MAC address to make it unique
3940
* @return worker context
4041
*/
41-
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init();
42+
TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init(uint16_t mac_xor);
4243

4344
/**
4445
* @brief Disposes bluetooth token input automation worker and releases all the allocated resources

0 commit comments

Comments
 (0)