annotate libervia/backend/memory/encryption.py @ 4090:e9d800b105c1

cli (event): minor typo
author Goffi <goffi@goffi.org>
date Thu, 08 Jun 2023 21:28:40 +0200
parents 4b842c1fb686
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT: a jabber client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3235
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
20 import copy
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from functools import partial
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
22 from typing import Optional
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
23 from twisted.words.protocols.jabber import jid
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
24 from twisted.internet import defer
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
25 from twisted.python import failure
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
26 from libervia.backend.core.core_types import EncryptionPlugin, EncryptionSession, MessageData
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
27 from libervia.backend.core.i18n import D_, _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
28 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
29 from libervia.backend.core import exceptions
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.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
32 from libervia.backend.tools import utils
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
33 from libervia.backend.memory import persistent
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
34
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
36 log = getLogger(__name__)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
39 class EncryptionHandler:
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 """Class to handle encryption sessions for a client"""
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 plugins = [] # plugin able to encrypt messages
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
43 def __init__(self, client):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
44 self.client = client
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self._sessions = {} # bare_jid ==> encryption_data
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
46 self._stored_session = persistent.PersistentDict(
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
47 "core:encryption", profile=client.profile)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
49 @property
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
50 def host(self):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
51 return self.client.host_app
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
52
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
53 async def load_sessions(self):
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
54 """Load persistent sessions"""
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
55 await self._stored_session.load()
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
56 start_d_list = []
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
57 for entity_jid_s, namespace in self._stored_session.items():
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
58 entity = jid.JID(entity_jid_s)
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
59 start_d_list.append(defer.ensureDeferred(self.start(entity, namespace)))
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
60
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
61 if start_d_list:
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
62 result = await defer.DeferredList(start_d_list)
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
63 for idx, (success, err) in enumerate(result):
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
64 if not success:
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
65 entity_jid_s, namespace = list(self._stored_session.items())[idx]
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
66 log.warning(_(
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
67 "Could not restart {namespace!r} encryption with {entity}: {err}"
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
68 ).format(namespace=namespace, entity=entity_jid_s, err=err))
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
69 log.info(_("encryption sessions restored"))
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
70
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
72 def register_plugin(cls, plg_instance, name, namespace, priority=0, directed=False):
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 """Register a plugin handling an encryption algorithm
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 @param plg_instance(object): instance of the plugin
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 it must have the following methods:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
77 - get_trust_ui(entity): return a XMLUI for trust management
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
78 entity(jid.JID): entity to manage
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
79 The returned XMLUI must be a form
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
80 if may have the following methods:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
81 - start_encryption(entity): start encrypted session
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
82 entity(jid.JID): entity to start encrypted session with
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
83 - stop_encryption(entity): start encrypted session
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
84 entity(jid.JID): entity to stop encrypted session with
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
85 if they don't exists, those 2 methods will be ignored.
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
86
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
87 @param name(unicode): human readable name of the encryption algorithm
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 @param namespace(unicode): namespace of the encryption algorithm
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 @param priority(int): priority of this plugin to encrypt an message when not
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 selected manually
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
91 @param directed(bool): True if this plugin is directed (if it works with one
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
92 device only at a time)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 """
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
94 existing_ns = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
95 existing_names = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
96 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
97 existing_ns.add(p.namespace.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
98 existing_names.add(p.name.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
99 if namespace.lower() in existing_ns:
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 raise exceptions.ConflictError("A plugin with this namespace already exists!")
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
101 if name.lower() in existing_names:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
102 raise exceptions.ConflictError("A plugin with this name already exists!")
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
103 plugin = EncryptionPlugin(
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 instance=plg_instance,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 name=name,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 namespace=namespace,
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
107 priority=priority,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
108 directed=directed)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
109 cls.plugins.append(plugin)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 cls.plugins.sort(key=lambda p: p.priority)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
111 log.info(_("Encryption plugin registered: {name}").format(name=name))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
113 @classmethod
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
114 def getPlugins(cls):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
115 return cls.plugins
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
116
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
117 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
118 def get_plugin(cls, namespace):
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
119 try:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
120 return next(p for p in cls.plugins if p.namespace == namespace)
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
121 except StopIteration:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
122 raise exceptions.NotFound(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
123 "Can't find requested encryption plugin: {namespace}").format(
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
124 namespace=namespace))
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
125
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
126 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
127 def get_namespaces(cls):
2749
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
128 """Get available plugin namespaces"""
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
129 return {p.namespace for p in cls.getPlugins()}
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
130
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
131 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
132 def get_ns_from_name(cls, name):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
133 """Retrieve plugin namespace from its name
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
134
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
135 @param name(unicode): name of the plugin (case insensitive)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
136 @return (unicode): namespace of the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
137 @raise exceptions.NotFound: there is not encryption plugin of this name
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
138 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
139 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
140 if p.name.lower() == name.lower():
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
141 return p.namespace
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
142 raise exceptions.NotFound(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
143 "Can't find a plugin with the name \"{name}\".".format(
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
144 name=name)))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
145
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
146 def get_bridge_data(self, session):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
147 """Retrieve session data serialized for bridge.
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
148
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
149 @param session(dict): encryption session
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
150 @return (unicode): serialized data for bridge
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
151 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
152 if session is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
153 return ''
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
154 plugin = session['plugin']
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
155 bridge_data = {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
156 'namespace': plugin.namespace}
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
157 if 'directed_devices' in session:
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
158 bridge_data['directed_devices'] = session['directed_devices']
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
159
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
160 return data_format.serialise(bridge_data)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
161
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
162 async def _start_encryption(self, plugin, entity):
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
163 """Start encryption with a plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
164
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
165 This method must be called just before adding a plugin session.
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
166 StartEncryptionn method of plugin will be called if it exists.
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
167 """
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
168 if not plugin.directed:
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
169 await self._stored_session.aset(entity.userhost(), plugin.namespace)
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
170 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
171 start_encryption = plugin.instance.start_encryption
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
172 except AttributeError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
173 log.debug(f"No start_encryption method found for {plugin.namespace}")
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
174 else:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
175 # we copy entity to avoid having the resource changed by stop_encryption
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
176 await utils.as_deferred(start_encryption, self.client, copy.copy(entity))
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
177
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
178 async def _stop_encryption(self, plugin, entity):
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
179 """Stop encryption with a plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
180
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
181 This method must be called just before removing a plugin session.
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
182 StopEncryptionn method of plugin will be called if it exists.
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
183 """
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
184 try:
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
185 await self._stored_session.adel(entity.userhost())
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
186 except KeyError:
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
187 pass
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
188 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
189 stop_encryption = plugin.instance.stop_encryption
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
190 except AttributeError:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
191 log.debug(f"No stop_encryption method found for {plugin.namespace}")
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
192 else:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
193 # we copy entity to avoid having the resource changed by stop_encryption
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
194 return utils.as_deferred(stop_encryption, self.client, copy.copy(entity))
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
195
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
196 async def start(self, entity, namespace=None, replace=False):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
197 """Start an encryption session with an entity
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
198
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
199 @param entity(jid.JID): entity to start an encryption session with
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 must be bare jid is the algorithm encrypt for all devices
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
201 @param namespace(unicode, None): namespace of the encryption algorithm
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
202 to use.
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 None to select automatically an algorithm
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
204 @param replace(bool): if True and an encrypted session already exists,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
205 it will be replaced by the new one
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 """
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 if not self.plugins:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
208 raise exceptions.NotFound(_("No encryption plugin is registered, "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
209 "an encryption session can't be started"))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
210
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 if namespace is None:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
212 plugin = self.plugins[0]
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
214 plugin = self.get_plugin(namespace)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
215
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
216 bare_jid = entity.userhostJID()
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
217 if bare_jid in self._sessions:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
218 # we have already an encryption session with this contact
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
219 former_plugin = self._sessions[bare_jid]["plugin"]
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
220 if former_plugin.namespace == namespace:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
221 log.info(_("Session with {bare_jid} is already encrypted with {name}. "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
222 "Nothing to do.").format(
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
223 bare_jid=bare_jid, name=former_plugin.name))
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
224 return
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
225
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
226 if replace:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
227 # there is a conflict, but replacement is requested
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
228 # so we stop previous encryption to use new one
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
229 del self._sessions[bare_jid]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
230 await self._stop_encryption(former_plugin, entity)
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
231 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
232 msg = (_("Session with {bare_jid} is already encrypted with {name}. "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
233 "Please stop encryption session before changing algorithm.")
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
234 .format(bare_jid=bare_jid, name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
235 log.warning(msg)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
236 raise exceptions.ConflictError(msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
237
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
238 data = {"plugin": plugin}
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
239 if plugin.directed:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
240 if not entity.resource:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
241 entity.resource = self.host.memory.main_resource_get(self.client, entity)
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
242 if not entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
243 raise exceptions.NotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
244 _("No resource found for {destinee}, can't encrypt with {name}")
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
245 .format(destinee=entity.full(), name=plugin.name))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
246 log.info(_("No resource specified to encrypt with {name}, using "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
247 "{destinee}.").format(destinee=entity.full(),
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
248 name=plugin.name))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 # indicate that we encrypt only for some devices
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
250 directed_devices = data['directed_devices'] = [entity.resource]
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
251 elif entity.resource:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
252 raise ValueError(_("{name} encryption must be used with bare jids."))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
253
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
254 await self._start_encryption(plugin, entity)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 self._sessions[entity.userhostJID()] = data
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
256 log.info(_("Encryption session has been set for {entity_jid} with "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
257 "{encryption_name}").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
258 entity_jid=entity.full(), encryption_name=plugin.name))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
259 self.host.bridge.message_encryption_started(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
260 entity.full(),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
261 self.get_bridge_data(data),
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
262 self.client.profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
263 msg = D_("Encryption session started: your messages with {destinee} are "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
264 "now end to end encrypted using {name} algorithm.").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
265 destinee=entity.full(), name=plugin.name)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
266 directed_devices = data.get('directed_devices')
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
267 if directed_devices:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
268 msg += "\n" + D_("Message are encrypted only for {nb_devices} device(s): "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
269 "{devices_list}.").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
270 nb_devices=len(directed_devices),
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
271 devices_list = ', '.join(directed_devices))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
272
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
273 self.client.feedback(bare_jid, msg)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
274
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
275 async def stop(self, entity, namespace=None):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
276 """Stop an encryption session with an entity
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
277
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
278 @param entity(jid.JID): entity with who the encryption session must be stopped
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
279 must be bare jid if the algorithm encrypt for all devices
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
280 @param namespace(unicode): namespace of the session to stop
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
281 when specified, used to check that we stop the right encryption session
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
282 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
283 session = self.getSession(entity.userhostJID())
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
284 if not session:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
285 raise failure.Failure(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
286 exceptions.NotFound(_("There is no encryption session with this "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
287 "entity.")))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
288 plugin = session['plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
289 if namespace is not None and plugin.namespace != namespace:
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
290 raise exceptions.InternalError(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
291 "The encryption session is not run with the expected plugin: encrypted "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
292 "with {current_name} and was expecting {expected_name}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
293 current_name=session['plugin'].namespace,
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
294 expected_name=namespace))
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
295 if entity.resource:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
296 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
297 directed_devices = session['directed_devices']
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
298 except KeyError:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
299 raise exceptions.NotFound(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
300 "There is a session for the whole entity (i.e. all devices of the "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
301 "entity), not a directed one. Please use bare jid if you want to "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
302 "stop the whole encryption with this entity."))
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
303
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
304 try:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
305 directed_devices.remove(entity.resource)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
306 except ValueError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
307 raise exceptions.NotFound(_("There is no directed session with this "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
308 "entity."))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
309 else:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
310 if not directed_devices:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
311 # if we have no more directed device sessions,
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
312 # we stop the whole session
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
313 # see comment below for deleting session before stopping encryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
314 del self._sessions[entity.userhostJID()]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
315 await self._stop_encryption(plugin, entity)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
316 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
317 # plugin's stop_encryption may call stop again (that's the case with OTR)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
318 # so we need to remove plugin from session before calling self._stop_encryption
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
319 del self._sessions[entity.userhostJID()]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
320 await self._stop_encryption(plugin, entity)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
321
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
322 log.info(_("encryption session stopped with entity {entity}").format(
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
323 entity=entity.full()))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
324 self.host.bridge.message_encryption_stopped(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
325 entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
326 {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
327 'namespace': plugin.namespace,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
328 },
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
329 self.client.profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
330 msg = D_("Encryption session finished: your messages with {destinee} are "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
331 "NOT end to end encrypted anymore.\nYour server administrators or "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
332 "{destinee} server administrators will be able to read them.").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
333 destinee=entity.full())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
334
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
335 self.client.feedback(entity, msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
336
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
337 def getSession(self, entity: jid.JID) -> Optional[EncryptionSession]:
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
338 """Get encryption session for this contact
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
339
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
340 @param entity(jid.JID): get the session for this entity
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
341 must be a bare jid
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
342 @return (dict, None): encryption session data
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
343 None if there is not encryption for this session with this jid
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
344 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
345 if entity.resource:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
346 raise ValueError("Full jid given when expecting bare jid")
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
347 return self._sessions.get(entity)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
348
3921
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
349 def get_namespace(self, entity: jid.JID) -> Optional[str]:
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
350 """Helper method to get the current encryption namespace used
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
351
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
352 @param entity: get the namespace for this entity must be a bare jid
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
353 @return: the algorithm namespace currently used in this session, or None if no
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
354 e2ee is currently used.
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
355 """
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
356 session = self.getSession(entity)
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
357 if session is None:
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
358 return None
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
359 return session["plugin"].namespace
cc2705225778 core (memory/encryption): helper method to get currently utilised e2ee algorithm's namespace:
Goffi <goffi@goffi.org>
parents: 3911
diff changeset
360
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
361 def get_trust_ui(self, entity_jid, namespace=None):
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
362 """Retrieve encryption UI
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
363
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
364 @param entity_jid(jid.JID): get the UI for this entity
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
365 must be a bare jid
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
366 @param namespace(unicode): namespace of the algorithm to manage
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
367 if None use current algorithm
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
368 @return D(xmlui): XMLUI for trust management
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
369 the xmlui is a form
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
370 None if there is not encryption for this session with this jid
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
371 @raise exceptions.NotFound: no algorithm/plugin found
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
372 @raise NotImplementedError: plugin doesn't handle UI management
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
373 """
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
374 if namespace is None:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
375 session = self.getSession(entity_jid)
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
376 if not session:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
377 raise exceptions.NotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
378 "No encryption session currently active for {entity_jid}"
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
379 .format(entity_jid=entity_jid.full()))
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
380 plugin = session['plugin']
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
381 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
382 plugin = self.get_plugin(namespace)
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
383 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
384 get_trust_ui = plugin.instance.get_trust_ui
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
385 except AttributeError:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
386 raise NotImplementedError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
387 "Encryption plugin doesn't handle trust management UI")
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
388 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
389 return utils.as_deferred(get_trust_ui, self.client, entity_jid)
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
390
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
391 ## Menus ##
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
392
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
393 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
394 def _import_menus(cls, host):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
395 host.import_menu(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
396 (D_("Encryption"), D_("unencrypted (plain text)")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
397 partial(cls._on_menu_unencrypted, host=host),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
398 security_limit=0,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
399 help_string=D_("End encrypted session"),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
400 type_=C.MENU_SINGLE,
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
401 )
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
402 for plg in cls.getPlugins():
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
403 host.import_menu(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
404 (D_("Encryption"), plg.name),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
405 partial(cls._on_menu_name, host=host, plg=plg),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
406 security_limit=0,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
407 help_string=D_("Start {name} session").format(name=plg.name),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
408 type_=C.MENU_SINGLE,
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
409 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
410 host.import_menu(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
411 (D_("Encryption"), D_("⛨ {name} trust").format(name=plg.name)),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
412 partial(cls._on_menu_trust, host=host, plg=plg),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
413 security_limit=0,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
414 help_string=D_("Manage {name} trust").format(name=plg.name),
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
415 type_=C.MENU_SINGLE,
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
416 )
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
417
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
418 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
419 def _on_menu_unencrypted(cls, data, host, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
420 client = host.get_client(profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
421 peer_jid = jid.JID(data['jid']).userhostJID()
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
422 d = defer.ensureDeferred(client.encryption.stop(peer_jid))
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
423 d.addCallback(lambda __: {})
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
424 return d
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
425
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
426 @classmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
427 def _on_menu_name(cls, data, host, plg, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
428 client = host.get_client(profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
429 peer_jid = jid.JID(data['jid'])
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
430 if not plg.directed:
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
431 peer_jid = peer_jid.userhostJID()
3226
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
432 d = defer.ensureDeferred(
2f406b762788 core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents: 3217
diff changeset
433 client.encryption.start(peer_jid, plg.namespace, replace=True))
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
434 d.addCallback(lambda __: {})
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
435 return d
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
436
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
437 @classmethod
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
438 @defer.inlineCallbacks
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
439 def _on_menu_trust(cls, data, host, plg, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
440 client = host.get_client(profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
441 peer_jid = jid.JID(data['jid']).userhostJID()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
442 ui = yield client.encryption.get_trust_ui(peer_jid, plg.namespace)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2810
diff changeset
443 defer.returnValue({'xmlui': ui.toXml()})
2810
c161a294fffd core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
444
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
445 ## Triggers ##
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
446
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
447 def set_encryption_flag(self, mess_data):
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
448 """Set "encryption" key in mess_data if session with destinee is encrypted"""
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 to_jid = mess_data['to']
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
450 encryption = self._sessions.get(to_jid.userhostJID())
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
451 if encryption is not None:
3231
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
452 plugin = encryption['plugin']
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
453 if mess_data["type"] == "groupchat" and plugin.directed:
3104
118d91c932a7 plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
454 raise exceptions.InternalError(
118d91c932a7 plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
455 f"encryption flag must not be set for groupchat if encryption algorithm "
118d91c932a7 plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
456 f"({encryption['plugin'].name}) is directed!")
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
457 mess_data[C.MESS_KEY_ENCRYPTION] = encryption
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
458 self.mark_as_encrypted(mess_data, plugin.namespace)
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
459
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
460 ## Misc ##
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
461
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
462 def mark_as_encrypted(self, mess_data, namespace):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
463 """Helper method to mark a message as having been e2e encrypted.
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
464
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
465 This should be used in the post_treat workflow of message_received trigger of
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
466 the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
467 @param mess_data(dict): message data as used in post treat workflow
3231
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
468 @param namespace(str): namespace of the algorithm used for encrypting the message
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
469 """
3228
cc3fea71c365 core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
Goffi <goffi@goffi.org>
parents: 3226
diff changeset
470 mess_data['extra'][C.MESS_KEY_ENCRYPTED] = True
3231
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
471 from_bare_jid = mess_data['from'].userhostJID()
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
472 if from_bare_jid != self.client.jid.userhostJID():
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
473 session = self.getSession(from_bare_jid)
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
474 if session is None:
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
475 # if we are currently unencrypted, we start a session automatically
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
476 # to avoid sending unencrypted messages in an encrypted context
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
477 log.info(_(
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
478 "Starting e2e session with {peer_jid} as we receive encrypted "
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
479 "messages")
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
480 .format(peer_jid=from_bare_jid)
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
481 )
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
482 defer.ensureDeferred(self.start(from_bare_jid, namespace))
e756e0eb1be4 core (memory/encryption): automatic start encryption if peer send encrypted message:
Goffi <goffi@goffi.org>
parents: 3228
diff changeset
483
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
484 return mess_data
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
485
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
486 def is_encryption_requested(
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
487 self,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
488 mess_data: MessageData,
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
489 namespace: Optional[str] = None
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
490 ) -> bool:
3180
826bca181226 core (memory/encryption): "isEncryptionRequested" helper method:
Goffi <goffi@goffi.org>
parents: 3171
diff changeset
491 """Helper method to check if encryption is requested in an outgoind message
826bca181226 core (memory/encryption): "isEncryptionRequested" helper method:
Goffi <goffi@goffi.org>
parents: 3171
diff changeset
492
3911
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
493 @param mess_data: message data for outgoing message
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
494 @param namespace: if set, check if encryption is requested for the algorithm
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
495 specified
8289ac1b34f4 plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents: 3479
diff changeset
496 @return: True if the encryption flag is present
3180
826bca181226 core (memory/encryption): "isEncryptionRequested" helper method:
Goffi <goffi@goffi.org>
parents: 3171
diff changeset
497 """
3217
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
498 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
499 if encryption is None:
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
500 return False
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
501 # we get plugin even if namespace is None to be sure that the key exists
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
502 plugin = encryption['plugin']
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
503 if namespace is None:
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
504 return True
0469c53ed5dd core (memory/encryption): namespace can now be specified to test a specific algorithm in isEncryptionRequested
Goffi <goffi@goffi.org>
parents: 3180
diff changeset
505 return plugin.namespace == namespace
3180
826bca181226 core (memory/encryption): "isEncryptionRequested" helper method:
Goffi <goffi@goffi.org>
parents: 3171
diff changeset
506
3171
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
507 def isEncrypted(self, mess_data):
3228
cc3fea71c365 core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
Goffi <goffi@goffi.org>
parents: 3226
diff changeset
508 """Helper method to check if a message has the e2e encrypted flag
3171
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
509
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
510 @param mess_data(dict): message data
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
511 @return (bool): True if the encrypted flag is present
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
512 """
3228
cc3fea71c365 core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
Goffi <goffi@goffi.org>
parents: 3226
diff changeset
513 return mess_data['extra'].get(C.MESS_KEY_ENCRYPTED, False)
3171
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
514
d073d82d9044 core (memory/encryption): new "isEncrypted" method to check if encrypted flag is set in message data
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
515
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
516 def mark_as_trusted(self, mess_data):
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
517 """Helper methor to mark a message as sent from a trusted entity.
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
518
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
519 This should be used in the post_treat workflow of message_received trigger of
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
520 the plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
521 @param mess_data(dict): message data as used in post treat workflow
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
522 """
2752
1fa615faec8b core (constants): added a constant for "encrypted"
Goffi <goffi@goffi.org>
parents: 2749
diff changeset
523 mess_data[C.MESS_KEY_TRUSTED] = True
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
524 return mess_data
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
525
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3921
diff changeset
526 def mark_as_untrusted(self, mess_data):
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
527 """Helper methor to mark a message as sent from an untrusted entity.
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
528
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
529 This should be used in the post_treat workflow of message_received trigger of
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
530 the plugin
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
531 @param mess_data(dict): message data as used in post treat workflow
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
532 """
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
533 mess_data['trusted'] = False
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
534 return mess_data