From 99314c948edf1258829b0b6772664dc448625044 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 13 Apr 2021 23:42:18 +0200 Subject: [PATCH] Fix broken olm channels automatically --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.yaml | 2 +- src/Olm.cpp | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca66e167..b208756e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,7 +361,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG 808605299937203696a572c585a51509b1de28cf + GIT_TAG 5b7654c5d4512abc38806a0f44efc199029ceef4 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.yaml b/io.github.NhekoReborn.Nheko.yaml index f5191271..3db57d57 100644 --- a/io.github.NhekoReborn.Nheko.yaml +++ b/io.github.NhekoReborn.Nheko.yaml @@ -148,7 +148,7 @@ modules: buildsystem: cmake-ninja name: mtxclient sources: - - commit: 7194b4f058406b1c10d3741d83abcf2d8963d849 + - commit: 5b7654c5d4512abc38806a0f44efc199029ceef4 type: git url: https://github.com/Nheko-Reborn/mtxclient.git - config-opts: diff --git a/src/Olm.cpp b/src/Olm.cpp index 895afee4..95aae99a 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -359,6 +359,26 @@ handle_olm_message(const OlmMessage &msg) return; } } + + try { + auto otherUserDeviceKeys = cache::userKeys(msg.sender); + + if (!otherUserDeviceKeys) + return; + + std::map> targets; + for (auto [device_id, key] : otherUserDeviceKeys->device_keys) { + if (key.keys.at("curve25519:" + device_id) == msg.sender_key) + targets[msg.sender].push_back(device_id); + } + + send_encrypted_to_device_messages( + targets, mtx::events::DeviceEvent{}, true); + nhlog::crypto()->info( + "Recovering from broken olm channel with {}:{}", msg.sender, msg.sender_key); + } catch (std::exception &e) { + nhlog::crypto()->error("Failed to recover from broken olm sessions: {}", e.what()); + } } nlohmann::json