From 518ba47e2aaea628e38132a826101a8c17801a79 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 25 Aug 2019 01:39:59 +0200 Subject: omemo: add an api in plugin_e2ee to get the fingerprint(s) of a jid --- poezio/plugin_e2ee.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index 910e3d01..fde7f10c 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -178,6 +178,14 @@ class E2EEPlugin(BasePlugin): help=trust_msg.format(name=self.encryption_short_name, state=state), ) + self.api.add_command( + self.encryption_short_name + '_fingerprint', + self._command_show_fingerprints, + usage='[jid]', + short='Show %s fingerprint(s) for a JID.' % self.encryption_short_name, + help='Show %s fingerprint(s) for a JID.' % self.encryption_short_name, + ) + ConversationTab.add_information_element( self.encryption_short_name, self._display_encryption_status, @@ -238,6 +246,33 @@ class E2EEPlugin(BasePlugin): 'Info', ) + def _show_fingerprints(self, jid: JID) -> None: + """Display encryption fingerprints for a JID.""" + fprs = self.get_fingerprints(jid) + if len(fprs) == 1: + self.api.information( + 'Fingerprint for %s: %s' % (jid, fprs[0]), + 'Info', + ) + elif fprs: + self.api.information( + 'Fingerprints for %s:\n\t%s' % (jid, '\n\t'.join(fprs)), + 'Info', + ) + else: + self.api.information( + 'No fingerprints to display', + 'Info', + ) + + @command_args_parser.quoted(0, 1) + def _command_show_fingerprints(self, args: List[str]) -> None: + if not args and isinstance(self.api.current_tab(), self.supported_tab_types): + jid = self.api.current_tab().name + else: + jid = args[0] + self._show_fingerprints(jid) + @command_args_parser.quoted(2) def __command_set_state_global(self, args, state='') -> None: jid, fpr = args @@ -422,3 +457,12 @@ class E2EEPlugin(BasePlugin): """ raise NotImplementedError + + def get_fingerprints(self, jid: JID) -> List[str]: + """Show fingerprint(s) for this encryption method and JID. + + To overload in plugins. + + :returns: A list of fingerprints to display + """ + return [] -- cgit v1.2.3