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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
From 9477752b43d6db7cec26f327faf4062da51527cb Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Thu, 21 Apr 2011 22:09:52 -0500
Subject: [PATCH 05/18] Verify signed presences
And store the keyID in the resource structure
---
src/core/rosters.c | 42 ++++++++++++++++++++++++++++++++++++++----
src/core/rosters.h | 1 +
2 files changed, 39 insertions(+), 4 deletions(-)
--- a/src/core/rosters.c
+++ b/src/core/rosters.c
@@ -138,6 +138,7 @@
resource->show= XMPP_PRESENCE_UNAVAILABLE;
resource->status = NULL;
resource->composing_id = NULL;
+ resource->pgp_keyid = NULL;
return resource;
}
@@ -152,6 +153,7 @@
g_free(resource->name);
g_free(resource->status);
g_free(resource->composing_id);
+ if(resource->pgp_keyid) free(resource->pgp_keyid);
g_free(resource);
}
@@ -342,7 +344,8 @@
static void
update_user_presence(XMPP_SERVER_REC *server, const char *full_jid,
- const char *show_str, const char *status, const char *priority_str)
+ const char *show_str, const char *status, const char *priority_str,
+ char *pgp_keyid)
{
XMPP_ROSTER_GROUP_REC *group;
XMPP_ROSTER_USER_REC *user;
@@ -386,6 +389,7 @@
resource->show = show;
resource->status = g_strdup(status);
resource->priority = priority;
+ resource->pgp_keyid = pgp_keyid;
if (!own) {
user->resources = g_slist_sort(
user->resources, func_sort_resource);
@@ -484,8 +488,8 @@
sig_recv_presence(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
const char *id, const char *from, const char *to)
{
- LmMessageNode *node, *node_show, *node_priority;
- char *status;
+ LmMessageNode *node, *node_show, *node_priority, *signature;
+ char *status, *pgp_keyid = NULL;
if (server->ischannel(SERVER(server), from))
return;
@@ -495,9 +499,39 @@
node = lm_message_node_get_child(lmsg->node, "status");
status = node != NULL ? xmpp_recode_in(node->value) : NULL;
node_priority = lm_message_node_get_child(lmsg->node, "priority");
+ signature = lm_find_node(lmsg->node, "x", "xmlns", "jabber:x:signed");
+ if(signature) {
+ char *send_to_gpg = malloc(sizeof( \
+ "-----BEGIN PGP SIGNATURE-----\n\n" \
+ "-----END PGP SIGNATURE-----\n")+ \
+ strlen(signature->value)+1 \
+ );
+ char *send_status = status ? status : "";
+ char *from_gpg;
+
+ send_to_gpg[0] = '\0';
+ strcat(send_to_gpg, "-----BEGIN PGP SIGNATURE-----\n\n");
+ strcat(send_to_gpg, signature->value);
+ strcat(send_to_gpg, "----- END PGP SIGNATURE-----\n");
+
+ from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1);
+ free(send_to_gpg);
+
+ /* If there is a good signature, grab the key ID */
+ if(strstr(from_gpg, "Good signature from")) {
+ char *s = strstr(from_gpg, "key ID ");
+ if(s) {
+ pgp_keyid = malloc(sizeof(*pgp_keyid)*9);
+ strncpy(pgp_keyid, s+7, 8);
+ pgp_keyid[8] = '\0';
+ }
+ }
+ free(from_gpg);
+ }
update_user_presence(server, from,
node_show != NULL ? node_show->value : NULL, status,
- node_priority != NULL ? node_priority->value : NULL);
+ node_priority != NULL ? node_priority->value : NULL,
+ pgp_keyid);
g_free(status);
break;
case LM_MESSAGE_SUB_TYPE_UNAVAILABLE:
--- a/src/core/rosters.h
+++ b/src/core/rosters.h
@@ -30,6 +30,7 @@
int show;
char *status;
char *composing_id;
+ char *pgp_keyid;
} XMPP_ROSTER_RESOURCE_REC;
typedef struct _XMPP_ROSTER_USER_REC {
|