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