aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp25
-rw-r--r--lib/connection.h2
-rw-r--r--lib/encryptionmanager.cpp2
-rw-r--r--lib/encryptionmanager.h2
-rw-r--r--lib/room.cpp17
5 files changed, 48 insertions, 0 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 98c8a4bc..6ad24fba 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -19,7 +19,9 @@
#include "connection.h"
#include "connectiondata.h"
+#ifdef Quotient_E2EE_ENABLED
#include "encryptionmanager.h"
+#endif // Quotient_E2EE_ENABLED
#include "room.h"
#include "settings.h"
#include "user.h"
@@ -43,7 +45,9 @@
#include "jobs/mediathumbnailjob.h"
#include "jobs/syncjob.h"
+#ifdef Quotient_E2EE_ENABLED
#include "account.h" // QtOlm
+#endif // Quotient_E2EE_ENABLED
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
@@ -107,7 +111,9 @@ public:
GetCapabilitiesJob* capabilitiesJob = nullptr;
GetCapabilitiesJob::Capabilities capabilities;
+#ifdef Quotient_E2EE_ENABLED
QScopedPointer<EncryptionManager> encryptionManager;
+#endif // Quotient_E2EE_ENABLED
SyncJob* syncJob = nullptr;
@@ -153,6 +159,10 @@ public:
RoomEventPtr sessionDecryptMessage(const EncryptedEvent& encryptedEvent)
{
+#ifndef Quotient_E2EE_ENABLED
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+ return {};
+#else // Quotient_E2EE_ENABLED
if (encryptedEvent.algorithm() != OlmV1Curve25519AesSha2AlgoKey)
{
return {};
@@ -208,6 +218,7 @@ public:
}
return decryptedEvent;
+#endif // Quotient_E2EE_ENABLED
}
};
@@ -304,8 +315,12 @@ void Connection::doConnectToServer(const QString& user, const QString& password,
connect(loginJob, &BaseJob::success, this, [this, loginJob] {
d->connectWithToken(loginJob->userId(), loginJob->accessToken(),
loginJob->deviceId());
+#ifndef Quotient_E2EE_ENABLED
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+#else // Quotient_E2EE_ENABLED
d->encryptionManager->uploadIdentityKeys(this);
d->encryptionManager->uploadOneTimeKeys(this);
+#endif // Quotient_E2EE_ENABLED
});
connect(loginJob, &BaseJob::failure, this, [this, loginJob] {
emit loginError(loginJob->errorString(), loginJob->rawDataSample());
@@ -362,12 +377,16 @@ void Connection::Private::connectWithToken(const QString& userId,
qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
<< "by user" << userId << "from device" << deviceId;
AccountSettings accountSettings(userId);
+#ifndef Quotient_E2EE_ENABLED
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+#else // Quotient_E2EE_ENABLED
encryptionManager.reset(
new EncryptionManager(accountSettings.encryptionAccountPickle()));
if (accountSettings.encryptionAccountPickle().isEmpty()) {
accountSettings.setEncryptionAccountPickle(
encryptionManager->olmAccountPickle());
}
+#endif // Quotient_E2EE_ENABLED
emit q->stateChanged();
emit q->connected();
q->reloadCapabilities();
@@ -594,6 +613,9 @@ void Connection::onSyncSuccess(SyncData&& data, bool fromCache)
d->dcLocalAdditions.clear();
d->dcLocalRemovals.clear();
}
+#ifndef Quotient_E2EE_ENABLED
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+#else // Quotient_E2EE_ENABLED
// handling m.room_key to-device encrypted event
for (auto&& toDeviceEvent : data.takeToDeviceEvents()) {
if (toDeviceEvent->type() == EncryptedEvent::typeId()) {
@@ -645,6 +667,7 @@ void Connection::onSyncSuccess(SyncData&& data, bool fromCache)
d->encryptionManager->updateOneTimeKeyCounts(this,
deviceOneTimeKeysCount);
}
+#endif // Quotient_E2EE_ENABLED
}
void Connection::stopSync()
@@ -1068,10 +1091,12 @@ QString Connection::deviceId() const { return d->data->deviceId(); }
QByteArray Connection::accessToken() const { return d->data->accessToken(); }
+#ifdef Quotient_E2EE_ENABLED
QtOlm::Account* Connection::olmAccount() const
{
return d->encryptionManager->account();
}
+#endif // Quotient_E2EE_ENABLED
SyncJob* Connection::syncJob() const { return d->syncJob; }
diff --git a/lib/connection.h b/lib/connection.h
index e4109fd4..b57f0ca8 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -304,7 +304,9 @@ public:
QString userId() const;
QString deviceId() const;
QByteArray accessToken() const;
+#ifdef Quotient_E2EE_ENABLED
QtOlm::Account* olmAccount() const;
+#endif // Quotient_E2EE_ENABLED
Q_INVOKABLE Quotient::SyncJob* syncJob() const;
Q_INVOKABLE int millisToReconnect() const;
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index e2834c45..0895fae9 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -1,3 +1,4 @@
+#ifdef Quotient_E2EE_ENABLED
#include "encryptionmanager.h"
#include "connection.h"
@@ -366,3 +367,4 @@ bool EncryptionManager::Private::oneTimeKeyShouldUpload()
}
return false;
}
+#endif // Quotient_E2EE_ENABLED
diff --git a/lib/encryptionmanager.h b/lib/encryptionmanager.h
index 8f346d37..5df15e83 100644
--- a/lib/encryptionmanager.h
+++ b/lib/encryptionmanager.h
@@ -1,3 +1,4 @@
+#ifdef Quotient_E2EE_ENABLED
#pragma once
#include <QtCore/QObject>
@@ -43,3 +44,4 @@ private:
};
} // namespace Quotient
+#endif // Quotient_E2EE_ENABLED
diff --git a/lib/room.cpp b/lib/room.cpp
index ecb5a7ad..5a966ceb 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -69,9 +69,11 @@
#include <cmath>
#include <functional>
+#ifdef Quotient_E2EE_ENABLED
#include <account.h> // QtOlm
#include <errors.h> // QtOlm
#include <groupsession.h> // QtOlm
+#endif // Quotient_E2EE_ENABLED
using namespace Quotient;
using namespace QtOlm;
@@ -342,6 +344,7 @@ public:
QJsonObject toJson() const;
+#ifdef Quotient_E2EE_ENABLED
// A map from <sessionId, messageIndex> to <event_id, origin_server_ts>
QHash<QPair<QString, uint32_t>, QPair<QString, QDateTime>>
groupSessionIndexRecord; // TODO: cache
@@ -424,6 +427,7 @@ public:
return decrypted.first;
}
+#endif // Quotient_E2EE_ENABLED
private:
using users_shortlist_t = std::array<User*, 3>;
@@ -1238,6 +1242,11 @@ const StateEventBase* Room::getCurrentState(const QString& evtType,
RoomEventPtr Room::decryptMessage(const EncryptedEvent& encryptedEvent)
{
+#ifndef Quotient_E2EE_ENABLED
+ Q_UNUSED(encryptedEvent);
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+ return {};
+#else // Quotient_E2EE_ENABLED
if (encryptedEvent.algorithm() == MegolmV1AesSha2AlgoKey) {
QString decrypted = d->groupSessionDecryptMessage(
encryptedEvent.ciphertext(), encryptedEvent.senderKey(),
@@ -1252,10 +1261,17 @@ RoomEventPtr Room::decryptMessage(const EncryptedEvent& encryptedEvent)
qCDebug(E2EE) << "Algorithm of the encrypted event with id"
<< encryptedEvent.id() << "is not for the current device";
return {};
+#endif // Quotient_E2EE_ENABLED
}
void Room::handleRoomKeyEvent(RoomKeyEvent* roomKeyEvent, QString senderKey)
{
+#ifndef Quotient_E2EE_ENABLED
+ Q_UNUSED(roomKeyEvent);
+ Q_UNUSED(senderKey);
+ qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
+ return;
+#else // Quotient_E2EE_ENABLED
if (roomKeyEvent->algorithm() != MegolmV1AesSha2AlgoKey) {
qCWarning(E2EE) << "Ignoring unsupported algorithm"
<< roomKeyEvent->algorithm() << "in m.room_key event";
@@ -1265,6 +1281,7 @@ void Room::handleRoomKeyEvent(RoomKeyEvent* roomKeyEvent, QString senderKey)
qCDebug(E2EE) << "added new inboundGroupSession:"
<< d->groupSessions.count();
}
+#endif // Quotient_E2EE_ENABLED
}
int Room::joinedCount() const