|
|
@ -8,24 +8,31 @@ |
|
|
|
#include <QDateTime> |
|
|
|
#include <QDateTime> |
|
|
|
#include <QTimer> |
|
|
|
#include <QTimer> |
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
|
|
|
static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
|
|
|
|
|
|
|
|
|
|
|
namespace msgs = mtx::events::msg; |
|
|
|
namespace msgs = mtx::events::msg; |
|
|
|
|
|
|
|
|
|
|
|
DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow::Type flow_type) |
|
|
|
DeviceVerificationFlow::DeviceVerificationFlow(QObject *, |
|
|
|
|
|
|
|
DeviceVerificationFlow::Type flow_type, |
|
|
|
|
|
|
|
TimelineModel *model) |
|
|
|
: type(flow_type) |
|
|
|
: type(flow_type) |
|
|
|
|
|
|
|
, model_(model) |
|
|
|
{ |
|
|
|
{ |
|
|
|
timeout = new QTimer(this); |
|
|
|
timeout = new QTimer(this); |
|
|
|
timeout->setSingleShot(true); |
|
|
|
timeout->setSingleShot(true); |
|
|
|
this->sas = olm::client()->sas_init(); |
|
|
|
this->sas = olm::client()->sas_init(); |
|
|
|
this->isMacVerified = false; |
|
|
|
this->isMacVerified = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model) { |
|
|
|
connect(this->model_, |
|
|
|
connect(this->model_, |
|
|
|
&TimelineModel::updateFlowEventId, |
|
|
|
&TimelineModel::updateFlowEventId, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](std::string event_id) { this->relation.in_reply_to.event_id = event_id; }); |
|
|
|
[this](std::string event_id) { |
|
|
|
|
|
|
|
this->relation.rel_type = mtx::common::RelationType::Reference; |
|
|
|
|
|
|
|
this->relation.event_id = event_id; |
|
|
|
|
|
|
|
this->transaction_id = event_id; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connect(timeout, &QTimer::timeout, this, [this]() { |
|
|
|
connect(timeout, &QTimer::timeout, this, [this]() { |
|
|
|
emit timedout(); |
|
|
|
emit timedout(); |
|
|
@ -42,8 +49,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if ((std::find(msg.key_agreement_protocols.begin(), |
|
|
|
if ((std::find(msg.key_agreement_protocols.begin(), |
|
|
@ -69,8 +75,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this->acceptVerificationRequest(); |
|
|
|
|
|
|
|
this->canonical_json = nlohmann::json(msg); |
|
|
|
this->canonical_json = nlohmann::json(msg); |
|
|
|
|
|
|
|
this->acceptVerificationRequest(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
} |
|
|
|
} |
|
|
@ -84,8 +90,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if ((msg.key_agreement_protocol == "curve25519-hkdf-sha256") && |
|
|
|
if ((msg.key_agreement_protocol == "curve25519-hkdf-sha256") && |
|
|
@ -116,8 +121,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
emit verificationCanceled(); |
|
|
|
emit verificationCanceled(); |
|
|
@ -131,8 +135,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this->sas->set_their_key(msg.key); |
|
|
|
this->sas->set_their_key(msg.key); |
|
|
@ -157,6 +160,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
} else if (this->method == DeviceVerificationFlow::Method::Decimal) { |
|
|
|
} else if (this->method == DeviceVerificationFlow::Method::Decimal) { |
|
|
|
this->sasList = this->sas->generate_bytes_decimal(info); |
|
|
|
this->sasList = this->sas->generate_bytes_decimal(info); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this->sender == false) { |
|
|
|
if (this->sender == false) { |
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
this->sendVerificationKey(); |
|
|
|
this->sendVerificationKey(); |
|
|
@ -181,8 +185,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + this->toClient.to_string() + |
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + this->toClient.to_string() + |
|
|
@ -227,12 +230,11 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
// this is just a workaround
|
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id = |
|
|
|
|
|
|
|
msg.relates_to.value().in_reply_to.event_id; |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this->deviceId = QString::fromStdString(msg.from_device); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this->startVerificationRequest(); |
|
|
|
this->startVerificationRequest(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -245,8 +247,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
if (msg.relates_to.value().event_id != this->relation.event_id) |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this->acceptDevice(); |
|
|
|
this->acceptDevice(); |
|
|
@ -297,12 +298,6 @@ DeviceVerificationFlow::getSasList() |
|
|
|
return this->sasList; |
|
|
|
return this->sasList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
DeviceVerificationFlow::setModel(TimelineModel *&model) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this->model_ = model; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::setTransactionId(QString transaction_id_) |
|
|
|
DeviceVerificationFlow::setTransactionId(QString transaction_id_) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -352,13 +347,15 @@ void |
|
|
|
DeviceVerificationFlow::setSender(bool sender_) |
|
|
|
DeviceVerificationFlow::setSender(bool sender_) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this->sender = sender_; |
|
|
|
this->sender = sender_; |
|
|
|
|
|
|
|
if (this->sender) |
|
|
|
this->transaction_id = http::client()->generate_txn_id(); |
|
|
|
this->transaction_id = http::client()->generate_txn_id(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::setEventId(std::string event_id) |
|
|
|
DeviceVerificationFlow::setEventId(std::string event_id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this->relation.in_reply_to.event_id = event_id; |
|
|
|
this->relation.rel_type = mtx::common::RelationType::Reference; |
|
|
|
|
|
|
|
this->relation.event_id = event_id; |
|
|
|
this->transaction_id = event_id; |
|
|
|
this->transaction_id = event_id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -477,6 +474,7 @@ DeviceVerificationFlow::startVerificationRequest() |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { |
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { |
|
|
|
req.relates_to = this->relation; |
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
this->canonical_json = nlohmann::json(req); |
|
|
|
(model_)->sendMessage(req); |
|
|
|
(model_)->sendMessage(req); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -562,6 +560,7 @@ DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_c |
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { |
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { |
|
|
|
req.relates_to = this->relation; |
|
|
|
req.relates_to = this->relation; |
|
|
|
(model_)->sendMessage(req); |
|
|
|
(model_)->sendMessage(req); |
|
|
|
|
|
|
|
this->deleteLater(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO : Handle Blocking user better
|
|
|
|
// TODO : Handle Blocking user better
|
|
|
|