diff options
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/message.c | 48 | ||||
-rw-r--r-- | src/xmpp/presence.c | 37 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 2 |
3 files changed, 86 insertions, 1 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 8ff4e85f..3191cd80 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -50,6 +50,7 @@ #include "roster_list.h" #include "xmpp/stanza.h" #include "xmpp/xmpp.h" +#include "pgp/gpg.h" #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx) @@ -103,7 +104,36 @@ message_send_chat(const char * const barejid, const char * const msg) } char *id = create_unique_id("msg"); - xmpp_stanza_t *message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); + xmpp_stanza_t *message = NULL; + +#ifdef HAVE_LIBGPGME + char *account_name = jabber_get_account_name(); + ProfAccount *account = accounts_get_account(account_name); + if (account->pgp_keyid) { + Jid *jidp = jid_create(jid); + char *encrypted = p_gpg_encrypt(jidp->barejid, msg); + if (encrypted) { + message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, "This message is encrypted."); + xmpp_stanza_t *x = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(x, STANZA_NAME_X); + xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED); + xmpp_stanza_t *enc_st = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(enc_st, encrypted); + xmpp_stanza_add_child(x, enc_st); + xmpp_stanza_release(enc_st); + xmpp_stanza_add_child(message, x); + xmpp_stanza_release(x); + free(encrypted); + } else { + message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); + } + } else { + message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); + } +#else + message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); +#endif + free(jid); if (state) { @@ -689,7 +719,23 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con if (delayed) { sv_ev_delayed_message(jid->barejid, message, tv_stamp); } else { +#ifdef HAVE_LIBGPGME + gboolean handled = FALSE; + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED); + if (x) { + char *enc_message = xmpp_stanza_get_text(x); + char *decrypted = p_gpg_decrypt(jid->barejid, enc_message); + if (decrypted) { + sv_ev_incoming_message(jid->barejid, jid->resourcepart, decrypted); + handled = TRUE; + } + } + if (!handled) { + sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); + } +#else sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); +#endif } _receipt_request_handler(stanza); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 0c6702b3..6d9ba14e 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -50,6 +50,9 @@ #include "xmpp/connection.h" #include "xmpp/stanza.h" #include "xmpp/xmpp.h" +#ifdef HAVE_LIBGPGME +#include "pgp/gpg.h" +#endif static Autocomplete sub_requests_ac; @@ -223,7 +226,31 @@ presence_update(const resource_presence_t presence_type, const char * const msg, char *id = create_unique_id("presence"); xmpp_stanza_set_id(presence, id); stanza_attach_show(ctx, presence, show); + stanza_attach_status(ctx, presence, msg); + +#ifdef HAVE_LIBGPGME + char *account_name = jabber_get_account_name(); + ProfAccount *account = accounts_get_account(account_name); + if (account->pgp_keyid) { + char *signed_status = p_gpg_sign(msg, account->pgp_keyid); + + if (signed_status) { + xmpp_stanza_t *x = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(x, STANZA_NAME_X); + xmpp_stanza_set_ns(x, STANZA_NS_SIGNED); + xmpp_stanza_t *signed_text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(signed_text, signed_status); + xmpp_stanza_add_child(x, signed_text); + xmpp_stanza_release(signed_text); + xmpp_stanza_add_child(presence, x); + xmpp_stanza_release(x); + + free(signed_status); + } + } +#endif + stanza_attach_priority(ctx, presence, pri); stanza_attach_last_activity(ctx, presence, idle); stanza_attach_caps(ctx, presence); @@ -588,6 +615,16 @@ _available_handler(xmpp_conn_t * const conn, log_debug("Presence available handler fired for: %s", jid); } +#ifdef HAVE_LIBGPGME + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED); + if (x) { + char *sign = xmpp_stanza_get_text(x); + if (sign) { + p_gpg_verify(xmpp_presence->jid->barejid, sign); + } + } +#endif + const char *my_jid_str = xmpp_conn_get_jid(conn); Jid *my_jid = jid_create(my_jid_str); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 89dbda57..042b6aea 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -160,6 +160,8 @@ #define STANZA_NS_CARBONS "urn:xmpp:carbons:2" #define STANZA_NS_FORWARD "urn:xmpp:forward:0" #define STANZA_NS_RECEIPTS "urn:xmpp:receipts" +#define STANZA_NS_SIGNED "jabber:x:signed" +#define STANZA_NS_ENCRYPTED "jabber:x:encrypted" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" |