From 3303376b4209a7f6005332bd113642ad68ca3c1e Mon Sep 17 00:00:00 2001 From: lightb Date: Sat, 19 Apr 2014 03:12:22 -0400 Subject: Added PREF_OTR_POLICY - should be default global policy and set to MANUAL --- src/config/preferences.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/preferences.h b/src/config/preferences.h index 310b9032..48748883 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -64,7 +64,8 @@ typedef enum { PREF_OTR_LOG, PREF_OTR_WARN, PREF_LOG_ROTATE, - PREF_LOG_SHARED + PREF_LOG_SHARED, + PREF_OTR_POLICY } preference_t; typedef struct prof_alias_t { -- cgit 1.4.1-2-gfad0 From 02b77cfa4e9b600c03c2fa79ab0e3fa55c33961f Mon Sep 17 00:00:00 2001 From: lightb Date: Sat, 19 Apr 2014 04:00:41 -0400 Subject: Added PREF_OTR_POLICY to preferences.c -> key -> otr.policy Added default value "manual" to PREF_OTR_POLICy -> preferences.c Modified help string to reflect otr_policy, started checks on cmd_otr --- src/command/command.c | 5 +++-- src/command/commands.c | 7 +++++++ src/config/preferences.c | 4 ++++ src/otr/otr.c | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 23d5bae4..31a481b7 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -594,8 +594,8 @@ static struct cmd_t command_defs[] = { "/otr", cmd_otr, parse_args, 1, 2, NULL, - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver", "Off The Record encryption commands.", - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver", + { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy", "Off The Record encryption commands.", + { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy", "-------------------------------------------------------------", "gen - Generate your private key.", "myfp - Show your fingerprint.", @@ -607,6 +607,7 @@ static struct cmd_t command_defs[] = "log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.", "warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.", "libver - Show which version of the libotr library is being used.", + "policy - manual, opportunistic or always.", NULL } } }, { "/outtype", diff --git a/src/command/commands.c b/src/command/commands.c index 8e026b50..ad94211c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2609,6 +2609,13 @@ cmd_otr(gchar **args, struct cmd_help_t help) char *version = otr_libotr_version(); cons_show("Using libotr version %s", version); return TRUE; + } else if (strcmp(args[0], "policy") == 0) { + char *choice = args[1]; + if (g_strcmp0(choice, "manual") == 0) { + prefs_set_string(PREF_OTR_POLICY, "manual"); + cons_show("OTR policy is now set to: manual"); + } + return TRUE; } if (jabber_get_connection_status() != JABBER_CONNECTED) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 9cc91cb6..4c00597e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -466,6 +466,8 @@ _get_key(preference_t pref) return "otr"; case PREF_OTR_WARN: return "otr.warn"; + case PREF_OTR_POLICY: + return "otr.policy"; case PREF_LOG_ROTATE: return "rotate"; case PREF_LOG_SHARED: @@ -500,6 +502,8 @@ _get_default_string(preference_t pref) return "off"; case PREF_OTR_LOG: return "redact"; + case PREF_OTR_POLICY: + return "manual"; case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CHAT: case PREF_STATUSES_MUC: diff --git a/src/otr/otr.c b/src/otr/otr.c index 5424b09a..8ff64640 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -421,6 +421,7 @@ _otr_get_their_fingerprint(const char * const recipient) static char * _otr_encrypt_message(const char * const to, const char * const message) { + return NULL; char *newmessage = NULL; gcry_error_t err = otrlib_encrypt_message(user_state, &ops, jid, to, message, &newmessage); -- cgit 1.4.1-2-gfad0 From a687e3f6b4abe5e5917d25fea9f9d0bfb0c3a98d Mon Sep 17 00:00:00 2001 From: lightb Date: Sat, 19 Apr 2014 04:18:53 -0400 Subject: Added /otr policy to commands (still need to add autocomplete stuff?) --- src/command/commands.c | 19 ++++++++++++++++++- src/config/preferences.c | 3 +++ src/otr/otr.c | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index ad94211c..e92bbe1d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2610,11 +2610,28 @@ cmd_otr(gchar **args, struct cmd_help_t help) cons_show("Using libotr version %s", version); return TRUE; } else if (strcmp(args[0], "policy") == 0) { + if (args[1] == NULL) { + char *policy = prefs_get_string(PREF_OTR_POLICY); + cons_show("OTR policy is now set to: %s", policy); + return TRUE; + } + char *choice = args[1]; if (g_strcmp0(choice, "manual") == 0) { prefs_set_string(PREF_OTR_POLICY, "manual"); cons_show("OTR policy is now set to: manual"); - } + } else + if (g_strcmp0(choice, "opportunistic") == 0) { + prefs_set_string(PREF_OTR_POLICY, "opportunistic"); + cons_show("OTR policy is now set to: opportunistic"); + } else + if (g_strcmp0(choice, "always") == 0) { + prefs_set_string(PREF_OTR_POLICY, "always"); + cons_show("OTR policy is now set to: always"); + } else + { + cons_show("OTR policy can be set to: manual, opportunistic or always."); + } return TRUE; } diff --git a/src/config/preferences.c b/src/config/preferences.c index 4c00597e..f4133413 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -45,6 +45,7 @@ #define PREF_GROUP_PRESENCE "presence" #define PREF_GROUP_CONNECTION "connection" #define PREF_GROUP_ALIAS "alias" +#define PREF_GROUP_OTR_POLICY "policy" static gchar *prefs_loc; static GKeyFile *prefs; @@ -396,6 +397,8 @@ _get_group(preference_t pref) case PREF_LOG_ROTATE: case PREF_LOG_SHARED: return PREF_GROUP_LOGGING; + case PREF_OTR_POLICY: + return PREF_GROUP_OTR_POLICY; case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MESSAGE: diff --git a/src/otr/otr.c b/src/otr/otr.c index 8ff64640..5424b09a 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -421,7 +421,6 @@ _otr_get_their_fingerprint(const char * const recipient) static char * _otr_encrypt_message(const char * const to, const char * const message) { - return NULL; char *newmessage = NULL; gcry_error_t err = otrlib_encrypt_message(user_state, &ops, jid, to, message, &newmessage); -- cgit 1.4.1-2-gfad0 From 1ceca892965189b6f8751f40bd5e58e83d0f7baa Mon Sep 17 00:00:00 2001 From: lightb Date: Sat, 19 Apr 2014 05:08:33 -0400 Subject: Added some otr policy functionality, if policy is set to "always" if otr_is_secure fails, the message will not be sent. Changed both cmd_msg and cmd_execute_default --- src/command/command.c | 4 ++++ src/command/commands.c | 4 ++++ src/xmpp/message.c | 1 - 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 31a481b7..902ef19a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1328,6 +1328,10 @@ cmd_execute_default(const char * const inp) ui_current_print_line("You are not currently connected."); } else { #ifdef HAVE_LIBOTR + if ((strcmp(prefs_get_string(PREF_OTR_POLICY), "always") == 0) && !otr_is_secure(recipient)) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } if (otr_is_secure(recipient)) { char *encrypted = otr_encrypt_message(recipient, inp); if (encrypted != NULL) { diff --git a/src/command/commands.c b/src/command/commands.c index e92bbe1d..8d5893c7 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -946,6 +946,10 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg != NULL) { #ifdef HAVE_LIBOTR + if ((strcmp(prefs_get_string(PREF_OTR_POLICY), "always") == 0) && !otr_is_secure(usr_jid)) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } if (otr_is_secure(usr_jid)) { char *encrypted = otr_encrypt_message(usr_jid, msg); if (encrypted != NULL) { diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 6da2b367..4fc71f63 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -522,4 +522,3 @@ message_init_module(void) message_send_inactive = _message_send_inactive; message_send_gone = _message_send_gone; } - -- cgit 1.4.1-2-gfad0 From da89e241720a65ecbf4c8f667f8245ceeb4a7d48 Mon Sep 17 00:00:00 2001 From: lightb Date: Mon, 21 Apr 2014 18:03:07 -0400 Subject: Added opportunistic send functionality to cmd_msg If policy is set to 'opportunistic' then when the user executes cmd_msg it will append the otr whitespace tag to the message The other client should start AKE once it receives the message. TODO: Analyze incoming messages for whitespace tag --- src/command/commands.c | 23 +++++++++++++++++++---- src/otr/otr.h | 2 ++ src/otr/otrlibv4.c | 2 ++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 8d5893c7..54310c76 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "chat_session.h" #include "command/commands.h" @@ -946,10 +947,6 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg != NULL) { #ifdef HAVE_LIBOTR - if ((strcmp(prefs_get_string(PREF_OTR_POLICY), "always") == 0) && !otr_is_secure(usr_jid)) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } if (otr_is_secure(usr_jid)) { char *encrypted = otr_encrypt_message(usr_jid, msg); if (encrypted != NULL) { @@ -971,7 +968,25 @@ cmd_msg(gchar **args, struct cmd_help_t help) cons_show_error("Failed to encrypt and send message,"); } } else { + char *policy = prefs_get_string(PREF_OTR_POLICY); + + if (strcmp(policy, "always") == 0) + { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } else if (strcmp(policy, "opportunistic") == 0) { + char *otr_base_tag = OTRL_MESSAGE_TAG_BASE; + char *otr_v2_tag = OTRL_MESSAGE_TAG_V2; + int N = strlen(otr_base_tag) + strlen(otr_v2_tag) + strlen(msg) + 1; + char *temp = (char *) malloc( (unsigned) N*sizeof(char *) ); + strcpy( temp , msg ); + strcat( temp , otr_base_tag); + strcat( temp, otr_v2_tag); + message_send(temp, usr_jid); + free(temp); + } else { message_send(msg, usr_jid); + } ui_outgoing_msg("me", usr_jid, msg); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 5239c033..21a15e4b 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -23,6 +23,8 @@ #ifndef OTR_H #define OTR_H +#define OTRL_TAG " \t \t\t\t\t \t \t \t " + #include "config/accounts.h" void otr_init_module(void); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 01afa868..9187473a 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -108,6 +108,8 @@ otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j { gcry_error_t err; + ops.policy = OTRL_POLICY_SEND_WHITESPACE_TAG; + err = otrl_message_sending( user_state, ops, -- cgit 1.4.1-2-gfad0 From 36c6dbda86889e1854854cc00f4eb7820740e52b Mon Sep 17 00:00:00 2001 From: lightb Date: Mon, 21 Apr 2014 18:08:38 -0400 Subject: Compilation v4 fix --- src/otr/otr.h | 2 -- src/otr/otrlibv4.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/otr/otr.h b/src/otr/otr.h index 21a15e4b..5239c033 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -23,8 +23,6 @@ #ifndef OTR_H #define OTR_H -#define OTRL_TAG " \t \t\t\t\t \t \t \t " - #include "config/accounts.h" void otr_init_module(void); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 9187473a..01afa868 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -108,8 +108,6 @@ otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j { gcry_error_t err; - ops.policy = OTRL_POLICY_SEND_WHITESPACE_TAG; - err = otrl_message_sending( user_state, ops, -- cgit 1.4.1-2-gfad0 From f95ae8b0dd98a1ccfffb4fe7866eb3007e28f8f8 Mon Sep 17 00:00:00 2001 From: lightb Date: Tue, 22 Apr 2014 13:07:19 -0400 Subject: Modified otrlibv4 and otrlibv4 to add informative message when starting OTR conversation. --- src/otr/otrlibv3.c | 2 +- src/otr/otrlibv4.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 633d07b8..4605f614 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -34,7 +34,7 @@ otrlib_policy(void) char * otrlib_start_query(void) { - return "?OTR?v2?"; + return "?OTR?v2? This user has requested an Off-the-Record private conversation. However, you do not have a plugin to support that. See http://otr.cypherpunks.ca/ for more information."; } static int diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 01afa868..c55d2972 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -35,7 +35,7 @@ otrlib_policy(void) char * otrlib_start_query(void) { - return "?OTR?v2?"; + return "?OTR?v2? This user has requested an Off-the-Record private conversation. However, you do not have a plugin to support that. See http://otr.cypherpunks.ca/ for more information."; } static const char* -- cgit 1.4.1-2-gfad0 From 6450e2a704c6ed13ec8e5d26d7e5cf933ad00c61 Mon Sep 17 00:00:00 2001 From: lightb Date: Tue, 22 Apr 2014 16:01:57 -0400 Subject: Added OTR opportunistic pattern intercept. When a message is received, OTRL_MESSAGE_TAG_BASE + OTRL_MESSAGE_TAG_V1 or OTRL_MESSAGE_TAG_V2 is searched for, if it is, the client attempts to start an OTR session. Tested between profanity clients: WORKED Tested between profanity and pidgin: NOT WORKING (not sure if pidgin checks for the whitespace) --- src/server_events.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/server_events.c b/src/server_events.c index afb29bcd..0d0ba9c6 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -32,6 +32,7 @@ #ifdef HAVE_LIBOTR #include "otr/otr.h" +#include #endif #include "ui/ui.h" @@ -205,6 +206,17 @@ void handle_incoming_message(char *from, char *message, gboolean priv) { #ifdef HAVE_LIBOTR +//check for OTR whitespace (opportunistic) + char *policy = prefs_get_string(PREF_OTR_POLICY); + if (strcmp(policy, "opportunistic") == 0) { + if (strstr(message,OTRL_MESSAGE_TAG_BASE)) { + if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { + char *otr_query_message = otr_start_query(); + cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...", message); + message_send(otr_query_message, from); + } + } + } gboolean was_decrypted = FALSE; char *newmessage; if (!priv) { -- cgit 1.4.1-2-gfad0 From 1bd617d38936dae2f36e51ad0f28c325f57868f6 Mon Sep 17 00:00:00 2001 From: lightb Date: Tue, 22 Apr 2014 16:26:45 -0400 Subject: Small modification, should check for whitespace pattern even if policy is always. --- src/server_events.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/server_events.c b/src/server_events.c index 0d0ba9c6..29cdfbc5 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -206,20 +206,21 @@ void handle_incoming_message(char *from, char *message, gboolean priv) { #ifdef HAVE_LIBOTR -//check for OTR whitespace (opportunistic) + gboolean was_decrypted = FALSE; + char *newmessage; + + if (!priv) { +//check for OTR whitespace (opportunistic or always) char *policy = prefs_get_string(PREF_OTR_POLICY); - if (strcmp(policy, "opportunistic") == 0) { + if (strcmp(policy, "opportunistic") == 0 || strcmp(policy, "always") == 0) { if (strstr(message,OTRL_MESSAGE_TAG_BASE)) { if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { char *otr_query_message = otr_start_query(); - cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...", message); + cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); message_send(otr_query_message, from); } } } - gboolean was_decrypted = FALSE; - char *newmessage; - if (!priv) { newmessage = otr_decrypt_message(from, message, &was_decrypted); // internal OTR message -- cgit 1.4.1-2-gfad0 From 1192e67cf76ba953031f420e5ac790989a81530c Mon Sep 17 00:00:00 2001 From: lightb Date: Tue, 22 Apr 2014 16:55:28 -0400 Subject: Strip whitespace from otr tagged message for proper display. Will handle BASE + OTRV1TAG/OTRV2TAG or BASE + OTRV1TAG + OTRV2TAG or BASE + OTRV2TAG + OTRV1TAG --- src/server_events.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server_events.c b/src/server_events.c index 29cdfbc5..3935bfbc 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -213,8 +213,15 @@ handle_incoming_message(char *from, char *message, gboolean priv) //check for OTR whitespace (opportunistic or always) char *policy = prefs_get_string(PREF_OTR_POLICY); if (strcmp(policy, "opportunistic") == 0 || strcmp(policy, "always") == 0) { - if (strstr(message,OTRL_MESSAGE_TAG_BASE)) { + char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE); + if (whitespace_base) { if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { + // Remove whitespace pattern for proper display in UI + // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8) + int tag_length = 24; + if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) tag_length = 32; + memmove(whitespace_base, whitespace_base+tag_length, tag_length); + log_debug("<%s>", message); char *otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); message_send(otr_query_message, from); -- cgit 1.4.1-2-gfad0