mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Implement decryption of images
It is a bit of a hack, but it works...
This commit is contained in:
parent
a689118d71
commit
5bfdaff778
6 changed files with 57 additions and 9 deletions
|
@ -365,6 +365,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
src/CommunitiesList.h
|
src/CommunitiesList.h
|
||||||
src/LoginPage.h
|
src/LoginPage.h
|
||||||
src/MainWindow.h
|
src/MainWindow.h
|
||||||
|
src/MxcImageProvider.h
|
||||||
src/InviteeItem.h
|
src/InviteeItem.h
|
||||||
src/QuickSwitcher.h
|
src/QuickSwitcher.h
|
||||||
src/RegisterPage.h
|
src/RegisterPage.h
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
void
|
void
|
||||||
MxcImageResponse::run()
|
MxcImageResponse::run()
|
||||||
{
|
{
|
||||||
if (m_requestedSize.isValid()) {
|
if (m_requestedSize.isValid() && !m_encryptionInfo) {
|
||||||
QString fileName = QString("%1_%2x%3_crop")
|
QString fileName = QString("%1_%2x%3_crop")
|
||||||
.arg(m_id)
|
.arg(m_id)
|
||||||
.arg(m_requestedSize.width())
|
.arg(m_requestedSize.width())
|
||||||
|
@ -65,7 +65,12 @@ MxcImageResponse::run()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = QByteArray(res.data(), res.size());
|
auto temp = res;
|
||||||
|
if (m_encryptionInfo)
|
||||||
|
temp = mtx::crypto::to_string(
|
||||||
|
mtx::crypto::decrypt_file(temp, m_encryptionInfo.value()));
|
||||||
|
|
||||||
|
auto data = QByteArray(temp.data(), temp.size());
|
||||||
m_image.loadFromData(data);
|
m_image.loadFromData(data);
|
||||||
m_image.setText("original filename",
|
m_image.setText("original filename",
|
||||||
QString::fromStdString(originalFilename));
|
QString::fromStdString(originalFilename));
|
||||||
|
|
|
@ -6,14 +6,21 @@
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
||||||
|
#include <mtx/common.hpp>
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
class MxcImageResponse
|
class MxcImageResponse
|
||||||
: public QQuickImageResponse
|
: public QQuickImageResponse
|
||||||
, public QRunnable
|
, public QRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MxcImageResponse(const QString &id, const QSize &requestedSize)
|
MxcImageResponse(const QString &id,
|
||||||
|
const QSize &requestedSize,
|
||||||
|
boost::optional<mtx::crypto::EncryptedFile> encryptionInfo)
|
||||||
: m_id(id)
|
: m_id(id)
|
||||||
, m_requestedSize(requestedSize)
|
, m_requestedSize(requestedSize)
|
||||||
|
, m_encryptionInfo(encryptionInfo)
|
||||||
{
|
{
|
||||||
setAutoDelete(false);
|
setAutoDelete(false);
|
||||||
}
|
}
|
||||||
|
@ -29,19 +36,34 @@ public:
|
||||||
QString m_id, m_error;
|
QString m_id, m_error;
|
||||||
QSize m_requestedSize;
|
QSize m_requestedSize;
|
||||||
QImage m_image;
|
QImage m_image;
|
||||||
|
boost::optional<mtx::crypto::EncryptedFile> m_encryptionInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MxcImageProvider : public QQuickAsyncImageProvider
|
class MxcImageProvider
|
||||||
|
: public QObject
|
||||||
|
, public QQuickAsyncImageProvider
|
||||||
{
|
{
|
||||||
public:
|
Q_OBJECT
|
||||||
|
public slots:
|
||||||
QQuickImageResponse *requestImageResponse(const QString &id,
|
QQuickImageResponse *requestImageResponse(const QString &id,
|
||||||
const QSize &requestedSize) override
|
const QSize &requestedSize) override
|
||||||
{
|
{
|
||||||
MxcImageResponse *response = new MxcImageResponse(id, requestedSize);
|
boost::optional<mtx::crypto::EncryptedFile> info;
|
||||||
|
auto temp = infos.find("mxc://" + id);
|
||||||
|
if (temp != infos.end())
|
||||||
|
info = *temp;
|
||||||
|
|
||||||
|
MxcImageResponse *response = new MxcImageResponse(id, requestedSize, info);
|
||||||
pool.start(response);
|
pool.start(response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addEncryptionInfo(mtx::crypto::EncryptedFile info)
|
||||||
|
{
|
||||||
|
infos.insert(QString::fromStdString(info.url), info);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QThreadPool pool;
|
QThreadPool pool;
|
||||||
|
QHash<QString, mtx::crypto::EncryptedFile> infos;
|
||||||
};
|
};
|
||||||
|
|
|
@ -673,6 +673,19 @@ TimelineModel::internalAddEvents(
|
||||||
continue; // don't insert redaction into timeline
|
continue; // don't insert redaction into timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto event =
|
||||||
|
boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&e)) {
|
||||||
|
auto temp = decryptEvent(*event).event;
|
||||||
|
auto encInfo = boost::apply_visitor(
|
||||||
|
[](const auto &ev) -> boost::optional<mtx::crypto::EncryptedFile> {
|
||||||
|
return eventEncryptionInfo(ev);
|
||||||
|
},
|
||||||
|
temp);
|
||||||
|
|
||||||
|
if (encInfo)
|
||||||
|
emit newEncryptedImage(encInfo.value());
|
||||||
|
}
|
||||||
|
|
||||||
this->events.insert(id, e);
|
this->events.insert(id, e);
|
||||||
ids.push_back(id);
|
ids.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
#include <mtx/common.hpp>
|
||||||
#include <mtx/responses.hpp>
|
#include <mtx/responses.hpp>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
|
@ -188,6 +189,7 @@ signals:
|
||||||
void nextPendingMessage();
|
void nextPendingMessage();
|
||||||
void newMessageToSend(mtx::events::collections::TimelineEvents event);
|
void newMessageToSend(mtx::events::collections::TimelineEvents event);
|
||||||
void mediaCached(QString mxcUrl, QString cacheUrl);
|
void mediaCached(QString mxcUrl, QString cacheUrl);
|
||||||
|
void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DecryptionResult decryptEvent(
|
DecryptionResult decryptEvent(
|
||||||
|
|
|
@ -102,9 +102,14 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms)
|
||||||
void
|
void
|
||||||
TimelineViewManager::addRoom(const QString &room_id)
|
TimelineViewManager::addRoom(const QString &room_id)
|
||||||
{
|
{
|
||||||
if (!models.contains(room_id))
|
if (!models.contains(room_id)) {
|
||||||
models.insert(room_id,
|
QSharedPointer<TimelineModel> newRoom(new TimelineModel(this, room_id));
|
||||||
QSharedPointer<TimelineModel>(new TimelineModel(this, room_id)));
|
connect(newRoom.data(),
|
||||||
|
&TimelineModel::newEncryptedImage,
|
||||||
|
imgProvider,
|
||||||
|
&MxcImageProvider::addEncryptionInfo);
|
||||||
|
models.insert(room_id, std::move(newRoom));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue