Skip to content

Commit 4548c3b

Browse files
authored
Implemented #30 (#31)
1 parent 68f0a34 commit 4548c3b

11 files changed

+53
-48
lines changed

.gitmodules

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
[submodule "flipperzero-firmware_unleashed"]
2-
path = flipperzero-firmware_unleashed
3-
url = https://github.com/Eng1n33r/flipperzero-firmware.git
4-
branch = dev
5-
ignore = dirty
61
[submodule "flipperzero-firmware_official_dev"]
72
path = flipperzero-firmware_official_dev
83
url = https://github.com/flipperdevices/flipperzero-firmware.git

.pvsoptions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--rules-config .pvsconfig -e flipperzero-firmware_unleashed -e flipperzero-firmware_official
1+
--rules-config .pvsconfig -e flipperzero-firmware_official_dev -e flipperzero-firmware_official_stable

FAQ.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Detailed description of file format can be found [here](docs/conf-file_descripti
3030

3131
When Flipper Authenticator is running `totp` CLI is available for you to list, add or remove tokens. Run `totp help` to get list of available commands and arguments.
3232

33-
## Manually typing codes is boring, is there Bad USB mode?
33+
## Manually typing codes is boring, is there a Bad USB mode?
3434

3535
**YES!**
3636

37-
Just pick the token you would like to auto-type then hold "arrow down" button for 1-2sec. and Flipper Authenticator will type it instead of you :)
37+
Just pick the token you would like to auto-type then hold "arrow down" button for 1-2sec. and Flipper Authenticator will type it instead of you 😀
3838

3939
## How to change\recover PIN?
4040

@@ -54,7 +54,7 @@ Flipper Zero clock has known clock drift problem. So there is a chance that cloc
5454

5555
### Timezone is not correct
5656

57-
Because of Flipper Zero API doesn't provide an access to timezone offset it is necessary to set it manually for correct TOTP tokens generation. You may find you timezone offset (or another name is "UTC offset") [here](https://www.timeanddate.com/time/zone/timezone/utc) or on any other website found in google. Then set it either in [conf file](docs/conf-file_description.md) or via setting menu of Flipper Authenticator.
57+
Because of Flipper Zero API doesn't provide an access to timezone offset it is necessary to set it manually for correct TOTP tokens generation. You may find you timezone offset (or another name is "UTC offset") [here](https://www.timeanddate.com/time/zone/timezone/utc) or on any other website found in google. Then set it in [conf file](docs/conf-file_description.md) or via setting menu of Flipper Authenticator or using CLI command `totp tz`.
5858

5959
### Token secret is not correct
6060

build.ps1

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ $build_commands = @(
1111
Name = "Official Dev";
1212
FbtSwitch = "od";
1313
FirmwarePath = "flipperzero-firmware_official_dev";
14-
ArtifactName = "totp_official-dev-fw.fap"
14+
ArtifactName = "totp_official-dev_unleashed_fw.fap"
1515
}
1616
[PSCustomObject]@{
1717
Name = "Official Stable";
1818
FbtSwitch = "os";
1919
FirmwarePath = "flipperzero-firmware_official_stable";
20-
ArtifactName = "totp_official-stable-fw.fap"
21-
}
22-
[PSCustomObject]@{
23-
Name = "Unleashed";
24-
FbtSwitch = "u";
25-
FirmwarePath = "flipperzero-firmware_unleashed";
26-
ArtifactName = "totp_unleashed-fw.fap"
20+
ArtifactName = "totp_official-stable_fw.fap"
2721
}
2822
)
2923

clang-format-all.ps1

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
Get-ChildItem -Path "totp" -Directory -Recurse | ForEach-Object {
2-
if ((Test-Path "$($_.FullName)/*.c") -or (Test-Path "$($_.FullName)/*.h")) {
3-
Push-Location $_.FullName
4-
Write-Host "Processing $($_.FullName)"
5-
&clang-format -i -style=file *.c *.h
6-
Pop-Location
7-
}
8-
9-
}
1+
$clang_format = Join-Path -Path $PSScriptRoot -ChildPath "flipperzero-firmware_unleashed/toolchain/x86_64-windows/bin/clang-format.exe"
2+
Push-Location $PSScriptRoot
3+
Get-ChildItem -Path "totp" -File -Recurse -Include "*.c", "*.h" | ForEach-Object {
4+
Write-Host "Formatting $($_.FullName)"
5+
& $clang_format -i -style=file $_.FullName
6+
}
7+
Pop-Location

fbt.ps1

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ Push-Location $PSScriptRoot
22

33
$firmware_path = ""
44
$firmware_name = ""
5-
if (('official-dev', 'off-dev', 'od').Contains($args[0])) {
5+
if (('official-dev', 'off-dev', 'od', 'unleashed', 'un', 'u').Contains($args[0])) {
66
$firmware_path = "flipperzero-firmware_official_dev"
77
$firmware_name = "Official Dev"
88
}
99
elseif (('official-stable', 'off-stbl', 'os').Contains($args[0])) {
1010
$firmware_path = "flipperzero-firmware_official_stable"
1111
$firmware_name = "Official Stable"
1212
}
13-
elseif (('unleashed', 'un', 'u').Contains($args[0])) {
14-
$firmware_path = "flipperzero-firmware_unleashed"
15-
$firmware_name = "Unleashed"
16-
}
1713
else {
1814
throw "Unable to recognize which firmware to use"
1915
}

flipperzero-firmware_unleashed

-1
This file was deleted.

pvs-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
pushd flipperzero-firmware_unleashed
3+
pushd flipperzero-firmware_official_dev
44
rm -rf applications/plugins/totp
55
sed -i 's/applications_user/../' site_scons/commandline.scons
66
./fbt fap_totp

sonar-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
pushd flipperzero-firmware_unleashed
3+
pushd flipperzero-firmware_official_dev
44
rm -rf applications/plugins/totp
55
sed -i 's/applications_user/../' site_scons/commandline.scons
66
./fbt fap_totp

totp/services/cli/cli_helpers.h

+7
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@
3737
TOTP_CLI_PRINTF( \
3838
"Invalid command arguments. use \"help\" command to get list of available commands")
3939

40+
/**
41+
* @brief Checks whether user is authenticated and entered correct PIN.
42+
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
43+
* @param plugin_state application state
44+
* @param cli reference to the firmware CLI subsystem
45+
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
46+
*/
4047
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);

totp/totp_app.c

+30-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
static void render_callback(Canvas* const canvas, void* ctx) {
2626
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
27-
if (plugin_state != NULL && !plugin_state->changing_scene) {
27+
if(plugin_state != NULL && !plugin_state->changing_scene) {
2828
totp_scene_director_render(canvas, plugin_state);
2929
}
3030

@@ -49,29 +49,43 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
4949

5050
totp_scene_director_init_scenes(plugin_state);
5151

52-
if (plugin_state->crypto_verify_data == NULL) {
52+
if(plugin_state->crypto_verify_data == NULL) {
5353
DialogMessage* message = dialog_message_alloc();
5454
dialog_message_set_buttons(message, "No", NULL, "Yes");
55-
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
55+
dialog_message_set_text(
56+
message,
57+
"Would you like to setup PIN?",
58+
SCREEN_WIDTH_CENTER,
59+
SCREEN_HEIGHT_CENTER,
60+
AlignCenter,
61+
AlignCenter);
5662
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
5763
dialog_message_free(message);
58-
if (dialog_result == DialogMessageButtonRight) {
64+
if(dialog_result == DialogMessageButtonRight) {
5965
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
6066
} else {
6167
totp_crypto_seed_iv(plugin_state, NULL, 0);
6268
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
6369
}
64-
} else if (plugin_state->pin_set) {
70+
} else if(plugin_state->pin_set) {
6571
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
6672
} else {
6773
totp_crypto_seed_iv(plugin_state, NULL, 0);
68-
if (totp_crypto_verify_key(plugin_state)) {
74+
if(totp_crypto_verify_key(plugin_state)) {
6975
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
7076
} else {
71-
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
77+
FURI_LOG_E(
78+
LOGGING_TAG,
79+
"Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
7280
DialogMessage* message = dialog_message_alloc();
7381
dialog_message_set_buttons(message, "Exit", NULL, NULL);
74-
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
82+
dialog_message_set_text(
83+
message,
84+
"Digital signature verification failed",
85+
SCREEN_WIDTH_CENTER,
86+
SCREEN_HEIGHT_CENTER,
87+
AlignCenter,
88+
AlignCenter);
7589
dialog_message_show(plugin_state->dialogs, message);
7690
dialog_message_free(message);
7791
return false;
@@ -94,15 +108,15 @@ static void totp_plugin_state_free(PluginState* plugin_state) {
94108

95109
ListNode* node = plugin_state->tokens_list;
96110
ListNode* tmp;
97-
while (node != NULL) {
111+
while(node != NULL) {
98112
tmp = node->next;
99113
TokenInfo* tokenInfo = node->data;
100114
token_info_free(tokenInfo);
101115
free(node);
102116
node = tmp;
103117
}
104118

105-
if (plugin_state->crypto_verify_data != NULL) {
119+
if(plugin_state->crypto_verify_data != NULL) {
106120
free(plugin_state->crypto_verify_data);
107121
}
108122
free(plugin_state);
@@ -113,7 +127,7 @@ int32_t totp_app() {
113127
PluginState* plugin_state = malloc(sizeof(PluginState));
114128
furi_check(plugin_state != NULL);
115129

116-
if (!totp_plugin_state_init(plugin_state)) {
130+
if(!totp_plugin_state_init(plugin_state)) {
117131
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
118132
totp_plugin_state_free(plugin_state);
119133
return 254;
@@ -138,18 +152,20 @@ int32_t totp_app() {
138152
bool processing = true;
139153
uint32_t last_user_interaction_time = furi_get_tick();
140154
while(processing) {
141-
if (plugin_state->changing_scene) continue;
155+
if(plugin_state->changing_scene) continue;
142156
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
143157

144158
PluginState* plugin_state_m = acquire_mutex_block(&state_mutex);
145159

146160
if(event_status == FuriStatusOk) {
147-
if (event.type == EventTypeKey) {
161+
if(event.type == EventTypeKey) {
148162
last_user_interaction_time = furi_get_tick();
149163
}
150164

151165
processing = totp_scene_director_handle_event(&event, plugin_state_m);
152-
} else if (plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
166+
} else if(
167+
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication &&
168+
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
153169
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL);
154170
}
155171

0 commit comments

Comments
 (0)