aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Andreyev <aa13q@ya.ru>2019-06-22 19:57:18 +0300
committerAlexey Andreyev <aa13q@ya.ru>2019-07-04 11:21:07 +0300
commite1bee9d71d88d6500d2c6124689a0e8685aeab90 (patch)
treeca55243329d83ecfede684a5f0e4def4b795706f
parent79f6f33bbbd60eafe92b5187a3bf5fd8966f8bf5 (diff)
downloadlibquotient-e1bee9d71d88d6500d2c6124689a0e8685aeab90.tar.gz
libquotient-e1bee9d71d88d6500d2c6124689a0e8685aeab90.zip
Upload one-time keys. Issue #88
-rw-r--r--lib/encryptionmanager.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index 80fdcebd..1e1fc669 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -137,7 +137,50 @@ void EncryptionManager::uploadIdentityKeys(Connection* connection)
void EncryptionManager::uploadOneTimeKeys(Connection* connection, bool forceUpdate)
{
- // TODO
+ if (forceUpdate || d->oneTimeKeyCounts.isEmpty())
+ {
+ auto job = connection->callApi<UploadKeysJob>();
+ connect(job, &BaseJob::success, this, [job,this] {
+ d->setOneTimeKeyCounts(job->oneTimeKeyCounts());
+ });
+
+ }
+
+ int signedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(SignedCurve25519Name, 0);
+ int unsignedKeysToUploadCount = d->oneTimeKeysToUploadCounts.value(Curve25519Name, 0);
+
+ d->olmAccount->generateOneTimeKeys(signedKeysToUploadCount + unsignedKeysToUploadCount);
+
+ QHash<QString, QVariant> oneTimeKeys = {};
+ const auto& olmAccountCurve25519OneTimeKeys = d->olmAccount->curve25519OneTimeKeys();
+
+ int oneTimeKeysCounter = 0;
+ for (auto it = olmAccountCurve25519OneTimeKeys.cbegin(); it != olmAccountCurve25519OneTimeKeys.cend(); ++it)
+ {
+ QString keyId = it.key();
+ QString keyType;
+ QVariant key;
+ if (oneTimeKeysCounter < signedKeysToUploadCount)
+ {
+ QJsonObject message
+ {
+ {QStringLiteral("key"), it.value().toString()}
+ };
+ key = d->olmAccount->sign(message);
+ keyType = SignedCurve25519Name;
+
+ } else {
+ key = it.value();
+ keyType = Curve25519Name;
+ }
+ ++oneTimeKeysCounter;
+ oneTimeKeys.insert(QString("%1:%2").arg(keyType).arg(keyId), key);
+ }
+
+ d->uploadOneTimeKeysJob = connection->callApi<UploadKeysJob>(none, oneTimeKeys);
+ d->olmAccount->markKeysAsPublished();
+ qDebug() << QString("Uploaded new one-time keys: %1 signed, %2 unsigned.")
+ .arg(signedKeysToUploadCount).arg(unsignedKeysToUploadCount);
}
void EncryptionManager::Private::updateKeysToUpload()