|
@@ -31,13 +31,13 @@ static bool token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str)
|
|
|
if(furi_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;
|
|
token_info->algo = SHA1;
|
|
|
return true;
|
|
return true;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME) == 0) {
|
|
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME) == 0) {
|
|
|
token_info->algo = SHA256;
|
|
token_info->algo = SHA256;
|
|
|
return true;
|
|
return true;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME) == 0) {
|
|
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME) == 0) {
|
|
|
token_info->algo = SHA512;
|
|
token_info->algo = SHA512;
|
|
|
return true;
|
|
return true;
|
|
@@ -47,11 +47,21 @@ static bool token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_add_print_help() {
|
|
void totp_cli_command_add_print_help() {
|
|
|
- TOTP_CLI_PRINTF("\t" TOTP_CLI_COMMAND_ADD " " TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_NAME) " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX " " TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_ALGO)) " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX " " TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_DIGITS)) " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) " - add new token\r\n");
|
|
|
|
|
|
|
+ TOTP_CLI_PRINTF("\t" TOTP_CLI_COMMAND_ADD " " TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_NAME) " " TOTP_CLI_OPTIONAL_PARAM(
|
|
|
|
|
+ TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX " " TOTP_CLI_ARG(
|
|
|
|
|
+ TOTP_CLI_COMMAND_ADD_ARG_ALGO)) " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
|
|
|
|
|
+ " " TOTP_CLI_ARG(
|
|
|
|
|
+ TOTP_CLI_COMMAND_ADD_ARG_DIGITS)) " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) " - add new token\r\n");
|
|
|
TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_NAME) " - token name\r\n");
|
|
TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_NAME) " - token name\r\n");
|
|
|
- TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_ALGO) " - " TOTP_CLI_OPTIONAL_PARAM_MARK " token hashing algorithm, could be one of: sha1, sha256, sha512; default: sha1\r\n");
|
|
|
|
|
- TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(TOTP_CLI_COMMAND_ADD_ARG_DIGITS) " - " TOTP_CLI_OPTIONAL_PARAM_MARK " number of digits to generate, one of: 6, 8; default: 6\r\n");
|
|
|
|
|
- TOTP_CLI_PRINTF("\t\t" TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX " - " TOTP_CLI_OPTIONAL_PARAM_MARK " to show console user input as-is without masking; default: show masked\r\n\r\n");
|
|
|
|
|
|
|
+ TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(
|
|
|
|
|
+ TOTP_CLI_COMMAND_ADD_ARG_ALGO) " - " TOTP_CLI_OPTIONAL_PARAM_MARK
|
|
|
|
|
+ " token hashing algorithm, could be one of: sha1, sha256, sha512; default: sha1\r\n");
|
|
|
|
|
+ TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(
|
|
|
|
|
+ TOTP_CLI_COMMAND_ADD_ARG_DIGITS) " - " TOTP_CLI_OPTIONAL_PARAM_MARK
|
|
|
|
|
+ " number of digits to generate, one of: 6, 8; default: 6\r\n");
|
|
|
|
|
+ TOTP_CLI_PRINTF(
|
|
|
|
|
+ "\t\t" TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX " - " TOTP_CLI_OPTIONAL_PARAM_MARK
|
|
|
|
|
+ " to show console user input as-is without masking; default: show masked\r\n\r\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
|
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
|
@@ -61,7 +71,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
TokenInfo* token_info = token_info_alloc();
|
|
TokenInfo* token_info = token_info_alloc();
|
|
|
|
|
|
|
|
// Reading token name
|
|
// Reading token name
|
|
|
- if (!args_read_probably_quoted_string_and_trim(args, temp_str)) {
|
|
|
|
|
|
|
+ if(!args_read_probably_quoted_string_and_trim(args, temp_str)) {
|
|
|
totp_cli_print_invalid_arguments();
|
|
totp_cli_print_invalid_arguments();
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
token_info_free(token_info);
|
|
token_info_free(token_info);
|
|
@@ -74,30 +84,39 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
|
|
|
|
|
// Read optional arguments
|
|
// Read optional arguments
|
|
|
bool mask_user_input = true;
|
|
bool mask_user_input = true;
|
|
|
- while (args_read_string_and_trim(args, temp_str)) {
|
|
|
|
|
|
|
+ while(args_read_string_and_trim(args, temp_str)) {
|
|
|
bool parsed = false;
|
|
bool parsed = false;
|
|
|
- if (furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX) == 0) {
|
|
|
|
|
- if (!args_read_string_and_trim(args, temp_str)) {
|
|
|
|
|
- TOTP_CLI_PRINTF("Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX "\"\r\n");
|
|
|
|
|
- } else if (!token_info_set_algo_from_str(token_info, temp_str)) {
|
|
|
|
|
- TOTP_CLI_PRINTF("\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX "\"\r\n", furi_string_get_cstr(temp_str));
|
|
|
|
|
|
|
+ if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX) == 0) {
|
|
|
|
|
+ if(!args_read_string_and_trim(args, temp_str)) {
|
|
|
|
|
+ TOTP_CLI_PRINTF("Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX
|
|
|
|
|
+ "\"\r\n");
|
|
|
|
|
+ } else if(!token_info_set_algo_from_str(token_info, temp_str)) {
|
|
|
|
|
+ TOTP_CLI_PRINTF(
|
|
|
|
|
+ "\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX
|
|
|
|
|
+ "\"\r\n",
|
|
|
|
|
+ furi_string_get_cstr(temp_str));
|
|
|
} else {
|
|
} else {
|
|
|
parsed = true;
|
|
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)) {
|
|
|
|
|
- TOTP_CLI_PRINTF("Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "\"\r\n");
|
|
|
|
|
- } else if (!token_info_set_digits_from_str(token_info, temp_str)) {
|
|
|
|
|
- TOTP_CLI_PRINTF("\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "\"\r\n", furi_string_get_cstr(temp_str));
|
|
|
|
|
|
|
+ } 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)) {
|
|
|
|
|
+ TOTP_CLI_PRINTF(
|
|
|
|
|
+ "Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
|
|
|
|
|
+ "\"\r\n");
|
|
|
|
|
+ } else if(!token_info_set_digits_from_str(token_info, temp_str)) {
|
|
|
|
|
+ TOTP_CLI_PRINTF(
|
|
|
|
|
+ "\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
|
|
|
|
|
+ "\"\r\n",
|
|
|
|
|
+ furi_string_get_cstr(temp_str));
|
|
|
} else {
|
|
} else {
|
|
|
parsed = true;
|
|
parsed = true;
|
|
|
}
|
|
}
|
|
|
- } else if (furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) == 0) {
|
|
|
|
|
|
|
+ } else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) == 0) {
|
|
|
mask_user_input = false;
|
|
mask_user_input = false;
|
|
|
parsed = true;
|
|
parsed = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!parsed) {
|
|
|
|
|
|
|
+ if(!parsed) {
|
|
|
totp_cli_print_invalid_arguments();
|
|
totp_cli_print_invalid_arguments();
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
token_info_free(token_info);
|
|
token_info_free(token_info);
|
|
@@ -111,7 +130,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
|
|
|
|
|
uint8_t c;
|
|
uint8_t c;
|
|
|
while(cli_read(cli, &c, 1) == 1) {
|
|
while(cli_read(cli, &c, 1) == 1) {
|
|
|
- if (c == CliSymbolAsciiEsc) {
|
|
|
|
|
|
|
+ if(c == CliSymbolAsciiEsc) {
|
|
|
uint8_t c2;
|
|
uint8_t c2;
|
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
cli_read_timeout(cli, &c2, 1, 0);
|
|
@@ -121,22 +140,21 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
token_info_free(token_info);
|
|
token_info_free(token_info);
|
|
|
return;
|
|
return;
|
|
|
} else if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
|
} else if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
|
|
- if (mask_user_input) {
|
|
|
|
|
|
|
+ if(mask_user_input) {
|
|
|
putc('*', stdout);
|
|
putc('*', stdout);
|
|
|
} else {
|
|
} else {
|
|
|
putc(c, stdout);
|
|
putc(c, stdout);
|
|
|
}
|
|
}
|
|
|
fflush(stdout);
|
|
fflush(stdout);
|
|
|
furi_string_push_back(temp_str, c);
|
|
furi_string_push_back(temp_str, c);
|
|
|
- } else if (c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
|
|
|
|
|
|
|
+ } else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
|
|
|
size_t temp_str_size = furi_string_size(temp_str);
|
|
size_t temp_str_size = furi_string_size(temp_str);
|
|
|
- if (temp_str_size > 0) {
|
|
|
|
|
|
|
+ if(temp_str_size > 0) {
|
|
|
TOTP_CLI_PRINTF("\b \b");
|
|
TOTP_CLI_PRINTF("\b \b");
|
|
|
fflush(stdout);
|
|
fflush(stdout);
|
|
|
furi_string_left(temp_str, temp_str_size - 1);
|
|
furi_string_left(temp_str, temp_str_size - 1);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- else if(c == CliSymbolAsciiCR) {
|
|
|
|
|
|
|
+ } else if(c == CliSymbolAsciiCR) {
|
|
|
cli_nl();
|
|
cli_nl();
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -144,13 +162,13 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
|
|
|
|
|
temp_cstr = furi_string_get_cstr(temp_str);
|
|
temp_cstr = furi_string_get_cstr(temp_str);
|
|
|
|
|
|
|
|
- if (!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
|
|
|
|
|
|
+ if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
token_info_free(token_info);
|
|
token_info_free(token_info);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!token_info_set_secret(token_info, temp_cstr, strlen(temp_cstr), plugin_state->iv)) {
|
|
|
|
|
|
|
+ if(!token_info_set_secret(token_info, temp_cstr, strlen(temp_cstr), plugin_state->iv)) {
|
|
|
TOTP_CLI_PRINTF("Token secret seems to be invalid and can not be parsed\r\n");
|
|
TOTP_CLI_PRINTF("Token secret seems to be invalid and can not be parsed\r\n");
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
token_info_free(token_info);
|
|
token_info_free(token_info);
|
|
@@ -161,7 +179,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
furi_string_free(temp_str);
|
|
furi_string_free(temp_str);
|
|
|
|
|
|
|
|
bool load_generate_token_scene = false;
|
|
bool load_generate_token_scene = false;
|
|
|
- if (plugin_state->current_scene == TotpSceneGenerateToken) {
|
|
|
|
|
|
|
+ if(plugin_state->current_scene == TotpSceneGenerateToken) {
|
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
|
|
|
load_generate_token_scene = true;
|
|
load_generate_token_scene = true;
|
|
|
}
|
|
}
|
|
@@ -174,7 +192,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
|
|
plugin_state->tokens_count++;
|
|
plugin_state->tokens_count++;
|
|
|
totp_config_file_save_new_token(token_info);
|
|
totp_config_file_save_new_token(token_info);
|
|
|
|
|
|
|
|
- if (load_generate_token_scene) {
|
|
|
|
|
|
|
+ if(load_generate_token_scene) {
|
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
|
|
}
|
|
}
|
|
|
|
|
|