Add option to ignore key requests altogether

This commit is contained in:
Konstantinos Sideris 2018-07-22 16:36:25 +03:00
parent 0247b47553
commit 24bad93f6b
6 changed files with 70 additions and 2 deletions

View File

@ -341,6 +341,7 @@ MainWindow::openRoomSettings(const QString &room_id)
roomSettingsModal_ = roomSettingsModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, roomSettingsDialog_.data())); QSharedPointer<OverlayModal>(new OverlayModal(this, roomSettingsDialog_.data()));
roomSettingsModal_->setContentAlignment(Qt::AlignTop | Qt::AlignHCenter);
roomSettingsModal_->show(); roomSettingsModal_->show();
} }

View File

@ -3,6 +3,7 @@
#include "Cache.h" #include "Cache.h"
#include "Logging.h" #include "Logging.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "Utils.h"
using namespace mtx::crypto; using namespace mtx::crypto;
@ -377,6 +378,11 @@ handle_key_request_message(const mtx::events::msg::KeyRequest &req)
return; return;
} }
if (!utils::respondsToKeyRequests(req.room_id)) {
nhlog::crypto()->info("ignoring all key requests for room {}", req.room_id);
return;
}
// //
// Prepare the m.room_key event. // Prepare the m.room_key event.
// //

View File

@ -15,6 +15,32 @@ utils::localUser()
return settings.value("auth/user_id").toString(); return settings.value("auth/user_id").toString();
} }
bool
utils::respondsToKeyRequests(const std::string &roomId)
{
return respondsToKeyRequests(QString::fromStdString(roomId));
}
bool
utils::respondsToKeyRequests(const QString &roomId)
{
if (roomId.isEmpty())
return false;
QSettings settings;
return settings.value("rooms/respond_to_key_requests/" + roomId, false).toBool();
}
void
utils::setKeyRequestsPreference(QString roomId, bool value)
{
if (roomId.isEmpty())
return;
QSettings settings;
settings.setValue("rooms/respond_to_key_requests/" + roomId, value);
}
QString QString
utils::descriptiveTime(const QDateTime &then) utils::descriptiveTime(const QDateTime &then)
{ {

View File

@ -18,6 +18,15 @@ using TimelineEvent = mtx::events::collections::TimelineEvents;
QString QString
localUser(); localUser();
//! Whether or not we should respond to key requests for the given room.
bool
respondsToKeyRequests(const QString &roomId);
bool
respondsToKeyRequests(const std::string &roomId);
void
setKeyRequestsPreference(QString roomId, bool value);
//! Human friendly timestamp representation. //! Human friendly timestamp representation.
QString QString
descriptiveTime(const QDateTime &then); descriptiveTime(const QDateTime &then);

View File

@ -260,18 +260,43 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
encryptionOptionLayout->addWidget(encryptionLabel, Qt::AlignBottom | Qt::AlignLeft); encryptionOptionLayout->addWidget(encryptionLabel, Qt::AlignBottom | Qt::AlignLeft);
encryptionOptionLayout->addWidget(encryptionToggle_, 0, Qt::AlignBottom | Qt::AlignRight); encryptionOptionLayout->addWidget(encryptionToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
auto keyRequestsLabel = new QLabel(tr("Respond to key requests"), this);
keyRequestsLabel->setToolTipDuration(6000);
keyRequestsLabel->setToolTip(
tr("Whether or not the client should respond automatically with the session keys\n"
" upon request. Use with caution, this is a temporary measure to test the\n"
" E2E implementation until device verification is completed."));
keyRequestsToggle_ = new Toggle(this);
connect(keyRequestsToggle_, &Toggle::toggled, this, [this](bool isOn) {
utils::setKeyRequestsPreference(room_id_, !isOn);
});
auto keyRequestsLayout = new QHBoxLayout;
keyRequestsLayout->setMargin(0);
keyRequestsLayout->setSpacing(0);
keyRequestsLayout->addWidget(keyRequestsLabel, Qt::AlignBottom | Qt::AlignLeft);
keyRequestsLayout->addWidget(keyRequestsToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
// Disable encryption button. // Disable encryption button.
if (usesEncryption_) { if (usesEncryption_) {
encryptionToggle_->setState(false); encryptionToggle_->setState(false);
encryptionToggle_->setEnabled(false); encryptionToggle_->setEnabled(false);
keyRequestsToggle_->setState(!utils::respondsToKeyRequests(room_id_));
} else { } else {
encryptionToggle_->setState(true); encryptionToggle_->setState(true);
keyRequestsLabel->hide();
keyRequestsToggle_->hide();
} }
// Hide encryption option for public rooms. // Hide encryption option for public rooms.
if (!usesEncryption_ && (info_.join_rule == JoinRule::Public)) { if (!usesEncryption_ && (info_.join_rule == JoinRule::Public)) {
encryptionToggle_->hide(); encryptionToggle_->hide();
encryptionLabel->hide(); encryptionLabel->hide();
keyRequestsLabel->hide();
keyRequestsToggle_->hide();
} }
avatar_ = new Avatar(this); avatar_ = new Avatar(this);
@ -284,8 +309,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
auto roomNameLabel = new QLabel(QString::fromStdString(info_.name), this); auto roomNameLabel = new QLabel(QString::fromStdString(info_.name), this);
roomNameLabel->setFont(doubleFont); roomNameLabel->setFont(doubleFont);
auto membersLabel = auto membersLabel = new QLabel(tr("%n member(s)", "", info_.member_count), this);
new QLabel(QString::fromStdString("%1 members").arg(info_.member_count), this);
auto textLayout = new QVBoxLayout; auto textLayout = new QVBoxLayout;
textLayout->addWidget(roomNameLabel); textLayout->addWidget(roomNameLabel);
@ -304,6 +328,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
layout->addLayout(notifOptionLayout_); layout->addLayout(notifOptionLayout_);
layout->addLayout(accessOptionLayout); layout->addLayout(accessOptionLayout);
layout->addLayout(encryptionOptionLayout); layout->addLayout(encryptionOptionLayout);
layout->addLayout(keyRequestsLayout);
layout->addStretch(1); layout->addStretch(1);
connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) { connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) {

View File

@ -91,6 +91,7 @@ private:
QComboBox *accessCombo; QComboBox *accessCombo;
Toggle *encryptionToggle_; Toggle *encryptionToggle_;
Toggle *keyRequestsToggle_;
}; };
} // dialogs } // dialogs