Commit 2dc16276 authored by Marcin Mielniczuk's avatar Marcin Mielniczuk

Display the current trust of the fingerprint for encrypted messages.

parent f650f51a
Pipeline #3967 passed with stages
in 2 minutes and 43 seconds
......@@ -206,6 +206,15 @@ class ChatControl(ChatControlBase):
self.session = session
# Enable encryption if needed
fprs = {}
if self.encryption is not None:
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
fprs = enc_plugin.get_fingerprints(acct,
self.contact.jid,
groupchat=False)
self.conv_textview.set_encryption(self.encryption, fprs)
self.no_autonegotiation = False
self.add_actions()
self.update_ui()
......
......@@ -367,7 +367,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.handlers[id_] = parent_win.window
self.encryption = self.get_encryption_state()
self.conv_textview.encryption_enabled = self.encryption is not None
# PluginSystem: adding GUI extension point for ChatControlBase
# instance object (also subclasses, eg. ChatControl or GroupchatControl)
......
......@@ -29,6 +29,7 @@ import queue
import urllib
import logging
from calendar import timegm
from typing import Optional, Tuple, Dict
from gi.repository import Gtk
from gi.repository import Pango
......@@ -221,6 +222,7 @@ class ConversationTextview(GObject.GObject):
self._cursor_changed = False
self.last_time_printout = 0
self.encryption_enabled = False
self.fingerprint_trust = {} # type: Dict[str, Trust]
style = self.tv.get_style_context()
style.add_class('gajim-conversation-font')
......@@ -366,6 +368,14 @@ class ConversationTextview(GObject.GObject):
app.css_config.get_value('.gajim-highlight-message', StyleAttr.COLOR))
self.tv.update_tags()
def set_encryption(self,
encryption: Optional[str],
fingerprints: Optional[Dict[str, Trust]] = None
) -> None:
self.encryption_enabled = encryption is not None
if self.encryption_enabled and fingerprints is not None:
self.fingerprint_trust = fingerprints
def scroll_to_end(self, force=False):
if self.autoscroll or force:
util.scroll_to_end(self.tv.get_parent())
......@@ -1147,13 +1157,21 @@ class ConversationTextview(GObject.GObject):
else:
name, fingerprint, trust = details
tooltip = _('Encrypted (%s)') % (name)
if trust is None:
# If a new fingerprint was added, but we may not have it in our dict
# until the textview is reloaded
if fingerprint in self.fingerprint_trust:
current_trust = self.fingerprint_trust[fingerprint]
icon, trust_tooltip, color = TRUST_SYMBOL_DATA[current_trust]
elif trust is None:
# The encryption plugin did not pass trust information
icon = 'channel-secure-symbolic'
color = 'encrypted-color'
else:
# Fallback to the original trust
icon, trust_tooltip, color = TRUST_SYMBOL_DATA[trust]
tooltip = '%s\n%s' % (tooltip, trust_tooltip)
if fingerprint is not None:
fingerprint = format_fingerprint(fingerprint)
tooltip = '%s\n<tt>%s</tt>' % (tooltip, fingerprint)
......@@ -1175,10 +1193,10 @@ class ConversationTextview(GObject.GObject):
self.tv.add_child_at_anchor(image, anchor)
@staticmethod
def _get_encryption_details(additional_data):
def _get_encryption_details(additional_data: AdditionalDataDict) -> Optional[Tuple[str, str, str]]:
name = additional_data.get_value('encrypted', 'name')
if name is None:
return
return None
fingerprint = additional_data.get_value('encrypted', 'fingerprint')
trust = additional_data.get_value('encrypted', 'trust')
......
......@@ -272,6 +272,15 @@ class GroupchatControl(ChatControlBase):
self.control_id)
# Encryption
fprs = {}
if self.encryption is not None:
enc_plugin = app.plugin_manager.encryption_plugins[self.encryption]
fprs = enc_plugin.get_fingerprints(acct,
self.contact.jid,
groupchat=True)
self.conv_textview.set_encryption(self.encryption, fprs)
self.lock_image = self.xml.get_object('lock_image')
self.authentication_button = self.xml.get_object(
'authentication_button')
......
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