annotate mcabber/src/otr.c @ 1301:37b41ed9ed35

Fixed compiler warnings
author Frank Zschockelt <mcabber_otr[at]freakysoft.de>
date Thu, 30 Aug 2007 02:49:36 +0200
parents 3b338a5c01fc
children b6fdbfa6b219
rev   line source
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1 /*
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
2 * otr.c -- Off-The-Record Messaging for mcabber
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
112
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
113 void otr_init(const char *jid)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
114 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
115 char * root = expand_filename("~/.mcabber/otr/");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
116 account = jidtodisp(jid);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
117 keyfile = g_strdup_printf("%s%s.key", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
118 fprfile = g_strdup_printf("%s%s.fpr", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
119 g_free(root);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
120
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
121 OTRL_INIT;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
122
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
123 userstate = otrl_userstate_create ();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
124 if (otrl_privkey_read(userstate, keyfile)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
125 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
126 cb_create_privkey(NULL, account, "jabber");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
127 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
128 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
129 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
130 fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
131 }
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 void otr_terminate(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
135 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
136 ConnContext * ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
137
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
138 for(ctx = userstate->context_root; ctx; ctx = ctx->next)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
139 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
140 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
141
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
142 g_free(account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
143 account = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
144 otrl_userstate_free(userstate);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
145 userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
146 g_free(keyfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
147 keyfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
148 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
149
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
150 static ConnContext * otr_get_context(const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
151 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
152 int null = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
153 return otrl_context_find(userstate, buddy, account, "jabber", 1, &null,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
154 NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
155 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
156
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
157 static void otr_message_disconnect(ConnContext *ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
158 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
159 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
160 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
161 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
162 ctx->protocol, ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
163 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
164
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
165 static void otr_startstop(const char * buddy, int start)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
166 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
167 char * msg = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
168 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
169
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
170 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
171 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
172
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
173 if (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
174 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
175
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
176 if (start) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
177 OtrlPolicy policy = cb_policy(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
178 msg = otrl_proto_default_query_msg(ctx->accountname, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
179 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
180 msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
181 free (msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
182 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
183 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
184 otr_message_disconnect(ctx);
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 void otr_establish(const char *buddy)
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 otr_startstop(buddy, 1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
190 }
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 void otr_disconnect(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
193 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
194 otr_startstop(buddy, 0);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
195 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
196
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
197 void otr_fingerprint(const char * buddy, const char * trust)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
198 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
199 char fpr[45], *tr;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
200 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
201 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
202 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
203
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
204 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
205 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
206 "No active fingerprint - start OTR for this buddy first.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
207 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
208 }
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 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
211 if (trust) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
212 if (strcmp(fpr, trust) == 0)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
213 otrl_context_set_trust(ctx->active_fingerprint, "trust");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
214 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
215 otrl_context_set_trust(ctx->active_fingerprint, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
216 }
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 tr = ctx->active_fingerprint->trust;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
219 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
220 tr && *tr ? "trusted" : "untrusted");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
221 cb_write_fingerprints(NULL);
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 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx)
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 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
227 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
228 NextExpectedSMP nextMsg = ctx->smstate->nextExpected;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
229
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
230 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
231 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
232 if (nextMsg != OTRL_SMP_EXPECT1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
233 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
234 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
235 sbuf = g_strdup_printf("OTR: Received SMP Initiation. "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
236 "Answer with /otr smpr %s $secret",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
237 ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
238 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
239 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
240 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
241 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
242 if (nextMsg != OTRL_SMP_EXPECT2)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
243 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
244 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
245 sbuf = g_strdup("OTR: Received SMP Response.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
246 /* If we received TLV2, we will send TLV3 and expect TLV4 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
247 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
248 }
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 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
251 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
252 if (nextMsg != OTRL_SMP_EXPECT3)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
253 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
254 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
255 /* If we received TLV3, we will send TLV4
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
256 * We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
257 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
258 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
259 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
260 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
261 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
262 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
263 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
264 }
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 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
267 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
268 if (nextMsg != OTRL_SMP_EXPECT4)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
269 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
270 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
271 /* We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
272 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
273 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
274 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
275 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
276 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
277 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
278 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
279 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
280 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
281 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
282 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
283 /* The message we are waiting for will not arrive, so reset
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
284 * and prepare for the next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
285 sbuf = g_strdup("OTR: SMP aborted by your buddy");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
286 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
287 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
288
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
289 if (sbuf) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
290 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
291 g_free(sbuf);
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 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
294
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
295 /*
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
296 * returns whether a otr_message was received
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
297 * 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
298 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
299 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
300 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
301 int ignore_message;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
302 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
303 OtrlTLV *tlvs = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
304 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
305 ConnContext * ctx;
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 *free_msg = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
308 ignore_message = otrl_message_receiving(userstate, &ops, NULL, account,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
309 "jabber", buddy, *otr_data, &newmessage, &tlvs, NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
310
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
311 ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
312
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
313 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
314 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
315 /* Notify the user that the other side disconnected. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
316 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
317 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
318 otr_disconnect(buddy);
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 otr_handle_smp_tlvs(tlvs, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
323
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
324 if (tlvs != NULL)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
325 otrl_tlv_free(tlvs);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
326
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
327 if (ignore_message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
328 *otr_data = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
329
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
330 if (!ignore_message && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
331 *free_msg = 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
332 *otr_data = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
333 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
334 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
335 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
336 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
337 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
338 }
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 int otr_send(char **msg, const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
341 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
342 gcry_error_t err;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
343 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
344 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
345
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
346 err = otrl_message_sending(userstate, &ops, NULL, account, "jabber", buddy,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
347 *msg, NULL, &newmessage, NULL, NULL);
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 if (err)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
350 *msg = NULL; /*something went wrong, don't send the plain-message! */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
351
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
352 if (!err && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
353 *msg = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
354 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
355 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION ||
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
356 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
357 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
358 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
359 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
360 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
361
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
362 /* Prints OTR connection state */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
363 void otr_print_info(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
364 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
365 const char *state, *auth, *policy;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
366 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
367 OtrlPolicy p = cb_policy (ctx->app_data, ctx);
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 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
370 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
371
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
372 switch (ctx->msgstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
373 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
374 case OTRL_MSGSTATE_ENCRYPTED:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
375 switch (ctx->protocol_version) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
376 case 1: state = "encrypted V1"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
377 case 2: state = "encrypted V2"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
378 default:state = "encrypted";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
379 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
380 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
381 case OTRL_MSGSTATE_FINISHED: state = "finished"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
382 default: state = "unknown state";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
383 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
384 switch (ctx->auth.authstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
385 case OTRL_AUTHSTATE_NONE:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
386 switch (ctx->otr_offer) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
387 case OFFER_NOT: auth = "no offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
388 case OFFER_SENT: auth = "offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
389 case OFFER_ACCEPTED: auth = "offer accepted"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
390 case OFFER_REJECTED: auth = "offer rejected"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
391 default: auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
392 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
393 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
394 case OTRL_AUTHSTATE_AWAITING_DHKEY:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
395 auth = "awaiting D-H key"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
396 case OTRL_AUTHSTATE_AWAITING_REVEALSIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
397 auth = "awaiting reveal signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
398 case OTRL_AUTHSTATE_AWAITING_SIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
399 auth = "awaiting signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
400 case OTRL_AUTHSTATE_V1_SETUP:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
401 auth = "v1 setup"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
402 default:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
403 auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
404 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
405 if (p == OTRL_POLICY_NEVER)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
406 policy = "plain";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
407 else if (p == (OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
408 policy = "opportunistic";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
409 else if (p == (OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
410 policy = "manual";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
411 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
412 policy = "always";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
413 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
414 policy = "unknown";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
415
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
416 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
417 ctx->username, state, auth, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
418 }
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 static ConnContext * otr_context_encrypted(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
421 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
422 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
423
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
424 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
425 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
426 "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
427 "use SMP.", buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
428 return NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
429 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
430
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
431 return ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
432 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
433
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
434 void otr_smp_query(const char * buddy, const char * secret)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
435 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
436 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
437
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
438 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
439 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
440 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
441 return;
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
444 if (ctx) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
445 otrl_message_initiate_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
446 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
447 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
448 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
449 "OTR: Socialist Millionaires' Protocol "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
450 "initiated.", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
451 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
452 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
453
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
454 void otr_smp_respond(const char * buddy, const char * secret)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
455 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
456 ConnContext * ctx = otr_context_encrypted(buddy);
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 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
459 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
460 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
461 return;
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
464 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
465 if (!ctx->smstate->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 "Don't call smpr before you haven't received an SMP "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
468 "Initiation!");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
469 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
470 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
471 otrl_message_respond_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
472 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
473 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
474 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
475 "OTR: Socialist Millionaires' Protocol: "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
476 "response sent", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
477 }
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 void otr_smp_abort(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
481 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
482 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
483
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
484 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
485 otrl_message_abort_smp(userstate, &ops, NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
486 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
487 "OTR: Socialist Millionaires' Protocol aborted.",
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
488 0, HBB_PREFIX_INFO, 0);
1299
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
492 void otr_key(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
493 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
494 OtrlPrivKey * key;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
495 char readable[45] = "";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
496
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
497 if(!userstate)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
498 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
499 for (key = userstate->privkey_root; key; key = key->next) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
500 otrl_privkey_fingerprint(userstate, readable, key->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
501 key->protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
502 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
503 }
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 /* Return the OTR policy for the given context. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
507 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx)
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 enum otr_policy p = settings_otr_getpolicy(NULL);
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 if(settings_otr_getpolicy(ctx->username))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
513 p = settings_otr_getpolicy(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
514
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
515 switch (p) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
516 case plain:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
517 return OTRL_POLICY_NEVER;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
518 case opportunistic:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
519 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
520 case manual:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
521 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
522 case always:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
523 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
524 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
525
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
526 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
527 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
528
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
529 /* Create a private key for the given accountname/protocol if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
530 * desired. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
531 static void cb_create_privkey(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
532 const char *protocol)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
533 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
534 gcry_error_t e;
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 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
537 "Generating new OTR key for %s. This may take a while...",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
538 accountname);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
539 scr_DoUpdate();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
540
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
541 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
542
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
543 if (e)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
544 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed!"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
545 " Please mkdir ~/.mcabber/otr/ and restart mcabber.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
546 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
547 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
548 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
549
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
550 /* 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
551 * 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
552 * If you return 1, messages such as heartbeats or other
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
553 * 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
554 * logged in" errors if you're wrong. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
555 static int cb_is_logged_in(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
556 const char *protocol, const char *recipient)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
557 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
558 int ret = (roster_getstatus((char *)recipient, NULL) != offline);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
559 return ret;
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
562 /* Send the given IM to the given recipient from the given
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
563 * accountname/protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
564 static void cb_inject_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
565 const char *protocol, const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
566 const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
567 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
568 char * id = g_strdup("otrinject");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
569 jb_send_msg(recipient, message, ROSTER_TYPE_USER, "", id, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
570 g_free(id);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
571 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
572
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
573 /* Display a notification message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
574 * accountname / protocol / username conversation. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
575 static void cb_notify(void *opdata, OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
576 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
577 const char *username, const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
578 const char *primary, const char *secondary)
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 char * type;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
581 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
582 switch (level) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
583 case OTRL_NOTIFY_ERROR: type = "error"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
584 case OTRL_NOTIFY_WARNING: type = "warning"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
585 case OTRL_NOTIFY_INFO: type = "info"; break;
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
586 default: type = "unknown";
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
587 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
588 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
589 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
590 g_free(sbuf);
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 /* Display an OTR control message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
594 * accountname / protocol / username conversation. Return 0 if you are able
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
595 * 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
596 * function is NULL), the control message will be displayed inline,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
597 * as a received message, or else by using the above notify()
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
598 * callback. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
599 static int cb_display_otr_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
600 const char *protocol, const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
601 const char *msg)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
602 {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
603 scr_WriteIncomingMessage(username, msg, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
604 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
605 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
606
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
607 /* When the list of ConnContexts changes (including a change in
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
608 * state), this is called so the UI can be updated. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
609 static void cb_update_context_list(void *opdata)
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 /*maybe introduce new status characters for mcabber,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
612 * then use this function (?!)*/
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
613 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
614
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
615 /* Return a newly allocated string containing a human-friendly name
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
616 * for the given protocol id */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
617 static const char *cb_protocol_name(void *opdata, const char *protocol)
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 return protocol;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
620 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
621
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
622 /* Deallocate a string allocated by protocol_name */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
623 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
624 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
625 /* 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
626 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
627
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
628 /* A new fingerprint for the given user has been received. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
629 static void cb_new_fingerprint(void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
630 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
631 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
632 unsigned char fingerprint[20])
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
633 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
634 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
635 char readable[45];
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 otrl_privkey_hash_to_human(readable, fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
638 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
639 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
640 g_free(sbuf);
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
643 /* The list of known fingerprints has changed. Write them to disk. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
644 static void cb_write_fingerprints(void *opdata)
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 otrl_privkey_write_fingerprints(userstate, fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
647 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
648
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
649 /* A ConnContext has entered a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
650 static void cb_gone_secure(void *opdata, ConnContext *context)
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 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
653 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
654 }
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 /* A ConnContext has left a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
657 static void cb_gone_insecure(void *opdata, ConnContext *context)
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 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
660 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
661 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
662
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
663 /* We have completed an authentication, using the D-H keys we
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
664 * already knew. is_reply indicates whether we initiated the AKE. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
665 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
666 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
667 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
668 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
669 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
670
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
671 /* Log a message. The passed message will end in "\n". */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
672 static void cb_log_message(void *opdata, const char *message)
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 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
675 }
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 /* Find the maximum message size supported by this protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
678 static int cb_max_message_size(void *opdata, ConnContext *context)
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 return 8192;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
681 }
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 #endif /* HAVE_LIBOTR */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
684 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */