about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-17 09:01:00 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-17 09:01:00 +0100
commit555e50cc92b03199379d8da027c305b6207e7eed (patch)
treea2b745af91f6e8456036ab4fff955e52e8269eb3
parentca3afa7e05ae87158b6c1bfca1758763d4b0d8a2 (diff)
parent7955f4426281fb14523064f5359a2942ad5996e4 (diff)
downloadprofani-tty-555e50cc92b03199379d8da027c305b6207e7eed.tar.gz
Merge branch 'feature/sendfile-enc-warn'
Close https://github.com/profanity-im/profanity/pull/1270
-rw-r--r--src/command/cmd_ac.c40
-rw-r--r--src/command/cmd_defs.c20
-rw-r--r--src/command/cmd_funcs.c72
-rw-r--r--src/command/cmd_funcs.h2
-rw-r--r--src/config/preferences.c9
-rw-r--r--src/config/preferences.h3
-rw-r--r--src/ui/console.c18
7 files changed, 157 insertions, 7 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 386e8939..4d6c1d90 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -173,9 +173,11 @@ 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;
+static Autocomplete omemo_sendfile_ac;
 static Autocomplete connect_property_ac;
 static Autocomplete tls_property_ac;
 static Autocomplete alias_ac;
@@ -204,6 +206,7 @@ static Autocomplete inpblock_ac;
 static Autocomplete receipts_ac;
 static Autocomplete pgp_ac;
 static Autocomplete pgp_log_ac;
+static Autocomplete pgp_sendfile_ac;
 static Autocomplete tls_ac;
 static Autocomplete titlebar_ac;
 static Autocomplete titlebar_show_ac;
@@ -604,6 +607,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");
@@ -615,6 +619,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");
@@ -626,6 +634,7 @@ cmd_ac_init(void)
     autocomplete_add(omemo_ac, "clear_device_list");
     autocomplete_add(omemo_ac, "policy");
     autocomplete_add(omemo_ac, "char");
+    autocomplete_add(omemo_ac, "sendfile");
 
     omemo_log_ac = autocomplete_new();
     autocomplete_add(omemo_log_ac, "on");
@@ -637,6 +646,10 @@ cmd_ac_init(void)
     autocomplete_add(omemo_policy_ac, "automatic");
     autocomplete_add(omemo_policy_ac, "always");
 
+    omemo_sendfile_ac = autocomplete_new();
+    autocomplete_add(omemo_sendfile_ac, "on");
+    autocomplete_add(omemo_sendfile_ac, "off");
+
     connect_property_ac = autocomplete_new();
     autocomplete_add(connect_property_ac, "server");
     autocomplete_add(connect_property_ac, "port");
@@ -776,12 +789,17 @@ cmd_ac_init(void)
     autocomplete_add(pgp_ac, "end");
     autocomplete_add(pgp_ac, "log");
     autocomplete_add(pgp_ac, "char");
+    autocomplete_add(pgp_ac, "sendfile");
 
     pgp_log_ac = autocomplete_new();
     autocomplete_add(pgp_log_ac, "on");
     autocomplete_add(pgp_log_ac, "off");
     autocomplete_add(pgp_log_ac, "redact");
 
+    pgp_sendfile_ac = autocomplete_new();
+    autocomplete_add(pgp_sendfile_ac, "on");
+    autocomplete_add(pgp_sendfile_ac, "off");
+
     tls_ac = autocomplete_new();
     autocomplete_add(tls_ac, "allow");
     autocomplete_add(tls_ac, "always");
@@ -1184,9 +1202,11 @@ 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);
+    autocomplete_reset(omemo_sendfile_ac);
     autocomplete_reset(connect_property_ac);
     autocomplete_reset(tls_property_ac);
     autocomplete_reset(alias_ac);
@@ -1215,6 +1235,7 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(receipts_ac);
     autocomplete_reset(pgp_ac);
     autocomplete_reset(pgp_log_ac);
+    autocomplete_reset(pgp_sendfile_ac);
     autocomplete_reset(tls_ac);
     autocomplete_reset(titlebar_ac);
     autocomplete_reset(titlebar_show_ac);
@@ -1328,9 +1349,11 @@ 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);
+    autocomplete_free(omemo_sendfile_ac);
     autocomplete_free(connect_property_ac);
     autocomplete_free(tls_property_ac);
     autocomplete_free(alias_ac);
@@ -1358,6 +1381,7 @@ cmd_ac_uninit(void)
     autocomplete_free(receipts_ac);
     autocomplete_free(pgp_ac);
     autocomplete_free(pgp_log_ac);
+    autocomplete_free(pgp_sendfile_ac);
     autocomplete_free(tls_ac);
     autocomplete_free(titlebar_ac);
     autocomplete_free(titlebar_show_ac);
@@ -2226,6 +2250,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;
@@ -2253,6 +2282,11 @@ _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous)
         return found;
     }
 
+    found = autocomplete_param_with_ac(input, "/pgp sendfile", pgp_sendfile_ac, TRUE, previous);
+    if (found) {
+        return found;
+    }
+
 #ifdef HAVE_LIBGPGME
     gboolean result;
     gchar **args = parse_args(input, 2, 3, &result);
@@ -2303,6 +2337,11 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
         return found;
     }
 
+    found = autocomplete_param_with_ac(input, "/omemo sendfile", omemo_sendfile_ac, TRUE, previous);
+    if (found) {
+        return found;
+    }
+
     jabber_conn_status_t conn_status = connection_get_status();
 
     if (conn_status == JABBER_CONNECTED) {
@@ -2316,7 +2355,6 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
             return found;
         }
 
-
 #ifdef HAVE_OMEMO
         if (window->type == WIN_CHAT) {
             ProfChatWin *chatwin = (ProfChatWin*)window;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 78a2e342..1e655a26 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1657,7 +1657,8 @@ static struct cmd_t command_defs[] =
             "/pgp start [<contact>]",
             "/pgp end",
             "/pgp log on|off|redact",
-            "/pgp char <char>")
+            "/pgp char <char>",
+            "/pgp sendfile on|off")
         CMD_DESC(
             "Open PGP commands to manage keys, and perform PGP encryption during chat sessions. "
             "See the /account command to set your own PGP key.")
@@ -1670,7 +1671,8 @@ static struct cmd_t command_defs[] =
             { "end",                      "End PGP encrypted chat with the current recipient." },
             { "log on|off",               "Enable or disable plaintext logging of PGP encrypted messages." },
             { "log redact",               "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." },
-            { "char <char>",              "Set the character to be displayed next to PGP encrypted messages." })
+            { "char <char>",              "Set the character to be displayed next to PGP encrypted messages." },
+            { "sendfile on|off",          "Allow /sendfile to send unencrypted files while otherwise using PGP session."})
         CMD_EXAMPLES(
             "/pgp log off",
             "/pgp setkey buddy@buddychat.org BA19CACE5A9592C5",
@@ -1695,7 +1697,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 +1715,8 @@ static struct cmd_t command_defs[] =
             "/otr answer <answer>",
             "/otr policy manual|opportunistic|always [<contact>]",
             "/otr log on|off|redact",
-            "/otr char <char>")
+            "/otr char <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 +1738,8 @@ static struct cmd_t command_defs[] =
             { "policy always <contact>",        "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 <char>",                    "Set the character to be displayed next to OTR encrypted messages." })
+            { "char <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",
@@ -2236,7 +2241,8 @@ static struct cmd_t command_defs[] =
             { "fingerprint", cmd_omemo_fingerprint },
             { "char", cmd_omemo_char },
             { "policy", cmd_omemo_policy },
-            { "clear_device_list", cmd_omemo_clear_device_list })
+            { "clear_device_list", cmd_omemo_clear_device_list },
+            { "sendfile", cmd_omemo_sendfile} )
         CMD_NOMAINFUNC
         CMD_TAGS(
             CMD_TAG_CHAT,
@@ -2250,6 +2256,7 @@ static struct cmd_t command_defs[] =
             "/omemo fingerprint [<contact>]",
             "/omemo char <char>",
             "/omemo policy manual|automatic|always",
+            "/omemo sendfile on|off",
             "/omemo clear_device_list")
         CMD_DESC(
             "OMEMO commands to manage keys, and perform encryption during chat sessions.")
@@ -2264,6 +2271,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 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 93b002f4..4f617ffe 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4797,6 +4797,47 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
+    switch (window->type) {
+        case WIN_MUC:
+        {
+            ProfMucWin *mucwin = (ProfMucWin*)window;
+            assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+
+            // only omemo, no pgp/otr available in MUCs
+            if (mucwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE)) {
+                cons_show_error("Uploading unencrypted files disabled. See /omemo sendfile, /otr sendfile, /pgp sendfile.");
+				win_println(window, THEME_ERROR, '-', "Sending encrypted files via http_upload is not possible yet.");
+				free(filename);
+				return TRUE;
+				}
+            break;
+        }
+        case WIN_CHAT:
+        {
+            ProfChatWin *chatwin = (ProfChatWin*)window;
+            assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+
+            if ((chatwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE))
+                    || (chatwin->pgp_send && !prefs_get_boolean(PREF_PGP_SENDFILE))
+                    || (chatwin->is_otr && !prefs_get_boolean(PREF_OTR_SENDFILE))) {
+                cons_show_error("Uploading unencrypted files disabled. See /omemo sendfile, /otr sendfile, /pgp sendfile.");
+                win_println(window, THEME_ERROR, '-', "Sending encrypted files via http_upload is not possible yet.");
+                free(filename);
+                return TRUE;
+            }
+            break;
+        }
+        case WIN_PRIVATE:
+        {
+            //we don't support encryption in private muc windows
+            break;
+        }
+        default:
+			cons_show_error("Unsupported window for file transmission.");
+			free(filename);
+			return TRUE;
+        }
+        
     if (access(filename, R_OK) != 0) {
         cons_show_error("Uploading '%s' failed: File not found!", filename);
         free(filename);
@@ -7296,6 +7337,11 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "sendfile") == 0) {
+        _cmd_set_boolean_preference(args[1], command, "Sending unencrypted files using /sendfile while otherwise using PGP", PREF_PGP_SENDFILE);
+        return TRUE;
+    }
+
     cons_bad_cmd_usage(command);
     return TRUE;
 #else
@@ -7770,6 +7816,19 @@ cmd_otr_answer(ProfWin *window, const char *const command, gchar **args)
 }
 
 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)
 {
     jabber_conn_status_t conn_status = connection_get_status();
@@ -8541,6 +8600,19 @@ cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args)
 }
 
 gboolean
+cmd_omemo_sendfile(ProfWin *window, const char *const command, gchar **args)
+{
+#ifdef HAVE_OMEMO
+    _cmd_set_boolean_preference(args[1], command, "Sending unencrypted files in an OMEMO session via /sendfile", PREF_OMEMO_SENDFILE);
+
+    return TRUE;
+#else
+    cons_show("This version of Profanity has not been built with OMEMO support enabled");
+    return TRUE;
+#endif
+}
+
+gboolean
 cmd_save(ProfWin *window, const char *const command, gchar **args)
 {
     log_info("Saving preferences to configuration file");
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index f283c910..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);
@@ -219,6 +220,7 @@ gboolean cmd_omemo_trust(ProfWin *window, const char *const command, gchar **arg
 gboolean cmd_omemo_untrust(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_omemo_sendfile(ProfWin *window, const char *const command, gchar **args);
 
 gboolean cmd_save(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_reload(ProfWin *window, const char *const command, gchar **args);
diff --git a/src/config/preferences.c b/src/config/preferences.c
index dea6a529..52ce5ca9 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -1790,8 +1790,10 @@ _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:
+        case PREF_PGP_SENDFILE:
             return PREF_GROUP_PGP;
         case PREF_BOOKMARK_INVITE:
         case PREF_ROOM_LIST_CACHE:
@@ -1800,6 +1802,7 @@ _get_group(preference_t pref)
             return PREF_GROUP_PLUGINS;
         case PREF_OMEMO_LOG:
         case PREF_OMEMO_POLICY:
+        case PREF_OMEMO_SENDFILE:
             return PREF_GROUP_OMEMO;
         default:
             return NULL;
@@ -1915,6 +1918,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:
@@ -1999,6 +2004,8 @@ _get_key(preference_t pref)
             return "titlebar.muc.title";
         case PREF_PGP_LOG:
             return "log";
+        case PREF_PGP_SENDFILE:
+            return "sendfile";
         case PREF_TLS_CERTPATH:
             return "tls.certpath";
         case PREF_TLS_SHOW:
@@ -2037,6 +2044,8 @@ _get_key(preference_t pref)
             return "log";
         case PREF_OMEMO_POLICY:
             return "policy";
+        case PREF_OMEMO_SENDFILE:
+            return "sendfile";
         case PREF_CORRECTION_ALLOW:
             return "correction.allow";
         default:
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 4c903272..4d04fd7d 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -135,12 +135,14 @@ typedef enum {
     PREF_LOG_SHARED,
     PREF_OTR_LOG,
     PREF_OTR_POLICY,
+    PREF_OTR_SENDFILE,
     PREF_RESOURCE_TITLE,
     PREF_RESOURCE_MESSAGE,
     PREF_INPBLOCK_DYNAMIC,
     PREF_ENC_WARN,
     PREF_TITLEBAR_MUC_TITLE,
     PREF_PGP_LOG,
+    PREF_PGP_SENDFILE,
     PREF_TLS_CERTPATH,
     PREF_TLS_SHOW,
     PREF_LASTACTIVITY,
@@ -160,6 +162,7 @@ typedef enum {
     PREF_STATUSBAR_ROOM,
     PREF_OMEMO_LOG,
     PREF_OMEMO_POLICY,
+    PREF_OMEMO_SENDFILE,
     PREF_OCCUPANTS_WRAP,
     PREF_CORRECTION_ALLOW,
 } preference_t;
diff --git a/src/ui/console.c b/src/ui/console.c
index f7fa448d..c0abbc36 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();
 }
 
@@ -2092,6 +2098,12 @@ cons_show_pgp_prefs(void)
     char ch = prefs_get_pgp_char();
     cons_show("PGP char (/pgp char)     : %c", ch);
 
+    if (prefs_get_boolean(PREF_PGP_SENDFILE)) {
+        cons_show("Allow sending unencrypted files via /sendfile while otherwise using PGP (/pgp sendfile): ON");
+    } else {
+        cons_show("Allow sending unencrypted files via /sendfile while otherwise using PGP (/pgp sendfile): OFF");
+    }
+
     cons_alert();
 }
 
@@ -2118,6 +2130,12 @@ cons_show_omemo_prefs(void)
     char ch = prefs_get_omemo_char();
     cons_show("OMEMO char (/omemo char)     : %c", ch);
 
+    if (prefs_get_boolean(PREF_OMEMO_SENDFILE)) {
+        cons_show("Allow sending unencrypted files in an OMEMO session via /sendfile (/omemo sendfile): ON");
+    } else {
+        cons_show("Allow sending unencrypted files in an OMEMO session via /sendfile (/omemo sendfile): OFF");
+    }
+
     cons_alert();
 }