Fix replies in encrypted rooms

The relation needs to be unencrypted...
This commit is contained in:
Nicolas Werner 2020-01-13 12:37:02 +01:00
parent 4ca8da9a89
commit 62f17dffbd
4 changed files with 24 additions and 12 deletions

4
deps/CMakeLists.txt vendored
View File

@ -46,10 +46,10 @@ set(BOOST_SHA256
set(
MTXCLIENT_URL
https://github.com/Nheko-Reborn/mtxclient/archive/6d2a02b6079c9d888c28cd24504618aaadb7fa97.zip
https://github.com/Nheko-Reborn/mtxclient/archive/84c6778cc367bca79755e73e77b2cc69950375b2.zip
)
set(MTXCLIENT_HASH
30811e076ee1fee22ba5d5d92c94a5425ff714a7ccb245ff4ac64fecb04dc539)
009fc9628cbdb94694eff3bba3fe54415e432385200c886bb1c1182bcf290c0a)
set(
TWEENY_URL
https://github.com/mobius3/tweeny/archive/b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf.tar.gz

View File

@ -159,15 +159,22 @@ handle_pre_key_olm_message(const std::string &sender,
}
mtx::events::msg::Encrypted
encrypt_group_message(const std::string &room_id,
const std::string &device_id,
const std::string &body)
encrypt_group_message(const std::string &room_id, const std::string &device_id, nlohmann::json body)
{
using namespace mtx::events;
// Always chech before for existence.
nhlog::crypto()->info("message body {}", body.dump());
// relations shouldn't be encrypted...
mtx::common::RelatesTo relation;
if (body["content"].count("m.relates_to") != 0) {
relation = body["content"]["m.relates_to"];
body["content"].erase("m.relates_to");
}
// Always check before for existence.
auto res = cache::getOutboundMegolmSession(room_id);
auto payload = olm::client()->encrypt_group_message(res.session, body);
auto payload = olm::client()->encrypt_group_message(res.session, body.dump());
// Prepare the m.room.encrypted event.
msg::Encrypted data;
@ -176,6 +183,7 @@ encrypt_group_message(const std::string &room_id,
data.session_id = res.data.session_id;
data.device_id = device_id;
data.algorithm = MEGOLM_ALGO;
data.relates_to = relation;
auto message_index = olm_outbound_group_session_message_index(res.session);
nhlog::crypto()->info("next message_index {}", message_index);

View File

@ -62,7 +62,7 @@ handle_pre_key_olm_message(const std::string &sender,
mtx::events::msg::Encrypted
encrypt_group_message(const std::string &room_id,
const std::string &device_id,
const std::string &body);
nlohmann::json body);
void
mark_keys_as_published();

View File

@ -734,6 +734,10 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
body["origin_server_ts"] = e.origin_server_ts;
body["unsigned"] = e.unsigned_data;
// relations are unencrypted in content...
if (json old_ev = e; old_ev["content"].count("m.relates_to") != 0)
body["content"]["m.relates_to"] = old_ev["content"]["m.relates_to"];
json event_array = json::array();
event_array.push_back(body);
@ -843,13 +847,13 @@ TimelineModel::sendEncryptedMessage(const std::string &txn_id, nlohmann::json co
using namespace mtx::events;
using namespace mtx::identifiers;
json doc{{"type", "m.room.message"}, {"content", content}, {"room_id", room_id}};
json doc = {{"type", "m.room.message"}, {"content", content}, {"room_id", room_id}};
try {
// Check if we have already an outbound megolm session then we can use.
if (cache::outboundMegolmSessionExists(room_id)) {
auto data = olm::encrypt_group_message(
room_id, http::client()->device_id(), doc.dump());
auto data =
olm::encrypt_group_message(room_id, http::client()->device_id(), doc);
http::client()->send_room_message<msg::Encrypted, EventType::RoomEncrypted>(
room_id,
@ -902,7 +906,7 @@ TimelineModel::sendEncryptedMessage(const std::string &txn_id, nlohmann::json co
std::make_shared<StateKeeper>([megolm_payload, room_id, doc, txn_id, this]() {
try {
auto data = olm::encrypt_group_message(
room_id, http::client()->device_id(), doc.dump());
room_id, http::client()->device_id(), doc);
http::client()
->send_room_message<msg::Encrypted, EventType::RoomEncrypted>(