diff options
author | lovetox <philipp@hoerist.com> | 2020-05-23 11:21:10 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-05-23 13:35:19 +0300 |
commit | 58c188eb0d0755adf1c6b1e50cb844b070f20742 (patch) | |
tree | b580fa6f5df9e8e18189e4dde32020c442d17e8f | |
parent | 57a9f9d1abee177418934862a9c96de409bba8cc (diff) |
[omemo] Sanitize BLOBs in secret table
-rw-r--r-- | omemo/backend/liteaxolotlstore.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/omemo/backend/liteaxolotlstore.py b/omemo/backend/liteaxolotlstore.py index 6e3d698..88bee0d 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=8; + PRAGMA user_version=9; END TRANSACTION; """ % (create_tables) self._con.executescript(create_db_sql) @@ -278,6 +278,27 @@ class LiteAxolotlStore(AxolotlStore): self._con.execute('PRAGMA user_version=8') self._con.commit() + if self.user_version() < 9: + # Sanitize invalid BLOBs from the python2 days + query_keys = '''SELECT device_id, + CAST(public_key as BLOB) as public_key, + CAST(private_key as BLOB) as private_key + FROM secret''' + rows = self._con.execute(query_keys).fetchall() + + delete = 'DELETE FROM secret' + self._con.execute(delete) + + insert = '''INSERT INTO secret (device_id, public_key, private_key) + 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=9') + self._con.commit() + def loadSignedPreKey(self, signedPreKeyId): query = 'SELECT record FROM signed_prekeys WHERE prekey_id = ?' result = self._con.execute(query, (signedPreKeyId, )).fetchone() |