diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/logging.cpp | 12 | ||||
-rw-r--r-- | lib/logging.h | 5 | ||||
-rw-r--r-- | lib/room.cpp | 58 |
3 files changed, 36 insertions, 39 deletions
diff --git a/lib/logging.cpp b/lib/logging.cpp index a7676c97..c346fbf1 100644 --- a/lib/logging.cpp +++ b/lib/logging.cpp @@ -18,17 +18,15 @@ #include "logging.h" -#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) -# define LOGGING_CATEGORY(Name, Id) \ - Q_LOGGING_CATEGORY((Name), (Id), QtInfoMsg) -#else -# define LOGGING_CATEGORY(Name, Id) Q_LOGGING_CATEGORY((Name), (Id)) -#endif +#define LOGGING_CATEGORY(Name, Id) Q_LOGGING_CATEGORY((Name), (Id), QtInfoMsg) // Use LOGGING_CATEGORY instead of Q_LOGGING_CATEGORY in the rest of the code LOGGING_CATEGORY(MAIN, "quotient.main") -LOGGING_CATEGORY(PROFILER, "quotient.profiler") LOGGING_CATEGORY(EVENTS, "quotient.events") +LOGGING_CATEGORY(STATE, "quotient.events.state") +LOGGING_CATEGORY(MESSAGES, "quotient.events.messages") LOGGING_CATEGORY(EPHEMERAL, "quotient.events.ephemeral") +LOGGING_CATEGORY(E2EE, "quotient.e2ee") LOGGING_CATEGORY(JOBS, "quotient.jobs") LOGGING_CATEGORY(SYNCJOB, "quotient.jobs.sync") +LOGGING_CATEGORY(PROFILER, "quotient.profiler") diff --git a/lib/logging.h b/lib/logging.h index 3d13569a..ce4131bb 100644 --- a/lib/logging.h +++ b/lib/logging.h @@ -22,11 +22,14 @@ #include <QtCore/QLoggingCategory> Q_DECLARE_LOGGING_CATEGORY(MAIN) -Q_DECLARE_LOGGING_CATEGORY(PROFILER) +Q_DECLARE_LOGGING_CATEGORY(STATE) +Q_DECLARE_LOGGING_CATEGORY(MESSAGES) Q_DECLARE_LOGGING_CATEGORY(EVENTS) Q_DECLARE_LOGGING_CATEGORY(EPHEMERAL) +Q_DECLARE_LOGGING_CATEGORY(E2EE) Q_DECLARE_LOGGING_CATEGORY(JOBS) Q_DECLARE_LOGGING_CATEGORY(SYNCJOB) +Q_DECLARE_LOGGING_CATEGORY(PROFILER) namespace Quotient { // QDebug manipulators diff --git a/lib/room.cpp b/lib/room.cpp index 031f9467..f7d3a797 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1107,34 +1107,30 @@ bool Room::usesEncryption() const return !d->getCurrentState<EncryptionEvent>()->algorithm().isEmpty(); } -const RoomEvent* Room::decryptMessage(EncryptedEvent* encryptedEvent) const +RoomEventPtr Room::decryptMessage(EncryptedEvent* encryptedEvent) { if (encryptedEvent->algorithm() == OlmV1Curve25519AesSha2AlgoKey) { - QString identityKey = connection()->olmAccount()->curve25519IdentityKey(); + QString identityKey = + connection()->olmAccount()->curve25519IdentityKey(); QJsonObject personalCipherObject = encryptedEvent->ciphertext(identityKey); if (personalCipherObject.isEmpty()) { - qCDebug(EVENTS) << "Encrypted event is not for the current device"; - return nullptr; + qCDebug(E2EE) << "Encrypted event is not for the current device"; + return {}; } - return makeEvent<RoomMessageEvent>( - decryptMessage(personalCipherObject, - encryptedEvent->senderKey().toLatin1())) - .get(); + return makeEvent<RoomMessageEvent>(decryptMessage( + personalCipherObject, encryptedEvent->senderKey().toLatin1())); } if (encryptedEvent->algorithm() == MegolmV1AesSha2AlgoKey) { - return makeEvent<RoomMessageEvent>( - decryptMessage(encryptedEvent->ciphertext(), - encryptedEvent->senderKey(), - encryptedEvent->deviceId(), - encryptedEvent->sessionId())) - .get(); + return makeEvent<RoomMessageEvent>(decryptMessage( + encryptedEvent->ciphertext(), encryptedEvent->senderKey(), + encryptedEvent->deviceId(), encryptedEvent->sessionId())); } - return nullptr; + return {}; } -const QString Room::decryptMessage(QJsonObject personalCipherObject, - QByteArray senderKey) const +QString Room::decryptMessage(QJsonObject personalCipherObject, + QByteArray senderKey) { QString decrypted; @@ -1145,25 +1141,26 @@ const QString Room::decryptMessage(QJsonObject personalCipherObject, int type = personalCipherObject.value(TypeKeyL).toInt(-1); QByteArray body = personalCipherObject.value(BodyKeyL).toString().toLatin1(); - PreKeyMessage* preKeyMessage = new PreKeyMessage(body); - session = new InboundSession(connection()->olmAccount(), preKeyMessage, - senderKey); + PreKeyMessage preKeyMessage { body }; + session = + new InboundSession(connection()->olmAccount(), &preKeyMessage, senderKey, this); if (type == 0) { - if (!session->matches(preKeyMessage, senderKey)) { + if (!session->matches(&preKeyMessage, senderKey)) { connection()->olmAccount()->removeOneTimeKeys(session); } try { - decrypted = session->decrypt(preKeyMessage); + decrypted = session->decrypt(&preKeyMessage); } catch (std::runtime_error& e) { qWarning(EVENTS) << "Decrypt failed:" << e.what(); } - } else if (type == 1) { - Message* message = new Message(body); - if (!session->matches(preKeyMessage, senderKey)) { + } + else if (type == 1) { + Message message { body }; + if (!session->matches(&preKeyMessage, senderKey)) { qWarning(EVENTS) << "Invalid encrypted message"; } try { - decrypted = session->decrypt(message); + decrypted = session->decrypt(&message); } catch (std::runtime_error& e) { qWarning(EVENTS) << "Decrypt failed:" << e.what(); } @@ -1172,16 +1169,15 @@ const QString Room::decryptMessage(QJsonObject personalCipherObject, return decrypted; } -const QString Room::sessionKey(const QString& senderKey, const QString& deviceId, - const QString& sessionId) const +QString Room::sessionKey(const QString& senderKey, const QString& deviceId, + const QString& sessionId) const { // TODO: handling an m.room_key event return ""; } -const QString Room::decryptMessage(QByteArray cipher, const QString& senderKey, - const QString& deviceId, - const QString& sessionId) const +QString Room::decryptMessage(QByteArray cipher, const QString& senderKey, + const QString& deviceId, const QString& sessionId) { QString decrypted; using namespace QtOlm; |