Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFella committed Aug 27, 2024
1 parent 23c3f4f commit 682f857
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
1 change: 0 additions & 1 deletion Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ void Connection::Private::completeSetup(const QString& mxId, const QString& devi
ConnectionEncryptionData::setup(q, mock, encryptionData).then([this](bool successful) {
if (!successful || !encryptionData)
useEncryption = false;
//TODO connect needssave -> saveOlmAccount?

emit q->encryptionChanged(useEncryption);
emit q->stateChanged();
Expand Down
37 changes: 22 additions & 15 deletions Quotient/connectionencryptiondata_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,35 @@ QFuture<bool> ConnectionEncryptionData::setup(Connection* connection, bool mock,
std::unique_ptr<ConnectionEncryptionData>& result)
{
return setupPicklingKey(connection, mock, result)
.then([connection, mock, &result] {
.then([connection, &result] {
// if (mock) {
// result->database.clear();
// result->olmAccount.setupNewAccount();
// return true;
// }
if (const auto olmAccount = result->database.setupOlmAccount(connection->userId(), connection->deviceId())) {
if (const auto accountResult = result->database.setupOlmAccount(connection->userId(), connection->deviceId()); accountResult.first) {
//TODO: check unpickling errors here
result->olmAccount = olmAccount;
return true;
result->olmAccount = accountResult.first;
result->olmAccount->connect(result->olmAccount, &QOlmAccount::needsSave, result->olmAccount, [&result]{
result->saveOlmAccount();
});

if (accountResult.second) {
qCDebug(E2EE) << "A new Olm account has been created, uploading device keys";
result->saveOlmAccount();
connection->callApi<UploadKeysJob>(result->olmAccount->deviceKeys())
.then(connection, [connection, &result] {
result->trackedUsers += connection->userId();
result->outdatedUsers += connection->userId();
result->encryptionUpdateRequired = true;
},
[](auto* job) {
qCWarning(E2EE) << "Failed to upload device keys:" << job->errorString();
}
);
}

}
qCDebug(E2EE) << "A new Olm account has been created, uploading device keys";
connection->callApi<UploadKeysJob>(result->olmAccount->deviceKeys())
.then(connection,
[connection, &result] {
result->trackedUsers += connection->userId();
result->outdatedUsers += connection->userId();
result->encryptionUpdateRequired = true;
},
[](auto* job) {
qCWarning(E2EE) << "Failed to upload device keys:" << job->errorString();
});
return true;
})
.onCanceled([connection] {
Expand Down
6 changes: 3 additions & 3 deletions Quotient/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ void Database::storeOlmAccount(const QOlmAccount& olmAccount)
commit();
}

QOlmAccount *Database::setupOlmAccount(const QString& userId, const QString& deviceId)
std::pair<QOlmAccount*, bool> Database::setupOlmAccount(const QString& userId, const QString& deviceId)
{
auto query = prepareQuery(QStringLiteral("SELECT pickle FROM accounts;"));
execute(query);
if (query.next())
return QOlmAccount::unpickle(query.value(QStringLiteral("pickle")).toByteArray(), m_picklingKey, nullptr);
return QOlmAccount::newAccount(nullptr/*TODO*/, userId, deviceId);
return {QOlmAccount::unpickle(query.value(QStringLiteral("pickle")).toByteArray(), m_picklingKey, nullptr), false};
return {QOlmAccount::newAccount(nullptr/*TODO*/, userId, deviceId), true};
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion Quotient/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QUOTIENT_API Database
QSqlQuery prepareQuery(const QString& queryString) const;

void storeOlmAccount(const QOlmAccount& olmAccount);
QOlmAccount *setupOlmAccount(const QString& userId, const QString& deviceId);
std::pair<QOlmAccount*, bool> setupOlmAccount(const QString& userId, const QString& deviceId);
void clear();
void saveOlmSession(const QByteArray& senderKey, const QOlmSession& session,
const QDateTime& timestamp);
Expand Down
2 changes: 1 addition & 1 deletion Quotient/e2ee/qolminboundsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ QOlmExpected<QOlmInboundGroupSession> QOlmInboundGroupSession::unpickle(
//TODO: This is terrible :(
std::array<std::uint8_t, 32> _key;
std::copy(key.data(), key.data() + 32, _key.begin());
auto session = megolm::inbound_group_session_from_pickle(rust::String(keyBytes.data(), keyBytes.size()), _key);
auto session = megolm::inbound_group_session_from_pickle(rust::String(pickled.data(), pickled.size()), _key);
return QOlmInboundGroupSession(std::move(session));
}

Expand Down

0 comments on commit 682f857

Please sign in to comment.