summary refs log tree commit diff
path: root/src/encryption/DeviceVerificationFlow.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-06-12 17:53:17 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-06-12 17:53:17 +0200
commit00740a7e65b1ba9571b58081361c6d50a5d5fc80 (patch)
tree792f9b0aa9f5fa90373446010c20ded680e7329b /src/encryption/DeviceVerificationFlow.cpp
parentFix crash on some systems because of reuseItems in completer (diff)
downloadnheko-00740a7e65b1ba9571b58081361c6d50a5d5fc80.tar.xz
Properly handle glare when verifying
Diffstat (limited to 'src/encryption/DeviceVerificationFlow.cpp')
-rw-r--r--src/encryption/DeviceVerificationFlow.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/encryption/DeviceVerificationFlow.cpp b/src/encryption/DeviceVerificationFlow.cpp

index 25ae8725..32473522 100644 --- a/src/encryption/DeviceVerificationFlow.cpp +++ b/src/encryption/DeviceVerificationFlow.cpp
@@ -157,7 +157,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, &ChatPage::receivedDeviceVerificationKey, this, [this](const mtx::events::msg::KeyVerificationKey &msg) { - nhlog::crypto()->info("verification: received key"); + nhlog::crypto()->info( + "verification: received key, sender {}, state {}", sender, state().toStdString()); if (msg.transaction_id.has_value()) { if (msg.transaction_id.value() != this->transaction_id) return; @@ -167,7 +168,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, } if (sender) { - if (state_ != WaitingForOtherToAccept) { + if (state_ != WaitingForOtherToAccept && state_ != WaitingForKeys) { this->cancelVerification(OutOfOrder); return; } @@ -567,12 +568,24 @@ DeviceVerificationFlow::handleStartMessage(const mtx::events::msg::KeyVerificati if (!sender) this->canonical_json = nlohmann::json(msg); else { - if (utils::localUser().toStdString() < this->toClient.to_string()) { + // resolve glare + if (utils::localUser().toStdString() > this->toClient.to_string() && + http::client()->device_id() > this->deviceId.toStdString()) { + // treat this as if the user with the smaller mxid and deviceid was the sender of + // "start" this->canonical_json = nlohmann::json(msg); + this->sender = false; + } + + if (msg.method != mtx::events::msg::VerificationMethods::SASv1) { + cancelVerification(DeviceVerificationFlow::Error::OutOfOrder); + return; } } - if (state_ != PromptStartVerification) + // If we didn't send "start", accept the verification (otherwise wait for the other side to + // accept + if (state_ != PromptStartVerification && !sender) this->acceptVerificationRequest(); } else { this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod);