aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/filesourceinfo.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/events/filesourceinfo.cpp b/lib/events/filesourceinfo.cpp
index e8b6794b..6abe6a08 100644
--- a/lib/events/filesourceinfo.cpp
+++ b/lib/events/filesourceinfo.cpp
@@ -59,19 +59,15 @@ std::pair<EncryptedFileMetadata, QByteArray> Quotient::encryptFile(
const QByteArray& plainText)
{
#ifdef Quotient_E2EE_ENABLED
- QByteArray k = getRandom(32);
- auto kBase64 = k.toBase64();
- QByteArray iv = getRandom(16);
- JWK key = { "oct"_ls,
- { "encrypt"_ls, "decrypt"_ls },
- "A256CTR"_ls,
- QString(k.toBase64())
- .replace(u'/', u'_')
- .replace(u'+', u'-')
- .left(kBase64.indexOf('=')),
- true };
-
- int length;
+ auto k = getRandom(32);
+ auto kBase64 = k.toBase64(QByteArray::Base64UrlEncoding
+ | QByteArray::OmitTrailingEquals);
+ auto iv = getRandom(16);
+ JWK key = {
+ "oct"_ls, { "encrypt"_ls, "decrypt"_ls }, "A256CTR"_ls, kBase64, true
+ };
+
+ int length = -1;
auto* ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), nullptr,
reinterpret_cast<const unsigned char*>(k.data()),
@@ -89,14 +85,11 @@ std::pair<EncryptedFileMetadata, QByteArray> Quotient::encryptFile(
EVP_CIPHER_CTX_free(ctx);
auto hash = QCryptographicHash::hash(cipherText, QCryptographicHash::Sha256)
- .toBase64();
- auto ivBase64 = iv.toBase64();
- EncryptedFileMetadata efm = { {},
- key,
- ivBase64.left(ivBase64.indexOf('=')),
- { { QStringLiteral("sha256"),
- hash.left(hash.indexOf('=')) } },
- "v2"_ls };
+ .toBase64(QByteArray::OmitTrailingEquals);
+ auto ivBase64 = iv.toBase64(QByteArray::OmitTrailingEquals);
+ EncryptedFileMetadata efm = {
+ {}, key, ivBase64, { { QStringLiteral("sha256"), hash } }, "v2"_ls
+ };
return { efm, cipherText };
#else
return {};