From e292b78a5d46a0bc34dfe69407e06d6f63a94d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 29 Sep 2018 18:29:59 +0200 Subject: [PATCH] Fix security labels --- gajim/chat_control.py | 2 +- gajim/chat_control_base.py | 33 ++++++++++++++----------- gajim/common/modules/security_labels.py | 8 ++++-- gajim/conversation_textview.py | 13 +++------- gajim/data/gui/chat_control.ui | 10 ++++---- gajim/data/gui/groupchat_control.ui | 4 +-- gajim/groupchat_control.py | 2 +- 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/gajim/chat_control.py b/gajim/chat_control.py index c1a8235fe..745a5a1f3 100644 --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -205,7 +205,7 @@ class ChatControl(ChatControlBase): session = app.connections[self.account].find_controlless_session( self.contact.jid, resource) - self.setup_seclabel(self.xml.get_object('label_selector')) + self.setup_seclabel() if session: session.control = self self.session = session diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 3520bb32d..4e9249171 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -27,6 +27,7 @@ import os import re import time +import nbxmpp from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib @@ -167,8 +168,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): def status_url_clicked(self, widget, url): helpers.launch_browser_mailer('url', url) - def setup_seclabel(self, combo): - self.seclabel_combo = combo + def setup_seclabel(self): self.seclabel_combo.hide() self.seclabel_combo.set_no_show_all(True) lb = Gtk.ListStore(str) @@ -185,7 +185,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): def _sec_labels_received(self, event): if event.account != self.account: return - if event.jid != self.contact.jid: + jid = nbxmpp.JID(self.contact.jid) + if event.host != jid.getDomain(): return lb = self.seclabel_combo.get_model() lb.clear() @@ -323,6 +324,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): self.command_hits = [] self.last_key_tabs = False + # Security Labels + self.seclabel_combo = self.xml.get_object('label_selector') + # chatstate timers and state self.reset_kbd_mouse_timeout_vars() self.possible_paused_timeout_id = None @@ -352,7 +356,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): self._nec_ping) app.ged.register_event_handler('ping-error', ged.GUI1, self._nec_ping) - app.ged.register_event_handler('sec-label-received', ged.GUI1, + app.ged.register_event_handler('sec-catalog-received', ged.GUI1, self._sec_labels_received) app.ged.register_event_handler('style-changed', ged.GUI1, self._style_changed) @@ -531,7 +535,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): 'chat_control_base_draw_banner', self) app.ged.remove_event_handler('our-show', ged.GUI1, self._nec_our_status) - app.ged.remove_event_handler('sec-label-received', ged.GUI1, + app.ged.remove_event_handler('sec-catalog-received', ged.GUI1, self._sec_labels_received) app.ged.remove_event_handler('style-changed', ged.GUI1, self._style_changed) @@ -764,15 +768,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): ft.send_file(self.account, contact, path) def get_seclabel(self): - label = None - if self.seclabel_combo is not None: - idx = self.seclabel_combo.get_active() - if idx != -1: - con = app.connections[self.account] - catalog = con.get_module('SecLabels').get_catalog(self.contact.jid) - labels, label_list, _ = catalog - lname = label_list[idx] - label = labels[lname] + idx = self.seclabel_combo.get_active() + if idx == -1: + return + + con = app.connections[self.account] + jid = nbxmpp.JID(self.contact.jid) + catalog = con.get_module('SecLabels').get_catalog(jid.getDomain()) + labels, label_list, _ = catalog + lname = label_list[idx] + label = labels[lname] return label def send_message(self, message, keyID='', type_='chat', chatstate=None, diff --git a/gajim/common/modules/security_labels.py b/gajim/common/modules/security_labels.py index d00318c48..ba84e1c7e 100644 --- a/gajim/common/modules/security_labels.py +++ b/gajim/common/modules/security_labels.py @@ -42,11 +42,12 @@ class SecLabels: log.info('Discovered security labels: %s', from_) def request_catalog(self, jid): + jid = nbxmpp.JID(jid) server = app.get_jid_from_account(self._account).split("@")[1] iq = nbxmpp.Iq(typ='get', to=server) iq.addChild(name='catalog', namespace=nbxmpp.NS_SECLABEL_CATALOG, - attrs={'to': jid}) + attrs={'to': jid.getDomain()}) log.info('Request catalog: server: %s, to: %s', server, jid) self._con.connection.SendAndCallForResponse( iq, self._catalog_received) @@ -73,8 +74,11 @@ class SecLabels: catalog = (labels, label_list, default) self._catalogs[to] = catalog + log.info('Received catalog from %s', stanza.getFrom()) + log.debug(catalog) + app.nec.push_incoming_event(SecLabelCatalog( - None, account=self._account, jid=to, catalog=catalog)) + None, account=self._account, host=to, catalog=catalog)) def get_catalog(self, jid): return self._catalogs.get(jid) diff --git a/gajim/conversation_textview.py b/gajim/conversation_textview.py index e0ed032cb..0f1dd0d60 100644 --- a/gajim/conversation_textview.py +++ b/gajim/conversation_textview.py @@ -1017,7 +1017,7 @@ class ConversationTextview(GObject.GObject): # If there's a displaymarking, print it here. if displaymarking: - self.print_displaymarking(displaymarking, iter_=iter_) + self.print_displaymarking(displaymarking, iter_) # kind = info, we print things as if it was a status: same color, ... if kind in ('error', 'info'): @@ -1209,21 +1209,16 @@ class ConversationTextview(GObject.GObject): buffer_.insert_with_tags_by_name(iter_, tim_format + '\n', 'time_sometimes') - def print_displaymarking(self, displaymarking, iter_=None): + def print_displaymarking(self, displaymarking, iter_): bgcolor = displaymarking.getAttr('bgcolor') or '#FFF' fgcolor = displaymarking.getAttr('fgcolor') or '#000' text = displaymarking.getData() if text: buffer_ = self.tv.get_buffer() - if iter_: - end_iter = iter_ - else: - end_iter = buffer_.get_end_iter() tag = self.displaymarking_tags.setdefault(bgcolor + '/' + fgcolor, buffer_.create_tag(None, background=bgcolor, foreground=fgcolor)) - buffer_.insert_with_tags(end_iter, '[' + text + ']', tag) - end_iter = buffer_.get_end_iter() - buffer_.insert_with_tags(end_iter, ' ') + buffer_.insert_with_tags(iter_, '[' + text + ']', tag) + buffer_.insert_with_tags(iter_, ' ') def print_name(self, name, kind, other_tags_for_name, direction_mark='', iter_=None): diff --git a/gajim/data/gui/chat_control.ui b/gajim/data/gui/chat_control.ui index d0309c7ef..0935ff898 100644 --- a/gajim/data/gui/chat_control.ui +++ b/gajim/data/gui/chat_control.ui @@ -1,5 +1,5 @@ - + @@ -24,6 +24,9 @@ True False False + + + True @@ -278,9 +281,6 @@ - - - True @@ -639,7 +639,7 @@ False - True + False True end 0 diff --git a/gajim/data/gui/groupchat_control.ui b/gajim/data/gui/groupchat_control.ui index f98bcb641..03c4118a2 100644 --- a/gajim/data/gui/groupchat_control.ui +++ b/gajim/data/gui/groupchat_control.ui @@ -1,5 +1,5 @@ - + @@ -386,7 +386,7 @@ True - True + False True 7 diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index 3616b04cc..33b159951 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -454,7 +454,7 @@ class GroupchatControl(ChatControlBase): column.set_visible(False) self.list_treeview.set_expander_column(column) - self.setup_seclabel(self.xml.get_object('label_selector')) + self.setup_seclabel() self.form_widget = None