From c39c3c80be43311f582b089918da7081310cbca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 24 Mar 2019 11:05:28 +0100 Subject: [PATCH] [omemo] Fix old invalid BLOB database values The way BLOBs are written to the database has changed in python3 So we read all BLOB values cast them to BLOB then write them back to the table Fixes #402, #278 --- omemo/backend/liteaxolotlstore.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/omemo/backend/liteaxolotlstore.py b/omemo/backend/liteaxolotlstore.py index f81ceb6..2ef53eb 100644 --- a/omemo/backend/liteaxolotlstore.py +++ b/omemo/backend/liteaxolotlstore.py @@ -254,6 +254,30 @@ class LiteAxolotlStore(AxolotlStore): END TRANSACTION; """ % convert) + if self.user_version() < 8: + # Sanitize invalid BLOBs from the python2 days + query_keys = '''SELECT recipient_id, registration_id, + CAST(public_key as BLOB) as public_key, + CAST(private_key as BLOB) as private_key, + timestamp, trust, shown + FROM identities''' + rows = self._con.execute(query_keys).fetchall() + + delete = 'DELETE FROM identities' + self._con.execute(delete) + + insert = '''INSERT INTO identities ( + recipient_id, registration_id, public_key, private_key, + timestamp, trust, shown) + 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=8') + self._con.commit() + def loadSignedPreKey(self, signedPreKeyId): query = 'SELECT record FROM signed_prekeys WHERE prekey_id = ?' result = self._con.execute(query, (signedPreKeyId, )).fetchone() -- GitLab