Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Commit

Permalink
Upload one-time keys. Issue quotient-im#88
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andreyev committed Jul 2, 2019
1 parent 8e3deb0 commit 6bc24df
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion lib/encryptionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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()
Expand Down

0 comments on commit 6bc24df

Please sign in to comment.