Page MenuHomePhorge

D337.1786197424.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D337.1786197424.diff

diff --git a/src/client/actions/encryption.cpp b/src/client/actions/encryption.cpp
--- a/src/client/actions/encryption.cpp
+++ b/src/client/actions/encryption.cpp
@@ -414,11 +414,6 @@
immer::map<std::string, immer::array<std::string>> deviceKeys;
auto encryptedUsers = m.deviceLists.outdatedUsers();
- if (encryptedUsers.empty()) {
- kzo.client.dbg() << "Keys are up-to-date." << std::endl;
- return std::nullopt;
- }
-
kzo.client.dbg() << "We need to query keys for: " << std::endl;
for (auto userId: encryptedUsers) {
kzo.client.dbg() << userId << std::endl;
@@ -426,6 +421,23 @@
}
kzo.client.dbg() << "^" << std::endl;
+ for (const auto &msg: m.toDevice) {
+ // If message cannot be verified because device key is unknown, try to fetch corresponding device key
+ if (msg.encrypted()
+ && !msg.decrypted()
+ && msg.decryptedJson().get().contains("/content/moe.kazv.mxc.errcode"_json_pointer)
+ && msg.decryptedJson().get().at("/content/moe.kazv.mxc.errcode"_json_pointer) == "MOE.KAZV.MXC_DEVICE_KEY_UNKNOWN"
+ // do not fetch if the (invalid) sender device keys is embedded
+ && !msg.decryptedJson().get().contains("/content/moe.kazv.mxc.raw/sender_device_keys"_json_pointer)) {
+ // the event does not include the device id that it is sent from, so query all devices for the sender
+ deviceKeys = std::move(deviceKeys).set(msg.sender(), {});
+ }
+ }
+
+ if (deviceKeys.empty()) {
+ return std::nullopt;
+ }
+
auto job = m.job<QueryKeysJob>()
.make(deviceKeys,
std::nullopt, // timeout
diff --git a/src/tests/client/encryption-test.cpp b/src/tests/client/encryption-test.cpp
--- a/src/tests/client/encryption-test.cpp
+++ b/src/tests/client/encryption-test.cpp
@@ -445,7 +445,7 @@
}
}
-TEST_CASE("tryDecryptEvents() rejects Olm-encrypted to-device event from unknown device", "[client][encryption][olm]")
+TEST_CASE("tryDecryptEvents() rejects Olm-encrypted to-device event from unknown device, which causes QueryKeysAction to query relevant keys", "[client][encryption][olm]")
{
// Bob: the current user, with crypto enabled
auto bobCrypto = makeCrypto();
@@ -524,6 +524,17 @@
REQUIRE(decryptedContent.contains("moe.kazv.mxc.error"));
REQUIRE(decryptedContent["moe.kazv.mxc.error"] == "device key unknown");
REQUIRE(decryptedContent["moe.kazv.mxc.errcode"] == "MOE.KAZV.MXC_DEVICE_KEY_UNKNOWN");
+
+ REQUIRE(next.deviceLists.outdatedUsers().empty());
+ std::tie(next, std::ignore) = ClientModel::update(next, QueryKeysAction{/* isInitialSync = */ false});
+ assert1Job(next);
+ auto job = next.nextJobs.at(0);
+ REQUIRE(job.jobId() == "QueryKeys");
+ auto jsonBody = json::parse(std::get<BytesBody>(job.requestBody()));
+ auto expected = json{
+ {"@alice:example.com", json::array()},
+ };
+ REQUIRE(jsonBody["device_keys"] == expected);
}
TEST_CASE("decryptEvent() handles Olm-encrypted to-device event", "[client][encryption][olm]")

File Metadata

Mime Type
text/plain
Expires
Sat, Aug 8, 6:57 AM (16 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1724304
Default Alt Text
D337.1786197424.diff (3 KB)

Event Timeline