[WIP] Add API to query the fingerprints from the app

parent e55f01bb
......@@ -18,6 +18,7 @@
import time
import sqlite3
from collections import namedtuple
from typing import List
from axolotl.state.axolotlstore import AxolotlStore
from axolotl.state.signedprekeyrecord import SignedPreKeyRecord
......@@ -229,7 +230,7 @@ class LiteAxolotlStore(AxolotlStore):
CREATE TABLE IF NOT EXISTS secret (
device_id INTEGER, public_key BLOB, private_key BLOB);
INSERT INTO secret (device_id, public_key, private_key)
SELECT registration_id + 1, public_key, private_key
SELECT registration_id + 1, public_key, private_key
FROM identities
WHERE recipient_id = -1;
"""
......@@ -540,7 +541,7 @@ class LiteAxolotlStore(AxolotlStore):
result = self._con.execute(query, (recipientId, public_key)).fetchone()
return result.trust if result is not None else None
def getFingerprints(self, jid):
def getFingerprints(self, jid: str) -> list:
query = '''SELECT recipient_id as "recipient_id [jid]",
public_key as "public_key [pk]",
trust,
......@@ -549,7 +550,7 @@ class LiteAxolotlStore(AxolotlStore):
WHERE recipient_id = ? ORDER BY trust ASC'''
return self._con.execute(query, (jid,)).fetchall()
def getMucFingerprints(self, jids):
def getMucFingerprints(self, jids: List[str]) -> list:
query = '''
SELECT recipient_id as "recipient_id [jid]",
public_key as "public_key [pk]",
......
......@@ -34,6 +34,7 @@ class Trust(IntEnum):
UNDECIDED = 2
# FIXME ??? why isn't that a method??
def get_fingerprint(identity_key, formatted=False):
public_key = identity_key.getPublicKey().serialize()
fingerprint = binascii.hexlify(public_key).decode()[2:]
......
......@@ -21,6 +21,7 @@ import binascii
import threading
from enum import IntEnum, unique
from pathlib import Path
from typing import Dict
from gi.repository import GLib
from gi.repository import Gtk
......@@ -28,6 +29,7 @@ from gi.repository import Gdk
from gajim import dialogs
from gajim.common import app, ged
from gajim.common.const import Trust as GajimTrust
from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _
from gajim.groupchat_control import GroupchatControl
......@@ -36,6 +38,7 @@ from omemo import file_crypto
from omemo.gtk.key import KeyDialog
from omemo.gtk.config import OMEMOConfigDialog
from omemo.backend.aes import aes_encrypt_file
from omemo.backend.util import IdentityKeyExtended, Trust
AXOLOTL_MISSING = 'You are missing Python3-Axolotl or use an outdated version'
......@@ -329,3 +332,19 @@ class OmemoPlugin(GajimPlugin):
if msg is None:
return
chat_control.print_conversation_line(msg, 'status', '', None)
def get_fingerprints(self, account: str, jid: str, groupchat: bool = False) -> Dict[IdentityKeyExtended, GajimTrust]:
omemo = self.get_omemo(account)
if groupchat:
members = list(omemo.backend.get_muc_members(jid))
fpr_list = omemo.backend.storage.getMucFingerprints(members)
else:
fpr_list = omemo.backend.storage.getFingerprints(jid)
log.warning(fpr_list)
# every row is like:
# recipient_id: str, public_key: omemo.backend.util.IdentityKeyExtended, trust: int, timestamp: Optional[int]
# FIXME, that code is awful
# FIXME do we want to expose the full type?
return {x.public_key: GajimTrust[Trust(x.trust).name] for x in fpr_list}
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