QXmpp::OmemoManager Class
class QXmpp::OmemoManagerThe OmemoManager class implements XEP-0384: OMEMO Encryption as OMEMO 0 (eu.siacs.conversations.axolotl, version 0.3) and OMEMO 2 (urn:xmpp:omemo:2, version 0.8 and later). More...
| Header: | #include <QXmppOmemoManager.h> |
| Since: | QXmpp 1.18 |
| Inherits: | QXmppClientExtension |
Public Types
| struct | DefaultDeviceLabel |
| struct | NoDeviceLabel |
| DeviceLabel | |
| enum class | State { Loading, NotSetUp, SettingUp, Ready } |
Public Functions
| OmemoManager(std::shared_ptr<QXmpp::OmemoStorage> storage, QList<QXmpp::Omemo::Version> versions = { Omemo::Version::Omemo0, Omemo::Version::Omemo2 }) | |
| QXmppTask<void> | authenticate(const QXmppUri &uri) |
| QXmppTask<void> | authenticate(QXmpp::Jid jid, QList<QByteArray> fingerprints) |
| QXmpp::OmemoManager::DeviceLabel | deviceLabel() const |
| QString | effectiveDeviceLabel() const |
| QBindable<QList<QXmpp::Omemo::Version>> | enabledVersions() const |
| QBindable<uint32_t> | ownDeviceId() const |
| QBindable<QByteArray> | ownKey(QXmpp::Omemo::Version version = Omemo::Version::Omemo2) const |
| QXmppTask<void> | removeContactDevices(QXmpp::Jid contactJid) |
| QXmppTask<QXmpp::Result<>> | resetAll() |
| QXmppTask<QXmpp::Result<>> | resetOwnDevice() |
| QXmppTask<void> | resetOwnDeviceLocally() |
| QXmppTask<QXmpp::TrustSecurityPolicy> | securityPolicy() |
| void | setDeviceLabel(const QXmpp::OmemoManager::DeviceLabel &label) |
| void | setEnabledVersions(QList<QXmpp::Omemo::Version> versions) |
| QXmppTask<void> | setSecurityPolicy(QXmpp::TrustSecurityPolicy securityPolicy) |
| QXmppTask<void> | setTrustLevel(QList<QXmpp::Omemo::Device> devices, QXmpp::TrustLevel trustLevel) |
| QBindable<QXmpp::OmemoManager::State> | state() const |
| QXmpp::Omemo::DeviceWatch | watchDevices(const QXmpp::Jid &jid) |
Signals
| void | errorOccurred(const QXmppError &error) |
Static Public Members
| QString | defaultDeviceLabel() |
| bool | isAuthenticationUri(const QXmppUri &uri) |
Detailed Description
Both versions use the same device ID and identity key, so a device has one fingerprint. Pre keys, sessions and the known devices are separate per version.
The manager loads its data from the storage when it is added to a client. On the first login, it creates the own device and publishes it. On each further login (not after resuming the stream), it renews the keys and publishes the data again.
QXmppPubSubManager and a QXmppTrustManager must be added to the client before this manager.
Trust
The trust levels of the keys are stored by the trust manager, separately for each version. Since a device uses the same identity key in both versions, a trust decision for a key is applied to the key of the same device in the other version, so a device has to be authenticated only once. Keys are authenticated via authenticate() or setTrustLevel().
The security policy (see QXmpp::TrustSecurityPolicy) decides the trust level of new keys. By default, TOAKAFA is used: New keys of a JID are trusted automatically until a key of the JID has been authenticated in either version. Then its automatically trusted keys are distrusted in both versions and its new keys are distrusted automatically. With QXmpp::NoSecurityPolicy, new keys are distrusted automatically and must be trusted manually. Messages are only encrypted for keys with trust levels accepted by QXmppSendStanzaParams::acceptedTrustLevels(). Sending fails with QXmpp::SendError::NoEncryptionRecipients if no device of the recipients has such a key, and for a message to the own JID if there is no other own device with such a key.
The security policy can be changed via setSecurityPolicy(). For authenticating keys via XEP-0450: Automatic Trust Management (ATM), a QXmppAtmManager should be used as the trust manager. It is recommended to use TOAKAFA with it.
A stanza is encrypted for at most 500 devices, the other own devices first, so that it stays below the stanza size limit of servers. Devices above the limit cannot decrypt it.
Selecting the version
Messages are encrypted with the version selected via the QXmpp::Messages::SelectEncryption hook: QXmpp::E2ee::Omemo0, QXmpp::E2ee::Omemo2 or QXmpp::Omemo::Automatic. The automatic mode encrypts for each device with the best version it supports, so a message contains elements of both versions only if a recipient's device does not support OMEMO 2. Contacts and groups can be migrated without losing devices supporting only OMEMO 0, e.g. Conversations and Dino. IQs are always encrypted with OMEMO 2.
In the automatic mode, a device using OMEMO 2 is never encrypted for with OMEMO 0 later, even if it is removed from the OMEMO 2 device list while it is still in the OMEMO 0 one. That could be used by a server to make the clients fall back to OMEMO 0. A device that disables OMEMO 2 later (see setEnabledVersions()) can therefore not decrypt the messages of contacts using the automatic mode. Devices are only known to use OMEMO 2 after it has been encrypted for them once, before that a server can still hide their OMEMO 2 device list.
OMEMO 0 only encrypts the body. The other sensitive elements, e.g. replies, reactions and chat states, are dropped for its devices unless they are allowed in the clear via the QXmpp::Messages::PrepareBodyOnly hook. Corrections and messages without body are not encrypted for them by default.
The other elements of received OMEMO 0 messages have been sent in the clear, so they are not protected by the key of the sender: anyone on the path, e.g. a server, can add or change elements such as corrections, retractions, replies, reactions or file sharing next to an authentic body. Such messages have QXmpp::E2ee::ContentEncryption::BodyOnly in QXmppE2eeMetadata::contentEncryption(). Applications decide which of their elements to use, e.g. only low-risk ones like receipts and chat markers, or show them as not protected. Trust messages of such messages are not used.
Stanzas of JIDs that are neither the own one nor in the roster, nor watched, nor known from their device lists, e.g. from strangers, are decrypted, but they cause no stanzas and no requests: key exchanges are not answered and sessions are not rebuilt automatically until the user interacts with the JID, e.g. by watching its devices (see watchDevices()) or by sending a message. Otherwise anyone could find out whether this device is online. At most 20 devices per JID and version that are not in its device list are stored.
For a message sent via QXmppClient::sendMessage() in the automatic mode, QXmpp::Messages::Sent::encryption() is QXmpp::E2ee::Omemo2 if at least one device has been encrypted for with OMEMO 2, also if other devices got OMEMO 0, and QXmpp::E2ee::Omemo0 otherwise. This is also the namespace announced via XEP-0380: Explicit Message Encryption. QXmpp::Messages::Sent::contentEncryption() is QXmpp::E2ee::ContentEncryption::BodyOnly if any device got OMEMO 0. The version of each device is reported in QXmpp::Omemo::EncryptionInfo.
Member Type Documentation
[alias] OmemoManager::DeviceLabel
The label of this device: DefaultDeviceLabel, NoDeviceLabel or a custom label. An empty custom label is not published.
enum class OmemoManager::State
| Constant | Value | Description |
|---|---|---|
QXmpp::OmemoManager::State::Loading | 0 | The data is being loaded from the storage. |
QXmpp::OmemoManager::State::NotSetUp | 1 | There is no own device yet. It is created on the next login. |
QXmpp::OmemoManager::State::SettingUp | 2 | The own device is being created. |
QXmpp::OmemoManager::State::Ready | 3 | The own device exists and stanzas can be encrypted and decrypted. |
Member Function Documentation
[explicit] OmemoManager::OmemoManager(std::shared_ptr<QXmpp::OmemoStorage> storage, QList<QXmpp::Omemo::Version> versions = { Omemo::Version::Omemo0, Omemo::Version::Omemo2 })
Constructs a manager storing its data in storage and using versions.
QXmppTask<void> OmemoManager::authenticate(const QXmppUri &uri)
Authenticates and distrusts the keys of the JID of uri as contained in it, e.g. after the user has scanned a QR code of another device (see DeviceWatch::authenticationUri()). The JID should be checked before, e.g. whether it is the one of the chat whose keys are authenticated.
The keys of OMEMO 2 are authenticated via XEP-0450: Automatic Trust Management (ATM) if the trust manager is a QXmppAtmManager, which sends trust messages to the devices with authenticated keys. Since trust messages exist only for OMEMO 2, the keys of OMEMO 0 are authenticated directly, together with the OMEMO 2 keys of the same devices.
With the security policy TOAKAFA, the automatically trusted keys of the JID are distrusted in all versions, see QXmpp::TrustSecurityPolicy.
See also isAuthenticationUri().
QXmppTask<void> OmemoManager::authenticate(QXmpp::Jid jid, QList<QByteArray> fingerprints)
Authenticates the keys of jid with fingerprints, e.g. entered by the user after comparing them with the ones shown by the other device (see Device::fingerprint()).
Fingerprints of known OMEMO 0 devices authenticate their keys, all others are authenticated as keys of OMEMO 2, also if their devices are not known yet. Keys are authenticated like by authenticate(const QXmppUri &).
[static] QString OmemoManager::defaultDeviceLabel()
Returns the label used for this device with DefaultDeviceLabel: the application name and the name of the operating system without its version, e.g. "Kaidan (Debian GNU/Linux)". The application name is QGuiApplication::applicationDisplayName() if set, otherwise QCoreApplication::applicationName(). The host name is not used, because the device list can be read by everyone.
QXmpp::OmemoManager::DeviceLabel OmemoManager::deviceLabel() const
Returns the label of this device as set via setDeviceLabel().
See also setDeviceLabel() and effectiveDeviceLabel().
QString OmemoManager::effectiveDeviceLabel() const
Returns the label of this device that is published in the OMEMO 2 device list. It is empty if no label is published.
QBindable<QList<QXmpp::Omemo::Version>> OmemoManager::enabledVersions() const
Returns the versions used for publishing and receiving. The bindable is read-only, the versions are changed via setEnabledVersions().
See also setEnabledVersions().
[signal] void OmemoManager::errorOccurred(const QXmppError &error)
[static] bool OmemoManager::isAuthenticationUri(const QXmppUri &uri)
Returns whether uri contains keys that can be authenticated via authenticate(), e.g. scanned from a QR code: keys of OMEMO 2 in a trust message (XEP-0434: Trust Messages) or of OMEMO 0 in the format of Conversations (omemo-sid-<device ID>=<fingerprint>).
See also DeviceWatch::authenticationUri().
QBindable<uint32_t> OmemoManager::ownDeviceId() const
Returns the ID of this device, 0 while there is none.
QBindable<QByteArray> OmemoManager::ownKey(QXmpp::Omemo::Version version = Omemo::Version::Omemo2) const
Returns the public identity key of this device in the format of version, empty while there is none.
Both versions share the same identity key. For OMEMO 2, it is in its Ed25519 form. For OMEMO 0, it is in its Curve25519 form with the type prefix (0x05), as used in the bundles and shown as fingerprint by other OMEMO 0 clients.
The format is the same as of Device::keyId.
QXmppTask<void> OmemoManager::removeContactDevices(QXmpp::Jid contactJid)
Removes the devices of jid, their sessions and the trust levels of their keys. This should be called after removing a contact. The own JID must not be passed, see resetAll().
If the presence subscription of the contact persists, its devices are added again on the next device list notification.
QXmppTask<QXmpp::Result<>> OmemoManager::resetAll()
Deletes the device lists and bundles of all own devices of the enabled versions from the server and resets the data of this device like resetOwnDeviceLocally(). The other own devices publish their data again when they are notified about it or on their next login. The user must be logged in.
Use this only if the OMEMO setup of the account cannot be recovered otherwise.
QXmppTask<QXmpp::Result<>> OmemoManager::resetOwnDevice()
Removes this device from the own device lists and its bundles from the server, and resets its local data like resetOwnDeviceLocally(). The data is only reset if the server data has been removed. The user must be logged in.
Call this when the account is removed from this device. A new device is created on the next login.
QXmppTask<void> OmemoManager::resetOwnDeviceLocally()
Resets the OMEMO data of this device and the trust data of OMEMO without changing the data on the server. Use this after the account has been removed from the server.
QXmppTask<QXmpp::TrustSecurityPolicy> OmemoManager::securityPolicy()
Returns the security policy deciding the trust level of new keys, the one of OMEMO 2 if it has been set differently per version via the trust manager.
See also setSecurityPolicy().
void OmemoManager::setDeviceLabel(const QXmpp::OmemoManager::DeviceLabel &label)
Sets the label of this device that is published in the OMEMO 2 device list.
The label is not stored, so a custom label must be set again after each start. It is published with a signature created with the identity key of this device on the next login or immediately while being logged in.
See also deviceLabel().
void OmemoManager::setEnabledVersions(QList<QXmpp::Omemo::Version> versions)
Sets the versions used for publishing and receiving.
While being logged in, the own device is published for added versions and removed from the device lists of removed versions immediately, otherwise on the next login. The service discovery features change with the next presence.
To keep decrypting messages of a version without encrypting with it anymore, e.g. OMEMO 0, leave it enabled and select only the other version via QXmpp::Messages::SelectEncryption.
See also enabledVersions().
QXmppTask<void> OmemoManager::setSecurityPolicy(QXmpp::TrustSecurityPolicy securityPolicy)
Sets the security policy deciding the trust level of new keys in both versions to securityPolicy. The default is QXmpp::Toakafa.
The security policy is stored by the trust manager and kept after a restart and after resetting the own device. It can also be set before the first setup.
The trust levels of known keys are not changed.
The manager must have been added to the client.
See also securityPolicy() and QXmpp::TrustSecurityPolicy.
QXmppTask<void> OmemoManager::setTrustLevel(QList<QXmpp::Omemo::Device> devices, QXmpp::TrustLevel trustLevel)
Sets the trust level of the keys of devices to trustLevel, e.g. after the user has authenticated them. Devices with unknown keys are skipped.
With the security policy TOAKAFA, authenticating keys distrusts the automatically trusted keys of their JIDs, see QXmpp::TrustSecurityPolicy.
QBindable<QXmpp::OmemoManager::State> OmemoManager::state() const
Returns the state of this device.
QXmpp::Omemo::DeviceWatch OmemoManager::watchDevices(const QXmpp::Jid &jid)
Returns a watch on the devices of jid listed in the device lists of all versions with their keys and trust levels, sorted by version and ID. This device is not included.
The known devices are available without network access, also while being disconnected. While a copy of the watch exists, the device lists of all versions are requested once per login. Without presence subscription, i.e. without notifications about changed device lists, the device lists of the enabled versions are subscribed to explicitly. The subscriptions are kept until the next login, so the device lists are not requested again if jid is watched again in the same session. Sessions with the devices with accepted trust levels are built in advance, so the first message can be encrypted faster and the keys of the devices become known. With both versions enabled, only the key of OMEMO 0 is fetched for a device using OMEMO 2, since it gets messages only with OMEMO 2.
The explicit subscriptions use the full JID of this client. The service of jid, and possibly jid itself, can therefore see the resource and that its devices have been watched, e.g. that its chat has been opened.
A chat should keep a watch while it is open. A watch can also be used to show the keys of a contact, e.g. to authenticate them.