Skip to content

Commit

Permalink
Implementation of #65 (#66)
Browse files Browse the repository at this point in the history
* Initial implementation of #65
  • Loading branch information
akopachov authored Jan 18, 2023
1 parent 7f13d5a commit 058e162
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 36 deletions.
16 changes: 16 additions & 0 deletions docs/conf-file_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ File format is standard for Flipper Zero device. Each line has one setting ident
</p>
</details>

<details>
<summary><h3 style="display: inline">TokenDuration</h3></summary>
<p>

**Type:** unsigned int

**Default value:** `30`

**Description:** Token lifetime duration in seconds. Should be between `15` and `255`. Majority websites requires `30`, however some rare websites may require custom lifetime. If you are not sure which one to use - use `30`.

</p>
</details>

## Example config file

```text
Expand All @@ -178,12 +191,15 @@ TokenName: Test plain
TokenSecret: 95 6B CE 3E 2F 01 AF 29 B2 9A DE CA E7 EF F5 B1
TokenAlgo: sha1
TokenDigits: 6
TokenDuration: 30
TokenName: Verifyr sha256
TokenSecret: SSECIUHGRYRCRBCNKKXPUQBLBGEQZ3PKNA7TA7TQV6IL5WDFU62TNNT3NHKVWRCQWF4QTSE4IGLG4S7RGY3LDMVDZVMAGB2ARPG7XYQ
TokenAlgo: sha256
TokenDigits: 6
TokenDuration: 60
TokenName: Verifyr sha512 8
TokenSecret: 3KKGABEJ4CKS5AHBZBDHFFNKUZHN6D7TKUGI3T7SHEUBAMIAPBUBWQNCMEEGEJX2LF23PYAFUCSRNVQ2ENOQWLHISCOJQCU2SCND4CI
TokenAlgo: sha512
TokenDigits: 8
TokenDuration: 30
```
2 changes: 1 addition & 1 deletion flipperzero-firmware_official_dev
Submodule flipperzero-firmware_official_dev updated 59 files
+14 −2 .vscode/example/tasks.json
+8 −0 SConstruct
+2 −2 applications/main/bad_usb/bad_usb_script.c
+3 −0 applications/main/gpio/scenes/gpio_scene_usb_uart_config.c
+1 −1 applications/services/desktop/views/desktop_view_slideshow.c
+49 −0 applications/services/gui/modules/button_menu.c
+11 −12 applications/services/gui/modules/text_input.c
+1 −1 applications/services/gui/modules/widget.h
+1 −1 applications/services/input/input.h
+379 −379 assets/resources/infrared/assets/tv.ir
+2 −1 firmware/targets/f7/api_symbols.csv
+1 −0 lib/flipper_application/elf/elf_file.c
+3 −6 lib/infrared/encoder_decoder/common/infrared_common_decoder.c
+5 −6 lib/infrared/encoder_decoder/common/infrared_common_encoder.c
+0 −140 lib/infrared/encoder_decoder/common/infrared_common_protocol_defs.c
+34 −29 lib/infrared/encoder_decoder/infrared.c
+10 −0 lib/infrared/encoder_decoder/infrared.h
+3 −2 lib/infrared/encoder_decoder/infrared_i.h
+0 −320 lib/infrared/encoder_decoder/infrared_protocol_defs_i.h
+3 −7 lib/infrared/encoder_decoder/kaseikyo/infrared_decoder_kaseikyo.c
+2 −6 lib/infrared/encoder_decoder/kaseikyo/infrared_encoder_kaseikyo.c
+0 −17 lib/infrared/encoder_decoder/kaseikyo/infrared_kaseikyo_spec.c
+40 −0 lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo.c
+31 −0 lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo.h
+30 −0 lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo_i.h
+3 −8 lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c
+4 −7 lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c
+0 −47 lib/infrared/encoder_decoder/nec/infrared_nec_spec.c
+74 −0 lib/infrared/encoder_decoder/nec/infrared_protocol_nec.c
+30 −0 lib/infrared/encoder_decoder/nec/infrared_protocol_nec.h
+29 −0 lib/infrared/encoder_decoder/nec/infrared_protocol_nec_i.h
+5 −8 lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c
+5 −7 lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c
+49 −0 lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5.c
+38 −0 lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5.h
+20 −0 lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5_i.h
+0 −27 lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c
+5 −8 lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c
+5 −7 lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c
+39 −0 lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.c
+37 −0 lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.h
+28 −0 lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h
+0 −17 lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c
+3 −7 lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c
+4 −6 lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c
+40 −0 lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung.c
+31 −0 lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung.h
+35 −0 lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung_i.h
+0 −17 lib/infrared/encoder_decoder/samsung/infrared_samsung_spec.c
+3 −8 lib/infrared/encoder_decoder/sirc/infrared_decoder_sirc.c
+2 −7 lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c
+64 −0 lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc.c
+37 −0 lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc.h
+26 −0 lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc_i.h
+0 −37 lib/infrared/encoder_decoder/sirc/infrared_sirc_spec.c
+2 −1 lib/infrared/worker/infrared_transmit.c
+31 −19 lib/infrared/worker/infrared_worker.c
+2 −0 scripts/fbt_tools/fbt_help.py
+15 −5 scripts/runfap.py
48 changes: 39 additions & 9 deletions totp/cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define TOTP_CLI_COMMAND_ADD_ARG_DIGITS "digits"
#define TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "-d"
#define TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX "-u"
#define TOTP_CLI_COMMAND_ADD_ARG_DURATION "duration"
#define TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX "-l"

static bool token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) {
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
Expand All @@ -34,6 +36,16 @@ static bool token_info_set_algo_from_str(TokenInfo* token_info, const FuriString
return false;
}

static bool args_read_uint8_and_trim(FuriString* args, uint8_t* value) {
int int_value;
if (!args_read_int_and_trim(args, &int_value) || int_value < 0 || int_value > UINT8_MAX) {
return false;
}

*value = (uint8_t)int_value;
return true;
}

void totp_cli_command_add_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_ADD ", " TOTP_CLI_COMMAND_ADD_ALT
", " TOTP_CLI_COMMAND_ADD_ALT2 " Add new token\r\n");
Expand All @@ -42,11 +54,11 @@ void totp_cli_command_add_docopt_commands() {
void totp_cli_command_add_docopt_usage() {
TOTP_CLI_PRINTF(
" " TOTP_CLI_COMMAND_NAME
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_ADD " | " TOTP_CLI_COMMAND_ADD_ALT " | " TOTP_CLI_COMMAND_ADD_ALT2) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_NAME) " " DOCOPT_OPTIONAL(
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_ADD " | " TOTP_CLI_COMMAND_ADD_ALT " | " TOTP_CLI_COMMAND_ADD_ALT2) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_NAME) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_ALGO))) " " DOCOPT_OPTIONAL(
DOCOPT_OPTION(
TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX,
TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX,
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_ADD_ARG_ALGO))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_DIGITS))) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX)) "\r\n");
TOTP_CLI_COMMAND_ADD_ARG_DIGITS))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_DURATION))) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX)) "\r\n");
}

void totp_cli_command_add_docopt_arguments() {
Expand All @@ -64,6 +76,10 @@ void totp_cli_command_add_docopt_options() {
TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX,
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_ADD_ARG_DIGITS)) " Number of digits to generate, one of: 6, 8 " DOCOPT_DEFAULT("6") "\r\n");
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX,
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_ADD_ARG_DURATION)) " Token lifetime duration in seconds, between: 15 and 255 " DOCOPT_DEFAULT("30") "\r\n");
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) " Show console user input as-is without masking\r\n");
}
Expand Down Expand Up @@ -110,16 +126,30 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
parsed = true;
}
} else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX) == 0) {
if(!args_read_string_and_trim(args, temp_str)) {
uint8_t digit_value;
if(!args_read_uint8_and_trim(args, &digit_value)) {
TOTP_CLI_PRINTF(
"Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
"Missed or incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
"\"\r\n");
} else if(!token_info_set_digits_from_int(
token_info, CONVERT_CHAR_TO_DIGIT(furi_string_get_char(temp_str, 0)))) {
} else if(!token_info_set_digits_from_int(token_info, digit_value)) {
TOTP_CLI_PRINTF(
"\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
"\"%" PRIu8 "\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
"\"\r\n",
furi_string_get_cstr(temp_str));
digit_value);
} else {
parsed = true;
}
} else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX) == 0) {
uint8_t duration_value;
if(!args_read_uint8_and_trim(args, &duration_value)) {
TOTP_CLI_PRINTF(
"Missed or incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX
"\"\r\n");
} else if(!token_info_set_duration_from_int(token_info, duration_value)) {
TOTP_CLI_PRINTF(
"\"%" PRIu8 "\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX
"\"\r\n",
duration_value);
} else {
parsed = true;
}
Expand Down
14 changes: 8 additions & 6 deletions totp/cli/commands/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
return;
}

TOTP_CLI_PRINTF("+-----+-----------------------------+--------+--------+\r\n");
TOTP_CLI_PRINTF("| %-*s | %-*s | %-*s | %-s |\r\n", 3, "#", 27, "Name", 6, "Algo", "Digits");
TOTP_CLI_PRINTF("+-----+-----------------------------+--------+--------+\r\n");
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
TOTP_CLI_PRINTF(
"| %-*s | %-*s | %-*s | %-s | %-s |\r\n", 3, "#", 25, "Name", 6, "Algo", "Ln", "Dur");
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
uint16_t index = 1;
TOTP_LIST_FOREACH(plugin_state->tokens_list, node, {
TokenInfo* token_info = (TokenInfo*)node->data;
TOTP_CLI_PRINTF(
"| %-3" PRIu16 " | %-27.27s | %-6s | %-6" PRIu8 " |\r\n",
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-3" PRIu8 " |\r\n",
index,
token_info->name,
get_algo_as_cstr(token_info->algo),
token_info->digits);
token_info->digits,
token_info->duration);
index++;
});
TOTP_CLI_PRINTF("+-----+-----------------------------+--------+--------+\r\n");
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
}
33 changes: 33 additions & 0 deletions totp/services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../types/common.h"
#include "../../types/token_info.h"
#include "migrations/config_migration_v1_to_v2.h"
#include "migrations/config_migration_v2_to_v3.h"

#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator")
#define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
Expand Down Expand Up @@ -173,6 +174,13 @@ static TotpConfigFileOpenResult totp_open_config_file(Storage* storage, FlipperF
flipper_format_write_comment(fff_data_file, temp_str);
flipper_format_write_comment_cstr(fff_data_file, " ");

flipper_format_write_comment_cstr(
fff_data_file,
"# Token lifetime duration in seconds. Should be between 15 and 255. Majority websites requires 30, however some rare websites may require custom lifetime. If you are not sure which one to use - use 30");
furi_string_printf(temp_str, "%s: 30", TOTP_CONFIG_KEY_TOKEN_DURATION);
flipper_format_write_comment(fff_data_file, temp_str);
flipper_format_write_comment_cstr(fff_data_file, " ");

flipper_format_write_comment_cstr(fff_data_file, "=== TOKEN SAMPLE END ===");
flipper_format_write_comment_cstr(fff_data_file, " ");

Expand Down Expand Up @@ -232,6 +240,12 @@ TotpConfigFileUpdateResult
break;
}

tmp_uint32 = token_info->duration;
if(!flipper_format_write_uint32(file, TOTP_CONFIG_KEY_TOKEN_DURATION, &tmp_uint32, 1)) {
update_result = TotpConfigFileUpdateError;
break;
}

update_result = TotpConfigFileUpdateSuccess;
} while(false);

Expand Down Expand Up @@ -483,6 +497,7 @@ TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_st
if(file_version == 1) {
if(totp_config_migrate_v1_to_v2(fff_data_file, fff_backup_data_file)) {
FURI_LOG_I(LOGGING_TAG, "Applied migration from v1 to v2");
file_version = 2;
} else {
FURI_LOG_W(
LOGGING_TAG, "An error occurred during migration from v1 to v2");
Expand All @@ -491,6 +506,18 @@ TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_st
}
}

if(file_version == 2) {
if(totp_config_migrate_v2_to_v3(fff_data_file, fff_backup_data_file)) {
FURI_LOG_I(LOGGING_TAG, "Applied migration from v2 to v3");
file_version = 3;
} else {
FURI_LOG_W(
LOGGING_TAG, "An error occurred during migration from v2 to v3");
result = TotpConfigFileOpenError;
break;
}
}

flipper_format_file_close(fff_backup_data_file);
flipper_format_free(fff_backup_data_file);
flipper_format_rewind(fff_data_file);
Expand Down Expand Up @@ -669,6 +696,12 @@ TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state)
tokenInfo->digits = TOTP_6_DIGITS;
}

if(!flipper_format_read_uint32(
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &temp_data32, 1) ||
!token_info_set_duration_from_int(tokenInfo, temp_data32)) {
tokenInfo->duration = TOTP_TOKEN_DURATION_DEFAULT;
}

FURI_LOG_D(LOGGING_TAG, "Found token \"%s\"", tokenInfo->name);

TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, tokenInfo, furi_check);
Expand Down
3 changes: 2 additions & 1 deletion totp/services/config/constants.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
#define CONFIG_FILE_ACTUAL_VERSION 2
#define CONFIG_FILE_ACTUAL_VERSION 3

#define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
#define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"
#define TOTP_CONFIG_KEY_TOKEN_SECRET "TokenSecret"
#define TOTP_CONFIG_KEY_TOKEN_ALGO "TokenAlgo"
#define TOTP_CONFIG_KEY_TOKEN_DIGITS "TokenDigits"
#define TOTP_CONFIG_KEY_TOKEN_DURATION "TokenDuration"
#define TOTP_CONFIG_KEY_CRYPTO_VERIFY "Crypto"
#define TOTP_CONFIG_KEY_BASE_IV "BaseIV"
#define TOTP_CONFIG_KEY_PINSET "PinIsSet"
Expand Down
3 changes: 2 additions & 1 deletion totp/services/config/migrations/config_migration_v1_to_v2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config_migration_v1_to_v2.h"
#include <flipper_format/flipper_format.h>
#include "../constants.h"
#include "../../../types/token_info.h"

#define NEW_VERSION 2

Expand Down Expand Up @@ -36,7 +37,7 @@ bool totp_config_migrate_v1_to_v2(

flipper_format_write_string_cstr(
fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
uint32_t default_digits = 6;
const uint32_t default_digits = TOTP_6_DIGITS;
flipper_format_write_uint32(
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
}
Expand Down
70 changes: 70 additions & 0 deletions totp/services/config/migrations/config_migration_v2_to_v3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "config_migration_v2_to_v3.h"
#include <flipper_format/flipper_format.h>
#include "../constants.h"
#include "../../../types/token_info.h"

#define NEW_VERSION 3

bool totp_config_migrate_v2_to_v3(
FlipperFormat* fff_data_file,
FlipperFormat* fff_backup_data_file) {
flipper_format_write_header_cstr(fff_data_file, CONFIG_FILE_HEADER, NEW_VERSION);

FuriString* temp_str = furi_string_alloc();

if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str);
}

flipper_format_rewind(fff_backup_data_file);

if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, temp_str);
}

flipper_format_rewind(fff_backup_data_file);

if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, temp_str);
}

flipper_format_rewind(fff_backup_data_file);

if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_PINSET, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_PINSET, temp_str);
}

flipper_format_rewind(fff_backup_data_file);

if(flipper_format_read_string(
fff_backup_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, temp_str);
}

flipper_format_rewind(fff_backup_data_file);

while(true) {
if(!flipper_format_read_string(
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {
break;
}

flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str);

flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str);

flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str);

flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, temp_str);

const uint32_t default_duration = TOTP_TOKEN_DURATION_DEFAULT;
flipper_format_write_uint32(
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DURATION, &default_duration, 1);
}

furi_string_free(temp_str);
return true;
}
7 changes: 7 additions & 0 deletions totp/services/config/migrations/config_migration_v2_to_v3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <flipper_format/flipper_format.h>

bool totp_config_migrate_v2_to_v3(
FlipperFormat* fff_data_file,
FlipperFormat* fff_backup_data_file);
9 changes: 9 additions & 0 deletions totp/types/token_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ bool token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits) {

return false;
}

bool token_info_set_duration_from_int(TokenInfo* token_info, uint8_t duration) {
if(duration >= 15) {
token_info->duration = duration;
return true;
}

return false;
}
17 changes: 16 additions & 1 deletion totp/types/token_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <inttypes.h>

#define TOTP_TOKEN_DURATION_DEFAULT 30

typedef uint8_t TokenHashAlgo;
typedef uint8_t TokenDigitsCount;

Expand Down Expand Up @@ -70,6 +72,11 @@ typedef struct {
* @brief Desired TOTP token length
*/
TokenDigitsCount digits;

/**
* @brief Desired TOTP token duration in seconds
*/
uint8_t duration;
} TokenInfo;

/**
Expand Down Expand Up @@ -102,6 +109,14 @@ bool token_info_set_secret(
* @brief Sets token digits count from \c uint8_t value
* @param token_info instance whichs token digits count length should be updated
* @param digits desired token digits count length
* @return \c true if token digits count length has been updated; \c false p
* @return \c true if token digits count length has been updated; \c false otherwise
*/
bool token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits);

/**
* @brief Sets token duration from \c uint8_t value
* @param token_info instance whichs token digits count length should be updated
* @param duration desired token duration in seconds
* @return \c true if token duration has been updated; \c false otherwise
*/
bool token_info_set_duration_from_int(TokenInfo* token_info, uint8_t duration);
Loading

0 comments on commit 058e162

Please sign in to comment.