mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Automatic key sharing with trusted users
This commit is contained in:
parent
bd0deb7213
commit
c25fd947a8
3 changed files with 62 additions and 23 deletions
16
src/Olm.cpp
16
src/Olm.cpp
|
@ -9,6 +9,7 @@
|
||||||
#include "DeviceVerificationFlow.h"
|
#include "DeviceVerificationFlow.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
#include "UserSettingsPage.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
static const std::string STORAGE_SECRET_KEY("secret");
|
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;
|
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 {}",
|
nhlog::crypto()->debug("ignoring all key requests for room {}",
|
||||||
req.content.room_id);
|
req.content.room_id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -72,8 +72,10 @@ UserSettings::load()
|
||||||
font_ = settings.value("user/font_family", "default").toString();
|
font_ = settings.value("user/font_family", "default").toString();
|
||||||
avatarCircles_ = settings.value("user/avatar_circles", true).toBool();
|
avatarCircles_ = settings.value("user/avatar_circles", true).toBool();
|
||||||
decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool();
|
decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool();
|
||||||
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
|
shareKeysWithTrustedUsers_ =
|
||||||
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
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_ =
|
presence_ =
|
||||||
settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence))
|
settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence))
|
||||||
.value<Presence>();
|
.value<Presence>();
|
||||||
|
@ -291,6 +293,16 @@ UserSettings::setUseStunServer(bool useStunServer)
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserSettings::setShareKeysWithTrustedUsers(bool shareKeys)
|
||||||
|
{
|
||||||
|
if (shareKeys == shareKeysWithTrustedUsers_)
|
||||||
|
return;
|
||||||
|
shareKeysWithTrustedUsers_ = shareKeys;
|
||||||
|
emit shareKeysWithTrustedUsersChanged(shareKeys);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserSettings::setDefaultAudioSource(const QString &defaultAudioSource)
|
UserSettings::setDefaultAudioSource(const QString &defaultAudioSource)
|
||||||
{
|
{
|
||||||
|
@ -374,6 +386,7 @@ UserSettings::save()
|
||||||
|
|
||||||
settings.setValue("avatar_circles", avatarCircles_);
|
settings.setValue("avatar_circles", avatarCircles_);
|
||||||
settings.setValue("decrypt_sidebar", decryptSidebar_);
|
settings.setValue("decrypt_sidebar", decryptSidebar_);
|
||||||
|
settings.setValue("share_keys_with_trusted_users", shareKeysWithTrustedUsers_);
|
||||||
settings.setValue("font_size", baseFontSize_);
|
settings.setValue("font_size", baseFontSize_);
|
||||||
settings.setValue("typing_notifications", typingNotifications_);
|
settings.setValue("typing_notifications", typingNotifications_);
|
||||||
settings.setValue("minor_events", sortByImportance_);
|
settings.setValue("minor_events", sortByImportance_);
|
||||||
|
@ -439,26 +452,27 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||||
general_->setFont(font);
|
general_->setFont(font);
|
||||||
|
|
||||||
trayToggle_ = new Toggle{this};
|
trayToggle_ = new Toggle{this};
|
||||||
startInTrayToggle_ = new Toggle{this};
|
startInTrayToggle_ = new Toggle{this};
|
||||||
avatarCircles_ = new Toggle{this};
|
avatarCircles_ = new Toggle{this};
|
||||||
decryptSidebar_ = new Toggle(this);
|
decryptSidebar_ = new Toggle(this);
|
||||||
groupViewToggle_ = new Toggle{this};
|
shareKeysWithTrustedUsers_ = new Toggle(this);
|
||||||
timelineButtonsToggle_ = new Toggle{this};
|
groupViewToggle_ = new Toggle{this};
|
||||||
typingNotifications_ = new Toggle{this};
|
timelineButtonsToggle_ = new Toggle{this};
|
||||||
messageHoverHighlight_ = new Toggle{this};
|
typingNotifications_ = new Toggle{this};
|
||||||
enlargeEmojiOnlyMessages_ = new Toggle{this};
|
messageHoverHighlight_ = new Toggle{this};
|
||||||
sortByImportance_ = new Toggle{this};
|
enlargeEmojiOnlyMessages_ = new Toggle{this};
|
||||||
readReceipts_ = new Toggle{this};
|
sortByImportance_ = new Toggle{this};
|
||||||
markdown_ = new Toggle{this};
|
readReceipts_ = new Toggle{this};
|
||||||
desktopNotifications_ = new Toggle{this};
|
markdown_ = new Toggle{this};
|
||||||
alertOnNotification_ = new Toggle{this};
|
desktopNotifications_ = new Toggle{this};
|
||||||
useStunServer_ = new Toggle{this};
|
alertOnNotification_ = new Toggle{this};
|
||||||
scaleFactorCombo_ = new QComboBox{this};
|
useStunServer_ = new Toggle{this};
|
||||||
fontSizeCombo_ = new QComboBox{this};
|
scaleFactorCombo_ = new QComboBox{this};
|
||||||
fontSelectionCombo_ = new QComboBox{this};
|
fontSizeCombo_ = new QComboBox{this};
|
||||||
emojiFontSelectionCombo_ = new QComboBox{this};
|
fontSelectionCombo_ = new QComboBox{this};
|
||||||
timelineMaxWidthSpin_ = new QSpinBox{this};
|
emojiFontSelectionCombo_ = new QComboBox{this};
|
||||||
|
timelineMaxWidthSpin_ = new QSpinBox{this};
|
||||||
|
|
||||||
if (!settings_->tray())
|
if (!settings_->tray())
|
||||||
startInTrayToggle_->setDisabled(true);
|
startInTrayToggle_->setDisabled(true);
|
||||||
|
@ -653,6 +667,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
formLayout_->addRow(new HorizontalLine{this});
|
formLayout_->addRow(new HorizontalLine{this});
|
||||||
boxWrap(tr("Device ID"), deviceIdValue_);
|
boxWrap(tr("Device ID"), deviceIdValue_);
|
||||||
boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_);
|
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(new HorizontalLine{this});
|
||||||
formLayout_->addRow(sessionKeysLabel, sessionKeysLayout);
|
formLayout_->addRow(sessionKeysLabel, sessionKeysLayout);
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ class UserSettings : public QObject
|
||||||
bool useStunServer READ useStunServer WRITE setUseStunServer NOTIFY useStunServerChanged)
|
bool useStunServer READ useStunServer WRITE setUseStunServer NOTIFY useStunServerChanged)
|
||||||
Q_PROPERTY(QString defaultAudioSource READ defaultAudioSource WRITE setDefaultAudioSource
|
Q_PROPERTY(QString defaultAudioSource READ defaultAudioSource WRITE setDefaultAudioSource
|
||||||
NOTIFY defaultAudioSourceChanged)
|
NOTIFY defaultAudioSourceChanged)
|
||||||
|
Q_PROPERTY(bool shareKeysWithTrustedUsers READ shareKeysWithTrustedUsers WRITE
|
||||||
|
setShareKeysWithTrustedUsers NOTIFY shareKeysWithTrustedUsersChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UserSettings();
|
UserSettings();
|
||||||
|
@ -113,6 +115,7 @@ public:
|
||||||
void setPresence(Presence state);
|
void setPresence(Presence state);
|
||||||
void setUseStunServer(bool state);
|
void setUseStunServer(bool state);
|
||||||
void setDefaultAudioSource(const QString &deviceName);
|
void setDefaultAudioSource(const QString &deviceName);
|
||||||
|
void setShareKeysWithTrustedUsers(bool state);
|
||||||
|
|
||||||
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
|
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
|
||||||
bool messageHoverHighlight() const { return messageHoverHighlight_; }
|
bool messageHoverHighlight() const { return messageHoverHighlight_; }
|
||||||
|
@ -140,6 +143,7 @@ public:
|
||||||
Presence presence() const { return presence_; }
|
Presence presence() const { return presence_; }
|
||||||
bool useStunServer() const { return useStunServer_; }
|
bool useStunServer() const { return useStunServer_; }
|
||||||
QString defaultAudioSource() const { return defaultAudioSource_; }
|
QString defaultAudioSource() const { return defaultAudioSource_; }
|
||||||
|
bool shareKeysWithTrustedUsers() const { return shareKeysWithTrustedUsers_; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void groupViewStateChanged(bool state);
|
void groupViewStateChanged(bool state);
|
||||||
|
@ -164,6 +168,7 @@ signals:
|
||||||
void presenceChanged(Presence state);
|
void presenceChanged(Presence state);
|
||||||
void useStunServerChanged(bool state);
|
void useStunServerChanged(bool state);
|
||||||
void defaultAudioSourceChanged(const QString &deviceName);
|
void defaultAudioSourceChanged(const QString &deviceName);
|
||||||
|
void shareKeysWithTrustedUsersChanged(bool state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Default to system theme if QT_QPA_PLATFORMTHEME var is set.
|
// Default to system theme if QT_QPA_PLATFORMTHEME var is set.
|
||||||
|
@ -186,6 +191,7 @@ private:
|
||||||
bool hasAlertOnNotification_;
|
bool hasAlertOnNotification_;
|
||||||
bool avatarCircles_;
|
bool avatarCircles_;
|
||||||
bool decryptSidebar_;
|
bool decryptSidebar_;
|
||||||
|
bool shareKeysWithTrustedUsers_;
|
||||||
int timelineMaxWidth_;
|
int timelineMaxWidth_;
|
||||||
double baseFontSize_;
|
double baseFontSize_;
|
||||||
QString font_;
|
QString font_;
|
||||||
|
@ -248,6 +254,7 @@ private:
|
||||||
Toggle *avatarCircles_;
|
Toggle *avatarCircles_;
|
||||||
Toggle *useStunServer_;
|
Toggle *useStunServer_;
|
||||||
Toggle *decryptSidebar_;
|
Toggle *decryptSidebar_;
|
||||||
|
Toggle *shareKeysWithTrustedUsers_;
|
||||||
QLabel *deviceFingerprintValue_;
|
QLabel *deviceFingerprintValue_;
|
||||||
QLabel *deviceIdValue_;
|
QLabel *deviceIdValue_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue