From 6490ee3a34c914a4c59125d947afd5b7fc01810d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 6 Sep 2021 00:32:09 +0200 Subject: [PATCH] Add workaround for broken key counts --- src/ChatPage.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 5d2117cc..c5c27964 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -1001,6 +1001,23 @@ ChatPage::ensureOneTimeKeyCount(const std::map &counts) // mark as published anyway, otherwise we may end up in a loop. olm::mark_keys_as_published(); }); + } else if (count->second > 2 * MAX_ONETIME_KEYS) { + nhlog::crypto()->warn("too many one-time keys, deleting 1"); + mtx::requests::ClaimKeys req; + req.one_time_keys[http::client()->user_id().to_string()] + [http::client()->device_id()] = + std::string(mtx::crypto::SIGNED_CURVE25519); + http::client()->claim_keys( + req, [](const mtx::responses::ClaimKeys &, mtx::http::RequestErr err) { + if (err) + nhlog::crypto()->warn( + "failed to clear 1 one-time key: {} {} {}", + err->matrix_error.error, + static_cast(err->status_code), + static_cast(err->error_code)); + else + nhlog::crypto()->info("cleared 1 one-time key"); + }); } } }