QXmpp Version: 1.10.0
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;
19
20class QXMPPOMEMO_EXPORT QXmppOmemoOwnDevice
21{
22public:
27
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:
48
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
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();
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();
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);
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
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:32
Main class for starting and managing connections to XMPP servers.
Definition: QXmppClient.h:62
Definition: QXmppE2eeExtension.h:23
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:23
Definition: QXmppMessageHandler.h:16
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:64
The QXmppOmemoDevice class represents a XEP-0384: OMEMO Encryption device.
Definition: QXmppOmemoManager.h:42
QXmppOmemoDevice(QXmppOmemoDevice &&) noexcept
Move-constructor.
QXmppOmemoDevice(const QXmppOmemoDevice &other)
Copy-constructor.
Definition: QXmppOmemoManager.h:69
Q_SIGNAL void deviceRemoved(const QString &jid, uint32_t deviceId)
std::variant< QXmpp::Success, QXmppError > Result
Definition: QXmppOmemoManager.h:73
Q_SIGNAL void allDevicesRemoved()
Q_SIGNAL void devicesRemoved(const QString &jid)
Q_SIGNAL void deviceAdded(const QString &jid, uint32_t deviceId)
Q_SIGNAL void trustLevelsChanged(const QMultiHash< QString, QByteArray > &modifiedKeys)
Q_SIGNAL void deviceChanged(const QString &jid, uint32_t deviceId)
The QXmppOmemoOwnDevice class represents the XEP-0384: OMEMO Encryption device of this client instanc...
Definition: QXmppOmemoManager.h:21
QXmppOmemoOwnDevice(const QXmppOmemoOwnDevice &other)
Copy-constructor.
QXmppOmemoOwnDevice(QXmppOmemoOwnDevice &&) noexcept
Move-constructor.
The QXmppOmemoStorage class stores data used by XEP-0384: OMEMO Encryption.
Definition: QXmppOmemoStorage.h:17
Definition: QXmppPubSubEventHandler.h:15
Definition: QXmppTask.h:62
Definition: Algorithms.h:12
TrustLevel
Definition: QXmppTrustLevel.h:19
TrustSecurityPolicy
Definition: QXmppTrustSecurityPolicy.h:18