Skip to content

Commit

Permalink
Fix broken base64 conversions after merge.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Jul 4, 2023
1 parent 13d8fd2 commit 2ee991e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ QByteArray encryptStringAsymmetric(const QSslKey key, const QByteArray &data)
const auto publicKeyPem = key.toPem();
BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size());
const auto publicKey = ClientSideEncryption::PKey::readPublicKey(publicKeyBio);
return EncryptionHelper::encryptStringAsymmetric(publicKey, data.toBase64());
return EncryptionHelper::encryptStringAsymmetric(publicKey, data);
}

QByteArray decryptStringAsymmetric(const QByteArray &privateKeyPem, const QByteArray &data)
Expand All @@ -543,13 +543,13 @@ QByteArray decryptStringAsymmetric(const QByteArray &privateKeyPem, const QByteA
const auto key = ClientSideEncryption::PKey::readPrivateKey(privateKeyBio);

// Also base64 decode the result
const auto decryptResult = EncryptionHelper::decryptStringAsymmetric(key, QByteArray::fromBase64(data));
const auto decryptResult = EncryptionHelper::decryptStringAsymmetric(key, data);

if (decryptResult.isEmpty()) {
qCDebug(lcCse()) << "ERROR. Could not decrypt data";
return {};
}
return QByteArray::fromBase64(decryptResult);
return decryptResult;
}

QByteArray encryptStringSymmetric(const QByteArray& key, const QByteArray& data) {
Expand Down Expand Up @@ -741,9 +741,8 @@ QByteArray encryptStringAsymmetric(EVP_PKEY *publicKey, const QByteArray& data)
exit(1);
}

// Transform the encrypted data into base64.
qCInfo(lcCse()) << out.toBase64();
return out.toBase64();
return out;
}

}
Expand Down Expand Up @@ -858,7 +857,7 @@ bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) con
BIO_write(privateKeyBio, privateKeyPem.constData(), privateKeyPem.size());
auto key = PKey::readPrivateKey(privateKeyBio);

QByteArray decryptResult = QByteArray::fromBase64(EncryptionHelper::decryptStringAsymmetric( key, QByteArray::fromBase64(encryptedData)));
QByteArray decryptResult = QByteArray::fromBase64(EncryptionHelper::decryptStringAsymmetric(key, encryptedData));

if (data != decryptResult) {
qCInfo(lcCse()) << "invalid private key";
Expand Down

0 comments on commit 2ee991e

Please sign in to comment.