From 32ccc6358ba6433e6b870b238fba20ccf1862fe2 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 18 Jun 2022 12:41:31 +0200 Subject: Move SecurityPolicy, TrustLevel intro extra headers This avoids the need to include the whole TrustStorage in files like SendStanzaParams.h. --- src/client/QXmppAtmManager.cpp | 19 +++++++------- src/client/QXmppSendStanzaParams.cpp | 10 ++++--- src/client/QXmppSendStanzaParams.h | 6 ++--- src/client/QXmppTrustLevel.h | 48 ++++++++++++++++++++++++++++++++++ src/client/QXmppTrustManager.cpp | 20 +++++++------- src/client/QXmppTrustManager.h | 25 +++++++++++------- src/client/QXmppTrustMemoryStorage.cpp | 21 ++++++++------- src/client/QXmppTrustMemoryStorage.h | 18 ++++++------- src/client/QXmppTrustSecurityPolicy.h | 30 +++++++++++++++++++++ src/client/QXmppTrustStorage.cpp | 14 +++++----- src/client/QXmppTrustStorage.h | 46 ++++++++------------------------ 11 files changed, 161 insertions(+), 96 deletions(-) create mode 100644 src/client/QXmppTrustLevel.h create mode 100644 src/client/QXmppTrustSecurityPolicy.h (limited to 'src/client') diff --git a/src/client/QXmppAtmManager.cpp b/src/client/QXmppAtmManager.cpp index b7ea5660..4ea30cae 100644 --- a/src/client/QXmppAtmManager.cpp +++ b/src/client/QXmppAtmManager.cpp @@ -13,6 +13,7 @@ #include "QXmppTrustMessageKeyOwner.h" #include "QXmppUtils.h" +using namespace QXmpp; using namespace QXmpp::Private; /// @@ -79,10 +80,10 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con { QFutureInterface interface(QFutureInterfaceBase::Started); - auto future = keys(encryption, QXmppTrustStorage::Authenticated | QXmppTrustStorage::ManuallyDistrusted); - await(future, this, [=](const QHash> &&keys) mutable { - const auto authenticatedKeys = keys.value(QXmppTrustStorage::Authenticated); - const auto manuallyDistrustedKeys = keys.value(QXmppTrustStorage::ManuallyDistrusted); + auto future = keys(encryption, TrustLevel::Authenticated | TrustLevel::ManuallyDistrusted); + await(future, this, [=](QHash> keys) mutable { + const auto authenticatedKeys = keys.value(TrustLevel::Authenticated); + const auto manuallyDistrustedKeys = keys.value(TrustLevel::ManuallyDistrusted); const auto ownJid = client()->configuration().jidBare(); const auto ownAuthenticatedKeys = authenticatedKeys.values(ownJid); @@ -303,7 +304,7 @@ QFuture QXmppAtmManager::handleMessage(const QXmppMessage &message) auto future = trustLevel(encryption, senderJid, senderKey); await(future, this, [=](const auto &&senderKeyTrustLevel) mutable { - const auto isSenderKeyAuthenticated = senderKeyTrustLevel == QXmppTrustStorage::Authenticated; + const auto isSenderKeyAuthenticated = senderKeyTrustLevel == TrustLevel::Authenticated; // key owner JIDs mapped to key IDs QMultiHash keysBeingAuthenticated; @@ -380,11 +381,11 @@ QFuture QXmppAtmManager::authenticate(const QString &encryption, const QMu QFutureInterface interface(QFutureInterfaceBase::Started); - auto future = setTrustLevel(encryption, keyIds, QXmppTrustStorage::Authenticated); + auto future = setTrustLevel(encryption, keyIds, TrustLevel::Authenticated); await(future, this, [=]() mutable { auto future = securityPolicy(encryption); await(future, this, [=](auto securityPolicy) mutable { - if (securityPolicy == QXmppTrustStorage::Toakafa) { + if (securityPolicy == Toakafa) { auto future = distrustAutomaticallyTrustedKeys(encryption, keyIds.uniqueKeys()); await(future, this, [=]() mutable { auto future = makePostponedTrustDecisions(encryption, keyIds.values()); @@ -418,7 +419,7 @@ QFuture QXmppAtmManager::distrust(const QString &encryption, const QMultiH QFutureInterface interface(QFutureInterfaceBase::Started); - auto future = setTrustLevel(encryption, keyIds, QXmppTrustStorage::ManuallyDistrusted); + auto future = setTrustLevel(encryption, keyIds, TrustLevel::ManuallyDistrusted); await(future, this, [=]() mutable { auto future = trustStorage()->removeKeysForPostponedTrustDecisions(encryption, keyIds.values()); await(future, this, [=]() mutable { @@ -438,7 +439,7 @@ QFuture QXmppAtmManager::distrust(const QString &encryption, const QMultiH /// QFuture QXmppAtmManager::distrustAutomaticallyTrustedKeys(const QString &encryption, const QList &keyOwnerJids) { - return setTrustLevel(encryption, keyOwnerJids, QXmppTrustStorage::AutomaticallyTrusted, QXmppTrustStorage::AutomaticallyDistrusted); + return setTrustLevel(encryption, keyOwnerJids, TrustLevel::AutomaticallyTrusted, TrustLevel::AutomaticallyDistrusted); } /// diff --git a/src/client/QXmppSendStanzaParams.cpp b/src/client/QXmppSendStanzaParams.cpp index 6c8b6ccc..9711750d 100644 --- a/src/client/QXmppSendStanzaParams.cpp +++ b/src/client/QXmppSendStanzaParams.cpp @@ -6,6 +6,8 @@ #include +using namespace QXmpp; + /// /// \class QXmppSendStanzaParams /// @@ -17,8 +19,8 @@ class QXmppSendStanzaParamsPrivate : public QSharedData { public: + TrustLevels acceptedTrustLevels; QVector encryptionJids; - QXmppTrustStorage::TrustLevels acceptedTrustLevels; }; QXmppSendStanzaParams::QXmppSendStanzaParams() @@ -65,7 +67,7 @@ void QXmppSendStanzaParams::setEncryptionJids(QVector encryptionJids) /// /// \return the trust levels of the keys used for encryption /// -std::optional QXmppSendStanzaParams::acceptedTrustLevels() const +std::optional QXmppSendStanzaParams::acceptedTrustLevels() const { if (d->acceptedTrustLevels) { return d->acceptedTrustLevels; @@ -80,7 +82,7 @@ std::optional QXmppSendStanzaParams::acceptedTru /// /// \param trustLevels trust levels of the keys used for encryption /// -void QXmppSendStanzaParams::setAcceptedTrustLevels(std::optional trustLevels) +void QXmppSendStanzaParams::setAcceptedTrustLevels(std::optional trustLevels) { - d->acceptedTrustLevels = trustLevels.value_or(QXmppTrustStorage::TrustLevels()); + d->acceptedTrustLevels = trustLevels.value_or(QXmpp::TrustLevels()); } diff --git a/src/client/QXmppSendStanzaParams.h b/src/client/QXmppSendStanzaParams.h index 70ef572a..56bb314b 100644 --- a/src/client/QXmppSendStanzaParams.h +++ b/src/client/QXmppSendStanzaParams.h @@ -6,7 +6,7 @@ #define QXMPPSENDSTANZAPARAMS_H #include "QXmppGlobal.h" -#include "QXmppTrustStorage.h" +#include "QXmppTrustLevel.h" #include @@ -27,8 +27,8 @@ public: QVector encryptionJids() const; void setEncryptionJids(QVector); - std::optional acceptedTrustLevels() const; - void setAcceptedTrustLevels(std::optional trustLevels); + std::optional acceptedTrustLevels() const; + void setAcceptedTrustLevels(std::optional trustLevels); private: QSharedDataPointer d; diff --git a/src/client/QXmppTrustLevel.h b/src/client/QXmppTrustLevel.h new file mode 100644 index 00000000..2cff9e2a --- /dev/null +++ b/src/client/QXmppTrustLevel.h @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2021 Melvin Keskin +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPTRUSTLEVEL_H +#define QXMPPTRUSTLEVEL_H + +#include +#include + +namespace QXmpp { + +/// +/// Trust level of public long-term keys used by end-to-end encryption +/// protocols +/// +/// \since QXmpp 1.5 +/// +enum class TrustLevel { + /// The key's trust is not decided. + Undecided = 1, + /// The key is automatically distrusted (e.g., by the security policy TOAKAFA). + /// \see SecurityPolicy + AutomaticallyDistrusted = 2, + /// The key is manually distrusted (e.g., by clicking a button or \xep{0450, Automatic Trust + /// Management (ATM)}). + ManuallyDistrusted = 4, + /// The key is automatically trusted (e.g., by the client for all keys of a bare JID until one + /// of it is authenticated). + AutomaticallyTrusted = 8, + /// The key is manually trusted (e.g., by clicking a button). + ManuallyTrusted = 16, + /// The key is authenticated (e.g., by QR code scanning or \xep{0450, Automatic Trust + /// Management (ATM)}). + Authenticated = 32, +}; + +Q_DECLARE_FLAGS(TrustLevels, TrustLevel) +Q_DECLARE_OPERATORS_FOR_FLAGS(TrustLevels) + +} // namespace QXmpp + +/// \cond +// Scoped enums (enum class) are not implicitly converted to int +inline uint qHash(QXmpp::TrustLevel key, uint seed) noexcept { return qHash(std::underlying_type_t(key), seed); } +/// \endcond + +#endif // QXMPPTRUSTLEVEL_H diff --git a/src/client/QXmppTrustManager.cpp b/src/client/QXmppTrustManager.cpp index e198255c..7b9b34ab 100644 --- a/src/client/QXmppTrustManager.cpp +++ b/src/client/QXmppTrustManager.cpp @@ -5,7 +5,9 @@ #include "QXmppTrustManager.h" #include "QXmppFutureUtils_p.h" +#include "QXmppTrustStorage.h" +using namespace QXmpp; using namespace QXmpp::Private; /// @@ -38,7 +40,7 @@ QXmppTrustManager::~QXmppTrustManager() = default; /// \param encryption encryption protocol namespace /// \param securityPolicy security policy being applied /// -QFuture QXmppTrustManager::setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy) +QFuture QXmppTrustManager::setSecurityPolicy(const QString &encryption, TrustSecurityPolicy securityPolicy) { return m_trustStorage->setSecurityPolicy(encryption, securityPolicy); } @@ -60,7 +62,7 @@ QFuture QXmppTrustManager::resetSecurityPolicy(const QString &encryption) /// /// \return the set security policy /// -QFuture QXmppTrustManager::securityPolicy(const QString &encryption) +QFuture QXmppTrustManager::securityPolicy(const QString &encryption) { return m_trustStorage->securityPolicy(encryption); } @@ -109,7 +111,7 @@ QFuture QXmppTrustManager::ownKey(const QString &encryption) /// \param keyIds IDs of the keys /// \param trustLevel trust level of the keys /// -QFuture QXmppTrustManager::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +QFuture QXmppTrustManager::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel) { return m_trustStorage->addKeys(encryption, keyOwnerJid, keyIds, trustLevel); } @@ -157,7 +159,7 @@ QFuture QXmppTrustManager::removeKeys(const QString &encryption) /// /// \return the key owner JIDs mapped to their keys with specific trust levels /// -QFuture>> QXmppTrustManager::keys(const QString &encryption, QXmppTrustStorage::TrustLevels trustLevels) +QFuture>> QXmppTrustManager::keys(const QString &encryption, QXmpp::TrustLevels trustLevels) { return m_trustStorage->keys(encryption, trustLevels); } @@ -175,7 +177,7 @@ QFuture>> Q /// /// \return the key IDs mapped to their trust levels for specific key owners /// -QFuture>> QXmppTrustManager::keys(const QString &encryption, const QList &keyOwnerJids, QXmppTrustStorage::TrustLevels trustLevels) +QFuture>> QXmppTrustManager::keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels) { return m_trustStorage->keys(encryption, keyOwnerJids, trustLevels); } @@ -190,7 +192,7 @@ QFuture>> QXmppT /// /// \return whether a key of the key owner with a passed trust level is stored /// -QFuture QXmppTrustManager::hasKey(const QString &encryption, const QString &keyOwnerJid, QXmppTrustStorage::TrustLevels trustLevels) +QFuture QXmppTrustManager::hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) { return m_trustStorage->hasKey(encryption, keyOwnerJid, trustLevels); } @@ -204,7 +206,7 @@ QFuture QXmppTrustManager::hasKey(const QString &encryption, const QString /// \param keyIds key owners' bare JIDs mapped to the IDs of their keys /// \param trustLevel trust level being set /// -QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) { QFutureInterface interface(QFutureInterfaceBase::Started); @@ -225,7 +227,7 @@ QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const /// \param oldTrustLevel trust level being changed /// \param newTrustLevel trust level being set /// -QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmppTrustStorage::TrustLevel oldTrustLevel, QXmppTrustStorage::TrustLevel newTrustLevel) +QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) { QFutureInterface interface(QFutureInterfaceBase::Started); @@ -249,7 +251,7 @@ QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const /// /// \return the key's trust level /// -QFuture QXmppTrustManager::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) +QFuture QXmppTrustManager::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) { return m_trustStorage->trustLevel(encryption, keyOwnerJid, keyId); } diff --git a/src/client/QXmppTrustManager.h b/src/client/QXmppTrustManager.h index 9081af92..601bb9ac 100644 --- a/src/client/QXmppTrustManager.h +++ b/src/client/QXmppTrustManager.h @@ -6,7 +6,12 @@ #define QXMPPTRUSTMANAGER_H #include "QXmppClientExtension.h" -#include "QXmppTrustStorage.h" +#include "QXmppTrustLevel.h" +#include "QXmppTrustSecurityPolicy.h" + +#include + +class QXmppTrustStorage; class QXMPP_EXPORT QXmppTrustManager : public QXmppClientExtension { @@ -16,25 +21,25 @@ public: QXmppTrustManager(QXmppTrustStorage *trustStorage); ~QXmppTrustManager(); - QFuture setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy); + QFuture setSecurityPolicy(const QString &encryption, QXmpp::TrustSecurityPolicy securityPolicy); QFuture resetSecurityPolicy(const QString &encryption); - QFuture securityPolicy(const QString &encryption); + QFuture securityPolicy(const QString &encryption); QFuture setOwnKey(const QString &encryption, const QByteArray &keyId); QFuture resetOwnKey(const QString &encryption); QFuture ownKey(const QString &encryption); - QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmppTrustStorage::TrustLevel trustLevel = QXmppTrustStorage::AutomaticallyDistrusted); + QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmpp::TrustLevel trustLevel = QXmpp::TrustLevel::AutomaticallyDistrusted); QFuture removeKeys(const QString &encryption, const QList &keyIds); QFuture removeKeys(const QString &encryption, const QString &keyOwnerJid); QFuture removeKeys(const QString &encryption); - QFuture>> keys(const QString &encryption, QXmppTrustStorage::TrustLevels trustLevels = {}); - QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, QXmppTrustStorage::TrustLevels trustLevels = {}); - QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, QXmppTrustStorage::TrustLevels trustLevels); + QFuture>> keys(const QString &encryption, QXmpp::TrustLevels trustLevels = {}); + QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels = {}); + QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, QXmpp::TrustLevels trustLevels); - QFuture setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmppTrustStorage::TrustLevel trustLevel); - QFuture setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmppTrustStorage::TrustLevel oldTrustLevel, QXmppTrustStorage::TrustLevel newTrustLevel); - QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId); + QFuture setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmpp::TrustLevel trustLevel); + QFuture setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevel oldTrustLevel, QXmpp::TrustLevel newTrustLevel); + QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId); QFuture resetAll(const QString &encryption); diff --git a/src/client/QXmppTrustMemoryStorage.cpp b/src/client/QXmppTrustMemoryStorage.cpp index a94768d2..daab2e73 100644 --- a/src/client/QXmppTrustMemoryStorage.cpp +++ b/src/client/QXmppTrustMemoryStorage.cpp @@ -6,6 +6,7 @@ #include "QXmppFutureUtils_p.h" +using namespace QXmpp; using namespace QXmpp::Private; /// @@ -23,14 +24,14 @@ struct Key { QByteArray id; QString ownerJid; - QXmppTrustStorage::TrustLevel trustLevel; + TrustLevel trustLevel; }; class QXmppTrustMemoryStoragePrivate { public: // encryption protocols mapped to security policies - QMap securityPolicies; + QMap securityPolicies; // encryption protocols mapped to keys of this client instance QMap ownKeys; @@ -50,7 +51,7 @@ QXmppTrustMemoryStorage::QXmppTrustMemoryStorage() QXmppTrustMemoryStorage::~QXmppTrustMemoryStorage() = default; /// \cond -QFuture QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy) +QFuture QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, TrustSecurityPolicy securityPolicy) { d->securityPolicies.insert(encryption, securityPolicy); return makeReadyFuture(); @@ -62,7 +63,7 @@ QFuture QXmppTrustMemoryStorage::resetSecurityPolicy(const QString &encryp return makeReadyFuture(); } -QFuture QXmppTrustMemoryStorage::securityPolicy(const QString &encryption) +QFuture QXmppTrustMemoryStorage::securityPolicy(const QString &encryption) { return makeReadyFuture(std::move(d->securityPolicies.value(encryption))); } @@ -85,7 +86,7 @@ QFuture QXmppTrustMemoryStorage::ownKey(const QString &encryption) return makeReadyFuture(std::move(key)); } -QFuture QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +QFuture QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel) { for (const auto &keyId : keyIds) { Key key; @@ -132,7 +133,7 @@ QFuture QXmppTrustMemoryStorage::removeKeys(const QString &encryption) return makeReadyFuture(); } -QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, TrustLevels trustLevels) +QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, TrustLevels trustLevels) { QHash> keys; @@ -147,9 +148,9 @@ QFuture>> Q return makeReadyFuture(std::move(keys)); } -QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, const QList &keyOwnerJids, TrustLevels trustLevels) +QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, const QList &keyOwnerJids, TrustLevels trustLevels) { - QHash> keys; + QHash> keys; const auto storedKeys = d->keys.values(encryption); for (const auto &key : storedKeys) { @@ -231,7 +232,7 @@ QFuture>> QXmppTrustMemoryStorage return makeReadyFuture(std::move(modifiedKeys)); } -QFuture QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) +QFuture QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) { const auto keys = d->keys.values(encryption); for (const auto &key : keys) { @@ -240,7 +241,7 @@ QFuture QXmppTrustMemoryStorage::trustLevel(const } } - return makeReadyFuture(std::move(QXmppTrustStorage::Undecided)); + return makeReadyFuture(std::move(TrustLevel::Undecided)); } QFuture QXmppTrustMemoryStorage::resetAll(const QString &encryption) diff --git a/src/client/QXmppTrustMemoryStorage.h b/src/client/QXmppTrustMemoryStorage.h index 1d0e2561..f5e92569 100644 --- a/src/client/QXmppTrustMemoryStorage.h +++ b/src/client/QXmppTrustMemoryStorage.h @@ -18,25 +18,25 @@ public: ~QXmppTrustMemoryStorage(); /// \cond - QFuture setSecurityPolicy(const QString &encryption, SecurityPolicy securityPolicy) override; + QFuture setSecurityPolicy(const QString &encryption, QXmpp::TrustSecurityPolicy securityPolicy) override; QFuture resetSecurityPolicy(const QString &encryption) override; - QFuture securityPolicy(const QString &encryption) override; + QFuture securityPolicy(const QString &encryption) override; QFuture setOwnKey(const QString &encryption, const QByteArray &keyId) override; QFuture resetOwnKey(const QString &encryption) override; QFuture ownKey(const QString &encryption) override; - QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel = TrustLevel::AutomaticallyDistrusted) override; + QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmpp::TrustLevel trustLevel = QXmpp::TrustLevel::AutomaticallyDistrusted) override; QFuture removeKeys(const QString &encryption, const QList &keyIds) override; QFuture removeKeys(const QString &encryption, const QString &keyOwnerJid) override; QFuture removeKeys(const QString &encryption) override; - QFuture>> keys(const QString &encryption, TrustLevels trustLevels = {}) override; - QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, TrustLevels trustLevels = {}) override; - QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) override; + QFuture>> keys(const QString &encryption, QXmpp::TrustLevels trustLevels = {}) override; + QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels = {}) override; + QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, QXmpp::TrustLevels trustLevels) override; - QFuture>> setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) override; - QFuture>> setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) override; - QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) override; + QFuture>> setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmpp::TrustLevel trustLevel) override; + QFuture>> setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevel oldTrustLevel, QXmpp::TrustLevel newTrustLevel) override; + QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) override; QFuture resetAll(const QString &encryption) override; /// \endcond diff --git a/src/client/QXmppTrustSecurityPolicy.h b/src/client/QXmppTrustSecurityPolicy.h new file mode 100644 index 00000000..5020b81d --- /dev/null +++ b/src/client/QXmppTrustSecurityPolicy.h @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2021 Melvin Keskin +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPTRUSTSECURITYPOLICY_H +#define QXMPPTRUSTSECURITYPOLICY_H + +#include + +namespace QXmpp { + +/// +/// Security policy to decide which public long-term keys are used for encryption because they are +/// trusted +/// +/// \since QXmpp 1.5 +/// +enum TrustSecurityPolicy { + /// New keys must be trusted manually. + NoSecurityPolicy, + /// New keys are trusted automatically until the first authentication but automatically + /// distrusted afterwards. \see \xep{0450, Automatic Trust Management (ATM)} + Toakafa, +}; + +} // namespace QXmpp + +Q_DECLARE_METATYPE(QXmpp::TrustSecurityPolicy) + +#endif // QXMPPTRUSTSECURITYPOLICY_H diff --git a/src/client/QXmppTrustStorage.cpp b/src/client/QXmppTrustStorage.cpp index 18637fab..50b39089 100644 --- a/src/client/QXmppTrustStorage.cpp +++ b/src/client/QXmppTrustStorage.cpp @@ -15,7 +15,7 @@ /// /// -/// \fn QXmppTrustStorage::setSecurityPolicy(const QString &encryption, SecurityPolicy securityPolicy) +/// \fn QXmppTrustStorage::setSecurityPolicy(const QString &encryption, QXmpp::SecurityPolicy securityPolicy) /// /// Sets the security policy for an encryption protocol. /// @@ -72,7 +72,7 @@ /// /// -/// \fn QXmppTrustStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmppTrustStorage::TrustLevel trustLevel) +/// \fn QXmppTrustStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmpp::TrustLevel trustLevel) /// /// Adds keys. /// @@ -109,7 +109,7 @@ /// /// -/// \fn QXmppTrustStorage::keys(const QString &encryption, TrustLevels trustLevels = {}) +/// \fn QXmppTrustStorage::keys(const QString &encryption, QXmpp::TrustLevels trustLevels = {}) /// /// Returns the JIDs of all key owners mapped to the IDs of their keys with /// specific trust levels. @@ -123,7 +123,7 @@ /// /// -/// \fn QXmppTrustStorage::keys(const QString &encryption, const QList &keyOwnerJids, TrustLevels trustLevels = {}) +/// \fn QXmppTrustStorage::keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels = {}) /// /// Returns the IDs of keys mapped to their trust levels for specific key /// owners. @@ -139,7 +139,7 @@ /// /// -/// \fn QXmppTrustStorage::hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) +/// \fn QXmppTrustStorage::hasKey(const QString &encryption, const QString &keyOwnerJid, QXmpp::TrustLevels trustLevels) /// /// Returns whether at least one key of a key owner with a specific trust level /// is stored. @@ -152,7 +152,7 @@ /// /// -/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) +/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmpp::TrustLevel trustLevel) /// /// Sets the trust level of keys. /// @@ -167,7 +167,7 @@ /// /// -/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) +/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevel oldTrustLevel, QXmpp::TrustLevel newTrustLevel) /// /// Sets the trust level of keys specified by their key owner and trust level. /// diff --git a/src/client/QXmppTrustStorage.h b/src/client/QXmppTrustStorage.h index b93eae7b..0edc92a4 100644 --- a/src/client/QXmppTrustStorage.h +++ b/src/client/QXmppTrustStorage.h @@ -6,61 +6,37 @@ #define QXMPPTRUSTSTORAGE_H #include "QXmppGlobal.h" +#include "QXmppTrustLevel.h" +#include "QXmppTrustSecurityPolicy.h" #include class QXMPP_EXPORT QXmppTrustStorage { public: - /// - /// Security policy to decide which public long-term keys are used for - /// encryption because they are trusted - /// - enum SecurityPolicy { - NoSecurityPolicy, ///< New keys must be trusted manually. - Toakafa, ///< New keys are trusted automatically until the first authentication but automatically distrusted afterwards. \see \xep{0450, Automatic Trust Management (ATM)} - }; - - /// - /// Trust level of public long-term keys used by end-to-end encryption - /// protocols - /// - enum TrustLevel { - Undecided = 1, ///< The key's trust is not decided. - AutomaticallyDistrusted = 2, ///< The key is automatically distrusted (e.g., by the security policy TOAKAFA). \see SecurityPolicy - ManuallyDistrusted = 4, ///< The key is manually distrusted (e.g., by clicking a button or \xep{0450, Automatic Trust Management (ATM)}). - AutomaticallyTrusted = 8, ///< The key is automatically trusted (e.g., by the client for all keys of a bare JID until one of it is authenticated). - ManuallyTrusted = 16, ///< The key is manually trusted (e.g., by clicking a button). - Authenticated = 32, ///< The key is authenticated (e.g., by QR code scanning or \xep{0450, Automatic Trust Management (ATM)}). - }; - Q_DECLARE_FLAGS(TrustLevels, TrustLevel) - virtual ~QXmppTrustStorage() = default; - virtual QFuture setSecurityPolicy(const QString &encryption, SecurityPolicy securityPolicy) = 0; + virtual QFuture setSecurityPolicy(const QString &encryption, QXmpp::TrustSecurityPolicy securityPolicy) = 0; virtual QFuture resetSecurityPolicy(const QString &encryption) = 0; - virtual QFuture securityPolicy(const QString &encryption) = 0; + virtual QFuture securityPolicy(const QString &encryption) = 0; virtual QFuture setOwnKey(const QString &encryption, const QByteArray &keyId) = 0; virtual QFuture resetOwnKey(const QString &encryption) = 0; virtual QFuture ownKey(const QString &encryption) = 0; - virtual QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel = TrustLevel::AutomaticallyDistrusted) = 0; + virtual QFuture addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmpp::TrustLevel trustLevel = QXmpp::TrustLevel::AutomaticallyDistrusted) = 0; virtual QFuture removeKeys(const QString &encryption, const QList &keyIds) = 0; virtual QFuture removeKeys(const QString &encryption, const QString &keyOwnerJid) = 0; virtual QFuture removeKeys(const QString &encryption) = 0; - virtual QFuture>> keys(const QString &encryption, TrustLevels trustLevels = {}) = 0; - virtual QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, TrustLevels trustLevels = {}) = 0; - virtual QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) = 0; + virtual QFuture>> keys(const QString &encryption, QXmpp::TrustLevels trustLevels = {}) = 0; + virtual QFuture>> keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels = {}) = 0; + virtual QFuture hasKey(const QString &encryption, const QString &keyOwnerJid, QXmpp::TrustLevels trustLevels) = 0; - virtual QFuture>> setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) = 0; - virtual QFuture>> setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) = 0; - virtual QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) = 0; + virtual QFuture>> setTrustLevel(const QString &encryption, const QMultiHash &keyIds, QXmpp::TrustLevel trustLevel) = 0; + virtual QFuture>> setTrustLevel(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevel oldTrustLevel, QXmpp::TrustLevel newTrustLevel) = 0; + virtual QFuture trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) = 0; virtual QFuture resetAll(const QString &encryption) = 0; }; -Q_DECLARE_METATYPE(QXmppTrustStorage::SecurityPolicy) -Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTrustStorage::TrustLevels) - #endif // QXMPPTRUSTSTORAGE_H -- cgit v1.2.3