diff options
author | Tobias Fella <fella@posteo.de> | 2021-05-24 16:52:45 +0200 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | 65877dc9fb6e024d456343d42ef55e0c5c8b67b3 (patch) | |
tree | abc2d7d31d409ff81576172f73b44e9769797e5c | |
parent | 0a75a095665101d4ffcbec10b43633eee5a0d6d3 (diff) | |
download | libquotient-65877dc9fb6e024d456343d42ef55e0c5c8b67b3.tar.gz libquotient-65877dc9fb6e024d456343d42ef55e0c5c8b67b3.zip |
Upload one-time keys when their count is low
-rw-r--r-- | lib/connection.cpp | 20 | ||||
-rw-r--r-- | lib/crypto/qolmaccount.cpp | 5 | ||||
-rw-r--r-- | lib/crypto/qolmaccount.h | 2 |
3 files changed, 16 insertions, 11 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 704bc1b4..9883b8f3 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -620,17 +620,15 @@ void Connection::onSyncSuccess(SyncData&& data, bool fromCache) d->consumePresenceData(data.takePresenceData()); d->consumeToDeviceEvents(data.takeToDeviceEvents()); #ifdef Quotient_E2EE_ENABLED - // handling device_one_time_keys_count - //if (!d->encryptionManager) - //{ - // qCDebug(E2EE) << "Encryption manager is not there yet, updating " - // "one-time key counts will be skipped"; - // return; - //} - //if (const auto deviceOneTimeKeysCount = data.deviceOneTimeKeysCount(); - // !deviceOneTimeKeysCount.isEmpty()) - // d->encryptionManager->updateOneTimeKeyCounts(this, - // deviceOneTimeKeysCount); + if(data.deviceOneTimeKeysCount()["signed_curve25519"] < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys()) { + d->olmAccount->generateOneTimeKeys(d->olmAccount->maxNumberOfOneTimeKeys() - data.deviceOneTimeKeysCount()["signed_curve25519"]); + auto keys = d->olmAccount->oneTimeKeys(); + auto job = d->olmAccount->createUploadKeyRequest(keys); + run(job, ForegroundRequest); + connect(job, &BaseJob::success, this, [=](){ + d->olmAccount->markKeysAsPublished(); + }); + } #endif // Quotient_E2EE_ENABLED } diff --git a/lib/crypto/qolmaccount.cpp b/lib/crypto/qolmaccount.cpp index 9368de4f..8cf21045 100644 --- a/lib/crypto/qolmaccount.cpp +++ b/lib/crypto/qolmaccount.cpp @@ -276,6 +276,11 @@ std::variant<std::unique_ptr<QOlmSession>, QOlmError> QOlmAccount::createOutboun return QOlmSession::createOutboundSession(this, theirIdentityKey, theirOneTimeKey); } +void QOlmAccount::markKeysAsPublished() +{ + olm_account_mark_keys_as_published(m_account); +} + bool Quotient::verifyIdentitySignature(const DeviceKeys &deviceKeys, const QString &deviceId, const QString &userId) diff --git a/lib/crypto/qolmaccount.h b/lib/crypto/qolmaccount.h index f3ca82f0..54d8506c 100644 --- a/lib/crypto/qolmaccount.h +++ b/lib/crypto/qolmaccount.h @@ -93,6 +93,8 @@ public: /// identity and one time key. std::variant<std::unique_ptr<QOlmSession>, QOlmError> createOutboundSession(const QByteArray &theirIdentityKey, const QByteArray &theirOneTimeKey); + void markKeysAsPublished(); + // HACK do not use directly QOlmAccount(OlmAccount *account); OlmAccount *data(); |