[Pkg-privacy-commits] [irssi-plugin-otr] 117/267: Fix: Unencrypted private message to new window

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 456ffa86caf7909a226b448ed19ba028f38f6851
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Wed Nov 7 23:14:18 2012 -0500

    Fix: Unencrypted private message to new window
    
    Also fix the msg state check for authentication that was mix up.
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/module.c            |  2 +-
 src/{key.h => module.h} | 16 +++++-----------
 src/otr-ops.c           | 35 ++++++++++++++++++++++-------------
 src/otr.c               | 13 ++++++++++---
 src/otr.h               |  1 +
 5 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/src/module.c b/src/module.c
index 886fa1f..fc78757 100644
--- a/src/module.c
+++ b/src/module.c
@@ -87,7 +87,7 @@ end:
 /*
  * Pipes all incoming private messages through OTR
  */
-static void sig_message_private(SERVER_REC *server, const char *msg,
+void sig_message_private(SERVER_REC *server, const char *msg,
 		const char *nick, const char *address)
 {
 	int ret;
diff --git a/src/key.h b/src/module.h
similarity index 61%
copy from src/key.h
copy to src/module.h
index 70d3d42..4110610 100644
--- a/src/key.h
+++ b/src/module.h
@@ -16,18 +16,12 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
-#ifndef IRSSI_OTR_KEY_H
-#define IRSSI_OTR_KEY_H
+#ifndef IRSSI_OTR_MODULE
+#define IRSSI_OTR_MODULE
 
 #include "otr.h"
 
-typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t;
+void sig_message_private(SERVER_REC *server, const char *msg,
+		const char *nick, const char *address);
 
-void key_generation_abort(struct otr_user_state *ustate, int ignoreidle);
-void key_generation_run(struct otr_user_state *ustate, const char *accname);
-void key_load(struct otr_user_state *ustate);
-void key_load_fingerprints(struct otr_user_state *ustate);
-void key_write_fingerprints(struct otr_user_state *ustate);
-void otr_writeinstags(struct otr_user_state *ustate);
-
-#endif /* IRSSI_OTR_KEY_H */
+#endif /* IRSSI_OTR_MODULE */
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 99bcd17..5b4ba29 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -20,6 +20,7 @@
 #include <assert.h>
 
 #include "key.h"
+#include "module.h"
 
 OtrlPolicy IO_DEFAULT_OTR_POLICY =
 	OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
@@ -91,9 +92,6 @@ static void ops_create_privkey(void *opdata, const char *accountname,
 
 /*
  * Inject OTR message.
- *
- * Deriving the server is currently a hack, need to derive the server from
- * accountname.
  */
 static void ops_inject_msg(void *opdata, const char *accountname,
 		const char *protocol, const char *recipient, const char *message)
@@ -221,8 +219,8 @@ static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
 				"reflecting your messages back at you.");
 		break;
 	case OTRL_MSGEVENT_MSG_RESENT:
-		IRSSI_NOTICE(server, username, "%9OTR:%9 The last message to %s was "
-				"resent.", username);
+		IRSSI_NOTICE(server, username, "%9OTR:%9 The last message to %9%s%9 "
+				"was resent: %s", username, message);
 		break;
 	case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE:
 		IRSSI_WARN(server, username, "%9OTR:%9 The encrypted message received "
@@ -247,13 +245,20 @@ static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
 		IRSSI_WARN(server, username, "%9OTR:%9 OTR Error: %s.", message);
 		break;
 	case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
-		if (context->msgstate == OTRL_MSGSTATE_PLAINTEXT) {
-			/* Relay message if in a plaintext state */
-			irssi_send_message(server, username, message);
-		} else {
-			IRSSI_WARN(server, username, "%9OTR:%9 The following message from "
-					"%9%s%9 was NOT encrypted: [%s]", username, message);
-		}
+		IRSSI_NOTICE(server, username,
+				"%9OTR:%9 The following message from %9%s%9 was NOT "
+				"encrypted: [%s]", username, message);
+		/*
+		 * This is a hack I found to send the message in a private window of
+		 * the username without creating an infinite loop since the 'message
+		 * private' signal is hijacked in this module. If someone is able to
+		 * clean this up with a more elegant solution, by all means PLEASE
+		 * submit a patch or email me a better way.
+		 */
+		signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
+		signal_emit("message private", 4, server, message, username,
+				IRSSI_CONN_ADDR(server));
+		signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
 		break;
 	case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
 		IRSSI_WARN(server, username, "%9OTR:%9 Unrecognized OTR message "
@@ -308,7 +313,11 @@ static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
 
 	if (!opc) {
 		IRSSI_DEBUG("%9OTR%9: SMP event cb. Unable to find peer context");
-		goto end;
+		opc = otr_create_peer_context();
+		if (!opc) {
+			goto end;
+		}
+		context->app_data = opc;
 	}
 
 	opc->smp_event = smp_event;
diff --git a/src/otr.c b/src/otr.c
index 89ebb1c..0fa84f4 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -112,7 +112,7 @@ static void add_peer_context_cb(void *data, ConnContext *context)
 {
 	struct otr_peer_context *opc;
 
-	opc = zmalloc(sizeof(*opc));
+	opc = otr_create_peer_context();
 	if (!opc) {
 		return;
 	}
@@ -134,6 +134,13 @@ static ConnContext *get_otrl_context(const char *accname, const char *nick,
 	return ctx;
 }
 
+struct otr_peer_context *otr_create_peer_context(void)
+{
+	struct otr_peer_context *opc;
+
+	return zmalloc(sizeof(*opc));
+}
+
 /*
  * Return a newly allocated OTR user state for the given username.
  */
@@ -165,7 +172,6 @@ void otr_free_user(struct otr_user_state *ustate)
 	key_generation_abort(ustate, TRUE);
 
 	if (ustate->otr_state) {
-		key_write_fingerprints(ustate);
 		otrl_userstate_free(ustate->otr_state);
 		ustate->otr_state = NULL;
 	}
@@ -523,7 +529,7 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
 		}
 	}
 
-	if (opc->smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER) {
+	if (opc->smp_event == OTRL_SMPEVENT_ASK_FOR_SECRET) {
 		otrl_message_respond_smp(user_state_global->otr_state, &otr_ops,
 				irssi, ctx, (unsigned char *) secret, strlen(secret));
 		otr_status_change(irssi, nick, OTR_STATUS_SMP_RESPONDED);
@@ -543,6 +549,7 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
 	}
 
 end:
+	free(accname);
 	return;
 }
 
diff --git a/src/otr.h b/src/otr.h
index 2199018..7586ed9 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -189,5 +189,6 @@ struct ctxlist_ *otr_contexts(struct otr_user_state *ustate);
 void otr_finishall(struct otr_user_state *ustate);
 
 int otr_getstatus_format(SERVER_REC *irssi, const char *nick);
+struct otr_peer_context *otr_create_peer_context(void);
 
 #endif /* IRSSI_OTR_OTR_H */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list