[omemo] Be consistent about omemo capable rooms
- non-anonymous and members-only must be set - Detect all MUC configuration changes - Check MUC capabilities on creation Fixes #445
This commit is contained in:
@@ -310,20 +310,12 @@ class OMEMO(BaseModule):
|
|||||||
else:
|
else:
|
||||||
self.backend.add_muc_member(room, jid)
|
self.backend.add_muc_member(room, jid)
|
||||||
|
|
||||||
if room in self._omemo_groupchats:
|
if self.is_omemo_groupchat(room):
|
||||||
if not self.is_contact_in_roster(jid):
|
if not self.is_contact_in_roster(jid):
|
||||||
# Query Devicelists from JIDs not in our Roster
|
# Query Devicelists from JIDs not in our Roster
|
||||||
self._log.info('%s not in Roster, query devicelist...', jid)
|
self._log.info('%s not in Roster, query devicelist...', jid)
|
||||||
self.request_devicelist(jid)
|
self.request_devicelist(jid)
|
||||||
|
|
||||||
if properties.is_muc_self_presence:
|
|
||||||
if StatusCode.NON_ANONYMOUS in status_codes:
|
|
||||||
# non-anonymous Room (Full JID)
|
|
||||||
self._omemo_groupchats.add(room)
|
|
||||||
|
|
||||||
self._log.info('OMEMO capable Room found: %s', room)
|
|
||||||
self.get_affiliation_list(room)
|
|
||||||
|
|
||||||
def get_affiliation_list(self, room_jid):
|
def get_affiliation_list(self, room_jid):
|
||||||
for affiliation in ('owner', 'admin', 'member'):
|
for affiliation in ('owner', 'admin', 'member'):
|
||||||
self._nbxmpp('MUC').get_affiliation(
|
self._nbxmpp('MUC').get_affiliation(
|
||||||
@@ -354,11 +346,22 @@ class OMEMO(BaseModule):
|
|||||||
return False
|
return False
|
||||||
return contact.sub == 'both'
|
return contact.sub == 'both'
|
||||||
|
|
||||||
def on_muc_config_changed(self, event):
|
def on_muc_disco_update(self, event):
|
||||||
status_codes = event.status_codes or []
|
self._check_if_omemo_capable(event.room_jid)
|
||||||
if StatusCode.CONFIG_NON_ANONYMOUS in status_codes:
|
|
||||||
self._omemo_groupchats.add(event.room_jid)
|
def on_muc_joined(self, event):
|
||||||
self._log.info('Room config change: non-anonymous')
|
self._check_if_omemo_capable(event.room_jid)
|
||||||
|
if self.is_omemo_groupchat(event.room_jid):
|
||||||
|
self.get_affiliation_list(event.room_jid)
|
||||||
|
|
||||||
|
def _check_if_omemo_capable(self, jid):
|
||||||
|
disco_info = app.logger.get_last_disco_info(jid)
|
||||||
|
if disco_info.muc_is_members_only and disco_info.muc_is_nonanonymous:
|
||||||
|
self._log.info('OMEMO room discovered: %s', jid)
|
||||||
|
self._omemo_groupchats.add(jid)
|
||||||
|
else:
|
||||||
|
self._log.info('OMEMO room removed due to config change: %s', jid)
|
||||||
|
self._omemo_groupchats.discard(jid)
|
||||||
|
|
||||||
def _check_for_missing_sessions(self, jid):
|
def _check_for_missing_sessions(self, jid):
|
||||||
devices_without_session = self.backend.devices_without_sessions(jid)
|
devices_without_session = self.backend.devices_without_sessions(jid)
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ class OmemoPlugin(GajimPlugin):
|
|||||||
self.events_handlers = {
|
self.events_handlers = {
|
||||||
'omemo-new-fingerprint': (ged.PRECORE, self._on_new_fingerprints),
|
'omemo-new-fingerprint': (ged.PRECORE, self._on_new_fingerprints),
|
||||||
'signed-in': (ged.PRECORE, self._on_signed_in),
|
'signed-in': (ged.PRECORE, self._on_signed_in),
|
||||||
'muc-config-changed': (ged.GUI2, self._on_muc_config_changed),
|
'muc-disco-update': (ged.GUI1, self._on_muc_disco_update),
|
||||||
|
'muc-joined': (ged.GUI1, self._on_muc_joined),
|
||||||
}
|
}
|
||||||
self.modules = [omemo]
|
self.modules = [omemo]
|
||||||
self.config_dialog = OMEMOConfigDialog(self)
|
self.config_dialog = OMEMOConfigDialog(self)
|
||||||
@@ -177,10 +178,15 @@ class OmemoPlugin(GajimPlugin):
|
|||||||
return
|
return
|
||||||
self.get_omemo(account).on_signed_in()
|
self.get_omemo(account).on_signed_in()
|
||||||
|
|
||||||
def _on_muc_config_changed(self, event):
|
def _on_muc_disco_update(self, event):
|
||||||
if not self._is_enabled_account(event.account):
|
if not self._is_enabled_account(event.account):
|
||||||
return
|
return
|
||||||
self.get_omemo(event.account).on_muc_config_changed(event)
|
self.get_omemo(event.account).on_muc_disco_update(event)
|
||||||
|
|
||||||
|
def _on_muc_joined(self, event):
|
||||||
|
if not self._is_enabled_account(event.account):
|
||||||
|
return
|
||||||
|
self.get_omemo(event.account).on_muc_joined(event)
|
||||||
|
|
||||||
def _update_caps(self, account):
|
def _update_caps(self, account):
|
||||||
if not self._is_enabled_account(account):
|
if not self._is_enabled_account(account):
|
||||||
@@ -189,14 +195,6 @@ class OmemoPlugin(GajimPlugin):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def activate_encryption(chat_control):
|
def activate_encryption(chat_control):
|
||||||
if isinstance(chat_control, GroupchatControl):
|
|
||||||
omemo_con = app.connections[chat_control.account].get_module('OMEMO')
|
|
||||||
if not omemo_con.is_omemo_groupchat(chat_control.room_jid):
|
|
||||||
dialogs.ErrorDialog(
|
|
||||||
_('Bad Configuration'),
|
|
||||||
_('To use OMEMO in a Groupchat, the Groupchat should be'
|
|
||||||
' non-anonymous and members-only.'))
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _muc_encrypt_message(self, conn, obj, callback):
|
def _muc_encrypt_message(self, conn, obj, callback):
|
||||||
@@ -249,6 +247,14 @@ class OmemoPlugin(GajimPlugin):
|
|||||||
self.new_fingerprints_available(chat_control)
|
self.new_fingerprints_available(chat_control)
|
||||||
if isinstance(chat_control, GroupchatControl):
|
if isinstance(chat_control, GroupchatControl):
|
||||||
room = chat_control.room_jid
|
room = chat_control.room_jid
|
||||||
|
if not omemo.is_omemo_groupchat(room):
|
||||||
|
dialogs.ErrorDialog(
|
||||||
|
_('Bad Configuration'),
|
||||||
|
_('To use OMEMO in a Groupchat, the Groupchat should be'
|
||||||
|
' non-anonymous and members-only.'))
|
||||||
|
chat_control.sendmessage = False
|
||||||
|
return
|
||||||
|
|
||||||
missing = True
|
missing = True
|
||||||
for jid in omemo.backend.get_muc_members(room):
|
for jid in omemo.backend.get_muc_members(room):
|
||||||
if not omemo.are_keys_missing(jid):
|
if not omemo.are_keys_missing(jid):
|
||||||
@@ -257,6 +263,7 @@ class OmemoPlugin(GajimPlugin):
|
|||||||
log.info('%s => No Trusted Fingerprints for %s',
|
log.info('%s => No Trusted Fingerprints for %s',
|
||||||
account, room)
|
account, room)
|
||||||
self.print_message(chat_control, UserMessages.NO_FINGERPRINTS)
|
self.print_message(chat_control, UserMessages.NO_FINGERPRINTS)
|
||||||
|
chat_control.sendmessage = False
|
||||||
else:
|
else:
|
||||||
# check if we have devices for the contact
|
# check if we have devices for the contact
|
||||||
if not omemo.backend.get_devices(contact.jid, without_self=True):
|
if not omemo.backend.get_devices(contact.jid, without_self=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user