Package: irssi-plugin-xmpp / 0.54-3

singpolyma-0013-Decrypt-incoming-messages.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From cec9e13dd16554b743ebff4b303cc10c4ca6205d Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Sat, 23 Apr 2011 15:04:55 -0500
Subject: [PATCH 13/18] Decrypt incoming messages

---
 src/core/protocol.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

--- a/src/core/protocol.c
+++ b/src/core/protocol.c
@@ -89,7 +89,7 @@
 sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
     const char *id, const char *from, const char *to)
 {
-	LmMessageNode *node;
+	LmMessageNode *node, *encrypted;
 	char *str, *subject;
 	
 	if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
@@ -106,9 +106,38 @@
 		signal_emit("message private", 4, server, subject, from, from);
 		g_free(subject);
 	}
-	node = lm_message_node_get_child(lmsg->node, "body");
-	if (node != NULL && node->value != NULL && *node->value != '\0') {
-		str = xmpp_recode_in(node->value);
+
+	str = NULL;
+	encrypted = lm_find_node(lmsg->node, "x", "xmlns", "jabber:x:encrypted");
+	if(encrypted && encrypted->value) {
+		/* TODO: indicate the message was encrypted */
+		/* TODO: verify signatures */
+		char *send_to_gpg = malloc(sizeof( \
+			"-----BEGIN PGP MESSAGE-----\n\n" \
+			"-----END PGP MESSAGE-----\n")+ \
+			strlen(encrypted->value)+1 \
+		);
+		char *from_gpg;
+
+		send_to_gpg[0] = '\0';
+		strcat(send_to_gpg, "-----BEGIN PGP MESSAGE-----\n\n");
+		strcat(send_to_gpg, encrypted->value);
+		strcat(send_to_gpg, "-----END PGP MESSAGE-----\n");
+
+		from_gpg = call_gpg("-d", send_to_gpg, NULL, 0, 0);
+		if(from_gpg) {
+			str = xmpp_recode_in(from_gpg);
+			free(from_gpg);
+		}
+
+		free(send_to_gpg);
+	} else {
+		node = lm_message_node_get_child(lmsg->node, "body");
+		if (node != NULL && node->value != NULL && *node->value != '\0') {
+			str = xmpp_recode_in(node->value);
+		}
+	}
+	if(str) {
 		if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
 			signal_emit("message xmpp action", 5,
 			    server, str+4, from, from,