mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-11 06:09:08 -07:00
totp update
This commit is contained in:
@@ -8,18 +8,21 @@ 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(
|
||||
# appid="totp_start",
|
||||
# apptype=FlipperAppType.STARTUP,
|
||||
# entry_point="totp_on_system_start",
|
||||
# requires=["totp"],
|
||||
# order=30,
|
||||
# )
|
||||
# appid="totp_start",
|
||||
# apptype=FlipperAppType.STARTUP,
|
||||
# entry_point="totp_on_system_start",
|
||||
# requires=["totp"],
|
||||
# order=30,
|
||||
# )
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "sha1.h"
|
||||
|
||||
union _buffer {
|
||||
uint8_t b[BLOCK_LENGTH];
|
||||
uint32_t w[BLOCK_LENGTH/4];
|
||||
} buffer;
|
||||
union _state {
|
||||
uint8_t b[HASH_LENGTH];
|
||||
uint32_t w[HASH_LENGTH/4];
|
||||
} state;
|
||||
|
||||
uint8_t bufferOffset;
|
||||
uint32_t byteCount;
|
||||
uint8_t keyBuffer[BLOCK_LENGTH];
|
||||
uint8_t innerHash[HASH_LENGTH];
|
||||
|
||||
#define SHA1_K0 0x5a827999
|
||||
#define SHA1_K20 0x6ed9eba1
|
||||
#define SHA1_K40 0x8f1bbcdc
|
||||
#define SHA1_K60 0xca62c1d6
|
||||
|
||||
uint8_t sha1InitState[] = {
|
||||
0x01,0x23,0x45,0x67, // H0
|
||||
0x89,0xab,0xcd,0xef, // H1
|
||||
0xfe,0xdc,0xba,0x98, // H2
|
||||
0x76,0x54,0x32,0x10, // H3
|
||||
0xf0,0xe1,0xd2,0xc3 // H4
|
||||
};
|
||||
|
||||
void sha1_init(void) {
|
||||
memcpy(state.b,sha1InitState,HASH_LENGTH);
|
||||
byteCount = 0;
|
||||
bufferOffset = 0;
|
||||
}
|
||||
|
||||
uint32_t rol32(uint32_t number, uint8_t bits) {
|
||||
return ((number << bits) | (uint32_t)(number >> (32-bits)));
|
||||
}
|
||||
|
||||
void hashBlock() {
|
||||
uint8_t i;
|
||||
uint32_t a,b,c,d,e,t;
|
||||
|
||||
a=state.w[0];
|
||||
b=state.w[1];
|
||||
c=state.w[2];
|
||||
d=state.w[3];
|
||||
e=state.w[4];
|
||||
for (i=0; i<80; i++) {
|
||||
if (i>=16) {
|
||||
t = buffer.w[(i+13)&15] ^ buffer.w[(i+8)&15] ^ buffer.w[(i+2)&15] ^ buffer.w[i&15];
|
||||
buffer.w[i&15] = rol32(t,1);
|
||||
}
|
||||
if (i<20) {
|
||||
t = (d ^ (b & (c ^ d))) + SHA1_K0;
|
||||
} else if (i<40) {
|
||||
t = (b ^ c ^ d) + SHA1_K20;
|
||||
} else if (i<60) {
|
||||
t = ((b & c) | (d & (b | c))) + SHA1_K40;
|
||||
} else {
|
||||
t = (b ^ c ^ d) + SHA1_K60;
|
||||
}
|
||||
t+=rol32(a,5) + e + buffer.w[i&15];
|
||||
e=d;
|
||||
d=c;
|
||||
c=rol32(b,30);
|
||||
b=a;
|
||||
a=t;
|
||||
}
|
||||
state.w[0] += a;
|
||||
state.w[1] += b;
|
||||
state.w[2] += c;
|
||||
state.w[3] += d;
|
||||
state.w[4] += e;
|
||||
}
|
||||
|
||||
void addUncounted(uint8_t data) {
|
||||
buffer.b[bufferOffset ^ 3] = data;
|
||||
bufferOffset++;
|
||||
if (bufferOffset == BLOCK_LENGTH) {
|
||||
hashBlock();
|
||||
bufferOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sha1_write(uint8_t data) {
|
||||
++byteCount;
|
||||
addUncounted(data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void sha1_write_array(uint8_t *buffer, uint8_t size){
|
||||
while (size--) {
|
||||
sha1_write(*buffer++);
|
||||
}
|
||||
}
|
||||
|
||||
void pad() {
|
||||
// Implement SHA-1 padding (fips180-2 <20><>5.1.1)
|
||||
|
||||
// Pad with 0x80 followed by 0x00 until the end of the block
|
||||
addUncounted(0x80);
|
||||
while (bufferOffset != 56) addUncounted(0x00);
|
||||
|
||||
// Append length in the last 8 bytes
|
||||
addUncounted(0); // We're only using 32 bit lengths
|
||||
addUncounted(0); // But SHA-1 supports 64 bit lengths
|
||||
addUncounted(0); // So zero pad the top bits
|
||||
addUncounted(byteCount >> 29); // Shifting to multiply by 8
|
||||
addUncounted(byteCount >> 21); // as SHA-1 supports bitstreams as well as
|
||||
addUncounted(byteCount >> 13); // byte.
|
||||
addUncounted(byteCount >> 5);
|
||||
addUncounted(byteCount << 3);
|
||||
}
|
||||
|
||||
uint8_t* sha1_result(void) {
|
||||
// Pad to complete the last block
|
||||
pad();
|
||||
|
||||
// Swap byte order back
|
||||
uint8_t i;
|
||||
for (i=0; i<5; i++) {
|
||||
uint32_t a,b;
|
||||
a=state.w[i];
|
||||
b=a<<24;
|
||||
b|=(a<<8) & 0x00ff0000;
|
||||
b|=(a>>8) & 0x0000ff00;
|
||||
b|=a>>24;
|
||||
state.w[i]=b;
|
||||
}
|
||||
|
||||
// Return pointer to hash (20 characters)
|
||||
return state.b;
|
||||
}
|
||||
|
||||
#define HMAC_IPAD 0x36
|
||||
#define HMAC_OPAD 0x5c
|
||||
|
||||
void sha1_init_hmac(const uint8_t* key, uint8_t keyLength) {
|
||||
uint8_t i;
|
||||
memset(keyBuffer,0,BLOCK_LENGTH);
|
||||
if (keyLength > BLOCK_LENGTH) {
|
||||
// Hash long keys
|
||||
sha1_init();
|
||||
for (;keyLength--;) sha1_write(*key++);
|
||||
memcpy(keyBuffer,sha1_result(),HASH_LENGTH);
|
||||
} else {
|
||||
// Block length keys are used as is
|
||||
memcpy(keyBuffer,key,keyLength);
|
||||
}
|
||||
// Start inner hash
|
||||
sha1_init();
|
||||
for (i=0; i<BLOCK_LENGTH; i++) {
|
||||
sha1_write(keyBuffer[i] ^ HMAC_IPAD);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* sha1_result_hmac(void) {
|
||||
uint8_t i;
|
||||
// Complete inner hash
|
||||
memcpy(innerHash,sha1_result(),HASH_LENGTH);
|
||||
// Calculate outer hash
|
||||
sha1_init();
|
||||
for (i=0; i<BLOCK_LENGTH; i++) sha1_write(keyBuffer[i] ^ HMAC_OPAD);
|
||||
for (i=0; i<HASH_LENGTH; i++) sha1_write(innerHash[i]);
|
||||
return sha1_result();
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef _sha1_h
|
||||
#define _sha1_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define HASH_LENGTH 20
|
||||
#define BLOCK_LENGTH 64
|
||||
|
||||
void sha1_init(void);
|
||||
void sha1_init_hmac(const uint8_t* secret, uint8_t secretLength);
|
||||
uint8_t* sha1_result(void);
|
||||
uint8_t* sha1_result_hmac(void);
|
||||
void sha1_write(uint8_t);
|
||||
void sha1_write_array(uint8_t *buffer, uint8_t size);
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
#include "canvas_extensions.h"
|
||||
|
||||
void canvas_draw_dots(Canvas* const canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height, const uint8_t *dots) {
|
||||
for (uint8_t i = 0; i < width; i++) {
|
||||
for (uint8_t j = 0; j < height; j++) {
|
||||
if (dots[i + j * width]) {
|
||||
canvas_draw_dot(canvas, x + i, y + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef _TOTPCANVAS_EXTENSIONS_H_
|
||||
#define _TOTPCANVAS_EXTENSIONS_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <gui/gui.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
void canvas_draw_dots(Canvas* const canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height, const uint8_t *dots);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_INPUT_TEXT_H_
|
||||
#define _TOTP_INPUT_TEXT_H_
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_SCENE_AUTHENTICATE_H_
|
||||
#define _TOTP_SCENE_AUTHENTICATE_H_
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <furi.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _SCENE_DIRECTOR_H_
|
||||
#define _SCENE_DIRECTOR_H_
|
||||
#pragma once
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include "../types/plugin_state.h"
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#ifndef _TOTP_SCENES_ENUM_H_
|
||||
#define _TOTP_SCENES_ENUM_H_
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
TotpSceneAuthentication,
|
||||
TotpSceneGenerateToken,
|
||||
TotpSceneAddNewToken,
|
||||
TotpSceneTokenMenu
|
||||
} Scene;
|
||||
#endif
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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_ */
|
||||
@@ -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"
|
||||
@@ -40,11 +41,11 @@ char* token_info_get_algo_as_cstr(TokenInfo* token_info) {
|
||||
}
|
||||
|
||||
void token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str) {
|
||||
if (string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -88,30 +89,29 @@ 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);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
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, " ");
|
||||
|
||||
@@ -163,8 +163,7 @@ void totp_config_file_load_base(PluginState* const plugin_state) {
|
||||
|
||||
plugin_state->timezone_offset = 0;
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
uint32_t file_version;
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &file_version)) {
|
||||
@@ -236,9 +235,8 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
|
||||
Storage* storage = totp_open_storage();
|
||||
FlipperFormat* fff_data_file = totp_open_config_file(storage);
|
||||
|
||||
FuriString* temp_str;
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
uint32_t temp_data32;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
|
||||
@@ -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>
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
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);
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HMAC_SHA1_H
|
||||
#define HMAC_SHA1_H
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -10,5 +9,3 @@
|
||||
output to pre-allocated 20 byte minimum RESBUF buffer. Return 0 on
|
||||
success. */
|
||||
int hmac_sha1 (const void *key, size_t keylen, const void *in, size_t inlen, void *restrict resbuf);
|
||||
|
||||
#endif /* HMAC_SHA1_H */
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HMAC_SHA256_H
|
||||
#define HMAC_SHA256_H
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -10,5 +9,3 @@
|
||||
output to pre-allocated 32 byte minimum RESBUF buffer. Return 0 on
|
||||
success. */
|
||||
int hmac_sha256 (const void *key, size_t keylen, const void *in, size_t inlen, void *restrict resbuf);
|
||||
|
||||
#endif /* HMAC_SHA256_H */
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HMAC_SHA512_H
|
||||
#define HMAC_SHA512_H
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -10,5 +9,3 @@
|
||||
output to pre-allocated 64 byte minimum RESBUF buffer. Return 0 on
|
||||
success. */
|
||||
int hmac_sha512 (const void *key, size_t keylen, const void *in, size_t inlen, void *restrict resbuf);
|
||||
|
||||
#endif /* HMAC_SHA512_H */
|
||||
@@ -18,8 +18,7 @@
|
||||
/* Written by Simon Josefsson. The interface was inspired by memxor
|
||||
in Niels Möller's Nettle. */
|
||||
|
||||
#ifndef MEMXOR_H
|
||||
# define MEMXOR_H
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -27,5 +26,3 @@
|
||||
the result in DEST, of length N bytes. Returns a pointer to
|
||||
DEST. */
|
||||
void *memxor (void */*restrict*/ dest, const void */*restrict*/ src, size_t n);
|
||||
|
||||
#endif /* MEMXOR_H */
|
||||
@@ -16,8 +16,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef SHA1_H
|
||||
# define SHA1_H 1
|
||||
#pragma once
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdint.h>
|
||||
@@ -105,8 +104,6 @@ extern int sha1_stream (FILE *stream, void *resblock);
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hey Emacs!
|
||||
* Local Variables:
|
||||
@@ -15,8 +15,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef SHA256_H
|
||||
# define SHA256_H 1
|
||||
#pragma once
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdint.h>
|
||||
@@ -111,8 +110,6 @@ extern int sha224_stream (FILE *stream, void *resblock);
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hey Emacs!
|
||||
* Local Variables:
|
||||
@@ -15,8 +15,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef SHA512_H
|
||||
# define SHA512_H 1
|
||||
#pragma once
|
||||
|
||||
# include <stdio.h>
|
||||
# include "u64.h"
|
||||
@@ -114,8 +113,6 @@ extern int sha384_stream (FILE *stream, void *resblock);
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hey Emacs!
|
||||
* Local Variables:
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _GL_U64_INLINE
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_LIST_H_
|
||||
#define _TOTP_LIST_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
@@ -15,5 +14,3 @@ ListNode *list_find(ListNode *head, void* data); /* returns pointer of element w
|
||||
ListNode *list_element_at(ListNode *head, uint16_t index); /* returns pointer of element with specified index in list. */
|
||||
ListNode *list_remove(ListNode *head, ListNode *ep); /* removes element from the list and returns new head node. */
|
||||
void list_free(ListNode *head); /* deletes all elements of the list. */
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef _TIMEZONE_UTILS_H_
|
||||
#define _TIMEZONE_UTILS_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
int32_t timezone_offset_from_hours(float hours);
|
||||
uint64_t timezone_offset_apply(uint64_t time, int32_t offset);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_H_
|
||||
#define _TOTP_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@@ -40,5 +39,3 @@ extern const TOTP_ALGO TOTP_ALGO_SHA512;
|
||||
0 otherwise
|
||||
*/
|
||||
uint32_t totp_at(TOTP_ALGO algo, uint8_t digits, const uint8_t* plain_secret, uint8_t plain_secret_length, uint64_t for_time, float timezone, uint8_t interval);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef _TOTP_UI_CONSTANTS_H_
|
||||
#define _TOTP_UI_CONSTANTS_H_
|
||||
#pragma once
|
||||
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
#define SCREEN_WIDTH_CENTER (SCREEN_WIDTH >> 1)
|
||||
#define SCREEN_HEIGHT_CENTER (SCREEN_HEIGHT >> 1)
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_ICONS_H_
|
||||
#define _TOTP_ICONS_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -10,5 +9,3 @@ static const uint8_t ICON_ARROW_LEFT_8x9[] = { 0x80,0xe0,0xf8,0xfe,0xff,0xfe,0xf
|
||||
#define ICON_ARROW_RIGHT_8x9_WIDTH 8
|
||||
#define ICON_ARROW_RIGHT_8x9_HEIGHT 9
|
||||
static const uint8_t ICON_ARROW_RIGHT_8x9[] = { 0x01,0x07,0x1f,0x7f,0xff,0x7f,0x1f,0x07,0x01 };
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_UI_CONTROLS_H_
|
||||
#define _TOTP_UI_CONTROLS_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <gui/gui.h>
|
||||
@@ -7,5 +6,3 @@
|
||||
void ui_control_text_box_render(Canvas* const canvas, int8_t y, char* text, bool is_selected);
|
||||
void ui_control_button_render(Canvas* const canvas, uint8_t x, int8_t y, uint8_t width, uint8_t height, char* text, bool is_selected);
|
||||
void ui_control_select_render(Canvas* const canvas, int8_t y, char* text, bool is_selected);
|
||||
|
||||
#endif
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include "lib/base32/base32.h"
|
||||
#include "lib/list/list.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "services/base32/base32.h"
|
||||
#include "services/list/list.h"
|
||||
#include "services/config/config.h"
|
||||
#include "types/plugin_state.h"
|
||||
#include "types/token_info.h"
|
||||
#include "types/plugin_event.h"
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#ifndef _TOTP_COMMON_TYPES_H_
|
||||
#define _TOTP_COMMON_TYPES_H_
|
||||
#pragma once
|
||||
|
||||
#define LOGGING_TAG "TOTP APP"
|
||||
#define CRYPTO_KEY_SLOT 2
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#ifndef _TOTP_EVENT_TYPE_H_
|
||||
#define _TOTP_EVENT_TYPE_H_
|
||||
|
||||
#pragma once
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_PLUGIN_EVENT_H_
|
||||
#define _TOTP_PLUGIN_EVENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <input/input.h>
|
||||
@@ -9,5 +8,3 @@ typedef struct {
|
||||
EventType type;
|
||||
InputEvent input;
|
||||
} PluginEvent;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#ifndef _TOTP_PLUGIN_STATE_H_
|
||||
#define _TOTP_PLUGIN_STATE_H_
|
||||
#pragma once
|
||||
|
||||
#include <notification/notification.h>
|
||||
#include <gui/gui.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include "../lib/list/list.h"
|
||||
#include "../services/list/list.h"
|
||||
#include "../scenes/totp_scenes_enum.h"
|
||||
|
||||
#define TOTP_IV_SIZE 16
|
||||
@@ -27,5 +26,3 @@ typedef struct {
|
||||
uint8_t iv[TOTP_IV_SIZE];
|
||||
uint8_t base_iv[TOTP_IV_SIZE];
|
||||
} PluginState;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "token_info.h"
|
||||
#include "stdlib.h"
|
||||
#include "common.h"
|
||||
#include "../lib/base32/base32.h"
|
||||
#include "../services/base32/base32.h"
|
||||
|
||||
TokenInfo* token_info_alloc() {
|
||||
TokenInfo* tokenInfo = malloc(sizeof(TokenInfo));
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _TOTP_TOKEN_INFO_H_
|
||||
#define _TOTP_TOKEN_INFO_H_
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -26,5 +25,3 @@ TokenInfo* token_info_alloc();
|
||||
void token_info_free(TokenInfo* token_info);
|
||||
void token_info_set_secret(TokenInfo* token_info, const char* base32_token_secret, uint8_t token_secret_length, uint8_t* iv);
|
||||
uint8_t token_info_get_digits_count(TokenInfo* token_info);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user