Use nbxmpp's parsed EME data
This commit is contained in:
parent
12d909d636
commit
0963f44443
|
@ -200,6 +200,23 @@ class MUCUser(IntEnum):
|
|||
AFFILIATION_TEXT = 4
|
||||
|
||||
|
||||
EME_MESSAGES = {
|
||||
'urn:xmpp:otr:0':
|
||||
_('This message was encrypted with OTR '
|
||||
'and could not be decrypted.'),
|
||||
'jabber:x:encrypted':
|
||||
_('This message was encrypted with Legacy '
|
||||
'OpenPGP and could not be decrypted. You can install '
|
||||
'the PGP plugin to handle those messages.'),
|
||||
'urn:xmpp:openpgp:0':
|
||||
_('This message was encrypted with '
|
||||
'OpenPGP for XMPP and could not be decrypted.'),
|
||||
'fallback':
|
||||
_('This message was encrypted with %s '
|
||||
'and could not be decrypted.')
|
||||
}
|
||||
|
||||
|
||||
ACTIVITIES = {
|
||||
'doing_chores': {
|
||||
'category': _('Doing Chores'),
|
||||
|
|
|
@ -33,7 +33,7 @@ from gajim.common.helpers import AdditionalDataDict
|
|||
from gajim.common.modules.misc import parse_delay
|
||||
from gajim.common.modules.misc import parse_oob
|
||||
from gajim.common.modules.misc import parse_correction
|
||||
from gajim.common.modules.misc import parse_eme
|
||||
from gajim.common.modules.util import get_eme_message
|
||||
|
||||
log = logging.getLogger('gajim.c.m.archiving')
|
||||
|
||||
|
@ -170,11 +170,9 @@ class MAM:
|
|||
else:
|
||||
app.plugin_manager.extension_point(
|
||||
'decrypt', self._con, event, self._decryption_finished)
|
||||
|
||||
if not event.encrypted:
|
||||
eme = parse_eme(event.message)
|
||||
if eme is not None:
|
||||
event.msgtxt = eme
|
||||
if properties.eme is not None:
|
||||
event.msgtxt = get_eme_message(properties.eme)
|
||||
self._decryption_finished(event)
|
||||
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
|
|
@ -28,10 +28,10 @@ from gajim.common.nec import NetworkIncomingEvent
|
|||
from gajim.common.nec import NetworkEvent
|
||||
from gajim.common.helpers import AdditionalDataDict
|
||||
from gajim.common.const import KindConstant
|
||||
from gajim.common.modules.util import get_eme_message
|
||||
from gajim.common.modules.security_labels import parse_securitylabel
|
||||
from gajim.common.modules.user_nickname import parse_nickname
|
||||
from gajim.common.modules.misc import parse_delay
|
||||
from gajim.common.modules.misc import parse_eme
|
||||
from gajim.common.modules.misc import parse_correction
|
||||
from gajim.common.modules.misc import parse_attention
|
||||
from gajim.common.modules.misc import parse_form
|
||||
|
@ -187,9 +187,8 @@ class Message:
|
|||
app.plugin_manager.extension_point(
|
||||
'decrypt', self._con, event, self._on_message_decrypted)
|
||||
if not event.encrypted:
|
||||
eme = parse_eme(event.stanza)
|
||||
if eme is not None:
|
||||
event.msgtxt = eme
|
||||
if properties.eme is not None:
|
||||
event.msgtxt = get_eme_message(properties.eme)
|
||||
self._on_message_decrypted(event)
|
||||
|
||||
def _on_message_decrypted(self, event):
|
||||
|
|
|
@ -19,50 +19,11 @@ import logging
|
|||
import nbxmpp
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common.i18n import _
|
||||
from gajim.common.modules.date_and_time import parse_datetime
|
||||
|
||||
log = logging.getLogger('gajim.c.m.misc')
|
||||
|
||||
|
||||
# XEP-0380: Explicit Message Encryption
|
||||
|
||||
_eme_namespaces = {
|
||||
'urn:xmpp:otr:0':
|
||||
_('This message was encrypted with OTR '
|
||||
'and could not be decrypted.'),
|
||||
'jabber:x:encrypted':
|
||||
_('This message was encrypted with Legacy '
|
||||
'OpenPGP and could not be decrypted. You can install '
|
||||
'the PGP plugin to handle those messages.'),
|
||||
'urn:xmpp:openpgp:0':
|
||||
_('This message was encrypted with '
|
||||
'OpenPGP for XMPP and could not be decrypted.'),
|
||||
'fallback':
|
||||
_('This message was encrypted with %s '
|
||||
'and could not be decrypted.')
|
||||
}
|
||||
|
||||
|
||||
def parse_eme(stanza):
|
||||
enc_tag = stanza.getTag('encryption', namespace=nbxmpp.NS_EME)
|
||||
if enc_tag is None:
|
||||
return
|
||||
|
||||
ns = enc_tag.getAttr('namespace')
|
||||
if ns is None:
|
||||
log.warning('No namespace on EME message')
|
||||
return
|
||||
|
||||
if ns in _eme_namespaces:
|
||||
log.info('Found not decrypted message: %s', ns)
|
||||
return _eme_namespaces.get(ns)
|
||||
|
||||
enc_name = enc_tag.getAttr('name')
|
||||
log.info('Found not decrypted message: %s', enc_name or ns)
|
||||
return _eme_namespaces.get('fallback') % enc_name or ns
|
||||
|
||||
|
||||
# XEP-0203: Delayed Delivery
|
||||
|
||||
def parse_delay(stanza, epoch=True, convert='utc', from_=None, not_from=None):
|
||||
|
|
|
@ -20,6 +20,7 @@ from functools import wraps
|
|||
from functools import partial
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common.const import EME_MESSAGES
|
||||
|
||||
|
||||
def from_xs_boolean(value: Union[str, bool]) -> bool:
|
||||
|
@ -73,3 +74,10 @@ def store_publish(func):
|
|||
return
|
||||
return func(self, *args, **kwargs)
|
||||
return func_wrapper
|
||||
|
||||
|
||||
def get_eme_message(eme_data):
|
||||
try:
|
||||
return EME_MESSAGES[eme_data.namespace]
|
||||
except KeyError:
|
||||
return EME_MESSAGES['fallback'] % eme_data.name
|
||||
|
|
|
@ -28,6 +28,7 @@ from unittest.mock import Mock
|
|||
import nbxmpp
|
||||
from nbxmpp import dispatcher_nb
|
||||
from nbxmpp import simplexml
|
||||
from nbxmpp.structs import StanzaHandler
|
||||
from nbxmpp.plugin import PlugIn
|
||||
from nbxmpp.idlequeue import IdleObject
|
||||
from nbxmpp.transports_nb import DATA_RECEIVED
|
||||
|
@ -322,8 +323,10 @@ class P2PClient(IdleObject):
|
|||
|
||||
def _register_handlers(self):
|
||||
self._caller.peerhost = self.Connection._sock.getsockname()
|
||||
self.RegisterHandler('message', lambda conn,
|
||||
data: self._caller._messageCB(self.Server, conn, data))
|
||||
|
||||
self.RegisterHandler(*StanzaHandler(name='message',
|
||||
callback=self._caller._messageCB))
|
||||
|
||||
self.RegisterHandler('iq', self._caller._siSetCB, 'set', nbxmpp.NS_SI)
|
||||
self.RegisterHandler('iq', self._caller._siErrorCB, 'error',
|
||||
nbxmpp.NS_SI)
|
||||
|
|
|
@ -27,14 +27,13 @@ import nbxmpp
|
|||
from gajim.common import app
|
||||
|
||||
from gajim.common.protocol.bytestream import ConnectionSocks5BytestreamZeroconf
|
||||
from gajim.common.zeroconf.zeroconf import Constant
|
||||
from gajim.common import connection_handlers
|
||||
from gajim.common.i18n import _
|
||||
from gajim.common.helpers import AdditionalDataDict
|
||||
from gajim.common.nec import NetworkIncomingEvent, NetworkEvent
|
||||
from gajim.common.const import KindConstant
|
||||
from gajim.common.modules.user_nickname import parse_nickname
|
||||
from gajim.common.modules.misc import parse_eme
|
||||
from gajim.common.modules.util import get_eme_message
|
||||
from gajim.common.modules.misc import parse_correction
|
||||
from gajim.common.modules.misc import parse_attention
|
||||
from gajim.common.modules.misc import parse_oob
|
||||
|
@ -65,11 +64,11 @@ class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
|
|||
connection_handlers.ConnectionJingle.__init__(self)
|
||||
connection_handlers.ConnectionHandlersBase.__init__(self)
|
||||
|
||||
def _messageCB(self, ip, con, stanza):
|
||||
def _messageCB(self, _con, stanza, properties):
|
||||
"""
|
||||
Called when we receive a message
|
||||
"""
|
||||
log.debug('Zeroconf MessageCB')
|
||||
log.info('Zeroconf MessageCB')
|
||||
|
||||
app.nec.push_incoming_event(NetworkEvent(
|
||||
'raw-message-received',
|
||||
|
@ -85,13 +84,6 @@ class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
|
|||
|
||||
fjid = str(stanza.getFrom())
|
||||
|
||||
if fjid is None:
|
||||
for key in self.connection.zeroconf.contacts:
|
||||
if ip == self.connection.zeroconf.contacts[key][
|
||||
Constant.ADDRESS]:
|
||||
fjid = key
|
||||
break
|
||||
|
||||
jid, resource = app.get_room_and_nick_from_fjid(fjid)
|
||||
|
||||
thread_id = stanza.getThread()
|
||||
|
@ -132,9 +124,8 @@ class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
|
|||
app.plugin_manager.extension_point(
|
||||
'decrypt', self, event, self._on_message_decrypted)
|
||||
if not event.encrypted:
|
||||
eme = parse_eme(event.stanza)
|
||||
if eme is not None:
|
||||
event.msgtxt = eme
|
||||
if properties.eme is not None:
|
||||
event.msgtxt = get_eme_message(properties.eme)
|
||||
self._on_message_decrypted(event)
|
||||
|
||||
def _on_message_decrypted(self, event):
|
||||
|
|
Loading…
Reference in New Issue