Implement device verification

This commit is contained in:
Tobias Fella
2022-04-03 23:54:28 +02:00
parent 3071901a47
commit b8262fef92
19 changed files with 403 additions and 7 deletions

View File

@@ -140,6 +140,10 @@ Q_SIGNALS:
void userConsentRequired(QUrl url);
void testConnectionResult(const QString &connection, bool usable);
void isOnlineChanged(bool isOnline);
void keyVerificationRequest(int timeLeft, Connection *connection, const QString &transactionId, const QString &deviceId);
void keyVerificationStart();
void keyVerificationAccept(const QString &commitment);
void keyVerificationKey(const QString &sas);
public Q_SLOTS:
void logout(Quotient::Connection *conn, bool serverSideLogout);

View File

@@ -6,11 +6,15 @@
#include <csapi/device_management.h>
#include "controller.h"
#include <connection.h>
DevicesModel::DevicesModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, &DevicesModel::fetchDevices);
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [=]() {
DevicesModel::fetchDevices();
Q_EMIT connectionChanged();
});
fetchDevices();
}
@@ -94,3 +98,8 @@ void DevicesModel::setName(int index, const QString &name)
endResetModel();
});
}
Connection *DevicesModel::connection() const
{
return Controller::instance().activeConnection();
}

View File

@@ -9,10 +9,17 @@
using namespace Quotient;
namespace Quotient
{
class Connection;
}
class DevicesModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(Connection *connection READ connection NOTIFY connectionChanged)
public:
enum Roles {
Id,
@@ -31,6 +38,11 @@ public:
Q_INVOKABLE void logout(int index, const QString &password);
Q_INVOKABLE void setName(int index, const QString &name);
Connection *connection() const;
Q_SIGNALS:
void connectionChanged();
private:
void fetchDevices();
QVector<Quotient::Device> m_devices;

View File

@@ -78,6 +78,9 @@
#include "userlistmodel.h"
#include "webshortcutmodel.h"
#include "windowcontroller.h"
#ifdef QUOTIENT_07
#include <keyverificationsession.h>
#endif
#ifdef HAVE_COLORSCHEME
#include "colorschemer.h"
#endif
@@ -225,6 +228,11 @@ int main(int argc, char *argv[])
qRegisterMetaType<NeoChatUser *>("NeoChatUser*");
qRegisterMetaType<GetRoomEventsJob *>("GetRoomEventsJob*");
qRegisterMetaType<QMimeType>("QMimeType");
#ifdef QUOTIENT_07
qRegisterMetaType<KeyVerificationSession *>("KeyVerificationSession*");
qmlRegisterUncreatableType<KeyVerificationSession>("org.kde.neochat", 1, 0, "KeyVerificationSession", {});
qRegisterMetaType<QVector<EmojiEntry>>("QVector<EmojiEntry>");
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<Emoji>();

View File

@@ -55,6 +55,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[FormattedBodyRole] = "formattedBody";
roles[AuthorIdRole] = "authorId";
roles[MediaUrlRole] = "mediaUrl";
roles[VerifiedRole] = "verified";
return roles;
}
@@ -791,6 +792,17 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return m_currentRoom->urlToDownload(evt.id());
}
if (role == VerifiedRole) {
#ifdef QUOTIENT_07
if (evt.originalEvent()) {
auto encrypted = dynamic_cast<const EncryptedEvent *>(evt.originalEvent());
Q_ASSERT(encrypted);
return m_currentRoom->connection()->isVerifiedSession(encrypted->sessionId());
}
return false;
#endif
}
return {};
}

View File

@@ -48,6 +48,7 @@ public:
// For debugging
EventResolvedTypeRole,
AuthorIdRole,
VerifiedRole,
LastRole, // Keep this last
};
Q_ENUM(EventRoles)