Mercurial > libervia-backend
annotate src/plugins/plugin_sec_otr.py @ 2132:c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
SkipHistory was skipping all remaining triggers just to skip history, which is not the intented behaviour.
Now history can be skipped by setting mess_data[u'history'] = C.HISTORY_SKIP, this way we won't skip importants triggers.
When history is skipped, mess_data[u'extra'][u'history'] will be set to C.HISTORY_SKIP for frontends, so they can inform user that the message is not stored locally.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 05 Feb 2017 14:55:21 +0100 |
parents | 6a66c8c5a567 |
children | 6e509ee853a8 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1055 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # SAT plugin for OTR encryption | |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
1055 | 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 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1249
diff
changeset
|
32 from sat.memory import persistent |
1055 | 33 import potr |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1249
diff
changeset
|
34 import copy |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 import time |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
36 import uuid |
1095 | 37 |
2125 | 38 |
1055 | 39 PLUGIN_INFO = { |
40 "name": "OTR", | |
41 "import_name": "OTR", | |
42 "type": "SEC", | |
43 "protocols": [], | |
44 "dependencies": [], | |
45 "main": "OTR", | |
46 "handler": "no", | |
2125 | 47 "description": _(u"""Implementation of OTR""") |
1055 | 48 } |
49 | |
2128 | 50 NS_OTR = "otr_plugin" |
51 PRIVATE_KEY = "PRIVATE KEY" | |
52 OTR_MENU = D_(u'OTR') | |
53 AUTH_TXT = D_(u"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 gives you is the same as below. If there is a mismatch, there can be a spy between you!") | |
54 DROP_TXT = D_(u"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?") | |
55 # NO_LOG_AND = D_(u"/!\\Your history is not logged anymore, and") # FIXME: not used at the moment | |
56 NO_ADV_FEATURES = D_(u"Most of advanced features are disabled !") | |
57 | |
58 DEFAULT_POLICY_FLAGS = { | |
59 'ALLOW_V1':False, | |
60 'ALLOW_V2':True, | |
61 'REQUIRE_ENCRYPTION':True, | |
62 } | |
63 | |
64 OTR_STATE_TRUSTED = 'trusted' | |
65 OTR_STATE_UNTRUSTED = 'untrusted' | |
66 OTR_STATE_UNENCRYPTED = 'unencrypted' | |
67 OTR_STATE_ENCRYPTED = 'encrypted' | |
68 | |
1055 | 69 |
70 class Context(potr.context.Context): | |
1095 | 71 def __init__(self, host, account, other_jid): |
72 super(Context, self).__init__(account, other_jid) | |
1055 | 73 self.host = host |
74 | |
75 def getPolicy(self, key): | |
76 if key in DEFAULT_POLICY_FLAGS: | |
77 return DEFAULT_POLICY_FLAGS[key] | |
78 else: | |
79 return False | |
80 | |
1095 | 81 def inject(self, msg_str, appdata=None): |
82 assert isinstance(self.peer, jid.JID) | |
83 msg = msg_str.decode('utf-8') | |
84 client = self.user.client | |
85 log.debug(u'inject(%s, appdata=%s, to=%s)' % (msg, appdata, self.peer)) | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
86 mess_data = { |
1055 | 87 'from': client.jid, |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
88 'to': self.peer, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
89 'uid': unicode(uuid.uuid4()), |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
90 'message': {'': msg}, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
91 'subject': {}, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
92 'type': 'chat', |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
93 'extra': {}, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
94 'timestamp': time.time(), |
1055 | 95 } |
96 self.host.generateMessageXML(mess_data) | |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
2128
diff
changeset
|
97 client.send(mess_data['xml']) |
1055 | 98 |
99 def setState(self, state): | |
2128 | 100 client = self.user.client |
1095 | 101 old_state = self.state |
1055 | 102 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
|
103 log.debug(u"setState: %s (old_state=%s)" % (state, old_state)) |
1095 | 104 |
105 if state == potr.context.STATE_PLAINTEXT: | |
106 feedback = _(u"/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {'other_jid': self.peer.full()} | |
2128 | 107 self.host.bridge.otrState(OTR_STATE_UNENCRYPTED, self.peer.full(), client.profile) |
1095 | 108 elif state == potr.context.STATE_ENCRYPTED: |
109 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
|
110 trusted = self.getCurrentTrust() |
1095 | 111 except TypeError: |
112 trusted = False | |
113 trusted_str = _(u"trusted") if trusted else _(u"untrusted") | |
114 | |
115 if old_state == potr.context.STATE_ENCRYPTED: | |
2125 | 116 feedback = D_(u"{trusted} OTR conversation with {other_jid} REFRESHED").format( |
117 trusted = trusted_str, | |
118 other_jid = self.peer.full()) | |
1095 | 119 else: |
2128 | 120 feedback = D_(u"{trusted} encrypted OTR conversation started with {other_jid}\n{extra_info}").format( |
2125 | 121 trusted = trusted_str, |
122 other_jid = self.peer.full(), | |
2128 | 123 extra_info = NO_ADV_FEATURES) |
124 self.host.bridge.otrState(OTR_STATE_ENCRYPTED, self.peer.full(), client.profile) | |
1095 | 125 elif state == potr.context.STATE_FINISHED: |
2125 | 126 feedback = D_(u"OTR conversation with {other_jid} is FINISHED").format(other_jid = self.peer.full()) |
2128 | 127 self.host.bridge.otrState(OTR_STATE_UNENCRYPTED, self.peer.full(), client.profile) |
1095 | 128 else: |
2125 | 129 log.error(D_(u"Unknown OTR state")) |
1095 | 130 return |
131 | |
2125 | 132 self.host.bridge.messageNew(uid=unicode(uuid.uuid4()), |
133 timestamp=time.time(), | |
134 from_jid=client.jid.full(), | |
135 to_jid=self.peer.full(), | |
136 message={u'': feedback}, | |
137 subject={}, | |
1171
0abce7f17782
core: a new "info" type is used in newMessage for system messages (not comming from outside)
Goffi <goffi@goffi.org>
parents:
1170
diff
changeset
|
138 mess_type=C.MESS_TYPE_INFO, |
1095 | 139 extra={}, |
140 profile=client.profile) | |
1055 | 141 |
1169
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
142 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
|
143 """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
|
144 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
|
145 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
|
146 |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
147 def finish(self): |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
148 """Finish the session - avoid to send any message but the user still has to end the session himself.""" |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
149 if self.state == potr.context.STATE_ENCRYPTED: |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
150 self.processTLVs([potr.proto.DisconnectTLV()]) |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
151 |
1055 | 152 |
153 class Account(potr.context.Account): | |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
154 #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 | 155 |
1095 | 156 def __init__(self, host, client): |
157 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
|
158 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
|
159 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
|
160 super(Account, self).__init__(unicode(client.jid), "xmpp", 1024) |
1095 | 161 self.host = host |
162 self.client = client | |
1055 | 163 |
164 def loadPrivkey(self): | |
1095 | 165 log.debug(u"loadPrivkey") |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
166 return self.privkey |
1055 | 167 |
168 def savePrivkey(self): | |
1095 | 169 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
|
170 if self.privkey is None: |
2125 | 171 raise exceptions.InternalError(_(u"Save is called but privkey is None !")) |
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
|
172 priv_key = self.privkey.serializePrivateKey().encode('hex') |
1095 | 173 d = self.host.memory.encryptValue(priv_key, self.client.profile) |
174 def save_encrypted_key(encrypted_priv_key): | |
2128 | 175 self.client._otr_data[PRIVATE_KEY] = encrypted_priv_key |
1095 | 176 d.addCallback(save_encrypted_key) |
1055 | 177 |
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
|
178 def loadTrusts(self): |
2128 | 179 trust_data = self.client._otr_data.get('trust', {}) |
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
|
180 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
|
181 for fingerprint, trust_level in jid_data.iteritems(): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
182 log.debug(u'setting trust for {jid}: [{fingerprint}] = "{trust_level}"'.format(jid=jid_, fingerprint=fingerprint, trust_level=trust_level)) |
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
|
183 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
|
184 |
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
|
185 def saveTrusts(self): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
186 log.debug(u"saving trusts for {profile}".format(profile=self.client.profile)) |
2128 | 187 log.debug(u"trusts = {}".format(self.client._otr_data['trust'])) |
188 self.client._otr_data.force('trust') | |
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
|
189 |
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
|
190 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
|
191 try: |
2128 | 192 trust_data = self.client._otr_data['trust'] |
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
|
193 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
|
194 trust_data = {} |
2128 | 195 self.client._otr_data['trust'] = trust_data |
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
|
196 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
|
197 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
|
198 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
|
199 |
1055 | 200 |
201 class ContextManager(object): | |
202 | |
203 def __init__(self, host, client): | |
204 self.host = host | |
1095 | 205 self.account = Account(host, client) |
1055 | 206 self.contexts = {} |
207 | |
1095 | 208 def startContext(self, other_jid): |
209 assert isinstance(other_jid, jid.JID) | |
210 context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid)) | |
211 return context | |
1055 | 212 |
213 def getContextForUser(self, other): | |
1095 | 214 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
|
215 if not other.resource: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
216 log.warning(u"getContextForUser called with a bare jid: %s" % other.full()) |
1055 | 217 return self.startContext(other) |
218 | |
219 | |
220 class OTR(object): | |
221 | |
222 def __init__(self, host): | |
1095 | 223 log.info(_(u"OTR plugin initialization")) |
1055 | 224 self.host = host |
225 self.context_managers = {} | |
2128 | 226 self.skipped_profiles = set() # FIXME: OTR should not be skipped per profile, this need to be refactored |
1055 | 227 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
228 host.trigger.add("messageSend", self.messageSendTrigger, priority=100000) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
229 host.bridge.addMethod("skipOTR", ".plugin", in_sign='s', out_sign='', method=self._skipOTR) # FIXME: must be removed, must be done on per-message basis |
2128 | 230 host.bridge.addSignal("otrState", ".plugin", signature='sss') # args: state, destinee_jid, profile |
2125 | 231 host.importMenu((OTR_MENU, D_(u"Start/Refresh")), self._otrStartRefresh, security_limit=0, help_string=D_(u"Start or refresh an OTR session"), type_=C.MENU_SINGLE) |
232 host.importMenu((OTR_MENU, D_(u"End session")), self._otrSessionEnd, security_limit=0, help_string=D_(u"Finish an OTR session"), type_=C.MENU_SINGLE) | |
233 host.importMenu((OTR_MENU, D_(u"Authenticate")), self._otrAuthenticate, security_limit=0, help_string=D_(u"Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE) | |
234 host.importMenu((OTR_MENU, D_(u"Drop private key")), self._dropPrivKey, security_limit=0, type_=C.MENU_SINGLE) | |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1463
diff
changeset
|
235 host.trigger.add("presenceReceived", self._presenceReceivedTrigger) |
1055 | 236 |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
237 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
|
238 """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
|
239 |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
240 @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
|
241 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
242 # FIXME: should not be done per profile but per message, using extra data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
243 # for message received, profile wide hook may be need, but client |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
244 # should be used anyway instead of a class attribute |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
245 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
|
246 |
1095 | 247 @defer.inlineCallbacks |
1055 | 248 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
|
249 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
|
250 return |
1055 | 251 client = self.host.getClient(profile) |
2128 | 252 ctxMng = client._otr_context_manager = ContextManager(self.host, client) |
253 client._otr_data = persistent.PersistentBinaryDict(NS_OTR, profile) | |
254 yield client._otr_data.load() | |
255 encrypted_priv_key = client._otr_data.get(PRIVATE_KEY, None) | |
1095 | 256 if encrypted_priv_key is not None: |
257 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
|
258 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0] |
1095 | 259 else: |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
260 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
|
261 ctxMng.account.loadTrusts() |
1055 | 262 |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
263 def profileDisconnected(self, profile): |
2128 | 264 if profile in self.skipped_profiles: |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
265 self.skipped_profiles.remove(profile) |
2128 | 266 return |
267 client = self.host.getClient(profile) | |
268 for context in client._otr_context_manager.contexts.values(): | |
269 context.disconnect() | |
270 del client._otr_context_manager | |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
271 |
2125 | 272 def _otrStartRefresh(self, menu_data, profile): |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
273 """Start or refresh an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
274 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
275 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
276 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
277 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
278 client = self.host.getClient(profile) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
279 try: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
280 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
|
281 except KeyError: |
2125 | 282 log.error(_(u"jid key is not present !")) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
283 return defer.fail(exceptions.DataError) |
2125 | 284 self.startRefresh(client, to_jid) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
285 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
286 |
2125 | 287 def startRefresh(self, client, to_jid): |
288 """Start or refresh an OTR session | |
289 | |
290 @param to_jid(jid.JID): jid to start encrypted session with | |
291 """ | |
292 if not to_jid.resource: | |
293 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored | |
2128 | 294 otrctx = client._otr_context_manager.getContextForUser(to_jid) |
2125 | 295 query = otrctx.sendMessage(0, '?OTRv?') |
296 otrctx.inject(query) | |
297 | |
298 def _otrSessionEnd(self, menu_data, profile): | |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
299 """End an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
300 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
301 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
302 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
303 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
304 client = self.host.getClient(profile) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
305 try: |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
306 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
|
307 except KeyError: |
2125 | 308 log.error(_(u"jid key is not present !")) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
309 return defer.fail(exceptions.DataError) |
2125 | 310 self.endSession(client, to_jid) |
311 return {} | |
312 | |
313 def endSession(self, client, to_jid): | |
314 """End an OTR session""" | |
315 if not to_jid.resource: | |
316 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored | |
2128 | 317 otrctx = client._otr_context_manager.getContextForUser(to_jid) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
318 otrctx.disconnect() |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
319 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
320 |
2125 | 321 def _otrAuthenticate(self, menu_data, profile): |
322 """End an OTR session | |
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
|
323 |
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 @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
|
325 @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
|
326 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 except KeyError: |
2125 | 331 log.error(_(u"jid key is not present !")) |
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
|
332 return defer.fail(exceptions.DataError) |
2125 | 333 return self.authenticate(client, to_jid) |
334 | |
335 def authenticate(self, client, to_jid): | |
336 """Authenticate other user and see our own fingerprint""" | |
337 if not to_jid.resource: | |
338 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored | |
2128 | 339 ctxMng = client._otr_context_manager |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
340 otrctx = ctxMng.getContextForUser(to_jid) |
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
341 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
|
342 |
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 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
|
344 # 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
|
345 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
|
346 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE, |
2125 | 347 C.XMLUI_DATA_MESS: _(u"You have no private key yet, start an OTR conversation to have one"), |
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
|
348 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
|
349 }, |
2125 | 350 title = _(u"No private key"), |
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
|
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 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
|
353 |
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 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
|
355 |
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 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
|
357 # 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
|
358 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
|
359 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE, |
2125 | 360 C.XMLUI_DATA_MESS: _(u"Your fingerprint is:\n{fingerprint}\n\nStart an OTR conversation to have your correspondent one.").format(fingerprint=priv_key), |
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
|
361 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
|
362 }, |
2125 | 363 title = _(u"Fingerprint"), |
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
|
364 ) |
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
|
365 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
|
366 |
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
|
367 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
|
368 # 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
|
369 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
|
370 if data['match'] == 'yes': |
2128 | 371 otrctx.setCurrentTrust(OTR_STATE_TRUSTED) |
2125 | 372 note_msg = _(u"Your correspondent {correspondent} is now TRUSTED") |
2128 | 373 self.host.bridge.otrState(OTR_STATE_TRUSTED, to_jid.full(), client.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
|
374 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
|
375 otrctx.setCurrentTrust('') |
2125 | 376 note_msg = _(u"Your correspondent {correspondent} is now UNTRUSTED") |
2128 | 377 self.host.bridge.otrState(OTR_STATE_UNTRUSTED, to_jid.full(), client.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
|
378 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
|
379 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
1147
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
380 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
|
381 ) |
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
|
382 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
|
383 |
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
|
384 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
|
385 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
|
386 |
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
|
387 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
|
388 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
|
389 xmlui.addDivider() |
2125 | 390 xmlui.addText(D_(u"Your own fingerprint is:\n{fingerprint}").format(fingerprint=priv_key)) |
391 xmlui.addText(D_(u"Your correspondent fingerprint should be:\n{fingerprint}").format(fingerprint=other_fingerprint)) | |
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
|
392 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
|
393 xmlui.changeContainer('pairs') |
2125 | 394 xmlui.addLabel(D_(u'Is your correspondent fingerprint the same as here ?')) |
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
|
395 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
|
396 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
|
397 |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
398 def _dropPrivKey(self, menu_data, profile): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
399 """Drop our private Key |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
400 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
401 @param menu_data: %(menu_data)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
402 @param profile: %(doc_profile)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
403 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
404 client = self.host.getClient(profile) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
405 try: |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
406 to_jid = jid.JID(menu_data['jid']) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
407 if not to_jid.resource: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
408 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
409 except KeyError: |
2125 | 410 log.error(_(u"jid key is not present !")) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
411 return defer.fail(exceptions.DataError) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
412 |
2128 | 413 ctxMng = client._otr_context_manager |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
414 if ctxMng.account.privkey is None: |
2125 | 415 return {'xmlui': xml_tools.note(_(u"You don't have a private key yet !")).toXml()} |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
416 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
417 def dropKey(data, profile): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
418 if C.bool(data['answer']): |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
419 # we end all sessions |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
420 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
|
421 context.disconnect() |
1147
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
422 ctxMng.account.privkey = None |
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
423 ctxMng.account.getPrivkey() # as account.privkey is None, getPrivkey will generate a new key, and save it |
2128 | 424 return {'xmlui': xml_tools.note(D_(u"Your private key has been dropped")).toXml()} |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
425 return {} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
426 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
427 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
|
428 |
2128 | 429 confirm = xml_tools.XMLUI(C.XMLUI_DIALOG, title=_(u'Confirm private key drop'), dialog_opt = {'type': C.XMLUI_DIALOG_CONFIRM, 'message': _(DROP_TXT)}, submit_id = submit_id) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
430 return {'xmlui': confirm.toXml()} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
431 |
2128 | 432 def _receivedTreatment(self, data, client): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
433 from_jid = data['from'] |
1095 | 434 log.debug(u"_receivedTreatment [from_jid = %s]" % from_jid) |
2128 | 435 otrctx = client._otr_context_manager.getContextForUser(from_jid) |
1055 | 436 |
437 try: | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
438 message = data['message'].itervalues().next() # FIXME: Q&D fix for message refactoring, message is now a dict |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
439 res = otrctx.receiveMessage(message.encode('utf-8')) |
1055 | 440 except potr.context.UnencryptedMessage: |
2128 | 441 encrypted = False |
1095 | 442 if otrctx.state == potr.context.STATE_ENCRYPTED: |
2128 | 443 log.warning(u"Received unencrypted message in an encrypted context (from {jid})".format( |
444 jid = from_jid.full())) | |
2125 | 445 |
446 feedback=D_(u"WARNING: received unencrypted data in a supposedly encrypted context"), | |
447 self.host.bridge.messageNew(uid=unicode(uuid.uuid4()), | |
448 timestamp=time.time(), | |
449 from_jid=from_jid.full(), | |
450 to_jid=client.jid.full(), | |
451 message={u'': feedback}, | |
452 subject={}, | |
1171
0abce7f17782
core: a new "info" type is used in newMessage for system messages (not comming from outside)
Goffi <goffi@goffi.org>
parents:
1170
diff
changeset
|
453 mess_type=C.MESS_TYPE_INFO, |
1095 | 454 extra={}, |
455 profile=client.profile) | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
456 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
457 return data |
2128 | 458 else: |
459 encrypted = True | |
1055 | 460 |
2128 | 461 if encrypted: |
1055 | 462 if res[0] != None: |
463 # decrypted messages handling. | |
464 # receiveMessage() will return a tuple, the first part of which will be the decrypted message | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
465 data['message'] = {'':res[0].decode('utf-8')} # FIXME: Q&D fix for message refactoring, message is now a dict |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
466 try: |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
467 # we want to keep message in history, even if no store is requested in message hints |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
468 del message[u'history'] |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
469 except KeyError: |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
470 pass |
2128 | 471 # TODO: add skip history as an option, but by default we don't skip it |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
472 # data[u'history'] = C.HISTORY_SKIP # we send the decrypted message to frontends, but we don't want it in history |
1055 | 473 else: |
2128 | 474 log.warning(u"An encrypted message was expected, but got {}".format(data['message'])) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
475 raise failure.Failure(exceptions.CancelError('Cancelled by OTR')) # no message at all (no history, no signal) |
2128 | 476 return data |
1055 | 477 |
2128 | 478 def _receivedTreatmentForSkippedProfiles(self, data): |
1174
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
479 """This profile must be skipped because the frontend manages OTR itself, |
2128 | 480 |
481 but we still need to check if the message must be stored in history or not | |
482 """ | |
483 # XXX: FIXME: this should not be done on a per-profile basis, but per-message | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
484 try: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
485 message = data['message'].itervalues().next().encode('utf-8') # FIXME: Q&D fix for message refactoring, message is now a dict |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
486 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
487 return data |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
488 if message.startswith(potr.proto.OTRTAG): |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
489 # FIXME: it may be better to cancel the message and send it direclty to bridge |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
490 # this is used by Libervia, but this may send garbage message to other frontends |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
491 # if they are used at the same time as Libervia. |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
492 # Hard to avoid with decryption on Libervia though. |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
493 data[u'history'] = C.HISTORY_SKIP |
1174
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
494 return data |
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
495 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
496 def MessageReceivedTrigger(self, client, message_elt, post_treat): |
2128 | 497 if message_elt.getAttribute('type') == C.MESS_TYPE_GROUPCHAT: |
498 # OTR is not possible in group chats | |
499 return True | |
500 if client.profile in self.skipped_profiles: | |
501 post_treat.addCallback(self._receivedTreatmentForSkippedProfiles) | |
1174
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
502 else: |
2128 | 503 post_treat.addCallback(self._receivedTreatment, client) |
1055 | 504 return True |
505 | |
2128 | 506 def _messageSendOTR(self, mess_data, client): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1249
diff
changeset
|
507 to_jid = copy.copy(mess_data['to']) |
2128 | 508 if not to_jid.resource: |
509 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: full jid may not be known | |
510 otrctx = client._otr_context_manager.getContextForUser(to_jid) | |
511 if otrctx.state != potr.context.STATE_PLAINTEXT: | |
1168
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
512 if otrctx.state == potr.context.STATE_ENCRYPTED: |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
513 log.debug(u"encrypting message") |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
514 try: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
515 msg = mess_data['message'][''] |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
516 except KeyError: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
517 try: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
518 msg = mess_data['message'].itervalues().next() |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
519 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
520 log.warning(u"No message found") |
2128 | 521 for key, value in mess_data['extra'].iteritems(): |
522 if key.startswith('rich') or key.startswith('xhtml'): | |
523 log.error(u'received rich content while OTR encryption is activated, cancelling') | |
524 raise failure.Failure(exceptions.CancelError()) | |
525 return mess_data | |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
526 otrctx.sendMessage(0, msg.encode('utf-8')) |
2128 | 527 self.host.messageAddToHistory(mess_data, client) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
528 self.host.messageSendToBridge(mess_data, client) |
1168
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
529 else: |
2125 | 530 feedback = D_(u"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.") |
531 self.host.bridge.messageNew(uid=unicode(uuid.uuid4()), | |
532 timestamp=time.time(), | |
533 from_jid=to_jid.full(), | |
534 to_jid=client.jid.full(), | |
535 message={u'': feedback}, | |
536 subject={}, | |
1171
0abce7f17782
core: a new "info" type is used in newMessage for system messages (not comming from outside)
Goffi <goffi@goffi.org>
parents:
1170
diff
changeset
|
537 mess_type=C.MESS_TYPE_INFO, |
1168
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
538 extra={}, |
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
539 profile=client.profile) |
2128 | 540 # we stop treatment here for OTR, as message is already sent |
541 raise failure.Failure(exceptions.CancelError()) | |
1055 | 542 else: |
2128 | 543 return mess_data |
544 | |
545 def messageSendTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments): | |
546 if mess_data['type'] == 'groupchat': | |
1055 | 547 return True |
2128 | 548 if client.profile in self.skipped_profiles: # FIXME: should not be done on a per-profile basis |
549 return True | |
550 pre_xml_treatments.addCallback(self._messageSendOTR, client) | |
551 return True | |
1055 | 552 |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1463
diff
changeset
|
553 def _presenceReceivedTrigger(self, entity, show, priority, statuses, profile): |
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1463
diff
changeset
|
554 if show != C.PRESENCE_UNAVAILABLE: |
1249
3be9d8ab2e15
plugin sec_otr: a trigger was not returning True
souliane <souliane@mailoo.org>
parents:
1246
diff
changeset
|
555 return True |
2128 | 556 client = self.host.getClient(profile) |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
557 if not entity.resource: |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
558 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
559 entity.resource = self.host.memory.getMainResource(client, entity) # FIXME: temporary and unsecure, must be changed when frontends are refactored |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
560 except exceptions.UnknownEntityError: |
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
561 return True # entity was not connected |
2128 | 562 if entity in client._otr_context_manager.contexts: |
563 otrctx = client._otr_context_manager.getContextForUser(entity) | |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
564 otrctx.disconnect() |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
565 return True |