Fix security labels

This commit is contained in:
Philipp Hörist 2018-09-29 18:29:59 +02:00
parent 2cf0fb2eef
commit e292b78a5d
7 changed files with 38 additions and 34 deletions

View File

@ -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

View File

@ -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,12 +768,13 @@ 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:
if idx == -1:
return
con = app.connections[self.account]
catalog = con.get_module('SecLabels').get_catalog(self.contact.jid)
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]

View File

@ -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)

View File

@ -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):

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.21.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="adjustment1">
@ -24,6 +24,9 @@
<property name="skip_pager_hint">True</property>
<property name="decorated">False</property>
<property name="deletable">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
@ -278,9 +281,6 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkMenu" id="formattings_menu">
<property name="visible">True</property>
@ -639,7 +639,7 @@
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.21.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="formattings_menu">
@ -386,7 +386,7 @@
<property name="no_show_all">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
</packing>

View File

@ -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