diff options
| author | Melvin Keskin <melvo@olomono.de> | 2022-04-19 20:05:16 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-05-06 13:36:43 +0200 |
| commit | 4c565dd7dd78340a393ccbf4bc3bed9f6ce360f2 (patch) | |
| tree | bc8f94f355a90b3c5b0380993ed13fd5d2e02032 | |
| parent | 2000431680f4ddf58f3fbe9ea138dd18bc9a1b8c (diff) | |
| download | qxmpp-4c565dd7dd78340a393ccbf4bc3bed9f6ce360f2.tar.gz | |
Add QXmppTrustManager as base of trust managers such as QXmppAtmManager
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/client/QXmppAtmManager.cpp | 23 | ||||
| -rw-r--r-- | src/client/QXmppAtmManager.h | 9 | ||||
| -rw-r--r-- | src/client/QXmppTrustManager.cpp | 282 | ||||
| -rw-r--r-- | src/client/QXmppTrustManager.h | 59 | ||||
| -rw-r--r-- | src/client/QXmppTrustMemoryStorage.cpp | 26 | ||||
| -rw-r--r-- | src/client/QXmppTrustMemoryStorage.h | 4 | ||||
| -rw-r--r-- | src/client/QXmppTrustStorage.cpp | 11 | ||||
| -rw-r--r-- | src/client/QXmppTrustStorage.h | 4 | ||||
| -rw-r--r-- | tests/qxmppatmmanager/tst_qxmppatmmanager.cpp | 194 |
10 files changed, 487 insertions, 127 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 426ea495..6425756b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,6 +113,7 @@ set(INSTALL_HEADER_FILES client/QXmppRpcManager.h client/QXmppTransferManager.h client/QXmppTransferManager_p.h + client/QXmppTrustManager.h client/QXmppTrustMemoryStorage.h client/QXmppTrustStorage.h client/QXmppUploadRequestManager.h @@ -224,6 +225,7 @@ set(SOURCE_FILES client/QXmppRpcManager.cpp client/QXmppTlsManager.cpp client/QXmppTransferManager.cpp + client/QXmppTrustManager.cpp client/QXmppTrustMemoryStorage.cpp client/QXmppTrustStorage.cpp client/QXmppUploadRequestManager.cpp diff --git a/src/client/QXmppAtmManager.cpp b/src/client/QXmppAtmManager.cpp index ca5b5f9e..b7ea5660 100644 --- a/src/client/QXmppAtmManager.cpp +++ b/src/client/QXmppAtmManager.cpp @@ -61,8 +61,8 @@ using namespace QXmpp::Private; /// \param trustStorage trust storage implementation /// QXmppAtmManager::QXmppAtmManager(QXmppAtmTrustStorage *trustStorage) + : QXmppTrustManager(trustStorage) { - m_trustStorage = trustStorage; } /// @@ -79,7 +79,7 @@ QFuture<void> QXmppAtmManager::makeTrustDecisions(const QString &encryption, con { QFutureInterface<void> interface(QFutureInterfaceBase::Started); - auto future = m_trustStorage->keys(encryption, QXmppTrustStorage::Authenticated | QXmppTrustStorage::ManuallyDistrusted); + auto future = keys(encryption, QXmppTrustStorage::Authenticated | QXmppTrustStorage::ManuallyDistrusted); await(future, this, [=](const QHash<QXmppTrustStorage::TrustLevel, QMultiHash<QString, QByteArray>> &&keys) mutable { const auto authenticatedKeys = keys.value(QXmppTrustStorage::Authenticated); const auto manuallyDistrustedKeys = keys.value(QXmppTrustStorage::ManuallyDistrusted); @@ -301,7 +301,7 @@ QFuture<void> QXmppAtmManager::handleMessage(const QXmppMessage &message) const auto senderKey = e2eeMetadata ? e2eeMetadata->senderKey() : QByteArray(); const auto encryption = trustMessageElement->encryption(); - auto future = m_trustStorage->trustLevel(encryption, senderJid, senderKey); + auto future = trustLevel(encryption, senderJid, senderKey); await(future, this, [=](const auto &&senderKeyTrustLevel) mutable { const auto isSenderKeyAuthenticated = senderKeyTrustLevel == QXmppTrustStorage::Authenticated; @@ -347,7 +347,7 @@ QFuture<void> QXmppAtmManager::handleMessage(const QXmppMessage &message) } } - auto future = m_trustStorage->addKeysForPostponedTrustDecisions(encryption, senderKey, keyOwnersForPostponedTrustDecisions); + auto future = trustStorage()->addKeysForPostponedTrustDecisions(encryption, senderKey, keyOwnersForPostponedTrustDecisions); await(future, this, [=]() mutable { auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); await(future, this, [=]() mutable { @@ -380,9 +380,10 @@ QFuture<void> QXmppAtmManager::authenticate(const QString &encryption, const QMu QFutureInterface<void> interface(QFutureInterfaceBase::Started); - auto future = m_trustStorage->setTrustLevel(encryption, keyIds, QXmppTrustStorage::Authenticated); + auto future = setTrustLevel(encryption, keyIds, QXmppTrustStorage::Authenticated); await(future, this, [=]() mutable { - await(m_trustStorage->securityPolicy(encryption), this, [=](const auto securityPolicy) mutable { + auto future = securityPolicy(encryption); + await(future, this, [=](auto securityPolicy) mutable { if (securityPolicy == QXmppTrustStorage::Toakafa) { auto future = distrustAutomaticallyTrustedKeys(encryption, keyIds.uniqueKeys()); await(future, this, [=]() mutable { @@ -417,9 +418,9 @@ QFuture<void> QXmppAtmManager::distrust(const QString &encryption, const QMultiH QFutureInterface<void> interface(QFutureInterfaceBase::Started); - auto future = m_trustStorage->setTrustLevel(encryption, keyIds, QXmppTrustStorage::ManuallyDistrusted); + auto future = setTrustLevel(encryption, keyIds, QXmppTrustStorage::ManuallyDistrusted); await(future, this, [=]() mutable { - auto future = m_trustStorage->removeKeysForPostponedTrustDecisions(encryption, keyIds.values()); + auto future = trustStorage()->removeKeysForPostponedTrustDecisions(encryption, keyIds.values()); await(future, this, [=]() mutable { interface.reportFinished(); }); @@ -437,7 +438,7 @@ QFuture<void> QXmppAtmManager::distrust(const QString &encryption, const QMultiH /// QFuture<void> QXmppAtmManager::distrustAutomaticallyTrustedKeys(const QString &encryption, const QList<QString> &keyOwnerJids) { - return m_trustStorage->setTrustLevel(encryption, keyOwnerJids, QXmppTrustStorage::AutomaticallyTrusted, QXmppTrustStorage::AutomaticallyDistrusted); + return setTrustLevel(encryption, keyOwnerJids, QXmppTrustStorage::AutomaticallyTrusted, QXmppTrustStorage::AutomaticallyDistrusted); } /// @@ -454,13 +455,13 @@ QFuture<void> QXmppAtmManager::makePostponedTrustDecisions(const QString &encryp { QFutureInterface<void> interface(QFutureInterfaceBase::Started); - auto future = m_trustStorage->keysForPostponedTrustDecisions(encryption, senderKeyIds); + auto future = trustStorage()->keysForPostponedTrustDecisions(encryption, senderKeyIds); await(future, this, [=](const QHash<bool, QMultiHash<QString, QByteArray>> &&keysForPostponedTrustDecisions) mutable { // JIDs of key owners mapped to the IDs of their keys const auto keysBeingAuthenticated = keysForPostponedTrustDecisions.value(true); const auto keysBeingDistrusted = keysForPostponedTrustDecisions.value(false); - auto future = m_trustStorage->removeKeysForPostponedTrustDecisions(encryption, keysBeingAuthenticated.values(), keysBeingDistrusted.values()); + auto future = trustStorage()->removeKeysForPostponedTrustDecisions(encryption, keysBeingAuthenticated.values(), keysBeingDistrusted.values()); await(future, this, [=]() mutable { auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); await(future, this, [=]() mutable { diff --git a/src/client/QXmppAtmManager.h b/src/client/QXmppAtmManager.h index 042d1342..d4145d06 100644 --- a/src/client/QXmppAtmManager.h +++ b/src/client/QXmppAtmManager.h @@ -6,13 +6,13 @@ #define QXMPPATMMANAGER_H #include "QXmppAtmTrustStorage.h" -#include "QXmppClientExtension.h" #include "QXmppSendResult.h" +#include "QXmppTrustManager.h" class QXmppMessage; class QXmppTrustMessageKeyOwner; -class QXMPP_EXPORT QXmppAtmManager : public QXmppClientExtension +class QXMPP_EXPORT QXmppAtmManager : public QXmppTrustManager { Q_OBJECT @@ -42,7 +42,10 @@ private: QFuture<QXmpp::SendResult> sendTrustMessage(const QString &encryption, const QList<QXmppTrustMessageKeyOwner> &keyOwners, const QString &recipientJid); - QXmppAtmTrustStorage *m_trustStorage; + inline QXmppAtmTrustStorage *trustStorage() const + { + return dynamic_cast<QXmppAtmTrustStorage *>(QXmppTrustManager::trustStorage()); + } friend class tst_QXmppAtmManager; }; diff --git a/src/client/QXmppTrustManager.cpp b/src/client/QXmppTrustManager.cpp new file mode 100644 index 00000000..094ed2f2 --- /dev/null +++ b/src/client/QXmppTrustManager.cpp @@ -0,0 +1,282 @@ +// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppTrustManager.h" + +#include "QXmppFutureUtils_p.h" + +using namespace QXmpp::Private; + +/// +/// \class QXmppTrustManager +/// +/// \brief The QXmppTrustManager manages end-to-end encryption trust decisions. +/// +/// \warning THIS API IS NOT FINALIZED YET! +/// +/// \ingroup Managers +/// +/// \since QXmpp 1.5 +/// + +/// +/// Constructs a trust manager. +/// +/// \param trustStorage trust storage implementation +/// +QXmppTrustManager::QXmppTrustManager(QXmppTrustStorage *trustStorage) + : m_trustStorage(trustStorage) +{ +} + +QXmppTrustManager::~QXmppTrustManager() = default; + +/// +/// Sets the security policy for an encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// \param securityPolicy security policy being applied +/// +QFuture<void> QXmppTrustManager::setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy) +{ + return m_trustStorage->setSecurityPolicy(encryption, securityPolicy); +} + +/// +/// Resets the security policy for an encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// +QFuture<void> QXmppTrustManager::resetSecurityPolicy(const QString &encryption) +{ + return m_trustStorage->resetSecurityPolicy(encryption); +} + +/// +/// Returns the security policy for an encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// +/// \return the set security policy +/// +QFuture<QXmppTrustStorage::SecurityPolicy> QXmppTrustManager::securityPolicy(const QString &encryption) +{ + return m_trustStorage->securityPolicy(encryption); +} + +/// +/// Sets the own key (i.e., the key used by this client instance) for an +/// encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// \param keyId ID of the key +/// +QFuture<void> QXmppTrustManager::setOwnKey(const QString &encryption, const QByteArray &keyId) +{ + return m_trustStorage->setOwnKey(encryption, keyId); +} + +/// +/// Resets the own key (i.e., the key used by this client instance) for an +/// encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// +QFuture<void> QXmppTrustManager::resetOwnKey(const QString &encryption) +{ + return m_trustStorage->resetOwnKey(encryption); +} + +/// +/// Returns the own key (i.e., the key used by this client instance) for an +/// encryption protocol. +/// +/// \param encryption encryption protocol namespace +/// +/// \return the ID of the own key +/// +QFuture<QByteArray> QXmppTrustManager::ownKey(const QString &encryption) +{ + return m_trustStorage->ownKey(encryption); +} + +/// +/// Adds keys. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJid key owner's bare JID +/// \param keyIds IDs of the keys +/// \param trustLevel trust level of the keys +/// +QFuture<void> QXmppTrustManager::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +{ + return m_trustStorage->addKeys(encryption, keyOwnerJid, keyIds, trustLevel); +} + +/// +/// Removes keys. +/// +/// \param encryption encryption protocol namespace +/// \param keyIds IDs of the keys +/// +QFuture<void> QXmppTrustManager::removeKeys(const QString &encryption, const QList<QByteArray> &keyIds) +{ + return m_trustStorage->removeKeys(encryption, keyIds); +} + +/// +/// Removes all keys of a key owner. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJid key owner's bare JID +/// +QFuture<void> QXmppTrustManager::removeKeys(const QString &encryption, const QString &keyOwnerJid) +{ + return m_trustStorage->removeKeys(encryption, keyOwnerJid); +} + +/// +/// Removes all keys for encryption. +/// +/// \param encryption encryption protocol namespace +/// +QFuture<void> QXmppTrustManager::removeKeys(const QString &encryption) +{ + return m_trustStorage->removeKeys(encryption); +} + +/// +/// Returns the JIDs of all key owners mapped to the IDs of their keys with +/// specific trust levels. +/// +/// If no trust levels are passed, all keys for encryption are returned. +/// +/// \param encryption encryption protocol namespace +/// \param trustLevels trust levels of the keys +/// +/// \return the key owner JIDs mapped to their keys with specific trust levels +/// +QFuture<QHash<QXmppTrustStorage::TrustLevel, QMultiHash<QString, QByteArray>>> QXmppTrustManager::keys(const QString &encryption, QXmppTrustStorage::TrustLevels trustLevels) +{ + return m_trustStorage->keys(encryption, trustLevels); +} + +/// +/// Returns the IDs of keys mapped to their trust levels for specific key +/// owners. +/// +/// If no trust levels are passed, all keys for encryption and keyOwnerJids are +/// returned. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJids key owners' bare JIDs +/// \param trustLevels trust levels of the keys +/// +/// \return the key IDs mapped to their trust levels for specific key owners +/// +QFuture<QHash<QString, QHash<QByteArray, QXmppTrustStorage::TrustLevel>>> QXmppTrustManager::keys(const QString &encryption, const QList<QString> &keyOwnerJids, QXmppTrustStorage::TrustLevels trustLevels) +{ + return m_trustStorage->keys(encryption, keyOwnerJids, trustLevels); +} + +/// +/// Returns whether at least one key of a key owner with a specific trust level +/// is stored. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJid key owner's bare JID +/// \param trustLevels possible trust levels of the key +/// +/// \return whether a key of the key owner with a passed trust level is stored +/// +QFuture<bool> QXmppTrustManager::hasKey(const QString &encryption, const QString &keyOwnerJid, QXmppTrustStorage::TrustLevels trustLevels) +{ + return m_trustStorage->hasKey(encryption, keyOwnerJid, trustLevels); +} + +/// +/// Sets the trust level of keys. +/// +/// If a key is not stored, it is added to the storage. +/// +/// \param encryption encryption protocol namespace +/// \param keyIds key owners' bare JIDs mapped to the IDs of their keys +/// \param trustLevel trust level being set +/// +QFuture<void> QXmppTrustManager::setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +{ + QFutureInterface<void> interface(QFutureInterfaceBase::Started); + + auto future = m_trustStorage->setTrustLevel(encryption, keyIds, trustLevel); + await(future, this, [=](QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys) mutable { + emit trustLevelsChanged(modifiedKeys); + interface.reportFinished(); + }); + + return interface.future(); +} + +/// +/// Sets the trust level of keys specified by their key owner and trust level. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJids key owners' bare JIDs +/// \param oldTrustLevel trust level being changed +/// \param newTrustLevel trust level being set +/// +QFuture<void> QXmppTrustManager::setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, QXmppTrustStorage::TrustLevel oldTrustLevel, QXmppTrustStorage::TrustLevel newTrustLevel) +{ + QFutureInterface<void> interface(QFutureInterfaceBase::Started); + + auto future = m_trustStorage->setTrustLevel(encryption, keyOwnerJids, oldTrustLevel, newTrustLevel); + await(future, this, [=](QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys) mutable { + emit trustLevelsChanged(modifiedKeys); + interface.reportFinished(); + }); + + return interface.future(); +} + +/// +/// Returns the trust level of a key. +/// +/// If the key is not stored, the trust in that key is undecided. +/// +/// \param encryption encryption protocol namespace +/// \param keyOwnerJid key owner's bare JID +/// \param keyId ID of the key +/// +/// \return the key's trust level +/// +QFuture<QXmppTrustStorage::TrustLevel> QXmppTrustManager::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) +{ + return m_trustStorage->trustLevel(encryption, keyOwnerJid, keyId); +} + +/// +/// Resets all data for encryption. +/// +/// \param encryption encryption protocol namespace +/// +QFuture<void> QXmppTrustManager::resetAll(const QString &encryption) +{ + return m_trustStorage->resetAll(encryption); +} + +/// \cond +bool QXmppTrustManager::handleStanza(const QDomElement &stanza) +{ + return false; +} +/// \endcond + +/// +/// \fn QXmppTrustManager::trustLevelsChanged(const QHash<QString, QMultiHash<QString, QByteArray>> &modifiedKeys) +/// +/// Emitted when the trust levels of keys changed because \c setTrustLevel() +/// added a new key or modified an existing one. +/// +/// \param modifiedKeys key owners' bare JIDs mapped to their modified keys for +/// specific encryption protocol namespaces +/// diff --git a/src/client/QXmppTrustManager.h b/src/client/QXmppTrustManager.h new file mode 100644 index 00000000..9081af92 --- /dev/null +++ b/src/client/QXmppTrustManager.h @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPTRUSTMANAGER_H +#define QXMPPTRUSTMANAGER_H + +#include "QXmppClientExtension.h" +#include "QXmppTrustStorage.h" + +class QXMPP_EXPORT QXmppTrustManager : public QXmppClientExtension +{ + Q_OBJECT + +public: + QXmppTrustManager(QXmppTrustStorage *trustStorage); + ~QXmppTrustManager(); + + QFuture<void> setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy); + QFuture<void> resetSecurityPolicy(const QString &encryption); + QFuture<QXmppTrustStorage::SecurityPolicy> securityPolicy(const QString &encryption); + + QFuture<void> setOwnKey(const QString &encryption, const QByteArray &keyId); + QFuture<void> resetOwnKey(const QString &encryption); + QFuture<QByteArray> ownKey(const QString &encryption); + + QFuture<void> addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel = QXmppTrustStorage::AutomaticallyDistrusted); + QFuture<void> removeKeys(const QString &encryption, const QList<QByteArray> &keyIds); + QFuture<void> removeKeys(const QString &encryption, const QString &keyOwnerJid); + QFuture<void> removeKeys(const QString &encryption); + QFuture<QHash<QXmppTrustStorage::TrustLevel, QMultiHash<QString, QByteArray>>> keys(const QString &encryption, QXmppTrustStorage::TrustLevels trustLevels = {}); + QFuture<QHash<QString, QHash<QByteArray, QXmppTrustStorage::TrustLevel>>> keys(const QString &encryption, const QList<QString> &keyOwnerJids, QXmppTrustStorage::TrustLevels trustLevels = {}); + QFuture<bool> hasKey(const QString &encryption, const QString &keyOwnerJid, QXmppTrustStorage::TrustLevels trustLevels); + + QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel); + QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, QXmppTrustStorage::TrustLevel oldTrustLevel, QXmppTrustStorage::TrustLevel newTrustLevel); + QFuture<QXmppTrustStorage::TrustLevel> trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId); + + QFuture<void> resetAll(const QString &encryption); + + /// \cond + bool handleStanza(const QDomElement &stanza) override; + /// \endcond + + Q_SIGNAL void trustLevelsChanged(const QHash<QString, QMultiHash<QString, QByteArray>> &modifiedKeys); + +protected: + /// \cond + inline QXmppTrustStorage *trustStorage() const + { + return m_trustStorage; + } + /// \endcond + +private: + QXmppTrustStorage *m_trustStorage; +}; + +#endif // QXMPPTRUSTMANAGER_H diff --git a/src/client/QXmppTrustMemoryStorage.cpp b/src/client/QXmppTrustMemoryStorage.cpp index c9e2f37f..a94768d2 100644 --- a/src/client/QXmppTrustMemoryStorage.cpp +++ b/src/client/QXmppTrustMemoryStorage.cpp @@ -50,7 +50,7 @@ QXmppTrustMemoryStorage::QXmppTrustMemoryStorage() QXmppTrustMemoryStorage::~QXmppTrustMemoryStorage() = default; /// \cond -QFuture<void> QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, const QXmppTrustStorage::SecurityPolicy securityPolicy) +QFuture<void> QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy) { d->securityPolicies.insert(encryption, securityPolicy); return makeReadyFuture(); @@ -85,7 +85,7 @@ QFuture<QByteArray> QXmppTrustMemoryStorage::ownKey(const QString &encryption) return makeReadyFuture(std::move(key)); } -QFuture<void> QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, const QXmppTrustStorage::TrustLevel trustLevel) +QFuture<void> QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel) { for (const auto &keyId : keyIds) { Key key; @@ -132,7 +132,7 @@ QFuture<void> QXmppTrustMemoryStorage::removeKeys(const QString &encryption) return makeReadyFuture(); } -QFuture<QHash<QXmppTrustStorage::TrustLevel, QMultiHash<QString, QByteArray>>> QXmppTrustMemoryStorage::keys(const QString &encryption, const TrustLevels trustLevels) +QFuture<QHash<QXmppTrustStorage::TrustLevel, QMultiHash<QString, QByteArray>>> QXmppTrustMemoryStorage::keys(const QString &encryption, TrustLevels trustLevels) { QHash<TrustLevel, QMultiHash<QString, QByteArray>> keys; @@ -175,8 +175,10 @@ QFuture<bool> QXmppTrustMemoryStorage::hasKey(const QString &encryption, const Q return makeReadyFuture(std::move(false)); } -QFuture<void> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, const TrustLevel trustLevel) +QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) { + QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys; + for (auto itr = keyIds.constBegin(); itr != keyIds.constEnd(); ++itr) { const auto keyOwnerJid = itr.key(); const auto keyId = itr.value(); @@ -191,6 +193,7 @@ QFuture<void> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, // Update the stored trust level if it differs from the new one. if (key.trustLevel != trustLevel) { key.trustLevel = trustLevel; + modifiedKeys[encryption].insert(keyOwnerJid, keyId); } isKeyFound = true; @@ -205,22 +208,27 @@ QFuture<void> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, key.ownerJid = keyOwnerJid; key.trustLevel = trustLevel; d->keys.insert(encryption, key); + modifiedKeys[encryption].insert(keyOwnerJid, keyId); } } - return makeReadyFuture(); + return makeReadyFuture(std::move(modifiedKeys)); } -QFuture<void> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, const QXmppTrustStorage::TrustLevel oldTrustLevel, const QXmppTrustStorage::TrustLevel newTrustLevel) +QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) { + QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys; + for (auto itr = d->keys.find(encryption); itr != d->keys.end() && itr.key() == encryption; ++itr) { auto &key = itr.value(); - if (keyOwnerJids.contains(key.ownerJid) && key.trustLevel == oldTrustLevel) { + auto keyOwnerJid = key.ownerJid; + if (keyOwnerJids.contains(keyOwnerJid) && key.trustLevel == oldTrustLevel) { key.trustLevel = newTrustLevel; + modifiedKeys[encryption].insert(keyOwnerJid, key.id); } } - return makeReadyFuture(); + return makeReadyFuture(std::move(modifiedKeys)); } QFuture<QXmppTrustStorage::TrustLevel> QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) @@ -228,7 +236,7 @@ QFuture<QXmppTrustStorage::TrustLevel> QXmppTrustMemoryStorage::trustLevel(const const auto keys = d->keys.values(encryption); for (const auto &key : keys) { if (key.id == keyId && key.ownerJid == keyOwnerJid) { - return makeReadyFuture(std::move(QXmppTrustStorage::TrustLevel(key.trustLevel))); + return makeReadyFuture(std::move(TrustLevel(key.trustLevel))); } } diff --git a/src/client/QXmppTrustMemoryStorage.h b/src/client/QXmppTrustMemoryStorage.h index c9d15fe9..1d0e2561 100644 --- a/src/client/QXmppTrustMemoryStorage.h +++ b/src/client/QXmppTrustMemoryStorage.h @@ -34,8 +34,8 @@ public: QFuture<QHash<QString, QHash<QByteArray, TrustLevel>>> keys(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevels trustLevels = {}) override; QFuture<bool> hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) override; - QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) override; - QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) override; + QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) override; + QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) override; QFuture<TrustLevel> trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) override; QFuture<void> resetAll(const QString &encryption) override; diff --git a/src/client/QXmppTrustStorage.cpp b/src/client/QXmppTrustStorage.cpp index 5cfe5b95..18637fab 100644 --- a/src/client/QXmppTrustStorage.cpp +++ b/src/client/QXmppTrustStorage.cpp @@ -5,8 +5,7 @@ /// /// \class QXmppTrustStorage /// -/// \brief The QXmppTrustStorage class stores trust data for end-to-end -/// encryption. +/// \brief The QXmppTrustStorage class stores end-to-end encryption trust data. /// /// The term "key" is used for a public long-term key. /// @@ -73,7 +72,7 @@ /// /// -/// \fn QXmppTrustStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, const QXmppTrustStorage::TrustLevel trustLevel) +/// \fn QXmppTrustStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QByteArray> &keyIds, QXmppTrustStorage::TrustLevel trustLevel) /// /// Adds keys. /// @@ -163,6 +162,9 @@ /// \param keyIds key owners' bare JIDs mapped to the IDs of their keys /// \param trustLevel trust level being set /// +/// \return the key owner JIDs mapped to their modified keys for specific +/// encryption protocols +/// /// /// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) @@ -174,6 +176,9 @@ /// \param oldTrustLevel trust level being changed /// \param newTrustLevel trust level being set /// +/// \return the key owner JIDs mapped to their modified keys for specific +/// encryption protocols +/// /// /// \fn QXmppTrustStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) diff --git a/src/client/QXmppTrustStorage.h b/src/client/QXmppTrustStorage.h index c1db773d..b93eae7b 100644 --- a/src/client/QXmppTrustStorage.h +++ b/src/client/QXmppTrustStorage.h @@ -53,8 +53,8 @@ public: virtual QFuture<QHash<QString, QHash<QByteArray, TrustLevel>>> keys(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevels trustLevels = {}) = 0; virtual QFuture<bool> hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) = 0; - virtual QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) = 0; - virtual QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) = 0; + virtual QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> setTrustLevel(const QString &encryption, const QMultiHash<QString, QByteArray> &keyIds, TrustLevel trustLevel) = 0; + virtual QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) = 0; virtual QFuture<TrustLevel> trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) = 0; virtual QFuture<void> resetAll(const QString &encryption) = 0; diff --git a/tests/qxmppatmmanager/tst_qxmppatmmanager.cpp b/tests/qxmppatmmanager/tst_qxmppatmmanager.cpp index 0f878914..944321f9 100644 --- a/tests/qxmppatmmanager/tst_qxmppatmmanager.cpp +++ b/tests/qxmppatmmanager/tst_qxmppatmmanager.cpp @@ -176,11 +176,11 @@ void tst_QXmppAtmManager::testMakePostponedTrustDecisions() QCoreApplication::processEvents(); } - auto futurePotsponed = m_trustStorage.keysForPostponedTrustDecisions(ns_omemo, + auto futurePostponed = m_trustStorage.keysForPostponedTrustDecisions(ns_omemo, { QByteArray::fromBase64(QByteArrayLiteral("wzsLdCDtOGUIoLkHAQN3Fdt86GLjE0716F0mnci/pVY=")), QByteArray::fromBase64(QByteArrayLiteral("cF3Li3ddEJzt9rw/1eAmMS31/G/G4ZTpf+9wbEs51HA=")) }); - QVERIFY(futurePotsponed.isFinished()); - auto resultPostponed = futurePotsponed.result(); + QVERIFY(futurePostponed.isFinished()); + auto resultPostponed = futurePostponed.result(); QVERIFY(resultPostponed.isEmpty()); QMultiHash<QString, QByteArray> trustedKeys = { { QStringLiteral("carol@example.net"), @@ -188,10 +188,10 @@ void tst_QXmppAtmManager::testMakePostponedTrustDecisions() QMultiHash<QString, QByteArray> distrustedKeys = { { QStringLiteral("carol@example.net"), QByteArray::fromBase64(QByteArrayLiteral("TKZIGhEMc+gyCgrJEyCnf7OtuoBFhOupOWhdwFhfZBk=")) } }; - futurePotsponed = m_trustStorage.keysForPostponedTrustDecisions(ns_omemo, + futurePostponed = m_trustStorage.keysForPostponedTrustDecisions(ns_omemo, { QByteArray::fromBase64(QByteArrayLiteral("Zgk0SxGFbeSgDw/Zanza/jzNrr6t1LU0jYX2d7RReKY=")) }); - QVERIFY(futurePotsponed.isFinished()); - resultPostponed = futurePotsponed.result(); + QVERIFY(futurePostponed.isFinished()); + resultPostponed = futurePostponed.result(); QCOMPARE( resultPostponed, QHash({ std::pair( @@ -210,8 +210,8 @@ void tst_QXmppAtmManager::testMakePostponedTrustDecisions() { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("3bqdCfhQalsOp3LcrFVucCQB4pRRWCyoBTV8KM/oOhY=")) } }; - auto future = m_trustStorage.keys(ns_omemo, - QXmppTrustStorage::Authenticated); + auto future = m_manager.keys(ns_omemo, + QXmppTrustStorage::Authenticated); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -229,8 +229,8 @@ void tst_QXmppAtmManager::testMakePostponedTrustDecisions() { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("U3+UnkTp12gusKbzWwN0lqDLEPb2CdMxP4bY85q9pxA=")) } }; - future = m_trustStorage.keys(ns_omemo, - QXmppTrustStorage::ManuallyDistrusted); + future = m_manager.keys(ns_omemo, + QXmppTrustStorage::ManuallyDistrusted); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE( @@ -244,26 +244,26 @@ void tst_QXmppAtmManager::testDistrustAutomaticallyTrustedKeys() { clearTrustStorage(); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")), QByteArray::fromBase64(QByteArrayLiteral("tfskruc1xcfC+VKzuqvLZUJVZccZX/Pg5j88ukpuY2M=")) }, QXmppTrustStorage::AutomaticallyTrusted); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("GaHysNhcfDSzG2q6OAThRGUpuFB9E7iCRR/1mK1TL+Q=")) }, QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("dZVdoBINK2n8BkWeTzVg0lVOah4n/9IA/IvQpzUuo1w=")) }, QXmppTrustStorage::AutomaticallyTrusted); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("We+r1A/kixDad8e383oTmhPDy8g+F5/ircMJmEET8MA=")) }, @@ -280,8 +280,8 @@ void tst_QXmppAtmManager::testDistrustAutomaticallyTrustedKeys() { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("dZVdoBINK2n8BkWeTzVg0lVOah4n/9IA/IvQpzUuo1w=")) } }; - auto future = m_trustStorage.keys(ns_omemo, - QXmppTrustStorage::AutomaticallyDistrusted); + auto future = m_manager.keys(ns_omemo, + QXmppTrustStorage::AutomaticallyDistrusted); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -300,7 +300,7 @@ void tst_QXmppAtmManager::testDistrust() { QStringLiteral("alice@example.org"), QByteArray::fromBase64(QByteArrayLiteral("tfskruc1xcfC+VKzuqvLZUJVZccZX/Pg5j88ukpuY2M=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), authenticatedKeys.values(), @@ -309,7 +309,7 @@ void tst_QXmppAtmManager::testDistrust() QMultiHash<QString, QByteArray> automaticallyTrustedKeys = { { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("mwT0Hwr7aG1p+x0q60H0UDSEnr8cr7hxvxDEhFGrLmY=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), automaticallyTrustedKeys.values(), @@ -320,7 +320,7 @@ void tst_QXmppAtmManager::testDistrust() { QStringLiteral("alice@example.org"), QByteArray::fromBase64(QByteArrayLiteral("QfXYzw7lmiD3Qoto6l2kx+HuM1tmKQYW2wCR+u78q8A=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), manuallyDistrustedKeys.values(), @@ -356,7 +356,7 @@ void tst_QXmppAtmManager::testDistrust() auto futureVoid = m_manager.distrust(ns_omemo, {}); QVERIFY(futureVoid.isFinished()); - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -394,7 +394,7 @@ void tst_QXmppAtmManager::testDistrust() { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("mwT0Hwr7aG1p+x0q60H0UDSEnr8cr7hxvxDEhFGrLmY=")) } }; - future = m_trustStorage.keys(ns_omemo); + future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE( @@ -448,20 +448,20 @@ void tst_QXmppAtmManager::testAuthenticate() clearTrustStorage(); QFETCH(QXmppTrustStorage::SecurityPolicy, securityPolicy); - m_trustStorage.setSecurityPolicy(ns_omemo, securityPolicy); + m_manager.setSecurityPolicy(ns_omemo, securityPolicy); QMultiHash<QString, QByteArray> authenticatedKeys = { { QStringLiteral("alice@example.org"), QByteArray::fromBase64(QByteArrayLiteral("rQIL2albuSR1i06EZAp1uZ838zUeEgGIq2whwu3s+Zg=")) }, { QStringLiteral("carol@example.net"), QByteArray::fromBase64(QByteArrayLiteral("+CQZlFyxdeTGgbPby7YvvZT3YIVcIi+1E8N5nSc6QTA=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), authenticatedKeys.values(QStringLiteral("alice@example.org")), QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), authenticatedKeys.values(QStringLiteral("carol@example.net")), @@ -472,7 +472,7 @@ void tst_QXmppAtmManager::testAuthenticate() { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("/dqv0+RNyFIPdMQiJ7mSEJWKVExFeUBEvTXxOtqIMDg=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), automaticallyTrustedKeys.values(), @@ -483,7 +483,7 @@ void tst_QXmppAtmManager::testAuthenticate() { QStringLiteral("alice@example.org"), QByteArray::fromBase64(QByteArrayLiteral("QfXYzw7lmiD3Qoto6l2kx+HuM1tmKQYW2wCR+u78q8A=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), manuallyDistrustedKeys.values(), @@ -494,7 +494,7 @@ void tst_QXmppAtmManager::testAuthenticate() { QStringLiteral("alice@example.org"), QByteArray::fromBase64(QByteArrayLiteral("tfskruc1xcfC+VKzuqvLZUJVZccZX/Pg5j88ukpuY2M=")) } }; - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), automaticallyDistrustedKeys.values(), @@ -556,7 +556,7 @@ void tst_QXmppAtmManager::testAuthenticate() auto futureVoid = m_manager.authenticate(ns_omemo, {}); QVERIFY(futureVoid.isFinished()); - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -626,7 +626,7 @@ void tst_QXmppAtmManager::testAuthenticate() QByteArray::fromBase64(QByteArrayLiteral("/dqv0+RNyFIPdMQiJ7mSEJWKVExFeUBEvTXxOtqIMDg=")) } }; } - future = m_trustStorage.keys(ns_omemo); + future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); result = future.result(); switch (securityPolicy) { @@ -709,7 +709,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisions() QCoreApplication::processEvents(); } - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -847,14 +847,14 @@ void tst_QXmppAtmManager::testHandleMessage() // Add the sender key in preparation for the test. if (areTrustDecisionsValid) { if (isSenderKeyAuthenticated) { - m_trustStorage.addKeys(ns_omemo, - senderJid, - { senderKey }, - QXmppTrustStorage::Authenticated); + m_manager.addKeys(ns_omemo, + senderJid, + { senderKey }, + QXmppTrustStorage::Authenticated); } else { - m_trustStorage.addKeys(ns_omemo, - senderJid, - { senderKey }); + m_manager.addKeys(ns_omemo, + senderJid, + { senderKey }); } } @@ -865,7 +865,7 @@ void tst_QXmppAtmManager::testHandleMessage() // Remove the sender key as soon as the method being tested is executed. if (areTrustDecisionsValid) { - m_trustStorage.removeKeys(ns_omemo, QList { senderKey }); + m_manager.removeKeys(ns_omemo, QList { senderKey }); } if (areTrustDecisionsValid) { @@ -887,7 +887,7 @@ void tst_QXmppAtmManager::testHandleMessage() } } - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -912,7 +912,7 @@ void tst_QXmppAtmManager::testHandleMessage() } } - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -982,7 +982,7 @@ void tst_QXmppAtmManager::testHandleMessage() } } } else { - auto futureHash = m_trustStorage.keys(ns_omemo); + auto futureHash = m_manager.keys(ns_omemo); QVERIFY(futureHash.isFinished()); auto resultHash = futureHash.result(); QVERIFY(resultHash.isEmpty()); @@ -1001,7 +1001,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsNoKeys() QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // key of own endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")), @@ -1009,7 +1009,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsNoKeys() QXmppTrustStorage::Authenticated); // key of contact's endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")) }, @@ -1042,7 +1042,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsNoKeys() QMultiHash<QString, QByteArray> manuallyDistrustedKeys = { { QStringLiteral("bob@example.com"), QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")) } }; - auto future = m_trustStorage.keys(ns_omemo); + auto future = m_manager.keys(ns_omemo); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE( @@ -1060,32 +1060,32 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeys() clearTrustStorage(); // keys of own endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")), QByteArray::fromBase64(QByteArrayLiteral("tfskruc1xcfC+VKzuqvLZUJVZccZX/Pg5j88ukpuY2M=")) }, QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("GaHysNhcfDSzG2q6OAThRGUpuFB9E7iCRR/1mK1TL+Q=")) }, QXmppTrustStorage::ManuallyDistrusted); // keys of contact's endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")) }, QXmppTrustStorage::ManuallyDistrusted); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1217,14 +1217,14 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysNoOwnEndpoints() clearTrustStorage(); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1347,21 +1347,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysNoOwnEndpointsWithAuthent clearTrustStorage(); // key of own endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("GaHysNhcfDSzG2q6OAThRGUpuFB9E7iCRR/1mK1TL+Q=")) }, QXmppTrustStorage::ManuallyDistrusted); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1488,7 +1488,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysNoContactsWithAuthenticat clearTrustStorage(); // keys of own endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")), @@ -1496,7 +1496,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysNoContactsWithAuthenticat QXmppTrustStorage::Authenticated); // keys of contact's endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")) }, @@ -1582,21 +1582,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleOwnKeyDistrusted() QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // key of own endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1682,9 +1682,9 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleOwnKeyDistrusted() QCOMPARE(sentMessagesCount, 2); QVERIFY2(!unexpectedTrustMessageSentSpy.wait(UNEXPECTED_TRUST_MESSAGE_WAITING_TIMEOUT), "Unexpected trust message sent!"); - auto futureTrustLevel = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("alice@example.org"), - QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI="))); + auto futureTrustLevel = m_manager.trustLevel(ns_omemo, + QStringLiteral("alice@example.org"), + QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI="))); QVERIFY(futureTrustLevel.isFinished()); auto result = futureTrustLevel.result(); QCOMPARE(result, QXmppTrustStorage::ManuallyDistrusted); @@ -1697,33 +1697,33 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeys() QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // keys of own endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")), QByteArray::fromBase64(QByteArrayLiteral("tfskruc1xcfC+VKzuqvLZUJVZccZX/Pg5j88ukpuY2M=")) }, QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("GaHysNhcfDSzG2q6OAThRGUpuFB9E7iCRR/1mK1TL+Q=")) }, QXmppTrustStorage::ManuallyDistrusted); // keys of contact's endpoints - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")), QByteArray::fromBase64(QByteArrayLiteral("T+dplAB8tGSdbYBbRiOm/jrS+8CPuzGHrH8ZmbjyvPo=")) }, QXmppTrustStorage::Authenticated); - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII=")) }, QXmppTrustStorage::ManuallyDistrusted); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1826,14 +1826,14 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeysNoOwnEndpoints() QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1869,21 +1869,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeysNoOwnEndpointsWithAut QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // key of own endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("GaHysNhcfDSzG2q6OAThRGUpuFB9E7iCRR/1mK1TL+Q=")) }, QXmppTrustStorage::ManuallyDistrusted); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -1953,21 +1953,21 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleContactKeyDistrusted() QSignalSpy unexpectedTrustMessageSentSpy(this, &tst_QXmppAtmManager::unexpectedTrustMessageSent); // key of own endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("alice@example.org"), { QByteArray::fromBase64(QByteArrayLiteral("RwyI/3m9l4wgju9JduFxb5MEJvBNRDfPfo1Ewhl1DEI=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("bob@example.com"), { QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g=")) }, QXmppTrustStorage::Authenticated); // key of contact's endpoint - m_trustStorage.addKeys( + m_manager.addKeys( ns_omemo, QStringLiteral("carol@example.net"), { QByteArray::fromBase64(QByteArrayLiteral("tVy3ygBnW4q6V2TYe8p4i904zD+x4rNMRegxPnPI7fw=")) }, @@ -2026,9 +2026,9 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleContactKeyDistrusted() QCOMPARE(sentMessagesCount, 1); QVERIFY2(!unexpectedTrustMessageSentSpy.wait(UNEXPECTED_TRUST_MESSAGE_WAITING_TIMEOUT), "Unexpected trust message sent!"); - const auto futureTrustLevel = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("bob@example.com"), - QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g="))); + const auto futureTrustLevel = m_manager.trustLevel(ns_omemo, + QStringLiteral("bob@example.com"), + QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g="))); QVERIFY(futureTrustLevel.isFinished()); const auto result = futureTrustLevel.result(); QCOMPARE(result, QXmppTrustStorage::ManuallyDistrusted); @@ -2036,23 +2036,23 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsSoleContactKeyDistrusted() void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysDone() { - auto future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("alice@example.org"), - QByteArray::fromBase64(QByteArrayLiteral("0RcVsGk3LnpEFsqqztTzAgCDgVXlfa03paSqJFOOWOU="))); + auto future = m_manager.trustLevel(ns_omemo, + QStringLiteral("alice@example.org"), + QByteArray::fromBase64(QByteArrayLiteral("0RcVsGk3LnpEFsqqztTzAgCDgVXlfa03paSqJFOOWOU="))); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE(result, QXmppTrustStorage::Authenticated); - future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("alice@example.org"), - QByteArray::fromBase64(QByteArrayLiteral("tYn/wcIOxBSoW4W1UfPr/zgbLipBK2KsFfC7F1bzut0="))); + future = m_manager.trustLevel(ns_omemo, + QStringLiteral("alice@example.org"), + QByteArray::fromBase64(QByteArrayLiteral("tYn/wcIOxBSoW4W1UfPr/zgbLipBK2KsFfC7F1bzut0="))); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE(result, QXmppTrustStorage::Authenticated); - future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("alice@example.org"), - QByteArray::fromBase64(QByteArrayLiteral("4iBsyJPVAfNWM/OgyA9fasOvkJ8K1/0wuYpwVGw4Q5M="))); + future = m_manager.trustLevel(ns_omemo, + QStringLiteral("alice@example.org"), + QByteArray::fromBase64(QByteArrayLiteral("4iBsyJPVAfNWM/OgyA9fasOvkJ8K1/0wuYpwVGw4Q5M="))); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE(result, QXmppTrustStorage::ManuallyDistrusted); @@ -2060,23 +2060,23 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsOwnKeysDone() void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeysDone() { - auto future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("bob@example.com"), - QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g="))); + auto future = m_manager.trustLevel(ns_omemo, + QStringLiteral("bob@example.com"), + QByteArray::fromBase64(QByteArrayLiteral("+1VJvMLCGvkDquZ6mQZ+SS+gTbQ436BJUwFOoW0Ma1g="))); QVERIFY(future.isFinished()); auto result = future.result(); QCOMPARE(result, QXmppTrustStorage::Authenticated); - future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("bob@example.com"), - QByteArray::fromBase64(QByteArrayLiteral("mzDeKTQBVm1cTmzF9DjCGKa14pDADZOVLT9Kh7CK7AM="))); + future = m_manager.trustLevel(ns_omemo, + QStringLiteral("bob@example.com"), + QByteArray::fromBase64(QByteArrayLiteral("mzDeKTQBVm1cTmzF9DjCGKa14pDADZOVLT9Kh7CK7AM="))); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE(result, QXmppTrustStorage::Authenticated); - future = m_trustStorage.trustLevel(ns_omemo, - QStringLiteral("bob@example.com"), - QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII="))); + future = m_manager.trustLevel(ns_omemo, + QStringLiteral("bob@example.com"), + QByteArray::fromBase64(QByteArrayLiteral("8gBTC1fspYkO4akS6QKN+XFA9Nmf9NEIg7hjtlpTjII="))); QVERIFY(future.isFinished()); result = future.result(); QCOMPARE(result, QXmppTrustStorage::ManuallyDistrusted); @@ -2084,7 +2084,7 @@ void tst_QXmppAtmManager::testMakeTrustDecisionsContactKeysDone() void tst_QXmppAtmManager::clearTrustStorage() { - m_trustStorage.removeKeys(ns_omemo); + m_manager.removeKeys(ns_omemo); m_trustStorage.removeKeysForPostponedTrustDecisions(ns_omemo); } |
