6 #ifndef QXMPPOMEMOMANAGER_P_H 7 #define QXMPPOMEMOMANAGER_P_H 9 #include "QXmppConstants_p.h" 10 #include "QXmppE2eeMetadata.h" 11 #include "QXmppOmemoDeviceBundle_p.h" 12 #include "QXmppOmemoManager.h" 13 #include "QXmppOmemoStorage.h" 14 #include "QXmppPubSubManager.h" 17 #include "OmemoLibWrappers.h" 19 #include <QDomElement> 27 class QXmppPubSubNodeConfig;
28 class QXmppPubSubPublishOptions;
30 class QXmppOmemoEnvelope;
31 class QXmppOmemoElement;
32 class QXmppOmemoDeviceListItem;
33 class QXmppOmemoDeviceBundleItem;
35 using namespace QXmpp;
37 using SecureByteArray = QXmpp::Private::Crypto::SecureByteArray;
46 constexpr
int UNRESPONDED_STANZAS_UNTIL_ENCRYPTION_IS_STOPPED = 106;
49 constexpr
int UNRESPONDED_STANZAS_UNTIL_HEARTBEAT_MESSAGE_IS_SENT = 53;
52 constexpr
int EMPTY_MESSAGE_DECRYPTION_DATA_SIZE = 32;
56 constexpr uint64_t PUBSUB_NODE_MAX_ITEMS_1 = 1000;
57 constexpr uint64_t PUBSUB_NODE_MAX_ITEMS_2 = 100;
58 constexpr uint64_t PUBSUB_NODE_MAX_ITEMS_3 = 10;
60 constexpr uint32_t PRE_KEY_ID_MIN = 1;
61 constexpr uint32_t SIGNED_PRE_KEY_ID_MIN = 1;
62 constexpr uint32_t PRE_KEY_ID_MAX = std::numeric_limits<int32_t>::max();
63 constexpr uint32_t SIGNED_PRE_KEY_ID_MAX = std::numeric_limits<int32_t>::max();
64 constexpr uint32_t PRE_KEY_INITIAL_CREATION_COUNT = 100;
67 constexpr
int DEVICES_PER_JID_MAX = 200;
70 constexpr
int DEVICES_PER_STANZA_MAX = 1000;
73 constexpr
auto SIGNED_PRE_KEY_RENEWAL_INTERVAL = 24h * 7 * 4;
76 constexpr
auto SIGNED_PRE_KEY_RENEWAL_CHECK_INTERVAL = 24h;
79 constexpr
auto DEVICE_REMOVAL_INTERVAL = 24h * 7 * 12;
82 constexpr
auto DEVICE_REMOVAL_CHECK_INTERVAL = 24h;
84 inline constexpr
auto HKDF_INFO =
"OMEMO Payload";
85 constexpr
int HKDF_KEY_SIZE = 32;
86 constexpr
int HKDF_SALT_SIZE = 32;
87 constexpr
int HKDF_OUTPUT_SIZE = 80;
89 constexpr uint32_t PAYLOAD_MESSAGE_AUTHENTICATION_CODE_SIZE = 16;
91 constexpr
int PAYLOAD_KEY_SIZE = 32;
92 constexpr uint32_t PAYLOAD_INITIALIZATION_VECTOR_SIZE = 16;
93 constexpr uint32_t PAYLOAD_AUTHENTICATION_KEY_SIZE = 32;
96 constexpr uint32_t SCE_RPAD_SIZE_MIN = 0;
97 constexpr uint32_t SCE_RPAD_SIZE_MAX = 200;
99 struct PayloadEncryptionResult {
100 SecureByteArray decryptionData;
101 QByteArray encryptedPayload;
104 struct DecryptionResult {
105 QDomElement sceContent;
109 struct IqDecryptionResult {
119 class QXmppOmemoManagerPrivate
122 using Result = std::variant<QXmpp::Success, QXmppError>;
126 bool initialized =
false;
127 bool isNewDeviceAutoSessionBuildingEnabled =
false;
133 QTimer signedPreKeyPairsRenewalTimer;
134 QTimer deviceRemovalTimer;
136 TrustLevels acceptedSessionBuildingTrustLevels = ACCEPTED_TRUST_LEVELS;
139 QHash<uint32_t, QByteArray> preKeyPairs;
140 QHash<uint32_t, QXmppOmemoStorage::SignedPreKeyPair> signedPreKeyPairs;
141 QXmppOmemoDeviceBundle deviceBundle;
143 int maximumDevicesPerJid = DEVICES_PER_JID_MAX;
144 int maximumDevicesPerStanza = DEVICES_PER_STANZA_MAX;
147 QHash<QString, QHash<uint32_t, QXmppOmemoStorage::Device>> devices;
149 QList<QString> jidsOfManuallySubscribedDevices;
151 OmemoContextPtr globalContext;
152 StoreContextPtr storeContext;
153 QRecursiveMutex mutex;
154 signal_crypto_provider cryptoProvider;
156 signal_protocol_identity_key_store identityKeyStore;
157 signal_protocol_pre_key_store preKeyStore;
158 signal_protocol_signed_pre_key_store signedPreKeyStore;
159 signal_protocol_session_store sessionStore;
163 void initOmemoLibrary();
165 QXMPP_EXPORT
bool initGlobalContext();
166 QXMPP_EXPORT
bool initLocking();
167 QXMPP_EXPORT
bool initCryptoProvider();
170 signal_protocol_identity_key_store createIdentityKeyStore()
const;
171 signal_protocol_signed_pre_key_store createSignedPreKeyStore()
const;
172 signal_protocol_pre_key_store createPreKeyStore()
const;
173 signal_protocol_session_store createSessionStore()
const;
176 std::optional<uint32_t> generateDeviceId();
177 std::optional<uint32_t> generateDeviceId(
const QVector<QString> &existingIds);
178 bool setUpIdentityKeyPair(ratchet_identity_key_pair **identityKeyPair);
179 void schedulePeriodicTasks();
180 void renewSignedPreKeyPairs();
181 bool updateSignedPreKeyPair(ratchet_identity_key_pair *identityKeyPair);
182 bool renewPreKeyPairs(uint32_t keyPairBeingRenewed);
183 bool updatePreKeyPairs(uint32_t count = 1);
184 void removeDevicesRemovedFromServer();
187 QVector<QString> recipientJids,
188 TrustLevels acceptedTrustLevels);
191 std::optional<PayloadEncryptionResult> encryptPayload(
const QByteArray &payload)
const;
193 QByteArray createSceEnvelope(
const T &stanza);
194 QByteArray createOmemoEnvelopeData(
const signal_protocol_address &address,
const SecureByteArray &payloadDecryptionData)
const;
201 uint32_t senderDeviceId,
202 const QXmppOmemoEnvelope &omemoEnvelope,
203 const QByteArray &omemoPayload,
204 bool isMessageStanza =
true);
206 uint32_t senderDeviceId,
207 const QXmppOmemoEnvelope &omemoEnvelope,
208 QByteArray omemoPayload,
209 bool isMessageStanza);
211 uint32_t senderDeviceId,
212 QXmppOmemoEnvelope omemoEnvelope,
213 bool isMessageStanza =
true);
214 QByteArray decryptPayload(
const SecureByteArray &payloadDecryptionData,
const QByteArray &payload)
const;
219 bool arePublishOptionsSupported,
220 bool isAutomaticCreationSupported,
221 bool isCreationAndConfigurationSupported,
222 bool isCreationSupported,
223 bool isConfigurationSupported,
224 bool isConfigNodeMaxSupported);
225 QXmppTask<bool> publishDeviceBundleWithoutOptions(
bool isDeviceBundlesNodeExistent,
226 bool isCreationAndConfigurationSupported,
227 bool isCreationSupported,
228 bool isConfigurationSupported,
229 bool isConfigNodeMaxSupported);
230 QXmppTask<bool> configureNodeAndPublishDeviceBundle(
bool isConfigNodeMaxSupported);
231 QXmppTask<bool> createAndConfigureDeviceBundlesNode(
bool isConfigNodeMaxSupported);
233 QXmppTask<bool> configureDeviceBundlesNode(
bool isConfigNodeMaxSupported);
236 QXmppOmemoDeviceBundleItem deviceBundleItem()
const;
241 bool arePublishOptionsSupported,
242 bool isAutomaticCreationSupported,
243 bool isCreationAndConfigurationSupported,
244 bool isCreationSupported,
245 bool isConfigurationSupported);
246 QXmppTask<bool> publishDeviceElementWithoutOptions(
bool isDeviceListNodeExistent,
247 bool isCreationAndConfigurationSupported,
248 bool isCreationSupported,
249 bool isConfigurationSupported);
256 QXmppOmemoDeviceListItem deviceListItem(
bool addOwnDevice =
true);
257 QXmppTask<bool> updateOwnDevicesLocally(
bool isDeviceListNodeExistent);
258 std::optional<QXmppOmemoDeviceListItem> updateContactDevices(
const QString &deviceOwnerJid,
const QVector<QXmppOmemoDeviceListItem> &deviceListItems);
259 void updateDevices(
const QString &deviceOwnerJid,
const QXmppOmemoDeviceListItem &deviceListItem);
260 void handleIrregularDeviceListChanges(
const QString &deviceOwnerJid);
264 QXmppTask<bool> createNode(
const QString &node,
const QXmppPubSubNodeConfig &config);
265 QXmppTask<bool> configureNode(
const QString &node,
const QXmppPubSubNodeConfig &config);
272 QXmppTask<bool> publishItem(
const QString &node,
const T &item,
const QXmppPubSubPublishOptions &publishOptions);
280 void subscribeToNewDeviceLists(
const QString &jid, uint32_t deviceId);
288 void resetCachedData();
292 bool buildSession(signal_protocol_address address,
const QXmppOmemoDeviceBundle &deviceBundle);
293 bool createSessionBundle(session_pre_key_bundle **sessionBundle,
294 const QByteArray &serializedPublicIdentityKey,
295 const QByteArray &serializedSignedPublicPreKey,
296 uint32_t signedPublicPreKeyId,
297 const QByteArray &serializedSignedPublicPreKeySignature,
298 const QByteArray &serializedPublicPreKey,
299 uint32_t publicPreKeyId);
301 bool deserializeIdentityKeyPair(ratchet_identity_key_pair **identityKeyPair)
const;
302 bool deserializePrivateIdentityKey(ec_private_key **privateIdentityKey,
const QByteArray &serializedPrivateIdentityKey)
const;
303 bool deserializePublicIdentityKey(ec_public_key **publicIdentityKey,
const QByteArray &serializedPublicIdentityKey)
const;
304 bool deserializeSignedPublicPreKey(ec_public_key **signedPublicPreKey,
const QByteArray &serializedSignedPublicPreKey)
const;
305 bool deserializePublicPreKey(ec_public_key **publicPreKey,
const QByteArray &serializedPublicPreKey)
const;
307 QXmppTask<QXmpp::SendResult> sendEmptyMessage(
const QString &recipientJid, uint32_t recipientDeviceId,
bool isKeyExchange =
false)
const;
311 QString ownBareJid()
const;
312 QString ownFullJid()
const;
313 QHash<uint32_t, QXmppOmemoStorage::Device> otherOwnDevices();
315 void warning(
const QString &msg)
const;
318 #endif // QXMPPOMEMOMANAGER_P_H
TrustLevel
Definition: QXmppTrustLevel.h:19
The QXmppOmemoStorage class stores data used by XEP-0384: OMEMO Encryption.
Definition: QXmppOmemoStorage.h:16
Definition: QXmppTask.h:67
The key is manually trusted (e.g., by clicking a button).
The QXmppTrustManager manages end-to-end encryption trust decisions.
Definition: QXmppTrustManager.h:17
Definition: QXmppOmemoManager.h:68
Definition: QXmppOmemoStorage.h:70
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:63
Definition: Algorithms.h:14
The QXmppPubSubManager aims to provide publish-subscribe functionality as specified in XEP-0060: Publ...
Definition: QXmppPubSubManager.h:20
Definition: OmemoCryptoProvider.cpp:174
Definition: QXmppOmemoStorage.h:22
std::variant< T, QXmppError > Result
Definition: QXmppGlobal.h:209