annotate sat/memory/encryption.py @ 2670:ef93fcbaa749

core(twisted): install reactor before doing anything else
author Goffi <goffi@goffi.org>
date Fri, 31 Aug 2018 17:18:51 +0200
parents 4e130cc9bfc0
children e347e32aa07f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
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
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
20 from sat.core.i18n import D_, _
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core import exceptions
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from collections import namedtuple
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.log import getLogger
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 log = getLogger(__name__)
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
26 from sat.tools.common import data_format
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance",
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 "name",
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "namespace",
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
32 "priority",
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
33 "directed"))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 class EncryptionHandler(object):
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 """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
38 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
39
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
40 def __init__(self, client):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
41 self.client = client
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self._sessions = {} # bare_jid ==> encryption_data
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
44 @property
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
45 def host(self):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
46 return self.client.host_app
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
47
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 @classmethod
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
49 def registerPlugin(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
50 """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
51
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @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
53 it must have the following methods:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 - startEncryption(jid.JID): start an encryption session with a bare jid
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 - stopEncryption(jid.JID): stop an encryption session with a bare jid
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
56 @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
57 @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
58 @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
59 selected manually
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
60 @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
61 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
62 """
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
63 existing_ns = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
64 existing_names = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
65 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
66 existing_ns.add(p.namespace.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
67 existing_names.add(p.name.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
68 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
69 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
70 if name.lower() in existing_names:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
71 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
72 plugin = EncryptionPlugin(
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 instance=plg_instance,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 name=name,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 namespace=namespace,
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
76 priority=priority,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
77 directed=directed)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
78 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
79 cls.plugins.sort(key=lambda p: p.priority)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
80 log.info(_(u"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
81
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
82 @classmethod
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
83 def getPlugins(cls):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
84 return cls.plugins
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
85
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
86 @classmethod
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
87 def getNSFromName(cls, name):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
88 """Retrieve plugin namespace from its name
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
89
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
90 @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
91 @return (unicode): namespace of the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
92 @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
93 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
94 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
95 if p.name.lower() == name.lower():
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
96 return p.namespace
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
97 raise exceptions.NotFound
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
99 def getBridgeData(self, session):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
100 """Retrieve session data serialized for bridge.
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
101
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
102 @param session(dict): encryption session
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
103 @return (unicode): serialized data for bridge
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
104 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
105 if session is None:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
106 return u''
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
107 plugin = session[u'plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
108 bridge_data = {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
109 'namespace': plugin.namespace}
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
110 if u'directed_devices' in session:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
111 bridge_data[u'directed_devices'] = session[u'directed_devices']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
112
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
113 return data_format.serialise(bridge_data)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
114
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
115 def start(self, entity, namespace=None, replace=False):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
116 """Start an encryption session with an entity
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
117
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
118 @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
119 must be bare jid is the algorithm encrypt for all devices
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 @param namespace(unicode, None): namespace of the encryption algorithm to use
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 None to select automatically an algorithm
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
122 @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
123 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
124 """
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if not self.plugins:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 raise exceptions.NotFound(_(u"No encryption plugin is registered, "
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 u"an encryption session can't be started"))
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
128
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 if namespace is None:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
130 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
131 else:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 try:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
133 plugin = next(p for p in self.plugins if p.namespace == namespace)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 except StopIteration:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 raise exceptions.NotFound(_(
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 u"Can't find requested encryption plugin: {namespace}").format(
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 namespace=namespace))
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
139 bare_jid = entity.userhostJID()
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
140 if bare_jid in self._sessions:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
141 # we have already an encryption session with this contact
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
142 former_plugin = self._sessions[bare_jid]['plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
143 if former_plugin.namespace == namespace:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
144 log.info(_(u"Session with {bare_jid} is already encrypted with {name}. "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
145 u"Nothing to do.").format(bare_jid=bare_jid, name=plugin.name))
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
146 return
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
147
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
148 if replace:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
149 # there is a conflict, but replacement is requested
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
150 # 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
151 del self._sessions[bare_jid]
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
152 else:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
153 msg = (_(u"Session with {bare_jid} is already encrypted with {name}. "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
154 u"Please stop encryption session before changing algorithm.")
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
155 .format(bare_jid=bare_jid, name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
156 log.warning(msg)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
157 raise exceptions.ConflictError(msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
158
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
159 data = {"plugin": plugin}
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
160 if plugin.directed:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
161 if not entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
162 entity.resource = self.host.memory.getMainResource(self.client, entity)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
163 if not entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
164 raise exceptions.NotFound(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
165 _(u"No resource found for {destinee}, can't encrypt with {name}")
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
166 .format(destinee=entity.full(), name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
167 log.info(_(u"No resource specified to encrypt with {name}, using "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
168 u"{destinee}.").format(destinee=entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
169 name=plugin.name))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 # indicate that we encrypt only for some devices
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
171 directed_devices = data[u'directed_devices'] = [entity.resource]
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
172 elif entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
173 raise ValueError(_(u"{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
174
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 self._sessions[entity.userhostJID()] = data
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
176 log.info(_(u"Encryption session has been set for {entity_jid} with "
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 u"{encryption_name}").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
178 entity_jid=entity.full(), encryption_name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
179 self.host.bridge.messageEncryptionStarted(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
180 entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
181 self.getBridgeData(data),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
182 self.client.profile)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
183 msg = D_(u"Encryption session started: your messages with {destinee} are "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
184 u"now end to end encrypted using {name} algorithm.").format(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
185 destinee=entity.full(), name=plugin.name)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
186 directed_devices = data.get(u'directed_devices')
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
187 if directed_devices:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
188 msg += u"\n" + D_(u"Message are encrypted only for {nb_devices} device(s): "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
189 u"{devices_list}.").format(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
190 nb_devices=len(directed_devices),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
191 devices_list = u', '.join(directed_devices))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
192
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
193 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
194
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
195 def stop(self, entity, namespace=None):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
196 """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
197
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
198 @param entity(jid.JID): entity with who the encryption session must be stopped
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
199 must be bare jid is the algorithm encrypt for all devices
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
200 @param namespace(unicode): namespace of the session to stop
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
201 when specified, used to check we stop the right encryption session
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
202 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
203 session = self.getSession(entity.userhostJID())
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
204 if not session:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
205 raise exceptions.NotFound(_(u"There is no encryption session with this "
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
206 u"entity."))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
207 plugin = session['plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
208 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
209 raise exceptions.InternalError(_(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
210 u"The encryption session is not run with the expected plugin: encrypted "
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
211 u"with {current_name} and was expecting {expected_name}").format(
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
212 current_name=session[u'plugin'].namespace,
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
213 expected_name=namespace))
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
214 if entity.resource:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
215 try:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
216 directed_devices = session[u'directed_devices']
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
217 except KeyError:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
218 raise exceptions.NotFound(_(
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
219 u"There is a session for the whole entity (i.e. all devices of the "
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
220 u"entity), not a directed one. Please use bare jid if you want to "
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
221 u"stop the whole encryption with this entity."))
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
222
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
223 try:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
224 directed_devices.remove(entity.resource)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
225 except ValueError:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
226 raise exceptions.NotFound(_(u"There is no directed session with this "
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
227 u"entity."))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
228 else:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
229 if not directed_devices:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
230 del session[u'directed_devices']
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
231 else:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
232 del self._sessions[entity]
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
233
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
234 log.info(_(u"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
235 entity=entity.full()))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
236 self.host.bridge.messageEncryptionStopped(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
237 entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
238 {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
239 'namespace': plugin.namespace,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
240 },
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
241 self.client.profile)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
242 msg = D_(u"Encryption session finished: your messages with {destinee} are "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
243 u"NOT end to end encrypted anymore.\nYour server administrators or "
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
244 u"{destinee} server administrators will be able to read them.").format(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
245 destinee=entity.full())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
246
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
247 self.client.feedback(entity, msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
248
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
249 def getSession(self, entity):
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
250 """Get encryption session for this contact
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
251
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
252 @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
253 must be a bare jid
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
254 @return (dict, None): encryption session data
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
255 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
256 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
257 if entity.resource:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
258 raise exceptions.InternalError(u"Full jid given when expecting bare jid")
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
259 return self._sessions.get(entity)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
260
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 ## Triggers ##
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 def setEncryptionFlag(self, mess_data):
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 """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
265
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 if mess_data["type"] == "groupchat":
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 # FIXME: to change when group chat encryption will be handled
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 return
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
269
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 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
271 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
272 if encryption is not None:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 mess_data[C.MESS_KEY_ENCRYPTION] = encryption
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
274
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
275 ## Misc ##
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
276
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
277 def markAsEncrypted(self, mess_data):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
278 """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
279
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
280 This should be used in the post_treat workflow of MessageReceived trigger of
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
281 the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
282 @param mess_data(dict): message data as used in post treat workflow
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
283 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
284 mess_data['encrypted'] = True
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
285 return mess_data