From a4dfef2daf5c32d1d70295777d4524d9c7a2d662 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Thu, 6 Feb 2025 11:34:49 +0100 Subject: [PATCH] remove duplicated code in ClientSideEncryption class Signed-off-by: Matthieu Gallien --- src/libsync/clientsideencryption.cpp | 34 +--------------------------- src/libsync/clientsideencryption.h | 1 - 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index a80268dad..c65c6639a 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -1316,38 +1316,6 @@ void ClientSideEncryption::fetchPublicKeyFromKeyChain(const AccountPtr &account) job->start(); } -bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) const -{ - QByteArray data = EncryptionHelper::generateRandom(64); - - Bio publicKeyBio; - QByteArray publicKeyPem = account->e2e()->getPublicKey().toPem(); - BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size()); - auto publicKey = PKey::readPublicKey(publicKeyBio); - - auto encryptedData = EncryptionHelper::encryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), data); - if (!encryptedData) { - qCWarning(lcCse()) << "encryption error"; - return false; - } - - auto key = _encryptionCertificate.getEvpPrivateKey(); - - const auto decryptionResult = EncryptionHelper::decryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), *encryptedData); - if (!decryptionResult) { - qCWarning(lcCse()) << "encryption error"; - return false; - } - const auto decryptResult = QByteArray::fromBase64(*decryptionResult); - - if (data != decryptResult) { - qCInfo(lcCse()) << "invalid private key"; - return false; - } - - return true; -} - bool ClientSideEncryption::checkEncryptionIsWorking() const { qCInfo(lcCse) << "check encryption is working before enabling end-to-end encryption feature"; @@ -2296,7 +2264,7 @@ void ClientSideEncryption::decryptPrivateKey(const AccountPtr &account, const QB } } - if (!getPrivateKey().isNull() && checkPublicKeyValidity(account)) { + if (!getPrivateKey().isNull() && checkEncryptionIsWorking()) { writePrivateKey(account); writeCertificate(account); writeMnemonic(account, [] () {}); diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 75bb149c9..fd7f369af 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -395,7 +395,6 @@ private: SUCCESS_CALLBACK nextCheck, ERROR_CALLBACK onError); - [[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const; [[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const; [[nodiscard]] bool sensitiveDataRemaining() const; -- 2.30.2