trust summary gui delivery
This commit is contained in:
parent
fffef9876a
commit
4f295fee3c
13 changed files with 169 additions and 143 deletions
|
@ -21,9 +21,15 @@
|
|||
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, bool p_active, NetworkAccess* p_net, QObject* parent):
|
||||
Core::Account::Account(
|
||||
const QString& p_login,
|
||||
const QString& p_server,
|
||||
const QString& p_password,
|
||||
const QString& p_name,
|
||||
bool p_active,
|
||||
NetworkAccess* p_net,
|
||||
QObject* parent
|
||||
):
|
||||
QObject(parent),
|
||||
name(p_name),
|
||||
archiveQueries(),
|
||||
|
@ -36,13 +42,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
rh(new RosterHandler(this)),
|
||||
vh(new VCardHandler(this)),
|
||||
dh(new DiscoveryHandler(this)),
|
||||
#ifdef WITH_OMEMO
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
th(new TrustHandler(this)),
|
||||
#endif
|
||||
#ifdef WITH_OMEMO
|
||||
oh(new OmemoHandler(this)),
|
||||
tm(new QXmppTrustManager(th)),
|
||||
om(new QXmppOmemoManager(oh)),
|
||||
#endif
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
tm(new QXmppTrustManager(th)),
|
||||
cm(new QXmppCarbonManagerV2()),
|
||||
psm(new QXmppPubSubManager()),
|
||||
#else
|
||||
|
@ -157,7 +165,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
}
|
||||
}
|
||||
|
||||
Account::~Account() {
|
||||
Core::Account::~Account() {
|
||||
if (reconnectScheduled) {
|
||||
reconnectScheduled = false;
|
||||
reconnectTimer->stop();
|
||||
|
@ -701,9 +709,7 @@ void Core::Account::setActive(bool p_active) {
|
|||
if (active != p_active) {
|
||||
active = p_active;
|
||||
|
||||
emit changed({
|
||||
{"active", active}
|
||||
});
|
||||
emit changed({{"active", active}});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -795,14 +801,12 @@ void Core::Account::addContactToGroupRequest(const QString& jid, const QString&
|
|||
void Core::Account::removeContactFromGroupRequest(const QString& jid, const QString& groupName) {
|
||||
rh->removeContactFromGroupRequest(jid, groupName);}
|
||||
|
||||
void Core::Account::renameContactRequest(const QString& jid, const QString& newName)
|
||||
{
|
||||
void Core::Account::renameContactRequest(const QString& jid, const QString& newName) {
|
||||
Contact* cnt = rh->getContact(jid);
|
||||
if (cnt == 0) {
|
||||
if (cnt == 0)
|
||||
qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping";
|
||||
} else {
|
||||
else
|
||||
rm->renameItem(jid, newName);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::invalidatePassword() {
|
||||
|
|
|
@ -191,14 +191,16 @@ private:
|
|||
RosterHandler* rh;
|
||||
VCardHandler* vh;
|
||||
DiscoveryHandler* dh;
|
||||
#ifdef WITH_OMEMO
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
TrustHandler* th;
|
||||
#endif
|
||||
#ifdef WITH_OMEMO
|
||||
OmemoHandler* oh;
|
||||
|
||||
QXmppTrustManager* tm;
|
||||
QXmppOmemoManager* om;
|
||||
#endif
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
QXmppTrustManager* tm;
|
||||
QXmppCarbonManagerV2* cm;
|
||||
QXmppPubSubManager* psm;
|
||||
#else
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "core/account.h"
|
||||
#include "core/adapterfunctions.h"
|
||||
|
||||
constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2";
|
||||
|
||||
Core::OmemoHandler::OmemoHandler(Account* account) :
|
||||
QObject(),
|
||||
QXmppOmemoStorage(),
|
||||
|
@ -182,7 +180,7 @@ void Core::OmemoHandler::requestOwnBundles() {
|
|||
void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
|
||||
std::list<Shared::KeyInfo> keys;
|
||||
acc->oh->getDevices(jid, keys);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
|
@ -200,7 +198,7 @@ void Core::OmemoHandler::onOwnBundlesReceived() {
|
|||
QString jid = acc->getBareJid();
|
||||
std::list<Shared::KeyInfo> keys;
|
||||
acc->oh->getDevices(jid, keys);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
|
|
|
@ -33,8 +33,7 @@ Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
|
|||
namespace Core {
|
||||
class Account;
|
||||
|
||||
class OmemoHandler :public QObject, public QXmppOmemoStorage
|
||||
{
|
||||
class OmemoHandler : public QObject, public QXmppOmemoStorage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair;
|
||||
|
|
|
@ -96,6 +96,9 @@ void Core::RosterHandler::addedAccount(const QString& jid) {
|
|||
|
||||
if (newContact) {
|
||||
QMap<QString, QVariant> cData = contact->getInfo();
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
cData.insert("trust", QVariant::fromValue(acc->th->getSummary(jid)));
|
||||
#endif
|
||||
int grCount = 0;
|
||||
for (QSet<QString>::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) {
|
||||
const QString& groupName = *itr;
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
#include "core/account.h"
|
||||
#include "core/adapterfunctions.h"
|
||||
|
||||
using namespace Core;
|
||||
|
||||
Core::TrustHandler::TrustHandler(Account* account):
|
||||
QObject(),
|
||||
QXmppTrustStorage(),
|
||||
acc(account),
|
||||
db(acc->getName() + "/trust"),
|
||||
protocols(db.createDirectory() + "/protocols"),
|
||||
|
@ -161,7 +161,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
|
||||
QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
|
@ -179,7 +179,7 @@ QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
|
|||
return Core::makeReadyTask(std::move(found));
|
||||
}
|
||||
|
||||
QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::keys(
|
||||
QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> Core::TrustHandler::keys(
|
||||
const QString& encryption,
|
||||
const QList<QString>& keyOwnerJids,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
|
@ -202,7 +202,7 @@ QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::ke
|
|||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandler::keys(
|
||||
QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> Core::TrustHandler::keys(
|
||||
const QString& encryption,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
|
@ -219,17 +219,17 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandle
|
|||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
|
||||
getCache(encryption)->drop();
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
|
||||
getCache(encryption)->removeRecord(keyOwnerJid);
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) {
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) {
|
||||
std::set<QByteArray> set;
|
||||
for (const QByteArray& keyId : keyIds)
|
||||
set.insert(keyId);
|
||||
|
@ -258,7 +258,7 @@ QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<
|
|||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::addKeys(
|
||||
QXmppTask<void> Core::TrustHandler::addKeys(
|
||||
const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
const QList<QByteArray>& keyIds,
|
||||
|
@ -287,7 +287,7 @@ QXmppTask<void> TrustHandler::addKeys(
|
|||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
|
||||
QXmppTask<QByteArray> Core::TrustHandler::ownKey(const QString& encryption) {
|
||||
QByteArray res;
|
||||
try {
|
||||
res = ownKeys->getRecord(encryption);
|
||||
|
@ -295,7 +295,7 @@ QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
|
|||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
try {
|
||||
ownKeys->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
|
@ -303,12 +303,12 @@ QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
|
|||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) {
|
||||
QXmppTask<void> Core::TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) {
|
||||
ownKeys->forceRecord(encryption, keyId);
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString& encryption) {
|
||||
QXmppTask<QXmpp::TrustSecurityPolicy> Core::TrustHandler::securityPolicy(const QString& encryption) {
|
||||
QXmpp::TrustSecurityPolicy res;
|
||||
try {
|
||||
res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption));
|
||||
|
@ -316,14 +316,14 @@ QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString
|
|||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::resetSecurityPolicy(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::resetSecurityPolicy(const QString& encryption) {
|
||||
try {
|
||||
securityPolicies->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::setSecurityPolicy(
|
||||
QXmppTask<void> Core::TrustHandler::setSecurityPolicy(
|
||||
const QString& encryption,
|
||||
QXmpp::TrustSecurityPolicy securityPolicy)
|
||||
{
|
||||
|
@ -333,8 +333,9 @@ QXmppTask<void> TrustHandler::setSecurityPolicy(
|
|||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, const QString& jid) const {
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(protocol);
|
||||
Core::TrustHandler::Keys Core::TrustHandler::getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const {
|
||||
const QString& prt = Shared::TrustSummary::protocolKeys.at(protocol);
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(prt);
|
||||
if (itr != keysByProtocol.end()) {
|
||||
try {
|
||||
Keys map = itr->second->getRecord(jid);
|
||||
|
@ -347,6 +348,21 @@ Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, co
|
|||
}
|
||||
}
|
||||
|
||||
Shared::TrustSummary Core::TrustHandler::getSummary(const QString& jid) const {
|
||||
Shared::TrustSummary result;
|
||||
for (const std::pair<const QString, KeyCache*>& pair : keysByProtocol) {
|
||||
try {
|
||||
Keys keys = pair.second->getRecord(jid);
|
||||
Shared::EncryptionProtocol protocol = Shared::TrustSummary::protocolValues.at(pair.first);
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : keys) {
|
||||
result.increment(protocol, trust.second);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) {
|
||||
switch (level) {
|
||||
case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define CORE_TRUSTHANDLER_H
|
||||
|
||||
#include <shared/enums.h>
|
||||
#include <shared/trustsummary.h>
|
||||
|
||||
#include <QXmppTrustStorage.h>
|
||||
#include <cache.h>
|
||||
|
@ -25,7 +26,8 @@
|
|||
namespace Core {
|
||||
class Account;
|
||||
|
||||
class TrustHandler : public QXmppTrustStorage {
|
||||
class TrustHandler : public QObject, public QXmppTrustStorage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TrustHandler(Account* account);
|
||||
~TrustHandler();
|
||||
|
@ -57,12 +59,13 @@ public:
|
|||
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;
|
||||
virtual QXmppTask<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy) override;
|
||||
virtual QXmppTask<void> setSecurityPolicy(const QString& encryption, QXmpp::TrustSecurityPolicy securityPolicy) override;
|
||||
|
||||
static TL convert(Shared::TrustLevel level);
|
||||
static Shared::TrustLevel convert(TL level);
|
||||
|
||||
Keys getKeys(const QString& protocol, const QString& jid) const;
|
||||
Keys getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const;
|
||||
Shared::TrustSummary getSummary(const QString& jid) const;
|
||||
|
||||
private:
|
||||
KeyCache* createNewCache(const QString& encryption);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue