annotate src/plugins/plugin_sec_otr.py @ 1141:7fcafc3206b1

plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
author Goffi <goffi@goffi.org>
date Wed, 27 Aug 2014 00:23:14 +0200
parents 768f1f1ef12c
children 2481fa96ac1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for OTR encryption
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 # XXX: thanks to Darrik L Mazey for his documentation (https://blog.darmasoft.net/2013/06/30/using-pure-python-otr.html)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 # this implentation is based on it
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
23 from sat.core.i18n import _, D_
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
24 from sat.core.constants import Const as C
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.log import getLogger
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core import exceptions
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log = getLogger(__name__)
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
28 from sat.tools import xml_tools
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from twisted.words.protocols.jabber import jid
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from twisted.python import failure
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
31 from twisted.internet import defer
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 import potr
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
33 from sat.memory import persistent
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
34
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
35 NS_OTR = "otr_plugin"
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
36 PRIVATE_KEY = "PRIVATE KEY"
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
37 MAIN_MENU = D_('OTR')
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
38 AUTH_TXT = D_("To authenticate your correspondent, you need to give your below fingerprint *BY AN EXTERNAL CANAL* (i.e. not in this chat), and check that the one he give you is the same as below. If there is a mismatch, there can be a spy between you !")
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 DEFAULT_POLICY_FLAGS = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 'ALLOW_V1':False,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 'ALLOW_V2':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 'REQUIRE_ENCRYPTION':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 PLUGIN_INFO = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 "import_name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "type": "SEC",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 "protocols": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "dependencies": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "main": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "handler": "no",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "description": _("""Implementation of OTR""")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 class Context(potr.context.Context):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
59 def __init__(self, host, account, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
60 super(Context, self).__init__(account, other_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def getPolicy(self, key):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 if key in DEFAULT_POLICY_FLAGS:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 return DEFAULT_POLICY_FLAGS[key]
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
69 def inject(self, msg_str, appdata=None):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
70 assert isinstance(self.peer, jid.JID)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
71 msg = msg_str.decode('utf-8')
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
72 client = self.user.client
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
73 log.debug(u'inject(%s, appdata=%s, to=%s)' % (msg, appdata, self.peer))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 mess_data = {'message': msg,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 'type': 'chat',
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 'from': client.jid,
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
77 'to': self.peer,
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 'subject': None,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.host.generateMessageXML(mess_data)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 client.xmlstream.send(mess_data['xml'])
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def setState(self, state):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
84 old_state = self.state
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 super(Context, self).setState(state)
1135
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
86 log.debug(u"setState: %s (old_state=%s)" % (state, old_state))
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
87
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
88 if state == potr.context.STATE_PLAINTEXT:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
89 feedback = _(u"/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
90 elif state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
91 try:
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
92 trusted = self.getCurrentTrust()
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
93 except TypeError:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
94 trusted = False
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
95 trusted_str = _(u"trusted") if trusted else _(u"untrusted")
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
96
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
97 if old_state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
98 feedback = _(u"%(trusted)s OTR conversation with %(other_jid)s REFRESHED") % {'trusted': trusted_str, 'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
99 else:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
100 feedback = _(u"%(trusted)s Encrypted OTR conversation started with %(other_jid)s") % {'trusted': trusted_str, 'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
101 elif state == potr.context.STATE_FINISHED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
102 feedback = _(u"OTR conversation with %(other_jid)s is FINISHED") % {'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
103 else:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
104 log.error(_(u"Unknown OTR state"))
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
105 return
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
106
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
107 client = self.user.client
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
108 # FIXME: newMessage should manage system message, so they don't appear as coming from the contact
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
109 self.host.bridge.newMessage(client.jid.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
110 feedback,
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
111 mess_type="headline",
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
112 to_jid=self.peer.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
113 extra={},
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
114 profile=client.profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
115 # TODO: send signal to frontends
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 class Account(potr.context.Account):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
120 def __init__(self, host, client):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
121 log.debug(u"new account: %s" % client.jid)
1135
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
122 if not client.jid.resource:
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
123 log.warning("Account created without resource")
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
124 super(Account, self).__init__(unicode(client.jid), "xmpp", 1024)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
125 self.host = host
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
126 self.client = client
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def loadPrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
129 log.debug(u"loadPrivkey")
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
130 return self.client.otr_priv_key
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 def savePrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
133 log.debug(u"savePrivkey")
1137
768f1f1ef12c plugin otr: priv_key is better than getPrivKey here, as it should not be None + fixed private key encryption/decryption
Goffi <goffi@goffi.org>
parents: 1136
diff changeset
134 if self.privkey is None:
768f1f1ef12c plugin otr: priv_key is better than getPrivKey here, as it should not be None + fixed private key encryption/decryption
Goffi <goffi@goffi.org>
parents: 1136
diff changeset
135 raise exceptions.InternalError(_("Save is called but privkey is None !"))
768f1f1ef12c plugin otr: priv_key is better than getPrivKey here, as it should not be None + fixed private key encryption/decryption
Goffi <goffi@goffi.org>
parents: 1136
diff changeset
136 priv_key = self.privkey.serializePrivateKey().encode('hex')
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
137 d = self.host.memory.encryptValue(priv_key, self.client.profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
138 def save_encrypted_key(encrypted_priv_key):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
139 self.client.otr_data[PRIVATE_KEY] = encrypted_priv_key
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
140 d.addCallback(save_encrypted_key)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
142 def loadTrusts(self):
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
143 trust_data = self.client.otr_data.get('trust', {})
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
144 for jid_, jid_data in trust_data.iteritems():
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
145 for fingerprint, trust_level in jid_data.iteritems():
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
146 log.debug('setting trust for {jid}: [{fingerprint}] = "{trust_level}"'.format(jid=jid_, fingerprint=fingerprint, trust_level=trust_level))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
147 self.trusts.setdefault(jid.JID(jid_), {})[fingerprint] = trust_level
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
148
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
149 def saveTrusts(self):
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
150 log.debug("saving trusts for {profile}".format(profile=self.client.profile))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
151 log.debug("trusts = {}".format(self.client.otr_data['trust']))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
152 self.client.otr_data.force('trust')
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
153
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
154 def setTrust(self, other_jid, fingerprint, trustLevel):
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
155 try:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
156 trust_data = self.client.otr_data['trust']
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
157 except KeyError:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
158 trust_data = {}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
159 self.client.otr_data['trust'] = trust_data
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
160 jid_data = trust_data.setdefault(other_jid.full(), {})
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
161 jid_data[fingerprint] = trustLevel
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
162 super(Account, self).setTrust(other_jid, fingerprint, trustLevel)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
163
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 class ContextManager(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 def __init__(self, host, client):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 self.host = host
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
169 self.account = Account(host, client)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self.contexts = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
172 def startContext(self, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
173 assert isinstance(other_jid, jid.JID)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
174 context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid))
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
175 return context
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def getContextForUser(self, other):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
178 log.debug(u"getContextForUser [%s]" % other)
1135
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
179 if not other.resource:
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1134
diff changeset
180 log.warning("getContextForUser called with a bare jid")
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 return self.startContext(other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 class OTR(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 def __init__(self, host):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
187 log.info(_(u"OTR plugin initialization"))
1134
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
188 self._fixPotr() # FIXME: to be removed when potr will be fixed
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 self.context_managers = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192 host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100000)
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
193 host.importMenu((MAIN_MENU, D_("Start/Refresh")), self._startRefresh, security_limit=0, help_string=D_("Start or refresh an OTR session"), type_=C.MENU_SINGLE)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
194 host.importMenu((MAIN_MENU, D_("End session")), self._endSession, security_limit=0, help_string=D_("Finish an OTR session"), type_=C.MENU_SINGLE)
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
195 host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196
1134
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
197 def _fixPotr(self):
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
198 # FIXME: potr fix for bad unicode handling
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
199 # this method monkeypatch it, must be removed when potr
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
200 # is fixed
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
201
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
202 def getDefaultQueryMessage(self, policy):
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
203 defaultQuery = '?OTRv{versions}?\nI would like to start ' \
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
204 'an Off-the-Record private conversation. However, you ' \
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
205 'do not have a plugin to support that.\nSee '\
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
206 'https://otr.cypherpunks.ca/ for more information.'
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
207 v = '2' if policy('ALLOW_V2') else ''
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
208 msg = defaultQuery.format(versions=v)
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
209 return msg.encode('ascii')
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
210
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
211 potr.context.Account.getDefaultQueryMessage = getDefaultQueryMessage
8def4a3f55c2 plugin OTR: temporary potr monkey patch to work around a unicode bug, to be removed as soon as a potr fixed version is released (potr maintainer should do it soon)
Goffi <goffi@goffi.org>
parents: 1095
diff changeset
212
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
213 @defer.inlineCallbacks
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 def profileConnected(self, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
215 client = self.host.getClient(profile)
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
216 ctxMng = self.context_managers[profile] = ContextManager(self.host, client)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
217 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
218 yield client.otr_data.load()
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
219 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
220 if encrypted_priv_key is not None:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
221 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile)
1137
768f1f1ef12c plugin otr: priv_key is better than getPrivKey here, as it should not be None + fixed private key encryption/decryption
Goffi <goffi@goffi.org>
parents: 1136
diff changeset
222 client.otr_priv_key = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0]
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
223 else:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
224 client.otr_priv_key = None
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
225 ctxMng.account.loadTrusts()
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
226
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
227 def _startRefresh(self, menu_data, profile):
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
228 """Start or refresh an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
229
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
230 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
231 @param profile: %(doc_profile)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
232 """
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
233 try:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
234 to_jid = jid.JID(menu_data['jid'])
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
235 if not to_jid.resource:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
236 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
237 except KeyError:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
238 log.error(_("jid key is not present !"))
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
239 return defer.fail(exceptions.DataError)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
240 otrctx = self.context_managers[profile].getContextForUser(to_jid)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
241 query = otrctx.sendMessage(0, '?OTRv?')
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
242 otrctx.inject(query)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
243 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
244
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
245 def _endSession(self, menu_data, profile):
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
246 """End an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
247
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
248 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
249 @param profile: %(doc_profile)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
250 """
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
251 try:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
252 to_jid = jid.JID(menu_data['jid'])
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
253 if not to_jid.resource:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
254 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
255 except KeyError:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
256 log.error(_("jid key is not present !"))
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
257 return defer.fail(exceptions.DataError)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
258 otrctx = self.context_managers[profile].getContextForUser(to_jid)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
259 otrctx.disconnect()
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
260 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
261
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
262 def _authenticate(self, menu_data, profile):
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
263 """Authenticate other user and see our own fingerprint
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
264
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
265 @param menu_data: %(menu_data)s
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
266 @param profile: %(doc_profile)s
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
267 """
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
268 try:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
269 to_jid = jid.JID(menu_data['jid'])
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
270 if not to_jid.resource:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
271 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
272 except KeyError:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
273 log.error(_("jid key is not present !"))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
274 return defer.fail(exceptions.DataError)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
275 otrctx = self.context_managers[profile].getContextForUser(to_jid)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
276
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
277 priv_key = otrctx.user.client.otr_priv_key
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
278
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
279 if priv_key is None:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
280 # we have no private key yet
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
281 dialog = xml_tools.XMLUI(C.XMLUI_DIALOG,
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
282 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
283 C.XMLUI_DATA_MESS: _("You have no private key yet, start an OTR conversation to have one"),
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
284 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_WARNING
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
285 },
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
286 title = _("No private key"),
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
287 )
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
288 return {'xmlui': dialog.toXml()}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
289
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
290 other_fingerprint = otrctx.getCurrentKey()
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
291
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
292 if other_fingerprint is None:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
293 # we have a private key, but not the fingerprint of our correspondent
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
294 dialog = xml_tools.XMLUI(C.XMLUI_DIALOG,
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
295 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
296 C.XMLUI_DATA_MESS: _("Your fingerprint is\n{fingerprint}\n\nStart an OTR conversation to have your correspondent one.").format(fingerprint=priv_key),
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
297 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_INFO
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
298 },
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
299 title = _("Fingerprint"),
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
300 )
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
301 return {'xmlui': dialog.toXml()}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
302
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
303 def setTrust(raw_data, profile):
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
304 # This method is called when authentication form is submited
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
305 data = xml_tools.XMLUIResult2DataFormResult(raw_data)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
306 if data['match'] == 'yes':
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
307 otrctx.setCurrentTrust('verified')
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
308 note_msg = _("Your correspondant {correspondent} is now TRUSTED")
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
309 else:
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
310 otrctx.setCurrentTrust('')
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
311 note_msg = _("Your correspondant {correspondent} is now UNTRUSTED")
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
312 note = xml_tools.XMLUI(C.XMLUI_DIALOG, dialog_opt = {
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
313 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
314 C.XMLUI_DATA_MESS: note_msg.format(correspondent=otrctx.user.name)}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
315 )
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
316 return {'xmlui': note.toXml()}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
317
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
318 submit_id = self.host.registerCallback(setTrust, with_data=True, one_shot=True)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
319 trusted = bool(otrctx.getCurrentTrust())
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
320
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
321 xmlui = xml_tools.XMLUI(C.XMLUI_FORM, title=_('Authentication (%s)') % to_jid.full(), submit_id=submit_id)
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
322 xmlui.addText(_(AUTH_TXT))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
323 xmlui.addDivider()
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
324 xmlui.addText(_("Your own fingerprint is:\n{fingerprint}").format(fingerprint=priv_key))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
325 xmlui.addText(_("Your correspondent fingerprint should be:\n{fingerprint}").format(fingerprint=other_fingerprint))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
326 xmlui.addDivider('blank')
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
327 xmlui.changeContainer('pairs')
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
328 xmlui.addLabel(_('Is your correspondent fingerprint the same as here ?'))
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
329 xmlui.addList("match", [('yes', _('yes')),('no', _('no'))], ['yes' if trusted else 'no'])
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
330 return {'xmlui': xmlui.toXml()}
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
331
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
332 def _receivedTreatment(self, data, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
333 from_jid = jid.JID(data['from'])
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
334 log.debug(u"_receivedTreatment [from_jid = %s]" % from_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
335 otrctx = self.context_managers[profile].getContextForUser(from_jid)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
336 encrypted = True
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
337
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
338 try:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
339 res = otrctx.receiveMessage(data['body'].encode('utf-8'))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
340 except potr.context.UnencryptedMessage:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
341 if otrctx.state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
342 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': from_jid.full()})
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
343 client = self.host.getClient(profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
344 self.host.bridge.newMessage(from_jid.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
345 _(u"WARNING: received unencrypted data in a supposedly encrypted context"),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
346 mess_type="headline", # FIXME: add message type for internal informations
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
347 to_jid=client.jid.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
348 extra={},
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
349 profile=client.profile)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
350 encrypted = False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
351
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
352 if not encrypted:
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
353 return data
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
354 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
355 if res[0] != None:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
356 # decrypted messages handling.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
357 # receiveMessage() will return a tuple, the first part of which will be the decrypted message
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
358 data['body'] = res[0].decode('utf-8')
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
359 raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
360 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
361 raise failure.Failure(exceptions.CancelError()) # no message at all (no history, no signal)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
362
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
363 def MessageReceivedTrigger(self, message, post_treat, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
364 post_treat.addCallback(self._receivedTreatment, profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
365 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
366
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
367 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
368 to_jid = mess_data['to']
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
369 if mess_data['type'] != 'groupchat' and not to_jid.resource:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
370 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
371 otrctx = self.context_managers[profile].getContextForUser(to_jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
372 if mess_data['type'] != 'groupchat' and otrctx.state == potr.context.STATE_ENCRYPTED:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
373 log.debug(u"encrypting message")
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
374 otrctx.sendMessage(0, mess_data['message'].encode('utf-8'))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
375 client = self.host.getClient(profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
376 self.host.sendMessageToBridge(mess_data, client)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
377 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
378 else:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
379 log.debug(u"sending message unencrypted")
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
380 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
381