Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0384.py @ 4281:9e63e02318ec
core: show warning instead of exception in case of missing dependency when loading plugins
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 12 Jul 2024 18:53:00 +0200 |
parents | 0d7bb4df2343 |
children | 23842a63ea00 |
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 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
19 import base64 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
20 from datetime import datetime |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
21 import enum |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
22 import logging |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
23 import time |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
24 from typing import ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
25 Any, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
26 Dict, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
27 FrozenSet, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
28 Iterable, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
29 List, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
30 Literal, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
31 NamedTuple, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
32 Optional, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
33 Set, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
34 Type, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
35 Union, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
36 cast, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
37 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
38 import uuid |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
39 import xml.etree.ElementTree as ET |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
40 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
|
41 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
42 from typing_extensions import Final, Never, assert_never |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
43 from wokkel import muc, pubsub # type: ignore[import] |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
44 import xmlschema |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
45 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
46 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
47 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
48 from libervia.backend.core.core_types import MessageData, SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
49 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
50 from libervia.backend.core.log import getLogger, Logger |
4073
7c5654c54fed
refactoring: rename `core.sat_main` to `core.main`
Goffi <goffi@goffi.org>
parents:
4072
diff
changeset
|
51 from libervia.backend.core.main import LiberviaBackend |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
52 from libervia.backend.core.xmpp import SatXMPPClient |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
53 from libervia.backend.memory import persistent |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
54 from libervia.backend.plugins.plugin_misc_text_commands import TextCommands |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
55 from libervia.backend.plugins.plugin_xep_0045 import XEP_0045 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
56 from libervia.backend.plugins.plugin_xep_0060 import XEP_0060 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
57 from libervia.backend.plugins.plugin_xep_0163 import XEP_0163 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
58 from libervia.backend.plugins.plugin_xep_0334 import XEP_0334 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
59 from libervia.backend.plugins.plugin_xep_0359 import XEP_0359 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
60 from libervia.backend.plugins.plugin_xep_0420 import ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
61 XEP_0420, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
62 SCEAffixPolicy, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
63 SCEAffixValues, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
64 SCEProfile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
65 ) |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
66 from libervia.backend.tools import xml_tools |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
67 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
|
68 from twisted.words.protocols.jabber import error, jid |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 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
|
70 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 try: |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 import omemo |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
73 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
|
74 import twomemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
75 import twomemo.etree |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
76 import oldmemo |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
77 import oldmemo.etree |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
78 import oldmemo.migrations |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
79 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
|
80 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
81 # 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
|
82 # 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
|
83 # attempted. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
84 except ImportError as import_error: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 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
|
86 "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
|
87 " download/install the pip packages 'omemo', 'twomemo', 'oldmemo' and" |
3976
db45d49518f6
plugin XEP-0384: log `import_error` when import is failing
Goffi <goffi@goffi.org>
parents:
3972
diff
changeset
|
88 f" 'xmlschema'.\nexception: {import_error}" |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
89 ) from import_error |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
90 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
92 __all__ = ["PLUGIN_INFO", "OMEMO"] # pylint: disable=unused-variable |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
93 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
94 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
|
95 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
96 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 PLUGIN_INFO = { |
3028 | 98 C.PI_NAME: "OMEMO", |
99 C.PI_IMPORT_NAME: "XEP-0384", | |
100 C.PI_TYPE: "SEC", | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
101 C.PI_PROTOCOLS: ["XEP-0384"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
102 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0280", "XEP-0334", "XEP-0060", "XEP-0420"], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
103 C.PI_RECOMMENDATIONS: ["XEP-0045", "XEP-0359", C.TEXT_CMDS], |
3028 | 104 C.PI_MAIN: "OMEMO", |
105 C.PI_HANDLER: "no", | |
106 C.PI_DESCRIPTION: _("""Implementation of OMEMO"""), | |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 } |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
110 PARAM_CATEGORY = "Security" |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
111 PARAM_NAME = "omemo_policy" |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
112 |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
113 NamespaceType = Literal["urn:xmpp:omemo:2", "eu.siacs.conversations.axolotl"] |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
114 |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
116 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
|
117 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
118 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
|
119 """ |
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
|
120 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
121 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
|
122 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
|
123 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
124 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
130 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 |
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 # 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
|
138 # 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
|
139 |
e7bfbded652a
plugin XEP-0384, install: adapted plugin to omemo module changes + added omemo module to dependencies:
Goffi <goffi@goffi.org>
parents:
2648
diff
changeset
|
140 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
141 class MUCPlaintextCacheKey(NamedTuple): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
142 # 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
|
143 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
144 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
|
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 client: SatXMPPClient |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
148 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
|
149 message_uid: str |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
150 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
151 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
152 @enum.unique |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
153 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
|
154 """ |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
155 The trust levels required for ATM and BTBV. |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
156 """ |
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 TRUSTED: str = "TRUSTED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
159 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
|
160 UNDECIDED: str = "UNDECIDED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
161 DISTRUSTED: str = "DISTRUSTED" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
162 |
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 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
|
165 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
|
166 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
167 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
168 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
|
169 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
170 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
|
171 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
172 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
173 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
|
174 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
175 @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
|
176 """ |
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 # 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
|
179 # 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
|
180 super().__init__() |
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 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
|
183 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
184 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
|
185 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
186 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
|
187 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
188 return omemo.Nothing() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
189 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
|
190 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
|
191 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
192 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
|
193 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
198 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
|
199 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
200 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
|
201 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
202 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
203 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
|
204 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
|
205 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
207 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
|
208 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
209 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
|
210 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
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 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
|
213 KEY_STATE = "STATE" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
214 KEY_SESSION = "SESSION" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
215 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
|
216 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
|
217 KEY_TRUST = "TRUST" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
218 KEY_ALL_JIDS = "ALL_JIDS" |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
220 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
|
221 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
222 @param profile: The profile this OMEMO data belongs to. |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
223 @param own_bare_jid: The own bare JID, to return by the :meth:`load_own_data` call. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 """ |
3911
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 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
|
227 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
|
228 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 return None |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
233 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
234 return oldmemo.migrations.OwnData( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
235 own_bare_jid=self.__own_bare_jid, own_device_id=own_device_id |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
236 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
237 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
238 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
|
239 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
240 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
|
241 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
242 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
243 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
244 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
|
245 return cast( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
246 Optional[oldmemo.migrations.State], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
247 await self.__storage.get(LegacyStorageImpl.KEY_STATE, None), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
248 ) |
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 deleteState(self) -> 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.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
|
253 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
254 pass |
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 loadSession( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
257 self, bare_jid: str, device_id: int |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
258 ) -> Optional[oldmemo.migrations.Session]: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
259 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
|
260 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
261 return cast( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
262 Optional[oldmemo.migrations.Session], await self.__storage.get(key, None) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
263 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
264 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
265 async def deleteSession(self, bare_jid: str, device_id: int) -> None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
266 key = "\n".join([LegacyStorageImpl.KEY_SESSION, bare_jid, str(device_id)]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
267 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
268 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
269 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
|
270 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
271 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
272 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
273 async def loadActiveDevices(self, bare_jid: str) -> Optional[List[int]]: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
274 key = "\n".join([LegacyStorageImpl.KEY_ACTIVE_DEVICES, bare_jid]) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
275 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
276 return cast(Optional[List[int]], await self.__storage.get(key, None)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
277 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
278 async def loadInactiveDevices(self, bare_jid: str) -> Optional[Dict[int, int]]: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
279 key = "\n".join([LegacyStorageImpl.KEY_INACTIVE_DEVICES, bare_jid]) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
280 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
281 return cast(Optional[Dict[int, int]], await self.__storage.get(key, None)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
282 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
283 async def deleteActiveDevices(self, bare_jid: str) -> None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
284 key = "\n".join([LegacyStorageImpl.KEY_ACTIVE_DEVICES, bare_jid]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
285 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
286 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
287 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
|
288 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
289 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
290 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
291 async def deleteInactiveDevices(self, bare_jid: str) -> None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
292 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
|
293 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
294 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
295 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
|
296 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
297 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
298 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
299 async def loadTrust( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
300 self, bare_jid: str, device_id: int |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
301 ) -> Optional[oldmemo.migrations.Trust]: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
302 key = "\n".join([LegacyStorageImpl.KEY_TRUST, bare_jid, str(device_id)]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
303 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
304 return cast( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
305 Optional[oldmemo.migrations.Trust], await self.__storage.get(key, None) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
306 ) |
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 async def deleteTrust(self, bare_jid: str, device_id: int) -> None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
309 key = "\n".join([LegacyStorageImpl.KEY_TRUST, bare_jid, str(device_id)]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
310 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
311 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
312 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
|
313 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
314 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
315 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
316 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
|
317 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
|
318 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
319 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
|
320 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
321 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
|
322 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
323 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
|
324 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
325 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
326 |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
327 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
328 async def download_oldmemo_bundle( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
329 client: SatXMPPClient, xep_0060: XEP_0060, bare_jid: str, device_id: int |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
330 ) -> oldmemo.oldmemo.BundleImpl: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
331 """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
|
332 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
333 @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
|
334 @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
|
335 @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
|
336 @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
|
337 @return: The bundle. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
338 @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
|
339 instead. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
340 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
341 # 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
|
342 # 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
|
343 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
344 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
|
345 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
|
346 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
347 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
348 items, __ = await xep_0060.get_items(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
|
349 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
|
350 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
351 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
|
352 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
353 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
354 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
355 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
|
356 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
357 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
|
358 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
|
359 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
360 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
361 element = next( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
362 iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), None |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
363 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
364 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
|
365 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
366 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
|
367 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
|
368 ) |
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
369 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
370 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
371 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
|
372 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
|
373 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
374 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
|
375 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
376 ) from e |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
379 # ATM only supports protocols based on SCE, which is currently only omemo:2, and relies on |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
380 # so many implementation details of the encryption protocol that it makes more sense to |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
381 # add ATM to the OMEMO plugin directly instead of having it a separate Libervia plugin. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
382 NS_TM: Final = "urn:xmpp:tm:1" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
383 NS_ATM: Final = "urn:xmpp:atm:1" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
384 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
385 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
386 TRUST_MESSAGE_SCHEMA = xmlschema.XMLSchema( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
387 """<?xml version='1.0' encoding='UTF-8'?> |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
388 <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
389 targetNamespace='urn:xmpp:tm:1' |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
390 xmlns='urn:xmpp:tm:1' |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
391 elementFormDefault='qualified'> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
392 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
393 <xs:element name='trust-message'> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
394 <xs:complexType> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
395 <xs:sequence> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
396 <xs:element ref='key-owner' minOccurs='1' maxOccurs='unbounded'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
397 </xs:sequence> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
398 <xs:attribute name='usage' type='xs:string' use='required'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
399 <xs:attribute name='encryption' type='xs:string' use='required'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
400 </xs:complexType> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
401 </xs:element> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
402 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
403 <xs:element name='key-owner'> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
404 <xs:complexType> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
405 <xs:sequence> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
406 <xs:element |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
407 name='trust' type='xs:base64Binary' minOccurs='0' maxOccurs='unbounded'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
408 <xs:element |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
409 name='distrust' type='xs:base64Binary' minOccurs='0' maxOccurs='unbounded'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
410 </xs:sequence> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
411 <xs:attribute name='jid' type='xs:string' use='required'/> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
412 </xs:complexType> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
413 </xs:element> |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
414 </xs:schema> |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
415 """ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
416 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
417 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
418 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
419 # This is compatible with omemo:2's SCE profile |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
420 TM_SCE_PROFILE = SCEProfile( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
421 rpad_policy=SCEAffixPolicy.REQUIRED, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
422 time_policy=SCEAffixPolicy.REQUIRED, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
423 to_policy=SCEAffixPolicy.OPTIONAL, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
424 from_policy=SCEAffixPolicy.OPTIONAL, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
425 custom_policies={}, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
426 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
427 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
428 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
429 class TrustUpdate(NamedTuple): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
430 # pylint: disable=invalid-name |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
431 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
432 An update to the trust status of an identity key, used by Automatic Trust Management. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
433 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
434 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
435 target_jid: jid.JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
436 target_key: bytes |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
437 target_trust: bool |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
438 |
4216 | 439 def to_dict(self) -> dict[str, Any]: |
440 """Convert the instance to a serialised dictionary""" | |
441 data = { | |
442 "target_jid": self.target_jid.full(), | |
443 "target_key": self.target_key.hex(), | |
444 "target_trust": self.target_trust, | |
445 } | |
446 return data | |
447 | |
448 @staticmethod | |
449 def from_dict(data: dict[str, Any]) -> "TrustUpdate": | |
450 """Load a serialized dictionary""" | |
451 data["target_jid"] = jid.JID(data["target_jid"]) | |
452 data["target_key"] = bytes.fromhex(data["target_key"]) | |
453 return TrustUpdate(**data) | |
454 | |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
455 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
456 class TrustMessageCacheEntry(NamedTuple): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
457 # pylint: disable=invalid-name |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
458 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
459 An entry in the trust message cache used by ATM. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
460 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
461 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
462 sender_jid: jid.JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
463 sender_key: bytes |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
464 timestamp: datetime |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
465 trust_update: TrustUpdate |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
466 |
4216 | 467 def to_dict(self) -> dict[str, Any]: |
468 """Convert the instance to a serialised dictionary""" | |
469 data = { | |
470 "sender_jid": self.sender_jid.full(), | |
471 "sender_key": self.sender_key.hex(), | |
472 "timestamp": self.timestamp.isoformat(), | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
473 "trust_update": self.trust_update.to_dict(), |
4216 | 474 } |
475 return data | |
476 | |
477 @staticmethod | |
478 def from_dict(data: dict[str, Any]) -> "TrustMessageCacheEntry": | |
479 """Load a serialized dictionary""" | |
480 data["sender_jid"] = jid.JID(data["sender_jid"]) | |
481 data["sender_key"] = bytes.fromhex(data["sender_key"]) | |
482 data["timestamp"] = datetime.fromisoformat(data["timestamp"]) | |
483 data["trust_update"] = TrustUpdate.from_dict(data["trust_update"]) | |
484 return TrustMessageCacheEntry(**data) | |
485 | |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
486 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
487 class PartialTrustMessage(NamedTuple): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
488 # pylint: disable=invalid-name |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
489 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
490 A structure representing a partial trust message, used by :func:`send_trust_messages` |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
491 to build trust messages. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
492 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
493 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
494 recipient_jid: jid.JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
495 updated_jid: jid.JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
496 trust_updates: FrozenSet[TrustUpdate] |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
497 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
498 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
499 async def manage_trust_message_cache( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
500 client: SatXMPPClient, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
501 session_manager: omemo.SessionManager, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
502 applied_trust_updates: FrozenSet[TrustUpdate], |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
503 ) -> None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
504 """Manage the ATM trust message cache after trust updates have been applied. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
505 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
506 @param client: The client this operation runs under. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
507 @param session_manager: The session manager to use. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
508 @param applied_trust_updates: The trust updates that have already been applied, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
509 triggering this cache management run. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
510 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
511 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
512 trust_message_cache = persistent.LazyPersistentBinaryDict( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
513 "XEP-0384/TM", client.profile |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
514 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
515 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
516 # Load cache entries |
4216 | 517 cache_entries = { |
518 TrustMessageCacheEntry.from_dict(d) | |
519 for d in await trust_message_cache.get("cache", []) | |
520 } | |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
521 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
522 # Expire cache entries that were overwritten by the applied trust updates |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
523 cache_entries_by_target = { |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
524 ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
525 cache_entry.trust_update.target_jid.userhostJID(), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
526 cache_entry.trust_update.target_key, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
527 ): cache_entry |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
528 for cache_entry in cache_entries |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
529 } |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
530 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
531 for trust_update in applied_trust_updates: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
532 cache_entry = cache_entries_by_target.get( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
533 (trust_update.target_jid.userhostJID(), trust_update.target_key), None |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
534 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
535 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
536 if cache_entry is not None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
537 cache_entries.remove(cache_entry) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
538 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
539 # Apply cached Trust Messages by newly trusted devices |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
540 new_trust_updates: Set[TrustUpdate] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
541 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
542 for trust_update in applied_trust_updates: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
543 if trust_update.target_trust: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
544 # Iterate over a copy such that cache_entries can be modified |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
545 for cache_entry in set(cache_entries): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
546 if ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
547 cache_entry.sender_jid.userhostJID() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
548 == trust_update.target_jid.userhostJID() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
549 and cache_entry.sender_key == trust_update.target_key |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
550 ): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
551 trust_level = ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
552 TrustLevel.TRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
553 if cache_entry.trust_update.target_trust |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
554 else TrustLevel.DISTRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
555 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
556 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
557 # Apply the trust update |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
558 await session_manager.set_trust( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
559 cache_entry.trust_update.target_jid.userhost(), |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
560 cache_entry.trust_update.target_key, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
561 trust_level.name, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
562 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
563 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
564 # Track the fact that this trust update has been applied |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
565 new_trust_updates.add(cache_entry.trust_update) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
566 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
567 # Remove the corresponding cache entry |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
568 cache_entries.remove(cache_entry) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
569 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
570 # Store the updated cache entries |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
571 await trust_message_cache.force("cache", [tm.to_dict() for tm in cache_entries]) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
572 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
573 # TODO: Notify the user ("feedback") about automatically updated trust? |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
574 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
575 if len(new_trust_updates) > 0: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
576 # If any trust has been updated, recursively perform another run of cache |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
577 # management |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
578 await manage_trust_message_cache( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
579 client, session_manager, frozenset(new_trust_updates) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
580 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
581 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
582 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
583 async def get_trust_as_trust_updates( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
584 session_manager: omemo.SessionManager, target_jid: jid.JID |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
585 ) -> FrozenSet[TrustUpdate]: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
586 """Get the trust status of all known keys of a JID as trust updates for use with ATM. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
587 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
588 @param session_manager: The session manager to load the trust from. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
589 @param target_jid: The JID to load the trust for. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
590 @return: The trust updates encoding the trust status of all known keys of the JID that |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
591 are either explicitly trusted or distrusted. Undecided keys are not included in |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
592 the trust updates. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
593 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
594 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
595 devices = await session_manager.get_device_information(target_jid.userhost()) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
596 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
597 trust_updates: Set[TrustUpdate] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
598 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
599 for device in devices: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
600 trust_level = TrustLevel(device.trust_level_name) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
601 target_trust: bool |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
602 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
603 if trust_level is TrustLevel.TRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
604 target_trust = True |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
605 elif trust_level is TrustLevel.DISTRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
606 target_trust = False |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
607 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
608 # Skip devices that are not explicitly trusted or distrusted |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
609 continue |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
610 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
611 trust_updates.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
612 TrustUpdate( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
613 target_jid=target_jid.userhostJID(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
614 target_key=device.identity_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
615 target_trust=target_trust, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
616 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
617 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
618 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
619 return frozenset(trust_updates) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
620 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
621 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
622 async def send_trust_messages( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
623 client: SatXMPPClient, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
624 session_manager: omemo.SessionManager, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
625 applied_trust_updates: FrozenSet[TrustUpdate], |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
626 ) -> None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
627 """Send information about updated trust to peers via ATM (XEP-0450). |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
628 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
629 @param client: The client. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
630 @param session_manager: The session manager. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
631 @param applied_trust_updates: The trust updates that have already been applied, to |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
632 notify other peers about. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
633 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
634 # NOTE: This currently sends information about oldmemo trust too. This is not |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
635 # specified and experimental, but since twomemo and oldmemo share the same identity |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
636 # keys and trust systems, this could be a cool side effect. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
637 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
638 # Send Trust Messages for newly trusted and distrusted devices |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
639 own_jid = client.jid.userhostJID() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
640 own_trust_updates = await get_trust_as_trust_updates(session_manager, own_jid) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
641 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
642 # JIDs of which at least one device's trust has been updated |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
643 updated_jids = frozenset( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
644 {trust_update.target_jid.userhostJID() for trust_update in applied_trust_updates} |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
645 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
646 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
647 trust_messages: Set[PartialTrustMessage] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
648 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
649 for updated_jid in updated_jids: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
650 # Get the trust updates for that JID |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
651 trust_updates = frozenset( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
652 { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
653 trust_update |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
654 for trust_update in applied_trust_updates |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
655 if trust_update.target_jid.userhostJID() == updated_jid |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
656 } |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
657 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
658 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
659 if updated_jid == own_jid: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
660 # If the own JID is updated, _all_ peers have to be notified |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
661 # TODO: Using my author's privilege here to shamelessly access private fields |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
662 # and storage keys until I've added public API to get a list of peers to |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
663 # python-omemo. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
664 storage: omemo.Storage = getattr(session_manager, "_SessionManager__storage") |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
665 peer_jids = frozenset( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
666 { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
667 jid.JID(bare_jid).userhostJID() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
668 for bare_jid in ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
669 await storage.load_list(f"/{OMEMO.NS_TWOMEMO}/bare_jids", str) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
670 ).maybe([]) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
671 } |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
672 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
673 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
674 if len(peer_jids) == 0: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
675 # If there are no peers to notify, notify our other devices about the |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
676 # changes directly |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
677 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
678 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
679 recipient_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
680 updated_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
681 trust_updates=trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
682 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
683 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
684 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
685 # Otherwise, notify all peers about the changes in trust and let carbons |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
686 # handle the copy to our own JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
687 for peer_jid in peer_jids: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
688 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
689 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
690 recipient_jid=peer_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
691 updated_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
692 trust_updates=trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
693 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
694 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
695 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
696 # Also send full trust information about _every_ peer to our newly |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
697 # trusted devices |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
698 peer_trust_updates = await get_trust_as_trust_updates( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
699 session_manager, peer_jid |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
700 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
701 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
702 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
703 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
704 recipient_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
705 updated_jid=peer_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
706 trust_updates=peer_trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
707 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
708 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
709 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
710 # Send information about our own devices to our newly trusted devices |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
711 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
712 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
713 recipient_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
714 updated_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
715 trust_updates=own_trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
716 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
717 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
718 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
719 # Notify our other devices about the changes in trust |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
720 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
721 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
722 recipient_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
723 updated_jid=updated_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
724 trust_updates=trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
725 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
726 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
727 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
728 # Send a summary of our own trust to newly trusted devices |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
729 trust_messages.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
730 PartialTrustMessage( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
731 recipient_jid=updated_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
732 updated_jid=own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
733 trust_updates=own_trust_updates, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
734 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
735 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
736 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
737 # All trust messages prepared. Merge all trust messages directed at the same |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
738 # recipient. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
739 recipient_jids = {trust_message.recipient_jid for trust_message in trust_messages} |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
740 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
741 for recipient_jid in recipient_jids: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
742 updated: Dict[jid.JID, Set[TrustUpdate]] = {} |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
743 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
744 for trust_message in trust_messages: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
745 # Merge trust messages directed at that recipient |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
746 if trust_message.recipient_jid == recipient_jid: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
747 # Merge the trust updates |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
748 updated[trust_message.updated_jid] = updated.get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
749 trust_message.updated_jid, set() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
750 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
751 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
752 updated[trust_message.updated_jid] |= trust_message.trust_updates |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
753 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
754 # Build the trust message |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
755 trust_message_elt = domish.Element((NS_TM, "trust-message")) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
756 trust_message_elt["usage"] = NS_ATM |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
757 trust_message_elt["encryption"] = twomemo.twomemo.NAMESPACE |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
758 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
759 for updated_jid, trust_updates in updated.items(): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
760 key_owner_elt = trust_message_elt.addElement((NS_TM, "key-owner")) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
761 key_owner_elt["jid"] = updated_jid.userhost() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
762 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
763 for trust_update in trust_updates: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
764 serialized_identity_key = base64.b64encode( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
765 trust_update.target_key |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
766 ).decode("ASCII") |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
767 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
768 if trust_update.target_trust: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
769 key_owner_elt.addElement( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
770 (NS_TM, "trust"), content=serialized_identity_key |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
771 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
772 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
773 key_owner_elt.addElement( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
774 (NS_TM, "distrust"), content=serialized_identity_key |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
775 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
776 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
777 # Finally, encrypt and send the trust message! |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
778 message_data = client.generate_message_xml( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
779 MessageData( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
780 { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
781 "from": own_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
782 "to": recipient_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
783 "uid": str(uuid.uuid4()), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
784 "message": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
785 "subject": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
786 "type": C.MESS_TYPE_CHAT, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
787 "extra": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
788 "timestamp": time.time(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
789 } |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
790 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
791 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
792 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
793 message_data["xml"].addChild(trust_message_elt) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
794 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
795 plaintext = XEP_0420.pack_stanza(TM_SCE_PROFILE, message_data["xml"]) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
796 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
797 feedback_jid = recipient_jid |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
798 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
799 # TODO: The following is mostly duplicate code |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
800 try: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
801 messages, encryption_errors = await session_manager.encrypt( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
802 frozenset({own_jid.userhost(), recipient_jid.userhost()}), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
803 {OMEMO.NS_TWOMEMO: plaintext}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
804 backend_priority_order=[OMEMO.NS_TWOMEMO], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
805 identifier=feedback_jid.userhost(), |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
806 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
807 except Exception as e: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
808 msg = _( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
809 # pylint: disable=consider-using-f-string |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
810 "Can't encrypt message for {entities}: {reason}".format( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
811 entities=", ".join({own_jid.userhost(), recipient_jid.userhost()}), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
812 reason=e, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
813 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
814 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
815 log.warning(msg) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
816 client.feedback(feedback_jid, msg, {C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR}) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
817 raise e |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
818 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
819 if len(encryption_errors) > 0: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
820 log.warning( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
821 f"Ignored the following non-critical encryption errors:" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
822 f" {encryption_errors}" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
823 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
824 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
825 encrypted_errors_stringified = ", ".join( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
826 [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
827 f"device {err.device_id} of {err.bare_jid} under namespace" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
828 f" {err.namespace}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
829 for err in encryption_errors |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
830 ] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
831 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
832 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
833 client.feedback( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
834 feedback_jid, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
835 D_( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
836 "There were non-critical errors during encryption resulting in some" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
837 " of your destinees' devices potentially not receiving the message." |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
838 " This happens when the encryption data/key material of a device is" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
839 " incomplete or broken, which shouldn't happen for actively used" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
840 " devices, and can usually be ignored. The following devices are" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
841 f" affected: {encrypted_errors_stringified}." |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
842 ), |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
843 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
844 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
845 message = next( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
846 message for message in messages if message.namespace == OMEMO.NS_TWOMEMO |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
847 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
848 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
849 # Add the encrypted element |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
850 message_data["xml"].addChild( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
851 xml_tools.et_elt_2_domish_elt(twomemo.etree.serialize_message(message)) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
852 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
853 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
854 await client.a_send(message_data["xml"]) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
855 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
856 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
857 def make_session_manager( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
858 sat: LiberviaBackend, profile: str |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
859 ) -> Type[omemo.SessionManager]: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
860 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
861 @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
|
862 @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
|
863 @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
|
864 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
|
865 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
866 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
867 client = sat.get_client(profile) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
868 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
|
869 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
870 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
|
871 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
872 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
|
873 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
|
874 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
875 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
876 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
877 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
|
878 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
|
879 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
|
880 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
881 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
|
882 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
883 await xep_0060.send_item( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
884 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
885 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
886 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
887 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
|
888 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
|
889 extra={ |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3929
diff
changeset
|
890 XEP_0060.EXTRA_PUBLISH_OPTIONS: { |
4218
c0f3f29377f1
plugin XEP-0384: be sure to have `open` access model for created nodes.
Goffi <goffi@goffi.org>
parents:
4216
diff
changeset
|
891 XEP_0060.OPT_ACCESS_MODEL: "open", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
892 XEP_0060.OPT_MAX_ITEMS: "max", |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
893 }, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
894 XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "raise", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
895 }, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
896 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
897 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
|
898 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
899 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
|
900 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
|
901 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
|
902 # 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
|
903 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
|
904 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
905 # 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
|
906 # 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
|
907 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
908 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
|
909 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
910 # 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
|
911 # 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
|
912 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
913 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
914 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
|
915 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
916 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
917 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
918 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
919 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
|
920 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
|
921 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
922 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
|
923 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
924 await xep_0060.send_item( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
925 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
926 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
927 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
928 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
|
929 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
|
930 extra={ |
4218
c0f3f29377f1
plugin XEP-0384: be sure to have `open` access model for created nodes.
Goffi <goffi@goffi.org>
parents:
4216
diff
changeset
|
931 XEP_0060.EXTRA_PUBLISH_OPTIONS: { |
c0f3f29377f1
plugin XEP-0384: be sure to have `open` access model for created nodes.
Goffi <goffi@goffi.org>
parents:
4216
diff
changeset
|
932 XEP_0060.OPT_ACCESS_MODEL: "open", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
933 XEP_0060.OPT_MAX_ITEMS: 1, |
4218
c0f3f29377f1
plugin XEP-0384: be sure to have `open` access model for created nodes.
Goffi <goffi@goffi.org>
parents:
4216
diff
changeset
|
934 }, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
935 XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "publish_without_options", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
936 }, |
3911
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 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
|
939 raise omemo.BundleUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
940 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
|
941 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
942 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
943 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
944 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
945 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
|
946 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
947 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
948 async def _download_bundle( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
949 namespace: str, bare_jid: str, device_id: int |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
950 ) -> omemo.Bundle: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
951 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
|
952 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
|
953 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
954 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
955 items, __ = await xep_0060.get_items( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
956 client, jid.JID(bare_jid), node, item_ids=[str(device_id)] |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
957 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
958 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
|
959 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
960 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
|
961 f" namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
962 ) from e |
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 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
|
965 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
966 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
|
967 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
|
968 f" {len(items)}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
969 ) |
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 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
|
972 iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
973 None, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
974 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
975 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
|
976 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
977 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
|
978 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
|
979 f" failed: {element}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
980 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
981 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
982 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
983 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
|
984 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
|
985 raise omemo.BundleDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
986 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
|
987 f" namespace {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
988 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
989 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
990 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
|
991 return await download_oldmemo_bundle( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
992 client, xep_0060, bare_jid, device_id |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
993 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
994 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
995 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
|
996 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
997 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
998 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
|
999 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
|
1000 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
|
1001 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1002 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1003 await xep_0060.retract_items( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1004 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1005 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1006 node, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1007 [str(device_id)], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1008 notify=False, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1009 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1010 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
|
1011 raise omemo.BundleDeletionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1012 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
|
1013 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1014 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1015 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1016 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1017 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1018 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
|
1019 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
|
1020 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1021 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1022 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
|
1023 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
|
1024 raise omemo.BundleDeletionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1025 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
|
1026 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1027 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1028 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1029 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1030 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1031 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
|
1032 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1033 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1034 async def _upload_device_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1035 namespace: str, device_list: Dict[int, Optional[str]] |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1036 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1037 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
|
1038 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
|
1039 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1047 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
|
1048 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
|
1049 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1050 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1051 await xep_0060.send_item( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1052 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1053 client.jid.userhostJID(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1054 node, |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1055 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
|
1056 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
|
1057 extra={ |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3929
diff
changeset
|
1058 XEP_0060.EXTRA_PUBLISH_OPTIONS: { |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3929
diff
changeset
|
1059 XEP_0060.OPT_MAX_ITEMS: 1, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1060 XEP_0060.OPT_ACCESS_MODEL: "open", |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1061 }, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1062 XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "raise", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1063 }, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1064 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1065 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
|
1066 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1067 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
|
1068 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
|
1069 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
|
1070 # 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
|
1071 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
|
1072 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1073 # 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
|
1074 # 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
|
1075 raise omemo.DeviceListUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1076 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
|
1077 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1078 # 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
|
1079 # in the XEP. |
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 raise omemo.DeviceListUploadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1082 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
|
1083 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1084 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1085 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1086 async def _download_device_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1087 namespace: str, bare_jid: str |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1088 ) -> 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
|
1089 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
|
1090 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1091 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
|
1092 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
|
1093 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
|
1094 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
|
1095 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1096 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
|
1097 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
|
1098 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1099 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1100 items, __ = await xep_0060.get_items(client, jid.JID(bare_jid), node) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1101 except exceptions.NotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1102 return {} |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1103 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
|
1104 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1105 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
|
1106 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1107 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1108 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1109 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
|
1110 return {} |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1111 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1112 if 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
|
1113 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1114 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
|
1115 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
|
1116 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1117 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1118 element = next( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1119 iter(xml_tools.domish_elt_2_et_elt(cast(domish.Element, items[0]))), None |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1120 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1121 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1122 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
|
1123 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1124 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
|
1125 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
|
1126 f" {element}." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1127 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1128 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1129 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 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
|
1135 raise omemo.DeviceListDownloadFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1136 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
|
1137 f" {namespace}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1138 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1139 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1140 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
|
1141 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1142 async def _evaluate_custom_trust_level( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1143 self, device: omemo.DeviceInformation |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1144 ) -> omemo.TrustLevel: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1145 # Get the custom trust level |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1146 try: |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1147 trust_level = TrustLevel(device.trust_level_name) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1148 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
|
1149 raise omemo.UnknownTrustLevel( |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1150 f"Unknown trust level name {device.trust_level_name}" |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1151 ) from e |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1152 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1153 # The first three cases are a straight-forward mapping |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1154 if trust_level is TrustLevel.TRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1155 return omemo.TrustLevel.TRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1156 if trust_level is TrustLevel.UNDECIDED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1157 return omemo.TrustLevel.UNDECIDED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1158 if trust_level is TrustLevel.DISTRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1159 return omemo.TrustLevel.DISTRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1160 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1161 # The blindly trusted case is more complicated, since its evaluation depends |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1162 # on the trust system and phase |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1163 if trust_level is TrustLevel.BLINDLY_TRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1164 # Get the name of the active trust system |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1165 trust_system = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1166 str, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1167 sat.memory.param_get_a( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1168 PARAM_NAME, PARAM_CATEGORY, profile_key=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1169 ), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1170 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1171 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1172 # If the trust model is BTBV, blind trust is always enabled |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1173 if trust_system == "btbv": |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1174 return omemo.TrustLevel.TRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1175 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1176 # If the trust model is ATM, blind trust is disabled in the second phase |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1177 # and counts as undecided |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1178 if trust_system == "atm": |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1179 # Find out whether we are in phase one or two |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1180 devices = await self.get_device_information(device.bare_jid) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1181 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1182 phase_one = all( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1183 TrustLevel(device.trust_level_name) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1184 in {TrustLevel.UNDECIDED, TrustLevel.BLINDLY_TRUSTED} |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1185 for device in devices |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1186 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1187 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1188 if phase_one: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1189 return omemo.TrustLevel.TRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1190 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1191 return omemo.TrustLevel.UNDECIDED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1192 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1193 raise exceptions.InternalError( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1194 f"Unknown trust system active: {trust_system}" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1195 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1196 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1197 assert_never(trust_level) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1198 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1199 async def _make_trust_decision( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1200 self, undecided: FrozenSet[omemo.DeviceInformation], identifier: Optional[str] |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1201 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1202 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
|
1203 raise omemo.TrustDecisionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1204 "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
|
1205 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1206 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1207 # 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
|
1208 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
|
1209 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1210 # Both the ATM and the BTBV trust models work with blind trust before the |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1211 # first manual verification is performed. Thus, we can separate bare JIDs into |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1212 # two pools here, one pool of bare JIDs for which blind trust is active, and |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1213 # one pool of bare JIDs for which manual trust is used instead. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1214 bare_jids = {device.bare_jid for device in undecided} |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1215 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1216 blind_trust_bare_jids: Set[str] = set() |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1217 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
|
1218 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1219 # For each bare JID, decide whether blind trust applies |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1220 for bare_jid in bare_jids: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1221 # Get all known devices belonging to the bare JID |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1222 devices = await self.get_device_information(bare_jid) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1223 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1224 # If the trust levels of all devices correspond to those used by blind |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1225 # trust, blind trust applies. Otherwise, fall back to manual trust. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1226 if all( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1227 TrustLevel(device.trust_level_name) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1228 in {TrustLevel.UNDECIDED, TrustLevel.BLINDLY_TRUSTED} |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1229 for device in devices |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1230 ): |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1231 blind_trust_bare_jids.add(bare_jid) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1232 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1233 manual_trust_bare_jids.add(bare_jid) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1234 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1235 # 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
|
1236 # be categorized too |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1237 blindly_trusted_devices = { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1238 dev for dev in undecided if dev.bare_jid in blind_trust_bare_jids |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1239 } |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1240 manually_trusted_devices = { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1241 dev for dev in undecided if dev.bare_jid in manual_trust_bare_jids |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1242 } |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1243 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1244 # Blindly trust devices handled by blind trust |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1245 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
|
1246 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
|
1247 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
|
1248 device.bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1249 device.identity_key, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1250 TrustLevel.BLINDLY_TRUSTED.name, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1251 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1252 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1253 blindly_trusted_devices_stringified = ", ".join( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1254 [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1255 f"device {device.device_id} of {device.bare_jid} under namespace" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1256 f" {device.namespaces}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1257 for device in blindly_trusted_devices |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1258 ] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1259 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1260 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1261 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1262 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1263 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1264 "Not all destination devices are trusted, unknown devices will be" |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1265 " blindly trusted.\nFollowing devices have been automatically" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1266 f" trusted: {blindly_trusted_devices_stringified}." |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1267 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1268 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1269 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1270 # 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
|
1271 # trust |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1272 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
|
1273 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1274 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1275 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1276 "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
|
1277 " 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
|
1278 " 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
|
1279 " send this message." |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1280 ), |
3911
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 await self.__prompt_manual_trust( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1283 frozenset(manually_trusted_devices), feedback_jid |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1284 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1285 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1286 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1287 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
|
1288 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
|
1289 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1295 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
|
1296 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
|
1297 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1298 message_data = client.generate_message_xml( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1299 MessageData( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1300 { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1301 "from": client.jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1302 "to": jid.JID(bare_jid), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1303 "uid": str(uuid.uuid4()), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1304 "message": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1305 "subject": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1306 "type": C.MESS_TYPE_CHAT, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1307 "extra": {}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1308 "timestamp": time.time(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1309 } |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1310 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
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 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1313 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
|
1314 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1315 try: |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
1316 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
|
1317 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
|
1318 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
|
1319 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1320 async def __prompt_manual_trust( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1321 self, undecided: FrozenSet[omemo.DeviceInformation], feedback_jid: jid.JID |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1322 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1323 """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
|
1324 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1325 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
|
1326 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
|
1327 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1328 @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
|
1329 @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
|
1330 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
|
1331 @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
|
1332 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1333 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1334 # This session manager handles encryption with both twomemo and oldmemo, but |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1335 # both are currently registered as different plugins and the `defer_xmlui` |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1336 # 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
|
1337 # 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
|
1338 # 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
|
1339 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
|
1340 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
|
1341 raise omemo.TrustDecisionFailed( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1342 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
|
1343 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1344 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1345 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
|
1346 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1347 # 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
|
1348 # pylint: disable=no-member |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1349 trust_ui = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1350 Any, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1351 xml_tools.XMLUI( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1352 panel_type=C.XMLUI_FORM, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1353 title=D_("OMEMO trust management"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1354 submit_id="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1355 ), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1356 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1357 trust_ui.addText( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1358 D_( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1359 "This is OMEMO trusting system. You'll see below the devices of your " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1360 "contacts, and a checkbox to trust them or not. A trusted device " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1361 "can read your messages in plain text, so be sure to only validate " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1362 "devices that you are sure are belonging to your contact. It's better " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1363 "to do this when you are next to your contact and their device, so " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1364 'you can check the "fingerprint" (the number next to the device) ' |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1365 "yourself. Do *not* validate a device if the fingerprint is wrong!" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1366 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1367 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1368 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1369 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
|
1370 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1371 trust_ui.change_container("label") |
3911
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_("This device ID")) |
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(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
|
1374 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
|
1375 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
|
1376 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1377 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1378 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1379 # 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
|
1380 # completely random |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1381 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
|
1382 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1383 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
|
1384 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
|
1385 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
|
1386 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
|
1387 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
|
1388 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
|
1389 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
|
1390 trust_ui.addLabel(D_("Trust this device?")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1391 trust_ui.addBool(f"trust_{index}", value=C.bool_const(False)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1392 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1393 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1394 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1395 trust_ui_result = await xml_tools.defer_xmlui( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1396 sat, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1397 trust_ui, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1398 action_extra={"meta_encryption_trust": namespace}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1399 profile=profile, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1400 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1401 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1402 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
|
1403 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
|
1404 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1405 data_form_result = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1406 Dict[str, str], xml_tools.xmlui_result_2_data_form_result(trust_ui_result) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1407 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1408 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1409 trust_updates: Set[TrustUpdate] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1410 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1411 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
|
1412 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
|
1413 continue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1414 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1415 device = undecided_ordered[int(key[len("trust_") :])] |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1416 target_trust = C.bool(value) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1417 trust_level = ( |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1418 TrustLevel.TRUSTED if target_trust else TrustLevel.DISTRUSTED |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1419 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1420 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1421 await self.set_trust( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1422 device.bare_jid, device.identity_key, trust_level.name |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1423 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1424 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1425 trust_updates.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1426 TrustUpdate( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1427 target_jid=jid.JID(device.bare_jid).userhostJID(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1428 target_key=device.identity_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1429 target_trust=target_trust, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1430 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1431 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1432 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1433 # Check whether ATM is enabled and handle everything in case it is |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1434 trust_system = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1435 str, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1436 sat.memory.param_get_a(PARAM_NAME, PARAM_CATEGORY, profile_key=profile), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1437 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1438 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1439 if trust_system == "atm": |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1440 await manage_trust_message_cache(client, self, frozenset(trust_updates)) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1441 await send_trust_messages(client, self, frozenset(trust_updates)) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1442 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1443 return SessionManagerImpl |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1444 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1445 |
3911
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( |
4072
040095a5dc7f
refactoring: rename `SAT` class to `LiberviaBackend`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1447 sat: LiberviaBackend, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1448 profile: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1449 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
|
1450 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
|
1451 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
|
1452 max_num_per_session_skipped_keys: int = 1000, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1453 max_num_per_message_skipped_keys: Optional[int] = None, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1454 ) -> omemo.SessionManager: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1455 """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
|
1456 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1457 @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
|
1458 @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
|
1459 @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
|
1460 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
|
1461 @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
|
1462 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
|
1463 and one month. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1464 @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
|
1465 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
|
1466 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
|
1467 @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
|
1468 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
|
1469 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
|
1470 :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
|
1471 @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
|
1472 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
|
1473 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
|
1474 ``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
|
1475 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
|
1476 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
|
1477 @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
|
1478 ``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
|
1479 profile. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1480 @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
|
1481 :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
|
1482 @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
|
1483 :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
|
1484 @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
|
1485 :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
|
1486 @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
|
1487 :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
|
1488 @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
|
1489 :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
|
1490 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1491 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1492 client = sat.get_client(profile) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1493 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
|
1494 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1495 storage = StorageImpl(profile) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1496 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1497 # TODO: Untested |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1498 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
|
1499 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
|
1500 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1501 # 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
|
1502 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
|
1503 TrustLevel.UNDECIDED.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1504 TrustLevel.DISTRUSTED.name, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1505 lambda bare_jid, device_id: download_oldmemo_bundle( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1506 client, xep_0060, bare_jid, device_id |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1507 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1508 ) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1509 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1510 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
|
1511 [ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1512 twomemo.Twomemo( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1513 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1514 max_num_per_session_skipped_keys, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1515 max_num_per_message_skipped_keys, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1516 ), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1517 oldmemo.Oldmemo( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1518 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1519 max_num_per_session_skipped_keys, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1520 max_num_per_message_skipped_keys, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1521 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1522 ], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1523 storage, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1524 client.jid.userhost(), |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1525 initial_own_label, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1526 TrustLevel.UNDECIDED.value, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1527 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
|
1528 pre_key_refill_threshold, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1529 omemo.AsyncFramework.TWISTED, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1530 ) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1531 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1532 # 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
|
1533 # 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
|
1534 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
|
1535 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1536 # 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
|
1537 # 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
|
1538 # 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
|
1539 # 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
|
1540 # 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
|
1541 # 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
|
1542 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
|
1543 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1544 return session_manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1545 |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1546 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1547 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
|
1548 <params> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1549 <individual> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1550 <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
|
1551 <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
|
1552 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
|
1553 type="list" security="3"> |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1554 <option value="atm" |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1555 label={quoteattr(D_('Automatic Trust Management (more secure)'))} /> |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1556 <option value="btbv" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1557 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
|
1558 selected="true" /> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1559 </param> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1560 </category> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1561 </individual> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1562 </params> |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1563 """ |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1564 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1565 |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1566 class OMEMO: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1567 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1568 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
|
1569 ``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
|
1570 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
|
1571 between the two is maintained. MUC messages are supported next to one to one messages. |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1572 For trust management, the two trust models "ATM" and "BTBV" are supported. |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1573 """ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1574 |
3918
e63f96e60f7b
plugin XEP-0384: expose OLDMEMO and TWOMEMO namespaces:
Goffi <goffi@goffi.org>
parents:
3914
diff
changeset
|
1575 NS_TWOMEMO = twomemo.twomemo.NAMESPACE |
e63f96e60f7b
plugin XEP-0384: expose OLDMEMO and TWOMEMO namespaces:
Goffi <goffi@goffi.org>
parents:
3914
diff
changeset
|
1576 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
|
1577 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1578 # 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
|
1579 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
|
1580 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
|
1581 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
|
1582 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
|
1583 from_policy=SCEAffixPolicy.OPTIONAL, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1584 custom_policies={}, |
3911
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 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1587 # 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
|
1588 SCE_PROFILE = SCEProfile( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1589 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
|
1590 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
|
1591 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
|
1592 from_policy=SCEAffixPolicy.OPTIONAL, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1593 custom_policies={}, |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1594 ) |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1595 |
4216 | 1596 def __init__(self, host: LiberviaBackend) -> None: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1597 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1598 @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
|
1599 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1600 |
4216 | 1601 self.host = host |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1602 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1603 # 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
|
1604 # model |
4216 | 1605 host.memory.update_params(DEFAULT_TRUST_MODEL_PARAM) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1606 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1607 # Plugins |
4216 | 1608 self._j = cast(XEP_0060, host.plugins["XEP-0060"]) |
1609 self.__xep_0045 = cast(Optional[XEP_0045], host.plugins.get("XEP-0045")) | |
1610 self.__xep_0334 = cast(XEP_0334, host.plugins["XEP-0334"]) | |
1611 self.__xep_0359 = cast(Optional[XEP_0359], host.plugins.get("XEP-0359")) | |
1612 self.__xep_0420 = cast(XEP_0420, host.plugins["XEP-0420"]) | |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1613 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1614 # 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
|
1615 # 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
|
1616 # 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
|
1617 # 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
|
1618 # 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
|
1619 # 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
|
1620 # 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
|
1621 # 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
|
1622 # 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
|
1623 # 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
|
1624 # really necessary. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1625 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
|
1626 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1627 # 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
|
1628 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
|
1629 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1630 # 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
|
1631 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
|
1632 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1633 # These triggers are used by oldmemo, which doesn't do SCE and only applies to |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1634 # messages. Temporarily, until a more fitting trigger for SCE-based encryption is |
4051
c23cad65ae99
core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1635 # added, the message_received trigger is also used for twomemo. |
4216 | 1636 host.trigger.add( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1637 "message_received", self._message_received_trigger, priority=100050 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1638 ) |
4164
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
1639 |
4216 | 1640 host.trigger.add("send", self.__send_trigger, priority=0) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1641 # 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
|
1642 # including IQs. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1643 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1644 # Give twomemo a (slightly) higher priority than oldmemo |
4216 | 1645 host.register_encryption_plugin(self, "OMEMO", twomemo.twomemo.NAMESPACE, 101) |
1646 host.register_encryption_plugin( | |
4150
26534d959d2d
Plugin XEP-0384: rename the pun names "OLDMEMO" and "TWOMEMO" to "OMEMO_legacy" and "OMEMO" for clarity.
Goffi <goffi@goffi.org>
parents:
4073
diff
changeset
|
1647 self, "OMEMO_legacy", oldmemo.oldmemo.NAMESPACE, 100 |
26534d959d2d
Plugin XEP-0384: rename the pun names "OLDMEMO" and "TWOMEMO" to "OMEMO_legacy" and "OMEMO" for clarity.
Goffi <goffi@goffi.org>
parents:
4073
diff
changeset
|
1648 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1649 |
4216 | 1650 xep_0163 = cast(XEP_0163, host.plugins["XEP-0163"]) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1651 xep_0163.add_pep_event( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1652 "TWOMEMO_DEVICES", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1653 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
|
1654 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
|
1655 self.__on_device_list_update(items_event, profile) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1656 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1657 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1658 xep_0163.add_pep_event( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1659 "OLDMEMO_DEVICES", |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1660 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
|
1661 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
|
1662 self.__on_device_list_update(items_event, profile) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1663 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1664 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1665 |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1666 try: |
4216 | 1667 self.__text_commands = cast(TextCommands, host.plugins[C.TEXT_CMDS]) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1668 except KeyError: |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1669 log.info(_("Text commands not available")) |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1670 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1671 self.__text_commands.register_text_commands(self) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1672 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1673 def profile_connected( # pylint: disable=invalid-name |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1674 self, client: SatXMPPClient |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1675 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1676 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1677 @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
|
1678 """ |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1679 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1680 defer.ensureDeferred(self.get_session_manager(cast(str, client.profile))) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1681 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1682 async def cmd_omemo_reset( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1683 self, client: SatXMPPClient, mess_data: MessageData |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1684 ) -> Literal[False]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1685 """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
|
1686 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1687 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
|
1688 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
|
1689 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
|
1690 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1691 @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
|
1692 @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
|
1693 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
|
1694 @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
|
1695 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
|
1696 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1697 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1698 twomemo_requested = client.encryption.is_encryption_requested( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1699 mess_data, twomemo.twomemo.NAMESPACE |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1700 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1701 oldmemo_requested = client.encryption.is_encryption_requested( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1702 mess_data, oldmemo.oldmemo.NAMESPACE |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1703 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1704 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1705 if not (twomemo_requested or oldmemo_requested): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1706 self.__text_commands.feed_back( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1707 client, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1708 _("You need to have OMEMO encryption activated to reset the session"), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1709 mess_data, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1710 ) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1711 return False |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1712 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1713 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
|
1714 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
1715 session_manager = await self.get_session_manager(client.profile) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1716 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
|
1717 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1718 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
|
1719 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
|
1720 await session_manager.replace_sessions(device) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1721 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1722 self.__text_commands.feed_back( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1723 client, _("OMEMO session has been reset"), mess_data |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1724 ) |
3218
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1725 |
806a7936a591
plugin XEP-0384: added "/omemo_reset" text command:
Goffi <goffi@goffi.org>
parents:
3214
diff
changeset
|
1726 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1727 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1728 async def get_trust_ui( # pylint: disable=invalid-name |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1729 self, client: SatXMPPClient, entity: jid.JID |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1730 ) -> xml_tools.XMLUI: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1731 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1732 @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
|
1733 @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
|
1734 @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
|
1735 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
|
1736 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1737 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1738 if entity.resource: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1739 raise ValueError("A bare JID is expected.") |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1740 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1741 bare_jids: Set[str] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1742 if self.__xep_0045 is not None and self.__xep_0045.is_joined_room(client, entity): |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1743 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
|
1744 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1745 bare_jids = {entity.userhost()} |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1746 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
1747 session_manager = await self.get_session_manager(client.profile) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1748 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1749 # 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
|
1750 # random |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1751 devices = sorted( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1752 cast(Set[omemo.DeviceInformation], set()).union( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1753 *[ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1754 await session_manager.get_device_information(bare_jid) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1755 for bare_jid in bare_jids |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1756 ] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1757 ), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1758 key=lambda device: device.bare_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1759 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1760 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1761 async def callback(data: Any, profile: str) -> Dict[Never, Never]: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1762 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1763 @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
|
1764 @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
|
1765 @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
|
1766 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
|
1767 """ |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1768 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1769 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
|
1770 return {} |
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 data_form_result = cast( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1773 Dict[str, str], xml_tools.xmlui_result_2_data_form_result(data) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1774 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1775 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1776 trust_updates: Set[TrustUpdate] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1777 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1778 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
|
1779 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
|
1780 continue |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1781 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1782 device = devices[int(key[len("trust_") :])] |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1783 trust_level_name = value |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1784 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1785 if device.trust_level_name != trust_level_name: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1786 await session_manager.set_trust( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1787 device.bare_jid, device.identity_key, trust_level_name |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1788 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1789 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1790 target_trust: Optional[bool] = None |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1791 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1792 if TrustLevel(trust_level_name) is TrustLevel.TRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1793 target_trust = True |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1794 if TrustLevel(trust_level_name) is TrustLevel.DISTRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1795 target_trust = False |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1796 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1797 if target_trust is not None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1798 trust_updates.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1799 TrustUpdate( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1800 target_jid=jid.JID(device.bare_jid).userhostJID(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1801 target_key=device.identity_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1802 target_trust=target_trust, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1803 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1804 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1805 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1806 # Check whether ATM is enabled and handle everything in case it is |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1807 trust_system = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1808 str, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1809 self.host.memory.param_get_a( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1810 PARAM_NAME, PARAM_CATEGORY, profile_key=profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1811 ), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1812 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1813 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1814 if trust_system == "atm": |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1815 if len(trust_updates) > 0: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1816 await manage_trust_message_cache( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1817 client, session_manager, frozenset(trust_updates) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1818 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1819 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1820 await send_trust_messages( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1821 client, session_manager, frozenset(trust_updates) |
3911
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 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1824 return {} |
2744
e6716d90c2fe
plugin XEP-0384: various bug fixes:
Goffi <goffi@goffi.org>
parents:
2738
diff
changeset
|
1825 |
4216 | 1826 submit_id = self.host.register_callback(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
|
1827 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1828 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
|
1829 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
|
1830 title=D_("OMEMO trust management"), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1831 submit_id=submit_id, |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1832 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1833 # 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
|
1834 # 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
|
1835 trust_ui = cast(Any, result) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1836 trust_ui.addText( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1837 D_( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1838 "This is OMEMO trusting system. You'll see below the devices of your" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1839 " contacts, and a list selection to trust them or not. A trusted device" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1840 " can read your messages in plain text, so be sure to only validate" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1841 " devices that you are sure are belonging to your contact. It's better" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1842 " to do this when you are next to your contact and their device, so" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1843 ' you can check the "fingerprint" (the number next to the device)' |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1844 " yourself. Do *not* validate a device if the fingerprint is wrong!" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1845 " Note that manually validating a fingerprint disables any form of automatic" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1846 " trust." |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1847 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1848 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1849 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1850 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
|
1851 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1852 trust_ui.change_container("label") |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1853 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
|
1854 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
|
1855 trust_ui.addLabel(D_("This device's fingerprint")) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1856 trust_ui.addText( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1857 " ".join(session_manager.format_identity_key(own_device.identity_key)) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1858 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1859 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1860 trust_ui.addEmpty() |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1861 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1862 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
|
1863 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
|
1864 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
|
1865 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
|
1866 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
|
1867 trust_ui.addLabel(D_("Fingerprint")) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1868 trust_ui.addText( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1869 " ".join(session_manager.format_identity_key(device.identity_key)) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1870 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1871 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
|
1872 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1873 current_trust_level = TrustLevel(device.trust_level_name) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1874 avaiable_trust_levels = { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1875 TrustLevel.DISTRUSTED, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1876 TrustLevel.TRUSTED, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1877 current_trust_level, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1878 } |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
1879 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1880 trust_ui.addList( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1881 f"trust_{index}", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1882 options=[trust_level.name for trust_level in avaiable_trust_levels], |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1883 selected=current_trust_level.name, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1884 styles=["inline"], |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1885 ) |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1886 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1887 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
|
1888 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
|
1889 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1890 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
|
1891 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
|
1892 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1893 trust_ui.addLabel(D_("(inactive for Twomemo)")) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
1894 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1895 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
|
1896 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
|
1897 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1898 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
|
1899 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
|
1900 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1901 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
|
1902 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1903 trust_ui.addEmpty() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1904 trust_ui.addEmpty() |
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 return result |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1907 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1908 @staticmethod |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1909 def __get_joined_muc_users( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1910 client: SatXMPPClient, xep_0045: XEP_0045, room_jid: jid.JID |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1911 ) -> Set[str]: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1912 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1913 @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
|
1914 @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
|
1915 @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
|
1916 @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
|
1917 @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
|
1918 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
|
1919 """ |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
1920 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1921 bare_jids: Set[str] = set() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1922 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1923 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
1924 room = cast(muc.Room, xep_0045.get_room(client, room_jid)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1925 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
|
1926 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1927 "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
|
1928 ) from e |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1929 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1930 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
|
1931 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
|
1932 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
|
1933 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1934 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
|
1935 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
|
1936 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1937 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1938 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
|
1939 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1940 return bare_jids |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1941 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
1942 async def get_session_manager(self, profile: str) -> omemo.SessionManager: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1943 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1944 @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
|
1945 @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
|
1946 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
|
1947 """ |
2662
0bef44f8e8ca
plugin XEP-0384: PEP handling + mark as encrypted:
Goffi <goffi@goffi.org>
parents:
2654
diff
changeset
|
1948 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
1949 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1950 # 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
|
1951 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
|
1952 except KeyError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1953 # 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
|
1954 # 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
|
1955 # 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
|
1956 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
|
1957 # 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
|
1958 # queue |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1959 deferred = defer.Deferred() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1960 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
|
1961 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
|
1962 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1963 # 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
|
1964 self.__session_manager_waiters[profile] = [] |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1965 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1966 # Build and store the session manager |
3929
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1967 try: |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1968 session_manager = await prepare_for_profile( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1969 self.host, profile, initial_own_label="Libervia" |
3929
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1970 ) |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1971 except Exception as e: |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1972 # In case of an error during initalization, notify the waiters accordingly |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1973 # and delete them |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1974 for waiter in self.__session_manager_waiters[profile]: |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1975 waiter.errback(e) |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1976 del self.__session_manager_waiters[profile] |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1977 |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1978 # Re-raise the exception |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1979 raise |
42d3110ac9b1
plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
Syndace <me@syndace.dev>
parents:
3919
diff
changeset
|
1980 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1981 self.__session_managers[profile] = session_manager |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1982 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1983 # 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
|
1984 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
|
1985 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
|
1986 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
|
1987 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1988 return session_manager |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
1989 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1990 async def __message_received_trigger_atm( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1991 self, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1992 client: SatXMPPClient, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1993 message_elt: domish.Element, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1994 session_manager: omemo.SessionManager, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1995 sender_device_information: omemo.DeviceInformation, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
1996 timestamp: datetime, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1997 ) -> None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1998 """Check a newly decrypted message stanza for ATM content and perform ATM in case. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
1999 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2000 @param client: The client which received the message. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2001 @param message_elt: The message element. Can be modified. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2002 @param session_manager: The session manager. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2003 @param sender_device_information: Information about the device that sent/encrypted |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2004 the message. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2005 @param timestamp: Timestamp extracted from the SCE time affix. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2006 """ |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2007 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2008 trust_message_cache = persistent.LazyPersistentBinaryDict( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2009 "XEP-0384/TM", client.profile |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2010 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2011 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2012 new_cache_entries: Set[TrustMessageCacheEntry] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2013 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2014 for trust_message_elt in message_elt.elements(NS_TM, "trust-message"): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2015 assert isinstance(trust_message_elt, domish.Element) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2016 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2017 try: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2018 TRUST_MESSAGE_SCHEMA.validate(trust_message_elt.toXml()) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2019 except xmlschema.XMLSchemaValidationError as e: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2020 raise exceptions.ParsingError( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2021 "<trust-message/> element doesn't pass schema validation." |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2022 ) from e |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2023 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2024 if trust_message_elt["usage"] != NS_ATM: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2025 # Skip non-ATM trust message |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2026 continue |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2027 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2028 if trust_message_elt["encryption"] != OMEMO.NS_TWOMEMO: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2029 # Skip non-twomemo trust message |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2030 continue |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2031 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2032 for key_owner_elt in trust_message_elt.elements(NS_TM, "key-owner"): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2033 assert isinstance(key_owner_elt, domish.Element) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2034 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2035 key_owner_jid = jid.JID(key_owner_elt["jid"]).userhostJID() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2036 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2037 for trust_elt in key_owner_elt.elements(NS_TM, "trust"): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2038 assert isinstance(trust_elt, domish.Element) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2039 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2040 new_cache_entries.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2041 TrustMessageCacheEntry( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2042 sender_jid=jid.JID(sender_device_information.bare_jid), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2043 sender_key=sender_device_information.identity_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2044 timestamp=timestamp, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2045 trust_update=TrustUpdate( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2046 target_jid=key_owner_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2047 target_key=base64.b64decode(str(trust_elt)), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2048 target_trust=True, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2049 ), |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2050 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2051 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2052 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2053 for distrust_elt in key_owner_elt.elements(NS_TM, "distrust"): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2054 assert isinstance(distrust_elt, domish.Element) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2055 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2056 new_cache_entries.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2057 TrustMessageCacheEntry( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2058 sender_jid=jid.JID(sender_device_information.bare_jid), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2059 sender_key=sender_device_information.identity_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2060 timestamp=timestamp, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2061 trust_update=TrustUpdate( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2062 target_jid=key_owner_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2063 target_key=base64.b64decode(str(distrust_elt)), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2064 target_trust=False, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2065 ), |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2066 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2067 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2068 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2069 # Load existing cache entries |
4216 | 2070 existing_cache_entries = { |
2071 TrustMessageCacheEntry.from_dict(d) | |
2072 for d in await trust_message_cache.get("cache", []) | |
2073 } | |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2074 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2075 # Discard cache entries by timestamp comparison |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2076 existing_by_target = { |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2077 ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2078 cache_entry.trust_update.target_jid.userhostJID(), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2079 cache_entry.trust_update.target_key, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2080 ): cache_entry |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2081 for cache_entry in existing_cache_entries |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2082 } |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2083 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2084 # Iterate over a copy here, such that new_cache_entries can be modified |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2085 for new_cache_entry in set(new_cache_entries): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2086 existing_cache_entry = existing_by_target.get( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2087 ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2088 new_cache_entry.trust_update.target_jid.userhostJID(), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2089 new_cache_entry.trust_update.target_key, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2090 ), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2091 None, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2092 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2093 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2094 if existing_cache_entry is not None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2095 if existing_cache_entry.timestamp > new_cache_entry.timestamp: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2096 # If the existing cache entry is newer than the new cache entry, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2097 # discard the new one in favor of the existing one |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2098 new_cache_entries.remove(new_cache_entry) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2099 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2100 # Otherwise, discard the existing cache entry. This includes the case |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2101 # when both cache entries have matching timestamps. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2102 existing_cache_entries.remove(existing_cache_entry) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2103 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2104 # If the sending device is trusted, apply the new cache entries |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2105 applied_trust_updates: Set[TrustUpdate] = set() |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2106 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2107 if TrustLevel(sender_device_information.trust_level_name) is TrustLevel.TRUSTED: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2108 # Iterate over a copy such that new_cache_entries can be modified |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2109 for cache_entry in set(new_cache_entries): |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2110 trust_update = cache_entry.trust_update |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2111 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2112 trust_level = ( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2113 TrustLevel.TRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2114 if trust_update.target_trust |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2115 else TrustLevel.DISTRUSTED |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2116 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2117 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2118 await session_manager.set_trust( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2119 trust_update.target_jid.userhost(), |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2120 trust_update.target_key, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2121 trust_level.name, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2122 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2123 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2124 applied_trust_updates.add(trust_update) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2125 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2126 new_cache_entries.remove(cache_entry) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2127 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2128 # Store the remaining existing and new cache entries |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2129 await trust_message_cache.force( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2130 "cache", [tm.to_dict() for tm in existing_cache_entries | new_cache_entries] |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2131 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2132 |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2133 # If the trust of at least one device was modified, run the ATM cache update logic |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2134 if len(applied_trust_updates) > 0: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2135 await manage_trust_message_cache( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2136 client, session_manager, frozenset(applied_trust_updates) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2137 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2138 |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2139 async def _message_received_trigger( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2140 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2141 client: SatXMPPClient, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2142 message_elt: domish.Element, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2143 post_treat: defer.Deferred, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2144 ) -> bool: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2145 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2146 @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
|
2147 @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
|
2148 @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
|
2149 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
|
2150 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
|
2151 encrypted. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2152 @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
|
2153 """ |
4007
1d5a81e3c9e8
plugin XEP-0384: skip MessageReceived trigger when in a component:
Goffi <goffi@goffi.org>
parents:
4004
diff
changeset
|
2154 if client.is_component: |
1d5a81e3c9e8
plugin XEP-0384: skip MessageReceived trigger when in a component:
Goffi <goffi@goffi.org>
parents:
4004
diff
changeset
|
2155 return True |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2156 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
|
2157 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2158 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
|
2159 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
|
2160 |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2161 message_type = message_elt.getAttribute("type", C.MESS_TYPE_NORMAL) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2162 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
|
2163 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
|
2164 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
|
2165 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2166 "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
|
2167 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2168 # 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
|
2169 # normally |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2170 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2171 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2172 room_jid = feedback_jid = sender_jid.userhostJID() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2173 |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2174 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
2175 room = cast(muc.Room, self.__xep_0045.get_room(client, room_jid)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2176 except exceptions.NotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2177 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2178 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
|
2179 f" {room_jid}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2180 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2181 # 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
|
2182 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2183 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2184 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
|
2185 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
|
2186 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2187 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
|
2188 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
|
2189 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2190 # 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
|
2191 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2192 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2193 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
|
2194 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
|
2195 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2196 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
|
2197 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
|
2198 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2199 # 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
|
2200 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2201 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2202 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
|
2203 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2204 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
|
2205 if self.__xep_0359 is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
2206 message_uid = self.__xep_0359.get_origin_id(message_elt) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2207 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
|
2208 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
|
2209 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
|
2210 muc_plaintext_cache_key = MUCPlaintextCacheKey( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2211 client, room_jid, message_uid |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2212 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2213 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2214 # 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
|
2215 # plugin. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2216 if sender_jid.userhostJID() == client.jid.userhostJID(): |
3944
748094d5a74d
plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
Goffi <goffi@goffi.org>
parents:
3943
diff
changeset
|
2217 try: |
748094d5a74d
plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
Goffi <goffi@goffi.org>
parents:
3943
diff
changeset
|
2218 feedback_jid = jid.JID(message_elt["to"]) |
748094d5a74d
plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
Goffi <goffi@goffi.org>
parents:
3943
diff
changeset
|
2219 except KeyError: |
748094d5a74d
plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
Goffi <goffi@goffi.org>
parents:
3943
diff
changeset
|
2220 feedback_jid = client.server_jid |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2221 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2222 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
|
2223 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2224 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
|
2225 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2226 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
|
2227 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
|
2228 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2229 twomemo_encrypted_elt = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2230 Optional[domish.Element], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2231 next(message_elt.elements(twomemo.twomemo.NAMESPACE, "encrypted"), None), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2232 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2233 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2234 oldmemo_encrypted_elt = cast( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2235 Optional[domish.Element], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2236 next(message_elt.elements(oldmemo.oldmemo.NAMESPACE, "encrypted"), None), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2237 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2238 |
3943
8dc6a4cfda4b
plugin XEP-0384: continue workflow and log error in case of issue in self.__prepare_for_profile:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
2239 try: |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
2240 session_manager = await self.get_session_manager(cast(str, client.profile)) |
3943
8dc6a4cfda4b
plugin XEP-0384: continue workflow and log error in case of issue in self.__prepare_for_profile:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
2241 except Exception as e: |
8dc6a4cfda4b
plugin XEP-0384: continue workflow and log error in case of issue in self.__prepare_for_profile:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
2242 log.error(f"error while preparing profile for {client.profile}: {e}") |
8dc6a4cfda4b
plugin XEP-0384: continue workflow and log error in case of issue in self.__prepare_for_profile:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
2243 # we don't want to block the workflow |
8dc6a4cfda4b
plugin XEP-0384: continue workflow and log error in case of issue in self.__prepare_for_profile:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
2244 return True |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2245 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2246 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
|
2247 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2248 message = twomemo.etree.parse_message( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2249 xml_tools.domish_elt_2_et_elt(twomemo_encrypted_elt), sender_bare_jid |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2250 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2251 except (ValueError, XMLSchemaValidationError): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2252 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2253 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
|
2254 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
|
2255 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2256 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2257 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
|
2258 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2259 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
|
2260 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2261 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
|
2262 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
|
2263 sender_bare_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2264 client.jid.userhost(), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2265 session_manager, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2266 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2267 except (ValueError, XMLSchemaValidationError): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2268 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2269 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
|
2270 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
|
2271 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2272 except omemo.SenderNotFound: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2273 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2274 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
|
2275 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
|
2276 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
|
2277 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2278 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2279 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
|
2280 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2281 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
|
2282 # 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
|
2283 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2284 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2285 message_elt.children.remove(encrypted_elt) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2286 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2287 log.debug( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2288 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
|
2289 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
|
2290 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2291 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2292 plaintext: Optional[bytes] |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2293 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
|
2294 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2295 if ( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2296 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
|
2297 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
|
2298 ): |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2299 # 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
|
2300 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
|
2301 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2302 # 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
|
2303 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
|
2304 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2305 try: |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
2306 plaintext, device_information, __ = await session_manager.decrypt(message) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2307 except omemo.MessageNotForUs: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2308 # 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
|
2309 # 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
|
2310 # 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
|
2311 # 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
|
2312 # 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
|
2313 # 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
|
2314 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
|
2315 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2316 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2317 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2318 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
|
2319 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
|
2320 ), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2321 {C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR}, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2322 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2323 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
|
2324 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2325 log.debug("Message not encrypted for us.") |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2326 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2327 # 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
|
2328 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2329 except Exception as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2330 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2331 _("Can't decrypt message: {reason}\n{xml}").format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2332 reason=e, xml=message_elt.toXml() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2333 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2334 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2335 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2336 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2337 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2338 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
|
2339 f" {e}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2340 ), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2341 {C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR}, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2342 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2343 # 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
|
2344 return False |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2345 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2346 affix_values: Optional[SCEAffixValues] = None |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2347 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2348 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
|
2349 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
|
2350 # 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
|
2351 # relevant modifications to the element |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2352 sce_profile = ( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2353 OMEMO.SCE_PROFILE_GROUPCHAT if is_muc_message else OMEMO.SCE_PROFILE |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2354 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2355 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2356 affix_values = self.__xep_0420.unpack_stanza( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2357 sce_profile, message_elt, plaintext |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2358 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2359 except Exception as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2360 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2361 D_(f"Error unpacking SCE-encrypted message: {e}\n{plaintext}") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2362 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2363 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2364 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2365 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2366 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
|
2367 f" {e}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2368 ), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2369 {C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR}, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2370 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2371 # 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
|
2372 return False |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2373 else: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2374 if affix_values.timestamp is not None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2375 # TODO: affix_values.timestamp contains the timestamp included in |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2376 # the encrypted element here. The XEP says it SHOULD be displayed |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2377 # with the plaintext by clients. |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2378 pass |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2379 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2380 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
|
2381 # 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
|
2382 # 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
|
2383 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
|
2384 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
|
2385 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
|
2386 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2387 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
|
2388 # 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
|
2389 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
|
2390 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2391 # Mark the message as trusted or untrusted. Undecided counts as untrusted here. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2392 trust_level = await session_manager._evaluate_custom_trust_level( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2393 device_information |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2394 ) |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2395 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2396 if trust_level is omemo.TrustLevel.TRUSTED: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
2397 post_treat.addCallback(client.encryption.mark_as_trusted) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2398 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4007
diff
changeset
|
2399 post_treat.addCallback(client.encryption.mark_as_untrusted) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2400 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2401 # 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
|
2402 post_treat.addCallback( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2403 client.encryption.mark_as_encrypted, namespace=message.namespace |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2404 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2405 |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2406 # Handle potential ATM trust updates |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2407 if affix_values is not None and affix_values.timestamp is not None: |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2408 await self.__message_received_trigger_atm( |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2409 client, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2410 message_elt, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2411 session_manager, |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2412 device_information, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2413 affix_values.timestamp, |
3967
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2414 ) |
f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
Syndace <me@syndace.dev>
parents:
3944
diff
changeset
|
2415 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2416 # 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
|
2417 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2418 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2419 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
|
2420 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2421 @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
|
2422 @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
|
2423 @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
|
2424 """ |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2425 # SCE is only applicable to message and IQ stanzas |
3919
7b2c51bcc8f5
plugin XEP-0384: temporarily disable `<iq>` stanza encryption:
Goffi <goffi@goffi.org>
parents:
3918
diff
changeset
|
2426 # FIXME: temporary disabling IQ stanza encryption |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2427 if stanza.name not in {"message"}: # , "iq" }: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2428 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2429 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2430 # 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
|
2431 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
|
2432 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
|
2433 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
|
2434 # 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
|
2435 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2436 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
|
2437 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
|
2438 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2439 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2440 # 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
|
2441 # 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
|
2442 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2443 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2444 # Parse the JID |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2445 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
|
2446 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2447 # 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
|
2448 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
|
2449 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2450 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
|
2451 # 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
|
2452 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2453 |
4164
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2454 encryption_ns = encryption["plugin"].namespace |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2455 # All pre-checks done, we can start encrypting! |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2456 if encryption_ns in (twomemo.twomemo.NAMESPACE, oldmemo.oldmemo.NAMESPACE): |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2457 await self.encrypt( |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2458 client, |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2459 encryption_ns, |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2460 stanza, |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2461 recipient_bare_jid, |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2462 stanza.getAttribute("type", C.MESS_TYPE_NORMAL) == C.MESS_TYPE_GROUPCHAT, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2463 stanza.getAttribute("id", None), |
4164
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2464 ) |
15482dc0b5d1
plugin XEP-0384: fix trigger used for OLDMEMO:
Goffi <goffi@goffi.org>
parents:
4150
diff
changeset
|
2465 else: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2466 # 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
|
2467 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2468 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2469 # 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
|
2470 if stanza.name == "message": |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2471 self.__xep_0334.add_hint_elements(stanza, ["store"]) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2472 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2473 # 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
|
2474 return True |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2475 |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2476 async def download_missing_device_lists( |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2477 self, |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2478 client: SatXMPPClient, |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2479 namespace: NamespaceType, |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2480 recipients: Iterable[jid.JID], |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2481 session_manager: omemo.SessionManager, |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2482 ) -> None: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2483 """Retrieves missing device lists for recipients outside the profile's roster. |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2484 |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2485 @param client: XMPP client. |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2486 @param namespace: The namespace of the OMEMO version to use. |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2487 @param recipients: Recipients to verify device list presence. |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2488 @param session_manager: OMEMO session manager. |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2489 """ |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2490 recipients = [j.userhostJID() for j in recipients] |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2491 not_in_roster = [j for j in recipients if not client.roster.is_jid_in_roster(j)] |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2492 for bare_jid in not_in_roster: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2493 device_information = await session_manager.get_device_information( |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2494 bare_jid.userhost() |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2495 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2496 if not device_information or not all( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2497 namespace in di.namespaces for di in device_information |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2498 ): |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2499 if namespace == self.NS_TWOMEMO: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2500 algo, node = "OMEMO", TWOMEMO_DEVICE_LIST_NODE |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2501 elif namespace == self.NS_OLDMEMO: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2502 algo, node = "OMEMO_legacy", OLDMEMO_DEVICE_LIST_NODE |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2503 else: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2504 raise ValueError(f"Invalid namespace: {namespace!r}") |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2505 |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2506 try: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2507 items, __ = await self._j.get_items(client, bare_jid, node, 1) |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2508 |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2509 except Exception: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2510 log.exception(f"Can't find {algo} devices list for {bare_jid}.") |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2511 else: |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2512 await self._update_device_list(client, bare_jid, items) |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2513 log.warning(f"{algo} devices list updated for {bare_jid}.") |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2514 |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2515 async def encrypt( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2516 self, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2517 client: SatXMPPClient, |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2518 namespace: NamespaceType, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2519 stanza: domish.Element, |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2520 recipient_jids: Union[jid.JID, Set[jid.JID]], |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2521 is_muc_message: bool, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2522 stanza_id: Optional[str], |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2523 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2524 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2525 @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
|
2526 @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
|
2527 @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
|
2528 oldmemo will encrypt only the body. The stanza is modified by this call. |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2529 @param recipient_jid: The JID of the recipients. |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2530 Can be a bare (aka "userhost") JIDs but doesn't have to. |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2531 A single JID can be used. |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2532 @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
|
2533 @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
|
2534 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
|
2535 reflection handling. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2536 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2537 @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
|
2538 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
|
2539 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
|
2540 """ |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2541 if isinstance(recipient_jids, jid.JID): |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2542 recipient_jids = {recipient_jids} |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2543 if not recipient_jids: |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2544 raise exceptions.InternalError("At least one JID must be specified") |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2545 recipient_jid = next(iter(recipient_jids)) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2546 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2547 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
|
2548 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2549 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
|
2550 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
|
2551 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2552 if is_muc_message: |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2553 if len(recipient_jids) != 1: |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2554 raise exceptions.InternalError( |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2555 'Only one JID can be set when "is_muc_message" is set' |
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2556 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2557 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
|
2558 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2559 "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
|
2560 " available." |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2561 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2562 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2563 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
|
2564 raise exceptions.InternalError( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2565 "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
|
2566 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2567 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2568 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
|
2569 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2570 recipient_bare_jids = self.__get_joined_muc_users( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2571 client, self.__xep_0045, room_jid |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2572 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2573 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2574 muc_plaintext_cache_key = MUCPlaintextCacheKey( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2575 client=client, room_jid=room_jid, message_uid=stanza_id |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2576 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2577 else: |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3969
diff
changeset
|
2578 recipient_bare_jids = {r.userhost() for r in recipient_jids} |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2579 feedback_jid = recipient_jid.userhostJID() |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2580 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2581 log.debug( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2582 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
|
2583 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
|
2584 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2585 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2586 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
|
2587 """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
|
2588 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2589 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
|
2590 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
|
2591 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2592 @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
|
2593 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
|
2594 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
|
2595 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
|
2596 """ |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2597 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2598 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
|
2599 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
|
2600 OMEMO.SCE_PROFILE_GROUPCHAT if is_muc_message else OMEMO.SCE_PROFILE, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2601 stanza, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2602 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2603 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2604 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
|
2605 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
|
2606 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2607 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
|
2608 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
|
2609 plaintext = str(child).encode("utf-8") |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2610 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2611 # Any other sensitive elements to remove here? |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2612 if child.name in {"body", "html"}: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2613 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
|
2614 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2615 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
|
2616 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2617 "No body found in intercepted message to be encrypted with" |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4219
diff
changeset
|
2618 f" oldmemo. [{client.profile}]" |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2619 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2620 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2621 return plaintext |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2622 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2623 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
|
2624 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2625 # 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
|
2626 # safety reasons. |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2627 plaintext = prepare_stanza() |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2628 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
|
2629 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2630 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2631 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
|
2632 |
3969
8e7d5796fb23
plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO):
Goffi <goffi@goffi.org>
parents:
3967
diff
changeset
|
2633 session_manager = await self.get_session_manager(client.profile) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2634 await self.download_missing_device_lists( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2635 client, namespace, recipient_jids, session_manager |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2636 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2637 |
3214
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
2638 try: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2639 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
|
2640 frozenset(recipient_bare_jids), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2641 {namespace: plaintext}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2642 backend_priority_order=[namespace], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2643 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
|
2644 ) |
8d92d4d829fb
plugin XEP-0384: use "max_items=1" for devices and bundles nodes:
Goffi <goffi@goffi.org>
parents:
3172
diff
changeset
|
2645 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
|
2646 msg = _( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2647 # 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
|
2648 "Can't encrypt message for {entities}: {reason}".format( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2649 entities=", ".join(recipient_bare_jids), reason=e |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2650 ) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3236
diff
changeset
|
2651 ) |
2859
4e875d9eea48
plugin XEP-0384: give feedback to client when encryption failed
Goffi <goffi@goffi.org>
parents:
2858
diff
changeset
|
2652 log.warning(msg) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2653 client.feedback(feedback_jid, msg, {C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR}) |
2858
31a5038cdf79
plugin XEP-0384: small refactoring to encrypt messages + bugfix:
Goffi <goffi@goffi.org>
parents:
2857
diff
changeset
|
2654 raise e |
2738
eb58f26ed236
plugin XEP-0384: update to last python-omemo + trust management:
Goffi <goffi@goffi.org>
parents:
2662
diff
changeset
|
2655 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2656 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
|
2657 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2658 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
|
2659 f" {encryption_errors}" |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2660 ) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2661 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2662 encrypted_errors_stringified = ", ".join( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2663 [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2664 f"device {err.device_id} of {err.bare_jid} under namespace" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2665 f" {err.namespace}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2666 for err in encryption_errors |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2667 ] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2668 ) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2669 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2670 client.feedback( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2671 feedback_jid, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2672 D_( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2673 "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
|
2674 " 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
|
2675 " 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
|
2676 " 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
|
2677 " 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
|
2678 f" affected: {encrypted_errors_stringified}." |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2679 ), |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2680 ) |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2681 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2682 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
|
2683 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2684 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
|
2685 # Add the encrypted element |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2686 stanza.addChild( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2687 xml_tools.et_elt_2_domish_elt(twomemo.etree.serialize_message(message)) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2688 ) |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2689 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2690 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
|
2691 # Add the encrypted element |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2692 stanza.addChild( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2693 xml_tools.et_elt_2_domish_elt(oldmemo.etree.serialize_message(message)) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2694 ) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2695 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2696 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
|
2697 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
|
2698 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2699 async def __on_device_list_update( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2700 self, items_event: pubsub.ItemsEvent, profile: str |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2701 ) -> None: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2702 """Handle device list updates fired by PEP. |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2703 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2704 @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
|
2705 @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
|
2706 """ |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2707 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2708 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
|
2709 items = cast(List[domish.Element], items_event.items) |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2710 client = self.host.get_client(profile) |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2711 await self._update_device_list(client, sender, items) |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2712 |
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2713 async def _update_device_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2714 self, client: SatXMPPEntity, sender: jid.JID, items: list[domish.Element] |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2715 ) -> None: |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2716 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2717 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
|
2718 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
|
2719 return |
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2720 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2721 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
|
2722 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
|
2723 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
|
2724 return |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2725 |
3914
4cb38c8312a1
plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing:
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
2726 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
|
2727 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2728 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
|
2729 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
|
2730 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2731 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
|
2732 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
|
2733 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2734 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
|
2735 except XMLSchemaValidationError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2736 pass |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2737 else: |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2738 namespace = twomemo.twomemo.NAMESPACE |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2739 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2740 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
|
2741 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
|
2742 try: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2743 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
|
2744 except XMLSchemaValidationError: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2745 pass |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2746 else: |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2747 namespace = oldmemo.oldmemo.NAMESPACE |
3104
118d91c932a7
plugin XEP-0384: OMEMO for MUC implementation:
Goffi <goffi@goffi.org>
parents:
3098
diff
changeset
|
2748 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2749 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
|
2750 log.warning( |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2751 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
|
2752 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
|
2753 ) |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2754 return |
2648
0f76813afc57
plugin XEP-0384: OMEMO implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2755 |
4219
1b5cf2ee1d86
plugin XEP-0384, XEP-0391: download missing devices list:
Goffi <goffi@goffi.org>
parents:
4218
diff
changeset
|
2756 session_manager = await self.get_session_manager(client.profile) |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2757 |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2758 await session_manager.update_device_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
2759 namespace, sender.userhost(), device_list |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3797
diff
changeset
|
2760 ) |