From 7bc57f76f77ac282afb78c3e4d02dd647dc0d449 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 23 Jan 2021 20:08:59 +0100 Subject: [PATCH] Request unknown message indices --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.json | 3 +-- src/Olm.cpp | 3 +++ src/Olm.h | 4 +++- src/timeline/EventStore.cpp | 21 +++++++++++++++------ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 319d9cc8..0e707977 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,7 +355,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG v0.4.0 + GIT_TAG 1e97d3195d366a15a086ca451d082d59972105ba ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.json b/io.github.NhekoReborn.Nheko.json index 37958470..fb921f65 100644 --- a/io.github.NhekoReborn.Nheko.json +++ b/io.github.NhekoReborn.Nheko.json @@ -220,8 +220,7 @@ "name": "mtxclient", "sources": [ { - "commit": "2d6e3f79917ce2065a54ca32e6a9f9d42c0b6347", - "tag": "v0.4.0", + "commit": "1e97d3195d366a15a086ca451d082d59972105ba", "type": "git", "url": "https://github.com/Nheko-Reborn/mtxclient.git" } diff --git a/src/Olm.cpp b/src/Olm.cpp index 028095a6..4ccf8ab9 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -890,12 +890,15 @@ decryptEvent(const MegolmSessionIndex &index, std::string msg_str; try { auto session = cache::client()->getInboundMegolmSession(index); + auto res = olm::client()->decrypt_group_message(session.get(), event.content.ciphertext); msg_str = std::string((char *)res.data.data(), res.data.size()); } catch (const lmdb::error &e) { return {DecryptionErrorCode::DbError, e.what(), std::nullopt}; } catch (const mtx::crypto::olm_exception &e) { + if (e.error_code() == mtx::crypto::OlmErrorCode::UNKNOWN_MESSAGE_INDEX) + return {DecryptionErrorCode::MissingSessionIndex, e.what(), std::nullopt}; return {DecryptionErrorCode::DecryptionFailed, e.what(), std::nullopt}; } diff --git a/src/Olm.h b/src/Olm.h index 78c1e641..45b6b890 100644 --- a/src/Olm.h +++ b/src/Olm.h @@ -17,7 +17,9 @@ enum class DecryptionErrorCode { MissingSession, // Session was not found, retrieve from backup or request from other devices // and try again - DbError, // DB read failed + MissingSessionIndex, // Session was found, but it does not reach back enough to this index, + // retrieve from backup or request from other devices and try again + DbError, // DB read failed DecryptionFailed, // libolm error ParsingFailed, // Failed to parse the actual event ReplayAttack, // Megolm index reused diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index 41001081..d7629456 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -543,12 +543,21 @@ EventStore::decryptEvent(const IdIndex &idx, if (decryptionResult.error) { switch (*decryptionResult.error) { - case olm::DecryptionErrorCode::MissingSession: { - dummy.content.body = - tr("-- Encrypted Event (No keys found for decryption) --", - "Placeholder, when the message was not decrypted yet or can't be " - "decrypted.") - .toStdString(); + case olm::DecryptionErrorCode::MissingSession: + case olm::DecryptionErrorCode::MissingSessionIndex: { + if (decryptionResult.error == olm::DecryptionErrorCode::MissingSession) + dummy.content.body = + tr("-- Encrypted Event (No keys found for decryption) --", + "Placeholder, when the message was not decrypted yet or can't " + "be " + "decrypted.") + .toStdString(); + else + dummy.content.body = + tr("-- Encrypted Event (Key not valid for this index) --", + "Placeholder, when the message can't be decrypted with this " + "key since it is not valid for this index ") + .toStdString(); nhlog::crypto()->info("Could not find inbound megolm session ({}, {}, {})", index.room_id, index.session_id,