Upgrade matrix-structs & mtxclient

This commit is contained in:
Konstantinos Sideris 2018-06-27 21:24:25 +03:00
parent 651ac95719
commit 1d6746e4c9
3 changed files with 36 additions and 31 deletions

4
deps/CMakeLists.txt vendored
View File

@ -37,10 +37,10 @@ set(BOOST_SHA256
5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9) 5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9)
set(MATRIX_STRUCTS_URL https://github.com/mujx/matrix-structs) 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_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_URL https://git.matrix.org/git/olm.git)
set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae) set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae)

View File

@ -10,26 +10,13 @@ constexpr auto OLM_ALGO = "m.olm.v1.curve25519-aes-sha2";
namespace olm { 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 struct OlmMessage
{ {
std::string sender_key; std::string sender_key;
std::string sender; std::string sender;
using RecipientKey = std::string; using RecipientKey = std::string;
std::map<RecipientKey, OlmCipherContent> ciphertext; std::map<RecipientKey, mtx::events::msg::OlmCipherContent> ciphertext;
}; };
inline void inline void
@ -43,8 +30,9 @@ from_json(const nlohmann::json &obj, OlmMessage &msg)
msg.sender = obj.at("sender"); msg.sender = obj.at("sender");
msg.sender_key = obj.at("content").at("sender_key"); msg.sender_key = obj.at("content").at("sender_key");
msg.ciphertext = msg.ciphertext = obj.at("content")
obj.at("content").at("ciphertext").get<std::map<std::string, OlmCipherContent>>(); .at("ciphertext")
.get<std::map<std::string, mtx::events::msg::OlmCipherContent>>();
} }
mtx::crypto::OlmClient * mtx::crypto::OlmClient *
@ -54,7 +42,8 @@ void
handle_to_device_messages(const std::vector<nlohmann::json> &msgs); handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
boost::optional<json> 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 void
handle_olm_message(const OlmMessage &msg); handle_olm_message(const OlmMessage &msg);
@ -68,7 +57,7 @@ create_inbound_megolm_session(const std::string &sender,
void void
handle_pre_key_olm_message(const std::string &sender, handle_pre_key_olm_message(const std::string &sender,
const std::string &sender_key, const std::string &sender_key,
const OlmCipherContent &content); const mtx::events::msg::OlmCipherContent &content);
mtx::events::msg::Encrypted mtx::events::msg::Encrypted
encrypt_group_message(const std::string &room_id, encrypt_group_message(const std::string &room_id,

View File

@ -29,15 +29,31 @@ handle_to_device_messages(const std::vector<nlohmann::json> &msgs)
nhlog::crypto()->info("received {} to_device messages", msgs.size()); nhlog::crypto()->info("received {} to_device messages", msgs.size());
for (const auto &msg : msgs) { for (const auto &msg : msgs) {
try { if (msg.count("type") == 0) {
OlmMessage olm_msg = msg; nhlog::crypto()->warn("received message with no type field: {}",
handle_olm_message(std::move(olm_msg)); msg.dump(2));
} catch (const nlohmann::json::exception &e) { continue;
nhlog::crypto()->warn( }
"parsing error for olm message: {} {}", e.what(), msg.dump(2));
} catch (const std::invalid_argument &e) { std::string msg_type = msg.at("type");
nhlog::crypto()->warn(
"validation error for olm message: {} {}", e.what(), msg.dump(2)); 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 void
handle_pre_key_olm_message(const std::string &sender, handle_pre_key_olm_message(const std::string &sender,
const std::string &sender_key, const std::string &sender_key,
const OlmCipherContent &content) const mtx::events::msg::OlmCipherContent &content)
{ {
nhlog::crypto()->info("opening olm session with {}", sender); nhlog::crypto()->info("opening olm session with {}", sender);
@ -155,7 +171,7 @@ encrypt_group_message(const std::string &room_id,
} }
boost::optional<json> 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); auto session_ids = cache::client()->getOlmSessions(sender_key);