aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-11-16 23:23:26 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:56:59 +0100
commit15e75b20d5bb9339a8b769b717db00fb5c16b050 (patch)
treeb50e53545c5369f60b07108ea37d35d175dcd942
parent06facdb1179e2e6789d7263541294fb427f649e5 (diff)
downloadlibquotient-15e75b20d5bb9339a8b769b717db00fb5c16b050.tar.gz
libquotient-15e75b20d5bb9339a8b769b717db00fb5c16b050.zip
Add function to decrypt notifications
-rw-r--r--lib/connection.cpp12
-rw-r--r--lib/connection.h1
-rw-r--r--lib/room.cpp1
3 files changed, 12 insertions, 2 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index cd4c9838..6ed116c4 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -837,7 +837,6 @@ void Connection::Private::consumeToDeviceEvents(Events&& toDeviceEvents)
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();
@@ -2062,3 +2061,14 @@ QString Connection::e2eeDataDir() const
dir.mkpath(path);
return path;
}
+
+QJsonObject Connection::decryptNotification(const QJsonObject &notification)
+{
+ auto room = provideRoom(notification["room_id"].toString());
+ auto event = makeEvent<EncryptedEvent>(notification["event"].toObject());
+ auto decrypted = room->decryptMessage(*event);
+ if(!decrypted) {
+ return QJsonObject();
+ }
+ return decrypted->fullJson();
+}
diff --git a/lib/connection.h b/lib/connection.h
index d1e3a992..824c7fb4 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -664,6 +664,7 @@ public Q_SLOTS:
#ifdef Quotient_E2EE_ENABLED
void encryptionUpdate(Room *room);
PicklingMode picklingMode() const;
+ QJsonObject decryptNotification(const QJsonObject &notification);
#endif
Q_SIGNALS:
/// \brief Initial server resolution has failed
diff --git a/lib/room.cpp b/lib/room.cpp
index 963b9f88..d755f8eb 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1599,7 +1599,6 @@ void Room::handleRoomKeyEvent(const RoomKeyEvent& roomKeyEvent,
if (auto encryptedEvent = d->timeline[i].viewAs<EncryptedEvent>()) {
auto decrypted = decryptMessage(*encryptedEvent);
if(decrypted) {
- qWarning() << "decrypted" << decrypted->fullJson();
auto oldEvent = d->timeline[i].replaceEvent(std::move(decrypted));
emit replacedEvent(d->timeline[i].event(), rawPtr(oldEvent));
}