aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2021-08-28 14:37:25 +0200
committerLinus Jahn <lnj@kaidan.im>2021-09-16 18:43:00 +0200
commit2a836ec1fb8329018d23ca3adb5ad388100bd13e (patch)
tree2fde13d39032c674c79757b2956d2ed08ce13818 /src
parent1c2a092a64c609e10f0fcbf2936b5dae70ee5e8c (diff)
downloadqxmpp-2a836ec1fb8329018d23ca3adb5ad388100bd13e.tar.gz
Add QXmppTrustStorage
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/client/QXmppTrustStorage.cpp194
-rw-r--r--src/client/QXmppTrustStorage.h69
3 files changed, 265 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e5357ad2..1802b1f2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -106,6 +106,7 @@ set(INSTALL_HEADER_FILES
client/QXmppRpcManager.h
client/QXmppTransferManager.h
client/QXmppTransferManager_p.h
+ client/QXmppTrustStorage.h
client/QXmppUploadRequestManager.h
client/QXmppUserTuneManager.h
client/QXmppVCardManager.h
@@ -209,6 +210,7 @@ set(SOURCE_FILES
client/QXmppRpcManager.cpp
client/QXmppTlsManager.cpp
client/QXmppTransferManager.cpp
+ client/QXmppTrustStorage.cpp
client/QXmppUploadRequestManager.cpp
client/QXmppUserTuneManager.cpp
client/QXmppVCardManager.cpp
diff --git a/src/client/QXmppTrustStorage.cpp b/src/client/QXmppTrustStorage.cpp
new file mode 100644
index 00000000..67f1ace9
--- /dev/null
+++ b/src/client/QXmppTrustStorage.cpp
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2008-2021 The QXmpp developers
+ *
+ * Author:
+ * Melvin Keskin <melvo@olomono.de>
+ *
+ * Source:
+ * https://github.com/qxmpp-project/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+///
+/// \class QXmppTrustStorage
+///
+/// \brief The QXmppTrustStorage class stores trust data for end-to-end
+/// encryption.
+///
+/// \warning THIS API IS NOT FINALIZED YET!
+///
+/// \since QXmpp 1.5
+///
+
+///
+/// \fn QXmppTrustStorage::addOwnKey(const QString &encryption, const QString &keyId)
+///
+/// Adds an own key (i.e., the key used by this client instance).
+///
+/// \param encryption encryption protocol namespace
+/// \param keyId ID of the key
+///
+
+///
+/// \fn QXmppTrustStorage::removeOwnKey(const QString &encryption)
+///
+/// Removes an own key (i.e., the key used by this client instance).
+///
+/// \param encryption encryption protocol namespace
+///
+
+///
+/// \fn QXmppTrustStorage::ownKey(const QString &encryption) const
+///
+/// Returns an own key (i.e., the key used by this client instance).
+///
+/// \param encryption encryption protocol namespace
+///
+/// \return the ID of the own key
+///
+
+///
+/// \fn QXmppTrustStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QString> &keyIds, const QXmppTrustStorage::TrustLevel trustLevel)
+///
+/// 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
+///
+
+///
+/// \fn QXmppTrustStorage::removeKeys(const QString &encryption, const QList<QString> &keyIds)
+///
+/// Removes keys.
+///
+/// If keyIds is not passed, all keys for encryption are removed.
+/// If encryption is also not passed, all keys are removed.
+///
+/// \param encryption encryption protocol namespace
+/// \param keyIds IDs of the keys
+///
+
+///
+/// \fn QXmppTrustStorage::keys(const QString &encryption, TrustLevels trustLevels = {}) const
+///
+/// Returns the JIDs of the key owners mapped to the IDs of their keys with a
+/// specific trust level.
+///
+/// If no trust levels are passed, all keys are returned.
+///
+/// \param encryption encryption protocol namespace
+/// \param trustLevels trust levels of the keys
+///
+/// \return the key owner JIDs mapped to their keys with a specific trust level
+///
+
+///
+/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QMultiHash<QString, QString> &keyIds, TrustLevel trustLevel)
+///
+/// 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
+///
+
+///
+/// \fn QXmppTrustStorage::setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel)
+///
+/// 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
+///
+
+///
+/// \fn QXmppTrustStorage::trustLevel(const QString &encryption, const QString &keyId) const
+///
+/// Returns the trust level of a key.
+///
+/// If the key is not stored, it is seen as automatically distrusted.
+///
+/// \param encryption encryption protocol namespace
+/// \param keyId ID of the key
+///
+/// \return the key's trust level
+///
+
+///
+/// \fn QXmppTrustStorage::addKeysForPostponedTrustDecisions(const QString &encryption, const QString &senderKeyId, const QList<QXmppTrustMessageKeyOwner> &keyOwners)
+///
+/// Adds keys that cannot be authenticated or distrusted directly because the
+/// key of the trust message's sender is not yet authenticated.
+///
+/// Those keys are being authenticated or distrusted once the sender's key is
+/// authenticated.
+/// Each element of keyOwners (i.e., keyOwner) can contain keys for postponed
+/// authentication as trustedKeys or for postponed distrusting as
+/// distrustedKeys.
+///
+/// If keys of keyOwner.trustedKeys() are already stored for postponed
+/// distrusting, they are changed to be used for postponed authentication.
+/// If keys of keyOwner.distrustedKeys() are already stored for postponed
+/// authentication, they are changed to be used for postponed distrusting.
+/// If the same keys are in keyOwner.trustedKeys() and
+/// keyOwner.distrustedKeys(), they are used for postponed distrusting.
+///
+/// \param encryption encryption protocol namespace
+/// \param senderKeyId key ID of the trust message's sender
+/// \param keyOwners key owners containing key IDs for postponed trust decisions
+///
+
+///
+/// \fn QXmppTrustStorage::removeKeysForPostponedTrustDecisions(const QString &encryption, const QList<QString> &keyIdsForAuthentication, const QList<QString> &keyIdsForDistrusting)
+///
+/// Removes keys for postponed authentication or distrusting.
+///
+/// \param encryption encryption protocol namespace
+/// \param keyIdsForAuthentication IDs of the keys for postponed authentication
+/// \param keyIdsForDistrusting IDs of the keys for postponed distrusting
+///
+
+///
+/// \fn QXmppTrustStorage::removeKeysForPostponedTrustDecisions(const QString &encryption = {}, const QList<QString> &senderKeyIds = {})
+///
+/// Removes keys for postponed authentication or distrusting by the trust
+/// message's sender's key ID.
+///
+/// If senderKeyIds is empty, all keys for encryption are removed.
+/// If encryption is empty too, all keys are removed.
+///
+/// \param encryption encryption protocol namespace
+/// \param senderKeyIds key IDs of the trust messages' senders
+///
+
+///
+/// \fn QXmppTrustStorage::keysForPostponedTrustDecisions(const QString &encryption, const QList<QString> &senderKeyIds = {})
+///
+/// Returns the JIDs of key owners mapped to the IDs of their keys stored for
+/// postponed authentication (true) or postponed distrusting (false).
+///
+/// If senderKeyIds is empty, all keys for encryption are returned.
+///
+/// \param encryption encryption protocol namespace
+/// \param senderKeyIds key IDs of the trust messages' senders
+///
+/// \return the key owner JIDs mapped to their keys
+///
diff --git a/src/client/QXmppTrustStorage.h b/src/client/QXmppTrustStorage.h
new file mode 100644
index 00000000..1252c06b
--- /dev/null
+++ b/src/client/QXmppTrustStorage.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008-2021 The QXmpp developers
+ *
+ * Author:
+ * Melvin Keskin <melvo@olomono.de>
+ *
+ * Source:
+ * https://github.com/qxmpp-project/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+#ifndef QXMPPTRUSTSTORAGE_H
+#define QXMPPTRUSTSTORAGE_H
+
+#include "QXmppGlobal.h"
+
+#include <QFuture>
+
+class QXmppTrustMessageKeyOwner;
+
+class QXMPP_EXPORT QXmppTrustStorage
+{
+public:
+ ///
+ /// trust level of public long-term keys used by end-to-end encryption
+ /// protocols
+ ///
+ enum TrustLevel {
+ AutomaticallyDistrusted = 1, ///< The key is automatically distrusted (e.g., by ATM's security policy).
+ ManuallyDistrusted = 2, ///< The key is manually distrusted (e.g., by clicking a button or ATM).
+ AutomaticallyTrusted = 4, ///< The key is automatically trusted (e.g., by the client for all keys of a bare JID until one of it is authenticated).
+ ManuallyTrusted = 8, ///< The key is manually trusted (e.g., by clicking a button).
+ Authenticated = 16, ///< The key is authenticated (e.g., by QR code scanning or ATM).
+ };
+ Q_DECLARE_FLAGS(TrustLevels, TrustLevel)
+
+ virtual QFuture<void> addOwnKey(const QString &encryption, const QString &keyId) = 0;
+ virtual QFuture<void> removeOwnKey(const QString &encryption) = 0;
+ virtual QFuture<QString> ownKey(const QString &encryption) const = 0;
+
+ virtual QFuture<void> addKeys(const QString &encryption, const QString &keyOwnerJid, const QList<QString> &keyIds, TrustLevel trustLevel = TrustLevel::AutomaticallyDistrusted) = 0;
+ virtual QFuture<void> removeKeys(const QString &encryption = {}, const QList<QString> &keyIds = {}) = 0;
+ virtual QFuture<QHash<TrustLevel, QMultiHash<QString, QString>>> keys(const QString &encryption, TrustLevels trustLevels = {}) const = 0;
+
+ virtual QFuture<void> setTrustLevel(const QString &encryption, const QMultiHash<QString, QString> &keyIds, TrustLevel trustLevel) = 0;
+ virtual QFuture<void> setTrustLevel(const QString &encryption, const QList<QString> &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) = 0;
+ virtual QFuture<TrustLevel> trustLevel(const QString &encryption, const QString &keyId) const = 0;
+
+ virtual QFuture<void> addKeysForPostponedTrustDecisions(const QString &encryption, const QString &senderKeyId, const QList<QXmppTrustMessageKeyOwner> &keyOwners) = 0;
+ virtual QFuture<void> removeKeysForPostponedTrustDecisions(const QString &encryption, const QList<QString> &keyIdsForAuthentication, const QList<QString> &keyIdsForDistrusting) = 0;
+ virtual QFuture<void> removeKeysForPostponedTrustDecisions(const QString &encryption = {}, const QList<QString> &senderKeyIds = {}) = 0;
+ virtual QFuture<QHash<bool, QMultiHash<QString, QString>>> keysForPostponedTrustDecisions(const QString &encryption, const QList<QString> &senderKeyIds = {}) = 0;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTrustStorage::TrustLevels)
+
+#endif // QXMPPTRUSTSTORAGE_H