annotate sat/memory/encryption.py @ 2795:25639611c303

plugin XEP-0198: fixed typo resulting in a crash on resume
author Goffi <goffi@goffi.org>
date Sat, 26 Jan 2019 20:08:33 +0100
parents 003b8b4b56a7
children c161a294fffd
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2752
diff changeset
5 # Copyright (C) 2009-2019 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
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
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
25 from sat.tools.common import data_format
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
26 from twisted.internet import defer
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
27 from twisted.python import failure
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
28 import copy
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 log = getLogger(__name__)
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
31 log = getLogger(__name__)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance",
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 "name",
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 "namespace",
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
36 "priority",
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
37 "directed"))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 class EncryptionHandler(object):
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """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
42 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
43
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
44 def __init__(self, client):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
45 self.client = client
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 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
47
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
48 @property
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
49 def host(self):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
50 return self.client.host_app
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
51
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @classmethod
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
53 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
54 """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
55
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 @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
57 it must have the following methods:
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
58 - getTrustUI(entity): return a XMLUI for trust management
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
59 entity(jid.JID): entity to manage
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
60 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
61 if may have the following methods:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
62 - startEncryption(entity): start encrypted session
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
63 entity(jid.JID): entity to start encrypted session with
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
64 - stopEncryption(entity): start encrypted session
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
65 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
66 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
67
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
68 @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
69 @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
70 @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
71 selected manually
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
72 @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
73 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
74 """
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
75 existing_ns = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
76 existing_names = set()
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
77 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
78 existing_ns.add(p.namespace.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
79 existing_names.add(p.name.lower())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
80 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
81 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
82 if name.lower() in existing_names:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
83 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
84 plugin = EncryptionPlugin(
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 instance=plg_instance,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 name=name,
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 namespace=namespace,
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
88 priority=priority,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
89 directed=directed)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
90 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
91 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
92 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
93
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
94 @classmethod
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
95 def getPlugins(cls):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
96 return cls.plugins
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
97
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
98 @classmethod
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
99 def getPlugin(cls, namespace):
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
100 try:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
101 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
102 except StopIteration:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
103 raise exceptions.NotFound(_(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
104 u"Can't find requested encryption plugin: {namespace}").format(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
105 namespace=namespace))
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
106
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
107 @classmethod
2749
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
108 def getNamespaces(cls):
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
109 """Get available plugin namespaces"""
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
110 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
111
4b8271399f67 core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents: 2743
diff changeset
112 @classmethod
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
113 def getNSFromName(cls, name):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
114 """Retrieve plugin namespace from its name
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
115
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
116 @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
117 @return (unicode): namespace of the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
118 @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
119 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
120 for p in cls.plugins:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
121 if p.name.lower() == name.lower():
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
122 return p.namespace
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
123 raise exceptions.NotFound(_(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
124 u"Can't find a plugin with the name \"{name}\".".format(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
125 name=name)))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
127 def getBridgeData(self, session):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
128 """Retrieve session data serialized for bridge.
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
129
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
130 @param session(dict): encryption session
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
131 @return (unicode): serialized data for bridge
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
132 """
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
133 if session is None:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
134 return u''
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
135 plugin = session[u'plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
136 bridge_data = {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
137 'namespace': plugin.namespace}
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
138 if u'directed_devices' in session:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
139 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
140
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
141 return data_format.serialise(bridge_data)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
142
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
143 def _startEncryption(self, plugin, entity):
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
144 """Start encryption with a plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
145
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
146 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
147 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
148 """
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
149 try:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
150 start_encryption = plugin.instance.startEncryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
151 except AttributeError:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
152 log.debug(u"No startEncryption method found for {plugin}".format(
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
153 plugin = plugin.namespace))
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
154 return defer.succeed(None)
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
155 else:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
156 # we copy entity to avoid having the resource changed by stop_encryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
157 return defer.maybeDeferred(start_encryption, self.client, copy.copy(entity))
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
158
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
159 def _stopEncryption(self, plugin, entity):
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
160 """Stop encryption with a plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
161
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
162 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
163 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
164 """
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
165 try:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
166 stop_encryption = plugin.instance.stopEncryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
167 except AttributeError:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
168 log.debug(u"No stopEncryption method found for {plugin}".format(
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
169 plugin = plugin.namespace))
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
170 return defer.succeed(None)
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
171 else:
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
172 # we copy entity to avoid having the resource changed by stop_encryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
173 return defer.maybeDeferred(stop_encryption, self.client, copy.copy(entity))
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
174
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
175 @defer.inlineCallbacks
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
176 def start(self, entity, namespace=None, replace=False):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
177 """Start an encryption session with an entity
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
178
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
179 @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
180 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
181 @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
182 to use.
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 None to select automatically an algorithm
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
184 @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
185 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
186 """
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 if not self.plugins:
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 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
189 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
190
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if namespace is None:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
192 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
193 else:
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
194 plugin = self.getPlugin(namespace)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
195
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
196 bare_jid = entity.userhostJID()
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
197 if bare_jid in self._sessions:
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
198 # we have already an encryption session with this contact
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
199 former_plugin = self._sessions[bare_jid][u"plugin"]
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
200 if former_plugin.namespace == namespace:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
201 log.info(_(u"Session with {bare_jid} is already encrypted with {name}. "
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
202 u"Nothing to do.").format(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
203 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
204 return
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
205
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
206 if replace:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
207 # there is a conflict, but replacement is requested
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
208 # 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
209 del self._sessions[bare_jid]
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
210 yield self._stopEncryption(former_plugin, entity)
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
211 else:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
212 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
213 u"Please stop encryption session before changing algorithm.")
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
214 .format(bare_jid=bare_jid, name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
215 log.warning(msg)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
216 raise exceptions.ConflictError(msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
217
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
218 data = {"plugin": plugin}
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
219 if plugin.directed:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
220 if not entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
221 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
222 if not entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
223 raise exceptions.NotFound(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
224 _(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
225 .format(destinee=entity.full(), name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
226 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
227 u"{destinee}.").format(destinee=entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
228 name=plugin.name))
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 # 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
230 directed_devices = data[u'directed_devices'] = [entity.resource]
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
231 elif entity.resource:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
232 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
233
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
234 yield self._startEncryption(plugin, entity)
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 self._sessions[entity.userhostJID()] = data
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
236 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
237 u"{encryption_name}").format(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
238 entity_jid=entity.full(), encryption_name=plugin.name))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
239 self.host.bridge.messageEncryptionStarted(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
240 entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
241 self.getBridgeData(data),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
242 self.client.profile)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
243 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
244 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
245 destinee=entity.full(), name=plugin.name)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
246 directed_devices = data.get(u'directed_devices')
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
247 if directed_devices:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
248 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
249 u"{devices_list}.").format(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
250 nb_devices=len(directed_devices),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
251 devices_list = u', '.join(directed_devices))
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
252
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
253 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
254
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
255 @defer.inlineCallbacks
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
256 def stop(self, entity, namespace=None):
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
257 """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
258
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
259 @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
260 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
261 @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
262 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
263 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
264 session = self.getSession(entity.userhostJID())
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
265 if not session:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
266 raise failure.Failure(
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
267 exceptions.NotFound(_(u"There is no encryption session with this "
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
268 u"entity.")))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
269 plugin = session['plugin']
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
270 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
271 raise exceptions.InternalError(_(
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
272 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
273 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
274 current_name=session[u'plugin'].namespace,
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
275 expected_name=namespace))
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
276 if entity.resource:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
277 try:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
278 directed_devices = session[u'directed_devices']
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
279 except KeyError:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
280 raise exceptions.NotFound(_(
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
281 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
282 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
283 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
284
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
285 try:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
286 directed_devices.remove(entity.resource)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
287 except ValueError:
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
288 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
289 u"entity."))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
290 else:
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
291 if not directed_devices:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
292 # 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
293 # we stop the whole session
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
294 # 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
295 del self._sessions[entity.userhostJID()]
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
296 yield self._stopEncryption(plugin, entity)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
297 else:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
298 # plugin's stopEncryption may call stop again (that's the case with OTR)
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
299 # so we need to remove plugin from session before calling self._stopEncryption
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
300 del self._sessions[entity.userhostJID()]
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
301 yield self._stopEncryption(plugin, entity)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
302
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
303 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
304 entity=entity.full()))
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
305 self.host.bridge.messageEncryptionStopped(
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
306 entity.full(),
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
307 {'name': plugin.name,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
308 'namespace': plugin.namespace,
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
309 },
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
310 self.client.profile)
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
311 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
312 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
313 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
314 destinee=entity.full())
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
315
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
316 self.client.feedback(entity, msg)
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
317
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
318 def getSession(self, entity):
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
319 """Get encryption session for this contact
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
320
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
321 @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
322 must be a bare jid
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
323 @return (dict, None): encryption session data
2651
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
324 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
325 """
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
326 if entity.resource:
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
327 raise ValueError(u"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
328 return self._sessions.get(entity)
ebcff5423465 core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents: 2646
diff changeset
329
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
330 def getTrustUI(self, entity_jid, namespace=None):
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
331 """Retrieve encryption UI
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
332
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
333 @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
334 must be a bare jid
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
335 @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
336 if None use current algorithm
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
337 @return D(xmlui): XMLUI for trust management
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
338 the xmlui is a form
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
339 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
340 @raise exceptions.NotFound: no algorithm/plugin found
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
341 @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
342 """
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
343 if namespace is None:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
344 session = self.getSession(entity_jid)
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
345 if not session:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
346 raise exceptions.NotFound(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
347 u"No encryption session currently active for {entity_jid}"
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
348 .format(entity_jid=entity_jid.full()))
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
349 plugin = session['plugin']
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
350 else:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
351 plugin = self.getPlugin(namespace)
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
352 try:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
353 get_trust_ui = plugin.instance.getTrustUI
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
354 except AttributeError:
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
355 raise NotImplementedError(
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
356 u"Encryption plugin doesn't handle trust management UI")
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
357 else:
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
358 return defer.maybeDeferred(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
359
2646
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 ## Triggers ##
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
361
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 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
363 """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
364
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 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
366 # 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
367 return
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
368
712cb4ff3e13 core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 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
370 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
371 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
372 mess_data[C.MESS_KEY_ENCRYPTION] = encryption
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
373
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
374 ## Misc ##
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
375
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
376 def markAsEncrypted(self, mess_data):
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
377 """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
378
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
379 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
380 the plugin
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
381 @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
382 """
2752
1fa615faec8b core (constants): added a constant for "encrypted"
Goffi <goffi@goffi.org>
parents: 2749
diff changeset
383 mess_data[C.MESS_KEY_ENCRYPTED] = True
2658
4e130cc9bfc0 core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents: 2651
diff changeset
384 return mess_data
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
385
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
386 def markAsTrusted(self, mess_data):
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
387 """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
388
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
389 This should be used in the post_treat workflow of MessageReceived trigger of
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
390 the plugin
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
391 @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
392 """
2752
1fa615faec8b core (constants): added a constant for "encrypted"
Goffi <goffi@goffi.org>
parents: 2749
diff changeset
393 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
394 return mess_data
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
395
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
396 def markAsUntrusted(self, mess_data):
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
397 """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
398
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
399 This should be used in the post_treat workflow of MessageReceived trigger of
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
400 the plugin
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
401 @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
402 """
2743
da59ff099b32 core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents: 2733
diff changeset
403 mess_data['trusted'] = False
2733
e347e32aa07f core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents: 2658
diff changeset
404 return mess_data