annotate sat_frontends/jp/cmd_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 003b8b4b56a7
children fee60f17ebac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SAT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2740
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat_frontends.jp import base
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat_frontends.jp.constants import Const as C
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from functools import partial
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools.common import data_format
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat_frontends.jp import xmlui_manager
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 __commands__ = ["Encryption"]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 class EncryptionAlgorithms(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 extra_outputs = {"default": self.default_output}
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 super(EncryptionAlgorithms, self).__init__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 host, "algorithms",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 use_output=C.OUTPUT_LIST_DICT,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 extra_outputs=extra_outputs,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 use_profile=False,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 help=_("show available encryption algorithms"))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.need_loop = True
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def add_parser_options(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 pass
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def encryptionPluginsGetCb(self, plugins):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.output(plugins)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.host.quit()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def default_output(self, plugins):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if not plugins:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
51 self.disp(_("No encryption plugin registered!"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.host.quit(C.EXIT_NOT_FOUND)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 self.disp(_("Following encryption algorithms are available: {algos}").format(
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 algos=', '.join([p['name'] for p in plugins])))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.host.quit()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def start(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.host.bridge.encryptionPluginsGet(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 callback=self.encryptionPluginsGetCb,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 errback=partial(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
63 msg=_("can't retrieve plugins: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 ),
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
68
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 class EncryptionGet(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 super(EncryptionGet, self).__init__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 host, "get",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 use_output=C.OUTPUT_DICT,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
75 help=_("get encryption session data"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.need_loop = True
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def add_parser_options(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
80 "jid",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
81 help=_("jid of the entity to check")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def messageEncryptionGetCb(self, serialised):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 session_data = data_format.deserialise(serialised)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 if session_data is None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
88 "No encryption session found, the messages are sent in plain text.")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.host.quit(C.EXIT_NOT_FOUND)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 self.output(session_data)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.host.quit()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
92
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def start(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 jids = self.host.check_jids([self.args.jid])
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 jid = jids[0]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.host.bridge.messageEncryptionGet(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 jid, self.profile,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 callback=self.messageEncryptionGetCb,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 errback=partial(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 msg=_("can't get session: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 ),
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 class EncryptionStart(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 super(EncryptionStart, self).__init__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 host, "start",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
112 help=_("start encrypted session with an entity"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.need_loop = True
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
114
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 def add_parser_options(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.parser.add_argument(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 "--encrypt-noreplace",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
119 help=_("don't replace encryption algorithm if an other one is already used"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 algorithm = self.parser.add_mutually_exclusive_group()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 algorithm.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
122 "-n", "--name", help=_("algorithm name (DEFAULT: choose automatically)"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 algorithm.add_argument(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 "-N", "--namespace",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
125 help=_("algorithm namespace (DEFAULT: choose automatically)"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
127 "jid",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
128 help=_("jid of the entity to stop encrypted session with")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
130
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def encryptionNamespaceGetCb(self, namespace):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 jids = self.host.check_jids([self.args.jid])
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 jid = jids[0]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.host.bridge.messageEncryptionStart(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 jid, namespace, not self.args.encrypt_noreplace,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 self.profile,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 callback=self.host.quit,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 errback=partial(self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
139 msg=_("Can't start encryption session: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 ))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def start(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if self.args.name is not None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.host.bridge.encryptionNamespaceGet(self.args.name,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 callback=self.encryptionNamespaceGetCb,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 errback=partial(self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
148 msg=_("Can't get encryption namespace: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 ))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 elif self.args.namespace is not None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self.encryptionNamespaceGetCb(self.args.namespace)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 self.encryptionNamespaceGetCb("")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 class EncryptionStop(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 super(EncryptionStop, self).__init__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 host, "stop",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
162 help=_("stop encrypted session with an entity"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.need_loop = True
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 def add_parser_options(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
167 "jid",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
168 help=_("jid of the entity to stop encrypted session with")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 def start(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 jids = self.host.check_jids([self.args.jid])
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 jid = jids[0]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.host.bridge.messageEncryptionStop(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 jid, self.profile,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 callback=self.host.quit,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 errback=partial(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
179 msg=_("can't end encrypted session: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 ),
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 class TrustUI(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 super(TrustUI, self).__init__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 host, "ui",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
190 help=_("get UI to manage trust"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 self.need_loop = True
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
192
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 def add_parser_options(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
195 "jid",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
196 help=_("jid of the entity to stop encrypted session with")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 algorithm = self.parser.add_mutually_exclusive_group()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 algorithm.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
200 "-n", "--name", help=_("algorithm name (DEFAULT: current algorithm)"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 algorithm.add_argument(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 "-N", "--namespace",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
203 help=_("algorithm namespace (DEFAULT: current algorithm)"))
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
204
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 def encryptionTrustUIGetCb(self, xmlui_raw):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 xmlui = xmlui_manager.create(self.host, xmlui_raw)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 xmlui.show()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 xmlui.submitForm()
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
209
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 def encryptionNamespaceGetCb(self, namespace):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 jids = self.host.check_jids([self.args.jid])
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 jid = jids[0]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.host.bridge.encryptionTrustUIGet(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 jid, namespace, self.profile,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 callback=self.encryptionTrustUIGetCb,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 errback=partial(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
218 msg=_("can't end encrypted session: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 ),
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
222
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 def start(self):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 if self.args.name is not None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 self.host.bridge.encryptionNamespaceGet(self.args.name,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 callback=self.encryptionNamespaceGetCb,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 errback=partial(self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
228 msg=_("Can't get encryption namespace: {}"),
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 exit_code=C.EXIT_BRIDGE_ERRBACK,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 ))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 elif self.args.namespace is not None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 self.encryptionNamespaceGetCb(self.args.namespace)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
234 self.encryptionNamespaceGetCb("")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
235
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 class EncryptionTrust(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 subcommands = (TrustUI,)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
239
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 super(EncryptionTrust, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
242 host, "trust", use_profile=False, help=_("trust manangement")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 )
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
244
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
245
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 class Encryption(base.CommandBase):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 subcommands = (EncryptionAlgorithms, EncryptionGet, EncryptionStart, EncryptionStop,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 EncryptionTrust)
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
249
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 def __init__(self, host):
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 super(Encryption, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
252 host, "encryption", use_profile=False, help=_("encryption sessions handling")
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 )