annotate sat_frontends/jp/cmd_encryption.py @ 2958:e2cb04b381bb

tools (xml_tools): added "read_only" argument in dataFormResult2XMLUI (and use it in plugin pubsub_schema)
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2019 09:11:28 +0200
parents 003b8b4b56a7
children ab2696e34d29
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:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.disp(_(u"No encryption plugin registered!"))
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:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.disp(_(u"Following encryption algorithms are available: {algos}").format(
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 msg=_(u"can't retrieve plugins: {}"),
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 help=_(u"get encryption session data"))
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "jid", type=base.unicode_decoder,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 help=_(u"jid of the entity to check")
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 u"No encryption session found, the messages are sent in plain text.")
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 msg=_(u"can't get session: {}"),
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 help=_(u"start encrypted session with an entity"))
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 help=_(u"don't replace encryption algorithm if an other one is already used"))
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 "-n", "--name", help=_(u"algorithm name (DEFAULT: choose automatically)"))
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 help=_(u"algorithm namespace (DEFAULT: choose automatically)"))
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.parser.add_argument(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "jid", type=base.unicode_decoder,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 help=_(u"jid of the entity to stop encrypted session with")
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 msg=_(u"Can't start encryption session: {}"),
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 msg=_(u"Can't get encryption namespace: {}"),
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:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.encryptionNamespaceGetCb(u"")
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 help=_(u"stop encrypted session with an entity"))
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 "jid", type=base.unicode_decoder,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 help=_(u"jid of the entity to stop encrypted session with")
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 msg=_(u"can't end encrypted session: {}"),
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 help=_(u"get UI to manage trust"))
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 "jid", type=base.unicode_decoder,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 help=_(u"jid of the entity to stop encrypted session with")
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(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 "-n", "--name", help=_(u"algorithm name (DEFAULT: current algorithm)"))
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",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 help=_(u"algorithm namespace (DEFAULT: current algorithm)"))
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 msg=_(u"can't end encrypted session: {}"),
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,
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 msg=_(u"Can't get encryption namespace: {}"),
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:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 self.encryptionNamespaceGetCb(u"")
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__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 host, "trust", use_profile=False, help=_(u"trust manangement")
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__(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 host, "encryption", use_profile=False, help=_(u"encryption sessions handling")
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 )