diff --git a/ChangeLog b/ChangeLog index 0806957..ee1d4c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Version 0.7.0: +xxxx-xx-xx Maxime “pep” Buquet + * Changes: + - Add own-key support to fingerprint method. Requires Poezio 237fd74. + Version 0.6.0: 2022-04-03 Maxime “pep” Buquet * Changes: diff --git a/poezio_omemo/__init__.py b/poezio_omemo/__init__.py index 5eb8b7a..c70931f 100644 --- a/poezio_omemo/__init__.py +++ b/poezio_omemo/__init__.py @@ -16,12 +16,12 @@ import base64 import hashlib import logging from pathlib import Path -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Tuple from poezio import colors from poezio.plugin_e2ee import E2EEPlugin from poezio.xdg import DATA_HOME -from poezio.theming import Theme +from poezio.theming import Theme, dump_tuple from poezio.tabs import ChatTab, DynamicConversationTab, StaticConversationTab, MucTab from omemo.exceptions import MissingBundleException @@ -123,13 +123,17 @@ class Plugin(E2EEPlugin): """Poezio logger Helper""" self.api.information(txt, 'Error') - async def get_fingerprints(self, jid: JID) -> List[str]: + async def get_fingerprints(self, jid: JID) -> List[Tuple[str, bool]]: """Return fingerprints for the provided JID""" # XXX: Do we want to keep this here? self.core.information('Fetching up-to-date fingerprint information…', 'Info') await self.core.xmpp['xep_0384'].fetch_devices(jid) await self.core.xmpp['xep_0384'].fetch_bundles(jid) + res: List[Tuple[str, bool]] = [] + if jid.bare == self.core.xmpp.boundjid.bare: + res = [(await self.core.xmpp['xep_0384'].my_fingerprint(), True)] + devices = await self.core.xmpp['xep_0384'].get_trust_for_jid(jid) # XXX: What to do with did -> None entries? @@ -137,14 +141,16 @@ class Plugin(E2EEPlugin): # For now I'll merge both. We should probably display them separately # later on. devices['active'].update(devices['inactive']) - return [ - slixmpp_omemo.fp_from_ik(trust['key']) + res.extend([ + (slixmpp_omemo.fp_from_ik(trust['key']), False) for trust in devices['active'].values() if trust is not None - ] + ]) + + return res @staticmethod - def format_fingerprint(fingerprint: str, theme: Theme) -> str: + def format_fingerprint(fingerprint: str, own: bool, theme: Theme) -> str: """ Color fingerprint as specified in in XEP-0384 0.8.3 “§8 Security Considerations”. @@ -166,6 +172,9 @@ class Plugin(E2EEPlugin): elif i == size - 1: separator = '' colored_fp += f'\x19{fg_color}}}{part}{separator}' + if own: + normal_color = dump_tuple(theme.COLOR_NORMAL_TEXT) + colored_fp += f'\x19{normal_color}}} (this device)' return colored_fp def reset_session(self, args: str) -> None: