Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_sec_otr.py @ 4351:6a0a081485b8
plugin autocrypt: Autocrypt protocol implementation:
Implementation of autocrypt: `autocrypt` header is checked, and if present and no public
key is known for the peer, the key is imported.
`autocrypt` header is also added to outgoing message (only if an email gateway is
detected).
For the moment, the JID is use as identifier, but the real email used by gateway should be
used in the future.
rel 456
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Feb 2025 09:23:35 +0100 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
1055 | 3 |
4 # SAT plugin for OTR encryption | |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
1055 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
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 | 22 # this implentation is based on it |
23 | |
3028 | 24 import copy |
25 import time | |
26 import uuid | |
27 from binascii import hexlify, unhexlify | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
28 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
29 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
30 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
31 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
32 from libervia.backend.tools import xml_tools |
1055 | 33 from twisted.words.protocols.jabber import jid |
34 from twisted.python import failure | |
1095 | 35 from twisted.internet import defer |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
36 from libervia.backend.memory import persistent |
1055 | 37 import potr |
3028 | 38 |
39 log = getLogger(__name__) | |
1095 | 40 |
2125 | 41 |
1055 | 42 PLUGIN_INFO = { |
3028 | 43 C.PI_NAME: "OTR", |
44 C.PI_IMPORT_NAME: "OTR", | |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
45 C.PI_MODES: [C.PLUG_MODE_CLIENT], |
3028 | 46 C.PI_TYPE: "SEC", |
47 C.PI_PROTOCOLS: ["XEP-0364"], | |
48 C.PI_DEPENDENCIES: ["XEP-0280", "XEP-0334"], | |
49 C.PI_MAIN: "OTR", | |
50 C.PI_HANDLER: "no", | |
51 C.PI_DESCRIPTION: _("""Implementation of OTR"""), | |
1055 | 52 } |
53 | |
2657
9190874a8ac5
plugin otr: use namespace specified in XEP-0378
Goffi <goffi@goffi.org>
parents:
2653
diff
changeset
|
54 NS_OTR = "urn:xmpp:otr:0" |
2128 | 55 PRIVATE_KEY = "PRIVATE KEY" |
3028 | 56 OTR_MENU = D_("OTR") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 AUTH_TXT = D_( |
3028 | 58 "To authenticate your correspondent, you need to give your below fingerprint " |
59 "*BY AN EXTERNAL CANAL* (i.e. not in this chat), and check that the one he gives " | |
60 "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
|
61 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 DROP_TXT = D_( |
3028 | 63 "You private key is used to encrypt messages for your correspondent, nobody except " |
64 "you must know it, if you are in doubt, you should drop it!\n\nAre you sure you " | |
65 "want to drop your private key?" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 ) |
2128 | 67 # NO_LOG_AND = D_(u"/!\\Your history is not logged anymore, and") # FIXME: not used at the moment |
3028 | 68 NO_ADV_FEATURES = D_("Some of advanced features are disabled !") |
2128 | 69 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 DEFAULT_POLICY_FLAGS = {"ALLOW_V1": False, "ALLOW_V2": True, "REQUIRE_ENCRYPTION": True} |
2128 | 71 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 OTR_STATE_TRUSTED = "trusted" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 OTR_STATE_UNTRUSTED = "untrusted" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 OTR_STATE_UNENCRYPTED = "unencrypted" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 OTR_STATE_ENCRYPTED = "encrypted" |
2128 | 76 |
1055 | 77 |
78 class Context(potr.context.Context): | |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
79 def __init__(self, context_manager, other_jid): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
80 self.context_manager = context_manager |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
81 super(Context, self).__init__(context_manager.account, other_jid) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
82 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
83 @property |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
84 def host(self): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
85 return self.context_manager.host |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
86 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
87 @property |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
88 def _p_hints(self): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
89 return self.context_manager.parent._p_hints |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
90 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
91 @property |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
92 def _p_carbons(self): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
93 return self.context_manager.parent._p_carbons |
1055 | 94 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
95 def get_policy(self, key): |
1055 | 96 if key in DEFAULT_POLICY_FLAGS: |
97 return DEFAULT_POLICY_FLAGS[key] | |
98 else: | |
99 return False | |
100 | |
1095 | 101 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
|
102 """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
|
103 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
104 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
|
105 stanza will be injected directly if appdata is None, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
106 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
|
107 @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
|
108 @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
|
109 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
|
110 """ |
1095 | 111 assert isinstance(self.peer, jid.JID) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
112 msg = msg_str.decode("utf-8") |
1095 | 113 client = self.user.client |
3028 | 114 log.debug("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
|
115 if appdata is None: |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
116 mess_data = { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 "from": client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 "to": self.peer, |
3028 | 119 "uid": str(uuid.uuid4()), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 "message": {"": msg}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 "subject": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 "type": "chat", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 "extra": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 "timestamp": time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
126 client.generate_message_xml(mess_data) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
127 xml = mess_data["xml"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
128 self._p_carbons.set_private(xml) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
129 self._p_hints.add_hint_elements( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
130 xml, [self._p_hints.HINT_NO_COPY, self._p_hints.HINT_NO_PERMANENT_STORE] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
131 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 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
|
133 else: |
3028 | 134 message_elt = appdata["xml"] |
135 assert message_elt.name == "message" | |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
136 message_elt.addElement("body", content=msg) |
1055 | 137 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
138 def stop_cb(self, __, feedback): |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
139 client = self.user.client |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
140 self.host.bridge.otr_state( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
141 OTR_STATE_UNENCRYPTED, self.peer.full(), client.profile |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
142 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
143 client.feedback(self.peer, feedback) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
144 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
145 def stop_eb(self, failure_): |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
146 # encryption may be already stopped in case of manual stop |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
147 if not failure_.check(exceptions.NotFound): |
3028 | 148 log.error("Error while stopping OTR encryption: {msg}".format(msg=failure_)) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
149 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
150 def is_trusted(self): |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
151 # we have to check value because potr code says that a 2-tuples should be |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
152 # returned while in practice it's either None or u"trusted" |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
153 trusted = self.getCurrentTrust() |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
154 if trusted is None: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
155 return False |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
156 elif trusted == "trusted": |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
157 return True |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
158 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
159 log.error("Unexpected getCurrentTrust() value: {value}".format(value=trusted)) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
160 return False |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
161 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
162 def set_state(self, state): |
2128 | 163 client = self.user.client |
1095 | 164 old_state = self.state |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
165 super(Context, self).set_state(state) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
166 log.debug("set_state: %s (old_state=%s)" % (state, old_state)) |
1095 | 167 |
168 if state == potr.context.STATE_PLAINTEXT: | |
3028 | 169 feedback = _("/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 "other_jid": self.peer.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 } |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
172 d = defer.ensureDeferred(client.encryption.stop(self.peer, NS_OTR)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
173 d.addCallback(self.stop_cb, feedback=feedback) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
174 d.addErrback(self.stop_eb) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
175 return |
1095 | 176 elif state == potr.context.STATE_ENCRYPTED: |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
177 defer.ensureDeferred(client.encryption.start(self.peer, NS_OTR)) |
1095 | 178 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
179 trusted = self.is_trusted() |
1095 | 180 except TypeError: |
181 trusted = False | |
3028 | 182 trusted_str = _("trusted") if trusted else _("untrusted") |
1095 | 183 |
184 if old_state == potr.context.STATE_ENCRYPTED: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 feedback = D_( |
3028 | 186 "{trusted} OTR conversation with {other_jid} REFRESHED" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 ).format(trusted=trusted_str, other_jid=self.peer.full()) |
1095 | 188 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 feedback = D_( |
3028 | 190 "{trusted} encrypted OTR conversation started with {other_jid}\n" |
191 "{extra_info}" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 ).format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
193 trusted=trusted_str, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 other_jid=self.peer.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 extra_info=NO_ADV_FEATURES, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
197 self.host.bridge.otr_state( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 OTR_STATE_ENCRYPTED, self.peer.full(), client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 ) |
1095 | 200 elif state == potr.context.STATE_FINISHED: |
3028 | 201 feedback = D_("OTR conversation with {other_jid} is FINISHED").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 other_jid=self.peer.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 ) |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
204 d = defer.ensureDeferred(client.encryption.stop(self.peer, NS_OTR)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
205 d.addCallback(self.stop_cb, feedback=feedback) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
206 d.addErrback(self.stop_eb) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
207 return |
1095 | 208 else: |
3028 | 209 log.error(D_("Unknown OTR state")) |
1095 | 210 return |
211 | |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
212 client.feedback(self.peer, feedback) |
1055 | 213 |
1169
a3354063dfb6
plugin OTR: disconnect the active OTR sessions and delete the context on profile disconnection
souliane <souliane@mailoo.org>
parents:
1168
diff
changeset
|
214 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
|
215 """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
|
216 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
|
217 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
|
218 |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
219 def finish(self): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
220 """Finish the session |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
221 |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
222 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
|
223 """ |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
224 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
|
225 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
|
226 |
1055 | 227 |
228 class Account(potr.context.Account): | |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
229 # 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
|
230 # 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
|
231 # correspondent jid) |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
232 # TODO: manage explicit message encryption |
1055 | 233 |
1095 | 234 def __init__(self, host, client): |
3028 | 235 log.debug("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
|
236 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
|
237 log.warning("Account created without resource") |
3028 | 238 super(Account, self).__init__(str(client.jid), "xmpp", 1024) |
1095 | 239 self.host = host |
240 self.client = client | |
1055 | 241 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
242 def load_privkey(self): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
243 log.debug("load_privkey") |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
244 return self.privkey |
1055 | 245 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
246 def save_privkey(self): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
247 log.debug("save_privkey") |
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
|
248 if self.privkey is None: |
3028 | 249 raise exceptions.InternalError(_("Save is called but privkey is None !")) |
250 priv_key = hexlify(self.privkey.serializePrivateKey()) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
251 encrypted_priv_key = self.host.memory.encrypt_value(priv_key, self.client.profile) |
3160
330a5f1d9eea
core (memory/crypto): replaced `PyCrypto` by `cryptography`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
252 self.client._otr_data[PRIVATE_KEY] = encrypted_priv_key |
1055 | 253 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
254 def load_trusts(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 trust_data = self.client._otr_data.get("trust", {}) |
3028 | 256 for jid_, jid_data in trust_data.items(): |
257 for fingerprint, trust_level in jid_data.items(): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 log.debug( |
3028 | 259 'setting trust for {jid}: [{fingerprint}] = "{trust_level}"'.format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 jid=jid_, fingerprint=fingerprint, trust_level=trust_level |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 ) |
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
|
263 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
|
264 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
265 def save_trusts(self): |
3028 | 266 log.debug("saving trusts for {profile}".format(profile=self.client.profile)) |
267 log.debug("trusts = {}".format(self.client._otr_data["trust"])) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 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
|
269 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
270 def set_trust(self, other_jid, fingerprint, trustLevel): |
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
|
271 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 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
|
273 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
|
274 trust_data = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 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
|
276 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
|
277 jid_data[fingerprint] = trustLevel |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
278 super(Account, self).set_trust(other_jid, fingerprint, trustLevel) |
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
|
279 |
1055 | 280 |
281 class ContextManager(object): | |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
282 def __init__(self, parent, client): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
283 self.parent = parent |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
284 self.account = Account(parent.host, client) |
1055 | 285 self.contexts = {} |
286 | |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
287 @property |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
288 def host(self): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
289 return self.parent.host |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
290 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
291 def start_context(self, other_jid): |
1095 | 292 assert isinstance(other_jid, jid.JID) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
293 context = self.contexts.setdefault(other_jid, Context(self, other_jid)) |
1095 | 294 return context |
1055 | 295 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
296 def get_context_for_user(self, other): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
297 log.debug("get_context_for_user [%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
|
298 if not other.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
299 log.warning("get_context_for_user called with a bare jid: %s" % other.full()) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
300 return self.start_context(other) |
1055 | 301 |
302 | |
303 class OTR(object): | |
2659
c26492bd2144
plugin OTR: use new "directed" attribute when registering + use new markAsEncrypted
Goffi <goffi@goffi.org>
parents:
2657
diff
changeset
|
304 |
1055 | 305 def __init__(self, host): |
3028 | 306 log.info(_("OTR plugin initialization")) |
1055 | 307 self.host = host |
308 self.context_managers = {} | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 self.skipped_profiles = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 set() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 ) # FIXME: OTR should not be skipped per profile, this need to be refactored |
3028 | 312 self._p_hints = host.plugins["XEP-0334"] |
313 self._p_carbons = host.plugins["XEP-0280"] | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
314 host.trigger.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
315 "message_received", self.message_received_trigger, priority=100000 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
316 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
317 host.trigger.add("sendMessage", self.send_message_trigger, priority=100000) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
318 host.trigger.add("send_message_data", self._send_message_data_trigger) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
319 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
320 "skip_otr", ".plugin", in_sign="s", out_sign="", method=self._skip_otr |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 ) # FIXME: must be removed, must be done on per-message basis |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
322 host.bridge.add_signal( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
323 "otr_state", ".plugin", signature="sss" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 ) # args: state, destinee_jid, profile |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
325 # XXX: menus are disabled in favor to the new more generic encryption menu |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
326 # there are let here commented for a little while as a reference |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
327 # host.import_menu( |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
328 # (OTR_MENU, D_(u"Start/Refresh")), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
329 # self._otr_start_refresh, |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
330 # security_limit=0, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
331 # help_string=D_(u"Start or refresh an OTR session"), |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
332 # type_=C.MENU_SINGLE, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
333 # ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
334 # host.import_menu( |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
335 # (OTR_MENU, D_(u"End session")), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
336 # self._otr_session_end, |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
337 # security_limit=0, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
338 # help_string=D_(u"Finish an OTR session"), |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
339 # type_=C.MENU_SINGLE, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
340 # ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
341 # host.import_menu( |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
342 # (OTR_MENU, D_(u"Authenticate")), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
343 # self._otr_authenticate, |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
344 # security_limit=0, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
345 # help_string=D_(u"Authenticate user/see your fingerprint"), |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
346 # type_=C.MENU_SINGLE, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
347 # ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
348 # host.import_menu( |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
349 # (OTR_MENU, D_(u"Drop private key")), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
350 # self._drop_priv_key, |
2811
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
351 # security_limit=0, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
352 # type_=C.MENU_SINGLE, |
a26b1ad2d3a4
plugin OTR: disabled menu as the new generic encryption menu allows to start/stop OTR or display the trust UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
353 # ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
354 host.trigger.add("presence_received", self._presence_received_trigger) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
355 self.host.register_encryption_plugin(self, "OTR", NS_OTR, directed=True) |
1055 | 356 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
357 def _skip_otr(self, profile): |
1149
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
358 """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
|
359 |
652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
souliane <souliane@mailoo.org>
parents:
1147
diff
changeset
|
360 @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
|
361 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
362 # 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
|
363 # 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
|
364 # 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
|
365 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
|
366 |
1095 | 367 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
368 def profile_connecting(self, client): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
369 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
|
370 return |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
371 ctxMng = client._otr_context_manager = ContextManager(self, client) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
372 client._otr_data = persistent.PersistentBinaryDict(NS_OTR, client.profile) |
2128 | 373 yield client._otr_data.load() |
374 encrypted_priv_key = client._otr_data.get(PRIVATE_KEY, None) | |
1095 | 375 if encrypted_priv_key is not None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
376 priv_key = self.host.memory.decrypt_value(encrypted_priv_key, client.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
378 unhexlify(priv_key.encode("utf-8")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
379 )[0] |
1095 | 380 else: |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
381 ctxMng.account.privkey = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
382 ctxMng.account.load_trusts() |
1055 | 383 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
384 def profile_disconnected(self, client): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
385 if client.profile in self.skipped_profiles: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
386 self.skipped_profiles.remove(client.profile) |
2128 | 387 return |
3028 | 388 for context in list(client._otr_context_manager.contexts.values()): |
2128 | 389 context.disconnect() |
390 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
|
391 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
392 # encryption plugin methods |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
393 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
394 def start_encryption(self, client, entity_jid): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
395 self.start_refresh(client, entity_jid) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
396 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
397 def stop_encryption(self, client, entity_jid): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
398 self.end_session(client, entity_jid) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
399 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
400 def get_trust_ui(self, client, entity_jid): |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
401 if not entity_jid.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
402 entity_jid.resource = self.host.memory.main_resource_get( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
403 client, entity_jid |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
404 ) # FIXME: temporary and unsecure, must be changed when frontends |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
405 # are refactored |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
406 ctxMng = client._otr_context_manager |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
407 otrctx = ctxMng.get_context_for_user(entity_jid) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
408 priv_key = ctxMng.account.privkey |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
409 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
410 if priv_key is None: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
411 # we have no private key yet |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
412 dialog = xml_tools.XMLUI( |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
413 C.XMLUI_DIALOG, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
414 dialog_opt={ |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
415 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
416 C.XMLUI_DATA_MESS: _( |
3028 | 417 "You have no private key yet, start an OTR conversation to " |
418 "have one" | |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
419 ), |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
420 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_WARNING, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
421 }, |
3028 | 422 title=_("No private key"), |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
423 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
424 return dialog |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
425 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
426 other_fingerprint = otrctx.getCurrentKey() |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
427 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
428 if other_fingerprint is None: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
429 # we have a private key, but not the fingerprint of our correspondent |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
430 dialog = xml_tools.XMLUI( |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
431 C.XMLUI_DIALOG, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
432 dialog_opt={ |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
433 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
434 C.XMLUI_DATA_MESS: _( |
3028 | 435 "Your fingerprint is:\n{fingerprint}\n\n" |
436 "Start an OTR conversation to have your correspondent one." | |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
437 ).format(fingerprint=priv_key), |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
438 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_INFO, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
439 }, |
3028 | 440 title=_("Fingerprint"), |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
441 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
442 return dialog |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
443 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
444 def set_trust(raw_data, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
445 if xml_tools.is_xmlui_cancelled(raw_data): |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
446 return {} |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
447 # This method is called when authentication form is submited |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
448 data = xml_tools.xmlui_result_2_data_form_result(raw_data) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
449 if data["match"] == "yes": |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
450 otrctx.setCurrentTrust(OTR_STATE_TRUSTED) |
3028 | 451 note_msg = _("Your correspondent {correspondent} is now TRUSTED") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
452 self.host.bridge.otr_state( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
453 OTR_STATE_TRUSTED, entity_jid.full(), client.profile |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
454 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
455 else: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
456 otrctx.setCurrentTrust("") |
3028 | 457 note_msg = _("Your correspondent {correspondent} is now UNTRUSTED") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
458 self.host.bridge.otr_state( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
459 OTR_STATE_UNTRUSTED, entity_jid.full(), client.profile |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
460 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
461 note = xml_tools.XMLUI( |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
462 C.XMLUI_DIALOG, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
463 dialog_opt={ |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
464 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
465 C.XMLUI_DATA_MESS: note_msg.format(correspondent=otrctx.peer), |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
466 }, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
467 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
468 return {"xmlui": note.toXml()} |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
469 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
470 submit_id = self.host.register_callback(set_trust, with_data=True, one_shot=True) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
471 trusted = otrctx.is_trusted() |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
472 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
473 xmlui = xml_tools.XMLUI( |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
474 C.XMLUI_FORM, |
3028 | 475 title=_("Authentication ({entity_jid})").format(entity_jid=entity_jid.full()), |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
476 submit_id=submit_id, |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
477 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
478 xmlui.addText(_(AUTH_TXT)) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
479 xmlui.addDivider() |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
480 xmlui.addText( |
3028 | 481 D_("Your own fingerprint is:\n{fingerprint}").format(fingerprint=priv_key) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
482 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
483 xmlui.addText( |
3028 | 484 D_("Your correspondent fingerprint should be:\n{fingerprint}").format( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
485 fingerprint=other_fingerprint |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
486 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
487 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
488 xmlui.addDivider("blank") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
489 xmlui.change_container("pairs") |
3028 | 490 xmlui.addLabel(D_("Is your correspondent fingerprint the same as here ?")) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
491 xmlui.addList( |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
492 "match", [("yes", _("yes")), ("no", _("no"))], ["yes" if trusted else "no"] |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
493 ) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
494 return xmlui |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
495 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
496 def _otr_start_refresh(self, menu_data, profile): |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
497 """Start or refresh an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
498 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
499 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
500 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
501 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
502 client = self.host.get_client(profile) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
503 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
504 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
|
505 except KeyError: |
3028 | 506 log.error(_("jid key is not present !")) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
507 return defer.fail(exceptions.DataError) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
508 self.start_refresh(client, to_jid) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
509 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
510 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
511 def start_refresh(self, client, to_jid): |
2125 | 512 """Start or refresh an OTR session |
513 | |
514 @param to_jid(jid.JID): jid to start encrypted session with | |
515 """ | |
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
|
516 encrypted_session = client.encryption.getSession(to_jid.userhostJID()) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
517 if encrypted_session and encrypted_session["plugin"].namespace != NS_OTR: |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
518 raise exceptions.ConflictError( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
519 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
520 "Can't start an OTR session, there is already an encrypted session " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
521 "with {name}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
522 ).format(name=encrypted_session["plugin"].name) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
523 ) |
2125 | 524 if not to_jid.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
525 to_jid.resource = self.host.memory.main_resource_get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
526 client, to_jid |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
527 ) # FIXME: temporary and unsecure, must be changed when frontends |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
528 # are refactored |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
529 otrctx = client._otr_context_manager.get_context_for_user(to_jid) |
3040 | 530 query = otrctx.sendMessage(0, b"?OTRv?") |
2125 | 531 otrctx.inject(query) |
532 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
533 def _otr_session_end(self, menu_data, profile): |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
534 """End an OTR session |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
535 |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
536 @param menu_data: %(menu_data)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
537 @param profile: %(doc_profile)s |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
538 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
539 client = self.host.get_client(profile) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
540 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
541 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
|
542 except KeyError: |
3028 | 543 log.error(_("jid key is not present !")) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
544 return defer.fail(exceptions.DataError) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
545 self.end_session(client, to_jid) |
2125 | 546 return {} |
547 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
548 def end_session(self, client, to_jid): |
2125 | 549 """End an OTR session""" |
550 if not to_jid.resource: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
551 to_jid.resource = self.host.memory.main_resource_get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
552 client, to_jid |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
553 ) # FIXME: temporary and unsecure, must be changed when frontends |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
554 # are refactored |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
555 otrctx = client._otr_context_manager.get_context_for_user(to_jid) |
1136
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
556 otrctx.disconnect() |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
557 return {} |
ea2bbdf5b541
plugin OTR: added start/refresh and end session menus
Goffi <goffi@goffi.org>
parents:
1135
diff
changeset
|
558 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
559 def _otr_authenticate(self, menu_data, profile): |
2125 | 560 """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
|
561 |
7fcafc3206b1
plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
562 @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
|
563 @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
|
564 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
565 client = self.host.get_client(profile) |
1141
7fcafc3206b1
plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
566 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
567 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
|
568 except KeyError: |
3028 | 569 log.error(_("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
|
570 return defer.fail(exceptions.DataError) |
2125 | 571 return self.authenticate(client, to_jid) |
572 | |
573 def authenticate(self, client, to_jid): | |
574 """Authenticate other user and see our own fingerprint""" | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
575 xmlui = self.get_trust_ui(client, to_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
576 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
|
577 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
578 def _drop_priv_key(self, menu_data, profile): |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
579 """Drop our private Key |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
580 |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
581 @param menu_data: %(menu_data)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
582 @param profile: %(doc_profile)s |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
583 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
584 client = self.host.get_client(profile) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
585 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
586 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
|
587 if not to_jid.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
588 to_jid.resource = self.host.memory.main_resource_get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
589 client, to_jid |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
590 ) # FIXME: temporary and unsecure, must be changed when frontends |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
591 # are refactored |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
592 except KeyError: |
3028 | 593 log.error(_("jid key is not present !")) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
594 return defer.fail(exceptions.DataError) |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
595 |
2128 | 596 ctxMng = client._otr_context_manager |
1146
1ac5ea74dbdf
plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
souliane <souliane@mailoo.org>
parents:
1144
diff
changeset
|
597 if ctxMng.account.privkey is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
598 return { |
3028 | 599 "xmlui": xml_tools.note(_("You don't have a private key yet !")).toXml() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
600 } |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
601 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
602 def drop_key(data, profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
603 if C.bool(data["answer"]): |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
604 # we end all sessions |
3028 | 605 for context in list(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
|
606 context.disconnect() |
1147
736f1dd6e142
plugin OTR: two small fixes
souliane <souliane@mailoo.org>
parents:
1146
diff
changeset
|
607 ctxMng.account.privkey = None |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
608 ctxMng.account.getPrivkey() # as account.privkey is None, getPrivkey |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
609 # will generate a new key, and save it |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
610 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
611 "xmlui": xml_tools.note( |
3028 | 612 D_("Your private key has been dropped") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
613 ).toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
614 } |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
615 return {} |
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
616 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
617 submit_id = self.host.register_callback(drop_key, with_data=True, one_shot=True) |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
618 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
619 confirm = xml_tools.XMLUI( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
620 C.XMLUI_DIALOG, |
3028 | 621 title=_("Confirm private key drop"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
622 dialog_opt={"type": C.XMLUI_DIALOG_CONFIRM, "message": _(DROP_TXT)}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
623 submit_id=submit_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
624 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
625 return {"xmlui": confirm.toXml()} |
1144
2481fa96ac1c
plugin OTR: added ability to drop private key
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
626 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
627 def _received_treatment(self, data, client): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
628 from_jid = data["from"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
629 log.debug("_received_treatment [from_jid = %s]" % from_jid) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
630 otrctx = client._otr_context_manager.get_context_for_user(from_jid) |
1055 | 631 |
632 try: | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
633 message = next( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
634 iter(data["message"].values()) |
2624
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 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
636 res = otrctx.receiveMessage(message.encode("utf-8")) |
3058
0408df45ebe7
plugin OTR: work around a bad exception raised in potr
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
637 except (potr.context.UnencryptedMessage, potr.context.NotOTRMessage): |
0408df45ebe7
plugin OTR: work around a bad exception raised in potr
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
638 # potr has a bug with Python 3 and test message against str while bytes are |
0408df45ebe7
plugin OTR: work around a bad exception raised in potr
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
639 # expected, resulting in a NoOTRMessage raised instead of UnencryptedMessage; |
0408df45ebe7
plugin OTR: work around a bad exception raised in potr
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
640 # so we catch NotOTRMessage as a workaround |
0408df45ebe7
plugin OTR: work around a bad exception raised in potr
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
641 # TODO: report this upstream |
2128 | 642 encrypted = False |
1095 | 643 if otrctx.state == potr.context.STATE_ENCRYPTED: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 log.warning( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
645 "Received unencrypted message in an encrypted context (from {jid})".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
646 jid=from_jid.full() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
647 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
648 ) |
2125 | 649 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 feedback = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 D_( |
3028 | 652 "WARNING: received unencrypted data in a supposedly encrypted " |
653 "context" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
654 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
655 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
656 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
|
657 except potr.context.NotEncryptedError: |
3028 | 658 msg = D_("WARNING: received OTR encrypted data in an unencrypted context") |
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 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
|
660 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
|
661 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
|
662 raise failure.Failure(exceptions.CancelError(msg)) |
2726
a86f494457c2
plugin OTR: catch and log potr.context.ErrorReceived instead of raising it.
Goffi <goffi@goffi.org>
parents:
2659
diff
changeset
|
663 except potr.context.ErrorReceived as e: |
3028 | 664 msg = D_("WARNING: received OTR error message: {msg}".format(msg=e)) |
2726
a86f494457c2
plugin OTR: catch and log potr.context.ErrorReceived instead of raising it.
Goffi <goffi@goffi.org>
parents:
2659
diff
changeset
|
665 log.warning(msg) |
a86f494457c2
plugin OTR: catch and log potr.context.ErrorReceived instead of raising it.
Goffi <goffi@goffi.org>
parents:
2659
diff
changeset
|
666 feedback = msg |
a86f494457c2
plugin OTR: catch and log potr.context.ErrorReceived instead of raising it.
Goffi <goffi@goffi.org>
parents:
2659
diff
changeset
|
667 client.feedback(from_jid, msg) |
a86f494457c2
plugin OTR: catch and log potr.context.ErrorReceived instead of raising it.
Goffi <goffi@goffi.org>
parents:
2659
diff
changeset
|
668 raise failure.Failure(exceptions.CancelError(msg)) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
669 except potr.crypt.InvalidParameterError as e: |
3028 | 670 msg = D_("Error while trying de decrypt OTR message: {msg}".format(msg=e)) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
671 log.warning(msg) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
672 feedback = msg |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
673 client.feedback(from_jid, msg) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
674 raise failure.Failure(exceptions.CancelError(msg)) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
675 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
676 return data |
2128 | 677 else: |
678 encrypted = True | |
1055 | 679 |
2128 | 680 if encrypted: |
1055 | 681 if res[0] != None: |
682 # decrypted messages handling. | |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
683 # receiveMessage() will return a tuple, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
684 # 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
|
685 data["message"] = { |
3028 | 686 "": res[0] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
687 } # 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
|
688 try: |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
689 # 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
|
690 # requested in message hints |
3028 | 691 del data["history"] |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
692 except KeyError: |
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
693 pass |
2128 | 694 # 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
|
695 # data[u'history'] = C.HISTORY_SKIP # we send the decrypted message to |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
696 # frontends, but we don't want it in |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
697 # history |
1055 | 698 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
699 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
700 exceptions.CancelError("Cancelled by OTR") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
701 ) # no message at all (no history, no signal) |
2753
3dd265d281e1
plugin OTR: fixed a bug which was tagging every message as "encrypted"
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
702 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
703 client.encryption.mark_as_encrypted(data, namespace=NS_OTR) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
704 trusted = otrctx.is_trusted() |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
705 |
2753
3dd265d281e1
plugin OTR: fixed a bug which was tagging every message as "encrypted"
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
706 if trusted: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
707 client.encryption.mark_as_trusted(data) |
2753
3dd265d281e1
plugin OTR: fixed a bug which was tagging every message as "encrypted"
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
708 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
709 client.encryption.mark_as_untrusted(data) |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2726
diff
changeset
|
710 |
2128 | 711 return data |
1055 | 712 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
713 def _received_treatment_for_skipped_profiles(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
|
714 """This profile must be skipped because the frontend manages OTR itself, |
2128 | 715 |
716 but we still need to check if the message must be stored in history or not | |
717 """ | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
718 # 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
|
719 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
720 message = ( |
3028 | 721 iter(data["message"].values()).next().encode("utf-8") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
722 ) # 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
|
723 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
724 return data |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
725 if message.startswith(potr.proto.OTRTAG): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
726 # 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
|
727 # bridge |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
728 # 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
|
729 # other frontends |
2132
c0577837680a
core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
730 # 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
|
731 # Hard to avoid with decryption on Libervia though. |
3028 | 732 data["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
|
733 return data |
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
734 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
735 def message_received_trigger(self, client, message_elt, post_treat): |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
736 if client.is_component: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
737 return True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
738 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: |
2128 | 739 # OTR is not possible in group chats |
740 return True | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
741 from_jid = jid.JID(message_elt["from"]) |
2821
3d735e0ab2fa
plugin OTR: ignore messages from sender without resource or from own jid
Goffi <goffi@goffi.org>
parents:
2820
diff
changeset
|
742 if not from_jid.resource or from_jid.userhostJID() == client.jid.userhostJID(): |
3d735e0ab2fa
plugin OTR: ignore messages from sender without resource or from own jid
Goffi <goffi@goffi.org>
parents:
2820
diff
changeset
|
743 # OTR is only usable when resources are present |
3d735e0ab2fa
plugin OTR: ignore messages from sender without resource or from own jid
Goffi <goffi@goffi.org>
parents:
2820
diff
changeset
|
744 return True |
2128 | 745 if client.profile in self.skipped_profiles: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
746 post_treat.addCallback(self._received_treatment_for_skipped_profiles) |
1174
bc811915a96a
plugin OTR: do not save in history the encrypted messages for skipped profiles
souliane <souliane@mailoo.org>
parents:
1171
diff
changeset
|
747 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
748 post_treat.addCallback(self._received_treatment, client) |
1055 | 749 return True |
750 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
751 def _send_message_data_trigger(self, client, mess_data): |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
752 if client.is_component: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
753 return True |
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
|
754 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
755 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
|
756 return |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
757 to_jid = 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
|
758 if not to_jid.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
759 to_jid.resource = self.host.memory.main_resource_get( |
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
|
760 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
|
761 ) # FIXME: temporary and unsecure, must be changed when frontends |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
762 otrctx = client._otr_context_manager.get_context_for_user(to_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
763 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
|
764 if otrctx.state == potr.context.STATE_ENCRYPTED: |
3028 | 765 log.debug("encrypting message") |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
766 body = None |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
767 for child in list(message_elt.children): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
768 if child.name == "body": |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
769 # we remove all unencrypted body, |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
770 # 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
|
771 if body is None: |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
772 body = child |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
773 message_elt.children.remove(child) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
774 elif child.name == "html": |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
775 # 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
|
776 message_elt.children.remove(child) |
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
777 if body is None: |
3028 | 778 log.warning("No message found") |
1168
39572f9d5249
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
1149
diff
changeset
|
779 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
780 self._p_carbons.set_private(message_elt) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
781 self._p_hints.add_hint_elements( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
782 message_elt, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
783 [self._p_hints.HINT_NO_COPY, self._p_hints.HINT_NO_PERMANENT_STORE], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
784 ) |
3028 | 785 otrctx.sendMessage(0, str(body).encode("utf-8"), appdata=mess_data) |
1055 | 786 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
787 feedback = D_( |
3028 | 788 "Your message was not sent because your correspondent closed the " |
789 "encrypted conversation on his/her side. " | |
790 "Either close your own side, or refresh the session." | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
791 ) |
3028 | 792 log.warning(_("Message discarded because closed encryption channel")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
793 client.feedback(to_jid, feedback) |
3028 | 794 raise failure.Failure(exceptions.CancelError("Cancelled by OTR plugin")) |
2128 | 795 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
796 def send_message_trigger( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
797 self, client, mess_data, pre_xml_treatments, post_xml_treatments |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
798 ): |
3795
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
799 if client.is_component: |
967a8e109cda
core (xmpp): adapt message workflow to components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
800 return True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
801 if mess_data["type"] == "groupchat": |
1055 | 802 return True |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
803 |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
804 if client.profile in self.skipped_profiles: |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
805 # FIXME: should not be done on a per-profile basis |
2128 | 806 return True |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
807 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
808 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
|
809 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
|
810 # 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
|
811 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
|
812 |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
813 if not to_jid.resource: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
814 to_jid.resource = self.host.memory.main_resource_get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
815 client, to_jid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
816 ) # FIXME: full jid may not be known |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
817 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
818 otrctx = client._otr_context_manager.get_context_for_user(to_jid) |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
819 |
2138
6e509ee853a8
plugin OTR, core; use of new sendMessage + OTR mini refactoring:
Goffi <goffi@goffi.org>
parents:
2132
diff
changeset
|
820 if otrctx.state != potr.context.STATE_PLAINTEXT: |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
821 defer.ensureDeferred(client.encryption.start(to_jid, NS_OTR)) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
822 client.encryption.set_encryption_flag(mess_data) |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
823 if not mess_data["to"].resource: |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
824 # if not resource was given, we force it here |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
825 mess_data["to"] = to_jid |
2128 | 826 return True |
1055 | 827 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
828 def _presence_received_trigger(self, client, entity, show, priority, statuses): |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1463
diff
changeset
|
829 if show != C.PRESENCE_UNAVAILABLE: |
1249
3be9d8ab2e15
plugin sec_otr: a trigger was not returning True
souliane <souliane@mailoo.org>
parents:
1246
diff
changeset
|
830 return True |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1169
diff
changeset
|
831 if not entity.resource: |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
832 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
833 entity.resource = self.host.memory.main_resource_get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
834 client, entity |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
835 ) # FIXME: temporary and unsecure, must be changed when frontends |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
836 # are refactored |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
837 except exceptions.UnknownEntityError: |
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
838 return True # entity was not connected |
2128 | 839 if entity in client._otr_context_manager.contexts: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3795
diff
changeset
|
840 otrctx = client._otr_context_manager.get_context_for_user(entity) |
1657
62cd8fc1aef7
plugin sec_otr: fixes bad handling of entity disconnection
souliane <souliane@mailoo.org>
parents:
1480
diff
changeset
|
841 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
|
842 return True |