Mercurial > libervia-backend
annotate src/plugins/plugin_sec_otr.py @ 1169:a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 05 Sep 2014 11:01:14 +0200 |
parents | 39572f9d5249 |
children | 2df6427a5299 |
rev | line source |
---|---|
1055 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin for OTR encryption | |
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 # XXX: thanks to Darrik L Mazey for his documentation (https://blog.darmasoft.net/2013/06/30/using-pure-python-otr.html) | |
21 # this implentation is based on it | |
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 | 25 from sat.core.log import getLogger |
26 from sat.core import exceptions | |
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 | 29 from twisted.words.protocols.jabber import jid |
30 from twisted.python import failure | |
1095 | 31 from twisted.internet import defer |
1055 | 32 import potr |
1095 | 33 from sat.memory import persistent |
34 | |
35 NS_OTR = "otr_plugin" | |
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 !") |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
39 DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it !\n\nAre you sure you want to drop your private key ?") |
1055 | 40 |
41 DEFAULT_POLICY_FLAGS = { | |
42 'ALLOW_V1':False, | |
43 'ALLOW_V2':True, | |
44 'REQUIRE_ENCRYPTION':True, | |
45 } | |
46 | |
47 PLUGIN_INFO = { | |
48 "name": "OTR", | |
49 "import_name": "OTR", | |
50 "type": "SEC", | |
51 "protocols": [], | |
52 "dependencies": [], | |
53 "main": "OTR", | |
54 "handler": "no", | |
55 "description": _("""Implementation of OTR""") | |
56 } | |
57 | |
58 | |
59 class Context(potr.context.Context): | |
1095 | 60 def __init__(self, host, account, other_jid): |
61 super(Context, self).__init__(account, other_jid) | |
1055 | 62 self.host = host |
63 | |
64 def getPolicy(self, key): | |
65 if key in DEFAULT_POLICY_FLAGS: | |
66 return DEFAULT_POLICY_FLAGS[key] | |
67 else: | |
68 return False | |
69 | |
1095 | 70 def inject(self, msg_str, appdata=None): |
71 assert isinstance(self.peer, jid.JID) | |
72 msg = msg_str.decode('utf-8') | |
73 client = self.user.client | |
74 log.debug(u'inject(%s, appdata=%s, to=%s)' % (msg, appdata, self.peer)) | |
1055 | 75 mess_data = {'message': msg, |
76 'type': 'chat', | |
77 'from': client.jid, | |
1095 | 78 'to': self.peer, |
1055 | 79 'subject': None, |
80 } | |
81 self.host.generateMessageXML(mess_data) | |
82 client.xmlstream.send(mess_data['xml']) | |
83 | |
84 def setState(self, state): | |
1095 | 85 old_state = self.state |
1055 | 86 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
|
87 log.debug(u"setState: %s (old_state=%s)" % (state, old_state)) |
1095 | 88 |
89 if state == potr.context.STATE_PLAINTEXT: | |
90 feedback = _(u"/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {'other_jid': self.peer.full()} | |
91 elif state == potr.context.STATE_ENCRYPTED: | |
92 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
|
93 trusted = self.getCurrentTrust() |
1095 | 94 except TypeError: |
95 trusted = False | |
96 trusted_str = _(u"trusted") if trusted else _(u"untrusted") | |
97 | |
98 if old_state == potr.context.STATE_ENCRYPTED: | |
99 feedback = _(u"%(trusted)s OTR conversation with %(other_jid)s REFRESHED") % {'trusted': trusted_str, 'other_jid': self.peer.full()} | |
100 else: | |
101 feedback = _(u"%(trusted)s Encrypted OTR conversation started with %(other_jid)s") % {'trusted': trusted_str, 'other_jid': self.peer.full()} | |
102 elif state == potr.context.STATE_FINISHED: | |
103 feedback = _(u"OTR conversation with %(other_jid)s is FINISHED") % {'other_jid': self.peer.full()} | |
104 else: | |
105 log.error(_(u"Unknown OTR state")) | |
106 return | |
107 | |
108 client = self.user.client | |
109 # FIXME: newMessage should manage system message, so they don't appear as coming from the contact | |
110 self.host.bridge.newMessage(client.jid.full(), | |
111 feedback, | |
112 mess_type="headline", | |
113 to_jid=self.peer.full(), | |
114 extra={}, | |
115 profile=client.profile) | |
116 # TODO: send signal to frontends | |
1055 | 117 |
1169
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
118 def disconnect(self): |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
119 """Disconnect the session.""" |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
120 if self.state != potr.context.STATE_PLAINTEXT: |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
121 super(Context, self).disconnect() |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
122 |
1055 | 123 |
124 class Account(potr.context.Account): | |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
125 #TODO: manage trusted keys: if a fingerprint is not used anymore, we have no way to remove it from database yet (same thing for a correspondent jid) |
1055 | 126 |
1095 | 127 def __init__(self, host, client): |
128 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
|
129 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
|
130 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
|
131 super(Account, self).__init__(unicode(client.jid), "xmpp", 1024) |
1095 | 132 self.host = host |
133 self.client = client | |
1055 | 134 |
135 def loadPrivkey(self): | |
1095 | 136 log.debug(u"loadPrivkey") |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
137 return self.privkey |
1055 | 138 |
139 def savePrivkey(self): | |
1095 | 140 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
|
141 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
|
142 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
|
143 priv_key = self.privkey.serializePrivateKey().encode('hex') |
1095 | 144 d = self.host.memory.encryptValue(priv_key, self.client.profile) |
145 def save_encrypted_key(encrypted_priv_key): | |
146 self.client.otr_data[PRIVATE_KEY] = encrypted_priv_key | |
147 d.addCallback(save_encrypted_key) | |
1055 | 148 |
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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 |
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 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
|
157 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
|
158 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
|
159 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
|
160 |
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 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 |
1055 | 171 |
172 class ContextManager(object): | |
173 | |
174 def __init__(self, host, client): | |
175 self.host = host | |
1095 | 176 self.account = Account(host, client) |
1055 | 177 self.contexts = {} |
178 | |
1095 | 179 def startContext(self, other_jid): |
180 assert isinstance(other_jid, jid.JID) | |
181 context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid)) | |
182 return context | |
1055 | 183 |
184 def getContextForUser(self, other): | |
1095 | 185 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
|
186 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
|
187 log.warning("getContextForUser called with a bare jid") |
1055 | 188 return self.startContext(other) |
189 | |
190 | |
191 class OTR(object): | |
192 | |
193 def __init__(self, host): | |
1095 | 194 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
|
195 self._fixPotr() # FIXME: to be removed when potr will be fixed |
1055 | 196 self.host = host |
197 self.context_managers = {} | |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
198 self.skipped_profiles = set() |
1055 | 199 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000) |
200 host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100000) | |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
201 host.bridge.addMethod("skipOTR", ".plugin", in_sign='s', out_sign='', method=self._skipOTR) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
202 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
|
203 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
|
204 host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
205 host.importMenu((MAIN_MENU, D_("Drop private key")), self._dropPrivKey, security_limit=0, type_=C.MENU_SINGLE) |
1055 | 206 |
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
|
207 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
|
208 # 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
|
209 # 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
|
210 # 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
|
211 |
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 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
|
213 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
|
214 '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
|
215 '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
|
216 '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
|
217 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
|
218 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
|
219 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
|
220 |
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
|
221 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
|
222 |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
223 def _skipOTR(self, profile): |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
224 """Tell the backend to not handle OTR for this profile. |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
225 |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
226 @param profile (str): %(doc_profile)s |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
227 """ |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
228 self.skipped_profiles.add(profile) |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
229 |
1095 | 230 @defer.inlineCallbacks |
1055 | 231 def profileConnected(self, profile): |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
232 if profile in self.skipped_profiles: |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
233 return |
1055 | 234 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
|
235 ctxMng = self.context_managers[profile] = ContextManager(self.host, client) |
1095 | 236 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile) |
237 yield client.otr_data.load() | |
238 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None) | |
239 if encrypted_priv_key is not None: | |
240 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile) | |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
241 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0] |
1095 | 242 else: |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
243 ctxMng.account.privkey = 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
|
244 ctxMng.account.loadTrusts() |
1055 | 245 |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
246 def profileDisconnected(self, profile): |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
247 try: |
1169
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
248 for context in self.context_managers[profile].contexts.values(): |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
249 context.disconnect() |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
250 del self.context_managers[profile] |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
251 except KeyError: |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
252 pass |
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
253 try: |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
254 self.skipped_profiles.remove(profile) |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
255 except KeyError: |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
256 pass |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
257 |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
258 def _startRefresh(self, menu_data, profile): |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
259 """Start or refresh an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
260 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
261 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
262 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
263 """ |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
264 try: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
265 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
|
266 if not to_jid.resource: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
267 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
|
268 except KeyError: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
269 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
|
270 return defer.fail(exceptions.DataError) |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
271 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
|
272 query = otrctx.sendMessage(0, '?OTRv?') |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
273 otrctx.inject(query) |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
274 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
275 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
276 def _endSession(self, menu_data, profile): |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
277 """End an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
278 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
279 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
280 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
281 """ |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
282 try: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
283 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
|
284 if not to_jid.resource: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
285 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
|
286 except KeyError: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
287 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
|
288 return defer.fail(exceptions.DataError) |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
289 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
|
290 otrctx.disconnect() |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
291 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
292 |
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
|
293 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
|
294 """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
|
295 |
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 @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
|
297 @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
|
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 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 return defer.fail(exceptions.DataError) |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
306 ctxMng = self.context_managers[profile] |
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
307 otrctx = ctxMng.getContextForUser(to_jid) |
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
308 priv_key = ctxMng.account.privkey |
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
|
309 |
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 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
|
311 # 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 }, |
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 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
|
318 ) |
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 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
|
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 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
|
322 |
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 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
|
324 # 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 }, |
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 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
|
331 ) |
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
|
332 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
|
333 |
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
|
334 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
|
335 # 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
1147
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
345 C.XMLUI_DATA_MESS: note_msg.format(correspondent=otrctx.peer)} |
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
|
346 ) |
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
|
347 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
|
348 |
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
|
349 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
|
350 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
|
351 |
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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
363 def _dropPrivKey(self, menu_data, profile): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
364 """Drop our private Key |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
365 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
366 @param menu_data: %(menu_data)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
367 @param profile: %(doc_profile)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
368 """ |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
369 try: |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
370 to_jid = jid.JID(menu_data['jid']) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
371 if not to_jid.resource: |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
372 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
373 except KeyError: |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
374 log.error(_("jid key is not present !")) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
375 return defer.fail(exceptions.DataError) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
376 |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
377 ctxMng = self.context_managers[profile] |
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
378 if ctxMng.account.privkey is None: |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
379 return {'xmlui': xml_tools.note(_("You don't have a private key yet !")).toXml()} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
380 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
381 def dropKey(data, profile): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
382 if C.bool(data['answer']): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
383 # we end all sessions |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
384 for context in ctxMng.contexts.values(): |
1169
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
385 context.disconnect() |
1147
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
386 ctxMng.account.privkey = None |
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
387 ctxMng.account.getPrivkey() # as account.privkey is None, getPrivkey will generate a new key, and save it |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
388 return {'xmlui': xml_tools.note(_("Your private key has been dropped")).toXml()} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
389 return {} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
390 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
391 submit_id = self.host.registerCallback(dropKey, with_data=True, one_shot=True) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
392 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
393 confirm = xml_tools.XMLUI(C.XMLUI_DIALOG, title=_('Confirm private key drop'), dialog_opt = {'type': C.XMLUI_DIALOG_CONFIRM, 'message': _(DROP_TXT)}, submit_id = submit_id) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
394 return {'xmlui': confirm.toXml()} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
395 |
1055 | 396 def _receivedTreatment(self, data, profile): |
397 from_jid = jid.JID(data['from']) | |
1095 | 398 log.debug(u"_receivedTreatment [from_jid = %s]" % from_jid) |
1055 | 399 otrctx = self.context_managers[profile].getContextForUser(from_jid) |
1095 | 400 encrypted = True |
1055 | 401 |
402 try: | |
1095 | 403 res = otrctx.receiveMessage(data['body'].encode('utf-8')) |
1055 | 404 except potr.context.UnencryptedMessage: |
1095 | 405 if otrctx.state == potr.context.STATE_ENCRYPTED: |
406 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': from_jid.full()}) | |
407 client = self.host.getClient(profile) | |
408 self.host.bridge.newMessage(from_jid.full(), | |
409 _(u"WARNING: received unencrypted data in a supposedly encrypted context"), | |
410 mess_type="headline", # FIXME: add message type for internal informations | |
411 to_jid=client.jid.full(), | |
412 extra={}, | |
413 profile=client.profile) | |
1055 | 414 encrypted = False |
415 | |
1095 | 416 if not encrypted: |
1055 | 417 return data |
418 else: | |
419 if res[0] != None: | |
420 # decrypted messages handling. | |
421 # receiveMessage() will return a tuple, the first part of which will be the decrypted message | |
422 data['body'] = res[0].decode('utf-8') | |
423 raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history | |
424 else: | |
425 raise failure.Failure(exceptions.CancelError()) # no message at all (no history, no signal) | |
426 | |
427 def MessageReceivedTrigger(self, message, post_treat, profile): | |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
428 if profile in self.skipped_profiles: |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
429 return True |
1055 | 430 post_treat.addCallback(self._receivedTreatment, profile) |
431 return True | |
432 | |
433 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): | |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
434 if profile in self.skipped_profiles: |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
435 return True |
1055 | 436 to_jid = mess_data['to'] |
437 if mess_data['type'] != 'groupchat' and not to_jid.resource: | |
438 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 | |
439 otrctx = self.context_managers[profile].getContextForUser(to_jid) | |
1168
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
440 if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT: |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
441 if otrctx.state == potr.context.STATE_ENCRYPTED: |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
442 log.debug(u"encrypting message") |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
443 otrctx.sendMessage(0, mess_data['message'].encode('utf-8')) |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
444 client = self.host.getClient(profile) |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
445 self.host.sendMessageToBridge(mess_data, client) |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
446 else: |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
447 feedback = D_("Your message was not sent because your correspondent closed the encrypted conversation on his/her side. Either close your own side, or refresh the session.") |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
448 client = self.host.getClient(profile) |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
449 self.host.bridge.newMessage(to_jid.full(), |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
450 feedback, |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
451 mess_type="headline", |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
452 to_jid=client.jid.full(), |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
453 extra={}, |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
454 profile=client.profile) |
1055 | 455 return False |
456 else: | |
1095 | 457 log.debug(u"sending message unencrypted") |
1055 | 458 return True |
459 |