Skip to content

Commit

Permalink
Implemented #30 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Nov 18, 2022
1 parent 68f0a34 commit 4548c3b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 48 deletions.
5 changes: 0 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[submodule "flipperzero-firmware_unleashed"]
path = flipperzero-firmware_unleashed
url = https://github.com/Eng1n33r/flipperzero-firmware.git
branch = dev
ignore = dirty
[submodule "flipperzero-firmware_official_dev"]
path = flipperzero-firmware_official_dev
url = https://github.com/flipperdevices/flipperzero-firmware.git
Expand Down
2 changes: 1 addition & 1 deletion .pvsoptions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--rules-config .pvsconfig -e flipperzero-firmware_unleashed -e flipperzero-firmware_official
--rules-config .pvsconfig -e flipperzero-firmware_official_dev -e flipperzero-firmware_official_stable
6 changes: 3 additions & 3 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Detailed description of file format can be found [here](docs/conf-file_descripti

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.

## Manually typing codes is boring, is there Bad USB mode?
## Manually typing codes is boring, is there a Bad USB mode?

**YES!**

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 :)
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 😀

## How to change\recover PIN?

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

### Timezone is not correct

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.
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`.

### Token secret is not correct

Expand Down
10 changes: 2 additions & 8 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ $build_commands = @(
Name = "Official Dev";
FbtSwitch = "od";
FirmwarePath = "flipperzero-firmware_official_dev";
ArtifactName = "totp_official-dev-fw.fap"
ArtifactName = "totp_official-dev_unleashed_fw.fap"
}
[PSCustomObject]@{
Name = "Official Stable";
FbtSwitch = "os";
FirmwarePath = "flipperzero-firmware_official_stable";
ArtifactName = "totp_official-stable-fw.fap"
}
[PSCustomObject]@{
Name = "Unleashed";
FbtSwitch = "u";
FirmwarePath = "flipperzero-firmware_unleashed";
ArtifactName = "totp_unleashed-fw.fap"
ArtifactName = "totp_official-stable_fw.fap"
}
)

Expand Down
16 changes: 7 additions & 9 deletions clang-format-all.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Get-ChildItem -Path "totp" -Directory -Recurse | ForEach-Object {
if ((Test-Path "$($_.FullName)/*.c") -or (Test-Path "$($_.FullName)/*.h")) {
Push-Location $_.FullName
Write-Host "Processing $($_.FullName)"
&clang-format -i -style=file *.c *.h
Pop-Location
}

}
$clang_format = Join-Path -Path $PSScriptRoot -ChildPath "flipperzero-firmware_unleashed/toolchain/x86_64-windows/bin/clang-format.exe"
Push-Location $PSScriptRoot
Get-ChildItem -Path "totp" -File -Recurse -Include "*.c", "*.h" | ForEach-Object {
Write-Host "Formatting $($_.FullName)"
& $clang_format -i -style=file $_.FullName
}
Pop-Location
6 changes: 1 addition & 5 deletions fbt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ Push-Location $PSScriptRoot

$firmware_path = ""
$firmware_name = ""
if (('official-dev', 'off-dev', 'od').Contains($args[0])) {
if (('official-dev', 'off-dev', 'od', 'unleashed', 'un', 'u').Contains($args[0])) {
$firmware_path = "flipperzero-firmware_official_dev"
$firmware_name = "Official Dev"
}
elseif (('official-stable', 'off-stbl', 'os').Contains($args[0])) {
$firmware_path = "flipperzero-firmware_official_stable"
$firmware_name = "Official Stable"
}
elseif (('unleashed', 'un', 'u').Contains($args[0])) {
$firmware_path = "flipperzero-firmware_unleashed"
$firmware_name = "Unleashed"
}
else {
throw "Unable to recognize which firmware to use"
}
Expand Down
1 change: 0 additions & 1 deletion flipperzero-firmware_unleashed
Submodule flipperzero-firmware_unleashed deleted from 598965
2 changes: 1 addition & 1 deletion pvs-build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

pushd flipperzero-firmware_unleashed
pushd flipperzero-firmware_official_dev
rm -rf applications/plugins/totp
sed -i 's/applications_user/../' site_scons/commandline.scons
./fbt fap_totp
Expand Down
2 changes: 1 addition & 1 deletion sonar-build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

pushd flipperzero-firmware_unleashed
pushd flipperzero-firmware_official_dev
rm -rf applications/plugins/totp
sed -i 's/applications_user/../' site_scons/commandline.scons
./fbt fap_totp
Expand Down
7 changes: 7 additions & 0 deletions totp/services/cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
TOTP_CLI_PRINTF( \
"Invalid command arguments. use \"help\" command to get list of available commands")

/**
* @brief Checks whether user is authenticated and entered correct PIN.
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
* @param plugin_state application state
* @param cli reference to the firmware CLI subsystem
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
*/
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
44 changes: 30 additions & 14 deletions totp/totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

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

totp_scene_director_init_scenes(plugin_state);

if (plugin_state->crypto_verify_data == NULL) {
if(plugin_state->crypto_verify_data == NULL) {
DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "No", NULL, "Yes");
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
dialog_message_set_text(
message,
"Would you like to setup PIN?",
SCREEN_WIDTH_CENTER,
SCREEN_HEIGHT_CENTER,
AlignCenter,
AlignCenter);
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message);
if (dialog_result == DialogMessageButtonRight) {
if(dialog_result == DialogMessageButtonRight) {
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
} else {
totp_crypto_seed_iv(plugin_state, NULL, 0);
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
}
} else if (plugin_state->pin_set) {
} else if(plugin_state->pin_set) {
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
} else {
totp_crypto_seed_iv(plugin_state, NULL, 0);
if (totp_crypto_verify_key(plugin_state)) {
if(totp_crypto_verify_key(plugin_state)) {
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
} else {
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");
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");
DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "Exit", NULL, NULL);
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
dialog_message_set_text(
message,
"Digital signature verification failed",
SCREEN_WIDTH_CENTER,
SCREEN_HEIGHT_CENTER,
AlignCenter,
AlignCenter);
dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message);
return false;
Expand All @@ -94,15 +108,15 @@ static void totp_plugin_state_free(PluginState* plugin_state) {

ListNode* node = plugin_state->tokens_list;
ListNode* tmp;
while (node != NULL) {
while(node != NULL) {
tmp = node->next;
TokenInfo* tokenInfo = node->data;
token_info_free(tokenInfo);
free(node);
node = tmp;
}

if (plugin_state->crypto_verify_data != NULL) {
if(plugin_state->crypto_verify_data != NULL) {
free(plugin_state->crypto_verify_data);
}
free(plugin_state);
Expand All @@ -113,7 +127,7 @@ int32_t totp_app() {
PluginState* plugin_state = malloc(sizeof(PluginState));
furi_check(plugin_state != NULL);

if (!totp_plugin_state_init(plugin_state)) {
if(!totp_plugin_state_init(plugin_state)) {
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
totp_plugin_state_free(plugin_state);
return 254;
Expand All @@ -138,18 +152,20 @@ int32_t totp_app() {
bool processing = true;
uint32_t last_user_interaction_time = furi_get_tick();
while(processing) {
if (plugin_state->changing_scene) continue;
if(plugin_state->changing_scene) continue;
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);

PluginState* plugin_state_m = acquire_mutex_block(&state_mutex);

if(event_status == FuriStatusOk) {
if (event.type == EventTypeKey) {
if(event.type == EventTypeKey) {
last_user_interaction_time = furi_get_tick();
}

processing = totp_scene_director_handle_event(&event, plugin_state_m);
} else if (plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
} else if(
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication &&
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL);
}

Expand Down

0 comments on commit 4548c3b

Please sign in to comment.