Automatic key sharing with trusted users

master
Nicolas Werner 4 years ago
parent bd0deb7213
commit c25fd947a8
  1. 16
      src/Olm.cpp
  2. 18
      src/UserSettingsPage.cpp
  3. 7
      src/UserSettingsPage.h

@ -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::DeviceEvent<mtx::events::msg::KeyR
return;
}
if (!utils::respondsToKeyRequests(req.content.room_id)) {
// check if device is verified
auto verificationStatus = cache::verificationStatus(req.sender);
bool verifiedDevice = false;
if (verificationStatus &&
ChatPage::instance()->userSettings()->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;

@ -72,6 +72,8 @@ 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();
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_ =
@ -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_);
@ -443,6 +456,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
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};
@ -653,6 +667,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> 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);

@ -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_;

Loading…
Cancel
Save