plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:

- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint

fix 375
This commit is contained in:
Syndace 2022-08-23 21:06:24 +02:00
commit 75ae8160ae

View file

@ -19,10 +19,11 @@
import copy
from functools import partial
from collections import namedtuple
from typing import Optional
from twisted.words.protocols.jabber import jid
from twisted.internet import defer
from twisted.python import failure
from sat.core.core_types import EncryptionPlugin, EncryptionSession, MessageData
from sat.core.i18n import D_, _
from sat.core.constants import Const as C
from sat.core import exceptions
@ -34,12 +35,6 @@ from sat.memory import persistent
log = getLogger(__name__)
EncryptionPlugin = namedtuple("EncryptionPlugin", ("instance",
"name",
"namespace",
"priority",
"directed"))
class EncryptionHandler:
"""Class to handle encryption sessions for a client"""
@ -339,7 +334,7 @@ class EncryptionHandler:
self.client.feedback(entity, msg)
def getSession(self, entity):
def getSession(self, entity: jid.JID) -> Optional[EncryptionSession]:
"""Get encryption session for this contact
@param entity(jid.JID): get the session for this entity
@ -476,13 +471,17 @@ class EncryptionHandler:
return mess_data
def isEncryptionRequested(self, mess_data, namespace=None):
def isEncryptionRequested(
self,
mess_data: MessageData,
namespace: Optional[str] = None
) -> bool:
"""Helper method to check if encryption is requested in an outgoind message
@param mess_data(dict): message data for outgoing message
@param namespace(str, None): if set, check if encryption is requested for the
algorithm specified
@return (bool): True if the encryption flag is present
@param mess_data: message data for outgoing message
@param namespace: if set, check if encryption is requested for the algorithm
specified
@return: True if the encryption flag is present
"""
encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
if encryption is None: