Debian Codegraph @

debian/patches/singpolyma-0005-Verify-signed-presences.patch

raw
1 From 9477752b43d6db7cec26f327faf4062da51527cb Mon Sep 17 00:00:00 2001
2 From: Stephen Paul Weber <[email protected]>
3 Date: Thu, 21 Apr 2011 22:09:52 -0500
4 Subject: [PATCH 05/18] Verify signed presences
5
6 And store the keyID in the resource structure
7 ---
8 src/core/rosters.c | 42 ++++++++++++++++++++++++++++++++++++++----
9 src/core/rosters.h | 1 +
10 2 files changed, 39 insertions(+), 4 deletions(-)
11
12 --- a/src/core/rosters.c
13 +++ b/src/core/rosters.c
14 @@ -139,6 +139,7 @@
15 resource->show= XMPP_PRESENCE_UNAVAILABLE;
16 resource->status = NULL;
17 resource->composing_id = NULL;
18 + resource->pgp_keyid = NULL;
19 return resource;
20 }
21
22 @@ -153,6 +154,7 @@
23 g_free(resource->name);
24 g_free(resource->status);
25 g_free(resource->composing_id);
26 + if(resource->pgp_keyid) free(resource->pgp_keyid);
27 g_free(resource);
28 }
29
30 @@ -342,7 +344,8 @@
31
32 static void
33 update_user_presence(XMPP_SERVER_REC *server, const char *full_jid,
34 - const char *show_str, const char *status, const char *priority_str)
35 + const char *show_str, const char *status, const char *priority_str,
36 + char *pgp_keyid)
37 {
38 XMPP_ROSTER_GROUP_REC *group;
39 XMPP_ROSTER_USER_REC *user;
40 @@ -386,6 +389,7 @@
41 resource->show = show;
42 resource->status = g_strdup(status);
43 resource->priority = priority;
44 + resource->pgp_keyid = pgp_keyid;
45 if (!own) {
46 user->resources = g_slist_sort(
47 user->resources, func_sort_resource);
48 @@ -484,8 +488,8 @@
49 sig_recv_presence(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
50 const char *id, const char *from, const char *to)
51 {
52 - LmMessageNode *node, *node_show, *node_priority;
53 - char *status;
54 + LmMessageNode *node, *node_show, *node_priority, *signature;
55 + char *status, *pgp_keyid = NULL;
56
57 if (server->ischannel(SERVER(server), from))
58 return;
59 @@ -495,9 +499,39 @@
60 node = lm_message_node_get_child(lmsg->node, "status");
61 status = node != NULL ? xmpp_recode_in(node->value) : NULL;
62 node_priority = lm_message_node_get_child(lmsg->node, "priority");
63 + signature = lm_find_node(lmsg->node, "x", "xmlns", "jabber:x:signed");
64 + if(signature) {
65 + char *send_to_gpg = malloc(sizeof( \
66 + "-----BEGIN PGP SIGNATURE-----\n\n" \
67 + "-----END PGP SIGNATURE-----\n")+ \
68 + strlen(signature->value)+1 \
69 + );
70 + char *send_status = status ? status : "";
71 + char *from_gpg;
72 +
73 + send_to_gpg[0] = '\0';
74 + strcat(send_to_gpg, "-----BEGIN PGP SIGNATURE-----\n\n");
75 + strcat(send_to_gpg, signature->value);
76 + strcat(send_to_gpg, "----- END PGP SIGNATURE-----\n");
77 +
78 + from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1);
79 + free(send_to_gpg);
80 +
81 + /* If there is a good signature, grab the key ID */
82 + if(strstr(from_gpg, "Good signature from")) {
83 + char *s = strstr(from_gpg, "key ID ");
84 + if(s) {
85 + pgp_keyid = malloc(sizeof(*pgp_keyid)*9);
86 + strncpy(pgp_keyid, s+7, 8);
87 + pgp_keyid[8] = '\0';
88 + }
89 + }
90 + free(from_gpg);
91 + }
92 update_user_presence(server, from,
93 node_show != NULL ? node_show->value : NULL, status,
94 - node_priority != NULL ? node_priority->value : NULL);
95 + node_priority != NULL ? node_priority->value : NULL,
96 + pgp_keyid);
97 g_free(status);
98 break;
99 case LM_MESSAGE_SUB_TYPE_UNAVAILABLE:
100 --- a/src/core/rosters.h
101 +++ b/src/core/rosters.h
102 @@ -30,6 +30,7 @@
103 int show;
104 char *status;
105 char *composing_id;
106 + char *pgp_keyid;
107 } XMPP_ROSTER_RESOURCE_REC;
108
109 typedef struct _XMPP_ROSTER_USER_REC {