Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112983
D69.1732362758.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D69.1732362758.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
@@ -289,9 +289,8 @@
std::string roomId = content.get().at("room_id");
std::string sessionId = content.get().at("session_id");
std::string sessionKey = content.get().at("session_key");
- std::string senderKey = e.originalJson().get().at("content").at("sender_key");
- auto k = KeyOfGroupSession{roomId, senderKey, sessionId};
+ auto k = KeyOfGroupSession{roomId, sessionId};
std::string ed25519Key = e.decryptedJson().get().at("keys").at(ed25519);
diff --git a/src/crypto/crypto-util.hpp b/src/crypto/crypto-util.hpp
--- a/src/crypto/crypto-util.hpp
+++ b/src/crypto/crypto-util.hpp
@@ -23,7 +23,6 @@
struct KeyOfGroupSession
{
std::string roomId;
- std::string senderKey;
std::string sessionId;
};
@@ -37,7 +36,6 @@
inline void from_json(const nlohmann::json &j, KeyOfGroupSession &k)
{
k.roomId = j.at("roomId");
- k.senderKey = j.at("senderKey");
k.sessionId = j.at("sessionId");
}
@@ -45,7 +43,6 @@
{
j = nlohmann::json::object({
{"roomId", k.roomId},
- {"senderKey", k.senderKey},
{"sessionId", k.sessionId},
});
}
@@ -53,7 +50,6 @@
inline bool operator==(KeyOfGroupSession a, KeyOfGroupSession b)
{
return a.roomId == b.roomId
- && a.senderKey == b.senderKey
&& a.sessionId == b.sessionId;
}
@@ -104,7 +100,6 @@
std::size_t operator()(const Kazv::KeyOfGroupSession & k) const noexcept {
std::size_t seed = 0;
boost::hash_combine(seed, k.roomId);
- boost::hash_combine(seed, k.senderKey);
boost::hash_combine(seed, k.sessionId);
return seed;
}
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -147,11 +147,10 @@
{
auto content = eventJson.at("content");
- auto senderKey = content.at("sender_key").get<std::string>();
auto sessionId = content.at("session_id").get<std::string>();
auto roomId = eventJson.at("room_id").get<std::string>();
- auto k = KeyOfGroupSession{roomId, senderKey, sessionId};
+ auto k = KeyOfGroupSession{roomId, sessionId};
if (inboundGroupSessions.find(k) == inboundGroupSessions.end()) {
return NotBut("We do not have the keys for this");
@@ -206,9 +205,8 @@
auto &session = outboundGroupSessions.at(roomId);
auto sessionId = session.sessionId();
auto sessionKey = session.sessionKey();
- auto senderKey = curve25519IdentityKey();
- auto k = KeyOfGroupSession{roomId, senderKey, sessionId};
+ auto k = KeyOfGroupSession{roomId, sessionId};
if (! createInboundGroupSession(k, sessionKey, ed25519IdentityKey())) {
kzo.client.warn() << "Create inbound group session from outbound group session failed. We may not be able to read our own messages." << std::endl;
@@ -449,11 +447,10 @@
{
auto content = eventJson.at("content");
- auto senderKey = content.at("sender_key").get<std::string>();
auto sessionId = content.at("session_id").get<std::string>();
auto roomId = eventJson.at("room_id").get<std::string>();
- auto k = KeyOfGroupSession{roomId, senderKey, sessionId};
+ auto k = KeyOfGroupSession{roomId, sessionId};
if (m_d->inboundGroupSessions.find(k) == m_d->inboundGroupSessions.end()) {
return NotBut("We do not have the keys for this");
@@ -531,6 +528,8 @@
return
json{
{"algorithm", CryptoConstants::megOlmAlgo},
+ // NOTE: we might stop sending sender_key in the future
+ // as per the Matrix spec
{"sender_key", curve25519IdentityKey()},
{"ciphertext", ciphertext},
{"session_id", session.sessionId()},
diff --git a/src/tests/crypto-test.cpp b/src/tests/crypto-test.cpp
--- a/src/tests/crypto-test.cpp
+++ b/src/tests/crypto-test.cpp
@@ -487,23 +487,74 @@
);
// encrypt to get the session id
- auto ev = crypto.encryptMegOlm(R"({
+ auto encryptedContent = crypto.encryptMegOlm(R"({
"content": {},
"type": "m.room.message",
"room_id": "!someroom:example.com"
})"_json);
- auto sessionId = ev["session_id"].template get<std::string>();
+ auto sessionId = encryptedContent["session_id"].template get<std::string>();
REQUIRE(crypto.hasInboundGroupSession(KeyOfGroupSession{
"!someroom:example.com",
- crypto.curve25519IdentityKey(),
sessionId,
}));
REQUIRE(!crypto.hasInboundGroupSession(KeyOfGroupSession{
"!someroom:example.com",
- crypto.curve25519IdentityKey(),
sessionId + "something something",
}));
}
+
+TEST_CASE("Crypto::decrypt(MegOlmEvent)", "[crypto][group-session]")
+{
+ Crypto crypto(RandomTag{}, genRandomData(Crypto::constructRandomSize()));
+
+ crypto.rotateMegOlmSessionWithRandom(
+ genRandomData(Crypto::rotateMegOlmSessionRandomSize()),
+ 0,
+ "!someroom:example.com"
+ );
+
+ auto plainText = R"({
+ "content": {"body": "something"},
+ "type": "m.room.message",
+ "room_id": "!someroom:example.com"
+ })"_json;
+ // encrypt to get the session id
+ auto encryptedContent = crypto.encryptMegOlm(plainText);
+
+ auto encryptedEvent = json{
+ {"event_id", "$some-event-id"},
+ {"origin_server_ts", 1719196953000},
+ {"content", encryptedContent},
+ {"type", "m.room.encrypted"},
+ {"room_id", "!someroom:example.com"},
+ };
+
+ auto res = crypto.decrypt(encryptedEvent);
+ auto decrypted = json::parse(res.value());
+ REQUIRE(decrypted == plainText);
+}
+
+TEST_CASE("KeyOfGroupSession serialization", "[crypto][group-session]")
+{
+ {
+ auto k = KeyOfGroupSession{"!someroom:example.com", "some-session-id"};
+ json j = k;
+ REQUIRE(j == json{
+ {"roomId", "!someroom:example.com"},
+ {"sessionId", "some-session-id"},
+ });
+ }
+
+ {
+ json j{
+ {"roomId", "!someroom:example.com"},
+ {"senderKey", "some-key"}, // legacy version
+ {"sessionId", "some-session-id"},
+ };
+ auto k = j.template get<KeyOfGroupSession>();
+ REQUIRE(k == KeyOfGroupSession{"!someroom:example.com", "some-session-id"});
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 3:52 AM (18 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39325
Default Alt Text
D69.1732362758.diff (6 KB)
Attached To
Mode
D69: Remove sender key from KeyOfGroupSession
Attached
Detach File
Event Timeline
Log In to Comment