From c25fd947a8412c19ec5a491c25cdc555cdcab756 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 18 Oct 2020 00:52:35 +0200 Subject: [PATCH] Automatic key sharing with trusted users --- src/Olm.cpp | 16 ++++++++++- src/UserSettingsPage.cpp | 62 ++++++++++++++++++++++++++-------------- src/UserSettingsPage.h | 7 +++++ 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/Olm.cpp b/src/Olm.cpp index 1d86b4d..059733c 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -9,6 +9,7 @@ #include "DeviceVerificationFlow.h" #include "Logging.h" #include "MatrixClient.h" +#include "UserSettingsPage.h" #include "Utils.h" static const std::string STORAGE_SECRET_KEY("secret"); @@ -519,7 +520,20 @@ handle_key_request_message(const mtx::events::DeviceEventuserSettings()->shareKeysWithTrustedUsers()) { + for (const auto &dev : verificationStatus->verified_devices) { + if (dev == req.content.requesting_device_id) { + verifiedDevice = true; + break; + } + } + } + + if (!utils::respondsToKeyRequests(req.content.room_id) && !verifiedDevice) { nhlog::crypto()->debug("ignoring all key requests for room {}", req.content.room_id); return; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 7d81e66..8f049a2 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -72,8 +72,10 @@ UserSettings::load() font_ = settings.value("user/font_family", "default").toString(); avatarCircles_ = settings.value("user/avatar_circles", true).toBool(); decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); - emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); - baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); + shareKeysWithTrustedUsers_ = + settings.value("user/share_keys_with_trusted_users", true).toBool(); + emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); + baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); presence_ = settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence)) .value(); @@ -291,6 +293,16 @@ UserSettings::setUseStunServer(bool useStunServer) save(); } +void +UserSettings::setShareKeysWithTrustedUsers(bool shareKeys) +{ + if (shareKeys == shareKeysWithTrustedUsers_) + return; + shareKeysWithTrustedUsers_ = shareKeys; + emit shareKeysWithTrustedUsersChanged(shareKeys); + save(); +} + void UserSettings::setDefaultAudioSource(const QString &defaultAudioSource) { @@ -374,6 +386,7 @@ UserSettings::save() settings.setValue("avatar_circles", avatarCircles_); settings.setValue("decrypt_sidebar", decryptSidebar_); + settings.setValue("share_keys_with_trusted_users", shareKeysWithTrustedUsers_); settings.setValue("font_size", baseFontSize_); settings.setValue("typing_notifications", typingNotifications_); settings.setValue("minor_events", sortByImportance_); @@ -439,26 +452,27 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); general_->setFont(font); - trayToggle_ = new Toggle{this}; - startInTrayToggle_ = new Toggle{this}; - avatarCircles_ = new Toggle{this}; - decryptSidebar_ = new Toggle(this); - groupViewToggle_ = new Toggle{this}; - timelineButtonsToggle_ = new Toggle{this}; - typingNotifications_ = new Toggle{this}; - messageHoverHighlight_ = new Toggle{this}; - enlargeEmojiOnlyMessages_ = new Toggle{this}; - sortByImportance_ = new Toggle{this}; - readReceipts_ = new Toggle{this}; - markdown_ = new Toggle{this}; - desktopNotifications_ = new Toggle{this}; - alertOnNotification_ = new Toggle{this}; - useStunServer_ = new Toggle{this}; - scaleFactorCombo_ = new QComboBox{this}; - fontSizeCombo_ = new QComboBox{this}; - fontSelectionCombo_ = new QComboBox{this}; - emojiFontSelectionCombo_ = new QComboBox{this}; - timelineMaxWidthSpin_ = new QSpinBox{this}; + trayToggle_ = new Toggle{this}; + startInTrayToggle_ = new Toggle{this}; + avatarCircles_ = new Toggle{this}; + decryptSidebar_ = new Toggle(this); + shareKeysWithTrustedUsers_ = new Toggle(this); + groupViewToggle_ = new Toggle{this}; + timelineButtonsToggle_ = new Toggle{this}; + typingNotifications_ = new Toggle{this}; + messageHoverHighlight_ = new Toggle{this}; + enlargeEmojiOnlyMessages_ = new Toggle{this}; + sortByImportance_ = new Toggle{this}; + readReceipts_ = new Toggle{this}; + markdown_ = new Toggle{this}; + desktopNotifications_ = new Toggle{this}; + alertOnNotification_ = new Toggle{this}; + useStunServer_ = new Toggle{this}; + scaleFactorCombo_ = new QComboBox{this}; + fontSizeCombo_ = new QComboBox{this}; + fontSelectionCombo_ = new QComboBox{this}; + emojiFontSelectionCombo_ = new QComboBox{this}; + timelineMaxWidthSpin_ = new QSpinBox{this}; if (!settings_->tray()) startInTrayToggle_->setDisabled(true); @@ -653,6 +667,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge formLayout_->addRow(new HorizontalLine{this}); boxWrap(tr("Device ID"), deviceIdValue_); boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_); + boxWrap( + tr("Share keys with trusted users"), + shareKeysWithTrustedUsers_, + tr("Automatically replies to key requests from other users, if they are verified.")); formLayout_->addRow(new HorizontalLine{this}); formLayout_->addRow(sessionKeysLabel, sessionKeysLayout); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index e947bfa..e4a3489 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -75,6 +75,8 @@ class UserSettings : public QObject bool useStunServer READ useStunServer WRITE setUseStunServer NOTIFY useStunServerChanged) Q_PROPERTY(QString defaultAudioSource READ defaultAudioSource WRITE setDefaultAudioSource NOTIFY defaultAudioSourceChanged) + Q_PROPERTY(bool shareKeysWithTrustedUsers READ shareKeysWithTrustedUsers WRITE + setShareKeysWithTrustedUsers NOTIFY shareKeysWithTrustedUsersChanged) public: UserSettings(); @@ -113,6 +115,7 @@ public: void setPresence(Presence state); void setUseStunServer(bool state); void setDefaultAudioSource(const QString &deviceName); + void setShareKeysWithTrustedUsers(bool state); QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool messageHoverHighlight() const { return messageHoverHighlight_; } @@ -140,6 +143,7 @@ public: Presence presence() const { return presence_; } bool useStunServer() const { return useStunServer_; } QString defaultAudioSource() const { return defaultAudioSource_; } + bool shareKeysWithTrustedUsers() const { return shareKeysWithTrustedUsers_; } signals: void groupViewStateChanged(bool state); @@ -164,6 +168,7 @@ signals: void presenceChanged(Presence state); void useStunServerChanged(bool state); void defaultAudioSourceChanged(const QString &deviceName); + void shareKeysWithTrustedUsersChanged(bool state); private: // Default to system theme if QT_QPA_PLATFORMTHEME var is set. @@ -186,6 +191,7 @@ private: bool hasAlertOnNotification_; bool avatarCircles_; bool decryptSidebar_; + bool shareKeysWithTrustedUsers_; int timelineMaxWidth_; double baseFontSize_; QString font_; @@ -248,6 +254,7 @@ private: Toggle *avatarCircles_; Toggle *useStunServer_; Toggle *decryptSidebar_; + Toggle *shareKeysWithTrustedUsers_; QLabel *deviceFingerprintValue_; QLabel *deviceIdValue_;