annotate mcabber/src/otr.c @ 1320:cb400799db8f

Configurable OTR directory
author franky@veqlargh.fs
date Wed, 03 Oct 2007 21:27:46 +0200
parents b17754d9221b
children ab1b7f7a682e
rev   line source
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1 /*
1303
b6fdbfa6b219 Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents: 1301
diff changeset
2 * otr.c -- Off-The-Record Messaging for mcabber
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
3 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
4 * Copyright (C) 2007 Frank Zschockelt <mcabber_otr@freakysoft.de>
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
5 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
9 * your option) any later version.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
10 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
14 * General Public License for more details.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
15 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
19 * USA
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
20 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
21
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
22 #include <config.h>
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
23
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
24 #ifdef HAVE_LIBOTR
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
25
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
26 #include "otr.h"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
27 #include "logprint.h"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
28 #include "hbuf.h"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
29 #include "jab_priv.h"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
30 #include "roster.h"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
31 #include "utils.h"
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
32 #include "screen.h"
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
33 #include "settings.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
34
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
35
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
36 static OtrlUserState userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
37 static char * account = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
38 static char * keyfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
39 static char * fprfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
40
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
41
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
42 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
43 static void cb_create_privkey (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
44 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
45 const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
46 static int cb_is_logged_in (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
47 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
48 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
49 const char *recipient);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
50 static void cb_inject_message (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
51 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
52 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
53 const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
54 const char *message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
55 static void cb_notify (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
56 OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
57 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
58 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
59 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
60 const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
61 const char *primary,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
62 const char *secondary);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
63 static int cb_display_otr_message(void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
64 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
65 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
66 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
67 const char *msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
68 static void cb_update_context_list(void *opdata);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
69 static const char *cb_protocol_name (void *opdata, const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
70 static void cb_protocol_name_free (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
71 const char *protocol_name);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
72 static void cb_new_fingerprint (void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
73 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
74 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
75 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
76 unsigned char fingerprint[20]);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
77 static void cb_write_fingerprints (void *opdata);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
78 static void cb_gone_secure (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
79 static void cb_gone_insecure (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
80 static void cb_still_secure (void *opdata, ConnContext *context,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
81 int is_reply);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
82 static void cb_log_message (void *opdata, const char *message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
83 static int cb_max_message_size (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
84
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
85 static OtrlMessageAppOps ops =
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
86 {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
87 cb_policy,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
88 cb_create_privkey,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
89 cb_is_logged_in,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
90 cb_inject_message,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
91 cb_notify,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
92 cb_display_otr_message,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
93 cb_update_context_list,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
94 cb_protocol_name,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
95 cb_protocol_name_free,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
96 cb_new_fingerprint,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
97 cb_write_fingerprints,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
98 cb_gone_secure,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
99 cb_gone_insecure,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
100 cb_still_secure,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
101 cb_log_message,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
102 cb_max_message_size,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
103 NULL, /*account_name*/
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
104 NULL /*account_name_free*/
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
105 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
106
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
107 static void otr_message_disconnect(ConnContext *ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
108 static ConnContext * otr_get_context(const char *buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
109 static void otr_startstop(const char * buddy, int start);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
110 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
111
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
112 static char * otr_get_dir(void);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
113
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
114 void otr_init(const char *jid)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
115 {
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
116 char * root = otr_get_dir();
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
117 account = jidtodisp(jid);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
118 keyfile = g_strdup_printf("%s%s.key", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
119 fprfile = g_strdup_printf("%s%s.fpr", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
120 g_free(root);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
121
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
122 OTRL_INIT;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
123
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
124 userstate = otrl_userstate_create ();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
125 if (otrl_privkey_read(userstate, keyfile)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
126 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
127 cb_create_privkey(NULL, account, "jabber");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
128 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
129 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
130 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
131 fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
132 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
133 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
134
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
135 void otr_terminate(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
136 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
137 ConnContext * ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
138
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
139 for (ctx = userstate->context_root; ctx; ctx = ctx->next)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
140 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
141 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
142
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
143 g_free(account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
144 account = NULL;
1307
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
145
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
146 /* XXX This #ifdef is a quick workaround: when mcabber
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
147 * is linked to both gnutls and libotr, libgcrypt will
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
148 * segfault when we call otrl_userstate_free().
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
149 * This is reported to be a bug in libgcrypt :-/
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
150 * Mikael
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
151 */
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
152 #if defined(HAVE_GNUTLS) && !defined(HAVE_OPENSSL)
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
153 if (!settings_opt_get_int("ssl"))
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
154 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
155 otrl_userstate_free(userstate);
1307
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
156
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
157 userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
158 g_free(keyfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
159 keyfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
160 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
161
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
162 static char * otr_get_dir(void)
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
163 {
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
164 char * configured_dir = (char *)settings_opt_get("otr_dir");
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
165
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
166 if (configured_dir)
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
167 return expand_filename(configured_dir);
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
168 else
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
169 return expand_filename("~/.mcabber/otr/");
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
170 }
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
171
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
172 static ConnContext * otr_get_context(const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
173 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
174 int null = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
175 return otrl_context_find(userstate, buddy, account, "jabber", 1, &null,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
176 NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
177 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
178
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
179 static void otr_message_disconnect(ConnContext *ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
180 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
181 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
182 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
183 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
184 ctx->protocol, ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
185 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
186
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
187 static void otr_startstop(const char * buddy, int start)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
188 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
189 char * msg = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
190 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
191
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
192 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
193 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
194
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
195 if (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
196 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
197
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
198 if (start) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
199 OtrlPolicy policy = cb_policy(NULL, ctx);
1308
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
200 if (policy == plain) {
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
201 scr_LogPrint(LPRINT_LOGNORM, "The OTR policy for this user is set to"
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
202 " plain. You have to change it first.");
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
203 return;
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
204 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
205 msg = otrl_proto_default_query_msg(ctx->accountname, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
206 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
207 msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
208 free (msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
209 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
210 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
211 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
212 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
213
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
214 void otr_establish(const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
215 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
216 otr_startstop(buddy, 1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
217 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
218
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
219 void otr_disconnect(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
220 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
221 otr_startstop(buddy, 0);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
222 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
223
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
224 void otr_fingerprint(const char * buddy, const char * trust)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
225 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
226 char fpr[45], *tr;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
227 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
228 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
229 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
230
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
231 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
232 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
233 "No active fingerprint - start OTR for this buddy first.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
234 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
235 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
236
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
237 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
238 if (trust) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
239 if (strcmp(fpr, trust) == 0)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
240 otrl_context_set_trust(ctx->active_fingerprint, "trust");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
241 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
242 otrl_context_set_trust(ctx->active_fingerprint, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
243 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
244
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
245 tr = ctx->active_fingerprint->trust;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
246 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
247 tr && *tr ? "trusted" : "untrusted");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
248 cb_write_fingerprints(NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
249 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
250
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
251 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
252 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
253 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
254 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
255 NextExpectedSMP nextMsg = ctx->smstate->nextExpected;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
256
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
257 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
258 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
259 if (nextMsg != OTRL_SMP_EXPECT1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
260 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
261 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
262 sbuf = g_strdup_printf("OTR: Received SMP Initiation. "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
263 "Answer with /otr smpr %s $secret",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
264 ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
265 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
266 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
267 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
268 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
269 if (nextMsg != OTRL_SMP_EXPECT2)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
270 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
271 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
272 sbuf = g_strdup("OTR: Received SMP Response.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
273 /* If we received TLV2, we will send TLV3 and expect TLV4 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
274 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
275 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
276 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
277 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
278 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
279 if (nextMsg != OTRL_SMP_EXPECT3)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
280 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
281 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
282 /* If we received TLV3, we will send TLV4
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
283 * We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
284 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
285 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
286 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
287 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
288 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
289 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
290 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
291 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
292 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
293 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
294 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
295 if (nextMsg != OTRL_SMP_EXPECT4)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
296 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
297 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
298 /* We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
299 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
300 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
301 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
302 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
303 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
304 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
305 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
306 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
307 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
308 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
309 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
310 /* The message we are waiting for will not arrive, so reset
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
311 * and prepare for the next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
312 sbuf = g_strdup("OTR: SMP aborted by your buddy");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
313 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
314 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
315
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
316 if (sbuf) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
317 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
318 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
319 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
320 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
321
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
322 /*
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
323 * returns whether a otr_message was received
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
324 * sets *otr_data to NULL, when it was an internal otr message
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
325 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
326 int otr_receive(char **otr_data, const char * buddy, int * free_msg)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
327 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
328 int ignore_message;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
329 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
330 OtrlTLV *tlvs = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
331 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
332 ConnContext * ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
333
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
334 *free_msg = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
335 ignore_message = otrl_message_receiving(userstate, &ops, NULL, account,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
336 "jabber", buddy, *otr_data, &newmessage, &tlvs, NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
337
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
338 ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
339
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
340 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
341 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
342 /* Notify the user that the other side disconnected. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
343 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
344 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
345 otr_disconnect(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
346 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
347 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
348
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
349 otr_handle_smp_tlvs(tlvs, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
350
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
351 if (tlvs != NULL)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
352 otrl_tlv_free(tlvs);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
353
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
354 if (ignore_message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
355 *otr_data = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
356
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
357 if (!ignore_message && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
358 *free_msg = 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
359 *otr_data = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
360 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
361 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
362 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
363 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
364 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
365 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
366
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
367 int otr_send(char **msg, const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
368 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
369 gcry_error_t err;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
370 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
371 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
372
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
373 err = otrl_message_sending(userstate, &ops, NULL, account, "jabber", buddy,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
374 *msg, NULL, &newmessage, NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
375
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
376 if (err)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
377 *msg = NULL; /*something went wrong, don't send the plain-message! */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
378
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
379 if (!err && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
380 *msg = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
381 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
382 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION ||
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
383 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
384 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
385 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
386 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
387 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
388
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
389 /* Prints OTR connection state */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
390 void otr_print_info(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
391 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
392 const char *state, *auth, *policy;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
393 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
394 OtrlPolicy p = cb_policy (ctx->app_data, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
395
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
396 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
397 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
398
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
399 switch (ctx->msgstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
400 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
401 case OTRL_MSGSTATE_ENCRYPTED:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
402 switch (ctx->protocol_version) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
403 case 1: state = "encrypted V1"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
404 case 2: state = "encrypted V2"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
405 default:state = "encrypted";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
406 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
407 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
408 case OTRL_MSGSTATE_FINISHED: state = "finished"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
409 default: state = "unknown state";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
410 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
411 switch (ctx->auth.authstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
412 case OTRL_AUTHSTATE_NONE:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
413 switch (ctx->otr_offer) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
414 case OFFER_NOT: auth = "no offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
415 case OFFER_SENT: auth = "offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
416 case OFFER_ACCEPTED: auth = "offer accepted"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
417 case OFFER_REJECTED: auth = "offer rejected"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
418 default: auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
419 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
420 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
421 case OTRL_AUTHSTATE_AWAITING_DHKEY:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
422 auth = "awaiting D-H key"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
423 case OTRL_AUTHSTATE_AWAITING_REVEALSIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
424 auth = "awaiting reveal signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
425 case OTRL_AUTHSTATE_AWAITING_SIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
426 auth = "awaiting signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
427 case OTRL_AUTHSTATE_V1_SETUP:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
428 auth = "v1 setup"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
429 default:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
430 auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
431 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
432 if (p == OTRL_POLICY_NEVER)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
433 policy = "plain";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
434 else if (p == (OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
435 policy = "opportunistic";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
436 else if (p == (OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
437 policy = "manual";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
438 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
439 policy = "always";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
440 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
441 policy = "unknown";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
442
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
443 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
444 ctx->username, state, auth, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
445 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
446
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
447 static ConnContext * otr_context_encrypted(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
448 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
449 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
450
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
451 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
452 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
453 "You have to start an OTR channel with %s before you can "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
454 "use SMP.", buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
455 return NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
456 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
457
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
458 return ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
459 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
460
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
461 void otr_smp_query(const char * buddy, const char * secret)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
462 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
463 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
464
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
465 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
466 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
467 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
468 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
469 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
470
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
471 if (ctx) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
472 otrl_message_initiate_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
473 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
474 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
475 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
476 "OTR: Socialist Millionaires' Protocol "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
477 "initiated.", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
478 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
479 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
480
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
481 void otr_smp_respond(const char * buddy, const char * secret)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
482 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
483 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
484
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
485 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
486 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
487 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
488 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
489 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
490
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
491 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
492 if (!ctx->smstate->secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
493 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
494 "Don't call smpr before you haven't received an SMP "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
495 "Initiation!");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
496 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
497 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
498 otrl_message_respond_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
499 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
500 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
501 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
502 "OTR: Socialist Millionaires' Protocol: "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
503 "response sent", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
504 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
505 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
506
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
507 void otr_smp_abort(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
508 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
509 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
510
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
511 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
512 otrl_message_abort_smp(userstate, &ops, NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
513 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
514 "OTR: Socialist Millionaires' Protocol aborted.",
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
515 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
516 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
517 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
518
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
519 void otr_key(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
520 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
521 OtrlPrivKey * key;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
522 char readable[45] = "";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
523
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
524 if(!userstate)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
525 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
526 for (key = userstate->privkey_root; key; key = key->next) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
527 otrl_privkey_fingerprint(userstate, readable, key->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
528 key->protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
529 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
530 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
531 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
532
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
533 /* Return the OTR policy for the given context. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
534 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
535 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
536 enum otr_policy p = settings_otr_getpolicy(NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
537
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
538 if(ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
539 if(settings_otr_getpolicy(ctx->username))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
540 p = settings_otr_getpolicy(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
541
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
542 switch (p) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
543 case plain:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
544 return OTRL_POLICY_NEVER;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
545 case opportunistic:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
546 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
547 case manual:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
548 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
549 case always:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
550 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
551 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
552
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
553 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
554 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
555
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
556 /* Create a private key for the given accountname/protocol if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
557 * desired. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
558 static void cb_create_privkey(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
559 const char *protocol)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
560 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
561 gcry_error_t e;
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
562 char * root;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
563
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
564 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
565 "Generating new OTR key for %s. This may take a while...",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
566 accountname);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
567 scr_DoUpdate();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
568
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
569 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
570
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
571 if (e) {
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
572 root = otr_get_dir();
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
573 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed! Please mkdir "
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
574 "%s if you want to use otr encryption.", root);
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
575 g_free(root);
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
576 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
577 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
578 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
579 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
580
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
581 /* Report whether you think the given user is online. Return 1 if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
582 * you think he is, 0 if you think he isn't, -1 if you're not sure.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
583 * If you return 1, messages such as heartbeats or other
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
584 * notifications may be sent to the user, which could result in "not
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
585 * logged in" errors if you're wrong. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
586 static int cb_is_logged_in(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
587 const char *protocol, const char *recipient)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
588 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
589 int ret = (roster_getstatus((char *)recipient, NULL) != offline);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
590 return ret;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
591 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
592
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
593 /* Send the given IM to the given recipient from the given
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
594 * accountname/protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
595 static void cb_inject_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
596 const char *protocol, const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
597 const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
598 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
599 char * id = g_strdup("otrinject");
1306
a7d21918234c Fix jb_send_msg() call in OTR
Mikael Berthe <mikael@lilotux.net>
parents: 1303
diff changeset
600 jb_send_msg(recipient, message, ROSTER_TYPE_USER, "", id, NULL, NULL);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
601 g_free(id);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
602 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
603
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
604 /* Display a notification message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
605 * accountname / protocol / username conversation. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
606 static void cb_notify(void *opdata, OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
607 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
608 const char *username, const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
609 const char *primary, const char *secondary)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
610 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
611 char * type;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
612 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
613 switch (level) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
614 case OTRL_NOTIFY_ERROR: type = "error"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
615 case OTRL_NOTIFY_WARNING: type = "warning"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
616 case OTRL_NOTIFY_INFO: type = "info"; break;
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
617 default: type = "unknown";
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
618 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
619 sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary);
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
620 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
621 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
622 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
623
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
624 /* Display an OTR control message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
625 * accountname / protocol / username conversation. Return 0 if you are able
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
626 * to successfully display it. If you return non-0 (or if this
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
627 * function is NULL), the control message will be displayed inline,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
628 * as a received message, or else by using the above notify()
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
629 * callback. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
630 static int cb_display_otr_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
631 const char *protocol, const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
632 const char *msg)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
633 {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
634 scr_WriteIncomingMessage(username, msg, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
635 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
636 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
637
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
638 /* When the list of ConnContexts changes (including a change in
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
639 * state), this is called so the UI can be updated. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
640 static void cb_update_context_list(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
641 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
642 /*maybe introduce new status characters for mcabber,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
643 * then use this function (?!)*/
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
644 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
645
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
646 /* Return a newly allocated string containing a human-friendly name
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
647 * for the given protocol id */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
648 static const char *cb_protocol_name(void *opdata, const char *protocol)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
649 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
650 return protocol;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
651 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
652
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
653 /* Deallocate a string allocated by protocol_name */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
654 static void cb_protocol_name_free (void *opdata, const char *protocol_name)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
655 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
656 /* We didn't allocated memory, so we don't have to free anything :p */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
657 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
658
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
659 /* A new fingerprint for the given user has been received. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
660 static void cb_new_fingerprint(void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
661 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
662 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
663 unsigned char fingerprint[20])
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
664 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
665 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
666 char readable[45];
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
667
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
668 otrl_privkey_hash_to_human(readable, fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
669 sbuf = g_strdup_printf("OTR: new fingerprint: %s", readable);
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
670 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
671 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
672 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
673
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
674 /* The list of known fingerprints has changed. Write them to disk. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
675 static void cb_write_fingerprints(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
676 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
677 otrl_privkey_write_fingerprints(userstate, fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
678 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
679
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
680 /* A ConnContext has entered a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
681 static void cb_gone_secure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
682 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
683 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
684 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
685 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
686
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
687 /* A ConnContext has left a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
688 static void cb_gone_insecure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
689 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
690 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
691 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
692 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
693
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
694 /* We have completed an authentication, using the D-H keys we
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
695 * already knew. is_reply indicates whether we initiated the AKE. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
696 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
697 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
698 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
699 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
700 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
701
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
702 /* Log a message. The passed message will end in "\n". */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
703 static void cb_log_message(void *opdata, const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
704 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
705 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
706 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
707
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
708 /* Find the maximum message size supported by this protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
709 static int cb_max_message_size(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
710 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
711 return 8192;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
712 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
713
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
714 #endif /* HAVE_LIBOTR */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
715 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */