diff options
| author | Melvin Keskin <melvo@olomono.de> | 2022-01-23 18:11:48 +0100 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-03-03 13:49:50 +0100 |
| commit | ec1480a11ee69924712b3b1b10cde7fbf6ba1866 (patch) | |
| tree | 9b6afbd3b3869fda4ccdded7859de743c607d5ca /src/base | |
| parent | 4f77a9d91d5841771d27821ced76c7c6801790f5 (diff) | |
| download | qxmpp-ec1480a11ee69924712b3b1b10cde7fbf6ba1866.tar.gz | |
Add QXmppE2eeMetadata used by QXmppStanza
That class contains addtional data needed for end-to-end encryption purposes.
'senderKey' is moved from QXmppMessage to QXmppE2eeMetadata.
'sceTimestamp' is introduced.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppMessage.cpp | 41 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 3 | ||||
| -rw-r--r-- | src/base/QXmppStanza.cpp | 140 | ||||
| -rw-r--r-- | src/base/QXmppStanza.h | 26 |
4 files changed, 166 insertions, 44 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index e2d4a003..ec285d0a 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -14,8 +14,6 @@ #include "QXmppTrustMessageElement.h" #include "QXmppUtils.h" -#include <optional> - #include <QDateTime> #include <QDomElement> #include <QTextStream> @@ -94,7 +92,6 @@ public: QString thread; QString parentThread; QXmppMessage::Type type; - QByteArray senderKey; // XEP-0066: Out of Band Data QString outOfBandUrl; @@ -312,44 +309,6 @@ void QXmppMessage::setParentThread(const QString &parent) } /// -/// Returns the ID of this message's sender's public long-term key. -/// -/// The key ID is not part of a transmitted message and thus not de- / -/// serialized. -/// Instead, the key ID is set by an encryption protocol such as -/// \xep{0384, OMEMO Encryption} when it decrypts this message. -/// It can be used by trust management protocols such as -/// \xep{0450, Automatic Trust Management (ATM)}. -/// -/// \return the ID of the sender's key -/// -/// \since QXmpp 1.5 -/// -QByteArray QXmppMessage::senderKey() const -{ - return d->senderKey; -} - -/// -/// Sets the ID of this message's sender's public long-term key. -/// -/// The key ID is not part of a transmitted message and thus not de- / -/// serialized. -/// Instead, the key ID is set by an encryption protocol such as -/// \xep{0384, OMEMO Encryption} when it decrypts this message. -/// It can be used by trust management protocols such as -/// \xep{0450, Automatic Trust Management (ATM)}. -/// -/// \param keyId ID of the sender's key -/// -/// \since QXmpp 1.5 -/// -void QXmppMessage::setSenderKey(const QByteArray &keyId) -{ - d->senderKey = keyId; -} - -/// /// Returns a possibly attached URL from \xep{0066}: Out of Band Data /// /// \since QXmpp 1.0 diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index bc209435..bdd47800 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -120,9 +120,6 @@ public: QXmppMessage::Type type() const; void setType(QXmppMessage::Type); - QByteArray senderKey() const; - void setSenderKey(const QByteArray &keyId); - // XEP-0066: Out of Band Data QString outOfBandUrl() const; void setOutOfBandUrl(const QString &); diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index 70c87420..25b9baac 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com> // SPDX-FileCopyrightText: 2010 Jeremy LainĂ© <jeremy.laine@m4x.org> // SPDX-FileCopyrightText: 2015 Georg Rudoy <0xd34df00d@gmail.com> +// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de> // // SPDX-License-Identifier: LGPL-2.1-or-later @@ -489,6 +490,124 @@ void QXmppStanza::Error::toXml(QXmlStreamWriter *writer) const } /// \endcond +/// +/// \class QXmppE2eeMetadata +/// +/// \brief The QXmppE2eeMetadata class contains data used for end-to-end +/// encryption purposes. +/// +/// \since QXmpp 1.5 +/// + +class QXmppE2eeMetadataPrivate : public QSharedData +{ +public: + QByteArray senderKey; + + // XEP-0420: Stanza Content Encryption + QDateTime sceTimestamp; +}; + +/// +/// Constructs a class for end-to-end encryption metadata. +/// +QXmppE2eeMetadata::QXmppE2eeMetadata() + : d(new QXmppE2eeMetadataPrivate) +{ +} + +/// +/// Constructs a copy of \a other. +/// +/// \param other +/// +QXmppE2eeMetadata::QXmppE2eeMetadata(const QXmppE2eeMetadata &other) = default; + +QXmppE2eeMetadata::~QXmppE2eeMetadata() = default; + +/// +/// Assigns \a other to this end-to-end encryption metadata class. +/// +/// \param other +/// +QXmppE2eeMetadata &QXmppE2eeMetadata::operator=(const QXmppE2eeMetadata &other) = default; + +/// +/// Returns the ID of this stanza's sender's public long-term key. +/// +/// The sender key ID is not part of a transmitted stanza and thus not de- / +/// serialized. +/// Instead, the key ID is set by an encryption protocol such as +/// \xep{0384, OMEMO Encryption} during decryption. +/// It can be used by trust management protocols such as +/// \xep{0450, Automatic Trust Management (ATM)}. +/// +/// \return the ID of the sender's key +/// +/// \since QXmpp 1.5 +/// +QByteArray QXmppE2eeMetadata::senderKey() const +{ + return d->senderKey; +} + +/// +/// Sets the ID of this stanza's sender's public long-term key. +/// +/// The sender key ID is not part of a transmitted stanza and thus not de- / +/// serialized. +/// Instead, it is set by an encryption protocol such as +/// \xep{0384, OMEMO Encryption} during decryption. +/// It can be used by trust management protocols such as +/// \xep{0450, Automatic Trust Management (ATM)}. +/// +/// \param keyId ID of the sender's key +/// +/// \since QXmpp 1.5 +/// +void QXmppE2eeMetadata::setSenderKey(const QByteArray &keyId) +{ + d->senderKey = keyId; +} + +/// +/// Returns the timestamp affix element's content as defined by +/// \xep{0420, Stanza Content Encryption} (SCE). +/// +/// The SCE timestamp is part of an encrypted stanza's SCE envelope, +/// not an unencrypted direct child of a transmitted stanza and thus not de- / +/// serialized by it. +/// Instead, it is set by an encryption protocol such as +/// \xep{0384, OMEMO Encryption} after decryption. +/// It can be used by trust management protocols such as +/// \xep{0450, Automatic Trust Management (ATM)}. +/// +/// \since QXmpp 1.5 +/// +QDateTime QXmppE2eeMetadata::sceTimestamp() const +{ + return d->sceTimestamp; +} + +/// +/// Sets the timestamp affix element's content as defined by +/// \xep{0420, Stanza Content Encryption} (SCE). +/// +/// The SCE timestamp is part of an encrypted stanza's SCE envelope, +/// not an unencrypted direct child of a transmitted stanza and thus not de- / +/// serialized by it. +/// Instead, it is set by an encryption protocol such as +/// \xep{0384, OMEMO Encryption} after decryption. +/// It can be used by trust management protocols such as +/// \xep{0450, Automatic Trust Management (ATM)}. +/// +/// \since QXmpp 1.5 +/// +void QXmppE2eeMetadata::setSceTimestamp(const QDateTime ×tamp) +{ + d->sceTimestamp = timestamp; +} + class QXmppStanzaPrivate : public QSharedData { public: @@ -499,6 +618,7 @@ public: QXmppStanza::Error error; QXmppElementList extensions; QList<QXmppExtendedAddress> extendedAddresses; + QXmppE2eeMetadata e2eeMetadata; }; /// @@ -651,6 +771,26 @@ void QXmppStanza::setExtendedAddresses(const QList<QXmppExtendedAddress> &addres d->extendedAddresses = addresses; } +/// +/// Returns additional data for end-to-end encryption purposes. +/// +/// \since QXmpp 1.5 +/// +QXmppE2eeMetadata QXmppStanza::e2eeMetadata() const +{ + return d->e2eeMetadata; +} + +/// +/// Sets additional data for end-to-end encryption purposes. +/// +/// \since QXmpp 1.5 +/// +void QXmppStanza::setE2eeMetadata(const QXmppE2eeMetadata &e2eeMetadata) +{ + d->e2eeMetadata = e2eeMetadata; +} + /// \cond void QXmppStanza::generateAndSetNextId() { diff --git a/src/base/QXmppStanza.h b/src/base/QXmppStanza.h index 84f731c5..34cd1aed 100644 --- a/src/base/QXmppStanza.h +++ b/src/base/QXmppStanza.h @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com> // SPDX-FileCopyrightText: 2010 Jeremy LainĂ© <jeremy.laine@m4x.org> // SPDX-FileCopyrightText: 2015 Georg Rudoy <0xd34df00d@gmail.com> +// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de> // // SPDX-License-Identifier: LGPL-2.1-or-later @@ -63,6 +64,28 @@ private: QSharedDataPointer<QXmppExtendedAddressPrivate> d; }; +class QXmppE2eeMetadataPrivate; + +class QXMPP_EXPORT QXmppE2eeMetadata +{ +public: + QXmppE2eeMetadata(); + QXmppE2eeMetadata(const QXmppE2eeMetadata &other); + ~QXmppE2eeMetadata(); + + QXmppE2eeMetadata &operator=(const QXmppE2eeMetadata &other); + + QByteArray senderKey() const; + void setSenderKey(const QByteArray &keyId); + + // XEP-0420: Stanza Content Encryption + QDateTime sceTimestamp() const; + void setSceTimestamp(const QDateTime ×tamp); + +private: + QSharedDataPointer<QXmppE2eeMetadataPrivate> d; +}; + class QXmppStanzaPrivate; class QXmppStanzaErrorPrivate; @@ -202,6 +225,9 @@ public: QList<QXmppExtendedAddress> extendedAddresses() const; void setExtendedAddresses(const QList<QXmppExtendedAddress> &extendedAddresses); + QXmppE2eeMetadata e2eeMetadata() const; + void setE2eeMetadata(const QXmppE2eeMetadata &e2eeMetadata); + /// \cond void parse(const QDomElement &element) override; |
