QXmpp: QXmppOmemoManager.h Source File

QXmpp Version: 1.14.4

Loading...
Searching...
No Matches
QXmppOmemoManager.h
1// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPOMEMOMANAGER_H
6#define QXMPPOMEMOMANAGER_H
7
8#include "QXmppClientExtension.h"
9#include "QXmppE2eeExtension.h"
10#include "QXmppMessageHandler.h"
11#include "QXmppPubSubEventHandler.h"
12#include "QXmppTrustSecurityPolicy.h"
13#include "qxmppomemo_export.h"
14
15class QXmppOmemoDevicePrivate;
16class QXmppOmemoManagerPrivate;
17class QXmppOmemoOwnDevicePrivate;
18class QXmppOmemoStorage;
19
20 class QXMPPOMEMO_EXPORT QXmppOmemoOwnDevice
21{
22public:
23 QXmppOmemoOwnDevice();
24 QXmppOmemoOwnDevice(const QXmppOmemoOwnDevice &other);
25 QXmppOmemoOwnDevice(QXmppOmemoOwnDevice &&) noexcept;
26 ~QXmppOmemoOwnDevice();
27
28 QXmppOmemoOwnDevice &operator=(const QXmppOmemoOwnDevice &);
29 QXmppOmemoOwnDevice &operator=(QXmppOmemoOwnDevice &&);
30
31 QString label() const;
32 void setLabel(const QString &label);
33
34 QByteArray keyId() const;
35 void setKeyId(const QByteArray &keyId);
36
37private:
38 QSharedDataPointer<QXmppOmemoOwnDevicePrivate> d;
39};
40
41class QXMPPOMEMO_EXPORT QXmppOmemoDevice
42{
43public:
44 QXmppOmemoDevice();
45 QXmppOmemoDevice(const QXmppOmemoDevice &other);
46 QXmppOmemoDevice(QXmppOmemoDevice &&) noexcept;
47 ~QXmppOmemoDevice();
48
49 QXmppOmemoDevice &operator=(const QXmppOmemoDevice &);
50 QXmppOmemoDevice &operator=(QXmppOmemoDevice &&);
51
52 QString jid() const;
53 void setJid(const QString &jid);
54
55 QString label() const;
56 void setLabel(const QString &label);
57
58 QByteArray keyId() const;
59 void setKeyId(const QByteArray &keyId);
60
61 QXmpp::TrustLevel trustLevel() const;
62 void setTrustLevel(QXmpp::TrustLevel trustLevel);
63
64private:
65 QSharedDataPointer<QXmppOmemoDevicePrivate> d;
66};
67
68class QXMPPOMEMO_EXPORT QXmppOmemoManager : public QXmppClientExtension, public QXmppE2eeExtension, public QXmppPubSubEventHandler, public QXmppMessageHandler
69{
70 Q_OBJECT
71
72public:
73 using Result = std::variant<QXmpp::Success, QXmppError>;
74
75 struct DevicesResult {
76 QString jid;
77 Result result;
78 };
79
80 explicit QXmppOmemoManager(QXmppOmemoStorage *omemoStorage);
81 ~QXmppOmemoManager() override;
82
83 QXmppTask<bool> load();
84 QXmppTask<bool> setUp(const QString &deviceLabel = {});
85
86 QXmppTask<QByteArray> ownKey();
87 QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> keys(QXmpp::TrustLevels trustLevels = {});
88 QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> keys(const QList<QString> &jids, QXmpp::TrustLevels trustLevels = {});
89
90 QXmppTask<bool> changeDeviceLabel(const QString &deviceLabel = {});
91
92 int maximumDevicesPerJid() const;
93 void setMaximumDevicesPerJid(int maximum);
94
95 int maximumDevicesPerStanza() const;
96 void setMaximumDevicesPerStanza(int maximum);
97
98 QXmppTask<QVector<DevicesResult>> requestDeviceLists(const QList<QString> &jids);
99 QXmppTask<QVector<DevicesResult>> subscribeToDeviceLists(const QList<QString> &jids);
100 QXmppTask<QVector<DevicesResult>> unsubscribeFromDeviceLists();
101
102 QXmppOmemoOwnDevice ownDevice();
103 QXmppTask<QVector<QXmppOmemoDevice>> devices();
104 QXmppTask<QVector<QXmppOmemoDevice>> devices(const QList<QString> &jids);
105 QXmppTask<Result> removeContactDevices(const QString &jid);
106
107 void setAcceptedSessionBuildingTrustLevels(QXmpp::TrustLevels trustLevels);
108 QXmpp::TrustLevels acceptedSessionBuildingTrustLevels();
109
110 void setNewDeviceAutoSessionBuildingEnabled(bool isNewDeviceAutoSessionBuildingEnabled);
111 bool isNewDeviceAutoSessionBuildingEnabled();
112
113 QXmppTask<void> buildMissingSessions(const QList<QString> &jids);
114
115 QXmppTask<bool> resetOwnDevice();
116 QXmppTask<void> resetOwnDeviceLocally();
117 QXmppTask<bool> resetAll();
118
119 QXmppTask<void> setSecurityPolicy(QXmpp::TrustSecurityPolicy securityPolicy);
120 QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy();
121
122 QXmppTask<void> setTrustLevel(const QMultiHash<QString, QByteArray> &keyIds, QXmpp::TrustLevel trustLevel);
123 QXmppTask<QXmpp::TrustLevel> trustLevel(const QString &keyOwnerJid, const QByteArray &keyId);
124
126 QXmppTask<MessageEncryptResult> encryptMessage(QXmppMessage &&message, const std::optional<QXmppSendStanzaParams> &params) override;
127 QXmppTask<MessageDecryptResult> decryptMessage(QXmppMessage &&message) override;
128
129 QXmppTask<IqEncryptResult> encryptIq(QXmppIq &&iq, const std::optional<QXmppSendStanzaParams> &params) override;
130 QXmppTask<IqDecryptResult> decryptIq(const QDomElement &element) override;
131
132 bool isEncrypted(const QDomElement &) override;
133 bool isEncrypted(const QXmppMessage &) override;
134
135 QStringList discoveryFeatures() const override;
136 bool handleStanza(const QDomElement &stanza) override;
137 bool handleMessage(const QXmppMessage &message) override;
139
140 Q_SIGNAL void trustLevelsChanged(const QMultiHash<QString, QByteArray> &modifiedKeys);
141
142 Q_SIGNAL void deviceAdded(const QString &jid, uint32_t deviceId);
143 Q_SIGNAL void deviceChanged(const QString &jid, uint32_t deviceId);
144 Q_SIGNAL void deviceRemoved(const QString &jid, uint32_t deviceId);
145 Q_SIGNAL void devicesRemoved(const QString &jid);
146 Q_SIGNAL void allDevicesRemoved();
147
148protected:
150 void onRegistered(QXmppClient *client) override;
151 void onUnregistered(QXmppClient *client) override;
152 bool handlePubSubEvent(const QDomElement &element, const QString &pubSubService, const QString &nodeName) override;
154
155private:
156 std::unique_ptr<QXmppOmemoManagerPrivate> d;
157
158 friend class QXmppOmemoManagerPrivate;
159 friend class tst_QXmppOmemoManager;
160};
161
162#endif // QXMPPOMEMOMANAGER_H
QXmppClientExtension::onUnregistered
virtual void onUnregistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:95
QXmppClientExtension::onRegistered
virtual void onRegistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:85
QXmppClientExtension::client
QXmppClient * client() const
Definition QXmppClientExtension.cpp:57
QXmppClientExtension::QXmppClientExtension
QXmppClientExtension()
Definition QXmppClientExtension.cpp:12
QXmppE2eeExtension
Definition QXmppE2eeExtension.h:23
QXmppMessageHandler
Definition QXmppMessageHandler.h:16
QXmppOmemoDevice::label
QString label() const
Definition QXmppOmemoManager.cpp:170
QXmppOmemoDevice::setTrustLevel
void setTrustLevel(QXmpp::TrustLevel trustLevel)
Definition QXmppOmemoManager.cpp:222
QXmppOmemoDevice::trustLevel
QXmpp::TrustLevel trustLevel() const
Definition QXmppOmemoManager.cpp:212
QXmppOmemoDevice::QXmppOmemoDevice
QXmppOmemoDevice()
Definition QXmppOmemoManager.cpp:128
QXmppOmemoDevice::keyId
QByteArray keyId() const
Definition QXmppOmemoManager.cpp:192
QXmppOmemoDevice::QXmppOmemoDevice
QXmppOmemoDevice(QXmppOmemoDevice &&) noexcept
Move-constructor.
QXmppOmemoDevice::QXmppOmemoDevice
QXmppOmemoDevice(const QXmppOmemoDevice &other)
Copy-constructor.
QXmppOmemoDevice::setLabel
void setLabel(const QString &label)
Definition QXmppOmemoManager.cpp:182
QXmppOmemoDevice::setKeyId
void setKeyId(const QByteArray &keyId)
Definition QXmppOmemoManager.cpp:202
QXmppOmemoDevice::jid
QString jid() const
Definition QXmppOmemoManager.cpp:148
QXmppOmemoDevice::setJid
void setJid(const QString &jid)
Definition QXmppOmemoManager.cpp:158
QXmppOmemoManager
Definition QXmppOmemoManager.h:69
QXmppOmemoManager::devicesRemoved
Q_SIGNAL void devicesRemoved(const QString &jid)
QXmppOmemoManager::deviceAdded
Q_SIGNAL void deviceAdded(const QString &jid, uint32_t deviceId)
QXmppOmemoManager::deviceChanged
Q_SIGNAL void deviceChanged(const QString &jid, uint32_t deviceId)
QXmppOmemoManager::Result
std::variant< QXmpp::Success, QXmppError > Result
Definition QXmppOmemoManager.h:73
QXmppOmemoManager::QXmppOmemoManager
QXmppOmemoManager(QXmppOmemoStorage *omemoStorage)
Definition QXmppOmemoManager.cpp:335
QXmppOmemoManager::deviceRemoved
Q_SIGNAL void deviceRemoved(const QString &jid, uint32_t deviceId)
QXmppOmemoManager::trustLevelsChanged
Q_SIGNAL void trustLevelsChanged(const QMultiHash< QString, QByteArray > &modifiedKeys)
QXmppOmemoManager::allDevicesRemoved
Q_SIGNAL void allDevicesRemoved()
QXmppOmemoOwnDevice::setLabel
void setLabel(const QString &label)
Definition QXmppOmemoManager.cpp:85
QXmppOmemoOwnDevice::keyId
QByteArray keyId() const
Definition QXmppOmemoManager.cpp:95
QXmppOmemoOwnDevice::setKeyId
void setKeyId(const QByteArray &keyId)
Definition QXmppOmemoManager.cpp:105
QXmppOmemoOwnDevice::QXmppOmemoOwnDevice
QXmppOmemoOwnDevice()
Definition QXmppOmemoManager.cpp:51
QXmppOmemoOwnDevice::label
QString label() const
Definition QXmppOmemoManager.cpp:73
QXmppOmemoOwnDevice::QXmppOmemoOwnDevice
QXmppOmemoOwnDevice(const QXmppOmemoOwnDevice &other)
Copy-constructor.
QXmppOmemoOwnDevice::QXmppOmemoOwnDevice
QXmppOmemoOwnDevice(QXmppOmemoOwnDevice &&) noexcept
Move-constructor.
QXmppOmemoStorage
The QXmppOmemoStorage class stores data used by XEP-0384: OMEMO Encryption.
Definition QXmppOmemoStorage.h:17
QXmppPubSubEventHandler
Definition QXmppPubSubEventHandler.h:15
QXmppPubSubEventHandler::handlePubSubEvent
virtual bool handlePubSubEvent(const QDomElement &element, const QString &pubSubService, const QString &nodeName)=0
QXmppTask
Definition QXmppTask.h:46
QXmpp
Definition Algorithms.h:14
QXmpp::TrustLevel
TrustLevel
Definition QXmppTrustLevel.h:19
QXmpp::TrustSecurityPolicy
TrustSecurityPolicy
Definition QXmppTrustSecurityPolicy.h:18