summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-04-20 14:19:07 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-04-20 14:19:07 +0200
commit20c1ca2aaec2ead2d0182fc248614819ae3ddf54 (patch)
tree6b025163c8fe699e701eea17be9a144fd500b69f /src
parentLinkify matrix uris (diff)
downloadnheko-20c1ca2aaec2ead2d0182fc248614819ae3ddf54.tar.xz
Fix a a session with a higher minimum index being able to overwrite an older one
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp

index 44b7d246..9e9e1586 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp
@@ -374,6 +374,18 @@ Cache::saveInboundMegolmSession(const MegolmSessionIndex &index, const auto pickled = pickle<InboundSessionObject>(session.get(), SECRET); auto txn = lmdb::txn::begin(env_); + + std::string_view value; + if (inboundMegolmSessionDb_.get(txn, key, value)) { + auto oldSession = unpickle<InboundSessionObject>(std::string(value), SECRET); + if (olm_inbound_group_session_first_known_index(session.get()) > + olm_inbound_group_session_first_known_index(oldSession.get())) { + nhlog::crypto()->warn( + "Not storing inbound session with newer first known index"); + return; + } + } + inboundMegolmSessionDb_.put(txn, key, pickled); txn.commit(); }