From 9477752b43d6db7cec26f327faf4062da51527cb Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber 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 @@ -139,6 +139,7 @@ resource->show= XMPP_PRESENCE_UNAVAILABLE; resource->status = NULL; resource->composing_id = NULL; + resource->pgp_keyid = NULL; return resource; } @@ -153,6 +154,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 {