Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0384.py @ 3918:e63f96e60f7b
plugin XEP-0384: expose OLDMEMO and TWOMEMO namespaces:
rel 379
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 06 Oct 2022 16:02:05 +0200 |
parents | 4cb38c8312a1 |
children | 7b2c51bcc8f5 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
3 # Libervia plugin for OMEMO encryption |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
4 # Copyright (C) 2022-2022 Tim Henkes (me@syndace.dev) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
19 import enum |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
20 import logging |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
21 import time |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
22 from typing import ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
23 Any, Callable, Dict, FrozenSet, List, Literal, NamedTuple, Optional, Set, Type, cast |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
24 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
25 import uuid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
26 import xml.etree.ElementTree as ET |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
27 from xml.sax.saxutils import quoteattr |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
28 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
29 from typing_extensions import Never, assert_never |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
30 from wokkel import muc, pubsub # type: ignore[import] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
31 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
32 from sat.core import exceptions |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from sat.core.constants import Const as C |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
34 from sat.core.core_types import MessageData, SatXMPPEntity |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
35 from sat.core.i18n import _, D_ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
36 from sat.core.log import getLogger, Logger |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
37 from sat.core.sat_main import SAT |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
38 from sat.core.xmpp import SatXMPPClient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
39 from sat.memory import persistent |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
40 from sat.plugins.plugin_misc_text_commands import TextCommands |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
41 from sat.plugins.plugin_xep_0045 import XEP_0045 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
42 from sat.plugins.plugin_xep_0060 import XEP_0060 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
43 from sat.plugins.plugin_xep_0163 import XEP_0163 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
44 from sat.plugins.plugin_xep_0334 import XEP_0334 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
45 from sat.plugins.plugin_xep_0359 import XEP_0359 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
46 from sat.plugins.plugin_xep_0420 import XEP_0420, SCEAffixPolicy, SCEProfile |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
47 from sat.tools import xml_tools |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
48 from twisted.internet import defer |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
49 from twisted.words.protocols.jabber import error, jid |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 from twisted.words.xish import domish |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
51 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 try: |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 import omemo |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
54 import omemo.identity_key_pair |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
55 import twomemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
56 import twomemo.etree |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
57 import oldmemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
58 import oldmemo.etree |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
59 import oldmemo.migrations |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
60 from xmlschema import XMLSchemaValidationError |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
61 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
62 # An explicit version check of the OMEMO libraries should not be required here, since |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
63 # the stored data is fully versioned and the library will complain if a downgrade is |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
64 # attempted. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
65 except ImportError as import_error: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 raise exceptions.MissingModule( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
67 "You are missing one or more package required by the OMEMO plugin. Please" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
68 " download/install the pip packages 'omemo', 'twomemo', 'oldmemo' and" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
69 " 'xmlschema'." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
70 ) from import_error |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
71 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
73 __all__ = [ # pylint: disable=unused-variable |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
74 "PLUGIN_INFO", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
75 "OMEMO" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
76 ] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
77 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
78 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
79 log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
80 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
81 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
82 string_to_domish = cast(Callable[[str], domish.Element], xml_tools.ElementParser()) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
83 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 PLUGIN_INFO = { |
3028 | 86 C.PI_NAME: "OMEMO", |
87 C.PI_IMPORT_NAME: "XEP-0384", | |
88 C.PI_TYPE: "SEC", | |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
89 C.PI_PROTOCOLS: [ "XEP-0384" ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
90 C.PI_DEPENDENCIES: [ "XEP-0163", "XEP-0280", "XEP-0334", "XEP-0060", "XEP-0420" ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
91 C.PI_RECOMMENDATIONS: [ "XEP-0045", "XEP-0359", C.TEXT_CMDS ], |
3028 | 92 C.PI_MAIN: "OMEMO", |
93 C.PI_HANDLER: "no", | |
94 C.PI_DESCRIPTION: _("""Implementation of OMEMO"""), | |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 } |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
98 PARAM_CATEGORY = "Security" |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
99 PARAM_NAME = "omemo_policy" |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
100 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
102 class LogHandler(logging.Handler): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
103 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
104 Redirect python-omemo's log output to Libervia's log system. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
105 """ |
2654
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
106 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
107 def emit(self, record: logging.LogRecord) -> None: |
2654
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
108 log.log(record.levelname, record.getMessage()) |
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
109 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
110 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
111 sm_logger = logging.getLogger(omemo.SessionManager.LOG_TAG) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
112 sm_logger.setLevel(logging.DEBUG) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
113 sm_logger.propagate = False |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
114 sm_logger.addHandler(LogHandler()) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
115 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
116 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
117 ikp_logger = logging.getLogger(omemo.identity_key_pair.IdentityKeyPair.LOG_TAG) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
118 ikp_logger.setLevel(logging.DEBUG) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
119 ikp_logger.propagate = False |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
120 ikp_logger.addHandler(LogHandler()) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
121 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
122 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
123 # TODO: Add handling for device labels, i.e. show device labels in the trust UI and give |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
124 # the user a way to change their own device label. |
2654
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
125 |
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
126 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
127 class MUCPlaintextCacheKey(NamedTuple): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
128 # pylint: disable=invalid-name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
129 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
130 Structure identifying an encrypted message sent to a MUC. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
131 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
132 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
133 client: SatXMPPClient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
134 room_jid: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
135 message_uid: str |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
136 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
137 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
138 # TODO: Convert without serialization/parsing |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
139 # On a medium-to-large-sized oldmemo message stanza, 10000 runs of this function took |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
140 # around 0.6 seconds on my setup. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
141 def etree_to_domish(element: ET.Element) -> domish.Element: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
142 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
143 @param element: An ElementTree element. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
144 @return: The ElementTree element converted to a domish element. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
145 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
146 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
147 return string_to_domish(ET.tostring(element, encoding="unicode")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
148 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
149 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
150 # TODO: Convert without serialization/parsing |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
151 # On a medium-to-large-sized oldmemo message stanza, 10000 runs of this function took less |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
152 # than one second on my setup. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
153 def domish_to_etree(element: domish.Element) -> ET.Element: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
154 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
155 @param element: A domish element. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
156 @return: The domish element converted to an ElementTree element. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
157 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
158 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
159 return ET.fromstring(element.toXml()) |
2654
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
160 |
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
161 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
162 def domish_to_etree2(element: domish.Element) -> ET.Element: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
163 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
164 WIP |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
165 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
166 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
167 element_name = element.name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
168 if element.uri is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
169 element_name = "{" + element.uri + "}" + element_name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
170 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
171 attrib: Dict[str, str] = {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
172 for qname, value in element.attributes.items(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
173 attribute_name = qname[1] if isinstance(qname, tuple) else qname |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
174 attribute_namespace = qname[0] if isinstance(qname, tuple) else None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
175 if attribute_namespace is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
176 attribute_name = "{" + attribute_namespace + "}" + attribute_name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
177 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
178 attrib[attribute_name] = value |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
179 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
180 result = ET.Element(element_name, attrib) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
181 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
182 last_child: Optional[ET.Element] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
183 for child in element.children: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
184 if isinstance(child, str): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
185 if last_child is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
186 result.text = child |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
187 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
188 last_child.tail = child |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
189 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
190 last_child = domish_to_etree2(child) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
191 result.append(last_child) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
192 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
193 return result |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
194 |
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
195 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
196 @enum.unique |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
197 class TrustLevel(enum.Enum): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
198 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
199 The trust levels required for BTBV and manual trust. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
200 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
201 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
202 TRUSTED: str = "TRUSTED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
203 BLINDLY_TRUSTED: str = "BLINDLY_TRUSTED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
204 UNDECIDED: str = "UNDECIDED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
205 DISTRUSTED: str = "DISTRUSTED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
206 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
207 def to_omemo_trust_level(self) -> omemo.TrustLevel: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
208 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
209 @return: This custom trust level evaluated to one of the OMEMO trust levels. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
210 """ |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
211 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
212 if self is TrustLevel.TRUSTED or self is TrustLevel.BLINDLY_TRUSTED: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
213 return omemo.TrustLevel.TRUSTED |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
214 if self is TrustLevel.UNDECIDED: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
215 return omemo.TrustLevel.UNDECIDED |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
216 if self is TrustLevel.DISTRUSTED: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
217 return omemo.TrustLevel.DISTRUSTED |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
218 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
219 return assert_never(self) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
220 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
221 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
222 TWOMEMO_DEVICE_LIST_NODE = "urn:xmpp:omemo:2:devices" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
223 OLDMEMO_DEVICE_LIST_NODE = "eu.siacs.conversations.axolotl.devicelist" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
224 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
225 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
226 class StorageImpl(omemo.Storage): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
227 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
228 Storage implementation for OMEMO based on :class:`persistent.LazyPersistentBinaryDict` |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
229 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
230 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
231 def __init__(self, profile: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
232 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
233 @param profile: The profile this OMEMO data belongs to. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
234 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
235 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
236 # persistent.LazyPersistentBinaryDict does not cache at all, so keep the caching |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
237 # option of omemo.Storage enabled. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
238 super().__init__() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
239 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
240 self.__storage = persistent.LazyPersistentBinaryDict("XEP-0384", profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
241 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
242 async def _load(self, key: str) -> omemo.Maybe[omemo.JSONType]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
243 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
244 return omemo.Just(await self.__storage[key]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
245 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
246 return omemo.Nothing() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
247 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
248 raise omemo.StorageException(f"Error while loading key {key}") from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
249 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
250 async def _store(self, key: str, value: omemo.JSONType) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
251 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
252 await self.__storage.force(key, value) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
253 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
254 raise omemo.StorageException(f"Error while storing key {key}: {value}") from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
255 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
256 async def _delete(self, key: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
257 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
258 await self.__storage.remove(key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
259 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
260 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
261 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
262 raise omemo.StorageException(f"Error while deleting key {key}") from e |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
265 class LegacyStorageImpl(oldmemo.migrations.LegacyStorage): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
266 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
267 Legacy storage implementation to migrate data from the old XEP-0384 plugin. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
268 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
270 KEY_DEVICE_ID = "DEVICE_ID" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
271 KEY_STATE = "STATE" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
272 KEY_SESSION = "SESSION" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
273 KEY_ACTIVE_DEVICES = "DEVICES" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
274 KEY_INACTIVE_DEVICES = "INACTIVE_DEVICES" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
275 KEY_TRUST = "TRUST" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
276 KEY_ALL_JIDS = "ALL_JIDS" |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
278 def __init__(self, profile: str, own_bare_jid: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
279 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
280 @param profile: The profile this OMEMO data belongs to. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
281 @param own_bare_jid: The own bare JID, to return by the :meth:`loadOwnData` call. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
283 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
284 self.__storage = persistent.LazyPersistentBinaryDict("XEP-0384", profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
285 self.__own_bare_jid = own_bare_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
286 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
287 async def loadOwnData(self) -> Optional[oldmemo.migrations.OwnData]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
288 own_device_id = await self.__storage.get(LegacyStorageImpl.KEY_DEVICE_ID, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
289 if own_device_id is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
290 return None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
291 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
292 return oldmemo.migrations.OwnData( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
293 own_bare_jid=self.__own_bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
294 own_device_id=own_device_id |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
295 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
296 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
297 async def deleteOwnData(self) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
298 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
299 await self.__storage.remove(LegacyStorageImpl.KEY_DEVICE_ID) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
300 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
301 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
302 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
303 async def loadState(self) -> Optional[oldmemo.migrations.State]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
304 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
305 Optional[oldmemo.migrations.State], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
306 await self.__storage.get(LegacyStorageImpl.KEY_STATE, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
307 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
308 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
309 async def deleteState(self) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
310 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
311 await self.__storage.remove(LegacyStorageImpl.KEY_STATE) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
312 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
313 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
314 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
315 async def loadSession( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
316 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
317 bare_jid: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
318 device_id: int |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
319 ) -> Optional[oldmemo.migrations.Session]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
320 key = "\n".join([ LegacyStorageImpl.KEY_SESSION, bare_jid, str(device_id) ]) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
322 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
323 Optional[oldmemo.migrations.Session], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
324 await self.__storage.get(key, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
325 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
326 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
327 async def deleteSession(self, bare_jid: str, device_id: int) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
328 key = "\n".join([ LegacyStorageImpl.KEY_SESSION, bare_jid, str(device_id) ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
329 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
330 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
331 await self.__storage.remove(key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
332 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
333 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
334 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
335 async def loadActiveDevices(self, bare_jid: str) -> Optional[List[int]]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
336 key = "\n".join([ LegacyStorageImpl.KEY_ACTIVE_DEVICES, bare_jid ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
337 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
338 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
339 Optional[List[int]], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
340 await self.__storage.get(key, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
341 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
342 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
343 async def loadInactiveDevices(self, bare_jid: str) -> Optional[Dict[int, int]]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
344 key = "\n".join([ LegacyStorageImpl.KEY_INACTIVE_DEVICES, bare_jid ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
345 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
346 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
347 Optional[Dict[int, int]], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
348 await self.__storage.get(key, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
349 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
350 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
351 async def deleteActiveDevices(self, bare_jid: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
352 key = "\n".join([ LegacyStorageImpl.KEY_ACTIVE_DEVICES, bare_jid ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
353 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
354 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
355 await self.__storage.remove(key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
356 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
357 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
358 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
359 async def deleteInactiveDevices(self, bare_jid: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
360 key = "\n".join([ LegacyStorageImpl.KEY_INACTIVE_DEVICES, bare_jid ]) |
3672
e4054b648111
plugin XEP-0384: fix calls outside of main thread:
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
361 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
362 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
363 await self.__storage.remove(key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
364 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
365 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
366 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
367 async def loadTrust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
368 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
369 bare_jid: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
370 device_id: int |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
371 ) -> Optional[oldmemo.migrations.Trust]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
372 key = "\n".join([ LegacyStorageImpl.KEY_TRUST, bare_jid, str(device_id) ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
373 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
374 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
375 Optional[oldmemo.migrations.Trust], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
376 await self.__storage.get(key, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
377 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
378 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
379 async def deleteTrust(self, bare_jid: str, device_id: int) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
380 key = "\n".join([ LegacyStorageImpl.KEY_TRUST, bare_jid, str(device_id) ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
381 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
382 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
383 await self.__storage.remove(key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
384 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
385 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
386 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
387 async def listJIDs(self) -> Optional[List[str]]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
388 bare_jids = await self.__storage.get(LegacyStorageImpl.KEY_ALL_JIDS, None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
389 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
390 return None if bare_jids is None else list(bare_jids) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
391 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
392 async def deleteJIDList(self) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
393 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
394 await self.__storage.remove(LegacyStorageImpl.KEY_ALL_JIDS) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
395 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
396 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
397 |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
398 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
399 async def download_oldmemo_bundle( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
400 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
401 xep_0060: XEP_0060, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
402 bare_jid: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
403 device_id: int |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
404 ) -> oldmemo.oldmemo.BundleImpl: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
405 """Download the oldmemo bundle corresponding to a specific device. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
406 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
407 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
408 @param xep_0060: The XEP-0060 plugin instance to use for pubsub interactions. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
409 @param bare_jid: The bare JID the device belongs to. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
410 @param device_id: The id of the device. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
411 @return: The bundle. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
412 @raise BundleDownloadFailed: if the download failed. Feel free to raise a subclass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
413 instead. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
414 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
415 # Bundle downloads are needed by the session manager and for migrations from legacy, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
416 # thus it is made a separate function. |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
417 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
418 namespace = oldmemo.oldmemo.NAMESPACE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
419 node = f"eu.siacs.conversations.axolotl.bundles:{device_id}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
420 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
421 try: |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
422 items, __ = await xep_0060.getItems(client, jid.JID(bare_jid), node, max_items=1) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
423 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
424 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
425 f"Bundle download failed for {bare_jid}: {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
426 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
427 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
428 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
429 if len(items) != 1: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
430 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
431 f"Bundle download failed for {bare_jid}: {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
432 f" {namespace}: Unexpected number of items retrieved: {len(items)}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
433 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
434 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
435 element = next(iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), None) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
436 if element is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
437 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
438 f"Bundle download failed for {bare_jid}: {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
439 f" {namespace}: Item download succeeded but parsing failed: {element}." |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
440 ) |
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
441 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
442 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
443 return oldmemo.etree.parse_bundle(element, bare_jid, device_id) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
444 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
445 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
446 f"Bundle parsing failed for {bare_jid}: {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
447 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
448 ) from e |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
451 def make_session_manager(sat: SAT, profile: str) -> Type[omemo.SessionManager]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
452 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
453 @param sat: The SAT instance. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
454 @param profile: The profile. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
455 @return: A non-abstract subclass of :class:`~omemo.session_manager.SessionManager` |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
456 with XMPP interactions and trust handled via the SAT instance. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
457 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
458 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
459 client = sat.getClient(profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
460 xep_0060 = cast(XEP_0060, sat.plugins["XEP-0060"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
461 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
462 class SessionManagerImpl(omemo.SessionManager): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
463 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
464 Session manager implementation handling XMPP interactions and trust via an |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
465 instance of :class:`~sat.core.sat_main.SAT`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
466 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
467 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
468 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
469 async def _upload_bundle(bundle: omemo.Bundle) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
470 if isinstance(bundle, twomemo.twomemo.BundleImpl): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
471 element = twomemo.etree.serialize_bundle(bundle) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
472 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
473 node = "urn:xmpp:omemo:2:bundles" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
474 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
475 await xep_0060.sendItem( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
476 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
477 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
478 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
479 xml_tools.et_elt_2_domish_elt(element), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
480 item_id=str(bundle.device_id), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
481 extra={ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
482 xep_0060.EXTRA_PUBLISH_OPTIONS: { |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
483 xep_0060.OPT_MAX_ITEMS: "max" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
484 }, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
485 xep_0060.EXTRA_ON_PRECOND_NOT_MET: "raise" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
486 } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
487 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
488 except (error.StanzaError, Exception) as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
489 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
490 isinstance(e, error.StanzaError) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
491 and e.condition == "conflict" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
492 and e.appCondition is not None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
493 # pylint: disable=no-member |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
494 and e.appCondition.name == "precondition-not-met" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
495 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
496 # publish options couldn't be set on the fly, manually reconfigure |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
497 # the node and publish again |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
498 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
499 f"precondition-not-met: {bundle}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
500 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
501 # TODO: What can I do here? The correct node configuration is a |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
502 # MUST in the XEP. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
503 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
504 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
505 f"Bundle upload failed: {bundle}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
506 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
507 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
508 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
509 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
510 if isinstance(bundle, oldmemo.oldmemo.BundleImpl): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
511 element = oldmemo.etree.serialize_bundle(bundle) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
512 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
513 node = f"eu.siacs.conversations.axolotl.bundles:{bundle.device_id}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
514 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
515 await xep_0060.sendItem( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
516 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
517 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
518 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
519 xml_tools.et_elt_2_domish_elt(element), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
520 item_id=xep_0060.ID_SINGLETON, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
521 extra={ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
522 xep_0060.EXTRA_PUBLISH_OPTIONS: { xep_0060.OPT_MAX_ITEMS: 1 }, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
523 xep_0060.EXTRA_ON_PRECOND_NOT_MET: "publish_without_options" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
524 } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
525 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
526 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
527 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
528 f"Bundle upload failed: {bundle}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
529 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
530 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
531 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
532 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
533 raise omemo.UnknownNamespace(f"Unknown namespace: {bundle.namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
534 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
535 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
536 async def _download_bundle( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
537 namespace: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
538 bare_jid: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
539 device_id: int |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
540 ) -> omemo.Bundle: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
541 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
542 node = "urn:xmpp:omemo:2:bundles" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
543 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
544 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
545 items, __ = await xep_0060.getItems( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
546 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
547 jid.JID(bare_jid), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
548 node, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
549 max_items=None, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
550 item_ids=[ str(device_id) ] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
551 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
552 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
553 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
554 f"Bundle download failed for {bare_jid}: {device_id} under" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
555 f" namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
556 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
557 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
558 if len(items) != 1: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
559 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
560 f"Bundle download failed for {bare_jid}: {device_id} under" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
561 f" namespace {namespace}: Unexpected number of items retrieved:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
562 f" {len(items)}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
563 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
564 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
565 element = next( |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
566 iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
567 None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
568 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
569 if element is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
570 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
571 f"Bundle download failed for {bare_jid}: {device_id} under" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
572 f" namespace {namespace}: Item download succeeded but parsing" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
573 f" failed: {element}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
574 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
575 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
576 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
577 return twomemo.etree.parse_bundle(element, bare_jid, device_id) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
578 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
579 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
580 f"Bundle parsing failed for {bare_jid}: {device_id} under" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
581 f" namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
582 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
583 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
584 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
585 return await download_oldmemo_bundle( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
586 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
587 xep_0060, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
588 bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
589 device_id |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
590 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
591 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
592 raise omemo.UnknownNamespace(f"Unknown namespace: {namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
593 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
594 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
595 async def _delete_bundle(namespace: str, device_id: int) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
596 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
597 node = "urn:xmpp:omemo:2:bundles" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
598 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
599 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
600 await xep_0060.retractItems( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
601 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
602 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
603 node, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
604 [ str(device_id) ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
605 notify=False |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
606 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
607 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
608 raise omemo.BundleDeletionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
609 f"Bundle deletion failed for {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
610 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
611 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
612 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
613 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
614 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
615 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
616 node = f"eu.siacs.conversations.axolotl.bundles:{device_id}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
617 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
618 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
619 await xep_0060.deleteNode(client, client.jid.userhostJID(), node) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
620 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
621 raise omemo.BundleDeletionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
622 f"Bundle deletion failed for {device_id} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
623 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
624 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
625 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
626 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
627 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
628 raise omemo.UnknownNamespace(f"Unknown namespace: {namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
629 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
630 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
631 async def _upload_device_list( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
632 namespace: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
633 device_list: Dict[int, Optional[str]] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
634 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
635 element: Optional[ET.Element] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
636 node: Optional[str] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
637 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
638 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
639 element = twomemo.etree.serialize_device_list(device_list) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
640 node = TWOMEMO_DEVICE_LIST_NODE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
641 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
642 element = oldmemo.etree.serialize_device_list(device_list) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
643 node = OLDMEMO_DEVICE_LIST_NODE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
644 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
645 if element is None or node is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
646 raise omemo.UnknownNamespace(f"Unknown namespace: {namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
647 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
648 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
649 await xep_0060.sendItem( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
650 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
651 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
652 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
653 xml_tools.et_elt_2_domish_elt(element), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
654 item_id=xep_0060.ID_SINGLETON, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
655 extra={ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
656 xep_0060.EXTRA_PUBLISH_OPTIONS: { |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
657 xep_0060.OPT_MAX_ITEMS: 1, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
658 xep_0060.OPT_ACCESS_MODEL: "open" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
659 }, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
660 xep_0060.EXTRA_ON_PRECOND_NOT_MET: "raise" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
661 } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
662 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
663 except (error.StanzaError, Exception) as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
664 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
665 isinstance(e, error.StanzaError) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
666 and e.condition == "conflict" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
667 and e.appCondition is not None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
668 # pylint: disable=no-member |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
669 and e.appCondition.name == "precondition-not-met" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
670 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
671 # publish options couldn't be set on the fly, manually reconfigure the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
672 # node and publish again |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
673 raise omemo.DeviceListUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
674 f"precondition-not-met for namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
675 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
676 # TODO: What can I do here? The correct node configuration is a MUST |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
677 # in the XEP. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
678 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
679 raise omemo.DeviceListUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
680 f"Device list upload failed for namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
681 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
682 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
683 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
684 async def _download_device_list( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
685 namespace: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
686 bare_jid: str |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
687 ) -> Dict[int, Optional[str]]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
688 node: Optional[str] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
689 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
690 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
691 node = TWOMEMO_DEVICE_LIST_NODE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
692 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
693 node = OLDMEMO_DEVICE_LIST_NODE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
694 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
695 if node is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
696 raise omemo.UnknownNamespace(f"Unknown namespace: {namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
697 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
698 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
699 items, __ = await xep_0060.getItems(client, jid.JID(bare_jid), node) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
700 except exceptions.NotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
701 return {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
702 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
703 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
704 f"Device list download failed for {bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
705 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
706 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
707 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
708 if len(items) == 0: |
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
709 return {} |
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
710 elif len(items) != 1: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
711 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
712 f"Device list download failed for {bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
713 f" {namespace}: Unexpected number of items retrieved: {len(items)}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
714 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
715 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
716 element = next(iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), None) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
717 if element is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
718 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
719 f"Device list download failed for {bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
720 f" {namespace}: Item download succeeded but parsing failed:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
721 f" {element}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
722 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
723 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
724 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
725 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
726 return twomemo.etree.parse_device_list(element) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
727 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
728 return oldmemo.etree.parse_device_list(element) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
729 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
730 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
731 f"Device list download failed for {bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
732 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
733 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
734 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
735 raise omemo.UnknownNamespace(f"Unknown namespace: {namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
736 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
737 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
738 def _evaluate_custom_trust_level(trust_level_name: str) -> omemo.TrustLevel: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
739 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
740 return TrustLevel(trust_level_name).to_omemo_trust_level() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
741 except ValueError as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
742 raise omemo.UnknownTrustLevel( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
743 f"Unknown trust level name {trust_level_name}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
744 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
745 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
746 async def _make_trust_decision( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
747 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
748 undecided: FrozenSet[omemo.DeviceInformation], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
749 identifier: Optional[str] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
750 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
751 if identifier is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
752 raise omemo.TrustDecisionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
753 "The identifier must contain the feedback JID." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
754 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
755 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
756 # The feedback JID is transferred via the identifier |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
757 feedback_jid = jid.JID(identifier).userhostJID() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
758 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
759 # Get the name of the trust model to use |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
760 trust_model = cast(str, sat.memory.getParamA( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
761 PARAM_NAME, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
762 PARAM_CATEGORY, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
763 profile_key=cast(str, client.profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
764 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
765 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
766 # Under the BTBV trust model, if at least one device of a bare JID is manually |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
767 # trusted or distrusted, the trust model is "downgraded" to manual trust. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
768 # Thus, we can separate bare JIDs into two pools here, one pool of bare JIDs |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
769 # for which BTBV is active, and one pool of bare JIDs for which manual trust |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
770 # is used. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
771 bare_jids = { device.bare_jid for device in undecided } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
772 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
773 btbv_bare_jids: Set[str] = set() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
774 manual_trust_bare_jids: Set[str] = set() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
775 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
776 if trust_model == "btbv": |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
777 # For each bare JID, decide whether BTBV or manual trust applies |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
778 for bare_jid in bare_jids: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
779 # Get all known devices belonging to the bare JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
780 devices = await self.get_device_information(bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
781 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
782 # If the trust levels of all devices correspond to those used by BTBV, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
783 # BTBV applies. Otherwise, fall back to manual trust. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
784 if all(TrustLevel(device.trust_level_name) in { |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
785 TrustLevel.UNDECIDED, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
786 TrustLevel.BLINDLY_TRUSTED |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
787 } for device in devices): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
788 btbv_bare_jids.add(bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
789 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
790 manual_trust_bare_jids.add(bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
791 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
792 if trust_model == "manual": |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
793 manual_trust_bare_jids = bare_jids |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
794 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
795 # With the JIDs sorted into their respective pools, the undecided devices can |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
796 # be categorized too |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
797 blindly_trusted_devices = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
798 { dev for dev in undecided if dev.bare_jid in btbv_bare_jids } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
799 manually_trusted_devices = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
800 { dev for dev in undecided if dev.bare_jid in manual_trust_bare_jids } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
801 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
802 # Blindly trust devices handled by BTBV |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
803 if len(blindly_trusted_devices) > 0: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
804 for device in blindly_trusted_devices: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
805 await self.set_trust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
806 device.bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
807 device.identity_key, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
808 TrustLevel.BLINDLY_TRUSTED.name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
809 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
810 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
811 blindly_trusted_devices_stringified = ", ".join([ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
812 f"device {device.device_id} of {device.bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
813 f" {device.namespaces}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
814 for device |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
815 in blindly_trusted_devices |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
816 ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
817 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
818 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
819 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
820 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
821 "Not all destination devices are trusted, unknown devices will be" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
822 " blindly trusted due to the Blind Trust Before Verification" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
823 " policy. If you want a more secure workflow, please activate the" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
824 " \"manual\" policy in the settings' \"Security\" tab.\nFollowing" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
825 " devices have been automatically trusted:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
826 f" {blindly_trusted_devices_stringified}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
827 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
828 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
829 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
830 # Prompt the user for manual trust decisions on the devices handled by manual |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
831 # trust |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
832 if len(manually_trusted_devices) > 0: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
833 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
834 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
835 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
836 "Not all destination devices are trusted, we can't encrypt" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
837 " message in such a situation. Please indicate if you trust" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
838 " those devices or not in the trust manager before we can" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
839 " send this message." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
840 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
841 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
842 await self.__prompt_manual_trust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
843 frozenset(manually_trusted_devices), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
844 feedback_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
845 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
846 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
847 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
848 async def _send_message(message: omemo.Message, bare_jid: str) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
849 element: Optional[ET.Element] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
850 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
851 if message.namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
852 element = twomemo.etree.serialize_message(message) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
853 if message.namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
854 element = oldmemo.etree.serialize_message(message) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
855 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
856 if element is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
857 raise omemo.UnknownNamespace(f"Unknown namespace: {message.namespace}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
858 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
859 # TODO: Untested |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
860 message_data = client.generateMessageXML(MessageData({ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
861 "from": client.jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
862 "to": jid.JID(bare_jid), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
863 "uid": str(uuid.uuid4()), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
864 "message": {}, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
865 "subject": {}, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
866 "type": C.MESS_TYPE_CHAT, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
867 "extra": {}, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
868 "timestamp": time.time() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
869 })) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
870 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
871 message_data["xml"].addChild(xml_tools.et_elt_2_domish_elt(element)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
872 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
873 try: |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
874 await client.a_send(message_data["xml"]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
875 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
876 raise omemo.MessageSendingFailed() from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
877 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
878 async def __prompt_manual_trust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
879 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
880 undecided: FrozenSet[omemo.DeviceInformation], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
881 feedback_jid: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
882 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
883 """Asks the user to decide on the manual trust level of a set of devices. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
884 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
885 Blocks until the user has made a decision and updates the trust levels of all |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
886 devices using :meth:`set_trust`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
887 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
888 @param undecided: The set of devices to prompt manual trust for. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
889 @param feedback_jid: The bare JID to redirect feedback to. In case of a one to |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
890 one message, the recipient JID. In case of a MUC message, the room JID. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
891 @raise TrustDecisionFailed: if the user cancels the prompt. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
892 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
893 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
894 # This session manager handles encryption with both twomemo and oldmemo, but |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
895 # both are currently registered as different plugins and the `deferXMLUI` |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
896 # below requires a single namespace identifying the encryption plugin. Thus, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
897 # get the namespace of the requested encryption method from the encryption |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
898 # session using the feedback JID. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
899 encryption = client.encryption.getSession(feedback_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
900 if encryption is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
901 raise omemo.TrustDecisionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
902 f"Encryption not requested for {feedback_jid.userhost()}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
903 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
904 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
905 namespace = encryption["plugin"].namespace |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
906 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
907 # Casting this to Any, otherwise all calls on the variable cause type errors |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
908 # pylint: disable=no-member |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
909 trust_ui = cast(Any, xml_tools.XMLUI( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
910 panel_type=C.XMLUI_FORM, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
911 title=D_("OMEMO trust management"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
912 submit_id="" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
913 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
914 trust_ui.addText(D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
915 "This is OMEMO trusting system. You'll see below the devices of your " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
916 "contacts, and a checkbox to trust them or not. A trusted device " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
917 "can read your messages in plain text, so be sure to only validate " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
918 "devices that you are sure are belonging to your contact. It's better " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
919 "to do this when you are next to your contact and their device, so " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
920 "you can check the \"fingerprint\" (the number next to the device) " |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
921 "yourself. Do *not* validate a device if the fingerprint is wrong!" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
922 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
923 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
924 own_device, __ = await self.get_own_device_information() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
925 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
926 trust_ui.changeContainer("label") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
927 trust_ui.addLabel(D_("This device ID")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
928 trust_ui.addText(str(own_device.device_id)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
929 trust_ui.addLabel(D_("This device's fingerprint")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
930 trust_ui.addText(" ".join(self.format_identity_key(own_device.identity_key))) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
931 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
932 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
933 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
934 # At least sort the devices by bare JID such that they aren't listed |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
935 # completely random |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
936 undecided_ordered = sorted(undecided, key=lambda device: device.bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
937 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
938 for index, device in enumerate(undecided_ordered): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
939 trust_ui.addLabel(D_("Contact")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
940 trust_ui.addJid(jid.JID(device.bare_jid)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
941 trust_ui.addLabel(D_("Device ID")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
942 trust_ui.addText(str(device.device_id)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
943 trust_ui.addLabel(D_("Fingerprint")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
944 trust_ui.addText(" ".join(self.format_identity_key(device.identity_key))) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
945 trust_ui.addLabel(D_("Trust this device?")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
946 trust_ui.addBool(f"trust_{index}", value=C.boolConst(False)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
947 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
948 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
949 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
950 trust_ui_result = await xml_tools.deferXMLUI( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
951 sat, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
952 trust_ui, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
953 action_extra={ "meta_encryption_trust": namespace }, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
954 profile=profile |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
955 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
956 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
957 if C.bool(trust_ui_result.get("cancelled", "false")): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
958 raise omemo.TrustDecisionFailed("Trust UI cancelled.") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
959 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
960 data_form_result = cast(Dict[str, str], xml_tools.XMLUIResult2DataFormResult( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
961 trust_ui_result |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
962 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
963 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
964 for key, value in data_form_result.items(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
965 if not key.startswith("trust_"): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
966 continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
967 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
968 device = undecided_ordered[int(key[len("trust_"):])] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
969 trust = C.bool(value) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
970 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
971 await self.set_trust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
972 device.bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
973 device.identity_key, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
974 TrustLevel.TRUSTED.name if trust else TrustLevel.DISTRUSTED.name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
975 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
976 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
977 return SessionManagerImpl |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
978 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
979 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
980 async def prepare_for_profile( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
981 sat: SAT, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
982 profile: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
983 initial_own_label: Optional[str], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
984 signed_pre_key_rotation_period: int = 7 * 24 * 60 * 60, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
985 pre_key_refill_threshold: int = 99, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
986 max_num_per_session_skipped_keys: int = 1000, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
987 max_num_per_message_skipped_keys: Optional[int] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
988 ) -> omemo.SessionManager: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
989 """Prepare the OMEMO library (storage, backends, core) for a specific profile. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
990 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
991 @param sat: The SAT instance. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
992 @param profile: The profile. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
993 @param initial_own_label: The initial (optional) label to assign to this device if |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
994 supported by any of the backends. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
995 @param signed_pre_key_rotation_period: The rotation period for the signed pre key, in |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
996 seconds. The rotation period is recommended to be between one week (the default) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
997 and one month. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
998 @param pre_key_refill_threshold: The number of pre keys that triggers a refill to 100. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
999 Defaults to 99, which means that each pre key gets replaced with a new one right |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1000 away. The threshold can not be configured to lower than 25. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1001 @param max_num_per_session_skipped_keys: The maximum number of skipped message keys to |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1002 keep around per session. Once the maximum is reached, old message keys are deleted |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1003 to make space for newer ones. Accessible via |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1004 :attr:`max_num_per_session_skipped_keys`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1005 @param max_num_per_message_skipped_keys: The maximum number of skipped message keys to |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1006 accept in a single message. When set to ``None`` (the default), this parameter |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1007 defaults to the per-session maximum (i.e. the value of the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1008 ``max_num_per_session_skipped_keys`` parameter). This parameter may only be 0 if |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1009 the per-session maximum is 0, otherwise it must be a number between 1 and the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1010 per-session maximum. Accessible via :attr:`max_num_per_message_skipped_keys`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1011 @return: A session manager with ``urn:xmpp:omemo:2`` and |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1012 ``eu.siacs.conversations.axolotl`` capabilities, specifically for the given |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1013 profile. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1014 @raise BundleUploadFailed: if a bundle upload failed. Forwarded from |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1015 :meth:`~omemo.session_manager.SessionManager.create`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1016 @raise BundleDownloadFailed: if a bundle download failed. Forwarded from |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1017 :meth:`~omemo.session_manager.SessionManager.create`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1018 @raise BundleDeletionFailed: if a bundle deletion failed. Forwarded from |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1019 :meth:`~omemo.session_manager.SessionManager.create`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1020 @raise DeviceListUploadFailed: if a device list upload failed. Forwarded from |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1021 :meth:`~omemo.session_manager.SessionManager.create`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1022 @raise DeviceListDownloadFailed: if a device list download failed. Forwarded from |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1023 :meth:`~omemo.session_manager.SessionManager.create`. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1024 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1025 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1026 client = sat.getClient(profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1027 xep_0060 = cast(XEP_0060, sat.plugins["XEP-0060"]) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1028 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1029 storage = StorageImpl(profile) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1030 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1031 # TODO: Untested |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1032 await oldmemo.migrations.migrate( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1033 LegacyStorageImpl(profile, client.jid.userhost()), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1034 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1035 # TODO: Do we want BLINDLY_TRUSTED or TRUSTED here? |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1036 TrustLevel.BLINDLY_TRUSTED.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1037 TrustLevel.UNDECIDED.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1038 TrustLevel.DISTRUSTED.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1039 lambda bare_jid, device_id: download_oldmemo_bundle( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1040 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1041 xep_0060, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1042 bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1043 device_id |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1044 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1045 ) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1046 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1047 session_manager = await make_session_manager(sat, profile).create( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1048 [ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1049 twomemo.Twomemo( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1050 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1051 max_num_per_session_skipped_keys, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1052 max_num_per_message_skipped_keys |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1053 ), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1054 oldmemo.Oldmemo( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1055 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1056 max_num_per_session_skipped_keys, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1057 max_num_per_message_skipped_keys |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1058 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1059 ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1060 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1061 client.jid.userhost(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1062 initial_own_label, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1063 TrustLevel.UNDECIDED.value, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1064 signed_pre_key_rotation_period, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1065 pre_key_refill_threshold, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1066 omemo.AsyncFramework.TWISTED |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1067 ) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1068 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1069 # This shouldn't hurt here since we're not running on overly constrainted devices. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1070 # TODO: Consider ensuring data consistency regularly/in response to certain events |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1071 await session_manager.ensure_data_consistency() |
3240
d85b68e44297
plugin XEP-0384: fixed /omemo_reset + device ID type:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1072 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1073 # TODO: Correct entering/leaving of the history synchronization mode isn't terribly |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1074 # important for now, since it only prevents an extremely unlikely race condition of |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1075 # multiple devices choosing the same pre key for new sessions while the device was |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1076 # offline. I don't believe other clients seriously defend against that race condition |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1077 # either. In the long run, it might still be cool to have triggers for when history |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1078 # sync starts and ends (MAM, MUC catch-up, etc.) and to react to those triggers. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1079 await session_manager.after_history_sync() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1080 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1081 return session_manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1082 |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1083 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1084 DEFAULT_TRUST_MODEL_PARAM = f""" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1085 <params> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1086 <individual> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1087 <category name="{PARAM_CATEGORY}" label={quoteattr(D_('Security'))}> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1088 <param name="{PARAM_NAME}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1089 label={quoteattr(D_('OMEMO default trust policy'))} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1090 type="list" security="3"> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1091 <option value="manual" label={quoteattr(D_('Manual trust (more secure)'))} /> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1092 <option value="btbv" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1093 label={quoteattr(D_('Blind Trust Before Verification (more user friendly)'))} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1094 selected="true" /> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1095 </param> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1096 </category> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1097 </individual> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1098 </params> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1099 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1100 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1101 |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1102 class OMEMO: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1103 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1104 Plugin equipping Libervia with OMEMO capabilities under the (modern) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1105 ``urn:xmpp:omemo:2`` namespace and the (legacy) ``eu.siacs.conversations.axolotl`` |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1106 namespace. Both versions of the protocol are handled by this plugin and compatibility |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1107 between the two is maintained. MUC messages are supported next to one to one messages. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1108 For trust management, the two trust models "BTBV" and "manual" are supported. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1109 """ |
3918
e63f96e60f7b
plugin XEP-0384: expose OLDMEMO and TWOMEMO namespaces:
Goffi <goffi@goffi.org>
parents:
3914
diff
changeset
|
1110 NS_TWOMEMO = twomemo.twomemo.NAMESPACE |
e63f96e60f7b
plugin XEP-0384: expose OLDMEMO and TWOMEMO namespaces:
Goffi <goffi@goffi.org>
parents:
3914
diff
changeset
|
1111 NS_OLDMEMO = oldmemo.oldmemo.NAMESPACE |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1112 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1113 # For MUC/MIX message stanzas, the <to/> affix is a MUST |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1114 SCE_PROFILE_GROUPCHAT = SCEProfile( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1115 rpad_policy=SCEAffixPolicy.REQUIRED, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1116 time_policy=SCEAffixPolicy.OPTIONAL, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1117 to_policy=SCEAffixPolicy.REQUIRED, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1118 from_policy=SCEAffixPolicy.OPTIONAL, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1119 custom_policies={} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1120 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1121 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1122 # For everything but MUC/MIX message stanzas, the <to/> affix is a MAY |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1123 SCE_PROFILE = SCEProfile( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1124 rpad_policy=SCEAffixPolicy.REQUIRED, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1125 time_policy=SCEAffixPolicy.OPTIONAL, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1126 to_policy=SCEAffixPolicy.OPTIONAL, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1127 from_policy=SCEAffixPolicy.OPTIONAL, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1128 custom_policies={} |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1129 ) |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1130 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1131 def __init__(self, sat: SAT) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1132 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1133 @param sat: The SAT instance. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1134 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1135 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1136 self.__sat = sat |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1137 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1138 # Add configuration option to choose between manual trust and BTBV as the trust |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1139 # model |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1140 sat.memory.updateParams(DEFAULT_TRUST_MODEL_PARAM) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1141 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1142 # Plugins |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1143 self.__xep_0045 = cast(Optional[XEP_0045], sat.plugins.get("XEP-0045")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1144 self.__xep_0334 = cast(XEP_0334, sat.plugins["XEP-0334"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1145 self.__xep_0359 = cast(Optional[XEP_0359], sat.plugins.get("XEP-0359")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1146 self.__xep_0420 = cast(XEP_0420, sat.plugins["XEP-0420"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1147 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1148 # In contrast to one to one messages, MUC messages are reflected to the sender. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1149 # Thus, the sender does not add messages to their local message log when sending |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1150 # them, but when the reflection is received. This approach does not pair well with |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1151 # OMEMO, since for security reasons it is forbidden to encrypt messages for the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1152 # own device. Thus, when the reflection of an OMEMO message is received, it can't |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1153 # be decrypted and added to the local message log as usual. To counteract this, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1154 # the plaintext of encrypted messages sent to MUCs are cached in this field, such |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1155 # that when the reflection is received, the plaintext can be looked up from the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1156 # cache and added to the local message log. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1157 # TODO: The old plugin expired this cache after some time. I'm not sure that's |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1158 # really necessary. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1159 self.__muc_plaintext_cache: Dict[MUCPlaintextCacheKey, bytes] = {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1160 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1161 # Mapping from profile name to corresponding session manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1162 self.__session_managers: Dict[str, omemo.SessionManager] = {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1163 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1164 # Calls waiting for a specific session manager to be built |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1165 self.__session_manager_waiters: Dict[str, List[defer.Deferred]] = {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1166 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1167 # These triggers are used by oldmemo, which doesn't do SCE and only applies to |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1168 # messages |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1169 sat.trigger.add( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1170 "messageReceived", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1171 self.__message_received_trigger, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1172 priority=100050 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1173 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1174 sat.trigger.add( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1175 "sendMessageData", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1176 self.__send_message_data_trigger, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1177 priority=100050 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1178 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1179 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1180 # These triggers are used by twomemo, which does do SCE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1181 sat.trigger.add("send", self.__send_trigger, priority=0) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1182 # TODO: Add new triggers here for freshly received and about-to-be-sent stanzas, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1183 # including IQs. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1184 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1185 # Give twomemo a (slightly) higher priority than oldmemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1186 sat.registerEncryptionPlugin(self, "TWOMEMO", twomemo.twomemo.NAMESPACE, 101) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1187 sat.registerEncryptionPlugin(self, "OLDMEMO", oldmemo.oldmemo.NAMESPACE, 100) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1188 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1189 xep_0163 = cast(XEP_0163, sat.plugins["XEP-0163"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1190 xep_0163.addPEPEvent( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1191 "TWOMEMO_DEVICES", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1192 TWOMEMO_DEVICE_LIST_NODE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1193 lambda items_event, profile: defer.ensureDeferred( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1194 self.__on_device_list_update(items_event, profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1195 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1196 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1197 xep_0163.addPEPEvent( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1198 "OLDMEMO_DEVICES", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1199 OLDMEMO_DEVICE_LIST_NODE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1200 lambda items_event, profile: defer.ensureDeferred( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1201 self.__on_device_list_update(items_event, profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1202 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1203 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1204 |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1205 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1206 self.__text_commands = cast(TextCommands, sat.plugins[C.TEXT_CMDS]) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1207 except KeyError: |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1208 log.info(_("Text commands not available")) |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1209 else: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1210 self.__text_commands.registerTextCommands(self) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1211 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1212 async def profileConnected( # pylint: disable=invalid-name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1213 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1214 client: SatXMPPClient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1215 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1216 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1217 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1218 """ |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1219 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1220 await self.__prepare_for_profile(cast(str, client.profile)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1221 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1222 async def cmd_omemo_reset( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1223 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1224 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1225 mess_data: MessageData |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1226 ) -> Literal[False]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1227 """Reset all sessions of devices that belong to the recipient of ``mess_data``. |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1228 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1229 This must only be callable manually by the user. Use this when a session is |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1230 apparently broken, i.e. sending and receiving encrypted messages doesn't work and |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1231 something being wrong has been confirmed manually with the recipient. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1232 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1233 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1234 @param mess_data: The message data, whose ``to`` attribute will be the bare JID to |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1235 reset all sessions with. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1236 @return: The constant value ``False``, indicating to the text commands plugin that |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1237 the message is not supposed to be sent. |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1238 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1239 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1240 twomemo_requested = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1241 client.encryption.isEncryptionRequested(mess_data, twomemo.twomemo.NAMESPACE) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1242 oldmemo_requested = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1243 client.encryption.isEncryptionRequested(mess_data, oldmemo.oldmemo.NAMESPACE) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1244 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1245 if not (twomemo_requested or oldmemo_requested): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1246 self.__text_commands.feedBack( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1247 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1248 _("You need to have OMEMO encryption activated to reset the session"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1249 mess_data |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1250 ) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1251 return False |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1252 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1253 bare_jid = mess_data["to"].userhost() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1254 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1255 session_manager = await self.__prepare_for_profile(client.profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1256 devices = await session_manager.get_device_information(bare_jid) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1257 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1258 for device in devices: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1259 log.debug(f"Replacing sessions with device {device}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1260 await session_manager.replace_sessions(device) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1261 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1262 self.__text_commands.feedBack( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1263 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1264 _("OMEMO session has been reset"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1265 mess_data |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1266 ) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1267 |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1268 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1269 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1270 async def getTrustUI( # pylint: disable=invalid-name |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1271 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1272 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1273 entity: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1274 ) -> xml_tools.XMLUI: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1275 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1276 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1277 @param entity: The entity whose device trust levels to manage. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1278 @return: An XMLUI instance which opens a form to manage the trust level of all |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1279 devices belonging to the entity. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1280 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1281 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1282 if entity.resource: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1283 raise ValueError("A bare JID is expected.") |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1284 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1285 bare_jids: Set[str] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1286 if self.__xep_0045 is not None and self.__xep_0045.isJoinedRoom(client, entity): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1287 bare_jids = self.__get_joined_muc_users(client, self.__xep_0045, entity) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1288 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1289 bare_jids = { entity.userhost() } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1290 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1291 session_manager = await self.__prepare_for_profile(client.profile) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1292 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1293 # At least sort the devices by bare JID such that they aren't listed completely |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1294 # random |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1295 devices = sorted(cast(Set[omemo.DeviceInformation], set()).union(*[ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1296 await session_manager.get_device_information(bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1297 for bare_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1298 in bare_jids |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1299 ]), key=lambda device: device.bare_jid) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1300 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1301 async def callback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1302 data: Any, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1303 profile: str # pylint: disable=unused-argument |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1304 ) -> Dict[Never, Never]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1305 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1306 @param data: The XMLUI result produces by the trust UI form. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1307 @param profile: The profile. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1308 @return: An empty dictionary. The type of the return value was chosen |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1309 conservatively since the exact options are neither known not needed here. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1310 """ |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1311 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1312 if C.bool(data.get("cancelled", "false")): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1313 return {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1314 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1315 data_form_result = cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1316 Dict[str, str], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1317 xml_tools.XMLUIResult2DataFormResult(data) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1318 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1319 for key, value in data_form_result.items(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1320 if not key.startswith("trust_"): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1321 continue |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1322 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1323 device = devices[int(key[len("trust_"):])] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1324 trust = TrustLevel(value) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1325 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1326 if TrustLevel(device.trust_level_name) is not trust: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1327 await session_manager.set_trust( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1328 device.bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1329 device.identity_key, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1330 value |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1331 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1332 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1333 return {} |
2744
e6716d90c2fe
plugin XEP-0384: various bug fixes:
Goffi <goffi@goffi.org>
parents:
2738
diff
changeset
|
1334 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1335 submit_id = self.__sat.registerCallback(callback, with_data=True, one_shot=True) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1336 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1337 result = xml_tools.XMLUI( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1338 panel_type=C.XMLUI_FORM, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1339 title=D_("OMEMO trust management"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1340 submit_id=submit_id |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1341 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1342 # Casting this to Any, otherwise all calls on the variable cause type errors |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1343 # pylint: disable=no-member |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1344 trust_ui = cast(Any, result) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1345 trust_ui.addText(D_( |
3028 | 1346 "This is OMEMO trusting system. You'll see below the devices of your " |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1347 "contacts, and a list selection to trust them or not. A trusted device " |
3028 | 1348 "can read your messages in plain text, so be sure to only validate " |
1349 "devices that you are sure are belonging to your contact. It's better " | |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1350 "to do this when you are next to your contact and their device, so " |
3028 | 1351 "you can check the \"fingerprint\" (the number next to the device) " |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1352 "yourself. Do *not* validate a device if the fingerprint is wrong!" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1353 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1354 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1355 own_device, __ = await session_manager.get_own_device_information() |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1356 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1357 trust_ui.changeContainer("label") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1358 trust_ui.addLabel(D_("This device ID")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1359 trust_ui.addText(str(own_device.device_id)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1360 trust_ui.addLabel(D_("This device's fingerprint")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1361 trust_ui.addText(" ".join(session_manager.format_identity_key( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1362 own_device.identity_key |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1363 ))) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1364 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1365 trust_ui.addEmpty() |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1366 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1367 for index, device in enumerate(devices): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1368 trust_ui.addLabel(D_("Contact")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1369 trust_ui.addJid(jid.JID(device.bare_jid)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1370 trust_ui.addLabel(D_("Device ID")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1371 trust_ui.addText(str(device.device_id)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1372 trust_ui.addLabel(D_("Fingerprint")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1373 trust_ui.addText(" ".join(session_manager.format_identity_key( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1374 device.identity_key |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1375 ))) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1376 trust_ui.addLabel(D_("Trust this device?")) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1377 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1378 current_trust_level = TrustLevel(device.trust_level_name) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1379 avaiable_trust_levels = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1380 { TrustLevel.DISTRUSTED, TrustLevel.TRUSTED, current_trust_level } |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1381 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1382 trust_ui.addList( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1383 f"trust_{index}", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1384 options=[ trust_level.name for trust_level in avaiable_trust_levels ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1385 selected=current_trust_level.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1386 styles=[ "inline" ] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1387 ) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1388 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1389 twomemo_active = dict(device.active).get(twomemo.twomemo.NAMESPACE) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1390 if twomemo_active is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1391 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1392 trust_ui.addLabel(D_("(not available for Twomemo)")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1393 if twomemo_active is False: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1394 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1395 trust_ui.addLabel(D_("(inactive for Twomemo)")) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
1396 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1397 oldmemo_active = dict(device.active).get(oldmemo.oldmemo.NAMESPACE) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1398 if oldmemo_active is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1399 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1400 trust_ui.addLabel(D_("(not available for Oldmemo)")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1401 if oldmemo_active is False: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1402 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1403 trust_ui.addLabel(D_("(inactive for Oldmemo)")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1404 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1405 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1406 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1407 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1408 return result |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1409 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1410 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1411 def __get_joined_muc_users( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1412 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1413 xep_0045: XEP_0045, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1414 room_jid: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1415 ) -> Set[str]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1416 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1417 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1418 @param xep_0045: A MUC plugin instance. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1419 @param room_jid: The room JID. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1420 @return: A set containing the bare JIDs of the MUC participants. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1421 @raise InternalError: if the MUC is not joined or the entity information of a |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1422 participant isn't available. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1423 """ |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1424 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1425 bare_jids: Set[str] = set() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1426 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1427 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1428 room = cast(muc.Room, xep_0045.getRoom(client, room_jid)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1429 except exceptions.NotFound as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1430 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1431 "Participant list of unjoined MUC requested." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1432 ) from e |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1433 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1434 for user in cast(Dict[str, muc.User], room.roster).values(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1435 entity = cast(Optional[SatXMPPEntity], user.entity) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1436 if entity is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1437 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1438 f"Participant list of MUC requested, but the entity information of" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1439 f" the participant {user} is not available." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1440 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1441 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1442 bare_jids.add(entity.jid.userhost()) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1443 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1444 return bare_jids |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1445 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1446 async def __prepare_for_profile(self, profile: str) -> omemo.SessionManager: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1447 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1448 @param profile: The profile to prepare for. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1449 @return: A session manager instance for this profile. Creates a new instance if |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1450 none was prepared before. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1451 """ |
2662
0bef44f8e8ca
plugin XEP-0384: PEP handling + mark as encrypted:
Goffi <goffi@goffi.org>
parents:
2654
diff
changeset
|
1452 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1453 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1454 # Try to return the session manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1455 return self.__session_managers[profile] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1456 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1457 # If a session manager for that profile doesn't exist yet, check whether it is |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1458 # currently being built. A session manager being built is signified by the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1459 # profile key existing on __session_manager_waiters. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1460 if profile in self.__session_manager_waiters: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1461 # If the session manager is being built, add ourselves to the waiting |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1462 # queue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1463 deferred = defer.Deferred() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1464 self.__session_manager_waiters[profile].append(deferred) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1465 return cast(omemo.SessionManager, await deferred) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1466 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1467 # If the session manager is not being built, do so here. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1468 self.__session_manager_waiters[profile] = [] |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1469 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1470 # Build and store the session manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1471 session_manager = await prepare_for_profile( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1472 self.__sat, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1473 profile, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1474 initial_own_label="Libervia" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1475 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1476 self.__session_managers[profile] = session_manager |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1477 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1478 # Notify the waiters and delete them |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1479 for waiter in self.__session_manager_waiters[profile]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1480 waiter.callback(session_manager) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1481 del self.__session_manager_waiters[profile] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1482 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1483 return session_manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1484 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1485 async def __message_received_trigger( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1486 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1487 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1488 message_elt: domish.Element, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1489 post_treat: defer.Deferred |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1490 ) -> bool: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1491 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1492 @param client: The client which received the message. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1493 @param message_elt: The message element. Can be modified. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1494 @param post_treat: A deferred which evaluates to a :class:`MessageData` once the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1495 message has fully progressed through the message receiving flow. Can be used |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1496 to apply treatments to the fully processed message, like marking it as |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1497 encrypted. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1498 @return: Whether to continue the message received flow. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1499 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1500 muc_plaintext_cache_key: Optional[MUCPlaintextCacheKey] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1501 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1502 sender_jid = jid.JID(message_elt["from"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1503 feedback_jid: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1504 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1505 message_type = message_elt.getAttribute("type", "unknown") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1506 is_muc_message = message_type == C.MESS_TYPE_GROUPCHAT |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1507 if is_muc_message: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1508 if self.__xep_0045 is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1509 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1510 "Ignoring MUC message since plugin XEP-0045 is not available." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1511 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1512 # Can't handle a MUC message without XEP-0045, let the flow continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1513 # normally |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1514 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1515 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1516 room_jid = feedback_jid = sender_jid.userhostJID() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1517 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1518 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1519 room = cast(muc.Room, self.__xep_0045.getRoom(client, room_jid)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1520 except exceptions.NotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1521 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1522 f"Ignoring MUC message from a room that has not been joined:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1523 f" {room_jid}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1524 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1525 # Whatever, let the flow continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1526 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1527 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1528 sender_user = cast(Optional[muc.User], room.getUser(sender_jid.resource)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1529 if sender_user is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1530 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1531 f"Ignoring MUC message from room {room_jid} since the sender's user" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1532 f" wasn't found {sender_jid.resource}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1533 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1534 # Whatever, let the flow continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1535 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1536 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1537 sender_user_jid = cast(Optional[jid.JID], sender_user.entity) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1538 if sender_user_jid is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1539 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1540 f"Ignoring MUC message from room {room_jid} since the sender's bare" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1541 f" JID couldn't be found from its user information: {sender_user}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1542 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1543 # Whatever, let the flow continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1544 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1545 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1546 sender_jid = sender_user_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1547 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1548 message_uid: Optional[str] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1549 if self.__xep_0359 is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1550 message_uid = self.__xep_0359.getOriginId(message_elt) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1551 if message_uid is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1552 message_uid = message_elt.getAttribute("id") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1553 if message_uid is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1554 muc_plaintext_cache_key = MUCPlaintextCacheKey( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1555 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1556 room_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1557 message_uid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1558 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1559 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1560 # I'm not sure why this check is required, this code is copied from the old |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1561 # plugin. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1562 if sender_jid.userhostJID() == client.jid.userhostJID(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1563 # TODO: I've seen this cause an exception "builtins.KeyError: 'to'", seems |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1564 # like "to" isn't always set. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1565 feedback_jid = jid.JID(message_elt["to"]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1566 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1567 feedback_jid = sender_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1568 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1569 sender_bare_jid = sender_jid.userhost() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1570 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1571 message: Optional[omemo.Message] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1572 encrypted_elt: Optional[domish.Element] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1573 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1574 twomemo_encrypted_elt = cast(Optional[domish.Element], next( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1575 message_elt.elements(twomemo.twomemo.NAMESPACE, "encrypted"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1576 None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1577 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1578 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1579 oldmemo_encrypted_elt = cast(Optional[domish.Element], next( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1580 message_elt.elements(oldmemo.oldmemo.NAMESPACE, "encrypted"), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1581 None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1582 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1583 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1584 session_manager = await self.__prepare_for_profile(cast(str, client.profile)) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1585 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1586 if twomemo_encrypted_elt is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1587 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1588 message = twomemo.etree.parse_message( |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1589 xml_tools.domish_elt_2_et_elt(twomemo_encrypted_elt), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1590 sender_bare_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1591 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1592 except (ValueError, XMLSchemaValidationError): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1593 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1594 f"Ingoring malformed encrypted message for namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1595 f" {twomemo.twomemo.NAMESPACE}: {twomemo_encrypted_elt.toXml()}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1596 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1597 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1598 encrypted_elt = twomemo_encrypted_elt |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1599 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1600 if oldmemo_encrypted_elt is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1601 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1602 message = await oldmemo.etree.parse_message( |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1603 xml_tools.domish_elt_2_et_elt(oldmemo_encrypted_elt), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1604 sender_bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1605 client.jid.userhost(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1606 session_manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1607 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1608 except (ValueError, XMLSchemaValidationError): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1609 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1610 f"Ingoring malformed encrypted message for namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1611 f" {oldmemo.oldmemo.NAMESPACE}: {oldmemo_encrypted_elt.toXml()}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1612 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1613 except omemo.SenderNotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1614 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1615 f"Ingoring encrypted message for namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1616 f" {oldmemo.oldmemo.NAMESPACE} by unknown sender:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1617 f" {oldmemo_encrypted_elt.toXml()}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1618 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1619 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1620 encrypted_elt = oldmemo_encrypted_elt |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1621 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1622 if message is None or encrypted_elt is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1623 # None of our business, let the flow continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1624 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1625 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1626 message_elt.children.remove(encrypted_elt) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1627 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1628 log.debug( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1629 f"{message.namespace} message of type {message_type} received from" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1630 f" {sender_bare_jid}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1631 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1632 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1633 plaintext: Optional[bytes] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1634 device_information: omemo.DeviceInformation |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1635 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1636 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1637 muc_plaintext_cache_key is not None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1638 and muc_plaintext_cache_key in self.__muc_plaintext_cache |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1639 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1640 # Use the cached plaintext |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1641 plaintext = self.__muc_plaintext_cache.pop(muc_plaintext_cache_key) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1642 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1643 # Since this message was sent by us, use the own device information here |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1644 device_information, __ = await session_manager.get_own_device_information() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1645 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1646 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1647 plaintext, device_information = await session_manager.decrypt(message) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1648 except omemo.MessageNotForUs: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1649 # The difference between this being a debug or a warning is whether there |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1650 # is a body included in the message. Without a body, we can assume that |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1651 # it's an empty OMEMO message used for protocol stability reasons, which |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1652 # is not expected to be sent to all devices of all recipients. If a body |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1653 # is included, we can assume that the message carries content and we |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1654 # missed out on something. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1655 if len(list(message_elt.elements(C.NS_CLIENT, "body"))) > 0: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1656 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1657 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1658 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1659 f"An OMEMO message from {sender_jid.full()} has not been" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1660 f" encrypted for our device, we can't decrypt it." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1661 ), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1662 { C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1663 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1664 log.warning("Message not encrypted for us.") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1665 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1666 log.debug("Message not encrypted for us.") |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1667 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1668 # No point in further processing this message. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1669 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1670 except Exception as e: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1671 log.warning(_("Can't decrypt message: {reason}\n{xml}").format( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1672 reason=e, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1673 xml=message_elt.toXml() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1674 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1675 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1676 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1677 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1678 f"An OMEMO message from {sender_jid.full()} can't be decrypted:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1679 f" {e}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1680 ), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1681 { C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1682 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1683 # No point in further processing this message |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1684 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1685 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1686 if message.namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1687 if plaintext is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1688 # XEP_0420.unpack_stanza handles the whole unpacking, including the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1689 # relevant modifications to the element |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1690 sce_profile = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1691 OMEMO.SCE_PROFILE_GROUPCHAT if is_muc_message else OMEMO.SCE_PROFILE |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1692 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1693 affix_values = self.__xep_0420.unpack_stanza( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1694 sce_profile, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1695 message_elt, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1696 plaintext |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1697 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1698 except Exception as e: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1699 log.warning(D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1700 f"Error unpacking SCE-encrypted message: {e}\n{plaintext}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1701 )) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1702 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1703 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1704 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1705 f"An OMEMO message from {sender_jid.full()} was rejected:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1706 f" {e}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1707 ), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1708 { C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1709 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1710 # No point in further processing this message |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1711 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1712 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1713 if affix_values.timestamp is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1714 # TODO: affix_values.timestamp contains the timestamp included in the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1715 # encrypted element here. The XEP says it SHOULD be displayed with the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1716 # plaintext by clients. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1717 pass |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1718 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1719 if message.namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1720 # Remove all body elements from the original element, since those act as |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1721 # fallbacks in case the encryption protocol is not supported |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1722 for child in message_elt.elements(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1723 if child.name == "body": |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1724 message_elt.children.remove(child) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1725 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1726 if plaintext is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1727 # Add the decrypted body |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1728 message_elt.addElement("body", content=plaintext.decode("utf-8")) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1729 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1730 # Mark the message as trusted or untrusted. Undecided counts as untrusted here. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1731 trust_level = \ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1732 TrustLevel(device_information.trust_level_name).to_omemo_trust_level() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1733 if trust_level is omemo.TrustLevel.TRUSTED: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1734 post_treat.addCallback(client.encryption.markAsTrusted) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1735 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1736 post_treat.addCallback(client.encryption.markAsUntrusted) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1737 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1738 # Mark the message as originally encrypted |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1739 post_treat.addCallback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1740 client.encryption.markAsEncrypted, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1741 namespace=message.namespace |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1742 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1743 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1744 # Message processed successfully, continue with the flow |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1745 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1746 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1747 async def __send_trigger(self, client: SatXMPPClient, stanza: domish.Element) -> bool: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1748 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1749 @param client: The client sending this message. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1750 @param stanza: The stanza that is about to be sent. Can be modified. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1751 @return: Whether the send message flow should continue or not. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1752 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1753 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1754 # SCE is only applicable to message and IQ stanzas |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1755 if stanza.name not in { "message", "iq" }: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1756 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1757 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1758 # Get the intended recipient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1759 recipient = stanza.getAttribute("to", None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1760 if recipient is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1761 if stanza.name == "message": |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1762 # Message stanzas must have a recipient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1763 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1764 f"Message without recipient encountered. Blocking further processing" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1765 f" to avoid leaking plaintext data: {stanza.toXml()}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1766 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1767 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1768 # IQs without a recipient are a thing, I believe those simply target the |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1769 # server and are thus not eligible for e2ee anyway. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1770 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1771 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1772 # Parse the JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1773 recipient_bare_jid = jid.JID(recipient).userhostJID() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1774 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1775 # Check whether encryption with twomemo is requested |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1776 encryption = client.encryption.getSession(recipient_bare_jid) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1777 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1778 if encryption is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1779 # Encryption is not requested for this recipient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1780 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1781 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1782 if encryption["plugin"].namespace != twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1783 # Encryption is requested for this recipient, but not with twomemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1784 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1785 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1786 # All pre-checks done, we can start encrypting! |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1787 await self.__encrypt( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1788 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1789 twomemo.twomemo.NAMESPACE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1790 stanza, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1791 recipient_bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1792 stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1793 stanza.getAttribute("id", None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1794 ) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1795 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1796 # Add a store hint if this is a message stanza |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1797 if stanza.name == "message": |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1798 self.__xep_0334.addHintElements(stanza, [ "store" ]) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1799 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1800 # Let the flow continue. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1801 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1802 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1803 async def __send_message_data_trigger( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1804 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1805 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1806 mess_data: MessageData |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1807 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1808 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1809 @param client: The client sending this message. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1810 @param mess_data: The message data that is about to be sent. Can be modified. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1811 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1812 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1813 # Check whether encryption is requested for this message |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1814 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1815 namespace = mess_data[C.MESS_KEY_ENCRYPTION]["plugin"].namespace |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1816 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1817 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1818 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1819 # If encryption is requested, check whether it's oldmemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1820 if namespace != oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1821 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1822 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1823 # All pre-checks done, we can start encrypting! |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1824 stanza = mess_data["xml"] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1825 recipient_jid = mess_data["to"] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1826 is_muc_message = mess_data["type"] == C.MESS_TYPE_GROUPCHAT |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1827 stanza_id = mess_data["uid"] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1828 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1829 await self.__encrypt( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1830 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1831 oldmemo.oldmemo.NAMESPACE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1832 stanza, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1833 recipient_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1834 is_muc_message, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1835 stanza_id |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1836 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1837 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1838 # Add a store hint |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1839 self.__xep_0334.addHintElements(stanza, [ "store" ]) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1840 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1841 async def __encrypt( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1842 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1843 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1844 namespace: Literal["urn:xmpp:omemo:2", "eu.siacs.conversations.axolotl"], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1845 stanza: domish.Element, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1846 recipient_jid: jid.JID, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1847 is_muc_message: bool, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1848 stanza_id: Optional[str] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1849 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1850 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1851 @param client: The client. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1852 @param namespace: The namespace of the OMEMO version to use. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1853 @param stanza: The stanza. Twomemo will encrypt the whole stanza using SCE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1854 oldmemo will encrypt only the body. The stanza is modified by this call. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1855 @param recipient_jid: The JID of the recipient. Can be a bare (aka "userhost") JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1856 but doesn't have to. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1857 @param is_muc_message: Whether the stanza is a message stanza to a MUC room. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1858 @param stanza_id: The id of this stanza. Especially relevant for message stanzas |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1859 to MUC rooms such that the outgoing plaintext can be cached for MUC message |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1860 reflection handling. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1861 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1862 @warning: The calling code MUST take care of adding the store message processing |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1863 hint to the stanza if applicable! This can be done before or after this call, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1864 the order doesn't matter. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1865 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1866 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1867 muc_plaintext_cache_key: Optional[MUCPlaintextCacheKey] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1868 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1869 recipient_bare_jids: Set[str] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1870 feedback_jid: jid.JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1871 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1872 if is_muc_message: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1873 if self.__xep_0045 is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1874 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1875 "Encryption of MUC message requested, but plugin XEP-0045 is not" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1876 " available." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1877 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1878 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1879 if stanza_id is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1880 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1881 "Encryption of MUC message requested, but stanza id not available." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1882 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1883 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1884 room_jid = feedback_jid = recipient_jid.userhostJID() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1885 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1886 recipient_bare_jids = self.__get_joined_muc_users( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1887 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1888 self.__xep_0045, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1889 room_jid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1890 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1891 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1892 muc_plaintext_cache_key = MUCPlaintextCacheKey( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1893 client=client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1894 room_jid=room_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1895 message_uid=stanza_id |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1896 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1897 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1898 recipient_bare_jids = { recipient_jid.userhost() } |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1899 feedback_jid = recipient_jid.userhostJID() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1900 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1901 log.debug( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1902 f"Intercepting message that is to be encrypted by {namespace} for" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1903 f" {recipient_bare_jids}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1904 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1905 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1906 def prepare_stanza() -> Optional[bytes]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1907 """Prepares the stanza for encryption. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1908 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1909 Does so by removing all parts that are not supposed to be sent in plain. Also |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1910 extracts/prepares the plaintext to encrypt. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1911 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1912 @return: The plaintext to encrypt. Returns ``None`` in case body-only |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1913 encryption is requested and no body was found. The function should |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1914 gracefully return in that case, i.e. it's not a critical error that should |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1915 abort the message sending flow. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1916 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1917 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1918 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1919 return self.__xep_0420.pack_stanza( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1920 OMEMO.SCE_PROFILE_GROUPCHAT if is_muc_message else OMEMO.SCE_PROFILE, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1921 stanza |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1922 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1923 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1924 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1925 plaintext: Optional[bytes] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1926 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1927 for child in stanza.elements(): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1928 if child.name == "body" and plaintext is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1929 plaintext = str(child).encode("utf-8") |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1930 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1931 # Any other sensitive elements to remove here? |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1932 if child.name in { "body", "html" }: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1933 stanza.children.remove(child) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1934 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1935 if plaintext is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1936 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1937 "No body found in intercepted message to be encrypted with" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1938 " oldmemo." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1939 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1940 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1941 return plaintext |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1942 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1943 return assert_never(namespace) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1944 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1945 # The stanza/plaintext preparation was moved into its own little function for type |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1946 # safety reasons. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1947 plaintext = prepare_stanza() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1948 if plaintext is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1949 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1950 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1951 log.debug(f"Plaintext to encrypt: {plaintext}") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1952 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1953 session_manager = await self.__prepare_for_profile(client.profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1954 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1955 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1956 messages, encryption_errors = await session_manager.encrypt( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1957 frozenset(recipient_bare_jids), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1958 { namespace: plaintext }, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1959 backend_priority_order=[ namespace ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1960 identifier=feedback_jid.userhost() |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1961 ) |
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1962 except Exception as e: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1963 msg = _( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1964 # pylint: disable=consider-using-f-string |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1965 "Can't encrypt message for {entities}: {reason}".format( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1966 entities=', '.join(recipient_bare_jids), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1967 reason=e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1968 ) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1969 ) |
2859
4e875d9eea48
plugin XEP-0384: give feedback to client when encryption failed
Goffi <goffi@goffi.org>
parents:
2858
diff
changeset
|
1970 log.warning(msg) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1971 client.feedback(feedback_jid, msg, { |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1972 C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1973 }) |
2858
31a5038cdf79
plugin XEP-0384: small refactoring to encrypt messages + bugfix:
Goffi <goffi@goffi.org>
parents:
2857
diff
changeset
|
1974 raise e |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1975 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1976 if len(encryption_errors) > 0: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1977 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1978 f"Ignored the following non-critical encryption errors:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1979 f" {encryption_errors}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1980 ) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
1981 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1982 encrypted_errors_stringified = ", ".join([ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1983 f"device {err.device_id} of {err.bare_jid} under namespace" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1984 f" {err.namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1985 for err |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1986 in encryption_errors |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1987 ]) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
1988 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1989 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1990 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1991 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1992 "There were non-critical errors during encryption resulting in some" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1993 " of your destinees' devices potentially not receiving the message." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1994 " This happens when the encryption data/key material of a device is" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1995 " incomplete or broken, which shouldn't happen for actively used" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1996 " devices, and can usually be ignored. The following devices are" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1997 f" affected: {encrypted_errors_stringified}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1998 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1999 ) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2000 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2001 message = next(message for message in messages if message.namespace == namespace) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
2002 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2003 if namespace == twomemo.twomemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2004 # Add the encrypted element |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
2005 stanza.addChild(xml_tools.et_elt_2_domish_elt(twomemo.etree.serialize_message(message))) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2006 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2007 if namespace == oldmemo.oldmemo.NAMESPACE: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2008 # Add the encrypted element |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
2009 stanza.addChild(xml_tools.et_elt_2_domish_elt(oldmemo.etree.serialize_message(message))) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2010 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2011 if muc_plaintext_cache_key is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2012 self.__muc_plaintext_cache[muc_plaintext_cache_key] = plaintext |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2013 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2014 async def __on_device_list_update( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2015 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2016 items_event: pubsub.ItemsEvent, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2017 profile: str |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2018 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2019 """Handle device list updates fired by PEP. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2020 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2021 @param items_event: The event. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2022 @param profile: The profile this event belongs to. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2023 """ |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2024 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2025 sender = cast(jid.JID, items_event.sender) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2026 items = cast(List[domish.Element], items_event.items) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2027 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2028 if len(items) > 1: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2029 log.warning("Ignoring device list update with more than one element.") |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2030 return |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2031 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2032 item = next(iter(items), None) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2033 if item is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2034 log.debug("Ignoring empty device list update.") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2035 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2036 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
2037 item_elt = xml_tools.domish_elt_2_et_elt(item) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2038 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2039 device_list: Dict[int, Optional[str]] = {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2040 namespace: Optional[str] = None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2041 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2042 list_elt = item_elt.find(f"{{{twomemo.twomemo.NAMESPACE}}}devices") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2043 if list_elt is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2044 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2045 device_list = twomemo.etree.parse_device_list(list_elt) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2046 except XMLSchemaValidationError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2047 pass |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2048 else: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2049 namespace = twomemo.twomemo.NAMESPACE |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2050 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2051 list_elt = item_elt.find(f"{{{oldmemo.oldmemo.NAMESPACE}}}list") |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2052 if list_elt is not None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2053 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2054 device_list = oldmemo.etree.parse_device_list(list_elt) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2055 except XMLSchemaValidationError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2056 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2057 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2058 namespace = oldmemo.oldmemo.NAMESPACE |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2059 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2060 if namespace is None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2061 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2062 f"Malformed device list update item:" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2063 f" {ET.tostring(item_elt, encoding='unicode')}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2064 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2065 return |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2066 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2067 session_manager = await self.__prepare_for_profile(profile) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2068 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2069 await session_manager.update_device_list( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2070 namespace, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2071 sender.userhost(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2072 device_list |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2073 ) |