annotate sat/plugins/plugin_sec_otr.py @ 2654:e7bfbded652a

plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies: - omemo module logs are now integrated in SàT - OmemoStorage adapated to changes - now really delete OTPK each time, behaviour may be modified in future - fixed bad arguments used during decryption - adapted to other changes OMEMO is now working \o/ It still needs some adjustements though: bundles/devices are for the moment requested on each message encryption, and fingerprints management is not implemented yet.
author Goffi <goffi@goffi.org>
date Sat, 11 Aug 2018 18:24:55 +0200
parents 7213caa5c5d0
children 9190874a8ac5
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 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
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
20 # XXX: thanks to Darrik L Mazey for his documentation
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
21 # (https://blog.darmasoft.net/2013/06/30/using-pure-python-otr.html)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 # this implentation is based on it
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
24 from sat.core.i18n import _, D_
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
25 from sat.core.constants import Const as C
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.log import getLogger
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat.core import exceptions
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
28
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 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
30 from sat.tools import xml_tools
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from twisted.words.protocols.jabber import jid
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.python import failure
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
33 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
34 from sat.memory import persistent
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 import potr
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1249
diff changeset
36 import copy
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
37 import time
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
38 import uuid
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
39
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
40
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
42 C.PI_NAME: u"OTR",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_IMPORT_NAME: u"OTR",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_TYPE: u"SEC",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_PROTOCOLS: [u"XEP-0364"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
46 C.PI_DEPENDENCIES: [u"XEP-0280", u"XEP-0334"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_MAIN: u"OTR",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_HANDLER: u"no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 C.PI_DESCRIPTION: _(u"""Implementation of OTR"""),
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
52 NS_OTR = "otr_plugin"
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
53 PRIVATE_KEY = "PRIVATE KEY"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 OTR_MENU = D_(u"OTR")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 AUTH_TXT = D_(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
56 u"To authenticate your correspondent, you need to give your below fingerprint "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
57 u"*BY AN EXTERNAL CANAL* (i.e. not in this chat), and check that the one he gives "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
58 u"you is the same as below. If there is a mismatch, there can be a spy between you!"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 DROP_TXT = D_(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
61 u"You private key is used to encrypt messages for your correspondent, nobody except "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
62 u"you must know it, if you are in doubt, you should drop it!\n\nAre you sure you "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
63 u"want to drop your private key?"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 )
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
65 # NO_LOG_AND = D_(u"/!\\Your history is not logged anymore, and") # FIXME: not used at the moment
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
66 NO_ADV_FEATURES = D_(u"Some of advanced features are disabled !")
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
67
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 DEFAULT_POLICY_FLAGS = {"ALLOW_V1": False, "ALLOW_V2": True, "REQUIRE_ENCRYPTION": True}
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
69
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 OTR_STATE_TRUSTED = "trusted"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 OTR_STATE_UNTRUSTED = "untrusted"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 OTR_STATE_UNENCRYPTED = "unencrypted"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 OTR_STATE_ENCRYPTED = "encrypted"
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
74
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 class Context(potr.context.Context):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
77 def __init__(self, host, account, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
78 super(Context, self).__init__(account, other_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def getPolicy(self, key):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if key in DEFAULT_POLICY_FLAGS:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 return DEFAULT_POLICY_FLAGS[key]
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
87 def inject(self, msg_str, appdata=None):
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
88 """Inject encrypted data in the stream
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
89
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
90 if appdata is not None, we are sending a message in sendMessageDataTrigger
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
91 stanza will be injected directly if appdata is None,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
92 else we just update the element and follow normal workflow
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
93 @param msg_str(str): encrypted message body
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
94 @param appdata(None, dict): None for signal message,
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
95 message data when an encrypted message is going to be sent
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
96 """
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
97 assert isinstance(self.peer, jid.JID)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 msg = msg_str.decode("utf-8")
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
99 client = self.user.client
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 log.debug(u"injecting encrypted message to {to}".format(to=self.peer))
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
101 if appdata is None:
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
102 mess_data = {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 "from": client.jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 "to": self.peer,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 "uid": unicode(uuid.uuid4()),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 "message": {"": msg},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 "subject": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 "type": "chat",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 "extra": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 "timestamp": time.time(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 }
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
112 client.generateMessageXML(mess_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 client.send(mess_data["xml"])
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
114 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 message_elt = appdata[u"xml"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 assert message_elt.name == u"message"
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
117 message_elt.addElement("body", content=msg)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def setState(self, state):
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
120 client = self.user.client
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
121 old_state = self.state
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 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
123 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
124
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
125 if state == potr.context.STATE_PLAINTEXT:
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
126 client.encryption.stop(self.peer, NS_OTR)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 feedback = _(u"/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 "other_jid": self.peer.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 self.host.bridge.otrState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 OTR_STATE_UNENCRYPTED, self.peer.full(), client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 )
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
133 elif state == potr.context.STATE_ENCRYPTED:
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
134 client.encryption.start(self.peer, NS_OTR)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
135 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
136 trusted = self.getCurrentTrust()
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
137 except TypeError:
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
138 trusted = False
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
139 trusted_str = _(u"trusted") if trusted else _(u"untrusted")
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
140
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
141 if old_state == potr.context.STATE_ENCRYPTED:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 feedback = D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 u"{trusted} OTR conversation with {other_jid} REFRESHED"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 ).format(trusted=trusted_str, other_jid=self.peer.full())
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
145 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 feedback = D_(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
147 u"{trusted} encrypted OTR conversation started with {other_jid}\n"
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
148 u"{extra_info}"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
149 ).format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 trusted=trusted_str,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 other_jid=self.peer.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 extra_info=NO_ADV_FEATURES,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 self.host.bridge.otrState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 OTR_STATE_ENCRYPTED, self.peer.full(), client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 )
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
157 elif state == potr.context.STATE_FINISHED:
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
158 client.encryption.stop(self.peer, NS_OTR)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 feedback = D_(u"OTR conversation with {other_jid} is FINISHED").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 other_jid=self.peer.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 self.host.bridge.otrState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 OTR_STATE_UNENCRYPTED, self.peer.full(), client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 )
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
165 else:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
166 log.error(D_(u"Unknown OTR state"))
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
167 return
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
168
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
169 client.feedback(self.peer, feedback)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170
1169
a3354063dfb6 plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents: 1168
diff changeset
171 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
172 """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
173 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
174 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
175
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1169
diff changeset
176 def finish(self):
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
177 """Finish the session
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
178
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
179 avoid to send any message but the user still has to end the session himself.
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
180 """
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1169
diff changeset
181 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
182 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
183
1055
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 class Account(potr.context.Account):
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
186 # TODO: manage trusted keys: if a fingerprint is not used anymore,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
187 # we have no way to remove it from database yet (same thing for a
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
188 # correspondent jid)
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
189 # TODO: manage explicit message encryption
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
191 def __init__(self, host, client):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
192 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
193 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
194 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
195 super(Account, self).__init__(unicode(client.jid), "xmpp", 1024)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
196 self.host = host
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
197 self.client = client
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199 def loadPrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
200 log.debug(u"loadPrivkey")
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
201 return self.privkey
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
203 def savePrivkey(self):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
204 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
205 if self.privkey is None:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
206 raise exceptions.InternalError(_(u"Save is called but privkey is None !"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 priv_key = self.privkey.serializePrivateKey().encode("hex")
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
208 d = self.host.memory.encryptValue(priv_key, self.client.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
210 def save_encrypted_key(encrypted_priv_key):
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
211 self.client._otr_data[PRIVATE_KEY] = encrypted_priv_key
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
213 d.addCallback(save_encrypted_key)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214
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 def loadTrusts(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 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
217 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
218 for fingerprint, trust_level in jid_data.iteritems():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 u'setting trust for {jid}: [{fingerprint}] = "{trust_level}"'.format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 jid=jid_, fingerprint=fingerprint, trust_level=trust_level
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 )
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
224 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
225
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
226 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
227 log.debug(u"saving trusts for {profile}".format(profile=self.client.profile))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 log.debug(u"trusts = {}".format(self.client._otr_data["trust"]))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 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
230
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
231 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
232 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 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
234 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
235 trust_data = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 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
237 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
238 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
239 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
240
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
241
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
242 class ContextManager(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243 def __init__(self, host, client):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
244 self.host = host
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
245 self.account = Account(host, client)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.contexts = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
247
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
248 def startContext(self, other_jid):
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
249 assert isinstance(other_jid, jid.JID)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 context = self.contexts.setdefault(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 other_jid, Context(self.host, self.account, other_jid)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
252 )
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
253 return context
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
254
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255 def getContextForUser(self, other):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
256 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
257 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
258 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
259 return self.startContext(other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
260
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
261
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
262 class OTR(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
263 def __init__(self, host):
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
264 log.info(_(u"OTR plugin initialization"))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
265 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self.context_managers = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
267 self.skipped_profiles = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 set()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 ) #  FIXME: OTR should not be skipped per profile, this need to be refactored
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 self._p_hints = host.plugins[u"XEP-0334"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 self._p_carbons = host.plugins[u"XEP-0280"]
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
272 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
273 host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100000)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
274 host.trigger.add("sendMessageData", self._sendMessageDataTrigger)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 "skipOTR", ".plugin", in_sign="s", out_sign="", method=self._skipOTR
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 ) # FIXME: must be removed, must be done on per-message basis
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 host.bridge.addSignal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
279 "otrState", ".plugin", signature="sss"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
280 ) # args: state, destinee_jid, profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
281 host.importMenu(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
282 (OTR_MENU, D_(u"Start/Refresh")),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
283 self._otrStartRefresh,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 security_limit=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
285 help_string=D_(u"Start or refresh an OTR session"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
286 type_=C.MENU_SINGLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 host.importMenu(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 (OTR_MENU, D_(u"End session")),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
290 self._otrSessionEnd,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 security_limit=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 help_string=D_(u"Finish an OTR session"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 type_=C.MENU_SINGLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
295 host.importMenu(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
296 (OTR_MENU, D_(u"Authenticate")),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
297 self._otrAuthenticate,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 security_limit=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 help_string=D_(u"Authenticate user/see your fingerprint"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 type_=C.MENU_SINGLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 host.importMenu(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 (OTR_MENU, D_(u"Drop private key")),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 self._dropPrivKey,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 security_limit=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 type_=C.MENU_SINGLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 )
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1463
diff changeset
308 host.trigger.add("presenceReceived", self._presenceReceivedTrigger)
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
309 self.host.registerEncryptionPlugin(self, u"OTR", NS_OTR)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
310
1149
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
311 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
312 """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
313
652cd93dfdb4 plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents: 1147
diff changeset
314 @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
315 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
316 # 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
317 # 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
318 # 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
319 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
320
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
321 @defer.inlineCallbacks
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
322 def profileConnected(self, client):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
323 if client.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
324 return
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
325 ctxMng = client._otr_context_manager = ContextManager(self.host, client)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
326 client._otr_data = persistent.PersistentBinaryDict(NS_OTR, client.profile)
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
327 yield client._otr_data.load()
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
328 encrypted_priv_key = client._otr_data.get(PRIVATE_KEY, None)
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
329 if encrypted_priv_key is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 priv_key = yield self.host.memory.decryptValue(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 encrypted_priv_key, client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
332 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
334 priv_key.decode("hex")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 )[0]
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
336 else:
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
337 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
338 ctxMng.account.loadTrusts()
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
339
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
340 def profileDisconnected(self, client):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
341 if client.profile in self.skipped_profiles:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
342 self.skipped_profiles.remove(client.profile)
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
343 return
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
344 for context in client._otr_context_manager.contexts.values():
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
345 context.disconnect()
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
346 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
347
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
348 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
349 """Start or refresh an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
350
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
351 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
352 @param profile: %(doc_profile)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
353 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
354 client = self.host.getClient(profile)
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
355 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 to_jid = jid.JID(menu_data["jid"])
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
357 except KeyError:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
358 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
359 return defer.fail(exceptions.DataError)
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
360 self.startRefresh(client, to_jid)
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
361 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
362
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
363 def startRefresh(self, client, to_jid):
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
364 """Start or refresh an OTR session
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
365
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
366 @param to_jid(jid.JID): jid to start encrypted session with
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
367 """
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
368 encrypted_session = client.encryption.getSession(to_jid.userhostJID())
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
369 if encrypted_session and encrypted_session[u'plugin'].namespace != NS_OTR:
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
370 raise exceptions.ConflictError(_(
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
371 u"Can't start an OTR session, there is already an encrypted session "
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
372 u"with {name}").format(name=encrypted_session[u'plugin'].name))
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
373 if not to_jid.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
374 to_jid.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 client, to_jid
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
376 ) # FIXME: temporary and unsecure, must be changed when frontends
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
377 # are refactored
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
378 otrctx = client._otr_context_manager.getContextForUser(to_jid)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
379 query = otrctx.sendMessage(0, "?OTRv?")
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
380 otrctx.inject(query)
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
381
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
382 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
383 """End an OTR session
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
384
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
385 @param menu_data: %(menu_data)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
386 @param profile: %(doc_profile)s
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
387 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
388 client = self.host.getClient(profile)
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
389 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
390 to_jid = jid.JID(menu_data["jid"])
1136
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
391 except KeyError:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
392 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
393 return defer.fail(exceptions.DataError)
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
394 self.endSession(client, to_jid)
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
395 return {}
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
396
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
397 def endSession(self, client, to_jid):
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
398 """End an OTR session"""
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
399 if not to_jid.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
400 to_jid.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
401 client, to_jid
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
402 ) # FIXME: temporary and unsecure, must be changed when frontends
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
403 # are refactored
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
404 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
405 otrctx.disconnect()
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
406 return {}
ea2bbdf5b541 plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents: 1135
diff changeset
407
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
408 def _otrAuthenticate(self, menu_data, profile):
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
409 """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
410
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
411 @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
412 @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
413 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
414 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
415 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 to_jid = jid.JID(menu_data["jid"])
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
417 except KeyError:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
418 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
419 return defer.fail(exceptions.DataError)
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
420 return self.authenticate(client, to_jid)
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
421
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
422 def authenticate(self, client, to_jid):
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
423 """Authenticate other user and see our own fingerprint"""
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
424 if not to_jid.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
425 to_jid.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 client, to_jid
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
427 ) # FIXME: temporary and unsecure, must be changed when frontends
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
428 # are refactored
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
429 ctxMng = client._otr_context_manager
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
430 otrctx = ctxMng.getContextForUser(to_jid)
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
431 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
432
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
433 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
434 # we have no private key yet
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
435 dialog = xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
436 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
437 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
438 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
439 C.XMLUI_DATA_MESS: _(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
440 u"You have no private key yet, start an OTR conversation to "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
441 u"have one"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
442 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
443 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_WARNING,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
444 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
445 title=_(u"No private key"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
446 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
447 return {"xmlui": dialog.toXml()}
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
448
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
449 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
450
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
451 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
452 # we have a private key, but not the fingerprint of our correspondent
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
453 dialog = xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
454 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
456 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
457 C.XMLUI_DATA_MESS: _(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
458 u"Your fingerprint is:\n{fingerprint}\n\n"
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
459 u"Start an OTR conversation to have your correspondent one."
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
460 ).format(fingerprint=priv_key),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
461 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_INFO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
462 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
463 title=_(u"Fingerprint"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
464 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
465 return {"xmlui": dialog.toXml()}
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
466
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
467 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
468 # 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
469 data = xml_tools.XMLUIResult2DataFormResult(raw_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
470 if data["match"] == "yes":
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
471 otrctx.setCurrentTrust(OTR_STATE_TRUSTED)
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
472 note_msg = _(u"Your correspondent {correspondent} is now TRUSTED")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
473 self.host.bridge.otrState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
474 OTR_STATE_TRUSTED, to_jid.full(), client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
475 )
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
476 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
477 otrctx.setCurrentTrust("")
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
478 note_msg = _(u"Your correspondent {correspondent} is now UNTRUSTED")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
479 self.host.bridge.otrState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 OTR_STATE_UNTRUSTED, to_jid.full(), client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
481 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
482 note = xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
483 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
484 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
485 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
486 C.XMLUI_DATA_MESS: note_msg.format(correspondent=otrctx.peer),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
487 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
488 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
489 return {"xmlui": note.toXml()}
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
490
7fcafc3206b1 plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents: 1137
diff changeset
491 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
492 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
493
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
494 xmlui = xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
495 C.XMLUI_FORM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
496 title=_("Authentication (%s)") % to_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
497 submit_id=submit_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
498 )
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
499 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
500 xmlui.addDivider()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
501 xmlui.addText(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
502 D_(u"Your own fingerprint is:\n{fingerprint}").format(fingerprint=priv_key)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
503 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
504 xmlui.addText(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
505 D_(u"Your correspondent fingerprint should be:\n{fingerprint}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
506 fingerprint=other_fingerprint
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
507 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
508 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
509 xmlui.addDivider("blank")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
510 xmlui.changeContainer("pairs")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
511 xmlui.addLabel(D_(u"Is your correspondent fingerprint the same as here ?"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
512 xmlui.addList(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
513 "match", [("yes", _("yes")), ("no", _("no"))], ["yes" if trusted else "no"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
514 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
515 return {"xmlui": xmlui.toXml()}
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
516
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
517 def _dropPrivKey(self, menu_data, profile):
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
518 """Drop our private Key
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
519
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
520 @param menu_data: %(menu_data)s
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
521 @param profile: %(doc_profile)s
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
522 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
523 client = self.host.getClient(profile)
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
524 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
525 to_jid = jid.JID(menu_data["jid"])
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
526 if not to_jid.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
527 to_jid.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
528 client, to_jid
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
529 ) # FIXME: temporary and unsecure, must be changed when frontends
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
530 # are refactored
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
531 except KeyError:
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
532 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
533 return defer.fail(exceptions.DataError)
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
534
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
535 ctxMng = client._otr_context_manager
1146
1ac5ea74dbdf plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents: 1144
diff changeset
536 if ctxMng.account.privkey is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
537 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
538 "xmlui": xml_tools.note(_(u"You don't have a private key yet !")).toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
539 }
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
540
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
541 def dropKey(data, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
542 if C.bool(data["answer"]):
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
543 # we end all sessions
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
544 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
545 context.disconnect()
1147
736f1dd6e142 plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents: 1146
diff changeset
546 ctxMng.account.privkey = None
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
547 ctxMng.account.getPrivkey() # as account.privkey is None, getPrivkey
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
548 # will generate a new key, and save it
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
549 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
550 "xmlui": xml_tools.note(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
551 D_(u"Your private key has been dropped")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
552 ).toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
553 }
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
554 return {}
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
555
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
556 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
557
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
558 confirm = xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
559 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
560 title=_(u"Confirm private key drop"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
561 dialog_opt={"type": C.XMLUI_DIALOG_CONFIRM, "message": _(DROP_TXT)},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
562 submit_id=submit_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
563 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 return {"xmlui": confirm.toXml()}
1144
2481fa96ac1c plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents: 1141
diff changeset
565
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
566 def _receivedTreatment(self, data, client):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
567 from_jid = data["from"]
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
568 log.debug(u"_receivedTreatment [from_jid = %s]" % from_jid)
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
569 otrctx = client._otr_context_manager.getContextForUser(from_jid)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
570
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
571 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
572 message = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
573 data["message"].itervalues().next()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
574 ) # FIXME: Q&D fix for message refactoring, message is now a dict
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
575 res = otrctx.receiveMessage(message.encode("utf-8"))
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
576 except potr.context.UnencryptedMessage:
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
577 encrypted = False
1095
ef7b7dd5c5db plugin OTR: various improvments:
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
578 if otrctx.state == potr.context.STATE_ENCRYPTED:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
579 log.warning(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
580 u"Received unencrypted message in an encrypted context (from {jid})"
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
581 .format(jid=from_jid.full())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
582 )
2125
ca82c97db195 plugin sec OTR: fixed OTR:
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
583
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
584 feedback = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
585 D_(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
586 u"WARNING: received unencrypted data in a supposedly encrypted "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
587 u"context"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
588 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
589 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
590 client.feedback(from_jid, feedback)
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
591 except potr.context.NotEncryptedError:
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
592 msg = D_(u"WARNING: received OTR encrypted data in an unencrypted context")
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
593 log.warning(msg)
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
594 feedback = msg
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
595 client.feedback(from_jid, msg)
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
596 raise failure.Failure(exceptions.CancelError(msg))
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
597 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
598 return data
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
599 else:
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
600 encrypted = True
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
601
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
602 if encrypted:
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
603 if res[0] != None:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
604 # decrypted messages handling.
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
605 # receiveMessage() will return a tuple,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
606 # the first part of which will be the decrypted message
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
607 data["message"] = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
608 "": res[0].decode("utf-8")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
609 } # 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
610 try:
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
611 # we want to keep message in history, even if no store is
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
612 # requested in message hints
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
613 del data[u"history"]
2132
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
614 except KeyError:
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
615 pass
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
616 # TODO: add skip history as an option, but by default we don't skip it
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
617 # data[u'history'] = C.HISTORY_SKIP # we send the decrypted message to
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
618 # frontends, but we don't want it in
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
619 # history
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
620 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
621 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
622 exceptions.CancelError("Cancelled by OTR")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
623 ) # no message at all (no history, no signal)
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
624 return data
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
625
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
626 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
627 """This profile must be skipped because the frontend manages OTR itself,
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
628
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
629 but we still need to check if the message must be stored in history or not
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
630 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 #  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
632 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
633 message = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
634 data["message"].itervalues().next().encode("utf-8")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
635 ) # FIXME: Q&D fix for message refactoring, message is now a dict
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
636 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
637 return data
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
638 if message.startswith(potr.proto.OTRTAG):
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
639 #  FIXME: it may be better to cancel the message and send it direclty to
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
640 # bridge
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
641 # this is used by Libervia, but this may send garbage message to
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
642 # other frontends
2132
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
643 # 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
644 # Hard to avoid with decryption on Libervia though.
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
645 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
646 return data
bc811915a96a plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents: 1171
diff changeset
647
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
648 def MessageReceivedTrigger(self, client, message_elt, post_treat):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
649 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT:
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
650 # OTR is not possible in group chats
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
651 return True
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
652 if client.profile in self.skipped_profiles:
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
653 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
654 else:
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
655 post_treat.addCallback(self._receivedTreatment, client)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
656 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
657
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
658 def _sendMessageDataTrigger(self, client, mess_data):
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
659 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
660 if encryption is None or encryption['plugin'].namespace != NS_OTR:
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
661 return
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
662 to_jid = mess_data['to']
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
663 if not to_jid.resource:
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
664 to_jid.resource = self.host.memory.getMainResource(
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
665 client, to_jid
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
666 ) # FIXME: temporary and unsecure, must be changed when frontends
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
667 otrctx = client._otr_context_manager.getContextForUser(to_jid)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
668 message_elt = mess_data["xml"]
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
669 if otrctx.state == potr.context.STATE_ENCRYPTED:
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
670 log.debug(u"encrypting message")
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
671 body = None
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
672 for child in list(message_elt.children):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
673 if child.name == "body":
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
674 # we remove all unencrypted body,
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
675 # and will only encrypt the first one
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
676 if body is None:
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
677 body = child
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
678 message_elt.children.remove(child)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
679 elif child.name == "html":
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
680 # we don't want any XHTML-IM element
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
681 message_elt.children.remove(child)
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
682 if body is None:
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
683 log.warning(u"No message found")
1168
39572f9d5249 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 1149
diff changeset
684 else:
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
685 self._p_carbons.setPrivate(message_elt)
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
686 self._p_hints.addHintElements(message_elt, [
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
687 self._p_hints.HINT_NO_COPY,
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
688 self._p_hints.HINT_NO_PERMANENT_STORE])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
689 otrctx.sendMessage(0, unicode(body).encode("utf-8"), appdata=mess_data)
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
690 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
691 feedback = D_(
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
692 u"Your message was not sent because your correspondent closed the "
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
693 u"encrypted conversation on his/her side. "
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
694 u"Either close your own side, or refresh the session."
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
695 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
696 log.warning(_(u"Message discarded because closed encryption channel"))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
697 client.feedback(to_jid, feedback)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
698 raise failure.Failure(exceptions.CancelError(u"Cancelled by OTR plugin"))
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
699
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
700 def sendMessageTrigger(self, client, mess_data, pre_xml_treatments,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
701 post_xml_treatments):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
702 if mess_data["type"] == "groupchat":
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
703 return True
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
704
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
705 if client.profile in self.skipped_profiles:
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
706 #  FIXME: should not be done on a per-profile basis
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
707 return True
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
708
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
709 to_jid = copy.copy(mess_data["to"])
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
710 if client.encryption.getSession(to_jid.userhostJID()):
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
711 # there is already an encrypted session with this entity
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
712 return True
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
713
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
714 if not to_jid.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
715 to_jid.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
716 client, to_jid
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
717 ) # FIXME: full jid may not be known
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
718
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
719 otrctx = client._otr_context_manager.getContextForUser(to_jid)
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
720
2138
6e509ee853a8 plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
721 if otrctx.state != potr.context.STATE_PLAINTEXT:
2653
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
722 client.encryption.start(to_jid, NS_OTR)
7213caa5c5d0 plugin OTR: integrated in new encryption handler + fixed use of bare jid where full jid was expected
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
723 client.encryption.setEncryptionFlag(mess_data)
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
724 if not mess_data["to"].resource:
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
725 # if not resource was given, we force it here
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
726 mess_data["to"] = to_jid
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
727 return True
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
728
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1463
diff changeset
729 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
730 if show != C.PRESENCE_UNAVAILABLE:
1249
3be9d8ab2e15 plugin sec_otr: a trigger was not returning True
souliane <souliane@mailoo.org>
parents: 1246
diff changeset
731 return True
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
732 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
733 if not entity.resource:
1657
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
734 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
735 entity.resource = self.host.memory.getMainResource(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
736 client, entity
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
737 ) # FIXME: temporary and unsecure, must be changed when frontends
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
738 # are refactored
1657
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
739 except exceptions.UnknownEntityError:
62cd8fc1aef7 plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents: 1480
diff changeset
740 return True # entity was not connected
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
741 if entity in client._otr_context_manager.contexts:
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2125
diff changeset
742 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
743 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
744 return True