Mercurial > libervia-backend
annotate sat/memory/encryption.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | c161a294fffd |
children | 118d91c932a7 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
2646
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 | 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 |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
20 from functools import partial |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 from collections import namedtuple |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 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
|
26 from sat.tools.common import data_format |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
27 from twisted.words.protocols.jabber import jid |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
28 from twisted.internet import defer |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
29 from twisted.python import failure |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
30 import copy |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 log = getLogger(__name__) |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
33 log = getLogger(__name__) |
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 EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance", |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 "name", |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "namespace", |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
38 "priority", |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
39 "directed")) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 class EncryptionHandler(object): |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 """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
|
44 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
|
45 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
46 def __init__(self, client): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
47 self.client = client |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 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
|
49 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
50 @property |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
51 def host(self): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
52 return self.client.host_app |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
53 |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 @classmethod |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
55 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
|
56 """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
|
57 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 @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
|
59 it must have the following methods: |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
60 - 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
|
61 entity(jid.JID): entity to manage |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
62 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
|
63 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
|
64 - startEncryption(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 start encrypted session with |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
66 - stopEncryption(entity): start encrypted session |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
67 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
|
68 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
|
69 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
70 @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
|
71 @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
|
72 @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
|
73 selected manually |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
74 @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
|
75 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
|
76 """ |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
77 existing_ns = set() |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
78 existing_names = set() |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
79 for p in cls.plugins: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
80 existing_ns.add(p.namespace.lower()) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
81 existing_names.add(p.name.lower()) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
82 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
|
83 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
|
84 if name.lower() in existing_names: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
85 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
|
86 plugin = EncryptionPlugin( |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 instance=plg_instance, |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 name=name, |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 namespace=namespace, |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
90 priority=priority, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
91 directed=directed) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
92 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
|
93 cls.plugins.sort(key=lambda p: p.priority) |
3028 | 94 log.info(_("Encryption plugin registered: {name}").format(name=name)) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
96 @classmethod |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
97 def getPlugins(cls): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
98 return cls.plugins |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
99 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
100 @classmethod |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
101 def getPlugin(cls, namespace): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
102 try: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
103 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
|
104 except StopIteration: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
105 raise exceptions.NotFound(_( |
3028 | 106 "Can't find requested encryption plugin: {namespace}").format( |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
107 namespace=namespace)) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
108 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
109 @classmethod |
2749
4b8271399f67
core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
110 def getNamespaces(cls): |
4b8271399f67
core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
111 """Get available plugin namespaces""" |
4b8271399f67
core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
112 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
|
113 |
4b8271399f67
core (memory/encryption): added getNamespaces method to retrieve all plugins namespaces
Goffi <goffi@goffi.org>
parents:
2743
diff
changeset
|
114 @classmethod |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
115 def getNSFromName(cls, name): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
116 """Retrieve plugin namespace from its name |
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 name(unicode): name of the plugin (case insensitive) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
119 @return (unicode): namespace of the plugin |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
120 @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
|
121 """ |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
122 for p in cls.plugins: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
123 if p.name.lower() == name.lower(): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
124 return p.namespace |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
125 raise exceptions.NotFound(_( |
3028 | 126 "Can't find a plugin with the name \"{name}\".".format( |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
127 name=name))) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
129 def getBridgeData(self, session): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
130 """Retrieve session data serialized for bridge. |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
131 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
132 @param session(dict): encryption session |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
133 @return (unicode): serialized data for bridge |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
134 """ |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
135 if session is None: |
3028 | 136 return '' |
137 plugin = session['plugin'] | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
138 bridge_data = {'name': plugin.name, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
139 'namespace': plugin.namespace} |
3028 | 140 if 'directed_devices' in session: |
141 bridge_data['directed_devices'] = session['directed_devices'] | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
142 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
143 return data_format.serialise(bridge_data) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
144 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
145 def _startEncryption(self, plugin, entity): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
146 """Start encryption with a plugin |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
147 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
148 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
|
149 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
|
150 """ |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
151 try: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
152 start_encryption = plugin.instance.startEncryption |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
153 except AttributeError: |
3028 | 154 log.debug("No startEncryption method found for {plugin}".format( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
155 plugin = plugin.namespace)) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
156 return defer.succeed(None) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
157 else: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
158 # 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
|
159 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
|
160 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
161 def _stopEncryption(self, plugin, entity): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
162 """Stop encryption with a plugin |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
163 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
164 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
|
165 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
|
166 """ |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
167 try: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
168 stop_encryption = plugin.instance.stopEncryption |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
169 except AttributeError: |
3028 | 170 log.debug("No stopEncryption method found for {plugin}".format( |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
171 plugin = plugin.namespace)) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
172 return defer.succeed(None) |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
173 else: |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
174 # 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
|
175 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
|
176 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
177 @defer.inlineCallbacks |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
178 def start(self, entity, namespace=None, replace=False): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
179 """Start an encryption session with an entity |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
180 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
181 @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
|
182 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
|
183 @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
|
184 to use. |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 None to select automatically an algorithm |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
186 @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
|
187 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
|
188 """ |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 if not self.plugins: |
3028 | 190 raise exceptions.NotFound(_("No encryption plugin is registered, " |
191 "an encryption session can't be started")) | |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 if namespace is None: |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
194 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
|
195 else: |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
196 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
|
197 |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
198 bare_jid = entity.userhostJID() |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
199 if bare_jid in self._sessions: |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
200 # we have already an encryption session with this contact |
3028 | 201 former_plugin = self._sessions[bare_jid]["plugin"] |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
202 if former_plugin.namespace == namespace: |
3028 | 203 log.info(_("Session with {bare_jid} is already encrypted with {name}. " |
204 "Nothing to do.").format( | |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
205 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
|
206 return |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
207 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
208 if replace: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
209 # there is a conflict, but replacement is requested |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
210 # 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
|
211 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
|
212 yield self._stopEncryption(former_plugin, entity) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
213 else: |
3028 | 214 msg = (_("Session with {bare_jid} is already encrypted with {name}. " |
215 "Please stop encryption session before changing algorithm.") | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
216 .format(bare_jid=bare_jid, name=plugin.name)) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
217 log.warning(msg) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
218 raise exceptions.ConflictError(msg) |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
219 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
220 data = {"plugin": plugin} |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
221 if plugin.directed: |
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 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
|
224 if not entity.resource: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
225 raise exceptions.NotFound( |
3028 | 226 _("No resource found for {destinee}, can't encrypt with {name}") |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
227 .format(destinee=entity.full(), name=plugin.name)) |
3028 | 228 log.info(_("No resource specified to encrypt with {name}, using " |
229 "{destinee}.").format(destinee=entity.full(), | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
230 name=plugin.name)) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 # indicate that we encrypt only for some devices |
3028 | 232 directed_devices = data['directed_devices'] = [entity.resource] |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
233 elif entity.resource: |
3028 | 234 raise ValueError(_("{name} encryption must be used with bare jids.")) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
236 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
|
237 self._sessions[entity.userhostJID()] = data |
3028 | 238 log.info(_("Encryption session has been set for {entity_jid} with " |
239 "{encryption_name}").format( | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
240 entity_jid=entity.full(), encryption_name=plugin.name)) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
241 self.host.bridge.messageEncryptionStarted( |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
242 entity.full(), |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
243 self.getBridgeData(data), |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
244 self.client.profile) |
3028 | 245 msg = D_("Encryption session started: your messages with {destinee} are " |
246 "now end to end encrypted using {name} algorithm.").format( | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
247 destinee=entity.full(), name=plugin.name) |
3028 | 248 directed_devices = data.get('directed_devices') |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
249 if directed_devices: |
3028 | 250 msg += "\n" + D_("Message are encrypted only for {nb_devices} device(s): " |
251 "{devices_list}.").format( | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
252 nb_devices=len(directed_devices), |
3028 | 253 devices_list = ', '.join(directed_devices)) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
254 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
255 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
|
256 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
257 @defer.inlineCallbacks |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
258 def stop(self, entity, namespace=None): |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
259 """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
|
260 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
261 @param entity(jid.JID): entity with who the encryption session must be stopped |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
262 must be bare jid if the algorithm encrypt for all devices |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
263 @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
|
264 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
|
265 """ |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
266 session = self.getSession(entity.userhostJID()) |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
267 if not session: |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
268 raise failure.Failure( |
3028 | 269 exceptions.NotFound(_("There is no encryption session with this " |
270 "entity."))) | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
271 plugin = session['plugin'] |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
272 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
|
273 raise exceptions.InternalError(_( |
3028 | 274 "The encryption session is not run with the expected plugin: encrypted " |
275 "with {current_name} and was expecting {expected_name}").format( | |
276 current_name=session['plugin'].namespace, | |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
277 expected_name=namespace)) |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
278 if entity.resource: |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
279 try: |
3028 | 280 directed_devices = session['directed_devices'] |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
281 except KeyError: |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
282 raise exceptions.NotFound(_( |
3028 | 283 "There is a session for the whole entity (i.e. all devices of the " |
284 "entity), not a directed one. Please use bare jid if you want to " | |
285 "stop the whole encryption with this entity.")) | |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
286 |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
287 try: |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
288 directed_devices.remove(entity.resource) |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
289 except ValueError: |
3028 | 290 raise exceptions.NotFound(_("There is no directed session with this " |
291 "entity.")) | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
292 else: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
293 if not directed_devices: |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
294 # 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
|
295 # we stop the whole session |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
296 # 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
|
297 del self._sessions[entity.userhostJID()] |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
298 yield self._stopEncryption(plugin, entity) |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
299 else: |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
300 # 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
|
301 # 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
|
302 del self._sessions[entity.userhostJID()] |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
303 yield self._stopEncryption(plugin, entity) |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
304 |
3028 | 305 log.info(_("encryption session stopped with entity {entity}").format( |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
306 entity=entity.full())) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
307 self.host.bridge.messageEncryptionStopped( |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
308 entity.full(), |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
309 {'name': plugin.name, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
310 'namespace': plugin.namespace, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
311 }, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
312 self.client.profile) |
3028 | 313 msg = D_("Encryption session finished: your messages with {destinee} are " |
314 "NOT end to end encrypted anymore.\nYour server administrators or " | |
315 "{destinee} server administrators will be able to read them.").format( | |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
316 destinee=entity.full()) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
317 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
318 self.client.feedback(entity, msg) |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
319 |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
320 def getSession(self, entity): |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
321 """Get encryption session for this contact |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
322 |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
323 @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
|
324 must be a bare jid |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
325 @return (dict, None): encryption session data |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
326 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
|
327 """ |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
328 if entity.resource: |
3028 | 329 raise ValueError("Full jid given when expecting bare jid") |
2651
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
330 return self._sessions.get(entity) |
ebcff5423465
core (memory/encryption): start improvments, stop and getSession:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
331 |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
332 def getTrustUI(self, entity_jid, namespace=None): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
333 """Retrieve encryption UI |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
334 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
335 @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
|
336 must be a bare jid |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
337 @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
|
338 if None use current algorithm |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
339 @return D(xmlui): XMLUI for trust management |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
340 the xmlui is a form |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
341 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
|
342 @raise exceptions.NotFound: no algorithm/plugin found |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
343 @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
|
344 """ |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
345 if namespace is None: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
346 session = self.getSession(entity_jid) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
347 if not session: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
348 raise exceptions.NotFound( |
3028 | 349 "No encryption session currently active for {entity_jid}" |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
350 .format(entity_jid=entity_jid.full())) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
351 plugin = session['plugin'] |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
352 else: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
353 plugin = self.getPlugin(namespace) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
354 try: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
355 get_trust_ui = plugin.instance.getTrustUI |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
356 except AttributeError: |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
357 raise NotImplementedError( |
3028 | 358 "Encryption plugin doesn't handle trust management UI") |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
359 else: |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
360 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
|
361 |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
362 ## Menus ## |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
363 |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
364 @classmethod |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
365 def _importMenus(cls, host): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
366 host.importMenu( |
3028 | 367 (D_("Encryption"), D_("unencrypted (plain text)")), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
368 partial(cls._onMenuUnencrypted, host=host), |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
369 security_limit=0, |
3028 | 370 help_string=D_("End encrypted session"), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
371 type_=C.MENU_SINGLE, |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
372 ) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
373 for plg in cls.getPlugins(): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
374 host.importMenu( |
3028 | 375 (D_("Encryption"), plg.name), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
376 partial(cls._onMenuName, host=host, plg=plg), |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
377 security_limit=0, |
3028 | 378 help_string=D_("Start {name} session").format(name=plg.name), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
379 type_=C.MENU_SINGLE, |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
380 ) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
381 host.importMenu( |
3028 | 382 (D_("Encryption"), D_("⛨ {name} trust").format(name=plg.name)), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
383 partial(cls._onMenuTrust, host=host, plg=plg), |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
384 security_limit=0, |
3028 | 385 help_string=D_("Manage {name} trust").format(name=plg.name), |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
386 type_=C.MENU_SINGLE, |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
387 ) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
388 |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
389 @classmethod |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
390 def _onMenuUnencrypted(cls, data, host, profile): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
391 client = host.getClient(profile) |
3028 | 392 peer_jid = jid.JID(data['jid']).userhostJID() |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
393 d = client.encryption.stop(peer_jid) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
394 d.addCallback(lambda __: {}) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
395 return d |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
396 |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
397 @classmethod |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
398 def _onMenuName(cls, data, host, plg, profile): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
399 client = host.getClient(profile) |
3028 | 400 peer_jid = jid.JID(data['jid']) |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
401 if not plg.directed: |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
402 peer_jid = peer_jid.userhostJID() |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
403 d = client.encryption.start(peer_jid, plg.namespace, replace=True) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
404 d.addCallback(lambda __: {}) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
405 return d |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
406 |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
407 @classmethod |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
408 @defer.inlineCallbacks |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
409 def _onMenuTrust(cls, data, host, plg, profile): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
410 client = host.getClient(profile) |
3028 | 411 peer_jid = jid.JID(data['jid']).userhostJID() |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
412 ui = yield client.encryption.getTrustUI(peer_jid, plg.namespace) |
3028 | 413 defer.returnValue({'xmlui': ui.toXml()}) |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
414 |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 ## Triggers ## |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 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
|
418 """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
|
419 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 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
|
421 # 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
|
422 return |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 mess_data[C.MESS_KEY_ENCRYPTION] = encryption |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
428 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
429 ## Misc ## |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
430 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
431 def markAsEncrypted(self, mess_data): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
432 """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
|
433 |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
434 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
|
435 the plugin |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
436 @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
|
437 """ |
2752
1fa615faec8b
core (constants): added a constant for "encrypted"
Goffi <goffi@goffi.org>
parents:
2749
diff
changeset
|
438 mess_data[C.MESS_KEY_ENCRYPTED] = True |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2651
diff
changeset
|
439 return mess_data |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
440 |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
441 def markAsTrusted(self, mess_data): |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
442 """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
|
443 |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
444 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
|
445 the plugin |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
446 @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
|
447 """ |
2752
1fa615faec8b
core (constants): added a constant for "encrypted"
Goffi <goffi@goffi.org>
parents:
2749
diff
changeset
|
448 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
|
449 return mess_data |
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
450 |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
451 def markAsUntrusted(self, mess_data): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
452 """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
|
453 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
454 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
|
455 the plugin |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
456 @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
|
457 """ |
2743
da59ff099b32
core (memory/encryption), plugin OTR: finished OTR integration in encryption:
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
458 mess_data['trusted'] = False |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2658
diff
changeset
|
459 return mess_data |