|
@@ -155,8 +155,15 @@ FlipperFormat* totp_open_config_file(Storage* storage) {
|
|
|
void totp_config_file_save_new_token_i(FlipperFormat* file, TokenInfo* token_info) {
|
|
void totp_config_file_save_new_token_i(FlipperFormat* file, TokenInfo* token_info) {
|
|
|
flipper_format_seek_to_end(file);
|
|
flipper_format_seek_to_end(file);
|
|
|
flipper_format_write_string_cstr(file, TOTP_CONFIG_KEY_TOKEN_NAME, token_info->name);
|
|
flipper_format_write_string_cstr(file, TOTP_CONFIG_KEY_TOKEN_NAME, token_info->name);
|
|
|
|
|
+ bool token_is_valid = token_info->token != NULL && token_info->token_length > 0;
|
|
|
|
|
+ if(!token_is_valid) {
|
|
|
|
|
+ flipper_format_write_comment_cstr(file, "!!! WARNING BEGIN: INVALID TOKEN !!!");
|
|
|
|
|
+ }
|
|
|
flipper_format_write_hex(
|
|
flipper_format_write_hex(
|
|
|
file, TOTP_CONFIG_KEY_TOKEN_SECRET, token_info->token, token_info->token_length);
|
|
file, TOTP_CONFIG_KEY_TOKEN_SECRET, token_info->token, token_info->token_length);
|
|
|
|
|
+ if(!token_is_valid) {
|
|
|
|
|
+ flipper_format_write_comment_cstr(file, "!!! WARNING END !!!");
|
|
|
|
|
+ }
|
|
|
flipper_format_write_string_cstr(
|
|
flipper_format_write_string_cstr(
|
|
|
file, TOTP_CONFIG_KEY_TOKEN_ALGO, token_info_get_algo_as_cstr(token_info));
|
|
file, TOTP_CONFIG_KEY_TOKEN_ALGO, token_info_get_algo_as_cstr(token_info));
|
|
|
uint32_t digits_count_as_uint32 = token_info_get_digits_as_int(token_info);
|
|
uint32_t digits_count_as_uint32 = token_info_get_digits_as_int(token_info);
|
|
@@ -312,7 +319,7 @@ void totp_config_file_load_base(PluginState* const plugin_state) {
|
|
|
totp_close_storage();
|
|
totp_close_storage();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void totp_config_file_load_tokens(PluginState* const plugin_state) {
|
|
|
|
|
|
|
+TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state) {
|
|
|
Storage* storage = totp_open_storage();
|
|
Storage* storage = totp_open_storage();
|
|
|
FlipperFormat* fff_data_file = totp_open_config_file(storage);
|
|
FlipperFormat* fff_data_file = totp_open_config_file(storage);
|
|
|
|
|
|
|
@@ -322,9 +329,10 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
|
|
|
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
|
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
|
|
FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
|
|
FURI_LOG_E(LOGGING_TAG, "Missing or incorrect header");
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
- return;
|
|
|
|
|
|
|
+ return TokenLoadingResultError;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ TokenLoadingResult result = TokenLoadingResultSuccess;
|
|
|
uint8_t index = 0;
|
|
uint8_t index = 0;
|
|
|
bool has_any_plain_secret = false;
|
|
bool has_any_plain_secret = false;
|
|
|
|
|
|
|
@@ -342,48 +350,61 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
|
|
|
uint32_t secret_bytes_count;
|
|
uint32_t secret_bytes_count;
|
|
|
if(!flipper_format_get_value_count(
|
|
if(!flipper_format_get_value_count(
|
|
|
fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, &secret_bytes_count)) {
|
|
fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, &secret_bytes_count)) {
|
|
|
- token_info_free(tokenInfo);
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ secret_bytes_count = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(secret_bytes_count == 1) { // Plain secret key
|
|
if(secret_bytes_count == 1) { // Plain secret key
|
|
|
- if(!flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
|
|
|
|
|
- token_info_free(tokenInfo);
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if(flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
|
|
|
|
|
+ temp_cstr = furi_string_get_cstr(temp_str);
|
|
|
|
|
+ if(token_info_set_secret(
|
|
|
|
|
+ tokenInfo, temp_cstr, strlen(temp_cstr), &plugin_state->iv[0])) {
|
|
|
|
|
+ FURI_LOG_W(LOGGING_TAG, "Token \"%s\" has plain secret", tokenInfo->name);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tokenInfo->token = NULL;
|
|
|
|
|
+ tokenInfo->token_length = 0;
|
|
|
|
|
+ FURI_LOG_W(LOGGING_TAG, "Token \"%s\" has invalid secret", tokenInfo->name);
|
|
|
|
|
+ result = TokenLoadingResultWarning;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tokenInfo->token = NULL;
|
|
|
|
|
+ tokenInfo->token_length = 0;
|
|
|
|
|
+ result = TokenLoadingResultWarning;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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;
|
|
has_any_plain_secret = true;
|
|
|
- FURI_LOG_W(LOGGING_TAG, "Found token with plain secret");
|
|
|
|
|
} else { // encrypted
|
|
} else { // encrypted
|
|
|
tokenInfo->token_length = secret_bytes_count;
|
|
tokenInfo->token_length = secret_bytes_count;
|
|
|
- tokenInfo->token = malloc(tokenInfo->token_length);
|
|
|
|
|
- if(!flipper_format_read_hex(
|
|
|
|
|
- fff_data_file,
|
|
|
|
|
- TOTP_CONFIG_KEY_TOKEN_SECRET,
|
|
|
|
|
- tokenInfo->token,
|
|
|
|
|
- tokenInfo->token_length)) {
|
|
|
|
|
- token_info_free(tokenInfo);
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if(secret_bytes_count > 0) {
|
|
|
|
|
+ tokenInfo->token = malloc(tokenInfo->token_length);
|
|
|
|
|
+ if(!flipper_format_read_hex(
|
|
|
|
|
+ fff_data_file,
|
|
|
|
|
+ TOTP_CONFIG_KEY_TOKEN_SECRET,
|
|
|
|
|
+ tokenInfo->token,
|
|
|
|
|
+ tokenInfo->token_length)) {
|
|
|
|
|
+ free(tokenInfo->token);
|
|
|
|
|
+ tokenInfo->token = NULL;
|
|
|
|
|
+ tokenInfo->token_length = 0;
|
|
|
|
|
+ result = TokenLoadingResultWarning;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tokenInfo->token = NULL;
|
|
|
|
|
+ result = TokenLoadingResultWarning;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(!flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str)) {
|
|
|
|
|
- token_info_free(tokenInfo);
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if(flipper_format_read_string(fff_data_file, TOTP_CONFIG_KEY_TOKEN_ALGO, temp_str)) {
|
|
|
|
|
+ token_info_set_algo_from_str(tokenInfo, temp_str);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tokenInfo->algo = SHA1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- token_info_set_algo_from_str(tokenInfo, temp_str);
|
|
|
|
|
-
|
|
|
|
|
- if(!flipper_format_read_uint32(
|
|
|
|
|
|
|
+ if(flipper_format_read_uint32(
|
|
|
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &temp_data32, 1)) {
|
|
fff_data_file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &temp_data32, 1)) {
|
|
|
- token_info_free(tokenInfo);
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ token_info_set_digits_from_int(tokenInfo, temp_data32);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tokenInfo->digits = TOTP_6_DIGITS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- token_info_set_digits_from_int(tokenInfo, temp_data32);
|
|
|
|
|
-
|
|
|
|
|
FURI_LOG_D(LOGGING_TAG, "Found token \"%s\"", tokenInfo->name);
|
|
FURI_LOG_D(LOGGING_TAG, "Found token \"%s\"", tokenInfo->name);
|
|
|
|
|
|
|
|
if(plugin_state->tokens_list == NULL) {
|
|
if(plugin_state->tokens_list == NULL) {
|
|
@@ -407,6 +428,8 @@ void totp_config_file_load_tokens(PluginState* const plugin_state) {
|
|
|
if(has_any_plain_secret) {
|
|
if(has_any_plain_secret) {
|
|
|
totp_full_save_config_file(plugin_state);
|
|
totp_full_save_config_file(plugin_state);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void totp_close_config_file(FlipperFormat* file) {
|
|
void totp_close_config_file(FlipperFormat* file) {
|