Add get_trust_for_jid method
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
545123773b
commit
179db446fe
1 changed files with 15 additions and 0 deletions
|
@ -16,6 +16,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
import codecs
|
||||||
import asyncio
|
import asyncio
|
||||||
from slixmpp.plugins.xep_0060.stanza import Items, EventItems
|
from slixmpp.plugins.xep_0060.stanza import Items, EventItems
|
||||||
from slixmpp.plugins.xep_0004 import Form
|
from slixmpp.plugins.xep_0004 import Form
|
||||||
|
@ -77,6 +78,10 @@ def _load_device_id(data_dir: str) -> int:
|
||||||
|
|
||||||
return did
|
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:
|
def _parse_bundle(backend: Backend, bundle: Bundle) -> ExtendedPublicBundle:
|
||||||
identity_key = b64dec(bundle['identityKey']['value'].strip())
|
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:
|
def distrust(self, jid: JID, device_id: int, ik: bytes) -> None:
|
||||||
self._omemo.distrust(jid.bare, device_id, ik)
|
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:
|
def is_encrypted(self, msg: Message) -> bool:
|
||||||
return msg.xml.find('{%s}encrypted' % OMEMO_BASE_NS) is not None
|
return msg.xml.find('{%s}encrypted' % OMEMO_BASE_NS) is not None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue