Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2020-05-23 11:54:50 +0300
committerlovetox <philipp@hoerist.com>2020-05-23 13:35:19 +0300
commit756edc858acd3f7a76312319cff6027ddc309d80 (patch)
tree0ecd54d41b19fdd707b3dd3cd957ed6b0ec52e8d
parenta0236e2dd59117d2771082796dfc542de07fb955 (diff)
[omemo] Sanitize BLOBs in signed_prekeys table
-rw-r--r--omemo/backend/liteaxolotlstore.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/omemo/backend/liteaxolotlstore.py b/omemo/backend/liteaxolotlstore.py
index 52bfde9..00bf239 100644
--- a/omemo/backend/liteaxolotlstore.py
+++ b/omemo/backend/liteaxolotlstore.py
@@ -147,7 +147,7 @@ class LiteAxolotlStore(AxolotlStore):
create_db_sql = """
BEGIN TRANSACTION;
%s
- PRAGMA user_version=11;
+ PRAGMA user_version=12;
END TRANSACTION;
""" % (create_tables)
self._con.executescript(create_db_sql)
@@ -347,6 +347,29 @@ class LiteAxolotlStore(AxolotlStore):
self._con.execute('PRAGMA user_version=11')
self._con.commit()
+ if self.user_version() < 12:
+ # Sanitize invalid BLOBs from the python2 days
+ query_keys = '''SELECT _id,
+ prekey_id,
+ timestamp,
+ CAST(record as BLOB) as record
+ FROM signed_prekeys'''
+ rows = self._con.execute(query_keys).fetchall()
+
+ delete = 'DELETE FROM signed_prekeys'
+ self._con.execute(delete)
+
+ insert = '''INSERT INTO signed_prekeys (
+ _id, prekey_id, timestamp, record)
+ VALUES (?, ?, ?, ?)'''
+ for row in rows:
+ try:
+ self._con.execute(insert, row)
+ except Exception as error:
+ self._log.warning(error)
+ self._con.execute('PRAGMA user_version=12')
+ self._con.commit()
+
def loadSignedPreKey(self, signedPreKeyId):
query = 'SELECT record FROM signed_prekeys WHERE prekey_id = ?'
result = self._con.execute(query, (signedPreKeyId, )).fetchone()