Add get_trust_for_jid method

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-08-25 01:56:28 +02:00
parent 545123773b
commit 179db446fe
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

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