Mercurial > libervia-backend
annotate libervia/cli/cmd_encryption.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
3479 | 5 # Copyright (C) 2009-2021 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 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
20 from libervia.cli import base |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
21 from libervia.cli.constants import Const as C |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
22 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.tools.common import data_format |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
24 from libervia.cli import xmlui_manager |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 __commands__ = ["Encryption"] |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
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 class EncryptionAlgorithms(base.CommandBase): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 extra_outputs = {"default": self.default_output} |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 super(EncryptionAlgorithms, self).__init__( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
34 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
35 "algorithms", |
2740
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, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
39 help=_("show available encryption algorithms"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
40 ) |
2740
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 default_output(self, plugins): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 if not plugins: |
3028 | 47 self.disp(_("No encryption plugin registered!")) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
49 self.disp( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
50 _("Following encryption algorithms are available: {algos}").format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
51 algos=", ".join([p["name"] for p in plugins]) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
52 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
53 ) |
3040 | 54 |
55 async def start(self): | |
56 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
57 plugins_ser = await self.host.bridge.encryption_plugins_get() |
3102
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
58 plugins = data_format.deserialise(plugins_ser, type_check=list) |
3040 | 59 except Exception as e: |
60 self.disp(f"can't retrieve plugins: {e}", error=True) | |
61 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
62 else: | |
63 await self.output(plugins) | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self.host.quit() |
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 class EncryptionGet(base.CommandBase): |
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 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 super(EncryptionGet, self).__init__( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
71 host, "get", use_output=C.OUTPUT_DICT, help=_("get encryption session data") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
72 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def add_parser_options(self): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
75 self.parser.add_argument("jid", help=_("jid of the entity to check")) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
3040 | 77 async def start(self): |
78 jids = await self.host.check_jids([self.args.jid]) | |
79 jid = jids[0] | |
80 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
81 serialised = await self.host.bridge.message_encryption_get(jid, self.profile) |
3040 | 82 except Exception as e: |
83 self.disp(f"can't get session: {e}", error=True) | |
84 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
85 | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 session_data = data_format.deserialise(serialised) |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 if session_data is None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
88 self.disp("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) |
3040 | 90 await self.output(session_data) |
2740
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 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 class EncryptionStart(base.CommandBase): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 super(EncryptionStart, self).__init__( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
98 host, "start", help=_("start encrypted session with an entity") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
99 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def add_parser_options(self): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 self.parser.add_argument( |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 "--encrypt-noreplace", |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 action="store_true", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
105 help=_("don't replace encryption algorithm if an other one is already used"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
106 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 algorithm = self.parser.add_mutually_exclusive_group() |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 algorithm.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
109 "-n", "--name", help=_("algorithm name (DEFAULT: choose automatically)") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
110 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 algorithm.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
112 "-N", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
113 "--namespace", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
114 help=_("algorithm namespace (DEFAULT: choose automatically)"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
115 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 self.parser.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
117 "jid", 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
|
118 ) |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
3040 | 120 async def start(self): |
121 if self.args.name is not None: | |
122 try: | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
123 namespace = await self.host.bridge.encryption_namespace_get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
124 self.args.name |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
125 ) |
3040 | 126 except Exception as e: |
127 self.disp(f"can't get encryption namespace: {e}", error=True) | |
128 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
129 elif self.args.namespace is not None: | |
130 namespace = self.args.namespace | |
131 else: | |
132 namespace = "" | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
3040 | 134 jids = await self.host.check_jids([self.args.jid]) |
135 jid = jids[0] | |
136 | |
137 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
138 await self.host.bridge.message_encryption_start( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
139 jid, namespace, not self.args.encrypt_noreplace, self.profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
140 ) |
3040 | 141 except Exception as e: |
142 self.disp(f"can't get encryption namespace: {e}", error=True) | |
143 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
144 | |
145 self.host.quit() | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 class EncryptionStop(base.CommandBase): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 super(EncryptionStop, self).__init__( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
152 host, "stop", help=_("stop encrypted session with an entity") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
153 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 def add_parser_options(self): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 self.parser.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
157 "jid", 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
|
158 ) |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
3040 | 160 async def start(self): |
161 jids = await self.host.check_jids([self.args.jid]) | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 jid = jids[0] |
3040 | 163 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
164 await self.host.bridge.message_encryption_stop(jid, self.profile) |
3040 | 165 except Exception as e: |
166 self.disp(f"can't end encrypted session: {e}", error=True) | |
167 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
168 | |
169 self.host.quit() | |
2740
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 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 class TrustUI(base.CommandBase): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 def __init__(self, host): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
175 super(TrustUI, self).__init__(host, "ui", help=_("get UI to manage trust")) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 def add_parser_options(self): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 self.parser.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
179 "jid", 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
|
180 ) |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 algorithm = self.parser.add_mutually_exclusive_group() |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 algorithm.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
183 "-n", "--name", help=_("algorithm name (DEFAULT: current algorithm)") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
184 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 algorithm.add_argument( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
186 "-N", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
187 "--namespace", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
188 help=_("algorithm namespace (DEFAULT: current algorithm)"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
189 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
3040 | 191 async def start(self): |
192 if self.args.name is not None: | |
193 try: | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
194 namespace = await self.host.bridge.encryption_namespace_get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
195 self.args.name |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
196 ) |
3040 | 197 except Exception as e: |
198 self.disp(f"can't get encryption namespace: {e}", error=True) | |
199 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
200 elif self.args.namespace is not None: | |
201 namespace = self.args.namespace | |
202 else: | |
203 namespace = "" | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
3040 | 205 jids = await self.host.check_jids([self.args.jid]) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 jid = jids[0] |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
3040 | 208 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
209 xmlui_raw = await self.host.bridge.encryption_trust_ui_get( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
210 jid, namespace, self.profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
211 ) |
3040 | 212 except Exception as e: |
213 self.disp(f"can't get encryption session trust UI: {e}", error=True) | |
214 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
3040 | 216 xmlui = xmlui_manager.create(self.host, xmlui_raw) |
217 await xmlui.show() | |
218 if xmlui.type != C.XMLUI_DIALOG: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 await xmlui.submit_form() |
3040 | 220 self.host.quit() |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
222 |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 class EncryptionTrust(base.CommandBase): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 subcommands = (TrustUI,) |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 super(EncryptionTrust, self).__init__( |
3028 | 228 host, "trust", use_profile=False, help=_("trust manangement") |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 ) |
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 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 class Encryption(base.CommandBase): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
233 subcommands = ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
234 EncryptionAlgorithms, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
235 EncryptionGet, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
236 EncryptionStart, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
237 EncryptionStop, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
238 EncryptionTrust, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
239 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 def __init__(self, host): |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 super(Encryption, self).__init__( |
3028 | 243 host, "encryption", use_profile=False, help=_("encryption sessions handling") |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 ) |