annotate libervia/backend/plugins/plugin_xep_0374.py @ 4320:9658c534287e

plugin XEP-0215, XEP-0376: fix bad calls to `hasFeature`: `hasFeature` was called like blocking code, missing the `await`. This has been fixed, and is now using the `memory.disco.has_feature` version.
author Goffi <goffi@goffi.org>
date Mon, 30 Sep 2024 14:14:38 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
1 #!/usr/bin/env python3
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
2
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
3 # Libervia plugin for OpenPGP for XMPP Instant Messaging
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
4 # Copyright (C) 2022-2022 Tim Henkes (me@syndace.dev)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
5
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
9 # (at your option) any later version.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
10
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
15
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
18
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
19 from typing import Dict, Optional, Set, cast
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
20
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
21 from typing_extensions import Final
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
22 from wokkel import muc # type: ignore[import]
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
23
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
24 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
25 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
26 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
27 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
28 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
29 from libervia.backend.core.main import LiberviaBackend
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
30 from libervia.backend.core.xmpp import SatXMPPClient
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
31 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
32 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
33 from libervia.backend.plugins.plugin_xep_0373 import NS_OX, XEP_0373, TrustLevel
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
34 from libervia.backend.tools import xml_tools
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
35 from twisted.internet import defer
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
36 from twisted.words.protocols.jabber import jid
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
37 from twisted.words.xish import domish
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
38
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
39
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
40 __all__ = ["PLUGIN_INFO", "XEP_0374", "NS_OXIM"] # pylint: disable=unused-variable
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
41
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
42
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
43 log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call]
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
44
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
45
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
46 PLUGIN_INFO = {
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
47 C.PI_NAME: "OXIM",
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
48 C.PI_IMPORT_NAME: "XEP-0374",
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
49 C.PI_TYPE: "SEC",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
50 C.PI_PROTOCOLS: ["XEP-0374"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
51 C.PI_DEPENDENCIES: ["XEP-0334", "XEP-0373"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
52 C.PI_RECOMMENDATIONS: ["XEP-0045"],
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
53 C.PI_MAIN: "XEP_0374",
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
54 C.PI_HANDLER: "no",
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
55 C.PI_DESCRIPTION: _("""Implementation of OXIM"""),
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
56 }
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
57
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
58
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
59 # The disco feature
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
60 NS_OXIM: Final = "urn:xmpp:openpgp:im:0"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
61
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
62
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
63 class XEP_0374:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
64 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
65 Plugin equipping Libervia with OXIM capabilities under the ``urn:xmpp:openpgp:im:0``
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
66 namespace. MUC messages are supported next to one to one messages. For trust
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
67 management, the two trust models "BTBV" and "manual" are supported.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
68 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
69
4072
040095a5dc7f refactoring: rename `SAT` class to `LiberviaBackend`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
70 def __init__(self, sat: LiberviaBackend) -> None:
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
71 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
72 @param sat: The SAT instance.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
73 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
74
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
75 self.__sat = sat
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
76
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
77 # Plugins
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
78 self.__xep_0045 = cast(Optional[XEP_0045], sat.plugins.get("XEP-0045"))
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
79 self.__xep_0334 = cast(XEP_0334, sat.plugins["XEP-0334"])
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
80 self.__xep_0373 = cast(XEP_0373, sat.plugins["XEP-0373"])
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
81
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
82 # Triggers
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
83 sat.trigger.add(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
84 "message_received", self.__message_received_trigger, priority=100050
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
85 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
86 sat.trigger.add("send", self.__send_trigger, priority=0)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
87
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
88 # Register the encryption plugin
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
89 sat.register_encryption_plugin(self, "OXIM", NS_OX, 102)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
90
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
91 async def get_trust_ui( # pylint: disable=invalid-name
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
92 self, client: SatXMPPClient, entity: jid.JID
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
93 ) -> xml_tools.XMLUI:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
94 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
95 @param client: The client.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
96 @param entity: The entity whose device trust levels to manage.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
97 @return: An XMLUI instance which opens a form to manage the trust level of all
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
98 devices belonging to the entity.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
99 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
100
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
101 return await self.__xep_0373.get_trust_ui(client, entity)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
102
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
103 @staticmethod
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
104 def __get_joined_muc_users(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
105 client: SatXMPPClient, xep_0045: XEP_0045, room_jid: jid.JID
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
106 ) -> Set[jid.JID]:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
107 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
108 @param client: The client.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
109 @param xep_0045: A MUC plugin instance.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
110 @param room_jid: The room JID.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
111 @return: A set containing the bare JIDs of the MUC participants.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
112 @raise InternalError: if the MUC is not joined or the entity information of a
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
113 participant isn't available.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
114 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
115
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
116 bare_jids: Set[jid.JID] = set()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
117
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
118 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
119 room = cast(muc.Room, xep_0045.get_room(client, room_jid))
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
120 except exceptions.NotFound as e:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
121 raise exceptions.InternalError(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
122 "Participant list of unjoined MUC requested."
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
123 ) from e
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
124
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
125 for user in cast(Dict[str, muc.User], room.roster).values():
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
126 entity = cast(Optional[SatXMPPEntity], user.entity)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
127 if entity is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
128 raise exceptions.InternalError(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
129 f"Participant list of MUC requested, but the entity information of"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
130 f" the participant {user} is not available."
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
131 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
132
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
133 bare_jids.add(entity.jid.userhostJID())
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
134
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
135 return bare_jids
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
136
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
137 async def __message_received_trigger(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
138 self,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
139 client: SatXMPPClient,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
140 message_elt: domish.Element,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
141 post_treat: defer.Deferred,
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
142 ) -> bool:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
143 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
144 @param client: The client which received the message.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
145 @param message_elt: The message element. Can be modified.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
146 @param post_treat: A deferred which evaluates to a :class:`MessageData` once the
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
147 message has fully progressed through the message receiving flow. Can be used
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
148 to apply treatments to the fully processed message, like marking it as
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
149 encrypted.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
150 @return: Whether to continue the message received flow.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
151 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
152 sender_jid = jid.JID(message_elt["from"])
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
153 feedback_jid: jid.JID
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
154
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
155 message_type = message_elt.getAttribute("type", "unknown")
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
156 is_muc_message = message_type == C.MESS_TYPE_GROUPCHAT
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
157 if is_muc_message:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
158 if self.__xep_0045 is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
159 log.warning(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
160 "Ignoring MUC message since plugin XEP-0045 is not available."
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
161 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
162 # Can't handle a MUC message without XEP-0045, let the flow continue
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
163 # normally
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
164 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
165
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
166 room_jid = feedback_jid = sender_jid.userhostJID()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
167
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
168 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
169 room = cast(muc.Room, self.__xep_0045.get_room(client, room_jid))
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
170 except exceptions.NotFound:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
171 log.warning(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
172 f"Ignoring MUC message from a room that has not been joined:"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
173 f" {room_jid}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
174 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
175 # Whatever, let the flow continue
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
176 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
177
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
178 sender_user = cast(Optional[muc.User], room.getUser(sender_jid.resource))
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
179 if sender_user is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
180 log.warning(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
181 f"Ignoring MUC message from room {room_jid} since the sender's user"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
182 f" wasn't found {sender_jid.resource}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
183 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
184 # Whatever, let the flow continue
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
185 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
186
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
187 sender_user_jid = cast(Optional[jid.JID], sender_user.entity)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
188 if sender_user_jid is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
189 log.warning(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
190 f"Ignoring MUC message from room {room_jid} since the sender's bare"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
191 f" JID couldn't be found from its user information: {sender_user}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
192 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
193 # Whatever, let the flow continue
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
194 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
195
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
196 sender_jid = sender_user_jid
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
197 else:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
198 # I'm not sure why this check is required, this code is copied from XEP-0384
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
199 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: 3935
diff changeset
200 try:
748094d5a74d plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
Goffi <goffi@goffi.org>
parents: 3935
diff changeset
201 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: 3935
diff changeset
202 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: 3935
diff changeset
203 feedback_jid = client.server_jid
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
204 else:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
205 feedback_jid = sender_jid
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
206
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
207 sender_bare_jid = sender_jid.userhost()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
208
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
209 openpgp_elt = cast(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
210 Optional[domish.Element], next(message_elt.elements(NS_OX, "openpgp"), None)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
211 )
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
212
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
213 if openpgp_elt is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
214 # None of our business, let the flow continue
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
215 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
216
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
217 try:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
218 payload_elt, timestamp = await self.__xep_0373.unpack_openpgp_element(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
219 client, openpgp_elt, "signcrypt", jid.JID(sender_bare_jid)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
220 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
221 except Exception as e:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
222 # TODO: More specific exception handling
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
223 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
224 _("Can't decrypt message: {reason}\n{xml}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
225 reason=e, xml=message_elt.toXml()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
226 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
227 )
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
228 client.feedback(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
229 feedback_jid,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
230 D_(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
231 f"An OXIM message from {sender_jid.full()} can't be decrypted:"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
232 f" {e}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
233 ),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
234 {C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR},
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
235 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
236 # No point in further processing this message
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
237 return False
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
238
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
239 message_elt.children.remove(openpgp_elt)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
240
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
241 log.debug(f"OXIM message of type {message_type} received from {sender_bare_jid}")
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
242
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
243 # Remove all body elements from the original element, since those act as
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
244 # fallbacks in case the encryption protocol is not supported
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
245 for child in message_elt.elements():
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
246 if child.name == "body":
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
247 message_elt.children.remove(child)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
248
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
249 # Move all extension elements from the payload to the stanza root
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
250 # TODO: There should probably be explicitly forbidden elements here too, just as
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
251 # for XEP-0420
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
252 for child in list(payload_elt.elements()):
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
253 # Remove the child from the content element
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
254 payload_elt.children.remove(child)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
255
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
256 # Add the child to the stanza
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
257 message_elt.addChild(child)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
258
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
259 # Mark the message as trusted or untrusted. Undecided counts as untrusted here.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
260 trust_level = TrustLevel.UNDECIDED # TODO: Load the actual trust level
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
261 if trust_level is TrustLevel.TRUSTED:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
262 post_treat.addCallback(client.encryption.mark_as_trusted)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
263 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3967
diff changeset
264 post_treat.addCallback(client.encryption.mark_as_untrusted)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
265
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
266 # Mark the message as originally encrypted
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
267 post_treat.addCallback(client.encryption.mark_as_encrypted, namespace=NS_OX)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
268
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
269 # Message processed successfully, continue with the flow
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
270 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
271
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
272 async def __send_trigger(self, client: SatXMPPClient, stanza: domish.Element) -> bool:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
273 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
274 @param client: The client sending this message.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
275 @param stanza: The stanza that is about to be sent. Can be modified.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
276 @return: Whether the send message flow should continue or not.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
277 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
278 # OXIM only handles message stanzas
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
279 if stanza.name != "message":
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
280 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
281
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
282 # Get the intended recipient
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
283 recipient = stanza.getAttribute("to", None)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
284 if recipient is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
285 raise exceptions.InternalError(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
286 f"Message without recipient encountered. Blocking further processing to"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
287 f" avoid leaking plaintext data: {stanza.toXml()}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
288 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
289
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
290 # Parse the JID
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
291 recipient_bare_jid = jid.JID(recipient).userhostJID()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
292
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
293 # Check whether encryption with OXIM is requested
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
294 encryption = client.encryption.getSession(recipient_bare_jid)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
295
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
296 if encryption is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
297 # Encryption is not requested for this recipient
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
298 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
299
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
300 if encryption["plugin"].namespace != NS_OX:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
301 # Encryption is requested for this recipient, but not with OXIM
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
302 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
303
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
304 # All pre-checks done, we can start encrypting!
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
305 await self.__encrypt(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
306 client,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
307 stanza,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
308 recipient_bare_jid,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
309 stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT,
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
310 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
311
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
312 # Add a store hint if this is a message stanza
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
313 self.__xep_0334.add_hint_elements(stanza, ["store"])
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
314
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
315 # Let the flow continue.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
316 return True
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
317
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
318 async def __encrypt(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
319 self,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
320 client: SatXMPPClient,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
321 stanza: domish.Element,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
322 recipient_jid: jid.JID,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
323 is_muc_message: bool,
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
324 ) -> None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
325 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
326 @param client: The client.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
327 @param stanza: The stanza, which is modified by this call.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
328 @param recipient_jid: The JID of the recipient. Can be a bare (aka "userhost") JID
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
329 but doesn't have to.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
330 @param is_muc_message: Whether the stanza is a message stanza to a MUC room.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
331
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
332 @warning: The calling code MUST take care of adding the store message processing
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
333 hint to the stanza if applicable! This can be done before or after this call,
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
334 the order doesn't matter.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
335 """
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
336
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
337 recipient_bare_jids: Set[jid.JID]
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
338 feedback_jid: jid.JID
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
339
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
340 if is_muc_message:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
341 if self.__xep_0045 is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
342 raise exceptions.InternalError(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
343 "Encryption of MUC message requested, but plugin XEP-0045 is not"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
344 " available."
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
345 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
346
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
347 room_jid = feedback_jid = recipient_jid.userhostJID()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
348
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
349 recipient_bare_jids = self.__get_joined_muc_users(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
350 client, self.__xep_0045, room_jid
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
351 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
352 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
353 recipient_bare_jids = {recipient_jid.userhostJID()}
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
354 feedback_jid = recipient_jid.userhostJID()
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
355
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
356 log.debug(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
357 f"Intercepting message that is to be encrypted by {NS_OX} for"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
358 f" {recipient_bare_jids}"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
359 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
360
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
361 signcrypt_elt, payload_elt = self.__xep_0373.build_signcrypt_element(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
362 recipient_bare_jids
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
363 )
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
364
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
365 # Move elements from the stanza to the content element.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
366 # TODO: There should probably be explicitly forbidden elements here too, just as
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
367 # for XEP-0420
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
368 for child in list(stanza.elements()):
3935
80d29f55ba8b plugin XEP-0374: exluce `openpgp` element from XEP-0373 on send trigger:
Goffi <goffi@goffi.org>
parents: 3933
diff changeset
369 if child.name == "openpgp" and child.uri == NS_OX:
80d29f55ba8b plugin XEP-0374: exluce `openpgp` element from XEP-0373 on send trigger:
Goffi <goffi@goffi.org>
parents: 3933
diff changeset
370 log.debug("not re-encrypting encrypted OX element")
80d29f55ba8b plugin XEP-0374: exluce `openpgp` element from XEP-0373 on send trigger:
Goffi <goffi@goffi.org>
parents: 3933
diff changeset
371 continue
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
372 # Remove the child from the stanza
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
373 stanza.children.remove(child)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
374
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
375 # A namespace of ``None`` can be used on domish elements to inherit the
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
376 # namespace from the parent. When moving elements from the stanza root to
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
377 # the content element, however, we don't want elements to inherit the
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
378 # namespace of the content element. Thus, check for elements with ``None``
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
379 # for their namespace and set the namespace to jabber:client, which is the
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
380 # namespace of the parent element.
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
381 if child.uri is None:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
382 child.uri = C.NS_CLIENT
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
383 child.defaultUri = C.NS_CLIENT
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
384
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
385 # Add the child with corrected namespaces to the content element
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
386 payload_elt.addChild(child)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
387
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
388 try:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
389 openpgp_elt = await self.__xep_0373.build_openpgp_element(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
390 client, signcrypt_elt, recipient_bare_jids
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
391 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
392 except Exception as e:
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
393 msg = _(
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
394 # pylint: disable=consider-using-f-string
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
395 "Can't encrypt message for {entities}: {reason}".format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
396 entities=", ".join(jid.userhost() for jid in recipient_bare_jids),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
397 reason=e,
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
398 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
399 )
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
400 log.warning(msg)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4073
diff changeset
401 client.feedback(feedback_jid, msg, {C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR})
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
402 raise e
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
403
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
404 stanza.addChild(openpgp_elt)