Package: irssi-plugin-xmpp / 0.53-1~bpo8+1

singpolyma-0009-Encrypt-outgoing-messages-when-told-to.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
63
64
65
66
67
68
69
70
71
From 0e29fbe582209e5470acbf8e423c3c50e33614ed Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Sat, 23 Apr 2011 14:03:18 -0500
Subject: [PATCH 09/18] Encrypt outgoing messages when told to

Also, sign messages when we have a keyid
---
 src/core/xmpp-servers.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

--- a/src/core/xmpp-servers.c
+++ b/src/core/xmpp-servers.c
@@ -61,6 +61,7 @@
 {
 	LmMessage *lmsg;
 	char *str, *recoded;
+	char *encrypt_to = NULL;
 
 	if (!IS_XMPP_SERVER(server))
 		return;
@@ -71,7 +72,18 @@
 		lmsg = lm_message_new_with_sub_type(recoded,
 		    LM_MESSAGE_TYPE_MESSAGE, LM_MESSAGE_SUB_TYPE_GROUPCHAT);
 	} else {
+		XMPP_ROSTER_USER_REC *user;
 		str = rosters_resolve_name(XMPP_SERVER(server), target);
+		user = rosters_find_user(((XMPP_SERVER_REC*)server)->roster, str, \
+			NULL, NULL);
+		if(user) {
+			XMPP_ROSTER_RESOURCE_REC *res;
+			res = rosters_find_resource(user->resources, \
+				xmpp_extract_resource(str));
+			if(res && res->pgp_encrypt) {
+				encrypt_to = res->pgp_keyid;
+			}
+		}
 		recoded = xmpp_recode_out(str != NULL ? str : target);
 		g_free(str);
 		lmsg = lm_message_new_with_sub_type(recoded,
@@ -82,6 +94,31 @@
 	str = recode_in(server, msg, target);
 	recoded = xmpp_recode_out(str);
 	g_free(str);
+
+	if(encrypt_to) {
+		LmMessageNode *x;
+		char *encrypted;
+		char switches[sizeof("-aesR 00000000")] = "-ae";
+		if(settings_get_str("xmpp_pgp")) strcat(switches, "s");
+		strcat(switches, "R ");
+		strcat(switches, encrypt_to);
+		encrypted = call_gpg(switches, recoded, NULL, 0);
+
+		x = lm_message_node_add_child(lmsg->node, "x", encrypted);
+		lm_message_node_set_attribute(x, "xmlns", "jabber:x:encrypted");
+
+		free(encrypted);
+
+		g_free(recoded);
+		recoded = g_strdup("[This message is encrypted.]");
+	} else if(settings_get_str("xmpp_pgp")) {
+		LmMessageNode *x;
+		char *msigned = call_gpg("-ab", recoded, NULL, 0);
+		x = lm_message_node_add_child(lmsg->node, "x", msigned);
+		lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
+		free(msigned);
+	}
+
 	lm_message_node_add_child(lmsg->node, "body", recoded);
 	g_free(recoded);
 	signal_emit("xmpp send message", 2, server, lmsg);