mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Rate limit olm session creation
This commit is contained in:
parent
d955444dc1
commit
6409462a96
1 changed files with 17 additions and 3 deletions
18
src/Olm.cpp
18
src/Olm.cpp
|
@ -1138,9 +1138,23 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
|||
|
||||
auto session = cache::getLatestOlmSession(device_curve);
|
||||
if (!session || force_new_session) {
|
||||
claims.one_time_keys[user][device] = mtx::crypto::SIGNED_CURVE25519;
|
||||
static QMap<QPair<std::string, std::string>, qint64> rateLimit;
|
||||
auto currentTime = QDateTime::currentSecsSinceEpoch();
|
||||
if (rateLimit.value(QPair(user, device)) + 60 * 60 * 10 <
|
||||
currentTime) {
|
||||
claims.one_time_keys[user][device] =
|
||||
mtx::crypto::SIGNED_CURVE25519;
|
||||
pks[user][device].ed25519 = d.keys.at("ed25519:" + device);
|
||||
pks[user][device].curve25519 = d.keys.at("curve25519:" + device);
|
||||
pks[user][device].curve25519 =
|
||||
d.keys.at("curve25519:" + device);
|
||||
|
||||
rateLimit.insert(QPair(user, device), currentTime);
|
||||
} else {
|
||||
nhlog::crypto()->warn("Not creating new session with {}:{} "
|
||||
"because of rate limit",
|
||||
user,
|
||||
device);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue