Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112856
D70.1732355845.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D70.1732355845.diff
View Options
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
@@ -173,21 +173,21 @@
bool valid = true;
try {
- std::string senderCurve25519Key = e.originalJson().get()
- .at("content").at("sender_key");
+ std::string algo = e.originalJson().get().at("content").at("algorithm");
+ if (algo == olmAlgo) {
+ std::string senderCurve25519Key = e.originalJson().get()
+ .at("content").at("sender_key");
- auto deviceInfoOpt = m.deviceLists.findByCurve25519Key(e.sender(), senderCurve25519Key);
+ auto deviceInfoOpt = m.deviceLists.findByCurve25519Key(e.sender(), senderCurve25519Key);
- if (! deviceInfoOpt) {
- kzo.client.dbg() << "Device key " << senderCurve25519Key
- << " unknown, thus invalid" << std::endl;
- valid = false;
- }
+ if (! deviceInfoOpt) {
+ kzo.client.dbg() << "Device key " << senderCurve25519Key
+ << " unknown, thus invalid" << std::endl;
+ valid = false;
+ }
- auto deviceInfo = deviceInfoOpt.value();
+ auto deviceInfo = deviceInfoOpt.value();
- std::string algo = e.originalJson().get().at("content").at("algorithm");
- if (algo == olmAlgo) {
if (! (plainJson.at("sender") == e.sender())) {
kzo.client.dbg() << "Sender does not match, thus invalid" << std::endl;
valid = false;
@@ -211,20 +211,6 @@
kzo.client.dbg() << "Room id does not match, thus invalid" << std::endl;
valid = false;
}
- if (e.originalJson().get().at("content").at("device_id").get<std::string>()
- != deviceInfo.deviceId) {
- kzo.client.dbg() << "Device id does not match, thus invalid" << std::endl;
- valid = false;
- }
- auto actualEd25519Key = m.constCrypto().getInboundGroupSessionEd25519KeyFromEvent(e.originalJson().get());
- if ((! actualEd25519Key)
- || deviceInfo.ed25519Key != actualEd25519Key.value()) {
- kzo.client.dbg() << "sender ed25519 key does not match, thus invalid" << std::endl;
- kzo.client.dbg() << "From group session: "
- << (actualEd25519Key ? actualEd25519Key.value() : "<none>") << std::endl;
- kzo.client.dbg() << "From device info: " << deviceInfo.ed25519Key << std::endl;
- valid = false;
- }
} else {
kzo.client.dbg() << "Unknown algorithm, thus invalid" << std::endl;
valid = false;
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
@@ -139,3 +139,51 @@
REQUIRE(res["@receiver:example.com"]["device2"].originalJson().get().at("content").at("ciphertext").size() == 1);
REQUIRE(res["@receiver:example.com"]["device2"].originalJson().get().at("content").at("ciphertext").contains(receiver2.curve25519IdentityKey()));
}
+
+TEST_CASE("tryDecryptEvents()", "[client][encryption]")
+{
+ auto roomId = "!someroom:example.com";
+ auto room = makeRoom(
+ withRoomEncrypted(true)
+ | withRoomId(roomId)
+ );
+ auto client = makeClient(
+ withCrypto(makeCrypto())
+ | withRoom(room)
+ );
+
+ auto plainText = makeEvent();
+ auto [encrypted, sessionId] = client.megOlmEncrypt(plainText, roomId, 1719196953000,
+ genRandomData(EncryptMegOlmEventAction::maxRandomSize()));
+ auto plainText2 = makeEvent();
+ // verify that we can decrypt events without sender_key or device_id
+ auto [encrypted2, sessionId2] = client.megOlmEncrypt(plainText2, roomId, 1719196953000,
+ genRandomData(EncryptMegOlmEventAction::maxRandomSize()));
+ auto j = encrypted2.originalJson().get();
+ j["content"].erase("sender_key");
+ j["content"].erase("device_id");
+ encrypted2 = Event(j);
+
+ auto events = EventList{
+ makeEvent(),
+ makeEvent(),
+ encrypted,
+ encrypted2,
+ };
+
+ withRoomTimeline(events)(room);
+ withRoom(room)(client);
+
+ auto nextClient = tryDecryptEvents(client);
+ auto decryptedEvent = nextClient.roomList.rooms[roomId].messages[encrypted.id()];
+ REQUIRE(decryptedEvent.encrypted());
+ REQUIRE(decryptedEvent.decrypted());
+ REQUIRE(decryptedEvent.type() == plainText.type());
+ REQUIRE(decryptedEvent.content() == plainText.content());
+
+ auto decryptedEvent2 = nextClient.roomList.rooms[roomId].messages[encrypted2.id()];
+ REQUIRE(decryptedEvent2.encrypted());
+ REQUIRE(decryptedEvent2.decrypted());
+ REQUIRE(decryptedEvent2.type() == plainText2.type());
+ REQUIRE(decryptedEvent2.content() == plainText2.content());
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 1:57 AM (17 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39253
Default Alt Text
D70.1732355845.diff (5 KB)
Attached To
Mode
D70: Do not verify sender key and sender device id for megolm events
Attached
Detach File
Event Timeline
Log In to Comment