aboutsummaryrefslogtreecommitdiff
path: root/lib/e2ee.h
blob: 4a42809dc690d212717cd0ebc51ca9963335cae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

#include <QtCore/QStringList>

namespace QMatrixClient
{
    static const auto CiphertextKeyL = "ciphertext"_ls;
    static const auto SenderKeyKeyL = "sender_key"_ls;
    static const auto DeviceIdKeyL = "device_id"_ls;
    static const auto SessionIdKeyL = "session_id"_ls;

    static const auto AlgorithmKeyL = "algorithm"_ls;
    static const auto RotationPeriodMsKeyL = "rotation_period_ms"_ls;
    static const auto RotationPeriodMsgsKeyL = "rotation_period_msgs"_ls;

    static const auto AlgorithmKey = QStringLiteral("algorithm");
    static const auto RotationPeriodMsKey = QStringLiteral("rotation_period_ms");
    static const auto RotationPeriodMsgsKey = QStringLiteral("rotation_period_msgs");

    static const auto Ed25519Key = QStringLiteral("ed25519");
    static const auto Curve25519Key = QStringLiteral("curve25519");
    static const auto SignedCurve25519Key = QStringLiteral("signed_curve25519");
    static const auto OlmV1Curve25519AesSha2AlgoKey = QStringLiteral("m.olm.v1.curve25519-aes-sha2");
    static const auto MegolmV1AesSha2AlgoKey = QStringLiteral("m.megolm.v1.aes-sha2");
    static const QStringList SupportedAlgorithms = { OlmV1Curve25519AesSha2AlgoKey, MegolmV1AesSha2AlgoKey };
}  // namespace QMatrixClient
atrixType, contentJson) {} RoomEvent::RoomEvent(Type type, const QJsonObject& json) : Event(type, json) { if (const auto redaction = unsignedPart<QJsonObject>(RedactedCauseKeyL); !redaction.isEmpty()) _redactedBecause = makeEvent<RedactionEvent>(redaction); } RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job QString RoomEvent::id() const { return fullJson()[EventIdKeyL].toString(); } QDateTime RoomEvent::originTimestamp() const { return Quotient::fromJson<QDateTime>(fullJson()["origin_server_ts"_ls]); } QString RoomEvent::roomId() const { return fullJson()[RoomIdKeyL].toString(); } QString RoomEvent::senderId() const { return fullJson()[SenderKeyL].toString(); } bool RoomEvent::isReplaced() const { return unsignedPart<QJsonObject>("m.relations"_ls).contains("m.replace"); } QString RoomEvent::replacedBy() const { // clang-format off return unsignedPart<QJsonObject>("m.relations"_ls) .value("m.replace"_ls).toObject() .value(EventIdKeyL).toString(); // clang-format on } QString RoomEvent::redactionReason() const { return isRedacted() ? _redactedBecause->reason() : QString {}; } QString RoomEvent::transactionId() const { return unsignedPart<QString>("transaction_id"_ls); } QString RoomEvent::stateKey() const { return fullJson()[StateKeyKeyL].toString(); } void RoomEvent::setRoomId(const QString& roomId) { editJson().insert(RoomIdKey, roomId); } void RoomEvent::setSender(const QString& senderId) { editJson().insert(SenderKey, senderId); } void RoomEvent::setTransactionId(const QString& txnId) { auto unsignedData = fullJson()[UnsignedKeyL].toObject(); unsignedData.insert(QStringLiteral("transaction_id"), txnId); editJson().insert(UnsignedKey, unsignedData); Q_ASSERT(transactionId() == txnId); } void RoomEvent::addId(const QString& newId) { Q_ASSERT(id().isEmpty()); Q_ASSERT(!newId.isEmpty()); editJson().insert(EventIdKey, newId); qCDebug(EVENTS) << "Event txnId -> id:" << transactionId() << "->" << id(); Q_ASSERT(id() == newId); } void RoomEvent::dumpTo(QDebug dbg) const { Event::dumpTo(dbg); dbg << " (made at " << originTimestamp().toString(Qt::ISODate) << ')'; } QJsonObject CallEventBase::basicJson(const QString& matrixType, const QString& callId, int version, QJsonObject contentJson) { contentJson.insert(QStringLiteral("call_id"), callId); contentJson.insert(QStringLiteral("version"), version); return RoomEvent::basicJson(matrixType, contentJson); } CallEventBase::CallEventBase(Type type, event_mtype_t matrixType, const QString& callId, int version, const QJsonObject& contentJson) : RoomEvent(type, basicJson(matrixType, callId, version, contentJson)) {} CallEventBase::CallEventBase(Type type, const QJsonObject& json) : RoomEvent(type, json) { if (callId().isEmpty()) qCWarning(EVENTS) << id() << "is a call event with an empty call id"; } #ifdef Quotient_E2EE_ENABLED void RoomEvent::setOriginalEvent(event_ptr_tt<RoomEvent>&& originalEvent) { _originalEvent = std::move(originalEvent); } const QJsonObject RoomEvent::encryptedJson() const { if(!_originalEvent) { return {}; } return _originalEvent->fullJson(); } #endif