diff options
author | lovetox <philipp@hoerist.com> | 2020-05-23 11:52:20 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-05-23 13:35:19 +0300 |
commit | a0236e2dd59117d2771082796dfc542de07fb955 (patch) | |
tree | 5785862e111a7ddff17586fe4d9e9568762b0e55 | |
parent | a8794f1eb832bad0f914684d8fab9d44d9dbd403 (diff) |
[omemo] Sanitize BLOBs in prekeys table
-rw-r--r-- | omemo/backend/liteaxolotlstore.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/omemo/backend/liteaxolotlstore.py b/omemo/backend/liteaxolotlstore.py index 99c4359..52bfde9 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=10; + PRAGMA user_version=11; END TRANSACTION; """ % (create_tables) self._con.executescript(create_db_sql) @@ -324,6 +324,29 @@ class LiteAxolotlStore(AxolotlStore): self._con.execute('PRAGMA user_version=10') self._con.commit() + if self.user_version() < 11: + # Sanitize invalid BLOBs from the python2 days + query_keys = '''SELECT _id, + prekey_id, + sent_to_server, + CAST(record as BLOB) as record + FROM prekeys''' + rows = self._con.execute(query_keys).fetchall() + + delete = 'DELETE FROM prekeys' + self._con.execute(delete) + + insert = '''INSERT INTO prekeys ( + _id, prekey_id, sent_to_server, 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=11') + self._con.commit() + def loadSignedPreKey(self, signedPreKeyId): query = 'SELECT record FROM signed_prekeys WHERE prekey_id = ?' result = self._con.execute(query, (signedPreKeyId, )).fetchone() |