Commit 4708625d authored by Philipp Hörist's avatar Philipp Hörist

[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
parent bed46293
......@@ -310,20 +310,12 @@ class OMEMO(BaseModule):
else:
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):
# Query Devicelists from JIDs not in our Roster
self._log.info('%s not in Roster, query 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):
for affiliation in ('owner', 'admin', 'member'):
self._nbxmpp('MUC').get_affiliation(
......@@ -354,11 +346,22 @@ class OMEMO(BaseModule):
return False
return contact.sub == 'both'
def on_muc_config_changed(self, event):
status_codes = event.status_codes or []
if StatusCode.CONFIG_NON_ANONYMOUS in status_codes:
self._omemo_groupchats.add(event.room_jid)
self._log.info('Room config change: non-anonymous')
def on_muc_disco_update(self, event):
self._check_if_omemo_capable(event.room_jid)
def on_muc_joined(self, event):
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):
devices_without_session = self.backend.devices_without_sessions(jid)
......
......@@ -91,7 +91,8 @@ class OmemoPlugin(GajimPlugin):
self.events_handlers = {
'omemo-new-fingerprint': (ged.PRECORE, self._on_new_fingerprints),
'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.config_dialog = OMEMOConfigDialog(self)
......@@ -177,10 +178,15 @@ class OmemoPlugin(GajimPlugin):
return
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):
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):
if not self._is_enabled_account(account):
......@@ -189,14 +195,6 @@ class OmemoPlugin(GajimPlugin):
@staticmethod
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
def _muc_encrypt_message(self, conn, obj, callback):
......@@ -249,6 +247,14 @@ class OmemoPlugin(GajimPlugin):
self.new_fingerprints_available(chat_control)
if isinstance(chat_control, GroupchatControl):
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
for jid in omemo.backend.get_muc_members(room):
if not omemo.are_keys_missing(jid):
......@@ -257,6 +263,7 @@ class OmemoPlugin(GajimPlugin):
log.info('%s => No Trusted Fingerprints for %s',
account, room)
self.print_message(chat_control, UserMessages.NO_FINGERPRINTS)
chat_control.sendmessage = False
else:
# check if we have devices for the contact
if not omemo.backend.get_devices(contact.jid, without_self=True):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment