1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Make /sendfile in OMEMO session configurable

`/omemo sendfile on` allows unencrypted file transfer in an OMEMO
session.

Regards https://github.com/profanity-im/profanity/pull/1270
This commit is contained in:
Michael Vetter 2020-02-17 08:31:46 +01:00
parent 674a8aaf7e
commit 36713a2ed7
7 changed files with 54 additions and 10 deletions

View File

@ -176,6 +176,7 @@ static Autocomplete otr_policy_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;
@ -626,6 +627,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 +639,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");
@ -1187,6 +1193,7 @@ cmd_ac_reset(ProfWin *window)
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);
@ -1331,6 +1338,7 @@ cmd_ac_uninit(void)
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);
@ -2303,6 +2311,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 +2329,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;

View File

@ -2236,7 +2236,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 +2251,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 +2266,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."},
{ "clear_device_list", "Clear your own device list on server side. Each client will reannounce itself when connected back."})
CMD_EXAMPLES(
"/omemo gen",

View File

@ -4802,8 +4802,10 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
{
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (mucwin->is_omemo) { //no pgp or otr available in MUCs
cons_show_error("Uploading '%s' failed: Encrypted file uploads not yet implemented!", filename);
// only omemo, no pgp/otr available in MUCs
if (mucwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_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);
return TRUE;
@ -4814,12 +4816,15 @@ cmd_sendfile(ProfWin *window, const char *const command, gchar **args)
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->pgp_send || chatwin->is_omemo || chatwin->is_otr) {
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);
return TRUE;
}
if ((chatwin->is_omemo && !prefs_get_boolean(PREF_OMEMO_SENDFILE))
|| (chatwin->pgp_send)
|| (chatwin->is_otr)) {
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);
return TRUE;
}
break;
}
case WIN_PRIVATE:
@ -8575,6 +8580,19 @@ cmd_omemo_policy(ProfWin *window, const char *const command, gchar **args)
#endif
}
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)
{

View File

@ -219,6 +219,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);

View File

@ -1800,6 +1800,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;
@ -2037,6 +2038,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:

View File

@ -160,6 +160,7 @@ typedef enum {
PREF_STATUSBAR_ROOM,
PREF_OMEMO_LOG,
PREF_OMEMO_POLICY,
PREF_OMEMO_SENDFILE,
PREF_OCCUPANTS_WRAP,
PREF_CORRECTION_ALLOW,
} preference_t;

View File

@ -2118,6 +2118,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();
}