Own omemo key display, a bit of CMake clean up
This commit is contained in:
parent
19835af3cf
commit
00af582287
16 changed files with 443 additions and 360 deletions
|
@ -1,18 +1,20 @@
|
|||
// 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/>.
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "manager.h"
|
||||
|
||||
|
@ -39,17 +41,14 @@ Core::DelayManager::Manager::Manager(const QString& poj, Job::Id mpj, QObject* p
|
|||
requestedBundles(),
|
||||
#endif
|
||||
ownJid(poj)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
Core::DelayManager::Manager::~Manager() {
|
||||
for (const std::pair<const Job::Id, Job*>& pair : runningJobs) {
|
||||
for (const std::pair<const Job::Id, Job*>& pair : runningJobs)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
for (Job* job : jobSequence) {
|
||||
for (Job* job : jobSequence)
|
||||
delete job;
|
||||
}
|
||||
}
|
||||
|
||||
Core::DelayManager::Job::Id Core::DelayManager::Manager::getNextJobId() {
|
||||
|
@ -151,11 +150,10 @@ void Core::DelayManager::Manager::preScheduleJob(Job* job) {
|
|||
|
||||
void Core::DelayManager::Manager::scheduleJob(Job* job) {
|
||||
preScheduleJob(job);
|
||||
if (runningJobs.size() < maxParallelJobs) {
|
||||
if (runningJobs.size() < maxParallelJobs)
|
||||
executeJob(job);
|
||||
} else {
|
||||
else
|
||||
scheduledJobs.push_back(job);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::preExecuteJob(Job* job) {
|
||||
|
@ -190,9 +188,9 @@ void Core::DelayManager::Manager::executeJob(Job* job) {
|
|||
|
||||
void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) {
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
if (itr == runningJobs.end())
|
||||
throw JobNotFound(jobId, "jobIsDone");
|
||||
}
|
||||
|
||||
Job* job = itr->second;
|
||||
delete job;
|
||||
runningJobs.erase(itr);
|
||||
|
@ -292,9 +290,9 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
|
|||
Job::Id jobId = cardItr->second;
|
||||
requestedVCards.erase(cardItr);
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
if (itr == runningJobs.end())
|
||||
throw JobNotFound(jobId, "receivedVCard");
|
||||
}
|
||||
|
||||
Job* job = itr->second;
|
||||
|
||||
switch (job->type) {
|
||||
|
@ -330,9 +328,9 @@ void Core::DelayManager::Manager::receivedOwnVCard(const Shared::VCard& card) {
|
|||
Job::Id jobId = ownVCardJobId;
|
||||
ownVCardJobId = 0;
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
if (itr == runningJobs.end())
|
||||
throw JobNotFound(jobId, "receivedOwnVCard");
|
||||
}
|
||||
|
||||
Job* job = itr->second;
|
||||
switch (job->type) {
|
||||
case Job::Type::ownCardInternal:
|
||||
|
@ -388,9 +386,9 @@ void Core::DelayManager::Manager::receivedOwnBundles(const std::list<Shared::Key
|
|||
Job::Id jobId = ownInfoJobId;
|
||||
ownInfoJobId = 0;
|
||||
std::map<Job::Id, Job*>::const_iterator jitr = runningJobs.find(jobId);
|
||||
if (jitr == runningJobs.end()) {
|
||||
if (jitr == runningJobs.end())
|
||||
throw JobNotFound(jobId, "receivedOwnBundles");
|
||||
}
|
||||
|
||||
Job* jb = jitr->second;
|
||||
OwnInfoForUser* job = dynamic_cast<OwnInfoForUser*>(jb);
|
||||
|
||||
|
@ -414,9 +412,9 @@ Core::DelayManager::Manager::UnexpectedJobType::UnexpectedJobType(Job::Type p_ty
|
|||
std::string Core::DelayManager::Manager::UnexpectedJobType::getMessage() const{
|
||||
std::string msg("Unexpected job type: ");
|
||||
msg += Job::TypeString[static_cast<int>(type)];
|
||||
if (method.size() > 0) {
|
||||
if (method.size() > 0)
|
||||
msg += " in method " + method;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
@ -430,8 +428,8 @@ std::string Core::DelayManager::Manager::JobNotFound::getMessage() const {
|
|||
std::string msg("Job with id ");
|
||||
msg += std::to_string(id);
|
||||
msg += " was not found";
|
||||
if (method.size() > 0) {
|
||||
if (method.size() > 0)
|
||||
msg += " in method " + method;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -147,10 +147,9 @@ bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outg
|
|||
initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
|
||||
QString jid = sMsg.getPenPalJid();
|
||||
Conference* cnt = acc->rh->getConference(jid);
|
||||
if (cnt == 0) {
|
||||
if (cnt == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id());
|
||||
if (std::get<0>(ids)) {
|
||||
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}};
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CORE_MESSAGEHANDLER_H
|
||||
#define CORE_MESSAGEHANDLER_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
@ -36,15 +35,9 @@
|
|||
#include <shared/pathcheck.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*/
|
||||
|
||||
class Account;
|
||||
|
||||
class MessageHandler : public QObject
|
||||
{
|
||||
class MessageHandler : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MessageHandler(Account* account);
|
||||
|
@ -90,5 +83,3 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CORE_MESSAGEHANDLER_H
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
// 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/>.
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#include "omemohandler.h"
|
||||
|
@ -196,18 +198,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(Shared::EncryptionProtocol::omemo2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
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!";
|
||||
}
|
||||
}
|
||||
std::list<Shared::KeyInfo> keys = readKeys(jid);
|
||||
|
||||
Contact* cnt = acc->rh->getContact(jid);
|
||||
if (cnt)
|
||||
|
@ -217,23 +208,35 @@ void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
|
|||
}
|
||||
|
||||
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(Shared::EncryptionProtocol::omemo2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
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!";
|
||||
}
|
||||
}
|
||||
std::list<Shared::KeyInfo> keys = readKeys(acc->getBareJid());
|
||||
if (ownDevice)
|
||||
keys.emplace_front(
|
||||
ownDevice->id,
|
||||
ownDevice->publicIdentityKey,
|
||||
ownDevice->label,
|
||||
QDateTime::currentDateTime(),
|
||||
Shared::TrustLevel::authenticated,
|
||||
Shared::EncryptionProtocol::omemo2,
|
||||
true
|
||||
);
|
||||
|
||||
acc->delay->receivedOwnBundles(keys);
|
||||
}
|
||||
|
||||
std::list<Shared::KeyInfo> Core::OmemoHandler::readKeys(const QString& jid) {
|
||||
std::list<Shared::KeyInfo> keys;
|
||||
getDevices(jid, keys);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
|
||||
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
std::map<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint);
|
||||
if (itr != trustLevels.end())
|
||||
key.trustLevel = itr->second;
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
void Core::OmemoHandler::onOmemoDeviceAdded(const QString& jid, uint32_t id) {
|
||||
SHARED_UNUSED(id);
|
||||
qDebug() << "OMEMO device added for" << jid;
|
||||
|
|
|
@ -69,6 +69,7 @@ public slots:
|
|||
private slots:
|
||||
void onBundlesReceived(const QString& jid);
|
||||
void onOwnBundlesReceived();
|
||||
std::list<Shared::KeyInfo> readKeys(const QString& jid);
|
||||
|
||||
private:
|
||||
Account* acc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue