aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/eventcontent.cpp9
-rw-r--r--lib/events/eventcontent.h6
-rw-r--r--lib/events/filesourceinfo.cpp49
3 files changed, 30 insertions, 34 deletions
diff --git a/lib/events/eventcontent.cpp b/lib/events/eventcontent.cpp
index 36b647cb..8db3b7e3 100644
--- a/lib/events/eventcontent.cpp
+++ b/lib/events/eventcontent.cpp
@@ -103,14 +103,13 @@ QJsonObject Quotient::EventContent::toInfoJson(const ImageInfo& info)
return infoJson;
}
-Thumbnail::Thumbnail(
- const QJsonObject& infoJson,
- const Omittable<EncryptedFileMetadata>& encryptedFileMetadata)
+Thumbnail::Thumbnail(const QJsonObject& infoJson,
+ const Omittable<EncryptedFileMetadata>& efm)
: ImageInfo(QUrl(infoJson["thumbnail_url"_ls].toString()),
infoJson["thumbnail_info"_ls].toObject())
{
- if (encryptedFileMetadata)
- source = *encryptedFileMetadata;
+ if (efm)
+ source = *efm;
}
void Thumbnail::dumpTo(QJsonObject& infoJson) const
diff --git a/lib/events/eventcontent.h b/lib/events/eventcontent.h
index 23281876..ea240122 100644
--- a/lib/events/eventcontent.h
+++ b/lib/events/eventcontent.h
@@ -146,7 +146,7 @@ namespace EventContent {
public:
using ImageInfo::ImageInfo;
Thumbnail(const QJsonObject& infoJson,
- const Omittable<EncryptedFileMetadata>& encryptedFile = none);
+ const Omittable<EncryptedFileMetadata>& efm = none);
//! \brief Add thumbnail information to the passed `info` JSON object
void dumpTo(QJsonObject& infoJson) const;
@@ -181,8 +181,8 @@ namespace EventContent {
json["filename"].toString())
, thumbnail(FileInfo::originalInfoJson)
{
- const auto efmJson = json.value("file"_ls).toObject();
- if (!efmJson.isEmpty())
+ if (const auto efmJson = json.value("file"_ls).toObject();
+ !efmJson.isEmpty())
InfoT::source = fromJson<EncryptedFileMetadata>(efmJson);
// Two small hacks on originalJson to expose mediaIds to QML
originalJson.insert("mediaId", InfoT::mediaId());
diff --git a/lib/events/filesourceinfo.cpp b/lib/events/filesourceinfo.cpp
index 43e8e44c..11f93d80 100644
--- a/lib/events/filesourceinfo.cpp
+++ b/lib/events/filesourceinfo.cpp
@@ -20,36 +20,33 @@ QByteArray Quotient::decryptFile(const QByteArray& ciphertext,
const EncryptedFileMetadata& metadata)
{
#ifdef Quotient_E2EE_ENABLED
- auto _key = metadata.key.k;
- const auto keyBytes = QByteArray::fromBase64(
- _key.replace(u'_', u'/').replace(u'-', u'+').toLatin1());
- const auto sha256 =
- QByteArray::fromBase64(metadata.hashes["sha256"_ls].toLatin1());
- if (sha256
+ if (QByteArray::fromBase64(metadata.hashes["sha256"_ls].toLatin1())
!= QCryptographicHash::hash(ciphertext, QCryptographicHash::Sha256)) {
qCWarning(E2EE) << "Hash verification failed for file";
return {};
}
- {
- int length;
- auto* ctx = EVP_CIPHER_CTX_new();
- QByteArray plaintext(ciphertext.size() + EVP_MAX_BLOCK_LENGTH - 1, '\0');
- EVP_DecryptInit_ex(
- ctx, EVP_aes_256_ctr(), nullptr,
- reinterpret_cast<const unsigned char*>(keyBytes.data()),
- reinterpret_cast<const unsigned char*>(
- QByteArray::fromBase64(metadata.iv.toLatin1()).data()));
- EVP_DecryptUpdate(
- ctx, reinterpret_cast<unsigned char*>(plaintext.data()), &length,
- reinterpret_cast<const unsigned char*>(ciphertext.data()),
- ciphertext.size());
- EVP_DecryptFinal_ex(ctx,
- reinterpret_cast<unsigned char*>(plaintext.data())
- + length,
- &length);
- EVP_CIPHER_CTX_free(ctx);
- return plaintext.left(ciphertext.size());
- }
+
+ auto _key = metadata.key.k;
+ const auto keyBytes = QByteArray::fromBase64(
+ _key.replace(u'_', u'/').replace(u'-', u'+').toLatin1());
+ int length;
+ auto* ctx = EVP_CIPHER_CTX_new();
+ QByteArray plaintext(ciphertext.size() + EVP_MAX_BLOCK_LENGTH - 1, '\0');
+ EVP_DecryptInit_ex(
+ ctx, EVP_aes_256_ctr(), nullptr,
+ reinterpret_cast<const unsigned char*>(keyBytes.data()),
+ reinterpret_cast<const unsigned char*>(
+ QByteArray::fromBase64(metadata.iv.toLatin1()).data()));
+ EVP_DecryptUpdate(ctx, reinterpret_cast<unsigned char*>(plaintext.data()),
+ &length,
+ reinterpret_cast<const unsigned char*>(ciphertext.data()),
+ ciphertext.size());
+ EVP_DecryptFinal_ex(ctx,
+ reinterpret_cast<unsigned char*>(plaintext.data())
+ + length,
+ &length);
+ EVP_CIPHER_CTX_free(ctx);
+ return plaintext.left(ciphertext.size());
#else
qWarning(MAIN) << "This build of libQuotient doesn't support E2EE, "
"cannot decrypt the file";