From 8af20885ab2a0e706b2bd3989de1bb83a979de8b Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 30 Oct 2023 20:20:55 +0100 Subject: [PATCH] Add account / device security settings page --- src/CMakeLists.txt | 1 + src/neochatconnection.cpp | 18 ++++++++++++++++++ src/neochatconnection.h | 5 +++++ src/qml/Security.qml | 36 ++++++++++++++++++++++++++++++++++++ src/qml/SettingsPage.qml | 11 +++++++++++ 5 files changed, 71 insertions(+) create mode 100644 src/qml/Security.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8418a8c36..976d773d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -286,6 +286,7 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN qml/SpaceHierarchyDelegate.qml qml/RemoveChildDialog.qml qml/SelectParentDialog.qml + qml/Security.qml RESOURCES qml/confetti.png qml/glowdot.png diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 0c8d8e4bb..2621f0f16 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -234,4 +235,21 @@ void NeoChatConnection::openOrCreateDirectChat(User *user) requestDirectChat(user); } +QString NeoChatConnection::deviceKey() const +{ + return edKeyForUserDevice(userId(), deviceId()); +} + +QString NeoChatConnection::encryptionKey() const +{ + auto query = database()->prepareQuery(QStringLiteral("SELECT curveKey FROM tracked_devices WHERE matrixId=:matrixId AND deviceid=:deviceId LIMIT 1;")); + query.bindValue(QStringLiteral(":matrixId"), userId()); + query.bindValue(QStringLiteral(":deviceId"), deviceId()); + database()->execute(query); + if (!query.next()) { + return {}; + } + return query.value(0).toString(); +} + #include "moc_neochatconnection.cpp" diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 6dd41cb07..1ed62f0df 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -23,6 +23,8 @@ class NeoChatConnection : public Quotient::Connection * Set to an empty string to remove the label. */ Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + Q_PROPERTY(QString deviceKey READ deviceKey CONSTANT) + Q_PROPERTY(QString encryptionKey READ encryptionKey CONSTANT) public: NeoChatConnection(QObject *parent = nullptr); @@ -68,6 +70,9 @@ public: */ Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user); + QString deviceKey() const; + QString encryptionKey() const; + Q_SIGNALS: void labelChanged(); }; diff --git a/src/qml/Security.qml b/src/qml/Security.qml new file mode 100644 index 000000000..0c859ab7f --- /dev/null +++ b/src/qml/Security.qml @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2023 Tobias Fella +// SPDX-License-Identifier: GPL-2.0-or-later + +import QtQuick +import QtQuick.Controls + +import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.formcard as FormCard + +import org.kde.neochat + +FormCard.FormCardPage { + id: root + + required property NeoChatConnection connection + + title: i18nc("@title", "Security") + + FormCard.FormHeader { + title: i18nc("@title", "Keys") + } + FormCard.FormCard { + FormCard.FormTextDelegate { + text: connection.deviceKey + description: i18n("Device key") + } + FormCard.FormTextDelegate { + text: connection.encryptionKey + description: i18n("Encryption Key") + } + FormCard.FormTextDelegate { + text: connection.deviceId + description: i18n("Device id") + } + } +} diff --git a/src/qml/SettingsPage.qml b/src/qml/SettingsPage.qml index 9ecfd9419..4a537e68b 100644 --- a/src/qml/SettingsPage.qml +++ b/src/qml/SettingsPage.qml @@ -33,6 +33,17 @@ KirigamiSettings.CategorizedSettings { icon.name: "preferences-desktop-notification" page: Qt.resolvedUrl("GlobalNotificationsPage.qml") }, + KirigamiSettings.SettingAction { + actionName: "security" + text: i18n("Security") + icon.name: "preferences-security" + page: Qt.resolvedUrl("Security.qml") + initialProperties: { + return { + connection: root.connection + } + } + }, KirigamiSettings.SettingAction { actionName: "accounts" text: i18n("Accounts")