annotate mcabber/src/otr.c @ 1299:3b338a5c01fc

OTR support
author Frank Zschockelt <mcabber_otr[at]freakysoft.de>
date Thu, 30 Aug 2007 00:52:51 +0200
parents
children 37b41ed9ed35
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"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
32
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
33
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
34 static OtrlUserState userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
35 static char * account = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
36 static char * keyfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
37 static char * fprfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
38 static enum otr_policy policy = manual;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
39
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 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
42 static void cb_create_privkey (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
43 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
44 const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
45 static int cb_is_logged_in (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
46 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
47 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
48 const char *recipient);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
49 static void cb_inject_message (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
50 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
51 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
52 const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
53 const char *message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
54 static void cb_notify (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
55 OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
56 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
57 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
58 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
59 const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
60 const char *primary,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
61 const char *secondary);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
62 static int cb_display_otr_message(void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
63 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
64 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
65 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
66 const char *msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
67 static void cb_update_context_list(void *opdata);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
68 static const char *cb_protocol_name (void *opdata, const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
69 static void cb_protocol_name_free (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
70 const char *protocol_name);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
71 static void cb_new_fingerprint (void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
72 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
73 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
74 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
75 unsigned char fingerprint[20]);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
76 static void cb_write_fingerprints (void *opdata);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
77 static void cb_gone_secure (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
78 static void cb_gone_insecure (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
79 static void cb_still_secure (void *opdata, ConnContext *context,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
80 int is_reply);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
81 static void cb_log_message (void *opdata, const char *message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
82 static int cb_max_message_size (void *opdata, ConnContext *context);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
83
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
84 static OtrlMessageAppOps ops =
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
85 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
86 policy: cb_policy,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
87 create_privkey: cb_create_privkey,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
88 is_logged_in: cb_is_logged_in,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
89 inject_message: cb_inject_message,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
90 notify: cb_notify,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
91 display_otr_message: cb_display_otr_message,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
92 update_context_list: cb_update_context_list,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
93 protocol_name: cb_protocol_name,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
94 protocol_name_free: cb_protocol_name_free,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
95 new_fingerprint: cb_new_fingerprint,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
96 write_fingerprints: cb_write_fingerprints,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
97 gone_secure: cb_gone_secure,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
98 gone_insecure: cb_gone_insecure,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
99 still_secure: cb_still_secure,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
100 log_message: cb_log_message,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
101 max_message_size: cb_max_message_size
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
102 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
103
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
104 static void otr_message_disconnect(ConnContext *ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
105 static ConnContext * otr_get_context(const char *buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
106 static void otr_startstop(const char * buddy, int start);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
107 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
108
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
109
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
110 int otr_init(const char *jid)
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 char * root = expand_filename("~/.mcabber/otr/");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
113 account = jidtodisp(jid);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
114 keyfile = g_strdup_printf("%s%s.key", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
115 fprfile = g_strdup_printf("%s%s.fpr", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
116 g_free(root);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
117
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
118 OTRL_INIT;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
119
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
120 userstate = otrl_userstate_create ();
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
121 if (otrl_privkey_read(userstate, keyfile)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
122 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
123 cb_create_privkey(NULL, account, "jabber");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
124 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
125 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
126 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
127 fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
128 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
129 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
130
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
131 void otr_terminate(void)
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 ConnContext * ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
134
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
135 for(ctx = userstate->context_root; ctx; ctx = ctx->next)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
136 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
137 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
138
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
139 g_free(account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
140 account = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
141 otrl_userstate_free(userstate);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
142 userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
143 g_free(keyfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
144 keyfile = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
145 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
146
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
147 static ConnContext * otr_get_context(const char *buddy)
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 int null = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
150 return otrl_context_find(userstate, buddy, account, "jabber", 1, &null,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
151 NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
152 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
153
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
154 static void otr_message_disconnect(ConnContext *ctx)
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 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
157 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
158 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
159 ctx->protocol, ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
160 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
161
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
162 static void otr_startstop(const char * buddy, int start)
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 char * msg = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
165 ConnContext *ctx = otr_get_context(buddy);
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 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
168 return;
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 (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
171 otr_message_disconnect(ctx);
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) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
174 OtrlPolicy policy = cb_policy(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
175 msg = otrl_proto_default_query_msg(ctx->accountname, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
176 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
177 msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
178 free (msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
179 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
180 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
181 otr_message_disconnect(ctx);
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
184 void otr_establish(const char *buddy)
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 otr_startstop(buddy, 1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
187 }
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 void otr_disconnect(const char * buddy)
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 otr_startstop(buddy, 0);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
192 }
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 void otr_fingerprint(const char * buddy, const char * trust)
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 char fpr[45], *tr;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
197 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
198 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
199 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
200
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
201 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
202 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
203 "No active fingerprint - start OTR for this buddy first.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
204 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
205 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
206
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
207 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
208 if (trust) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
209 if (strcmp(fpr, trust) == 0)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
210 otrl_context_set_trust(ctx->active_fingerprint, "trust");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
211 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
212 otrl_context_set_trust(ctx->active_fingerprint, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
213 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
214
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
215 tr = ctx->active_fingerprint->trust;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
216 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
217 tr && *tr ? "trusted" : "untrusted");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
218 cb_write_fingerprints(NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
219 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
220
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
221 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx)
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 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
224 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
225 NextExpectedSMP nextMsg = ctx->smstate->nextExpected;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
226
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
227 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
228 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
229 if (nextMsg != OTRL_SMP_EXPECT1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
230 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
231 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
232 sbuf = g_strdup_printf("OTR: Received SMP Initiation. "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
233 "Answer with /otr smpr %s $secret",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
234 ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
235 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
236 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
237 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
238 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
239 if (nextMsg != OTRL_SMP_EXPECT2)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
240 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
241 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
242 sbuf = g_strdup("OTR: Received SMP Response.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
243 /* If we received TLV2, we will send TLV3 and expect TLV4 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
244 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
245 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
246 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
247 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
248 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
249 if (nextMsg != OTRL_SMP_EXPECT3)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
250 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
251 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
252 /* If we received TLV3, we will send TLV4
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
253 * We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
254 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
255 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
256 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
257 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
258 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
259 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
260 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
261 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
262 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
263 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
264 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
265 if (nextMsg != OTRL_SMP_EXPECT4)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
266 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
267 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
268 /* We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
269 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
270 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
271 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
272 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
273 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
274 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
275 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
276 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
277 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
278 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
279 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
280 /* The message we are waiting for will not arrive, so reset
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
281 * and prepare for the next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
282 sbuf = g_strdup("OTR: SMP aborted by your buddy");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
283 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
284 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
285
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
286 if (sbuf) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
287 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
288 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
289 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
290 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
291
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
292 /*
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
293 * returns whether a otr_message was received
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
294 * 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
295 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
296 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
297 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
298 int ignore_message;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
299 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
300 OtrlTLV *tlvs = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
301 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
302 ConnContext * ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
303
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
304 *free_msg = 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
305 ignore_message = otrl_message_receiving(userstate, &ops, NULL, account,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
306 "jabber", buddy, *otr_data, &newmessage, &tlvs, NULL, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
307
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
308 ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
309
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
310 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
311 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
312 /* Notify the user that the other side disconnected. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
313 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
314 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
315 otr_disconnect(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
316 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
317 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
318
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
319 otr_handle_smp_tlvs(tlvs, ctx);
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 if (tlvs != NULL)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
322 otrl_tlv_free(tlvs);
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 (ignore_message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
325 *otr_data = NULL;
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 && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
328 *free_msg = 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
329 *otr_data = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
330 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
331 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
332 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
333 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
334 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
335 }
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 int otr_send(char **msg, const char *buddy)
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 gcry_error_t err;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
340 char *newmessage = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
341 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
342
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
343 err = otrl_message_sending(userstate, &ops, NULL, account, "jabber", buddy,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
344 *msg, NULL, &newmessage, NULL, NULL);
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 if (err)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
347 *msg = NULL; /*something went wrong, don't send the plain-message! */
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 && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
350 *msg = g_strdup(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
351 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
352 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION ||
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
353 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
354 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
355 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
356 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
357 }
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 /* Prints OTR connection state */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
360 void otr_print_info(const char * buddy)
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 const char *state, *auth, *policy;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
363 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
364 OtrlPolicy p = cb_policy (ctx->app_data, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
365
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
366 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
367 return;
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 switch (ctx->msgstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
370 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
371 case OTRL_MSGSTATE_ENCRYPTED:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
372 switch (ctx->protocol_version) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
373 case 1: state = "encrypted V1"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
374 case 2: state = "encrypted V2"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
375 default:state = "encrypted";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
376 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
377 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
378 case OTRL_MSGSTATE_FINISHED: state = "finished"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
379 default: state = "unknown state";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
380 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
381 switch (ctx->auth.authstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
382 case OTRL_AUTHSTATE_NONE:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
383 switch (ctx->otr_offer) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
384 case OFFER_NOT: auth = "no offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
385 case OFFER_SENT: auth = "offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
386 case OFFER_ACCEPTED: auth = "offer accepted"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
387 case OFFER_REJECTED: auth = "offer rejected"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
388 default: auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
389 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
390 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
391 case OTRL_AUTHSTATE_AWAITING_DHKEY:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
392 auth = "awaiting D-H key"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
393 case OTRL_AUTHSTATE_AWAITING_REVEALSIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
394 auth = "awaiting reveal signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
395 case OTRL_AUTHSTATE_AWAITING_SIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
396 auth = "awaiting signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
397 case OTRL_AUTHSTATE_V1_SETUP:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
398 auth = "v1 setup"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
399 default:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
400 auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
401 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
402 if (p == OTRL_POLICY_NEVER)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
403 policy = "plain";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
404 else if (p == OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
405 policy = "opportunistic";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
406 else if (p == OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
407 policy = "manual";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
408 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
409 policy = "always";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
410 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
411 policy = "unknown";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
412
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
413 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
414 ctx->username, state, auth, policy);
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
417 static ConnContext * otr_context_encrypted(const char * buddy)
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 ConnContext * ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
420
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
421 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
422 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
423 "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
424 "use SMP.", buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
425 return NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
426 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
427
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
428 return ctx;
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 void otr_smp_query(const char * buddy, const char * secret)
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 ConnContext * ctx = otr_context_encrypted(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
434
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
435 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
436 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
437 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
438 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
439 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
440
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
441 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
442 otrl_message_initiate_smp(userstate, &ops, NULL, ctx, secret,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
443 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
444 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
445 "OTR: Socialist Millionaires' Protocol "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
446 "initiated.", 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
447 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
448 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
449
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
450 void otr_smp_respond(const char * buddy, const char * secret)
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 ConnContext * ctx = otr_context_encrypted(buddy);
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 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
455 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
456 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
457 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
458 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
459
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
460 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
461 if (!ctx->smstate->secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
462 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
463 "Don't call smpr before you haven't received an SMP "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
464 "Initiation!");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
465 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
466 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
467 otrl_message_respond_smp(userstate, &ops, NULL, ctx, secret,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
468 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
469 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
470 "OTR: Socialist Millionaires' Protocol: "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
471 "response sent", 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
472 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
473 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
474
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
475 void otr_smp_abort(const char * buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
476 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
477 ConnContext * ctx = otr_context_encrypted(buddy);
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 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
480 otrl_message_abort_smp(userstate, &ops, NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
481 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
482 "OTR: Socialist Millionaires' Protocol aborted.",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
483 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
484 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
485 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
486
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
487 void otr_key(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
488 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
489 OtrlPrivKey * key;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
490 char readable[45] = "";
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 if(!userstate)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
493 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
494 for (key = userstate->privkey_root; key; key = key->next) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
495 otrl_privkey_fingerprint(userstate, readable, key->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
496 key->protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
497 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
498 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
499 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
500
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
501 /* Return the OTR policy for the given context. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
502 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx)
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 enum otr_policy p = settings_otr_getpolicy(NULL);
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 if(ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
507 if(settings_otr_getpolicy(ctx->username))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
508 p = settings_otr_getpolicy(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
509
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
510 switch (p) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
511 case plain:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
512 return OTRL_POLICY_NEVER;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
513 case opportunistic:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
514 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
515 case manual:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
516 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
517 case always:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
518 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
519 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
520 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
521
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
522 /* Create a private key for the given accountname/protocol if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
523 * desired. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
524 static void cb_create_privkey(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
525 const char *protocol)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
526 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
527 gcry_error_t e;
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 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
530 "Generating new OTR key for %s. This may take a while...",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
531 accountname);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
532 scr_DoUpdate();
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 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol);
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 if (e)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
537 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed!"
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
538 " Please mkdir ~/.mcabber/otr/ and restart mcabber.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
539 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
540 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
541 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
542
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
543 /* 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
544 * 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
545 * If you return 1, messages such as heartbeats or other
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
546 * 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
547 * logged in" errors if you're wrong. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
548 static int cb_is_logged_in(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
549 const char *protocol, const char *recipient)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
550 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
551 int ret = (roster_getstatus((char *)recipient, NULL) != offline);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
552 return ret;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
553 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
554
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
555 /* Send the given IM to the given recipient from the given
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
556 * accountname/protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
557 static void cb_inject_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
558 const char *protocol, const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
559 const char *message)
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 char * id = g_strdup("otrinject");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
562 jb_send_msg(recipient, message, ROSTER_TYPE_USER, "", id, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
563 g_free(id);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
564 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
565
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
566 /* Display a notification message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
567 * accountname / protocol / username conversation. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
568 static void cb_notify(void *opdata, OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
569 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
570 const char *username, const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
571 const char *primary, const char *secondary)
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 char * type;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
574 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
575 switch (level) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
576 case OTRL_NOTIFY_ERROR: type = "error"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
577 case OTRL_NOTIFY_WARNING: type = "warning"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
578 case OTRL_NOTIFY_INFO: type = "info"; break;
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 sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
581 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
582 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
583 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
584
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
585 /* Display an OTR control message for a particular
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
586 * accountname / protocol / username conversation. Return 0 if you are able
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
587 * 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
588 * function is NULL), the control message will be displayed inline,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
589 * as a received message, or else by using the above notify()
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
590 * callback. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
591 static int cb_display_otr_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
592 const char *protocol, const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
593 const char *msg)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
594 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
595 scr_WriteIncomingMessage(username, msg, 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
596 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
597 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
598
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
599 /* When the list of ConnContexts changes (including a change in
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
600 * state), this is called so the UI can be updated. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
601 static void cb_update_context_list(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
602 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
603 /*maybe introduce new status characters for mcabber,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
604 * then use this function (?!)*/
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 /* Return a newly allocated string containing a human-friendly name
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
608 * for the given protocol id */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
609 static const char *cb_protocol_name(void *opdata, const char *protocol)
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 return protocol;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
612 }
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 /* Deallocate a string allocated by protocol_name */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
615 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
616 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
617 /* 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
618 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
619
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
620 /* A new fingerprint for the given user has been received. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
621 static void cb_new_fingerprint(void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
622 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
623 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
624 unsigned char fingerprint[20])
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
625 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
626 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
627 char readable[45];
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
628
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
629 otrl_privkey_hash_to_human(readable, fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
630 sbuf = g_strdup_printf("OTR: new fingerprint: %s", readable);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
631 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
632 g_free(sbuf);
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
635 /* The list of known fingerprints has changed. Write them to disk. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
636 static void cb_write_fingerprints(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
637 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
638 otrl_privkey_write_fingerprints(userstate, fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
639 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
640
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
641 /* A ConnContext has entered a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
642 static void cb_gone_secure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
643 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
644 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
645 HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
646 }
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 /* A ConnContext has left a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
649 static void cb_gone_insecure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
650 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
651 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
652 HBB_PREFIX_INFO);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
653 }
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 /* We have completed an authentication, using the D-H keys we
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
656 * already knew. is_reply indicates whether we initiated the AKE. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
657 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
658 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
659 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
660 HBB_PREFIX_INFO);
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 /* Log a message. The passed message will end in "\n". */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
664 static void cb_log_message(void *opdata, const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
665 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
666 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
667 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
668
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
669 /* Find the maximum message size supported by this protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
670 static int cb_max_message_size(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
671 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
672 return 8192;
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
675 #endif /* HAVE_LIBOTR */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
676 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */