mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Send SSSS requests
This commit is contained in:
parent
97688763f6
commit
9825f1bbd0
3 changed files with 104 additions and 0 deletions
80
src/Olm.cpp
80
src/Olm.cpp
|
@ -1,9 +1,13 @@
|
||||||
#include "Olm.h"
|
#include "Olm.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
#include <mtx/secret_storage.hpp>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
|
@ -18,6 +22,8 @@ constexpr auto MEGOLM_ALGO = "m.megolm.v1.aes-sha2";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
auto client_ = std::make_unique<mtx::crypto::OlmClient>();
|
auto client_ = std::make_unique<mtx::crypto::OlmClient>();
|
||||||
|
|
||||||
|
std::map<std::string, std::string> request_id_to_secret_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace olm {
|
namespace olm {
|
||||||
|
@ -1035,4 +1041,78 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
request_cross_signing_keys()
|
||||||
|
{
|
||||||
|
mtx::events::msg::SecretRequest secretRequest{};
|
||||||
|
secretRequest.action = mtx::events::msg::RequestAction::Request;
|
||||||
|
secretRequest.requesting_device_id = http::client()->device_id();
|
||||||
|
|
||||||
|
auto local_user = http::client()->user_id();
|
||||||
|
|
||||||
|
auto verificationStatus = cache::verificationStatus(local_user.to_string());
|
||||||
|
|
||||||
|
if (!verificationStatus)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto request = [&](std::string secretName) {
|
||||||
|
secretRequest.name = secretName;
|
||||||
|
secretRequest.request_id = "ss." + http::client()->generate_txn_id();
|
||||||
|
|
||||||
|
request_id_to_secret_name[secretRequest.request_id] = secretRequest.name;
|
||||||
|
|
||||||
|
std::map<mtx::identifiers::User,
|
||||||
|
std::map<std::string, mtx::events::msg::SecretRequest>>
|
||||||
|
body;
|
||||||
|
|
||||||
|
for (const auto &dev : verificationStatus->verified_devices) {
|
||||||
|
if (dev != secretRequest.requesting_device_id)
|
||||||
|
body[local_user][dev] = secretRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
http::client()->send_to_device<mtx::events::msg::SecretRequest>(
|
||||||
|
http::client()->generate_txn_id(),
|
||||||
|
body,
|
||||||
|
[request_id = secretRequest.request_id, secretName](mtx::http::RequestErr err) {
|
||||||
|
if (err) {
|
||||||
|
request_id_to_secret_name.erase(request_id);
|
||||||
|
nhlog::net()->error("Failed to send request for secrect '{}'",
|
||||||
|
secretName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto &dev : verificationStatus->verified_devices) {
|
||||||
|
if (dev != secretRequest.requesting_device_id)
|
||||||
|
body[local_user][dev].action =
|
||||||
|
mtx::events::msg::RequestAction::Cancellation;
|
||||||
|
}
|
||||||
|
|
||||||
|
// timeout after 15 min
|
||||||
|
QTimer::singleShot(15 * 60 * 1000, [secretRequest, body]() {
|
||||||
|
if (request_id_to_secret_name.count(secretRequest.request_id)) {
|
||||||
|
request_id_to_secret_name.erase(secretRequest.request_id);
|
||||||
|
http::client()->send_to_device<mtx::events::msg::SecretRequest>(
|
||||||
|
http::client()->generate_txn_id(),
|
||||||
|
body,
|
||||||
|
[secretRequest](mtx::http::RequestErr err) {
|
||||||
|
if (err) {
|
||||||
|
nhlog::net()->error(
|
||||||
|
"Failed to cancel request for secrect '{}'",
|
||||||
|
secretRequest.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
request(mtx::secret_storage::secrets::cross_signing_self_signing);
|
||||||
|
request(mtx::secret_storage::secrets::cross_signing_user_signing);
|
||||||
|
request(mtx::secret_storage::secrets::megolm_backup_v1);
|
||||||
|
}
|
||||||
|
void
|
||||||
|
download_cross_signing_keys()
|
||||||
|
{}
|
||||||
|
|
||||||
} // namespace olm
|
} // namespace olm
|
||||||
|
|
|
@ -102,4 +102,11 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
||||||
const mtx::events::collections::DeviceEvents &event,
|
const mtx::events::collections::DeviceEvents &event,
|
||||||
bool force_new_session = false);
|
bool force_new_session = false);
|
||||||
|
|
||||||
|
//! Request backup and signing keys and cache them locally
|
||||||
|
void
|
||||||
|
request_cross_signing_keys();
|
||||||
|
//! Download backup and signing keys and cache them locally
|
||||||
|
void
|
||||||
|
download_cross_signing_keys();
|
||||||
|
|
||||||
} // namespace olm
|
} // namespace olm
|
||||||
|
|
|
@ -649,6 +649,18 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight);
|
sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight);
|
||||||
sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight);
|
sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight);
|
||||||
|
|
||||||
|
auto crossSigningKeysLabel = new QLabel{tr("Cross Signing Keys"), this};
|
||||||
|
crossSigningKeysLabel->setFont(font);
|
||||||
|
crossSigningKeysLabel->setMargin(OptionMargin);
|
||||||
|
|
||||||
|
auto crossSigningRequestBtn = new QPushButton{tr("REQUEST"), this};
|
||||||
|
auto crossSigningDownloadBtn = new QPushButton{tr("DOWNLOAD"), this};
|
||||||
|
|
||||||
|
auto crossSigningKeysLayout = new QHBoxLayout;
|
||||||
|
crossSigningKeysLayout->addWidget(new QLabel{"", this}, 1, Qt::AlignRight);
|
||||||
|
crossSigningKeysLayout->addWidget(crossSigningRequestBtn, 0, Qt::AlignRight);
|
||||||
|
crossSigningKeysLayout->addWidget(crossSigningDownloadBtn, 0, Qt::AlignRight);
|
||||||
|
|
||||||
auto boxWrap = [this, &font](QString labelText, QWidget *field, QString tooltipText = "") {
|
auto boxWrap = [this, &font](QString labelText, QWidget *field, QString tooltipText = "") {
|
||||||
auto label = new QLabel{labelText, this};
|
auto label = new QLabel{labelText, this};
|
||||||
label->setFont(font);
|
label->setFont(font);
|
||||||
|
@ -787,6 +799,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
tr("Automatically replies to key requests from other users, if they are verified."));
|
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);
|
||||||
|
formLayout_->addRow(crossSigningKeysLabel, crossSigningKeysLayout);
|
||||||
|
|
||||||
auto scrollArea_ = new QScrollArea{this};
|
auto scrollArea_ = new QScrollArea{this};
|
||||||
scrollArea_->setFrameShape(QFrame::NoFrame);
|
scrollArea_->setFrameShape(QFrame::NoFrame);
|
||||||
|
@ -982,6 +995,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
connect(
|
connect(
|
||||||
sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys);
|
sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys);
|
||||||
|
|
||||||
|
connect(crossSigningRequestBtn, &QPushButton::clicked, this, []() {
|
||||||
|
olm::request_cross_signing_keys();
|
||||||
|
});
|
||||||
|
|
||||||
connect(backBtn_, &QPushButton::clicked, this, [this]() {
|
connect(backBtn_, &QPushButton::clicked, this, [this]() {
|
||||||
settings_->save();
|
settings_->save();
|
||||||
emit moveBack();
|
emit moveBack();
|
||||||
|
|
Loading…
Reference in a new issue