Upgrade matrix-structs & mtxclient
This commit is contained in:
parent
651ac95719
commit
1d6746e4c9
4
deps/CMakeLists.txt
vendored
4
deps/CMakeLists.txt
vendored
@ -37,10 +37,10 @@ set(BOOST_SHA256
|
||||
5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9)
|
||||
|
||||
set(MATRIX_STRUCTS_URL https://github.com/mujx/matrix-structs)
|
||||
set(MATRIX_STRUCTS_TAG eeb7373729a1618e2b3838407863342b88b8a0de)
|
||||
set(MATRIX_STRUCTS_TAG c24cb9b38312dfa24b33413847e3238600c678cd)
|
||||
|
||||
set(MTXCLIENT_URL https://github.com/mujx/mtxclient)
|
||||
set(MTXCLIENT_TAG 96fd35e57d36511b10b7d30de7227c6cd2ffa386)
|
||||
set(MTXCLIENT_TAG 73491268f94ddeb606284836bb5f512d11b0e249)
|
||||
|
||||
set(OLM_URL https://git.matrix.org/git/olm.git)
|
||||
set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae)
|
||||
|
@ -10,26 +10,13 @@ constexpr auto OLM_ALGO = "m.olm.v1.curve25519-aes-sha2";
|
||||
|
||||
namespace olm {
|
||||
|
||||
struct OlmCipherContent
|
||||
{
|
||||
std::string body;
|
||||
uint8_t type;
|
||||
};
|
||||
|
||||
inline void
|
||||
from_json(const nlohmann::json &obj, OlmCipherContent &msg)
|
||||
{
|
||||
msg.body = obj.at("body");
|
||||
msg.type = obj.at("type");
|
||||
}
|
||||
|
||||
struct OlmMessage
|
||||
{
|
||||
std::string sender_key;
|
||||
std::string sender;
|
||||
|
||||
using RecipientKey = std::string;
|
||||
std::map<RecipientKey, OlmCipherContent> ciphertext;
|
||||
std::map<RecipientKey, mtx::events::msg::OlmCipherContent> ciphertext;
|
||||
};
|
||||
|
||||
inline void
|
||||
@ -43,8 +30,9 @@ from_json(const nlohmann::json &obj, OlmMessage &msg)
|
||||
|
||||
msg.sender = obj.at("sender");
|
||||
msg.sender_key = obj.at("content").at("sender_key");
|
||||
msg.ciphertext =
|
||||
obj.at("content").at("ciphertext").get<std::map<std::string, OlmCipherContent>>();
|
||||
msg.ciphertext = obj.at("content")
|
||||
.at("ciphertext")
|
||||
.get<std::map<std::string, mtx::events::msg::OlmCipherContent>>();
|
||||
}
|
||||
|
||||
mtx::crypto::OlmClient *
|
||||
@ -54,7 +42,8 @@ void
|
||||
handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
|
||||
|
||||
boost::optional<json>
|
||||
try_olm_decryption(const std::string &sender_key, const OlmCipherContent &content);
|
||||
try_olm_decryption(const std::string &sender_key,
|
||||
const mtx::events::msg::OlmCipherContent &content);
|
||||
|
||||
void
|
||||
handle_olm_message(const OlmMessage &msg);
|
||||
@ -68,7 +57,7 @@ create_inbound_megolm_session(const std::string &sender,
|
||||
void
|
||||
handle_pre_key_olm_message(const std::string &sender,
|
||||
const std::string &sender_key,
|
||||
const OlmCipherContent &content);
|
||||
const mtx::events::msg::OlmCipherContent &content);
|
||||
|
||||
mtx::events::msg::Encrypted
|
||||
encrypt_group_message(const std::string &room_id,
|
||||
|
38
src/Olm.cpp
38
src/Olm.cpp
@ -29,15 +29,31 @@ handle_to_device_messages(const std::vector<nlohmann::json> &msgs)
|
||||
nhlog::crypto()->info("received {} to_device messages", msgs.size());
|
||||
|
||||
for (const auto &msg : msgs) {
|
||||
try {
|
||||
OlmMessage olm_msg = msg;
|
||||
handle_olm_message(std::move(olm_msg));
|
||||
} catch (const nlohmann::json::exception &e) {
|
||||
nhlog::crypto()->warn(
|
||||
"parsing error for olm message: {} {}", e.what(), msg.dump(2));
|
||||
} catch (const std::invalid_argument &e) {
|
||||
nhlog::crypto()->warn(
|
||||
"validation error for olm message: {} {}", e.what(), msg.dump(2));
|
||||
if (msg.count("type") == 0) {
|
||||
nhlog::crypto()->warn("received message with no type field: {}",
|
||||
msg.dump(2));
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string msg_type = msg.at("type");
|
||||
|
||||
if (msg_type == to_string(mtx::events::EventType::RoomEncrypted)) {
|
||||
try {
|
||||
OlmMessage olm_msg = msg;
|
||||
handle_olm_message(std::move(olm_msg));
|
||||
} catch (const nlohmann::json::exception &e) {
|
||||
nhlog::crypto()->warn(
|
||||
"parsing error for olm message: {} {}", e.what(), msg.dump(2));
|
||||
} catch (const std::invalid_argument &e) {
|
||||
nhlog::crypto()->warn(
|
||||
"validation error for olm message: {} {}", e.what(), msg.dump(2));
|
||||
}
|
||||
|
||||
// TODO: Move this event type into matrix-structs
|
||||
} else if (msg_type == "m.room_key_request") {
|
||||
nhlog::crypto()->warn("handling key request event: {}", msg.dump(2));
|
||||
} else {
|
||||
nhlog::crypto()->warn("unhandled event: {}", msg.dump(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +95,7 @@ handle_olm_message(const OlmMessage &msg)
|
||||
void
|
||||
handle_pre_key_olm_message(const std::string &sender,
|
||||
const std::string &sender_key,
|
||||
const OlmCipherContent &content)
|
||||
const mtx::events::msg::OlmCipherContent &content)
|
||||
{
|
||||
nhlog::crypto()->info("opening olm session with {}", sender);
|
||||
|
||||
@ -155,7 +171,7 @@ encrypt_group_message(const std::string &room_id,
|
||||
}
|
||||
|
||||
boost::optional<json>
|
||||
try_olm_decryption(const std::string &sender_key, const OlmCipherContent &msg)
|
||||
try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg)
|
||||
{
|
||||
auto session_ids = cache::client()->getOlmSessions(sender_key);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user