Skip to content

Commit

Permalink
* Updated to FuriString
Browse files Browse the repository at this point in the history
* Build for Unleashed and Official firmware
  • Loading branch information
akopachov committed Oct 10, 2022
1 parent e85da67 commit 99e8ceb
Show file tree
Hide file tree
Showing 56 changed files with 81 additions and 169 deletions.
6 changes: 4 additions & 2 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ App(
"gui",
"cli",
"dialogs",
"storage"
"storage",
"input",
"notification"
],
provides=["totp_start"],
stack_size=2 * 1024,
order=20,
fap_category="Misc",
fap_icon="totp_10px.png",
fap_icon="totp_10px.png"
)

App(
Expand Down
5 changes: 1 addition & 4 deletions scenes/add_new_token/totp_input_text.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_INPUT_TEXT_H_
#define _TOTP_INPUT_TEXT_H_
#pragma once

#include <gui/gui.h>
#include <gui/view.h>
Expand Down Expand Up @@ -37,5 +36,3 @@ InputTextSceneState* totp_input_text_activate(InputTextSceneContext* context);
void totp_input_text_render(Canvas* const canvas, InputTextSceneState* text_input_state);
bool totp_input_text_handle_event(PluginEvent* const event, InputTextSceneState* text_input_state);
void totp_input_text_free(InputTextSceneState* state);

#endif
10 changes: 5 additions & 5 deletions scenes/add_new_token/totp_scene_add_new_token.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "totp_scene_add_new_token.h"
#include "../../types/common.h"
#include "../../lib/ui/constants.h"
#include "../../services/ui/constants.h"
#include "../scene_director.h"
#include "totp_input_text.h"
#include "../../types/token_info.h"
#include "../../lib/list/list.h"
#include "../../lib/base32/base32.h"
#include "../../lib/config/config.h"
#include "../../lib/ui/ui_controls.h"
#include "../../services/list/list.h"
#include "../../services/base32/base32.h"
#include "../../services/config/config.h"
#include "../../services/ui/ui_controls.h"
#include "../generate_token/totp_scene_generate_token.h"

#define TOKEN_ALGO_LIST_LENGTH 3
Expand Down
5 changes: 1 addition & 4 deletions scenes/add_new_token/totp_scene_add_new_token.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_SCENE_ADD_NEW_TOKEN_H_
#define _TOTP_SCENE_ADD_NEW_TOKEN_H_
#pragma once

#include <gui/gui.h>
#include <furi.h>
Expand All @@ -17,5 +16,3 @@ void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_s
bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState* plugin_state);
void totp_scene_add_new_token_deactivate(PluginState* plugin_state);
void totp_scene_add_new_token_free(PluginState* plugin_state);

#endif
6 changes: 3 additions & 3 deletions scenes/authenticate/totp_scene_authenticate.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "totp_scene_authenticate.h"
#include <dialogs/dialogs.h>
#include "../../types/common.h"
#include "../../lib/ui/icons.h"
#include "../../lib/ui/constants.h"
#include "../../lib/config/config.h"
#include "../../services/ui/icons.h"
#include "../../services/ui/constants.h"
#include "../../services/config/config.h"
#include "../scene_director.h"
#include "../totp_scenes_enum.h"

Expand Down
5 changes: 1 addition & 4 deletions scenes/authenticate/totp_scene_authenticate.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_SCENE_AUTHENTICATE_H_
#define _TOTP_SCENE_AUTHENTICATE_H_
#pragma once

#include <gui/gui.h>
#include <furi.h>
Expand All @@ -13,5 +12,3 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st
bool totp_scene_authenticate_handle_event(PluginEvent* const event, PluginState* plugin_state);
void totp_scene_authenticate_deactivate(PluginState* plugin_state);
void totp_scene_authenticate_free(PluginState* plugin_state);

#endif
8 changes: 4 additions & 4 deletions scenes/generate_token/totp_scene_generate_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "totp_scene_generate_token.h"
#include "../../types/token_info.h"
#include "../../types/common.h"
#include "../../lib/ui/icons.h"
#include "../../lib/ui/constants.h"
#include "../../lib/totp/totp.h"
#include "../../lib/config/config.h"
#include "../../services/ui/icons.h"
#include "../../services/ui/constants.h"
#include "../../services/totp/totp.h"
#include "../../services/config/config.h"
#include "../scene_director.h"
#include "../token_menu/totp_scene_token_menu.h"

Expand Down
5 changes: 1 addition & 4 deletions scenes/generate_token/totp_scene_generate_token.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_SCENE_GENERATE_TOKEN_H_
#define _TOTP_SCENE_GENERATE_TOKEN_H_
#pragma once

#include <gui/gui.h>
#include <furi.h>
Expand All @@ -17,5 +16,3 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_
bool totp_scene_generate_token_handle_event(PluginEvent* const event, PluginState* plugin_state);
void totp_scene_generate_token_deactivate(PluginState* plugin_state);
void totp_scene_generate_token_free(PluginState* plugin_state);

#endif
5 changes: 1 addition & 4 deletions scenes/scene_director.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _SCENE_DIRECTOR_H_
#define _SCENE_DIRECTOR_H_
#pragma once

#include <gui/gui.h>
#include "../types/plugin_state.h"
Expand All @@ -12,5 +11,3 @@ void totp_scene_director_init_scenes(PluginState* const plugin_state);
void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state);
void totp_scene_director_dispose(PluginState* const plugin_state);
bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state);

#endif
8 changes: 4 additions & 4 deletions scenes/token_menu/totp_scene_token_menu.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "totp_scene_token_menu.h"
#include <gui/gui.h>
#include <dialogs/dialogs.h>
#include "../../lib/ui/ui_controls.h"
#include "../../lib/ui/constants.h"
#include "../../services/ui/ui_controls.h"
#include "../../services/ui/constants.h"
#include "../scene_director.h"
#include "../../lib/config/config.h"
#include "../../lib/list/list.h"
#include "../../services/config/config.h"
#include "../../services/list/list.h"
#include "../../types/token_info.h"
#include "../generate_token/totp_scene_generate_token.h"
#include "../add_new_token/totp_scene_add_new_token.h"
Expand Down
5 changes: 1 addition & 4 deletions scenes/token_menu/totp_scene_token_menu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_SCENE_TOKEN_MENU_H_
#define _TOTP_SCENE_TOKEN_MENU_H_
#pragma once

#include <gui/gui.h>
#include <furi.h>
Expand All @@ -17,5 +16,3 @@ void totp_scene_token_menu_render(Canvas* const canvas, PluginState* plugin_stat
bool totp_scene_token_menu_handle_event(PluginEvent* const event, PluginState* plugin_state);
void totp_scene_token_menu_deactivate(PluginState* plugin_state);
void totp_scene_token_menu_free(PluginState* plugin_state);

#endif
5 changes: 2 additions & 3 deletions scenes/totp_scenes_enum.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef _TOTP_SCENES_ENUM_H_
#define _TOTP_SCENES_ENUM_H_
#pragma once

typedef enum {
TotpSceneAuthentication,
TotpSceneGenerateToken,
TotpSceneAddNewToken,
TotpSceneTokenMenu
} Scene;
#endif
File renamed without changes.
5 changes: 1 addition & 4 deletions lib/base32/base32.h → services/base32/base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
// All functions return the number of output bytes or -1 on error. If the
// output buffer is too small, the result will silently be truncated.

#ifndef _BASE32_H_
#define _BASE32_H_
#pragma once

#include <stdint.h>

Expand All @@ -35,5 +34,3 @@ int base32_decode(const uint8_t *encoded, uint8_t *result, int bufSize)
int base32_encode(const uint8_t *data, int length, uint8_t *result,
int bufSize)
__attribute__((visibility("hidden")));

#endif /* _BASE32_H_ */
42 changes: 20 additions & 22 deletions lib/config/config.c → services/config/config.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "../list/list.h"
#include "../../types/common.h"
#include "../../types/token_info.h"
#include "migrations/config_migration_v1_to_v2.h"
Expand Down Expand Up @@ -39,12 +40,12 @@ char* token_info_get_algo_as_cstr(TokenInfo* token_info) {
return NULL;
}

void token_info_set_algo_from_str(TokenInfo* token_info, string_t str) {
if (string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
void token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str) {
if (furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
token_info->algo = SHA1;
} else if (string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME)) {
} else if (furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME)) {
token_info->algo = SHA256;
} else if (string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME)) {
} else if (furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME)) {
token_info->algo = SHA512;
}
}
Expand Down Expand Up @@ -88,37 +89,36 @@ FlipperFormat* totp_open_config_file(Storage* storage) {
flipper_format_write_comment_cstr(fff_data_file, " ");
flipper_format_write_comment_cstr(fff_data_file, "Timezone offset in hours. Important note: do not put '+' sign for positive values");
flipper_format_write_float(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &tmp_tz, 1);
string_t temp_str;
string_init(temp_str);
FuriString* temp_str = furi_string_alloc();

flipper_format_write_comment_cstr(fff_data_file, " ");
flipper_format_write_comment_cstr(fff_data_file, "=== TOKEN SAMPLE BEGIN ===");
flipper_format_write_comment_cstr(fff_data_file, " ");
flipper_format_write_comment_cstr(fff_data_file, "# Token name which will be visible in the UI.");
string_printf(temp_str, "%s: Sample token name", TOTP_CONFIG_KEY_TOKEN_NAME);
furi_string_printf(temp_str, "%s: Sample token name", TOTP_CONFIG_KEY_TOKEN_NAME);
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, "# Plain token secret without spaces, dashes and etc, just pure alpha-numeric characters. Important note: plain token will be encrypted and replaced by TOTP app");
string_printf(temp_str, "%s: plaintokensecret", TOTP_CONFIG_KEY_TOKEN_SECRET);
furi_string_printf(temp_str, "%s: plaintokensecret", TOTP_CONFIG_KEY_TOKEN_SECRET);
flipper_format_write_comment(fff_data_file, temp_str);
flipper_format_write_comment_cstr(fff_data_file, " ");

string_printf(temp_str, " # Token hashing algorithm to use during code generation. Supported options are %s, %s and %s. If you are not use which one to use - use %s", TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
furi_string_printf(temp_str, " # Token hashing algorithm to use during code generation. Supported options are %s, %s and %s. If you are not use which one to use - use %s", TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
flipper_format_write_comment(fff_data_file, temp_str);
string_printf(temp_str, "%s: %s", TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
furi_string_printf(temp_str, "%s: %s", TOTP_CONFIG_KEY_TOKEN_ALGO, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME);
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, "# How many digits there should be in generated code. Available options are 6 and 8. Majority websites requires 6 digits code, however some rare websites wants to get 8 digits code. If you are not sure which one to use - use 6");
string_printf(temp_str, "%s: 6", TOTP_CONFIG_KEY_TOKEN_DIGITS);
furi_string_printf(temp_str, "%s: 6", TOTP_CONFIG_KEY_TOKEN_DIGITS);
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, " ");

string_clear(temp_str);
furi_string_free(temp_str);
if(!flipper_format_rewind(fff_data_file)) {
totp_close_config_file(fff_data_file);
FURI_LOG_E(LOGGING_TAG, "Rewind error");
Expand Down Expand Up @@ -163,13 +163,12 @@ void totp_config_file_load_base(PluginState* const plugin_state) {

plugin_state->timezone_offset = 0;

string_t temp_str;
string_init(temp_str);
FuriString* temp_str = furi_string_alloc();

uint32_t file_version;
if(!flipper_format_read_header(fff_data_file, temp_str, &file_version)) {
FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
string_clear(temp_str);
furi_string_free(temp_str);
return;
}

Expand Down Expand Up @@ -227,7 +226,7 @@ void totp_config_file_load_base(PluginState* const plugin_state) {
FURI_LOG_D(LOGGING_TAG, "Missing timezone offset information, defaulting to 0");
}

string_clear(temp_str);
furi_string_free(temp_str);
totp_close_config_file(fff_data_file);
totp_close_storage();
}
Expand All @@ -236,13 +235,12 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
Storage* storage = totp_open_storage();
FlipperFormat* fff_data_file = totp_open_config_file(storage);

string_t temp_str;
FuriString* temp_str = furi_string_alloc();
uint32_t temp_data32;
string_init(temp_str);

if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
string_clear(temp_str);
furi_string_free(temp_str);
return;
}

Expand All @@ -256,7 +254,7 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {

TokenInfo* tokenInfo = token_info_alloc();

const char* temp_cstr = string_get_cstr(temp_str);
const char* temp_cstr = furi_string_get_cstr(temp_str);
tokenInfo->name = (char *)malloc(strlen(temp_cstr) + 1);
strcpy(tokenInfo->name, temp_cstr);

Expand All @@ -272,7 +270,7 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
continue;
}

temp_cstr = string_get_cstr(temp_str);
temp_cstr = furi_string_get_cstr(temp_str);
token_info_set_secret(tokenInfo, temp_cstr, strlen(temp_cstr), &plugin_state->iv[0]);
has_any_plain_secret = true;
FURI_LOG_W(LOGGING_TAG, "Found token with plain secret");
Expand Down Expand Up @@ -315,7 +313,7 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {

FURI_LOG_D(LOGGING_TAG, "Found %d tokens", index);

string_clear(temp_str);
furi_string_free(temp_str);
totp_close_config_file(fff_data_file);
totp_close_storage();

Expand Down
5 changes: 1 addition & 4 deletions lib/config/config.h → services/config/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_CONFIG_FILE_H_
#define _TOTP_CONFIG_FILE_H_
#pragma once

#include <flipper_format/flipper_format.h>
#include <furi.h>
Expand All @@ -15,5 +14,3 @@ void totp_full_save_config_file(PluginState* const plugin_state);
void totp_config_file_load_base(PluginState* const plugin_state);
void totp_config_file_load_tokens(PluginState* const plugin_state);
void totp_config_file_save_new_token(FlipperFormat* file, TokenInfo* token_info);

#endif
5 changes: 1 addition & 4 deletions lib/config/constants.h → services/config/constants.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _TOTP_CONFIG_CONSTANTS_FILE_H_
#define _TOTP_CONFIG_CONSTANTS_FILE_H_
#pragma once

#define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
#define CONFIG_FILE_ACTUAL_VERSION 2
Expand All @@ -15,5 +14,3 @@
#define TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME "sha1"
#define TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME "sha256"
#define TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME "sha512"

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
bool totp_config_migrate_v1_to_v2(FlipperFormat* fff_data_file, FlipperFormat* fff_backup_data_file) {
flipper_format_write_header_cstr(fff_data_file, CONFIG_FILE_HEADER, NEW_VERSION);

string_t temp_str;
string_init(temp_str);
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);
Expand Down Expand Up @@ -37,6 +36,6 @@ bool totp_config_migrate_v1_to_v2(FlipperFormat* fff_data_file, FlipperFormat* f
flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &default_digits, 1);
}

string_clear(temp_str);
furi_string_free(temp_str);
return true;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#ifndef _TOTP_CONFIG_FILE_MIGRATE_V1_TO_V2_H_
#define _TOTP_CONFIG_FILE_MIGRATE_V1_TO_V2_H_
#pragma once

#include <flipper_format/flipper_format.h>

bool totp_config_migrate_v1_to_v2(FlipperFormat* fff_data_file, FlipperFormat* fff_backup_data_file);

#endif
File renamed without changes.
5 changes: 1 addition & 4 deletions lib/hmac/byteswap.h → services/hmac/byteswap.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef BYTESWAP_H
#define BYTESWAP_H
#pragma once

#include <stdint.h>

uint32_t swap_uint32( uint32_t val );
uint64_t swap_uint64( uint64_t val );

#endif
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 99e8ceb

Please sign in to comment.