about summary refs log tree commit diff stats
path: root/src/xmpp/message.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp/message.c')
-rw-r--r--src/xmpp/message.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 8febbe11..aa5e55d9 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -49,6 +49,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)
 
@@ -104,7 +105,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) {
@@ -641,7 +671,23 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
                 if (delayed) {
                     srv_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) {
+                            srv_incoming_message(jid->barejid, jid->resourcepart, decrypted);
+                            handled = TRUE;
+                        }
+                    }
+                    if (!handled) {
+                        srv_incoming_message(jid->barejid, jid->resourcepart, message);
+                    }
+#else
                     srv_incoming_message(jid->barejid, jid->resourcepart, message);
+#endif
                 }
                 if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) {
                     xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);