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 Jun 27, 2019
1 parent 2388521 commit cb2f652
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/encryptionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,47 @@ 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 QVariantMap& olmAccountCurve25519OneTimeKeys = d->olmAccount->curve25519OneTimeKeys();
for (int i = 0; i < olmAccountCurve25519OneTimeKeys.count(); ++i)
{
QString keyId = olmAccountCurve25519OneTimeKeys.keys().at(i);
QString keyType;
QVariant key;
if (i < signedKeysToUploadCount)
{
QJsonObject message
{
{QStringLiteral("key"), olmAccountCurve25519OneTimeKeys.value(keyId).toString()}
};
key = d->olmAccount->sign(message);
keyType = signedCurve25519Name;

} else {
key = olmAccountCurve25519OneTimeKeys.value(keyId);
keyType = curve25519Name;
}
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 cb2f652

Please sign in to comment.