#!/usr/bin/env python # vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79 from __future__ import ( generators, division, absolute_import, with_statement, print_function ) import sys import os import os.path import sqlite3 from glob import iglob import binascii import qrcode from axolotl.state.sessionrecord import SessionRecord from axolotl.identitykey import IdentityKey _home = os.environ.get('HOME', '/') xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(_home, '.local', 'share')) def save_qr(path, data): sys.stderr.write("generating %r with content %r\n" % (path, data)) qr = qrcode.QRCode(version=None, error_correction=2, box_size=4, border=1) qr.add_data(data) qr.make(fit=True) img = qr.make_image() img.save(path) def main(): trusted_fps = {} for dbname in iglob(os.path.join(xdg_data_home, "gajim/omemo_*.db")): sys.stderr.write("reading %r\n" % (dbname,)) account = os.path.basename(dbname)[6:-3] with sqlite3.connect(dbname) as con: con.text_factory = bytes con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(""" select recipient_id, public_key from identities where trust=1 or ( trust is null and registration_id is not null )""") for row in cur.fetchall(): jid, pkey = row if jid == "-1": jid = account if jid not in trusted_fps: trusted_fps[jid] = set() # identity_key = SessionRecord(serialized=pkey). \ # getSessionState().getRemoteIdentityKey() #ownfpr = binascii.hexlify(state.store.getIdentityKeyPair() # .getPublicKey().serialize()) # fpr = binascii.hexlify(identity_key.getPublicKey().serialize()) fpr = binascii.hexlify(IdentityKey( pkey, 0, ).getPublicKey().serialize()) assert fpr[:2] == '05' fpr = fpr[2:] #fpr = human_hash(fpr[2:]) #trusted_fps[jid].add(pkey.encode('hex')) trusted_fps[jid].add(fpr) for jid, fps in trusted_fps.items(): save_qr( "omemo_qr_%s.png" % jid, "xmpp:%s?%s" % (jid, ";".join( "omemo-sid-%d=%s" % (n, fp) for n, fp in enumerate(fps) )), ) if __name__ == '__main__': main()