2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
#include "DeviceVerificationFlow.h"
|
2020-07-29 00:55:47 +03:00
|
|
|
|
2020-07-05 19:03:27 +03:00
|
|
|
#include "Cache.h"
|
2020-10-27 19:45:28 +03:00
|
|
|
#include "Cache_p.h"
|
2020-06-09 19:36:41 +03:00
|
|
|
#include "ChatPage.h"
|
2020-06-07 14:35:32 +03:00
|
|
|
#include "Logging.h"
|
2020-10-27 19:45:28 +03:00
|
|
|
#include "Utils.h"
|
2020-07-29 00:55:47 +03:00
|
|
|
#include "timeline/TimelineModel.h"
|
2020-06-17 21:28:35 +03:00
|
|
|
|
2020-06-04 16:44:15 +03:00
|
|
|
#include <QDateTime>
|
2020-03-13 23:05:18 +03:00
|
|
|
#include <QTimer>
|
2020-08-29 11:07:51 +03:00
|
|
|
#include <iostream>
|
2020-03-13 23:05:18 +03:00
|
|
|
|
|
|
|
static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
|
|
|
|
2020-06-09 19:36:41 +03:00
|
|
|
namespace msgs = mtx::events::msg;
|
|
|
|
|
2020-10-06 18:02:41 +03:00
|
|
|
static mtx::events::msg::KeyVerificationMac
|
|
|
|
key_verification_mac(mtx::crypto::SAS *sas,
|
|
|
|
mtx::identifiers::User sender,
|
|
|
|
const std::string &senderDevice,
|
|
|
|
mtx::identifiers::User receiver,
|
|
|
|
const std::string &receiverDevice,
|
|
|
|
const std::string &transactionId,
|
|
|
|
std::map<std::string, std::string> keys);
|
|
|
|
|
2020-08-18 08:59:02 +03:00
|
|
|
DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
|
|
|
DeviceVerificationFlow::Type flow_type,
|
2020-10-05 23:12:10 +03:00
|
|
|
TimelineModel *model,
|
|
|
|
QString userID,
|
|
|
|
QString deviceId_)
|
|
|
|
: sender(false)
|
|
|
|
, type(flow_type)
|
|
|
|
, deviceId(deviceId_)
|
2020-08-18 08:59:02 +03:00
|
|
|
, model_(model)
|
2020-03-13 23:05:18 +03:00
|
|
|
{
|
|
|
|
timeout = new QTimer(this);
|
|
|
|
timeout->setSingleShot(true);
|
2020-06-26 01:54:42 +03:00
|
|
|
this->sas = olm::client()->sas_init();
|
|
|
|
this->isMacVerified = false;
|
2020-07-29 00:55:47 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
auto user_id = userID.toStdString();
|
|
|
|
this->toClient = mtx::identifiers::parse<mtx::identifiers::User>(user_id);
|
2020-10-27 19:45:28 +03:00
|
|
|
cache::client()->query_keys(
|
2020-10-05 23:12:10 +03:00
|
|
|
user_id, [user_id, this](const UserKeyCache &res, mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to query device keys: {},{}",
|
2021-03-05 02:56:25 +03:00
|
|
|
mtx::errors::to_string(err->matrix_error.errcode),
|
2020-10-05 23:12:10 +03:00
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->deviceId.isEmpty() &&
|
|
|
|
(res.device_keys.find(deviceId.toStdString()) == res.device_keys.end())) {
|
|
|
|
nhlog::net()->warn("no devices retrieved {}", user_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:02:41 +03:00
|
|
|
this->their_keys = res;
|
2020-10-05 23:12:10 +03:00
|
|
|
});
|
|
|
|
|
2020-10-27 19:45:28 +03:00
|
|
|
cache::client()->query_keys(
|
2020-10-08 19:30:31 +03:00
|
|
|
http::client()->user_id().to_string(),
|
|
|
|
[this](const UserKeyCache &res, mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to query device keys: {},{}",
|
2021-03-05 02:56:25 +03:00
|
|
|
mtx::errors::to_string(err->matrix_error.errcode),
|
2020-10-08 19:30:31 +03:00
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res.master_keys.keys.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (auto status =
|
|
|
|
cache::verificationStatus(http::client()->user_id().to_string());
|
2021-05-07 13:19:46 +03:00
|
|
|
status && status->user_verified == crypto::Trust::Verified)
|
2020-10-08 19:30:31 +03:00
|
|
|
this->our_trusted_master_key = res.master_keys.keys.begin()->second;
|
|
|
|
});
|
|
|
|
|
2020-08-18 08:59:02 +03:00
|
|
|
if (model) {
|
|
|
|
connect(this->model_,
|
|
|
|
&TimelineModel::updateFlowEventId,
|
|
|
|
this,
|
2020-09-04 09:32:24 +03:00
|
|
|
[this](std::string event_id_) {
|
2020-08-18 08:59:02 +03:00
|
|
|
this->relation.rel_type = mtx::common::RelationType::Reference;
|
2020-09-04 09:32:24 +03:00
|
|
|
this->relation.event_id = event_id_;
|
|
|
|
this->transaction_id = event_id_;
|
2020-08-18 08:59:02 +03:00
|
|
|
});
|
|
|
|
}
|
2020-08-09 06:05:15 +03:00
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
connect(timeout, &QTimer::timeout, this, [this]() {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: timeout");
|
2020-10-05 23:58:07 +03:00
|
|
|
if (state_ != Success && state_ != Failed)
|
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::Timeout);
|
2020-03-13 23:05:18 +03:00
|
|
|
});
|
2020-06-20 15:20:43 +03:00
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
connect(ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationStart,
|
|
|
|
this,
|
|
|
|
&DeviceVerificationFlow::handleStartMessage);
|
|
|
|
connect(ChatPage::instance(),
|
|
|
|
&ChatPage::receivedDeviceVerificationAccept,
|
2020-07-17 23:16:30 +03:00
|
|
|
this,
|
|
|
|
[this](const mtx::events::msg::KeyVerificationAccept &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: received accept");
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((msg.key_agreement_protocol == "curve25519-hkdf-sha256") &&
|
|
|
|
(msg.hash == "sha256") &&
|
|
|
|
(msg.message_authentication_code == "hkdf-hmac-sha256")) {
|
|
|
|
this->commitment = msg.commitment;
|
|
|
|
if (std::find(msg.short_authentication_string.begin(),
|
|
|
|
msg.short_authentication_string.end(),
|
|
|
|
mtx::events::msg::SASMethods::Emoji) !=
|
|
|
|
msg.short_authentication_string.end()) {
|
2020-10-05 23:12:10 +03:00
|
|
|
this->method = mtx::events::msg::SASMethods::Emoji;
|
2020-07-17 23:16:30 +03:00
|
|
|
} else {
|
2020-10-05 23:12:10 +03:00
|
|
|
this->method = mtx::events::msg::SASMethods::Decimal;
|
2020-07-17 23:16:30 +03:00
|
|
|
}
|
|
|
|
this->mac_method = msg.message_authentication_code;
|
|
|
|
this->sendVerificationKey();
|
|
|
|
} else {
|
|
|
|
this->cancelVerification(
|
|
|
|
DeviceVerificationFlow::Error::UnknownMethod);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-09 19:36:41 +03:00
|
|
|
connect(ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationCancel,
|
2020-06-09 19:36:41 +03:00
|
|
|
this,
|
2020-07-17 23:16:30 +03:00
|
|
|
[this](const mtx::events::msg::KeyVerificationCancel &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: received cancel");
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
2020-06-09 19:36:41 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
error_ = User;
|
2020-10-06 18:02:41 +03:00
|
|
|
emit errorChanged();
|
2020-10-05 23:12:10 +03:00
|
|
|
setState(Failed);
|
2020-06-09 19:36:41 +03:00
|
|
|
});
|
2020-07-17 23:16:30 +03:00
|
|
|
|
|
|
|
connect(ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationKey,
|
2020-07-17 23:16:30 +03:00
|
|
|
this,
|
|
|
|
[this](const mtx::events::msg::KeyVerificationKey &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: received key");
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
|
|
|
|
if (sender) {
|
|
|
|
if (state_ != WaitingForOtherToAccept) {
|
|
|
|
this->cancelVerification(OutOfOrder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state_ != WaitingForKeys) {
|
|
|
|
this->cancelVerification(OutOfOrder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
this->sas->set_their_key(msg.key);
|
|
|
|
std::string info;
|
|
|
|
if (this->sender == true) {
|
|
|
|
info = "MATRIX_KEY_VERIFICATION_SAS|" +
|
|
|
|
http::client()->user_id().to_string() + "|" +
|
|
|
|
http::client()->device_id() + "|" + this->sas->public_key() +
|
|
|
|
"|" + this->toClient.to_string() + "|" +
|
|
|
|
this->deviceId.toStdString() + "|" + msg.key + "|" +
|
|
|
|
this->transaction_id;
|
|
|
|
} else {
|
|
|
|
info = "MATRIX_KEY_VERIFICATION_SAS|" + this->toClient.to_string() +
|
|
|
|
"|" + this->deviceId.toStdString() + "|" + msg.key + "|" +
|
|
|
|
http::client()->user_id().to_string() + "|" +
|
|
|
|
http::client()->device_id() + "|" + this->sas->public_key() +
|
|
|
|
"|" + this->transaction_id;
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:02:41 +03:00
|
|
|
nhlog::ui()->info("Info is: '{}'", info);
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
if (this->sender == false) {
|
|
|
|
this->sendVerificationKey();
|
|
|
|
} else {
|
2020-10-05 23:12:10 +03:00
|
|
|
if (this->commitment !=
|
2020-07-17 23:16:30 +03:00
|
|
|
mtx::crypto::bin2base64_unpadded(
|
|
|
|
mtx::crypto::sha256(msg.key + this->canonical_json.dump()))) {
|
|
|
|
this->cancelVerification(
|
|
|
|
DeviceVerificationFlow::Error::MismatchedCommitment);
|
2020-10-05 23:12:10 +03:00
|
|
|
return;
|
2020-07-17 23:16:30 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
|
|
|
|
if (this->method == mtx::events::msg::SASMethods::Emoji) {
|
|
|
|
this->sasList = this->sas->generate_bytes_emoji(info);
|
|
|
|
setState(CompareEmoji);
|
|
|
|
} else if (this->method == mtx::events::msg::SASMethods::Decimal) {
|
|
|
|
this->sasList = this->sas->generate_bytes_decimal(info);
|
|
|
|
setState(CompareNumber);
|
|
|
|
}
|
2020-07-17 23:16:30 +03:00
|
|
|
});
|
|
|
|
|
2020-06-20 15:20:43 +03:00
|
|
|
connect(
|
|
|
|
ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationMac,
|
2020-06-20 15:20:43 +03:00
|
|
|
this,
|
2020-07-17 23:16:30 +03:00
|
|
|
[this](const mtx::events::msg::KeyVerificationMac &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: received mac");
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:02:41 +03:00
|
|
|
std::map<std::string, std::string> key_list;
|
2020-07-17 23:16:30 +03:00
|
|
|
std::string key_string;
|
2020-10-06 18:02:41 +03:00
|
|
|
for (const auto &mac : msg.mac) {
|
2020-10-08 20:29:42 +03:00
|
|
|
for (const auto &[deviceid, key] : their_keys.device_keys) {
|
|
|
|
(void)deviceid;
|
2020-10-06 18:02:41 +03:00
|
|
|
if (key.keys.count(mac.first))
|
|
|
|
key_list[mac.first] = key.keys.at(mac.first);
|
2020-10-08 20:29:42 +03:00
|
|
|
}
|
2020-10-06 18:02:41 +03:00
|
|
|
|
|
|
|
if (their_keys.master_keys.keys.count(mac.first))
|
|
|
|
key_list[mac.first] = their_keys.master_keys.keys[mac.first];
|
|
|
|
if (their_keys.user_signing_keys.keys.count(mac.first))
|
|
|
|
key_list[mac.first] =
|
|
|
|
their_keys.user_signing_keys.keys[mac.first];
|
|
|
|
if (their_keys.self_signing_keys.keys.count(mac.first))
|
|
|
|
key_list[mac.first] =
|
|
|
|
their_keys.self_signing_keys.keys[mac.first];
|
|
|
|
}
|
|
|
|
auto macs = key_verification_mac(sas.get(),
|
|
|
|
toClient,
|
|
|
|
this->deviceId.toStdString(),
|
|
|
|
http::client()->user_id(),
|
|
|
|
http::client()->device_id(),
|
|
|
|
this->transaction_id,
|
|
|
|
key_list);
|
|
|
|
|
|
|
|
for (const auto &[key, mac] : macs.mac) {
|
|
|
|
if (mac != msg.mac.at(key)) {
|
|
|
|
this->cancelVerification(
|
|
|
|
DeviceVerificationFlow::Error::KeyMismatch);
|
|
|
|
return;
|
2020-06-20 15:20:43 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-06 18:02:41 +03:00
|
|
|
|
|
|
|
if (msg.keys == macs.keys) {
|
2020-10-08 17:17:38 +03:00
|
|
|
mtx::requests::KeySignaturesUpload req;
|
|
|
|
if (utils::localUser().toStdString() == this->toClient.to_string()) {
|
|
|
|
// self verification, sign master key with device key, if we
|
|
|
|
// verified it
|
|
|
|
for (const auto &mac : msg.mac) {
|
|
|
|
if (their_keys.master_keys.keys.count(mac.first)) {
|
|
|
|
json j = their_keys.master_keys;
|
|
|
|
j.erase("signatures");
|
|
|
|
j.erase("unsigned");
|
|
|
|
mtx::crypto::CrossSigningKeys master_key = j;
|
|
|
|
master_key
|
|
|
|
.signatures[utils::localUser().toStdString()]
|
|
|
|
["ed25519:" +
|
|
|
|
http::client()->device_id()] =
|
|
|
|
olm::client()->sign_message(j.dump());
|
|
|
|
req.signatures[utils::localUser().toStdString()]
|
|
|
|
[master_key.keys.at(mac.first)] =
|
|
|
|
master_key;
|
2020-12-17 04:34:32 +03:00
|
|
|
} else if (mac.first ==
|
|
|
|
"ed25519:" + this->deviceId.toStdString()) {
|
|
|
|
// Sign their device key with self signing key
|
|
|
|
|
|
|
|
auto device_id = this->deviceId.toStdString();
|
|
|
|
|
|
|
|
if (their_keys.device_keys.count(device_id)) {
|
|
|
|
json j =
|
|
|
|
their_keys.device_keys.at(device_id);
|
|
|
|
j.erase("signatures");
|
|
|
|
j.erase("unsigned");
|
|
|
|
|
|
|
|
auto secret = cache::secret(
|
|
|
|
mtx::secret_storage::secrets::
|
|
|
|
cross_signing_self_signing);
|
|
|
|
if (!secret)
|
|
|
|
continue;
|
|
|
|
auto ssk =
|
|
|
|
mtx::crypto::PkSigning::from_seed(
|
|
|
|
*secret);
|
|
|
|
|
|
|
|
mtx::crypto::DeviceKeys dev = j;
|
|
|
|
dev.signatures
|
|
|
|
[utils::localUser().toStdString()]
|
|
|
|
["ed25519:" + ssk.public_key()] =
|
|
|
|
ssk.sign(j.dump());
|
|
|
|
|
|
|
|
req.signatures[utils::localUser()
|
|
|
|
.toStdString()]
|
|
|
|
[device_id] = dev;
|
|
|
|
}
|
2020-10-08 17:17:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-17 04:34:32 +03:00
|
|
|
// Sign their master key with user signing key
|
|
|
|
for (const auto &mac : msg.mac) {
|
|
|
|
if (their_keys.master_keys.keys.count(mac.first)) {
|
|
|
|
json j = their_keys.master_keys;
|
|
|
|
j.erase("signatures");
|
|
|
|
j.erase("unsigned");
|
|
|
|
|
|
|
|
auto secret =
|
|
|
|
cache::secret(mtx::secret_storage::secrets::
|
|
|
|
cross_signing_user_signing);
|
|
|
|
if (!secret)
|
|
|
|
continue;
|
|
|
|
auto usk =
|
|
|
|
mtx::crypto::PkSigning::from_seed(*secret);
|
|
|
|
|
|
|
|
mtx::crypto::CrossSigningKeys master_key = j;
|
|
|
|
master_key
|
|
|
|
.signatures[utils::localUser().toStdString()]
|
|
|
|
["ed25519:" + usk.public_key()] =
|
|
|
|
usk.sign(j.dump());
|
|
|
|
|
|
|
|
req.signatures[toClient.to_string()]
|
|
|
|
[master_key.keys.at(mac.first)] =
|
|
|
|
master_key;
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 17:17:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!req.signatures.empty()) {
|
|
|
|
http::client()->keys_signatures_upload(
|
|
|
|
req,
|
|
|
|
[](const mtx::responses::KeySignaturesUpload &res,
|
|
|
|
mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->error(
|
|
|
|
"failed to upload signatures: {},{}",
|
2021-03-05 03:11:08 +03:00
|
|
|
mtx::errors::to_string(
|
|
|
|
err->matrix_error.errcode),
|
2020-10-08 17:17:38 +03:00
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &[user_id, tmp] : res.errors)
|
|
|
|
for (const auto &[key_id, e] : tmp)
|
|
|
|
nhlog::net()->error(
|
|
|
|
"signature error for user {} and key "
|
|
|
|
"id {}: {}, {}",
|
|
|
|
user_id,
|
|
|
|
key_id,
|
2021-03-05 02:56:25 +03:00
|
|
|
mtx::errors::to_string(e.errcode),
|
2020-10-08 17:17:38 +03:00
|
|
|
e.error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
this->isMacVerified = true;
|
|
|
|
this->acceptDevice();
|
2020-07-17 23:16:30 +03:00
|
|
|
} else {
|
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::KeyMismatch);
|
2020-06-26 01:54:42 +03:00
|
|
|
}
|
|
|
|
});
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-06-23 01:05:56 +03:00
|
|
|
connect(ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationReady,
|
2020-06-23 01:05:56 +03:00
|
|
|
this,
|
2020-07-17 23:16:30 +03:00
|
|
|
[this](const mtx::events::msg::KeyVerificationReady &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: received ready");
|
2020-09-04 09:32:24 +03:00
|
|
|
if (!sender) {
|
|
|
|
if (msg.from_device != http::client()->device_id()) {
|
2020-10-05 23:12:10 +03:00
|
|
|
error_ = User;
|
|
|
|
emit errorChanged();
|
|
|
|
setState(Failed);
|
2020-09-04 09:32:24 +03:00
|
|
|
}
|
|
|
|
|
2020-08-29 11:07:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-09-04 09:32:24 +03:00
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
2020-08-18 08:59:02 +03:00
|
|
|
else {
|
|
|
|
this->deviceId = QString::fromStdString(msg.from_device);
|
|
|
|
}
|
2020-06-23 01:05:56 +03:00
|
|
|
}
|
2020-07-17 23:16:30 +03:00
|
|
|
this->startVerificationRequest();
|
2020-06-23 01:05:56 +03:00
|
|
|
});
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-06-23 01:05:56 +03:00
|
|
|
connect(ChatPage::instance(),
|
2020-10-05 23:12:10 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationDone,
|
2020-06-23 01:05:56 +03:00
|
|
|
this,
|
2020-07-17 23:16:30 +03:00
|
|
|
[this](const mtx::events::msg::KeyVerificationDone &msg) {
|
2021-07-10 17:11:33 +03:00
|
|
|
nhlog::crypto()->info("verification: receoved done");
|
2020-07-17 23:16:30 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-07-17 23:16:30 +03:00
|
|
|
return;
|
2020-06-09 19:36:41 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
nhlog::ui()->info("Flow done on other side");
|
2020-06-09 19:36:41 +03:00
|
|
|
});
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
timeout->start(TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
QString
|
2020-10-05 23:12:10 +03:00
|
|
|
DeviceVerificationFlow::state()
|
2020-06-17 21:28:35 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
switch (state_) {
|
|
|
|
case PromptStartVerification:
|
|
|
|
return "PromptStartVerification";
|
|
|
|
case CompareEmoji:
|
|
|
|
return "CompareEmoji";
|
|
|
|
case CompareNumber:
|
|
|
|
return "CompareNumber";
|
|
|
|
case WaitingForKeys:
|
|
|
|
return "WaitingForKeys";
|
|
|
|
case WaitingForOtherToAccept:
|
|
|
|
return "WaitingForOtherToAccept";
|
|
|
|
case WaitingForMac:
|
|
|
|
return "WaitingForMac";
|
|
|
|
case Success:
|
|
|
|
return "Success";
|
|
|
|
case Failed:
|
|
|
|
return "Failed";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::next()
|
|
|
|
{
|
|
|
|
if (sender) {
|
|
|
|
switch (state_) {
|
|
|
|
case PromptStartVerification:
|
|
|
|
sendVerificationRequest();
|
|
|
|
break;
|
|
|
|
case CompareEmoji:
|
|
|
|
case CompareNumber:
|
|
|
|
sendVerificationMac();
|
|
|
|
break;
|
|
|
|
case WaitingForKeys:
|
|
|
|
case WaitingForOtherToAccept:
|
|
|
|
case WaitingForMac:
|
|
|
|
case Success:
|
|
|
|
case Failed:
|
|
|
|
nhlog::db()->error("verification: Invalid state transition!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (state_) {
|
|
|
|
case PromptStartVerification:
|
|
|
|
if (canonical_json.is_null())
|
|
|
|
sendVerificationReady();
|
|
|
|
else // legacy path without request and ready
|
|
|
|
acceptVerificationRequest();
|
|
|
|
break;
|
|
|
|
case CompareEmoji:
|
|
|
|
[[fallthrough]];
|
|
|
|
case CompareNumber:
|
|
|
|
sendVerificationMac();
|
|
|
|
break;
|
|
|
|
case WaitingForKeys:
|
|
|
|
case WaitingForOtherToAccept:
|
|
|
|
case WaitingForMac:
|
|
|
|
case Success:
|
|
|
|
case Failed:
|
|
|
|
nhlog::db()->error("verification: Invalid state transition!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 21:28:35 +03:00
|
|
|
}
|
|
|
|
|
2020-06-07 14:35:32 +03:00
|
|
|
QString
|
|
|
|
DeviceVerificationFlow::getUserId()
|
2020-06-04 16:44:15 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
return QString::fromStdString(this->toClient.to_string());
|
2020-06-07 14:35:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
DeviceVerificationFlow::getDeviceId()
|
|
|
|
{
|
|
|
|
return this->deviceId;
|
|
|
|
}
|
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
bool
|
|
|
|
DeviceVerificationFlow::getSender()
|
|
|
|
{
|
|
|
|
return this->sender;
|
|
|
|
}
|
|
|
|
|
2020-06-20 15:20:43 +03:00
|
|
|
std::vector<int>
|
|
|
|
DeviceVerificationFlow::getSasList()
|
|
|
|
{
|
|
|
|
return this->sasList;
|
|
|
|
}
|
|
|
|
|
2021-01-12 15:32:12 +03:00
|
|
|
bool
|
|
|
|
DeviceVerificationFlow::isSelfVerification() const
|
|
|
|
{
|
|
|
|
return this->toClient.to_string() == http::client()->user_id().to_string();
|
|
|
|
}
|
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
void
|
2020-10-05 23:12:10 +03:00
|
|
|
DeviceVerificationFlow::setEventId(std::string event_id_)
|
2020-07-29 00:55:47 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
this->relation.rel_type = mtx::common::RelationType::Reference;
|
|
|
|
this->relation.event_id = event_id_;
|
|
|
|
this->transaction_id = event_id_;
|
2020-07-29 00:55:47 +03:00
|
|
|
}
|
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
void
|
2020-10-05 23:12:10 +03:00
|
|
|
DeviceVerificationFlow::handleStartMessage(const mtx::events::msg::KeyVerificationStart &msg,
|
|
|
|
std::string)
|
2020-06-17 21:28:35 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
if (msg.transaction_id.has_value()) {
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id)
|
|
|
|
return;
|
2021-01-27 00:36:35 +03:00
|
|
|
} else if (msg.relations.references()) {
|
|
|
|
if (msg.relations.references() != this->relation.event_id)
|
2020-10-05 23:12:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((std::find(msg.key_agreement_protocols.begin(),
|
|
|
|
msg.key_agreement_protocols.end(),
|
|
|
|
"curve25519-hkdf-sha256") != msg.key_agreement_protocols.end()) &&
|
|
|
|
(std::find(msg.hashes.begin(), msg.hashes.end(), "sha256") != msg.hashes.end()) &&
|
|
|
|
(std::find(msg.message_authentication_codes.begin(),
|
|
|
|
msg.message_authentication_codes.end(),
|
|
|
|
"hkdf-hmac-sha256") != msg.message_authentication_codes.end())) {
|
|
|
|
if (std::find(msg.short_authentication_string.begin(),
|
|
|
|
msg.short_authentication_string.end(),
|
|
|
|
mtx::events::msg::SASMethods::Emoji) !=
|
|
|
|
msg.short_authentication_string.end()) {
|
|
|
|
this->method = mtx::events::msg::SASMethods::Emoji;
|
|
|
|
} else if (std::find(msg.short_authentication_string.begin(),
|
|
|
|
msg.short_authentication_string.end(),
|
|
|
|
mtx::events::msg::SASMethods::Decimal) !=
|
|
|
|
msg.short_authentication_string.end()) {
|
|
|
|
this->method = mtx::events::msg::SASMethods::Decimal;
|
|
|
|
} else {
|
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!sender)
|
|
|
|
this->canonical_json = nlohmann::json(msg);
|
|
|
|
else {
|
|
|
|
if (utils::localUser().toStdString() < this->toClient.to_string()) {
|
|
|
|
this->canonical_json = nlohmann::json(msg);
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 21:28:35 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
if (state_ != PromptStartVerification)
|
|
|
|
this->acceptVerificationRequest();
|
|
|
|
} else {
|
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod);
|
|
|
|
}
|
2020-07-29 00:55:47 +03:00
|
|
|
}
|
|
|
|
|
2020-06-04 16:44:15 +03:00
|
|
|
//! accepts a verification
|
2020-03-13 23:05:18 +03:00
|
|
|
void
|
|
|
|
DeviceVerificationFlow::acceptVerificationRequest()
|
|
|
|
{
|
2020-06-04 16:44:15 +03:00
|
|
|
mtx::events::msg::KeyVerificationAccept req;
|
|
|
|
|
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
2020-06-17 21:28:35 +03:00
|
|
|
req.key_agreement_protocol = "curve25519-hkdf-sha256";
|
2020-06-07 14:35:32 +03:00
|
|
|
req.hash = "sha256";
|
2020-06-17 21:28:35 +03:00
|
|
|
req.message_authentication_code = "hkdf-hmac-sha256";
|
2020-10-05 23:12:10 +03:00
|
|
|
if (this->method == mtx::events::msg::SASMethods::Emoji)
|
2020-06-20 15:20:43 +03:00
|
|
|
req.short_authentication_string = {mtx::events::msg::SASMethods::Emoji};
|
2020-10-05 23:12:10 +03:00
|
|
|
else if (this->method == mtx::events::msg::SASMethods::Decimal)
|
2020-06-20 15:20:43 +03:00
|
|
|
req.short_authentication_string = {mtx::events::msg::SASMethods::Decimal};
|
|
|
|
req.commitment = mtx::crypto::bin2base64_unpadded(
|
|
|
|
mtx::crypto::sha256(this->sas->public_key() + this->canonical_json.dump()));
|
2020-06-04 16:44:15 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
|
|
|
setState(WaitingForKeys);
|
2020-06-04 16:44:15 +03:00
|
|
|
}
|
2020-06-23 01:05:56 +03:00
|
|
|
//! responds verification request
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::sendVerificationReady()
|
|
|
|
{
|
|
|
|
mtx::events::msg::KeyVerificationReady req;
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
req.from_device = http::client()->device_id();
|
|
|
|
req.methods = {mtx::events::msg::VerificationMethods::SASv1};
|
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
|
|
|
setState(WaitingForKeys);
|
2020-06-23 01:05:56 +03:00
|
|
|
}
|
|
|
|
//! accepts a verification
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::sendVerificationDone()
|
|
|
|
{
|
|
|
|
mtx::events::msg::KeyVerificationDone req;
|
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
2020-06-23 01:05:56 +03:00
|
|
|
}
|
2020-06-04 16:44:15 +03:00
|
|
|
//! starts the verification flow
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::startVerificationRequest()
|
|
|
|
{
|
2020-06-07 14:35:32 +03:00
|
|
|
mtx::events::msg::KeyVerificationStart req;
|
|
|
|
|
|
|
|
req.from_device = http::client()->device_id();
|
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
2020-06-17 21:28:35 +03:00
|
|
|
req.key_agreement_protocols = {"curve25519-hkdf-sha256"};
|
|
|
|
req.hashes = {"sha256"};
|
2020-07-17 23:16:30 +03:00
|
|
|
req.message_authentication_codes = {"hkdf-hmac-sha256"};
|
2020-06-17 21:28:35 +03:00
|
|
|
req.short_authentication_string = {mtx::events::msg::SASMethods::Decimal,
|
|
|
|
mtx::events::msg::SASMethods::Emoji};
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) {
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationStart> body;
|
2020-10-05 23:12:10 +03:00
|
|
|
req.transaction_id = this->transaction_id;
|
|
|
|
this->canonical_json = nlohmann::json(req);
|
2020-08-09 06:05:15 +03:00
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) {
|
2021-01-27 00:36:35 +03:00
|
|
|
req.relations.relations.push_back(this->relation);
|
|
|
|
// Set synthesized to surpress the nheko relation extensions
|
|
|
|
req.relations.synthesized = true;
|
|
|
|
this->canonical_json = nlohmann::json(req);
|
2020-07-17 23:16:30 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
|
|
|
setState(WaitingForOtherToAccept);
|
2020-06-04 16:44:15 +03:00
|
|
|
}
|
|
|
|
//! sends a verification request
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::sendVerificationRequest()
|
|
|
|
{
|
|
|
|
mtx::events::msg::KeyVerificationRequest req;
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
req.from_device = http::client()->device_id();
|
2020-10-02 13:18:54 +03:00
|
|
|
req.methods = {mtx::events::msg::VerificationMethods::SASv1};
|
2020-07-17 23:16:30 +03:00
|
|
|
|
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) {
|
2020-10-02 13:18:54 +03:00
|
|
|
QDateTime currentTime = QDateTime::currentDateTimeUtc();
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
req.timestamp = (uint64_t)currentTime.toMSecsSinceEpoch();
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-08-09 06:05:15 +03:00
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) {
|
2020-10-05 23:12:10 +03:00
|
|
|
req.to = this->toClient.to_string();
|
2020-08-09 06:05:15 +03:00
|
|
|
req.msgtype = "m.key.verification.request";
|
|
|
|
req.body = "User is requesting to verify keys with you. However, your client does "
|
|
|
|
"not support this method, so you will need to use the legacy method of "
|
|
|
|
"key verification.";
|
2020-07-17 23:16:30 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
|
|
|
|
send(req);
|
|
|
|
setState(WaitingForOtherToAccept);
|
2020-03-13 23:05:18 +03:00
|
|
|
}
|
|
|
|
//! cancels a verification flow
|
|
|
|
void
|
2020-06-26 12:40:37 +03:00
|
|
|
DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_code)
|
2020-03-13 23:05:18 +03:00
|
|
|
{
|
2021-07-10 17:11:33 +03:00
|
|
|
if (state_ == State::Success || state_ == State::Failed)
|
|
|
|
return;
|
|
|
|
|
2020-06-04 16:44:15 +03:00
|
|
|
mtx::events::msg::KeyVerificationCancel req;
|
|
|
|
|
2020-06-26 12:40:37 +03:00
|
|
|
if (error_code == DeviceVerificationFlow::Error::UnknownMethod) {
|
|
|
|
req.code = "m.unknown_method";
|
2020-10-05 23:12:10 +03:00
|
|
|
req.reason = "unknown method received";
|
2020-06-26 12:40:37 +03:00
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::MismatchedCommitment) {
|
|
|
|
req.code = "m.mismatched_commitment";
|
|
|
|
req.reason = "commitment didn't match";
|
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::MismatchedSAS) {
|
|
|
|
req.code = "m.mismatched_sas";
|
|
|
|
req.reason = "sas didn't match";
|
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::KeyMismatch) {
|
|
|
|
req.code = "m.key_match";
|
|
|
|
req.reason = "keys did not match";
|
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::Timeout) {
|
|
|
|
req.code = "m.timeout";
|
|
|
|
req.reason = "timed out";
|
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::User) {
|
|
|
|
req.code = "m.user";
|
|
|
|
req.reason = "user cancelled the verification";
|
2020-10-05 23:12:10 +03:00
|
|
|
} else if (error_code == DeviceVerificationFlow::Error::OutOfOrder) {
|
|
|
|
req.code = "m.unexpected_message";
|
|
|
|
req.reason = "received messages out of order";
|
2020-06-26 12:40:37 +03:00
|
|
|
}
|
2020-06-07 14:35:32 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
this->error_ = error_code;
|
|
|
|
emit errorChanged();
|
|
|
|
this->setState(Failed);
|
2020-06-20 15:20:43 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
2020-03-13 23:05:18 +03:00
|
|
|
}
|
2020-06-09 19:36:41 +03:00
|
|
|
//! sends the verification key
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::sendVerificationKey()
|
|
|
|
{
|
|
|
|
mtx::events::msg::KeyVerificationKey req;
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
req.key = this->sas->public_key();
|
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
2020-06-09 19:36:41 +03:00
|
|
|
}
|
2020-10-02 02:14:42 +03:00
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationMac
|
|
|
|
key_verification_mac(mtx::crypto::SAS *sas,
|
|
|
|
mtx::identifiers::User sender,
|
|
|
|
const std::string &senderDevice,
|
|
|
|
mtx::identifiers::User receiver,
|
|
|
|
const std::string &receiverDevice,
|
|
|
|
const std::string &transactionId,
|
|
|
|
std::map<std::string, std::string> keys)
|
2020-06-09 19:36:41 +03:00
|
|
|
{
|
|
|
|
mtx::events::msg::KeyVerificationMac req;
|
|
|
|
|
2020-10-02 02:14:42 +03:00
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + sender.to_string() + senderDevice +
|
|
|
|
receiver.to_string() + receiverDevice + transactionId;
|
|
|
|
|
|
|
|
std::string key_list;
|
|
|
|
bool first = true;
|
|
|
|
for (const auto &[key_id, key] : keys) {
|
|
|
|
req.mac[key_id] = sas->calculate_mac(key, info + key_id);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
key_list += ",";
|
|
|
|
key_list += key_id;
|
|
|
|
first = false;
|
2020-06-23 01:05:56 +03:00
|
|
|
}
|
|
|
|
|
2020-10-02 02:14:42 +03:00
|
|
|
req.keys = sas->calculate_mac(key_list, info + "KEY_IDS");
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sends the mac of the keys
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::sendVerificationMac()
|
|
|
|
{
|
|
|
|
std::map<std::string, std::string> key_list;
|
|
|
|
key_list["ed25519:" + http::client()->device_id()] = olm::client()->identity_keys().ed25519;
|
|
|
|
|
2020-10-08 19:30:31 +03:00
|
|
|
// send our master key, if we trust it
|
|
|
|
if (!this->our_trusted_master_key.empty())
|
|
|
|
key_list["ed25519:" + our_trusted_master_key] = our_trusted_master_key;
|
|
|
|
|
2020-10-02 02:14:42 +03:00
|
|
|
mtx::events::msg::KeyVerificationMac req =
|
|
|
|
key_verification_mac(sas.get(),
|
|
|
|
http::client()->user_id(),
|
|
|
|
http::client()->device_id(),
|
|
|
|
this->toClient,
|
|
|
|
this->deviceId.toStdString(),
|
|
|
|
this->transaction_id,
|
|
|
|
key_list);
|
2020-06-09 19:36:41 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
send(req);
|
|
|
|
|
|
|
|
setState(WaitingForMac);
|
|
|
|
acceptDevice();
|
2020-06-09 19:36:41 +03:00
|
|
|
}
|
2020-03-13 23:05:18 +03:00
|
|
|
//! Completes the verification flow
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::acceptDevice()
|
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
if (!isMacVerified) {
|
|
|
|
setState(WaitingForMac);
|
|
|
|
} else if (state_ == WaitingForMac) {
|
|
|
|
cache::markDeviceVerified(this->toClient.to_string(), this->deviceId.toStdString());
|
|
|
|
this->sendVerificationDone();
|
|
|
|
setState(Success);
|
2020-12-17 05:16:06 +03:00
|
|
|
|
|
|
|
// Request secrets. We should probably check somehow, if a device knowns about the
|
|
|
|
// secrets.
|
|
|
|
if (utils::localUser().toStdString() == this->toClient.to_string() &&
|
|
|
|
(!cache::secret(mtx::secret_storage::secrets::cross_signing_self_signing) ||
|
|
|
|
!cache::secret(mtx::secret_storage::secrets::cross_signing_user_signing))) {
|
|
|
|
olm::request_cross_signing_keys();
|
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceVerificationFlow::unverify()
|
|
|
|
{
|
|
|
|
cache::markDeviceUnverified(this->toClient.to_string(), this->deviceId.toStdString());
|
2020-07-05 19:03:27 +03:00
|
|
|
|
|
|
|
emit refreshProfile();
|
|
|
|
}
|
2020-10-02 02:14:42 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
QSharedPointer<DeviceVerificationFlow>
|
|
|
|
DeviceVerificationFlow::NewInRoomVerification(QObject *parent_,
|
|
|
|
TimelineModel *timelineModel_,
|
|
|
|
const mtx::events::msg::KeyVerificationRequest &msg,
|
|
|
|
QString other_user_,
|
|
|
|
QString event_id_)
|
2020-07-05 19:03:27 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
QSharedPointer<DeviceVerificationFlow> flow(
|
2020-10-06 18:02:41 +03:00
|
|
|
new DeviceVerificationFlow(parent_,
|
|
|
|
Type::RoomMsg,
|
|
|
|
timelineModel_,
|
|
|
|
other_user_,
|
|
|
|
QString::fromStdString(msg.from_device)));
|
2020-10-05 23:12:10 +03:00
|
|
|
|
2020-10-06 18:02:41 +03:00
|
|
|
flow->setEventId(event_id_.toStdString());
|
2020-07-05 19:03:27 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
if (std::find(msg.methods.begin(),
|
|
|
|
msg.methods.end(),
|
|
|
|
mtx::events::msg::VerificationMethods::SASv1) == msg.methods.end()) {
|
|
|
|
flow->cancelVerification(UnknownMethod);
|
2020-07-05 19:03:27 +03:00
|
|
|
}
|
2020-06-04 16:44:15 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
QSharedPointer<DeviceVerificationFlow>
|
|
|
|
DeviceVerificationFlow::NewToDeviceVerification(QObject *parent_,
|
|
|
|
const mtx::events::msg::KeyVerificationRequest &msg,
|
|
|
|
QString other_user_,
|
|
|
|
QString txn_id_)
|
|
|
|
{
|
|
|
|
QSharedPointer<DeviceVerificationFlow> flow(new DeviceVerificationFlow(
|
|
|
|
parent_, Type::ToDevice, nullptr, other_user_, QString::fromStdString(msg.from_device)));
|
|
|
|
flow->transaction_id = txn_id_.toStdString();
|
|
|
|
|
|
|
|
if (std::find(msg.methods.begin(),
|
|
|
|
msg.methods.end(),
|
|
|
|
mtx::events::msg::VerificationMethods::SASv1) == msg.methods.end()) {
|
|
|
|
flow->cancelVerification(UnknownMethod);
|
2020-07-05 19:03:27 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
|
|
|
|
return flow;
|
2020-07-05 19:03:27 +03:00
|
|
|
}
|
2020-10-05 23:12:10 +03:00
|
|
|
QSharedPointer<DeviceVerificationFlow>
|
|
|
|
DeviceVerificationFlow::NewToDeviceVerification(QObject *parent_,
|
|
|
|
const mtx::events::msg::KeyVerificationStart &msg,
|
|
|
|
QString other_user_,
|
|
|
|
QString txn_id_)
|
|
|
|
{
|
|
|
|
QSharedPointer<DeviceVerificationFlow> flow(new DeviceVerificationFlow(
|
|
|
|
parent_, Type::ToDevice, nullptr, other_user_, QString::fromStdString(msg.from_device)));
|
|
|
|
flow->transaction_id = txn_id_.toStdString();
|
2020-07-05 19:03:27 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
flow->handleStartMessage(msg, "");
|
|
|
|
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
QSharedPointer<DeviceVerificationFlow>
|
|
|
|
DeviceVerificationFlow::InitiateUserVerification(QObject *parent_,
|
|
|
|
TimelineModel *timelineModel_,
|
|
|
|
QString userid)
|
2020-07-05 19:03:27 +03:00
|
|
|
{
|
2020-10-05 23:12:10 +03:00
|
|
|
QSharedPointer<DeviceVerificationFlow> flow(
|
|
|
|
new DeviceVerificationFlow(parent_, Type::RoomMsg, timelineModel_, userid, ""));
|
|
|
|
flow->sender = true;
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
QSharedPointer<DeviceVerificationFlow>
|
|
|
|
DeviceVerificationFlow::InitiateDeviceVerification(QObject *parent_, QString userid, QString device)
|
|
|
|
{
|
|
|
|
QSharedPointer<DeviceVerificationFlow> flow(
|
|
|
|
new DeviceVerificationFlow(parent_, Type::ToDevice, nullptr, userid, device));
|
2020-07-05 19:03:27 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
flow->sender = true;
|
|
|
|
flow->transaction_id = http::client()->generate_txn_id();
|
|
|
|
|
|
|
|
return flow;
|
2020-03-13 23:05:18 +03:00
|
|
|
}
|