summaryrefslogtreecommitdiffstats
path: root/src/encryption
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-02-27 06:41:48 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-02-27 06:43:45 +0100
commit8e20139079c44504bae30b9b9013f199ebdd788d (patch)
tree5f58070233d9a0911eae143e0bd0992a77c41eff /src/encryption
parent9f5b647fb38d1f362c557d707274597189942c48 (diff)
Allow properly editing pending encrypted messages
Diffstat (limited to 'src/encryption')
-rw-r--r--src/encryption/Olm.cpp38
-rw-r--r--src/encryption/Olm.h5
2 files changed, 30 insertions, 13 deletions
diff --git a/src/encryption/Olm.cpp b/src/encryption/Olm.cpp
index 5de18fa3..e6426658 100644
--- a/src/encryption/Olm.cpp
+++ b/src/encryption/Olm.cpp
@@ -471,6 +471,30 @@ handle_pre_key_olm_message(const std::string &sender,
}
mtx::events::msg::Encrypted
+encrypt_group_message_with_session(mtx::crypto::OutboundGroupSessionPtr &session,
+ const std::string &device_id,
+ nlohmann::json body)
+{
+ using namespace mtx::events;
+
+ // relations shouldn't be encrypted...
+ mtx::common::Relations relations = mtx::common::parse_relations(body["content"]);
+
+ auto payload = olm::client()->encrypt_group_message(session.get(), body.dump());
+
+ // Prepare the m.room.encrypted event.
+ msg::Encrypted data;
+ data.ciphertext = std::string((char *)payload.data(), payload.size());
+ data.sender_key = olm::client()->identity_keys().curve25519;
+ data.session_id = mtx::crypto::session_id(session.get());
+ data.device_id = device_id;
+ data.algorithm = MEGOLM_ALGO;
+ data.relations = relations;
+
+ return data;
+}
+
+mtx::events::msg::Encrypted
encrypt_group_message(const std::string &room_id, const std::string &device_id, nlohmann::json body)
{
using namespace mtx::events;
@@ -631,19 +655,7 @@ encrypt_group_message(const std::string &room_id, const std::string &device_id,
if (!sendSessionTo.empty())
olm::send_encrypted_to_device_messages(sendSessionTo, megolm_payload);
- // relations shouldn't be encrypted...
- mtx::common::Relations relations = mtx::common::parse_relations(body["content"]);
-
- auto payload = olm::client()->encrypt_group_message(session.get(), body.dump());
-
- // Prepare the m.room.encrypted event.
- msg::Encrypted data;
- data.ciphertext = std::string((char *)payload.data(), payload.size());
- data.sender_key = olm::client()->identity_keys().curve25519;
- data.session_id = mtx::crypto::session_id(session.get());
- data.device_id = device_id;
- data.algorithm = MEGOLM_ALGO;
- data.relations = relations;
+ auto data = encrypt_group_message_with_session(session, device_id, body);
group_session_data.message_index = olm_outbound_group_session_message_index(session.get());
nhlog::crypto()->debug("next message_index {}", group_session_data.message_index);
diff --git a/src/encryption/Olm.h b/src/encryption/Olm.h
index a6822b68..9d99bcf4 100644
--- a/src/encryption/Olm.h
+++ b/src/encryption/Olm.h
@@ -80,6 +80,11 @@ handle_pre_key_olm_message(const std::string &sender,
const mtx::events::msg::OlmCipherContent &content);
mtx::events::msg::Encrypted
+encrypt_group_message_with_session(mtx::crypto::OutboundGroupSessionPtr &session,
+ const std::string &device_id,
+ nlohmann::json body);
+
+mtx::events::msg::Encrypted
encrypt_group_message(const std::string &room_id,
const std::string &device_id,
nlohmann::json body);