aboutsummaryrefslogtreecommitdiff
path: root/lib/events/filesourceinfo.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-26 12:57:23 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-29 08:21:27 +0200
commitc2e9256b1c334bdadcc208429084cbc83496fb4b (patch)
treee13329c8f8f3c3c23e53533ed5e14bf91c1ccd1e /lib/events/filesourceinfo.cpp
parent0e1f49a4ab8e6903709f387c154c2bf131a1370c (diff)
downloadlibquotient-c2e9256b1c334bdadcc208429084cbc83496fb4b.tar.gz
libquotient-c2e9256b1c334bdadcc208429084cbc83496fb4b.zip
Cleanup and address Sonar warnings
Diffstat (limited to 'lib/events/filesourceinfo.cpp')
-rw-r--r--lib/events/filesourceinfo.cpp49
1 files changed, 23 insertions, 26 deletions
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";