aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-11-15 21:26:47 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:56:59 +0100
commit34db4fd1294e41765a5db58ee1a0c59712af62c6 (patch)
tree27a58367029402c66a9072b1ca17ce86d00a4e92 /lib
parent82cffec29937e4449a75040485d5188f429b7b1e (diff)
downloadlibquotient-34db4fd1294e41765a5db58ee1a0c59712af62c6.tar.gz
libquotient-34db4fd1294e41765a5db58ee1a0c59712af62c6.zip
Various improvements and fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp54
-rw-r--r--lib/crypto/qolmsession.cpp4
-rw-r--r--lib/encryptionmanager.cpp2
-rw-r--r--lib/mxcreply.cpp1
-rw-r--r--lib/room.cpp4
-rw-r--r--lib/settings.cpp6
6 files changed, 34 insertions, 37 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index d8e98bb0..f36166ff 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -830,33 +830,35 @@ void Connection::Private::consumePresenceData(Events&& presenceData)
void Connection::Private::consumeToDeviceEvents(Events&& toDeviceEvents)
{
#ifdef Quotient_E2EE_ENABLED
- qWarning() << "Consuming to device events" << toDeviceEvents.size();
- if(toDeviceEvents.size() > 0)
- visitEach(toDeviceEvents, [this](const EncryptedEvent& event) {
- if (event.algorithm() != OlmV1Curve25519AesSha2AlgoKey) {
- qCDebug(E2EE) << "Unsupported algorithm" << event.id() << "for event" << event.algorithm();
- return;
- }
- const auto decryptedEvent = sessionDecryptMessage(event);
- if(!decryptedEvent) {
- qCWarning(E2EE) << "Failed to decrypt event" << event.id();
- return;
- }
+ if(toDeviceEvents.size() > 0) {
+ qCDebug(E2EE) << "Consuming" << toDeviceEvents.size() << "to-device events";
+ visitEach(toDeviceEvents, [this](const EncryptedEvent& event) {
+ if (event.algorithm() != OlmV1Curve25519AesSha2AlgoKey) {
+ qCDebug(E2EE) << "Unsupported algorithm" << event.id() << "for event" << event.algorithm();
+ return;
+ }
+ qWarning() << event.fullJson();
+ const auto decryptedEvent = sessionDecryptMessage(event);
+ if(!decryptedEvent) {
+ qCWarning(E2EE) << "Failed to decrypt event" << event.id();
+ return;
+ }
- visit(*decryptedEvent,
- [this, senderKey = event.senderKey()](const RoomKeyEvent& roomKeyEvent) {
- if (auto* detectedRoom = q->room(roomKeyEvent.roomId())) {
- detectedRoom->handleRoomKeyEvent(roomKeyEvent, senderKey);
- } else {
- qCDebug(E2EE) << "Encrypted event room id" << roomKeyEvent.roomId()
- << "is not found at the connection" << q->objectName();
- }
- },
- [](const Event& evt) {
- qCDebug(E2EE) << "Skipping encrypted to_device event, type"
- << evt.matrixType();
- });
- });
+ visit(*decryptedEvent,
+ [this, senderKey = event.senderKey()](const RoomKeyEvent& roomKeyEvent) {
+ if (auto* detectedRoom = q->room(roomKeyEvent.roomId())) {
+ detectedRoom->handleRoomKeyEvent(roomKeyEvent, senderKey);
+ } else {
+ qCDebug(E2EE) << "Encrypted event room id" << roomKeyEvent.roomId()
+ << "is not found at the connection" << q->objectName();
+ }
+ },
+ [](const Event& evt) {
+ qCDebug(E2EE) << "Skipping encrypted to_device event, type"
+ << evt.matrixType();
+ });
+ });
+ }
#endif
}
diff --git a/lib/crypto/qolmsession.cpp b/lib/crypto/qolmsession.cpp
index 2068a7d9..a327a643 100644
--- a/lib/crypto/qolmsession.cpp
+++ b/lib/crypto/qolmsession.cpp
@@ -46,9 +46,7 @@ std::variant<std::unique_ptr<QOlmSession>, QOlmError> QOlmSession::createInbound
if (error == olm_error()) {
const auto lastErr = lastError(olmSession);
- if (lastErr == QOlmError::NotEnoughRandom) {
- qCCritical(E2EE) << "Error when creating inbound session" << lastErr;
- }
+ qCWarning(E2EE) << "Error when creating inbound session" << lastErr;
return lastErr;
}
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index 5c1750c9..81c13e50 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -137,7 +137,7 @@ public:
qCDebug(E2EE) << "Creating new inbound session";
auto newSessionResult = olmAccount->createInboundSessionFrom(senderKey.toUtf8(), message);
if(std::holds_alternative<QOlmError>(newSessionResult)) {
- qCWarning(E2EE) << "Failed to create inbound session for" << senderKey;
+ qCWarning(E2EE) << "Failed to create inbound session for" << senderKey << std::get<QOlmError>(newSessionResult);
return {};
}
std::unique_ptr<QOlmSession> newSession = std::move(std::get<std::unique_ptr<QOlmSession>>(newSessionResult));
diff --git a/lib/mxcreply.cpp b/lib/mxcreply.cpp
index 65078301..639c1324 100644
--- a/lib/mxcreply.cpp
+++ b/lib/mxcreply.cpp
@@ -52,6 +52,7 @@ MxcReply::MxcReply(QNetworkReply* reply, Room* room, const QString &eventId)
EncryptedFile file = *d->m_encryptedFile;
auto buffer = new QBuffer(this);
buffer->setData(EncryptionManager::decryptFile(d->m_reply->readAll(), &file));
+ buffer->open(ReadOnly);
d->m_device = buffer;
}
setOpenMode(ReadOnly);
diff --git a/lib/room.cpp b/lib/room.cpp
index 6c5a9d33..94f0c9eb 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1600,7 +1600,9 @@ void Room::handleRoomKeyEvent(const RoomKeyEvent& roomKeyEvent,
if (auto encryptedEvent = d->timeline[i].viewAs<EncryptedEvent>()) {
auto decrypted = decryptMessage(*encryptedEvent);
if(decrypted) {
- d->timeline[i].replaceEvent(std::move(decrypted));
+ qWarning() << "decrypted" << decrypted->fullJson();
+ auto oldEvent = d->timeline[i].replaceEvent(std::move(decrypted));
+ emit replacedEvent(d->timeline[i].event(), rawPtr(oldEvent));
}
}
}
diff --git a/lib/settings.cpp b/lib/settings.cpp
index ed9082b0..f9b4f471 100644
--- a/lib/settings.cpp
+++ b/lib/settings.cpp
@@ -136,18 +136,12 @@ void AccountSettings::clearAccessToken()
QByteArray AccountSettings::encryptionAccountPickle()
{
- QString passphrase = ""; // FIXME: add QtKeychain
return value("encryption_account_pickle", "").toByteArray();
}
void AccountSettings::setEncryptionAccountPickle(
const QByteArray& encryptionAccountPickle)
{
- qCWarning(MAIN)
- << "Saving encryption_account_pickle to QSettings is insecure."
- " Developers, do it manually or contribute to share QtKeychain "
- "logic to libQuotient.";
- QString passphrase = ""; // FIXME: add QtKeychain
setValue("encryption_account_pickle", encryptionAccountPickle);
}