diff options
author | Philipp Hörist <philipp@hoerist.com> | 2019-04-14 13:19:59 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2019-04-14 13:20:33 +0300 |
commit | d343e2be5b162607e08081c4378ca7895af4b1b1 (patch) | |
tree | d96cec6fd0f6b5acb8a1d9c9e24fc77de0a00b25 | |
parent | 11dffacfefb7db839ab5bdd47749edc935089dfa (diff) |
Add PGP Legacy (XEP-0027) module
-rw-r--r-- | nbxmpp/dispatcher.py | 4 | ||||
-rw-r--r-- | nbxmpp/modules/pgplegacy.py (renamed from nbxmpp/modules/signed.py) | 24 | ||||
-rw-r--r-- | nbxmpp/structs.py | 5 |
3 files changed, 30 insertions, 3 deletions
diff --git a/nbxmpp/dispatcher.py b/nbxmpp/dispatcher.py index a70ed01..f78a5bd 100644 --- a/nbxmpp/dispatcher.py +++ b/nbxmpp/dispatcher.py @@ -50,7 +50,7 @@ from nbxmpp.modules.nickname import Nickname from nbxmpp.modules.delay import Delay from nbxmpp.modules.muc import MUC from nbxmpp.modules.idle import Idle -from nbxmpp.modules.signed import Signed +from nbxmpp.modules.pgplegacy import PGPLegacy from nbxmpp.modules.vcard_avatar import VCardAvatar from nbxmpp.modules.captcha import Captcha from nbxmpp.modules.entity_caps import EntityCaps @@ -187,7 +187,7 @@ class XMPPDispatcher(PlugIn): self._modules['Delay'] = Delay(self._owner) self._modules['Captcha'] = Captcha(self._owner) self._modules['Idle'] = Idle(self._owner) - self._modules['Signed'] = Signed(self._owner) + self._modules['PGPLegacy'] = PGPLegacy(self._owner) self._modules['VCardAvatar'] = VCardAvatar(self._owner) self._modules['EntityCaps'] = EntityCaps(self._owner) self._modules['Blocking'] = Blocking(self._owner) diff --git a/nbxmpp/modules/signed.py b/nbxmpp/modules/pgplegacy.py index 159e491..256b89f 100644 --- a/nbxmpp/modules/signed.py +++ b/nbxmpp/modules/pgplegacy.py @@ -18,15 +18,20 @@ import logging from nbxmpp.protocol import NS_SIGNED +from nbxmpp.protocol import NS_ENCRYPTED from nbxmpp.structs import StanzaHandler log = logging.getLogger('nbxmpp.m.signed') -class Signed: +class PGPLegacy: def __init__(self, client): self._client = client self.handlers = [ + StanzaHandler(name='message', + callback=self._process_pgplegacy_message, + ns=NS_ENCRYPTED, + priority=7), StanzaHandler(name='presence', callback=self._process_signed, ns=NS_SIGNED, @@ -40,3 +45,20 @@ class Signed: return properties.signed = signed.getData() + + @staticmethod + def _process_pgplegacy_message(_con, stanza, properties): + pgplegacy = stanza.getTag('x', namespace=NS_ENCRYPTED) + if pgplegacy is None: + log.warning('No x node found') + log.warning(stanza) + return + + data = pgplegacy.getData() + if not data: + log.warning('No data in x node found') + log.warning(stanza) + return + + log.info('Encrypted message received') + properties.pgp_legacy = data diff --git a/nbxmpp/structs.py b/nbxmpp/structs.py index f0d72a6..1ff6a8b 100644 --- a/nbxmpp/structs.py +++ b/nbxmpp/structs.py @@ -206,6 +206,7 @@ class MessageProperties: self.openpgp = None self.omemo = None self.encrypted = None + self.pgp_legacy = None @property def has_user_delay(self): @@ -224,6 +225,10 @@ class MessageProperties: return self.openpgp is not None @property + def is_pgp_legacy(self): + return self.pgp_legacy is not None + + @property def is_pubsub(self): return self.pubsub |