From 86bcadcbe3806439ca2039b39af08afd4db70429 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 17 Feb 2020 08:44:26 +0100 Subject: [PATCH] Make /sendfile in OTR session configurable `/otr sendfile on` allows unencrypted file transfer in an OMEMO session. Regards https://github.com/profanity-im/profanity/pull/1270 --- src/command/cmd_ac.c | 13 +++++++++++++ src/command/cmd_defs.c | 11 +++++++---- src/command/cmd_funcs.c | 18 ++++++++++++++++-- src/command/cmd_funcs.h | 1 + src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/ui/console.c | 6 ++++++ 7 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 0e65c3fd..7d170d10 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -173,6 +173,7 @@ static Autocomplete bookmark_property_ac; static Autocomplete otr_ac; static Autocomplete otr_log_ac; static Autocomplete otr_policy_ac; +static Autocomplete otr_sendfile_ac; static Autocomplete omemo_ac; static Autocomplete omemo_log_ac; static Autocomplete omemo_policy_ac; @@ -605,6 +606,7 @@ cmd_ac_init(void) autocomplete_add(otr_ac, "question"); autocomplete_add(otr_ac, "answer"); autocomplete_add(otr_ac, "char"); + autocomplete_add(otr_ac, "sendfile"); otr_log_ac = autocomplete_new(); autocomplete_add(otr_log_ac, "on"); @@ -616,6 +618,10 @@ cmd_ac_init(void) autocomplete_add(otr_policy_ac, "opportunistic"); autocomplete_add(otr_policy_ac, "always"); + otr_sendfile_ac = autocomplete_new(); + autocomplete_add(otr_sendfile_ac, "on"); + autocomplete_add(otr_sendfile_ac, "off"); + omemo_ac = autocomplete_new(); autocomplete_add(omemo_ac, "gen"); autocomplete_add(omemo_ac, "log"); @@ -1190,6 +1196,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(otr_ac); autocomplete_reset(otr_log_ac); autocomplete_reset(otr_policy_ac); + autocomplete_reset(otr_sendfile_ac); autocomplete_reset(omemo_ac); autocomplete_reset(omemo_log_ac); autocomplete_reset(omemo_policy_ac); @@ -1335,6 +1342,7 @@ cmd_ac_uninit(void) autocomplete_free(otr_ac); autocomplete_free(otr_log_ac); autocomplete_free(otr_policy_ac); + autocomplete_free(otr_sendfile_ac); autocomplete_free(omemo_ac); autocomplete_free(omemo_log_ac); autocomplete_free(omemo_policy_ac); @@ -2234,6 +2242,11 @@ _otr_autocomplete(ProfWin *window, const char *const input, gboolean previous) return found; } + found = autocomplete_param_with_ac(input, "/otr sendfile", otr_sendfile_ac, TRUE, previous); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/otr", otr_ac, TRUE, previous); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 5d3d0067..3897efc1 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1695,7 +1695,8 @@ static struct cmd_t command_defs[] = { "untrust", cmd_otr_untrust }, { "secret", cmd_otr_secret }, { "question", cmd_otr_question }, - { "answer", cmd_otr_answer }) + { "answer", cmd_otr_answer }, + { "sendfile", cmd_otr_sendfile }) CMD_NOMAINFUNC CMD_TAGS( CMD_TAG_CHAT, @@ -1712,7 +1713,8 @@ static struct cmd_t command_defs[] = "/otr answer ", "/otr policy manual|opportunistic|always []", "/otr log on|off|redact", - "/otr char ") + "/otr char ", + "/otr sendfile on|off") CMD_DESC( "Off The Record (OTR) commands to manage keys, and perform OTR encryption during chat sessions.") CMD_ARGS( @@ -1734,7 +1736,8 @@ static struct cmd_t command_defs[] = { "policy always ", "Set the OTR policy to always for a specific contact." }, { "log on|off", "Enable or disable plaintext logging of OTR encrypted messages." }, { "log redact", "Log OTR encrypted messages, but replace the contents with [redacted]. This is the default." }, - { "char ", "Set the character to be displayed next to OTR encrypted messages." }) + { "char ", "Set the character to be displayed next to OTR encrypted messages." }, + { "sendfile on|off", "Allow /sendfile to send unencrypted files while in an OTR session."}) CMD_EXAMPLES( "/otr log off", "/otr policy manual", @@ -2266,7 +2269,7 @@ static struct cmd_t command_defs[] = { "policy manual", "Set the global OMEMO policy to manual, OMEMO sessions must be started manually." }, { "policy automatic", "Set the global OMEMO policy to opportunistic, an OMEMO session will be attempted upon starting a conversation." }, { "policy always", "Set the global OMEMO policy to always, an error will be displayed if an OMEMO session cannot be initiated upon starting a conversation." }, - { "sendfile", "Allow /sendfile to send unencrypted files while in an OMEMO session."}, + { "sendfile on|off", "Allow /sendfile to send unencrypted files while in an OMEMO session."}, { "clear_device_list", "Clear your own device list on server side. Each client will reannounce itself when connected back."}) CMD_EXAMPLES( "/omemo gen", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index e5c540c3..e93397cb 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4819,7 +4819,7 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args) if ((chatwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE)) || (chatwin->pgp_send) - || (chatwin->is_otr)) { + || (chatwin->is_otr && !prefs_get_boolean(PREF_OTR_SENDFILE))) { cons_show_error("Uploading '%s' failed: Encrypted file uploads not yet implemented!", filename); win_println(window, THEME_ERROR, '-', "Sending encrypted files via http_upload is not possible yet."); free(filename); @@ -4829,7 +4829,8 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args) } case WIN_PRIVATE: { - break; //we don't support encryption in private muc windows anyway + //we don't support encryption in private muc windows + break; } default: cons_show_error("Unsupported window for file transmission."); @@ -7809,6 +7810,19 @@ cmd_otr_answer(ProfWin *window, const char *const command, gchar **args) #endif } +gboolean +cmd_otr_sendfile(ProfWin *window, const char *const command, gchar **args) +{ +#ifdef HAVE_LIBOTR + _cmd_set_boolean_preference(args[1], command, "Sending unencrypted files in an OTR session via /sendfile", PREF_OTR_SENDFILE); + + return TRUE; +#else + cons_show("This version of Profanity has not been built with OTR support enabled"); + return TRUE; +#endif +} + gboolean cmd_command_list(ProfWin *window, const char *const command, gchar **args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 389c35de..58d99635 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -201,6 +201,7 @@ gboolean cmd_otr_untrust(ProfWin *window, const char *const command, gchar **arg gboolean cmd_otr_secret(ProfWin *window, const char *const command, gchar **args); gboolean cmd_otr_question(ProfWin *window, const char *const command, gchar **args); gboolean cmd_otr_answer(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_otr_sendfile(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_unread(ProfWin *window, const char *const command, gchar **args); diff --git a/src/config/preferences.c b/src/config/preferences.c index 8a503291..085aa910 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1790,6 +1790,7 @@ _get_group(preference_t pref) return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: + case PREF_OTR_SENDFILE: return PREF_GROUP_OTR; case PREF_PGP_LOG: return PREF_GROUP_PGP; @@ -1916,6 +1917,8 @@ _get_key(preference_t pref) return "log"; case PREF_OTR_POLICY: return "policy"; + case PREF_OTR_SENDFILE: + return "sendfile"; case PREF_LOG_ROTATE: return "rotate"; case PREF_LOG_SHARED: diff --git a/src/config/preferences.h b/src/config/preferences.h index a373a701..d850df5c 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -135,6 +135,7 @@ typedef enum { PREF_LOG_SHARED, PREF_OTR_LOG, PREF_OTR_POLICY, + PREF_OTR_SENDFILE, PREF_RESOURCE_TITLE, PREF_RESOURCE_MESSAGE, PREF_INPBLOCK_DYNAMIC, diff --git a/src/ui/console.c b/src/ui/console.c index 6de8258f..4877725d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2070,6 +2070,12 @@ cons_show_otr_prefs(void) char ch = prefs_get_otr_char(); cons_show("OTR char (/otr char) : %c", ch); + if (prefs_get_boolean(PREF_OTR_SENDFILE)) { + cons_show("Allow sending unencrypted files in an OTR session via /sendfile (/otr sendfile): ON"); + } else { + cons_show("Allow sending unencrypted files in an OTR session via /sendfile (/otr sendfile): OFF"); + } + cons_alert(); }