1
From 86e642797d08ccd0bcf3ca2bc9eda5c0ed407ed6 Mon Sep 17 00:00:00 2001
2
From: Stephen Paul Weber <singpolyma@singpolyma.net>
3
Date: Thu, 21 Apr 2011 00:11:19 -0500
4
Subject: [PATCH 03/18] If an OpenPGP KeyID is set, sign presence
7
src/core/protocol.c | 98 +++++++++++++++++++++++++++++++++++++++++++++----
8
src/core/xmpp-servers.c | 1 +
10
3 files changed, 94 insertions(+), 7 deletions(-)
12
--- a/src/core/protocol.c
13
+++ b/src/core/protocol.c
15
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+#define _POSIX_SOURCE 1
19
+#define _BSD_SOURCE 1
20
+#define _SVID_SOURCE 1
25
+#include "settings.h"
27
#include "xmpp-servers.h"
28
#include "rosters-tools.h"
31
+char *pgp_passwd = NULL;
33
+char *call_gpg(char *keyid, char *switches, char *input) {
34
+ int pipefd[2], tmp_fd, in_data = 0;
36
+ char *cmd, *tmp_path, *output = NULL;
37
+ size_t output_size = 0;
38
+ char buf[100], buf2[100] = "";
40
+ if(pipe(pipefd)) goto pgp_error;
41
+ if(!pgp_passwd) pgp_passwd = get_password("OpenPGP Password:");
43
+ if(write(pipefd[1], pgp_passwd, strlen(pgp_passwd)) < 1) goto pgp_error;
44
+ if(close(pipefd[1])) goto pgp_error;
46
+ if(!(tmp_path = tempnam(NULL, "irssi-xmpp-gpg"))) goto pgp_error;
47
+ if((tmp_fd = open(tmp_path, O_WRONLY|O_CREAT|O_EXCL, \
48
+ S_IRUSR|S_IWUSR)) < 0)
51
+ if(write(tmp_fd, input, strlen(input)) < 0) goto pgp_error;
53
+ cmd = malloc(sizeof("gpg -u '' -qo - --no-tty --passphrase-fd '' ''") \
54
+ +strlen(switches)+6+strlen(tmp_path));
55
+ sprintf(cmd, "gpg -u '%s' %s -qo - --no-tty --passphrase-fd '%d' '%s'", \
56
+ keyid, switches, pipefd[0], tmp_path);
58
+ cstream = popen(cmd, "r");
60
+ while(fgets(buf, sizeof(buf)-1, cstream)) {
61
+ if(strlen(buf2) > 0) {
62
+ output = realloc(output, output_size+strlen(buf2)+1);
63
+ if(!output) goto pgp_error;
64
+ if(output_size < 1) output[0] = '\0';
65
+ output_size += strlen(buf2);
66
+ strcat(output, buf2);
69
+ if(!in_data && buf[0] == '\n') {
72
+ } else if(in_data) {
77
+ pclose(cstream); /* TODO: check exit code */
90
sig_set_presence(XMPP_SERVER_REC *server, const int show, const char *status,
95
+ const char *pgp_keyid;
97
g_return_if_fail(IS_XMPP_SERVER(server));
98
if (!xmpp_presence_changed(show, server->show, status,
104
+ lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE);
106
- g_free(server->away_reason);
107
- server->away_reason = g_strdup(status);
109
if (!xmpp_priority_out_of_bound(priority))
110
server->priority = priority;
111
- lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE);
113
if (show != XMPP_PRESENCE_AVAILABLE)
114
lm_message_node_add_child(lmsg->node, "show",
115
xmpp_presence_show[server->show]);
116
- if (status != NULL) {
117
- str = xmpp_recode_out(server->away_reason);
118
- lm_message_node_add_child(lmsg->node, "status", str);
121
+ if(server->away_reason) g_free(server->away_reason);
122
+ server->away_reason = NULL;
124
+ if(!status) status = "";
125
+ server->away_reason = g_strdup(status);
126
+ str = xmpp_recode_out(server->away_reason);
127
+ lm_message_node_add_child(lmsg->node, "status", str);
128
+ if(!str) str = g_strdup("");
130
+ if((pgp_keyid = settings_get_str("xmpp_pgp"))) {
132
+ char *signature = call_gpg(pgp_keyid, "-ab", str);
134
+ x = lm_message_node_add_child(lmsg->node, "x", signature);
135
+ lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
142
str = g_strdup_printf("%d", server->priority);
143
lm_message_node_add_child(lmsg->node, "priority", str);
146
signal_emit("xmpp send presence", 2, server, lmsg);
147
lm_message_unref(lmsg);
148
if (show != XMPP_PRESENCE_AVAILABLE) /* away */
149
--- a/src/core/xmpp-servers.c
150
+++ b/src/core/xmpp-servers.c
153
settings_add_int("xmpp", "xmpp_priority", 0);
154
settings_add_int("xmpp", "xmpp_priority_away", -1);
155
+ settings_add_str("xmpp", "xmpp_pgp", NULL);
156
settings_add_bool("xmpp_lookandfeel", "xmpp_set_nick_as_username",
158
settings_add_bool("xmpp_proxy", "xmpp_use_proxy", FALSE);
159
--- a/src/core/xmpp.h
160
+++ b/src/core/xmpp.h
162
#define IRSSI_XMPP_PACKAGE "irssi-xmpp"
163
#define IRSSI_XMPP_VERSION "0.52"
165
+extern char *pgp_passwd;