From 36625da3d8c02fe2dd6c42b0e027a79f0720501a Mon Sep 17 00:00:00 2001 From: Paolo Stivanin Date: Fri, 8 Mar 2024 11:23:44 +0100 Subject: [PATCH] Add possibility to export authpro/2fas using the cli --- src/cli/exec-action.c | 26 ++++++++++++++++++++++++++ src/cli/main.c | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cli/exec-action.c b/src/cli/exec-action.c index d906583..6fe233a 100644 --- a/src/cli/exec-action.c +++ b/src/cli/exec-action.c @@ -124,6 +124,32 @@ gboolean exec_action (CmdlineOpts *cmdline_opts, gcry_free (export_pwd); exported = TRUE; } + if (g_ascii_strcasecmp (cmdline_opts->export_type, "twofas_plain") == 0 || g_ascii_strcasecmp (cmdline_opts->export_type, "twofas_encrypted") == 0) { + if (g_ascii_strcasecmp (cmdline_opts->export_type, "twofas_encrypted") == 0) { + export_pwd = get_pwd (_("Type the export encryption password: ")); + if (export_pwd == NULL) { + free_dbdata (db_data); + return FALSE; + } + } + exported_file_path = g_build_filename (export_directory, export_pwd != NULL ? "twofas_encrypted_v4.2fas" : "twofas_plain_v4.2fas", NULL); + ret_msg = export_twofas (exported_file_path, export_pwd, db_data->json_data); + gcry_free (export_pwd); + exported = TRUE; + } + if (g_ascii_strcasecmp (cmdline_opts->export_type, "authpro_plain") == 0 || g_ascii_strcasecmp (cmdline_opts->export_type, "authpro_encrypted") == 0) { + if (g_ascii_strcasecmp (cmdline_opts->export_type, "authpro_encrypted") == 0) { + export_pwd = get_pwd (_("Type the export encryption password: ")); + if (export_pwd == NULL) { + free_dbdata (db_data); + return FALSE; + } + } + exported_file_path = g_build_filename (export_directory, export_pwd != NULL ? "authpro_encrypted.bin" : "authpro_plain.json", NULL); + ret_msg = export_authpro (exported_file_path, export_pwd, db_data->json_data); + gcry_free (export_pwd); + exported = TRUE; + } if (ret_msg != NULL) { g_printerr (_("An error occurred while exporting the data: %s\n"), ret_msg); g_free (ret_msg); diff --git a/src/cli/main.c b/src/cli/main.c index 9bb888a..719c8fe 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -34,7 +34,7 @@ main (gint argc, { "show-next", 'n', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Show also next OTP (to be used with --show, optional)", NULL}, { "list", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "List all accounts and issuers for a given database.", NULL }, { "export", 'e', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Export a database.", NULL }, - { "type", 't', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, "The export type for the database. Must be either one of: andotp_plain, andotp_encrypted, freeotpplus, aegis, aegis_encrypted (to be used with --export, mandatory)", NULL }, + { "type", 't', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, "The export type for the database. Must be either one of: andotp_plain, andotp_encrypted, freeotpplus, aegis_plain, aegis_encrypted, twofas_plain, twofas_encrypted, authpro_plain, authpro_encrypted (to be used with --export, mandatory)", NULL }, #ifndef USE_FLATPAK_APP_FOLDER { "output-dir", 'o', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, "The output directory (defaults to the user's home. To be used with --export, optional)", NULL }, #endif