[omemo] Add sqlite identity key converter
This commit is contained in:
@@ -33,6 +33,7 @@ from axolotl.util.medium import Medium
|
|||||||
from axolotl.util.keyhelper import KeyHelper
|
from axolotl.util.keyhelper import KeyHelper
|
||||||
|
|
||||||
from omemo.backend.util import Trust
|
from omemo.backend.util import Trust
|
||||||
|
from omemo.backend.util import IdentityKeyExtended
|
||||||
from omemo.backend.util import DEFAULT_PREKEY_AMOUNT
|
from omemo.backend.util import DEFAULT_PREKEY_AMOUNT
|
||||||
|
|
||||||
|
|
||||||
@@ -42,8 +43,14 @@ log = logging.getLogger('gajim.plugin_system.omemo')
|
|||||||
def _convert_to_string(text):
|
def _convert_to_string(text):
|
||||||
return text.decode()
|
return text.decode()
|
||||||
|
|
||||||
|
def _convert_identity_key(key):
|
||||||
|
if not key:
|
||||||
|
return
|
||||||
|
return IdentityKeyExtended(DjbECPublicKey(key[1:]))
|
||||||
|
|
||||||
|
|
||||||
sqlite3.register_converter('jid', _convert_to_string)
|
sqlite3.register_converter('jid', _convert_to_string)
|
||||||
|
sqlite3.register_converter('pk', _convert_identity_key)
|
||||||
|
|
||||||
|
|
||||||
class LiteAxolotlStore(AxolotlStore):
|
class LiteAxolotlStore(AxolotlStore):
|
||||||
@@ -399,13 +406,12 @@ class LiteAxolotlStore(AxolotlStore):
|
|||||||
self.storePreKey(pre_key.getId(), pre_key)
|
self.storePreKey(pre_key.getId(), pre_key)
|
||||||
|
|
||||||
def getIdentityKeyPair(self):
|
def getIdentityKeyPair(self):
|
||||||
query = '''SELECT public_key, private_key FROM identities
|
query = '''SELECT public_key as "public_key [pk]", private_key
|
||||||
WHERE recipient_id = -1'''
|
FROM identities WHERE recipient_id = -1'''
|
||||||
result = self._con.execute(query).fetchone()
|
result = self._con.execute(query).fetchone()
|
||||||
|
|
||||||
return IdentityKeyPair(
|
return IdentityKeyPair(result.public_key,
|
||||||
IdentityKey(DjbECPublicKey(result.public_key[1:])),
|
DjbECPrivateKey(result.private_key))
|
||||||
DjbECPrivateKey(result.private_key))
|
|
||||||
|
|
||||||
def getLocalRegistrationId(self):
|
def getLocalRegistrationId(self):
|
||||||
query = 'SELECT registration_id FROM identities WHERE recipient_id = -1'
|
query = 'SELECT registration_id FROM identities WHERE recipient_id = -1'
|
||||||
@@ -460,12 +466,12 @@ class LiteAxolotlStore(AxolotlStore):
|
|||||||
|
|
||||||
def getFingerprints(self, jid):
|
def getFingerprints(self, jid):
|
||||||
query = '''SELECT _id, recipient_id as "recipient_id [jid]",
|
query = '''SELECT _id, recipient_id as "recipient_id [jid]",
|
||||||
public_key, trust FROM identities
|
public_key as "public_key [pk]", trust FROM identities
|
||||||
WHERE recipient_id =? ORDER BY trust ASC'''
|
WHERE recipient_id =? ORDER BY trust ASC'''
|
||||||
return self._con.execute(query, (jid,)).fetchall()
|
return self._con.execute(query, (jid,)).fetchall()
|
||||||
|
|
||||||
def getTrustedFingerprints(self, jid):
|
def getTrustedFingerprints(self, jid):
|
||||||
query = '''SELECT public_key FROM identities
|
query = '''SELECT public_key as "public_key [pk]" FROM identities
|
||||||
WHERE recipient_id = ? AND trust = ?'''
|
WHERE recipient_id = ? AND trust = ?'''
|
||||||
result = self._con.execute(query, (jid, Trust.TRUSTED)).fetchall()
|
result = self._con.execute(query, (jid, Trust.TRUSTED)).fetchall()
|
||||||
return [row.public_key for row in result]
|
return [row.public_key for row in result]
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import binascii
|
|||||||
import textwrap
|
import textwrap
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
|
from axolotl.identitykey import IdentityKey
|
||||||
|
|
||||||
DEFAULT_PREKEY_AMOUNT = 100
|
DEFAULT_PREKEY_AMOUNT = 100
|
||||||
MIN_PREKEY_AMOUNT = 80
|
MIN_PREKEY_AMOUNT = 80
|
||||||
SPK_ARCHIVE_TIME = 86400 * 15 # 15 Days
|
SPK_ARCHIVE_TIME = 86400 * 15 # 15 Days
|
||||||
@@ -43,3 +45,12 @@ def get_fingerprint(identity_key, formatted=False):
|
|||||||
buf += '{0} '.format(fingerprint[w:w + wordsize])
|
buf += '{0} '.format(fingerprint[w:w + wordsize])
|
||||||
buf = textwrap.fill(buf, width=36)
|
buf = textwrap.fill(buf, width=36)
|
||||||
return buf.rstrip().upper()
|
return buf.rstrip().upper()
|
||||||
|
|
||||||
|
|
||||||
|
class IdentityKeyExtended(IdentityKey):
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(self.publicKey.serialize())
|
||||||
|
|
||||||
|
def get_fingerprint(self, formatted=False):
|
||||||
|
return get_fingerprint(self, formatted=formatted)
|
||||||
|
|
||||||
Reference in New Issue
Block a user