aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-26 08:34:09 +0200
committerGitHub <noreply@github.com>2022-08-26 08:34:09 +0200
commitb257cf4e38d540a0063f06ebdb51dcd2574cc809 (patch)
tree68e43acc8a0577110c0d03b8d04265622a895a3e /lib/database.cpp
parent4ad2f6e165a4eb486155eae652e187dc4d6b7d99 (diff)
parent6404b8cd4d57468b810538da04f8017fb13ccc37 (diff)
downloadlibquotient-b257cf4e38d540a0063f06ebdb51dcd2574cc809.tar.gz
libquotient-b257cf4e38d540a0063f06ebdb51dcd2574cc809.zip
Merge #547: Implement device verification
Diffstat (limited to 'lib/database.cpp')
-rw-r--r--lib/database.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/database.cpp b/lib/database.cpp
index ed7bd794..4eb82cf5 100644
--- a/lib/database.cpp
+++ b/lib/database.cpp
@@ -31,7 +31,8 @@ Database::Database(const QString& matrixId, const QString& deviceId, QObject* pa
case 0: migrateTo1(); [[fallthrough]];
case 1: migrateTo2(); [[fallthrough]];
case 2: migrateTo3(); [[fallthrough]];
- case 3: migrateTo4();
+ case 3: migrateTo4(); [[fallthrough]];
+ case 4: migrateTo5();
}
}
@@ -102,7 +103,7 @@ void Database::migrateTo2()
{
qCDebug(DATABASE) << "Migrating database to version 2";
transaction();
- //TODO remove this column again - we don't need it after all
+
execute(QStringLiteral("ALTER TABLE inbound_megolm_sessions ADD ed25519Key TEXT"));
execute(QStringLiteral("ALTER TABLE olm_sessions ADD lastReceived TEXT"));
@@ -141,6 +142,16 @@ void Database::migrateTo4()
commit();
}
+void Database::migrateTo5()
+{
+ qCDebug(DATABASE) << "Migrating database to version 5";
+ transaction();
+
+ execute(QStringLiteral("ALTER TABLE tracked_devices ADD verified BOOL;"));
+ execute(QStringLiteral("PRAGMA user_version = 5"));
+ commit();
+}
+
QByteArray Database::accountPickle()
{
auto query = prepareQuery(QStringLiteral("SELECT pickle FROM accounts;"));
@@ -392,3 +403,19 @@ void Database::updateOlmSession(const QString& senderKey, const QString& session
commit();
}
+void Database::setSessionVerified(const QString& edKeyId)
+{
+ auto query = prepareQuery(QStringLiteral("UPDATE tracked_devices SET verified=true WHERE edKeyId=:edKeyId;"));
+ query.bindValue(":edKeyId", edKeyId);
+ transaction();
+ execute(query);
+ commit();
+}
+
+bool Database::isSessionVerified(const QString& edKey)
+{
+ auto query = prepareQuery(QStringLiteral("SELECT verified FROM tracked_devices WHERE edKey=:edKey"));
+ query.bindValue(":edKey", edKey);
+ execute(query);
+ return query.next() && query.value("verified").toBool();
+}