|
|
@ -6,11 +6,13 @@ |
|
|
|
#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::DeviceVerificationFlow(QObject *, DeviceVerificationFlow::Type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
timeout = new QTimer(this); |
|
|
|
timeout = new QTimer(this); |
|
|
|
timeout->setSingleShot(true); |
|
|
|
timeout->setSingleShot(true); |
|
|
@ -26,192 +28,218 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *) |
|
|
|
ChatPage::instance(), |
|
|
|
ChatPage::instance(), |
|
|
|
&ChatPage::recievedDeviceVerificationStart, |
|
|
|
&ChatPage::recievedDeviceVerificationStart, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
[this](const mtx::events::msg::KeyVerificationStart &msg, std::string) { |
|
|
|
auto msg = |
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationStart>>(message); |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
return; |
|
|
|
if ((std::find(msg.content.key_agreement_protocols.begin(), |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
msg.content.key_agreement_protocols.end(), |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
"curve25519-hkdf-sha256") != |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
msg.content.key_agreement_protocols.end()) && |
|
|
|
return; |
|
|
|
(std::find(msg.content.hashes.begin(), |
|
|
|
|
|
|
|
msg.content.hashes.end(), |
|
|
|
|
|
|
|
"sha256") != msg.content.hashes.end()) && |
|
|
|
|
|
|
|
(std::find(msg.content.message_authentication_codes.begin(), |
|
|
|
|
|
|
|
msg.content.message_authentication_codes.end(), |
|
|
|
|
|
|
|
"hmac-sha256") != |
|
|
|
|
|
|
|
msg.content.message_authentication_codes.end())) { |
|
|
|
|
|
|
|
if (std::find(msg.content.short_authentication_string.begin(), |
|
|
|
|
|
|
|
msg.content.short_authentication_string.end(), |
|
|
|
|
|
|
|
mtx::events::msg::SASMethods::Decimal) != |
|
|
|
|
|
|
|
msg.content.short_authentication_string.end()) { |
|
|
|
|
|
|
|
this->method = DeviceVerificationFlow::Method::Emoji; |
|
|
|
|
|
|
|
} else if (std::find( |
|
|
|
|
|
|
|
msg.content.short_authentication_string.begin(), |
|
|
|
|
|
|
|
msg.content.short_authentication_string.end(), |
|
|
|
|
|
|
|
mtx::events::msg::SASMethods::Emoji) != |
|
|
|
|
|
|
|
msg.content.short_authentication_string.end()) { |
|
|
|
|
|
|
|
this->method = DeviceVerificationFlow::Method::Decimal; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this->acceptVerificationRequest(); |
|
|
|
|
|
|
|
this->canonical_json = nlohmann::json(msg.content); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
if ((std::find(msg.key_agreement_protocols.begin(), |
|
|
|
connect( |
|
|
|
msg.key_agreement_protocols.end(), |
|
|
|
ChatPage::instance(), |
|
|
|
"curve25519-hkdf-sha256") != msg.key_agreement_protocols.end()) && |
|
|
|
&ChatPage::recievedDeviceVerificationAccept, |
|
|
|
(std::find(msg.hashes.begin(), msg.hashes.end(), "sha256") != |
|
|
|
this, |
|
|
|
msg.hashes.end()) && |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
(std::find(msg.message_authentication_codes.begin(), |
|
|
|
auto msg = |
|
|
|
msg.message_authentication_codes.end(), |
|
|
|
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationAccept>>(message); |
|
|
|
"hmac-sha256") != msg.message_authentication_codes.end())) { |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
if (std::find(msg.short_authentication_string.begin(), |
|
|
|
if ((msg.content.key_agreement_protocol == "curve25519-hkdf-sha256") && |
|
|
|
msg.short_authentication_string.end(), |
|
|
|
(msg.content.hash == "sha256") && |
|
|
|
mtx::events::msg::SASMethods::Decimal) != |
|
|
|
(msg.content.message_authentication_code == "hkdf-hmac-sha256")) { |
|
|
|
msg.short_authentication_string.end()) { |
|
|
|
this->commitment = msg.content.commitment; |
|
|
|
this->method = DeviceVerificationFlow::Method::Emoji; |
|
|
|
if (std::find(msg.content.short_authentication_string.begin(), |
|
|
|
} else if (std::find(msg.short_authentication_string.begin(), |
|
|
|
msg.content.short_authentication_string.end(), |
|
|
|
msg.short_authentication_string.end(), |
|
|
|
mtx::events::msg::SASMethods::Emoji) != |
|
|
|
mtx::events::msg::SASMethods::Emoji) != |
|
|
|
msg.content.short_authentication_string.end()) { |
|
|
|
msg.short_authentication_string.end()) { |
|
|
|
this->method = DeviceVerificationFlow::Method::Emoji; |
|
|
|
this->method = DeviceVerificationFlow::Method::Decimal; |
|
|
|
} else { |
|
|
|
|
|
|
|
this->method = DeviceVerificationFlow::Method::Decimal; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this->mac_method = msg.content.message_authentication_code; |
|
|
|
|
|
|
|
this->sendVerificationKey(); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this->cancelVerification( |
|
|
|
this->cancelVerification( |
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this->acceptVerificationRequest(); |
|
|
|
|
|
|
|
this->canonical_json = nlohmann::json(msg); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(ChatPage::instance(), |
|
|
|
|
|
|
|
&ChatPage::recievedDeviceVerificationAccept, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
[this](const mtx::events::msg::KeyVerificationAccept &msg) { |
|
|
|
|
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
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()) { |
|
|
|
|
|
|
|
this->method = DeviceVerificationFlow::Method::Emoji; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->method = DeviceVerificationFlow::Method::Decimal; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this->mac_method = msg.message_authentication_code; |
|
|
|
|
|
|
|
this->sendVerificationKey(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::UnknownMethod); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect(ChatPage::instance(), |
|
|
|
connect(ChatPage::instance(), |
|
|
|
&ChatPage::recievedDeviceVerificationCancel, |
|
|
|
&ChatPage::recievedDeviceVerificationCancel, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
[this](const mtx::events::msg::KeyVerificationCancel &msg) { |
|
|
|
auto msg = |
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationCancel>>(message); |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
return; |
|
|
|
emit verificationCanceled(); |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
emit verificationCanceled(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(ChatPage::instance(), |
|
|
|
|
|
|
|
&ChatPage::recievedDeviceVerificationKey, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
[this](const mtx::events::msg::KeyVerificationKey &msg) { |
|
|
|
|
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
|
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this->method == DeviceVerificationFlow::Method::Emoji) { |
|
|
|
|
|
|
|
this->sasList = this->sas->generate_bytes_emoji(info); |
|
|
|
|
|
|
|
} else if (this->method == DeviceVerificationFlow::Method::Decimal) { |
|
|
|
|
|
|
|
this->sasList = this->sas->generate_bytes_decimal(info); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this->sender == false) { |
|
|
|
|
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
|
|
|
|
this->sendVerificationKey(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (this->commitment == |
|
|
|
|
|
|
|
mtx::crypto::bin2base64_unpadded( |
|
|
|
|
|
|
|
mtx::crypto::sha256(msg.key + this->canonical_json.dump()))) { |
|
|
|
|
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::MismatchedCommitment); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect( |
|
|
|
connect( |
|
|
|
ChatPage::instance(), |
|
|
|
ChatPage::instance(), |
|
|
|
&ChatPage::recievedDeviceVerificationKey, |
|
|
|
&ChatPage::recievedDeviceVerificationMac, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
[this](const mtx::events::msg::KeyVerificationMac &msg) { |
|
|
|
auto msg = std::get<mtx::events::DeviceEvent<msgs::KeyVerificationKey>>(message); |
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
this->sas->set_their_key(msg.content.key); |
|
|
|
return; |
|
|
|
std::string info; |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
if (this->sender == true) { |
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
info = "MATRIX_KEY_VERIFICATION_SAS|" + |
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
http::client()->user_id().to_string() + "|" + |
|
|
|
return; |
|
|
|
http::client()->device_id() + "|" + |
|
|
|
} |
|
|
|
this->sas->public_key() + "|" + |
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + this->toClient.to_string() + |
|
|
|
this->toClient.to_string() + "|" + |
|
|
|
this->deviceId.toStdString() + |
|
|
|
this->deviceId.toStdString() + "|" + msg.content.key + |
|
|
|
http::client()->user_id().to_string() + |
|
|
|
"|" + this->transaction_id; |
|
|
|
http::client()->device_id() + this->transaction_id; |
|
|
|
} else { |
|
|
|
|
|
|
|
info = "MATRIX_KEY_VERIFICATION_SAS|" + |
|
|
|
std::vector<std::string> key_list; |
|
|
|
this->toClient.to_string() + "|" + |
|
|
|
std::string key_string; |
|
|
|
this->deviceId.toStdString() + "|" + msg.content.key + |
|
|
|
for (auto mac : msg.mac) { |
|
|
|
"|" + http::client()->user_id().to_string() + "|" + |
|
|
|
key_string += mac.first + ","; |
|
|
|
http::client()->device_id() + "|" + |
|
|
|
if (device_keys[mac.first] != "") { |
|
|
|
this->sas->public_key() + "|" + this->transaction_id; |
|
|
|
if (mac.second == |
|
|
|
} |
|
|
|
this->sas->calculate_mac(this->device_keys[mac.first], |
|
|
|
|
|
|
|
info + mac.first)) { |
|
|
|
if (this->method == DeviceVerificationFlow::Method::Emoji) { |
|
|
|
|
|
|
|
this->sasList = this->sas->generate_bytes_emoji(info); |
|
|
|
|
|
|
|
} else if (this->method == DeviceVerificationFlow::Method::Decimal) { |
|
|
|
|
|
|
|
this->sasList = this->sas->generate_bytes_decimal(info); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this->sender == false) { |
|
|
|
|
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
|
|
|
|
this->sendVerificationKey(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (this->commitment == |
|
|
|
|
|
|
|
mtx::crypto::bin2base64_unpadded(mtx::crypto::sha256( |
|
|
|
|
|
|
|
msg.content.key + this->canonical_json.dump()))) { |
|
|
|
|
|
|
|
emit this->verificationRequestAccepted(this->method); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this->cancelVerification( |
|
|
|
this->cancelVerification( |
|
|
|
DeviceVerificationFlow::Error::MismatchedCommitment); |
|
|
|
DeviceVerificationFlow::Error::KeyMismatch); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
key_string = key_string.substr(0, key_string.length() - 1); |
|
|
|
connect( |
|
|
|
if (msg.keys == this->sas->calculate_mac(key_string, info + "KEY_IDS")) { |
|
|
|
ChatPage::instance(), |
|
|
|
// uncomment this in future to be compatible with the
|
|
|
|
&ChatPage::recievedDeviceVerificationMac, |
|
|
|
// MSC2366 this->sendVerificationDone(); and remove the
|
|
|
|
this, |
|
|
|
// below line
|
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
if (this->isMacVerified == true) { |
|
|
|
auto msg = std::get<mtx::events::DeviceEvent<msgs::KeyVerificationMac>>(message); |
|
|
|
this->acceptDevice(); |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
} else |
|
|
|
std::string info = |
|
|
|
this->isMacVerified = true; |
|
|
|
"MATRIX_KEY_VERIFICATION_MAC" + this->toClient.to_string() + |
|
|
|
} else { |
|
|
|
this->deviceId.toStdString() + http::client()->user_id().to_string() + |
|
|
|
this->cancelVerification(DeviceVerificationFlow::Error::KeyMismatch); |
|
|
|
http::client()->device_id() + this->transaction_id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> key_list; |
|
|
|
|
|
|
|
std::string key_string; |
|
|
|
|
|
|
|
for (auto mac : msg.content.mac) { |
|
|
|
|
|
|
|
key_string += mac.first + ","; |
|
|
|
|
|
|
|
if (device_keys[mac.first] != "") { |
|
|
|
|
|
|
|
if (mac.second == |
|
|
|
|
|
|
|
this->sas->calculate_mac(this->device_keys[mac.first], |
|
|
|
|
|
|
|
info + mac.first)) { |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::KeyMismatch); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
key_string = key_string.substr(0, key_string.length() - 1); |
|
|
|
|
|
|
|
if (msg.content.keys == |
|
|
|
|
|
|
|
this->sas->calculate_mac(key_string, info + "KEY_IDS")) { |
|
|
|
|
|
|
|
// uncomment this in future to be compatible with the
|
|
|
|
|
|
|
|
// MSC2366 this->sendVerificationDone(); and remove the
|
|
|
|
|
|
|
|
// below line
|
|
|
|
|
|
|
|
if (this->isMacVerified == true) { |
|
|
|
|
|
|
|
this->acceptDevice(); |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
this->isMacVerified = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this->cancelVerification( |
|
|
|
|
|
|
|
DeviceVerificationFlow::Error::KeyMismatch); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect(ChatPage::instance(), |
|
|
|
connect(ChatPage::instance(), |
|
|
|
&ChatPage::recievedDeviceVerificationReady, |
|
|
|
&ChatPage::recievedDeviceVerificationReady, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
[this](const mtx::events::msg::KeyVerificationReady &msg) { |
|
|
|
auto msg = |
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationReady>>(message); |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
return; |
|
|
|
this->startVerificationRequest(); |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this->startVerificationRequest(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect(ChatPage::instance(), |
|
|
|
connect(ChatPage::instance(), |
|
|
|
&ChatPage::recievedDeviceVerificationDone, |
|
|
|
&ChatPage::recievedDeviceVerificationDone, |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::events::collections::DeviceEvents &message) { |
|
|
|
[this](const mtx::events::msg::KeyVerificationDone &msg) { |
|
|
|
auto msg = |
|
|
|
if (msg.transaction_id.has_value()) { |
|
|
|
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationDone>>(message); |
|
|
|
if (msg.transaction_id.value() != this->transaction_id) |
|
|
|
if (msg.content.transaction_id == this->transaction_id) { |
|
|
|
return; |
|
|
|
this->acceptDevice(); |
|
|
|
} else if (msg.relates_to.has_value()) { |
|
|
|
|
|
|
|
if (msg.relates_to.value().in_reply_to.event_id != |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id) |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this->acceptDevice(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
timeout->start(TIMEOUT); |
|
|
|
timeout->start(TIMEOUT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -294,18 +322,18 @@ void |
|
|
|
DeviceVerificationFlow::setSender(bool sender_) |
|
|
|
DeviceVerificationFlow::setSender(bool sender_) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this->sender = sender_; |
|
|
|
this->sender = sender_; |
|
|
|
if (this->sender == true) |
|
|
|
if (this->sender == true && this->type == DeviceVerificationFlow::Type::ToDevice) |
|
|
|
this->transaction_id = http::client()->generate_txn_id(); |
|
|
|
this->transaction_id = http::client()->generate_txn_id(); |
|
|
|
|
|
|
|
else if (this->sender == true && this->type == DeviceVerificationFlow::Type::RoomMsg) |
|
|
|
|
|
|
|
this->relation.in_reply_to.event_id = http::client()->generate_txn_id(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//! accepts a verification
|
|
|
|
//! accepts a verification
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::acceptVerificationRequest() |
|
|
|
DeviceVerificationFlow::acceptVerificationRequest() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationAccept> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationAccept req; |
|
|
|
mtx::events::msg::KeyVerificationAccept req; |
|
|
|
|
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.key_agreement_protocol = "curve25519-hkdf-sha256"; |
|
|
|
req.key_agreement_protocol = "curve25519-hkdf-sha256"; |
|
|
|
req.hash = "sha256"; |
|
|
|
req.hash = "sha256"; |
|
|
@ -317,126 +345,152 @@ DeviceVerificationFlow::acceptVerificationRequest() |
|
|
|
req.commitment = mtx::crypto::bin2base64_unpadded( |
|
|
|
req.commitment = mtx::crypto::bin2base64_unpadded( |
|
|
|
mtx::crypto::sha256(this->sas->public_key() + this->canonical_json.dump())); |
|
|
|
mtx::crypto::sha256(this->sas->public_key() + this->canonical_json.dump())); |
|
|
|
|
|
|
|
|
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationAccept> body; |
|
|
|
http::client() |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationAccept, |
|
|
|
|
|
|
|
mtx::events::EventType::KeyVerificationAccept>( |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
|
|
|
|
if (err) |
|
|
|
http::client() |
|
|
|
nhlog::net()->warn("failed to accept verification request: {} {}", |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationAccept, |
|
|
|
err->matrix_error.error, |
|
|
|
mtx::events::EventType::KeyVerificationAccept>( |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
}); |
|
|
|
if (err) |
|
|
|
|
|
|
|
nhlog::net()->warn( |
|
|
|
|
|
|
|
"failed to accept verification request: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! responds verification request
|
|
|
|
//! responds verification request
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::sendVerificationReady() |
|
|
|
DeviceVerificationFlow::sendVerificationReady() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationReady> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationReady req; |
|
|
|
mtx::events::msg::KeyVerificationReady req; |
|
|
|
|
|
|
|
|
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
req.methods = {mtx::events::msg::VerificationMethods::SASv1}; |
|
|
|
req.methods = {mtx::events::msg::VerificationMethods::SASv1}; |
|
|
|
|
|
|
|
|
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationReady> body; |
|
|
|
http::client() |
|
|
|
|
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationReady, |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
mtx::events::EventType::KeyVerificationReady>( |
|
|
|
|
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
http::client() |
|
|
|
if (err) |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationReady, |
|
|
|
nhlog::net()->warn("failed to send verification ready: {} {}", |
|
|
|
mtx::events::EventType::KeyVerificationReady>( |
|
|
|
err->matrix_error.error, |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
if (err) |
|
|
|
}); |
|
|
|
nhlog::net()->warn("failed to send verification ready: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! accepts a verification
|
|
|
|
//! accepts a verification
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::sendVerificationDone() |
|
|
|
DeviceVerificationFlow::sendVerificationDone() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationDone> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationDone req; |
|
|
|
mtx::events::msg::KeyVerificationDone req; |
|
|
|
|
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationDone> body; |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
|
|
|
|
http::client() |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationDone, |
|
|
|
|
|
|
|
mtx::events::EventType::KeyVerificationDone>( |
|
|
|
http::client() |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationDone, |
|
|
|
if (err) |
|
|
|
mtx::events::EventType::KeyVerificationDone>( |
|
|
|
nhlog::net()->warn("failed to send verification done: {} {}", |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
err->matrix_error.error, |
|
|
|
if (err) |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
nhlog::net()->warn("failed to send verification done: {} {}", |
|
|
|
}); |
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! starts the verification flow
|
|
|
|
//! starts the verification flow
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::startVerificationRequest() |
|
|
|
DeviceVerificationFlow::startVerificationRequest() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationStart> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationStart req; |
|
|
|
mtx::events::msg::KeyVerificationStart req; |
|
|
|
|
|
|
|
|
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.method = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.key_agreement_protocols = {"curve25519-hkdf-sha256"}; |
|
|
|
req.key_agreement_protocols = {"curve25519-hkdf-sha256"}; |
|
|
|
req.hashes = {"sha256"}; |
|
|
|
req.hashes = {"sha256"}; |
|
|
|
req.message_authentication_codes = {"hkdf-hmac-sha256", "hmac-sha256"}; |
|
|
|
req.message_authentication_codes = {"hkdf-hmac-sha256"}; |
|
|
|
req.short_authentication_string = {mtx::events::msg::SASMethods::Decimal, |
|
|
|
req.short_authentication_string = {mtx::events::msg::SASMethods::Decimal, |
|
|
|
mtx::events::msg::SASMethods::Emoji}; |
|
|
|
mtx::events::msg::SASMethods::Emoji}; |
|
|
|
|
|
|
|
|
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
this->canonical_json = nlohmann::json(req); |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationStart> body; |
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
http::client() |
|
|
|
this->canonical_json = nlohmann::json(req); |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationStart, |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
mtx::events::EventType::KeyVerificationStart>( |
|
|
|
|
|
|
|
this->transaction_id, body, [body](mtx::http::RequestErr err) { |
|
|
|
http::client() |
|
|
|
if (err) |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationStart, |
|
|
|
nhlog::net()->warn("failed to start verification request: {} {}", |
|
|
|
mtx::events::EventType::KeyVerificationStart>( |
|
|
|
err->matrix_error.error, |
|
|
|
this->transaction_id, body, [body](mtx::http::RequestErr err) { |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
if (err) |
|
|
|
}); |
|
|
|
nhlog::net()->warn( |
|
|
|
|
|
|
|
"failed to start verification request: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! sends a verification request
|
|
|
|
//! sends a verification request
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::sendVerificationRequest() |
|
|
|
DeviceVerificationFlow::sendVerificationRequest() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QDateTime CurrentTime = QDateTime::currentDateTimeUtc(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationRequest> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationRequest req; |
|
|
|
mtx::events::msg::KeyVerificationRequest req; |
|
|
|
|
|
|
|
|
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.from_device = http::client()->device_id(); |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
req.methods.resize(1); |
|
|
|
req.methods.resize(1); |
|
|
|
req.methods[0] = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.methods[0] = mtx::events::msg::VerificationMethods::SASv1; |
|
|
|
req.timestamp = (uint64_t)CurrentTime.toTime_t(); |
|
|
|
|
|
|
|
|
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
QDateTime CurrentTime = QDateTime::currentDateTimeUtc(); |
|
|
|
|
|
|
|
|
|
|
|
http::client() |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationRequest, |
|
|
|
req.timestamp = (uint64_t)CurrentTime.toTime_t(); |
|
|
|
mtx::events::EventType::KeyVerificationRequest>( |
|
|
|
|
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationRequest> body; |
|
|
|
if (err) |
|
|
|
|
|
|
|
nhlog::net()->warn("failed to send verification request: {} {}", |
|
|
|
body[this->toClient][this->deviceId.toStdString()] = req; |
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
http::client() |
|
|
|
}); |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationRequest, |
|
|
|
|
|
|
|
mtx::events::EventType::KeyVerificationRequest>( |
|
|
|
|
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
|
|
|
|
if (err) |
|
|
|
|
|
|
|
nhlog::net()->warn("failed to send verification request: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
std::cout << "lulz" << std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! cancels a verification flow
|
|
|
|
//! cancels a verification flow
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_code) |
|
|
|
DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_code) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationCancel> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationCancel req; |
|
|
|
mtx::events::msg::KeyVerificationCancel req; |
|
|
|
|
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
if (error_code == DeviceVerificationFlow::Error::UnknownMethod) { |
|
|
|
if (error_code == DeviceVerificationFlow::Error::UnknownMethod) { |
|
|
|
req.code = "m.unknown_method"; |
|
|
|
req.code = "m.unknown_method"; |
|
|
|
req.reason = "unknown method recieved"; |
|
|
|
req.reason = "unknown method recieved"; |
|
|
@ -457,65 +511,79 @@ DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_c |
|
|
|
req.reason = "user cancelled the verification"; |
|
|
|
req.reason = "user cancelled the verification"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit this->verificationCanceled(); |
|
|
|
emit this->verificationCanceled(); |
|
|
|
|
|
|
|
|
|
|
|
http::client() |
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationCancel, |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
mtx::events::EventType::KeyVerificationCancel>( |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationCancel> body; |
|
|
|
this->transaction_id, body, [this](mtx::http::RequestErr err) { |
|
|
|
|
|
|
|
if (err) |
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
nhlog::net()->warn("failed to cancel verification request: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
http::client() |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationCancel, |
|
|
|
auto verified_cache = cache::getVerifiedCache(this->userId.toStdString()); |
|
|
|
mtx::events::EventType::KeyVerificationCancel>( |
|
|
|
if (verified_cache.has_value()) { |
|
|
|
this->transaction_id, body, [this](mtx::http::RequestErr err) { |
|
|
|
verified_cache->device_blocked.push_back(this->deviceId.toStdString()); |
|
|
|
if (err) |
|
|
|
cache::setVerifiedCache(this->userId.toStdString(), |
|
|
|
nhlog::net()->warn( |
|
|
|
verified_cache.value()); |
|
|
|
"failed to cancel verification request: {} {}", |
|
|
|
} else { |
|
|
|
err->matrix_error.error, |
|
|
|
cache::setVerifiedCache( |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
this->userId.toStdString(), |
|
|
|
|
|
|
|
DeviceVerifiedCache{{}, {}, {this->deviceId.toStdString()}}); |
|
|
|
this->deleteLater(); |
|
|
|
} |
|
|
|
}); |
|
|
|
this->deleteLater(); |
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
}); |
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO : Handle Blocking user better
|
|
|
|
|
|
|
|
// auto verified_cache = cache::getVerifiedCache(this->userId.toStdString());
|
|
|
|
|
|
|
|
// if (verified_cache.has_value()) {
|
|
|
|
|
|
|
|
// verified_cache->device_blocked.push_back(this->deviceId.toStdString());
|
|
|
|
|
|
|
|
// cache::setVerifiedCache(this->userId.toStdString(),
|
|
|
|
|
|
|
|
// verified_cache.value());
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// cache::setVerifiedCache(
|
|
|
|
|
|
|
|
// this->userId.toStdString(),
|
|
|
|
|
|
|
|
// DeviceVerifiedCache{{}, {}, {this->deviceId.toStdString()}});
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
//! sends the verification key
|
|
|
|
//! sends the verification key
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::sendVerificationKey() |
|
|
|
DeviceVerificationFlow::sendVerificationKey() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationKey> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationKey req; |
|
|
|
mtx::events::msg::KeyVerificationKey req; |
|
|
|
|
|
|
|
|
|
|
|
req.key = this->sas->public_key(); |
|
|
|
req.key = this->sas->public_key(); |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
|
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationKey> body; |
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
http::client() |
|
|
|
|
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationKey, |
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
mtx::events::EventType::KeyVerificationKey>( |
|
|
|
|
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
http::client() |
|
|
|
if (err) |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationKey, |
|
|
|
nhlog::net()->warn("failed to send verification key: {} {}", |
|
|
|
mtx::events::EventType::KeyVerificationKey>( |
|
|
|
err->matrix_error.error, |
|
|
|
this->transaction_id, body, [](mtx::http::RequestErr err) { |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
if (err) |
|
|
|
}); |
|
|
|
nhlog::net()->warn("failed to send verification key: {} {}", |
|
|
|
|
|
|
|
err->matrix_error.error, |
|
|
|
|
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! sends the mac of the keys
|
|
|
|
//! sends the mac of the keys
|
|
|
|
void |
|
|
|
void |
|
|
|
DeviceVerificationFlow::sendVerificationMac() |
|
|
|
DeviceVerificationFlow::sendVerificationMac() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationMac> body; |
|
|
|
|
|
|
|
mtx::events::msg::KeyVerificationMac req; |
|
|
|
mtx::events::msg::KeyVerificationMac req; |
|
|
|
|
|
|
|
|
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + http::client()->user_id().to_string() + |
|
|
|
std::string info = "MATRIX_KEY_VERIFICATION_MAC" + http::client()->user_id().to_string() + |
|
|
|
http::client()->device_id() + this->toClient.to_string() + |
|
|
|
http::client()->device_id() + this->toClient.to_string() + |
|
|
|
this->deviceId.toStdString() + this->transaction_id; |
|
|
|
this->deviceId.toStdString() + this->transaction_id; |
|
|
|
|
|
|
|
|
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
|
|
|
|
//! this vector stores the type of the key and the key
|
|
|
|
//! this vector stores the type of the key and the key
|
|
|
|
std::vector<std::pair<std::string, std::string>> key_list; |
|
|
|
std::vector<std::pair<std::string, std::string>> key_list; |
|
|
|
key_list.push_back(make_pair("ed25519", olm::client()->identity_keys().ed25519)); |
|
|
|
key_list.push_back(make_pair("ed25519", olm::client()->identity_keys().ed25519)); |
|
|
@ -531,22 +599,28 @@ DeviceVerificationFlow::sendVerificationMac() |
|
|
|
req.keys = |
|
|
|
req.keys = |
|
|
|
this->sas->calculate_mac(req.keys.substr(0, req.keys.size() - 1), info + "KEY_IDS"); |
|
|
|
this->sas->calculate_mac(req.keys.substr(0, req.keys.size() - 1), info + "KEY_IDS"); |
|
|
|
|
|
|
|
|
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
if (this->type == DeviceVerificationFlow::Type::ToDevice) { |
|
|
|
|
|
|
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationMac> body; |
|
|
|
http::client() |
|
|
|
req.transaction_id = this->transaction_id; |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationMac, |
|
|
|
body[this->toClient][deviceId.toStdString()] = req; |
|
|
|
mtx::events::EventType::KeyVerificationMac>( |
|
|
|
|
|
|
|
this->transaction_id, body, [this](mtx::http::RequestErr err) { |
|
|
|
http::client() |
|
|
|
if (err) |
|
|
|
->send_to_device<mtx::events::msg::KeyVerificationMac, |
|
|
|
nhlog::net()->warn("failed to send verification MAC: {} {}", |
|
|
|
mtx::events::EventType::KeyVerificationMac>( |
|
|
|
err->matrix_error.error, |
|
|
|
this->transaction_id, body, [this](mtx::http::RequestErr err) { |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
if (err) |
|
|
|
|
|
|
|
nhlog::net()->warn("failed to send verification MAC: {} {}", |
|
|
|
if (this->isMacVerified == true) |
|
|
|
err->matrix_error.error, |
|
|
|
this->acceptDevice(); |
|
|
|
static_cast<int>(err->status_code)); |
|
|
|
else |
|
|
|
|
|
|
|
this->isMacVerified = true; |
|
|
|
if (this->isMacVerified == true) |
|
|
|
}); |
|
|
|
this->acceptDevice(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
this->isMacVerified = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { |
|
|
|
|
|
|
|
req.relates_to = this->relation; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//! Completes the verification flow
|
|
|
|
//! Completes the verification flow
|
|
|
|
void |
|
|
|
void |
|
|
@ -555,14 +629,11 @@ DeviceVerificationFlow::acceptDevice() |
|
|
|
auto verified_cache = cache::getVerifiedCache(this->userId.toStdString()); |
|
|
|
auto verified_cache = cache::getVerifiedCache(this->userId.toStdString()); |
|
|
|
if (verified_cache.has_value()) { |
|
|
|
if (verified_cache.has_value()) { |
|
|
|
verified_cache->device_verified.push_back(this->deviceId.toStdString()); |
|
|
|
verified_cache->device_verified.push_back(this->deviceId.toStdString()); |
|
|
|
for (auto it = verified_cache->device_blocked.begin(); |
|
|
|
verified_cache->device_blocked.erase( |
|
|
|
it != verified_cache->device_blocked.end(); |
|
|
|
std::remove(verified_cache->device_blocked.begin(), |
|
|
|
it++) { |
|
|
|
verified_cache->device_blocked.end(), |
|
|
|
if (*it == this->deviceId.toStdString()) { |
|
|
|
this->deviceId.toStdString()), |
|
|
|
verified_cache->device_blocked.erase(it); |
|
|
|
verified_cache->device_blocked.end()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cache::setVerifiedCache(this->userId.toStdString(), verified_cache.value()); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cache::setVerifiedCache( |
|
|
|
cache::setVerifiedCache( |
|
|
|
this->userId.toStdString(), |
|
|
|
this->userId.toStdString(), |
|
|
|