forked from blue/squawk
some further work on omemo, far from done yet
This commit is contained in:
parent
6f32e99593
commit
77dd28b600
18 changed files with 161 additions and 43 deletions
|
@ -110,10 +110,10 @@ void Core::DiscoveryHandler::onInfoReceived(const QXmppDiscoveryIq& info)
|
|||
}
|
||||
}
|
||||
acc->setPepSupport(pepSupported ? Shared::Support::supported : Shared::Support::unsupported);
|
||||
} else {
|
||||
qDebug() << "Received info for account" << accName << "about" << from;
|
||||
} else {
|
||||
QString node = info.queryNode();
|
||||
if (!node.isEmpty()) {
|
||||
qDebug() << "Received features and identities for account" << accName << "about" << from;
|
||||
QStringList feats = info.features();
|
||||
std::set<Shared::Identity> identities;
|
||||
std::set<QString> features(feats.begin(), feats.end());
|
||||
|
@ -135,7 +135,7 @@ void Core::DiscoveryHandler::onInfoReceived(const QXmppDiscoveryIq& info)
|
|||
} else {
|
||||
Contact* cont = acc->rh->getContact(from);
|
||||
if (cont != nullptr) {
|
||||
qDebug() << "Received info for account" << accName << "about" << from;
|
||||
qDebug() << "Received info for account" << accName << "about contact" << from;
|
||||
QList<QXmppDiscoveryIq::Identity> identities = info.identities();
|
||||
bool pepSupported = false;
|
||||
for (const QXmppDiscoveryIq::Identity& identity : identities) {
|
||||
|
|
|
@ -154,6 +154,19 @@ QXmppTask<void> Core::OmemoHandler::resetAll() {
|
|||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
void Core::OmemoHandler::getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const {
|
||||
QHash<uint32_t, Device> devs;
|
||||
try {
|
||||
devs = devices->getRecord(jid);
|
||||
} catch (const DataBase::NotFound& error) {}
|
||||
|
||||
for (QHash<uint32_t, Device>::const_iterator itr = devs.begin(), end = devs.end(); itr != end; ++itr) {
|
||||
const Device& dev = itr.value();
|
||||
out.emplace_back(itr.key(), dev.keyId, dev.label, QDateTime(), Shared::TrustLevel::undecided, Shared::EncryptionProtocol::omemo2, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) {
|
||||
in >> device.label;
|
||||
in >> device.keyId;
|
||||
|
|
|
@ -17,9 +17,15 @@
|
|||
#ifndef CORE_OMEMOHANDLER_H
|
||||
#define CORE_OMEMOHANDLER_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include <QXmppOmemoStorage.h>
|
||||
#include <cache.h>
|
||||
|
||||
#include <shared/keyinfo.h>
|
||||
#include <shared/enums.h>
|
||||
|
||||
Q_DECLARE_METATYPE(QXmppOmemoStorage::OwnDevice);
|
||||
Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
|
||||
|
||||
|
@ -34,24 +40,26 @@ public:
|
|||
OmemoHandler(Account* account);
|
||||
~OmemoHandler() override;
|
||||
|
||||
QXmppTask<OmemoData> allData() override;
|
||||
virtual QXmppTask<OmemoData> allData() override;
|
||||
|
||||
QXmppTask<void> setOwnDevice(const std::optional<OwnDevice> &device) override;
|
||||
virtual QXmppTask<void> setOwnDevice(const std::optional<OwnDevice> &device) override;
|
||||
|
||||
QXmppTask<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override;
|
||||
QXmppTask<void> removeSignedPreKeyPair(uint32_t keyId) override;
|
||||
virtual QXmppTask<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override;
|
||||
virtual QXmppTask<void> removeSignedPreKeyPair(uint32_t keyId) override;
|
||||
|
||||
QXmppTask<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override;
|
||||
QXmppTask<void> removePreKeyPair(uint32_t keyId) override;
|
||||
virtual QXmppTask<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override;
|
||||
virtual QXmppTask<void> removePreKeyPair(uint32_t keyId) override;
|
||||
|
||||
QXmppTask<void> addDevice(const QString &jid, uint32_t deviceId, const Device &device) override;
|
||||
QXmppTask<void> removeDevice(const QString &jid, uint32_t deviceId) override;
|
||||
QXmppTask<void> removeDevices(const QString &jid) override;
|
||||
virtual QXmppTask<void> addDevice(const QString &jid, uint32_t deviceId, const Device &device) override;
|
||||
virtual QXmppTask<void> removeDevice(const QString &jid, uint32_t deviceId) override;
|
||||
virtual QXmppTask<void> removeDevices(const QString &jid) override;
|
||||
|
||||
QXmppTask<void> resetAll() override;
|
||||
virtual QXmppTask<void> resetAll() override;
|
||||
|
||||
bool hasOwnDevice();
|
||||
|
||||
void getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const;
|
||||
|
||||
private:
|
||||
Account* acc;
|
||||
std::optional<OwnDevice> ownDevice;
|
||||
|
|
|
@ -326,6 +326,20 @@ 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);
|
||||
if (itr != keysByProtocol.end()) {
|
||||
try {
|
||||
Keys map = itr->second->getRecord(jid);
|
||||
return map;
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
return Keys();
|
||||
}
|
||||
} else {
|
||||
return Keys();
|
||||
}
|
||||
}
|
||||
|
||||
Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level)
|
||||
{
|
||||
switch (level) {
|
||||
|
|
|
@ -41,27 +41,29 @@ public:
|
|||
typedef std::map<QByteArray, Shared::TrustLevel> Keys;
|
||||
typedef DataBase::Cache<QString, Keys> KeyCache;
|
||||
|
||||
virtual QXmppTask<void> resetAll(CSR encryption);
|
||||
virtual QXmppTask<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId);
|
||||
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel);
|
||||
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel);
|
||||
virtual QXmppTask<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels);
|
||||
virtual QXmppTask<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels);
|
||||
virtual QXmppTask<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels);
|
||||
virtual QXmppTask<void> removeKeys(CSR encryption);
|
||||
virtual QXmppTask<void> removeKeys(CSR encryption, CSR keyOwnerJid);
|
||||
virtual QXmppTask<void> removeKeys(CSR encryption, CLBAR keyIds);
|
||||
virtual QXmppTask<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel);
|
||||
virtual QXmppTask<QByteArray> ownKey(CSR encryption);
|
||||
virtual QXmppTask<void> resetOwnKey(CSR encryption);
|
||||
virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId);
|
||||
virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption);
|
||||
virtual QXmppTask<void> resetSecurityPolicy(CSR encryption);
|
||||
virtual QXmppTask<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy);
|
||||
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;
|
||||
virtual QXmppTask<void> setSecurityPolicy(CSR 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;
|
||||
|
||||
private:
|
||||
KeyCache* createNewCache(const QString& encryption);
|
||||
KeyCache* getCache(const QString& encryption);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "vcardhandler.h"
|
||||
#include "core/account.h"
|
||||
|
||||
constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2";
|
||||
|
||||
Core::VCardHandler::VCardHandler(Account* account):
|
||||
QObject(),
|
||||
acc(account),
|
||||
|
@ -102,6 +104,20 @@ void Core::VCardHandler::onVCardReceived(const QXmppVCardIq& card) {
|
|||
|
||||
Shared::Info info(jid, Shared::EntryType::contact);
|
||||
item->handleResponseVCard(card, resource, info.getVCardRef());
|
||||
#ifdef WITH_OMEMO
|
||||
std::list<Shared::KeyInfo>& aks = info.getActiveKeysRef();
|
||||
acc->oh->getDevices(jid, aks);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << aks.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : aks) {
|
||||
std::map<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint);
|
||||
if (itr != trustLevels.end()) {
|
||||
key.trustLevel = itr->second;
|
||||
qDebug() << "Found a trust level for a device!";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
emit acc->infoReady(info);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue