aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp2
-rw-r--r--lib/encryptionmanager.cpp4
-rw-r--r--lib/room.cpp8
3 files changed, 8 insertions, 6 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 60ffed09..7a96bc50 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -634,7 +634,7 @@ void Connection::onSyncSuccess(SyncData&& data, bool fromCache)
#ifdef Quotient_E2EE_ENABLED
if(data.deviceOneTimeKeysCount()["signed_curve25519"] < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys() && !d->isUploadingKeys) {
d->isUploadingKeys = true;
- d->olmAccount->generateOneTimeKeys(d->olmAccount->maxNumberOfOneTimeKeys() - data.deviceOneTimeKeysCount()["signed_curve25519"]);
+ d->olmAccount->generateOneTimeKeys(d->olmAccount->maxNumberOfOneTimeKeys() / 2 - data.deviceOneTimeKeysCount()["signed_curve25519"]);
auto keys = d->olmAccount->oneTimeKeys();
auto job = d->olmAccount->createUploadKeyRequest(keys);
run(job, ForegroundRequest);
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index d36d5a7a..e8cc7b3a 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -125,8 +125,8 @@ public:
if(std::holds_alternative<bool>(matches) && std::get<bool>(matches)) {
qCDebug(E2EE) << "Found inbound session";
const auto result = session.second->decrypt(message);
+ saveSessions();
if(std::holds_alternative<QString>(result)) {
- saveSessions();
return std::get<QString>(result);
} else {
qCDebug(E2EE) << "Failed to decrypt prekey message";
@@ -145,8 +145,8 @@ public:
olmAccount->removeOneTimeKeys(newSession);
const auto result = newSession->decrypt(message);
sessions[senderKey] = std::move(newSession);
+ saveSessions();
if(std::holds_alternative<QString>(result)) {
- saveSessions();
return std::get<QString>(result);
} else {
qCDebug(E2EE) << "Failed to decrypt prekey message with new session";
diff --git a/lib/room.cpp b/lib/room.cpp
index 5fedd861..a1354fc5 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -372,7 +372,7 @@ public:
std::map<QPair<QString, QString>, std::unique_ptr<QOlmInboundGroupSession>> groupSessions;
void loadMegOlmSessions() {
- QFile file { connection->stateCacheDir().filePath("megolmsessions.json") };
+ QFile file { connection->stateCacheDir().filePath(QStringLiteral("megolm/%1.json").arg(id)) };
if(!file.exists() || !file.open(QIODevice::ReadOnly)) {
qCDebug(E2EE) << "No megolm sessions cache exists.";
return;
@@ -387,7 +387,7 @@ public:
#endif
;
if (json.isEmpty()) {
- qCWarning(MAIN) << "Megolm sessions cache is empty";
+ qCWarning(E2EE) << "Megolm sessions cache is empty";
return;
}
for(const auto &s : json["sessions"].toArray()) {
@@ -403,7 +403,8 @@ public:
}
}
void saveMegOlmSessions() {
- QFile outFile { connection->stateCacheDir().filePath("megolmsessions.json") };
+ connection->stateCacheDir().mkdir("megolm");
+ QFile outFile { connection->stateCacheDir().filePath(QStringLiteral("megolm/%1.json").arg(id))};
if (!outFile.open(QFile::WriteOnly)) {
qCWarning(E2EE) << "Error opening" << outFile.fileName() << ":"
<< outFile.errorString();
@@ -521,6 +522,7 @@ Room::Room(Connection* connection, QString id, JoinState initialJoinState)
return this == r; // loadedRoomState fires only once per room
});
qCDebug(STATE) << "New" << initialJoinState << "Room:" << id;
+
#ifdef Quotient_E2EE_ENABLED
connectSingleShot(this, &Room::encryption, this, [=](){
connection->encryptionUpdate(this);