|
|
@ -92,7 +92,7 @@ handle_olm_message(const OlmMessage &msg) |
|
|
|
auto payload = try_olm_decryption(msg.sender_key, cipher.second); |
|
|
|
auto payload = try_olm_decryption(msg.sender_key, cipher.second); |
|
|
|
|
|
|
|
|
|
|
|
if (!payload.is_null()) { |
|
|
|
if (!payload.is_null()) { |
|
|
|
nhlog::crypto()->info("decrypted olm payload: {}", payload.dump(2)); |
|
|
|
nhlog::crypto()->debug("decrypted olm payload: {}", payload.dump(2)); |
|
|
|
create_inbound_megolm_session(msg.sender, msg.sender_key, payload); |
|
|
|
create_inbound_megolm_session(msg.sender, msg.sender_key, payload); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -146,7 +146,7 @@ handle_pre_key_olm_message(const std::string &sender, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto plaintext = json::parse(std::string((char *)output.data(), output.size())); |
|
|
|
auto plaintext = json::parse(std::string((char *)output.data(), output.size())); |
|
|
|
nhlog::crypto()->info("decrypted message: \n {}", plaintext.dump(2)); |
|
|
|
nhlog::crypto()->debug("decrypted message: \n {}", plaintext.dump(2)); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
cache::client()->saveOlmSession(sender_key, std::move(inbound_session)); |
|
|
|
cache::client()->saveOlmSession(sender_key, std::move(inbound_session)); |
|
|
@ -206,11 +206,11 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip |
|
|
|
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body); |
|
|
|
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body); |
|
|
|
cache::client()->saveOlmSession(id, std::move(session.value())); |
|
|
|
cache::client()->saveOlmSession(id, std::move(session.value())); |
|
|
|
} catch (const mtx::crypto::olm_exception &e) { |
|
|
|
} catch (const mtx::crypto::olm_exception &e) { |
|
|
|
nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}", |
|
|
|
nhlog::crypto()->debug("failed to decrypt olm message ({}, {}) with {}: {}", |
|
|
|
msg.type, |
|
|
|
msg.type, |
|
|
|
sender_key, |
|
|
|
sender_key, |
|
|
|
id, |
|
|
|
id, |
|
|
|
e.what()); |
|
|
|
e.what()); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} catch (const lmdb::error &e) { |
|
|
|
} catch (const lmdb::error &e) { |
|
|
|
nhlog::crypto()->critical("failed to save session: {}", e.what()); |
|
|
|
nhlog::crypto()->critical("failed to save session: {}", e.what()); |
|
|
@ -339,19 +339,19 @@ void |
|
|
|
handle_key_request_message(const mtx::events::msg::KeyRequest &req) |
|
|
|
handle_key_request_message(const mtx::events::msg::KeyRequest &req) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (req.algorithm != MEGOLM_ALGO) { |
|
|
|
if (req.algorithm != MEGOLM_ALGO) { |
|
|
|
nhlog::crypto()->info("ignoring key request {} with invalid algorithm: {}", |
|
|
|
nhlog::crypto()->debug("ignoring key request {} with invalid algorithm: {}", |
|
|
|
req.request_id, |
|
|
|
req.request_id, |
|
|
|
req.algorithm); |
|
|
|
req.algorithm); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if we were the sender of the session being requested.
|
|
|
|
// Check if we were the sender of the session being requested.
|
|
|
|
if (req.sender_key != olm::client()->identity_keys().curve25519) { |
|
|
|
if (req.sender_key != olm::client()->identity_keys().curve25519) { |
|
|
|
nhlog::crypto()->info("ignoring key request {} because we were not the sender: " |
|
|
|
nhlog::crypto()->debug("ignoring key request {} because we were not the sender: " |
|
|
|
"\nrequested({}) ours({})", |
|
|
|
"\nrequested({}) ours({})", |
|
|
|
req.request_id, |
|
|
|
req.request_id, |
|
|
|
req.sender_key, |
|
|
|
req.sender_key, |
|
|
|
olm::client()->identity_keys().curve25519); |
|
|
|
olm::client()->identity_keys().curve25519); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -380,7 +380,7 @@ handle_key_request_message(const mtx::events::msg::KeyRequest &req) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!utils::respondsToKeyRequests(req.room_id)) { |
|
|
|
if (!utils::respondsToKeyRequests(req.room_id)) { |
|
|
|
nhlog::crypto()->info("ignoring all key requests for room {}", req.room_id); |
|
|
|
nhlog::crypto()->debug("ignoring all key requests for room {}", req.room_id); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -433,7 +433,7 @@ send_megolm_key_to_device(const std::string &user_id, |
|
|
|
|
|
|
|
|
|
|
|
if ((device_keys.find(curveKey) == device_keys.end()) || |
|
|
|
if ((device_keys.find(curveKey) == device_keys.end()) || |
|
|
|
(device_keys.find(edKey) == device_keys.end())) { |
|
|
|
(device_keys.find(edKey) == device_keys.end())) { |
|
|
|
nhlog::net()->info("ignoring malformed keys for device {}", device_id); |
|
|
|
nhlog::net()->debug("ignoring malformed keys for device {}", device_id); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -499,7 +499,7 @@ send_megolm_key_to_device(const std::string &user_id, |
|
|
|
body["messages"][user_id] = json::object(); |
|
|
|
body["messages"][user_id] = json::object(); |
|
|
|
|
|
|
|
|
|
|
|
auto device = retrieved_devices.begin()->second; |
|
|
|
auto device = retrieved_devices.begin()->second; |
|
|
|
nhlog::net()->info("{} : \n {}", device_id, device.dump(2)); |
|
|
|
nhlog::net()->debug("{} : \n {}", device_id, device.dump(2)); |
|
|
|
|
|
|
|
|
|
|
|
json device_msg; |
|
|
|
json device_msg; |
|
|
|
|
|
|
|
|
|
|
|