2022-12-19 15:43:24 +00:00
|
|
|
// Squawk messenger.
|
|
|
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program 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 General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef CORE_TRUSTHANDLER_H
|
|
|
|
#define CORE_TRUSTHANDLER_H
|
|
|
|
|
|
|
|
#include <shared/enums.h>
|
2023-03-17 20:59:51 +00:00
|
|
|
#include <shared/trustsummary.h>
|
2022-12-19 15:43:24 +00:00
|
|
|
|
|
|
|
#include <QXmppTrustStorage.h>
|
|
|
|
#include <cache.h>
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class Account;
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
class TrustHandler : public QObject, public QXmppTrustStorage {
|
|
|
|
Q_OBJECT
|
2022-12-19 15:43:24 +00:00
|
|
|
public:
|
|
|
|
TrustHandler(Account* account);
|
|
|
|
~TrustHandler();
|
|
|
|
|
2023-03-17 23:50:04 +00:00
|
|
|
signals:
|
|
|
|
void trustLevelsChanged(const QString& jid, const Shared::TrustSummary& summary) const;
|
|
|
|
|
|
|
|
public:
|
2022-12-19 15:43:24 +00:00
|
|
|
typedef QMultiHash<QString, QByteArray> MultySB;
|
|
|
|
typedef QHash<QString, MultySB> HashSM;
|
|
|
|
typedef const QList<QString>& CLSR;
|
|
|
|
typedef const QList<QByteArray>& CLBAR;
|
|
|
|
typedef const QString& CSR;
|
|
|
|
typedef QXmpp::TrustLevel TL;
|
|
|
|
typedef QHash<QString, QHash<QByteArray, TL>> HSHBTL;
|
|
|
|
|
|
|
|
typedef std::map<QByteArray, Shared::TrustLevel> Keys;
|
|
|
|
typedef DataBase::Cache<QString, Keys> KeyCache;
|
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> resetAll(CSR encryption) override;
|
|
|
|
virtual QXmppTask<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId) override;
|
|
|
|
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel) override;
|
|
|
|
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel) override;
|
|
|
|
virtual QXmppTask<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels) override;
|
|
|
|
virtual QXmppTask<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels) override;
|
|
|
|
virtual QXmppTask<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels) override;
|
|
|
|
virtual QXmppTask<void> removeKeys(CSR encryption) override;
|
|
|
|
virtual QXmppTask<void> removeKeys(CSR encryption, CSR keyOwnerJid) override;
|
|
|
|
virtual QXmppTask<void> removeKeys(CSR encryption, CLBAR keyIds) override;
|
|
|
|
virtual QXmppTask<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel) override;
|
|
|
|
virtual QXmppTask<QByteArray> ownKey(CSR encryption) override;
|
|
|
|
virtual QXmppTask<void> resetOwnKey(CSR encryption) override;
|
|
|
|
virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId) override;
|
|
|
|
virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption) override;
|
|
|
|
virtual QXmppTask<void> resetSecurityPolicy(CSR encryption) override;
|
2023-03-17 20:59:51 +00:00
|
|
|
virtual QXmppTask<void> setSecurityPolicy(const QString& encryption, QXmpp::TrustSecurityPolicy securityPolicy) override;
|
2022-12-19 15:43:24 +00:00
|
|
|
|
|
|
|
static TL convert(Shared::TrustLevel level);
|
|
|
|
static Shared::TrustLevel convert(TL level);
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
Keys getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const;
|
|
|
|
Shared::TrustSummary getSummary(const QString& jid) const;
|
2023-03-02 18:17:06 +00:00
|
|
|
|
2022-12-19 15:43:24 +00:00
|
|
|
private:
|
|
|
|
KeyCache* createNewCache(const QString& encryption);
|
|
|
|
KeyCache* getCache(const QString& encryption);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Account* acc;
|
|
|
|
DataBase db;
|
|
|
|
QFile protocols;
|
|
|
|
DataBase::Cache<QString, uint8_t>* securityPolicies;
|
|
|
|
DataBase::Cache<QString, QByteArray>* ownKeys;
|
|
|
|
std::map<QString, KeyCache*> keysByProtocol;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CORE_TRUSTHANDLER_H
|