mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Fix keys not being reshared to the same devices, that already got them, if the message got lost
This commit is contained in:
parent
20c1ca2aae
commit
1936749ff5
4 changed files with 49 additions and 24 deletions
|
@ -361,13 +361,13 @@ if(USE_BUNDLED_MTXCLIENT)
|
|||
FetchContent_Declare(
|
||||
MatrixClient
|
||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||
GIT_TAG v0.5.0
|
||||
GIT_TAG v0.5.1
|
||||
)
|
||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||
FetchContent_MakeAvailable(MatrixClient)
|
||||
else()
|
||||
find_package(MatrixClient 0.4.1 REQUIRED)
|
||||
find_package(MatrixClient 0.5.1 REQUIRED)
|
||||
endif()
|
||||
if(USE_BUNDLED_OLM)
|
||||
include(FetchContent)
|
||||
|
|
|
@ -148,7 +148,8 @@ modules:
|
|||
buildsystem: cmake-ninja
|
||||
name: mtxclient
|
||||
sources:
|
||||
- commit: fe3df73f71d921b6927f09b8ef58feba03408414
|
||||
- commit: b19f1dc7e422f1bb217f02487567fc09e25e7d2b
|
||||
tag: v0.5.1
|
||||
type: git
|
||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||
- config-opts:
|
||||
|
|
|
@ -334,7 +334,7 @@ Cache::exportSessionKeys()
|
|||
exported.room_id = index.room_id;
|
||||
exported.sender_key = index.sender_key;
|
||||
exported.session_id = index.session_id;
|
||||
exported.session_key = export_session(saved_session.get());
|
||||
exported.session_key = export_session(saved_session.get(), -1);
|
||||
|
||||
keys.sessions.push_back(exported);
|
||||
}
|
||||
|
|
40
src/Olm.cpp
40
src/Olm.cpp
|
@ -823,10 +823,10 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
|||
}
|
||||
|
||||
// Check if we have the keys for the requested session.
|
||||
if (!cache::outboundMegolmSessionExists(req.content.room_id)) {
|
||||
auto outboundSession = cache::getOutboundMegolmSession(req.content.room_id);
|
||||
if (!outboundSession.session) {
|
||||
nhlog::crypto()->warn("requested session not found in room: {}",
|
||||
req.content.room_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -854,7 +854,9 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
|||
auto verificationStatus = cache::verificationStatus(req.sender);
|
||||
bool verifiedDevice = false;
|
||||
if (verificationStatus &&
|
||||
ChatPage::instance()->userSettings()->shareKeysWithTrustedUsers()) {
|
||||
// Share keys, if the option to share with trusted users is enabled or with yourself
|
||||
(ChatPage::instance()->userSettings()->shareKeysWithTrustedUsers() ||
|
||||
req.sender == http::client()->user_id().to_string())) {
|
||||
for (const auto &dev : verificationStatus->verified_devices) {
|
||||
if (dev == req.content.requesting_device_id) {
|
||||
verifiedDevice = true;
|
||||
|
@ -864,13 +866,31 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
|||
}
|
||||
}
|
||||
|
||||
if (!utils::respondsToKeyRequests(req.content.room_id) && !verifiedDevice) {
|
||||
nhlog::crypto()->debug("ignoring all key requests for room {}",
|
||||
req.content.room_id);
|
||||
bool shouldSeeKeys = false;
|
||||
uint64_t minimumIndex = -1;
|
||||
if (outboundSession.data.currently.keys.count(req.sender)) {
|
||||
if (outboundSession.data.currently.keys.at(req.sender)
|
||||
.devices.count(req.content.requesting_device_id)) {
|
||||
shouldSeeKeys = true;
|
||||
minimumIndex = outboundSession.data.currently.keys.at(req.sender)
|
||||
.devices.at(req.content.requesting_device_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!verifiedDevice && !shouldSeeKeys &&
|
||||
!utils::respondsToKeyRequests(req.content.room_id)) {
|
||||
nhlog::crypto()->debug("ignoring key request for room {}", req.content.room_id);
|
||||
return;
|
||||
}
|
||||
|
||||
auto session_key = mtx::crypto::export_session(session.get());
|
||||
if (verifiedDevice || utils::respondsToKeyRequests(req.content.room_id)) {
|
||||
// share the minimum index we have
|
||||
minimumIndex = -1;
|
||||
}
|
||||
|
||||
try {
|
||||
auto session_key = mtx::crypto::export_session(session.get(), minimumIndex);
|
||||
|
||||
//
|
||||
// Prepare the m.room_key event.
|
||||
//
|
||||
|
@ -885,7 +905,11 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
|||
forward_key.sender_claimed_ed25519_key = olm::client()->identity_keys().ed25519;
|
||||
forward_key.forwarding_curve25519_key_chain = {};
|
||||
|
||||
send_megolm_key_to_device(req.sender, req.content.requesting_device_id, forward_key);
|
||||
send_megolm_key_to_device(
|
||||
req.sender, req.content.requesting_device_id, forward_key);
|
||||
} catch (std::exception &e) {
|
||||
nhlog::crypto()->error("Failed to forward session key: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue