From: Kevin Ottens Date: Mon, 10 Aug 2020 09:08:15 +0000 (+0200) Subject: Restore the symmetry between *StringSymmetric functions X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~242^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=54a19945fdb717c7e0c3ac37827ebfa3bc563ebf;p=nextcloud-desktop.git Restore the symmetry between *StringSymmetric functions If we receive data without base64 encoding for encryption, it makes sense to get it without base64 encoding out of decryption. Signed-off-by: Kevin Ottens --- diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 3d339a4b5..f78c264d4 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -515,7 +515,7 @@ QByteArray decryptStringSymmetric(const QByteArray& key, const QByteArray& data) return QByteArray(); } - return QByteArray(ptext, plen); + return QByteArray::fromBase64(QByteArray(ptext, plen)); } QByteArray privateKeyToPem(const QByteArray key) { @@ -1288,7 +1288,7 @@ void FolderMetadata::setupExistingMetadata(const QByteArray& metadata) // Cool, We actually have the key, we can decrypt the rest of the metadata. qCDebug(lcCse) << "Sharing: " << sharing; if (sharing.size()) { - auto sharingDecrypted = QByteArray::fromBase64(decryptJsonObject(sharing, _metadataKeys.last())); + auto sharingDecrypted = decryptJsonObject(sharing, _metadataKeys.last()); qCDebug(lcCse) << "Sharing Decrypted" << sharingDecrypted; //Sharing is also a JSON object, so extract it and populate. @@ -1313,7 +1313,7 @@ void FolderMetadata::setupExistingMetadata(const QByteArray& metadata) //Decrypt encrypted part QByteArray key = _metadataKeys[file.metadataKey]; auto encryptedFile = fileObj["encrypted"].toString().toLocal8Bit(); - auto decryptedFile = QByteArray::fromBase64(decryptJsonObject(encryptedFile, key)); + auto decryptedFile = decryptJsonObject(encryptedFile, key); auto decryptedFileDoc = QJsonDocument::fromJson(decryptedFile); auto decryptedFileObj = decryptedFileDoc.object(); diff --git a/test/testclientsideencryption.cpp b/test/testclientsideencryption.cpp index 495f62ecc..b439c17ac 100644 --- a/test/testclientsideencryption.cpp +++ b/test/testclientsideencryption.cpp @@ -88,8 +88,8 @@ private slots: const auto originalData = QByteArrayLiteral("bar"); const auto cipher = EncryptionHelper::encryptStringSymmetric(encryptionKey, originalData); - // WHEN (not it is still in base64 when returned) - const auto data = QByteArray::fromBase64(EncryptionHelper::decryptStringSymmetric(encryptionKey, cipher)); + // WHEN + const auto data = EncryptionHelper::decryptStringSymmetric(encryptionKey, cipher); // THEN QCOMPARE(data, originalData);