annotate src/plugins/plugin_sec_otr.py @ 1955:633b5c21aefd

backend, frontend: messages refactoring (huge commit, not finished): /!\ database schema has been modified, do a backup before updating message have been refactored, here are the main changes: - languages are now handled - all messages have an uid (internal to SàT) - message updating is anticipated - subject is now first class - new naming scheme is used newMessage => messageNew, getHistory => historyGet, sendMessage => messageSend - minimal compatibility refactoring in quick_frontend/Primitivus, better refactoring should follow - threads handling - delayed messages are saved into history - info messages may also be saved in history (e.g. to keep track of people joining/leaving a room) - duplicate messages should be avoided - historyGet return messages in right order, no need to sort again - plugins have been updated to follow new features, some of them need to be reworked (e.g. OTR) - XEP-0203 (Delayed Delivery) is now fully handled in core, the plugin just handle disco and creation of a delay element - /!\ jp and Libervia are currently broken, as some features of Primitivus It has been put in one huge commit to avoid breaking messaging between changes. This is the main part of message refactoring, other commits will follow to take profit of the new features/behaviour.
author Goffi <goffi@goffi.org>
date Tue, 24 May 2016 22:11:04 +0200
parents 2daf7b4c6756
children a2bc5089c2eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for OTR encryption
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1657
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 # XXX: thanks to Darrik L Mazey for his documentation (https://blog.darmasoft.net/2013/06/30/using-pure-python-otr.html)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 # this implentation is based on it
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
23 from sat.core.i18n import _, D_
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
24 from sat.core.constants import Const as C
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.log import getLogger
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core import exceptions
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log = getLogger(__name__)
1141
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
28 from sat.tools import xml_tools
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from twisted.words.protocols.jabber import jid
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from twisted.python import failure
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
31 from twisted.internet import defer
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
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
37
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
38 NS_OTR = "otr_plugin"
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
39 PRIVATE_KEY = "PRIVATE KEY"
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
40 MAIN_MENU = D_('OTR')
1463
364dcdae2bff plugin OTR: fixes a couple of typos
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
41 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 gives you is the same as below. If there is a mismatch, there can be a spy between you!")
364dcdae2bff plugin OTR: fixes a couple of typos
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
42 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
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 DEFAULT_POLICY_FLAGS = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 'ALLOW_V1':False,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 'ALLOW_V2':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 'REQUIRE_ENCRYPTION':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 PLUGIN_INFO = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "import_name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "type": "SEC",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "protocols": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "dependencies": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "main": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "handler": "no",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "description": _("""Implementation of OTR""")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 class Context(potr.context.Context):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
63 def __init__(self, host, account, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
64 super(Context, self).__init__(account, other_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def getPolicy(self, key):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 if key in DEFAULT_POLICY_FLAGS:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 return DEFAULT_POLICY_FLAGS[key]
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
73 def inject(self, msg_str, appdata=None):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
74 assert isinstance(self.peer, jid.JID)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
75 msg = msg_str.decode('utf-8')
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
76 client = self.user.client
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
77 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
78 mess_data = {
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 'from': client.jid,
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
80 'to': self.peer,
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
81 'uid': unicode(uuid.uuid4()),
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
82 'message': {'': msg},
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
83 'subject': {},
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
84 'type': 'chat',
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
85 'extra': {},
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
86 'timestamp': time.time(),
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host.generateMessageXML(mess_data)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 client.xmlstream.send(mess_data['xml'])
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def setState(self, state):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
92 old_state = self.state
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 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
94 log.debug(u"setState: %s (old_state=%s)" % (state, old_state))
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
95
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
96 if state == potr.context.STATE_PLAINTEXT:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
97 feedback = _(u"/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
98 elif state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
99 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
100 trusted = self.getCurrentTrust()
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
101 except TypeError:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
102 trusted = False
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
103 trusted_str = _(u"trusted") if trusted else _(u"untrusted")
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
104
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
105 if old_state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
106 feedback = _(u"%(trusted)s OTR conversation with %(other_jid)s REFRESHED") % {'trusted': trusted_str, 'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
107 else:
1187
eb1144a22e20 plugin OTR: added a warning to tell that the history is not logged anymore and advanced feature are disabled when using OTR
Goffi <goffi@goffi.org>
parents: 1174
diff changeset
108 feedback = _(u"%(trusted)s Encrypted OTR conversation started with %(other_jid)s\n/!\\ Your history is not logged anymore, and most of advanced features are disabled !") % {'trusted': trusted_str, 'other_jid': self.peer.full()}
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
109 elif state == potr.context.STATE_FINISHED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
110 feedback = _(u"OTR conversation with %(other_jid)s is FINISHED") % {'other_jid': self.peer.full()}
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
111 else:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
112 log.error(_(u"Unknown OTR state"))
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
113 return
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
114
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
115 client = self.user.client
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
116 self.host.bridge.messageNew(client.jid.full(),
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
117 feedback,
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
118 mess_type=C.MESS_TYPE_INFO,
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
119 to_jid=self.peer.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
120 extra={},
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
121 profile=client.profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
122 # TODO: send signal to frontends
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123
1169
a3354063dfb6 plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents: 1168
diff changeset
124 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
125 """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
126 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
127 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
128
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1169
diff changeset
129 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
130 """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
131 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
132 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
133
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 class Account(potr.context.Account):
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
136 #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
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
138 def __init__(self, host, client):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
139 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
140 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
141 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
142 super(Account, self).__init__(unicode(client.jid), "xmpp", 1024)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
143 self.host = host
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
144 self.client = client
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 def loadPrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
147 log.debug(u"loadPrivkey")
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
148 return self.privkey
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 def savePrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
151 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
152 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
153 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
154 priv_key = self.privkey.serializePrivateKey().encode('hex')
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
155 d = self.host.memory.encryptValue(priv_key, self.client.profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
156 def save_encrypted_key(encrypted_priv_key):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
157 self.client.otr_data[PRIVATE_KEY] = encrypted_priv_key
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
158 d.addCallback(save_encrypted_key)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159
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
160 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
161 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
162 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
163 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
164 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
165 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
166
7fcafc3206b1 plugin OTR: 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 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
168 log.debug(u"saving trusts for {profile}".format(profile=self.client.profile))
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
169 log.debug(u"trusts = {}".format(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
170 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
171
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 class ContextManager(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185 def __init__(self, host, client):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self.host = host
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
187 self.account = Account(host, client)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188 self.contexts = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
190 def startContext(self, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
191 assert isinstance(other_jid, jid.JID)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
192 context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid))
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
193 return context
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195 def getContextForUser(self, other):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
196 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
197 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
198 log.warning(u"getContextForUser called with a bare jid: %s" % other.full())
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199 return self.startContext(other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
200
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
201
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 class OTR(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
203
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
204 def __init__(self, host):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
205 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
206 self._fixPotr() # FIXME: to be removed when potr will be fixed
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 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
209 self.skipped_profiles = set()
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 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
211 host.trigger.add("messageSend", self.messageSendTrigger, 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
212 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
213 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
214 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
215 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
216 host.importMenu((MAIN_MENU, D_("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
217 host.trigger.add("presenceReceived", self._presenceReceivedTrigger)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218
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
219 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
220 # 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
221 # 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
222 # 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
223
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
224 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
225 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
226 '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
227 '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
228 '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
229 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
230 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
231 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
232
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
233 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
234
1149
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
235 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
236 """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
237
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
238 @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
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 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
241
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
242 @defer.inlineCallbacks
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243 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
244 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
245 return
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246 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
247 ctxMng = self.context_managers[profile] = ContextManager(self.host, client)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
248 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
249 yield client.otr_data.load()
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
250 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None)
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
251 if encrypted_priv_key is not None:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
252 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
253 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0]
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
254 else:
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
255 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
256 ctxMng.account.loadTrusts()
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
257
1149
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
258 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
259 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
260 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
261 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
262 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
263 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
264 pass
a3354063dfb6 plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents: 1168
diff changeset
265 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
266 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
267 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
268 pass
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
269
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
270 def _startRefresh(self, menu_data, profile):
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
271 """Start or refresh an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
272
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
273 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
274 @param profile: %(doc_profile)s
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 try:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
277 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
278 if not to_jid.resource:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
279 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
280 except KeyError:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
281 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
282 return defer.fail(exceptions.DataError)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
283 otrctx = self.context_managers[profile].getContextForUser(to_jid)
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
284 query = otrctx.messageSend(0, '?OTRv?')
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
285 otrctx.inject(query)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
286 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
287
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
288 def _endSession(self, menu_data, profile):
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
289 """End an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
290
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
291 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
292 @param profile: %(doc_profile)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
293 """
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
294 try:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
295 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
296 if not to_jid.resource:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
297 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
298 except KeyError:
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
299 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
300 return defer.fail(exceptions.DataError)
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
301 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
302 otrctx.disconnect()
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
303 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
304
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
305 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
306 """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
307
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
308 @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
309 @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
310 """
7fcafc3206b1 plugin OTR: 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 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
312 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
313 if not to_jid.resource:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
314 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
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
315 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
316 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
317 return defer.fail(exceptions.DataError)
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
318 ctxMng = self.context_managers[profile]
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
319 otrctx = ctxMng.getContextForUser(to_jid)
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
320 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
321
7fcafc3206b1 plugin OTR: 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 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
323 # 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
324 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
325 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
326 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
327 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
328 },
7fcafc3206b1 plugin OTR: 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 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
330 )
7fcafc3206b1 plugin OTR: 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 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
332
7fcafc3206b1 plugin OTR: 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 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
334
7fcafc3206b1 plugin OTR: 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 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
336 # 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
337 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
338 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
1463
364dcdae2bff plugin OTR: fixes a couple of typos
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
339 C.XMLUI_DATA_MESS: _("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
340 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
341 },
7fcafc3206b1 plugin OTR: 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 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
343 )
7fcafc3206b1 plugin OTR: 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 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
345
7fcafc3206b1 plugin OTR: 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 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
347 # 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
348 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
349 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
350 otrctx.setCurrentTrust('verified')
1463
364dcdae2bff plugin OTR: fixes a couple of typos
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
351 note_msg = _("Your correspondent {correspondent} is now TRUSTED")
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
352 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
353 otrctx.setCurrentTrust('')
1463
364dcdae2bff plugin OTR: fixes a couple of typos
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
354 note_msg = _("Your correspondent {correspondent} is now UNTRUSTED")
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
355 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
356 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
1147
736f1dd6e142 plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents: 1146
diff changeset
357 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
358 )
7fcafc3206b1 plugin OTR: 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 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
360
7fcafc3206b1 plugin OTR: 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 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
362 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
363
7fcafc3206b1 plugin OTR: 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 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
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
375 def _dropPrivKey(self, menu_data, profile):
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
376 """Drop our private Key
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
377
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
378 @param menu_data: %(menu_data)s
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
379 @param profile: %(doc_profile)s
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 try:
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
382 to_jid = jid.JID(menu_data['jid'])
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
383 if not to_jid.resource:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
384 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # 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
385 except KeyError:
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
386 log.error(_("jid key is not present !"))
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
387 return defer.fail(exceptions.DataError)
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
388
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
389 ctxMng = self.context_managers[profile]
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
390 if ctxMng.account.privkey is None:
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
391 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
392
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
393 def dropKey(data, profile):
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
394 if C.bool(data['answer']):
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
395 # we end all sessions
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
396 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
397 context.disconnect()
1147
736f1dd6e142 plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents: 1146
diff changeset
398 ctxMng.account.privkey = None
736f1dd6e142 plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents: 1146
diff changeset
399 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
400 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
401 return {}
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
402
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
403 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
404
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
405 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
406 return {'xmlui': confirm.toXml()}
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
407
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
408 def _receivedTreatment(self, data, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
409 from_jid = jid.JID(data['from'])
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
410 log.debug(u"_receivedTreatment [from_jid = %s]" % from_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
411 otrctx = self.context_managers[profile].getContextForUser(from_jid)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
412 encrypted = True
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
413
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
414 try:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
415 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
416 res = otrctx.receiveMessage(message.encode('utf-8'))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
417 except potr.context.UnencryptedMessage:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
418 if otrctx.state == potr.context.STATE_ENCRYPTED:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
419 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': from_jid.full()})
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
420 client = self.host.getClient(profile)
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
421 self.host.bridge.messageNew(from_jid.full(),
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
422 _(u"WARNING: received unencrypted data in a supposedly encrypted context"),
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
423 mess_type=C.MESS_TYPE_INFO,
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
424 to_jid=client.jid.full(),
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
425 extra={},
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
426 profile=client.profile)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
427 encrypted = False
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
428 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
429 return data
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
430
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
431 if not encrypted:
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
432 return data
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
433 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
434 if res[0] != None:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
435 # decrypted messages handling.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
436 # 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
437 data['message'] = {'':res[0].decode('utf-8')} # FIXME: Q&D fix for message refactoring, message is now a dict
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
438 raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
439 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
440 raise failure.Failure(exceptions.CancelError()) # no message at all (no history, no signal)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
441
1174
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
442 def _receivedTreatmentForSkippedProfiles(self, data, profile):
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
443 """This profile must be skipped because the frontend manages OTR itself,
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
444 but we still need to check if the message must be stored in history or not"""
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
445 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
446 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
447 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
448 return data
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
449 if message.startswith(potr.proto.OTRTAG):
1174
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
450 raise failure.Failure(exceptions.SkipHistory())
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
451 return data
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
452
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
453 def MessageReceivedTrigger(self, client, message, post_treat):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
454 profile = client.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
455 if profile in self.skipped_profiles:
1174
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
456 post_treat.addCallback(self._receivedTreatmentForSkippedProfiles, profile)
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
457 else:
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
458 post_treat.addCallback(self._receivedTreatment, profile)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
459 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
460
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
461 def messageSendTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
462 profile = client.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
463 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
464 return True
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
465 to_jid = copy.copy(mess_data['to'])
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
466 if mess_data['type'] != 'groupchat' and not to_jid.resource:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
467 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
468 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
469 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
470 if otrctx.state == potr.context.STATE_ENCRYPTED:
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
471 log.debug(u"encrypting message")
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
472 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
473 msg = mess_data['message']['']
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
474 except KeyError:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
475 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
476 msg = mess_data['message'].itervalues().next()
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
477 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
478 log.warning(u"No message found")
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
479 return False
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
480 otrctx.sendMessage(0, msg.encode('utf-8'))
1168
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
481 self.host.sendMessageToBridge(mess_data, client)
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
482 else:
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
483 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.")
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
484 self.host.bridge.messageNew(to_jid.full(),
1168
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
485 feedback,
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
486 mess_type=C.MESS_TYPE_INFO,
1168
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
487 to_jid=client.jid.full(),
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
488 extra={},
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
489 profile=client.profile)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
490 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
491 else:
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
492 log.debug(u"sending message unencrypted")
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
493 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
494
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1463
diff changeset
495 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
496 if show != C.PRESENCE_UNAVAILABLE:
1249
3be9d8ab2e15 plugin sec_otr: a trigger was not returning True
souliane <souliane@mailoo.org>
parents: 1246
diff changeset
497 return True
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1169
diff changeset
498 if not entity.resource:
1657
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
499 try:
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
500 entity.resource = self.host.memory.getMainResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
501 except exceptions.UnknownEntityError:
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
502 return True # entity was not connected
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
503 if entity in self.context_managers[profile].contexts:
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
504 otrctx = self.context_managers[profile].getContextForUser(entity)
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
505 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
506 return True