Add get_trust_for_jid method

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <>
parent 54512377
......@@ -16,6 +16,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
import os
import json
import base64
import codecs
import asyncio
from slixmpp.plugins.xep_0060.stanza import Items, EventItems
from slixmpp.plugins.xep_0004 import Form
......@@ -77,6 +78,10 @@ def _load_device_id(data_dir: str) -> int:
return did
def fp_from_ik(ik: bytes) -> str:
"""Convert identityKey to a string representation (fingerprint)"""
return codecs.getencoder("hex")(ik)[0].decode("US-ASCII").upper()
def _parse_bundle(backend: Backend, bundle: Bundle) -> ExtendedPublicBundle:
identity_key = b64dec(bundle['identityKey']['value'].strip())
......@@ -382,6 +387,16 @@ class XEP_0384(BasePlugin):
def distrust(self, jid: JID, device_id: int, ik: bytes) -> None:
self._omemo.distrust(jid.bare, device_id, ik)
def get_trust_for_jid(self, jid: JID) -> Dict[str, List[Optional[Tuple[bytes, bool, str]]]]:
devices = self._omemo.getTrustForJID(jid.bare)
for trust in devices['active'].values():
if trust is not None:
trust['fingerprint'] = fp_from_ik(trust['key'])
for trust in devices['inactive'].values():
if trust is not None:
trust['fingerprint'] = fp_from_ik(trust['key'])
return devices
def is_encrypted(self, msg: Message) -> bool:
return msg.xml.find('{%s}encrypted' % OMEMO_BASE_NS) is not None
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