Skip to content

Commit e941816

Browse files
committed
remove duplicated code in ClientSideEncryption class
Signed-off-by: Matthieu Gallien <[email protected]>
1 parent e1bb8fc commit e941816

File tree

2 files changed

+1
-34
lines changed

2 files changed

+1
-34
lines changed

src/libsync/clientsideencryption.cpp

+1-33
Original file line numberDiff line numberDiff line change
@@ -1316,38 +1316,6 @@ void ClientSideEncryption::fetchPublicKeyFromKeyChain(const AccountPtr &account)
13161316
job->start();
13171317
}
13181318

1319-
bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) const
1320-
{
1321-
QByteArray data = EncryptionHelper::generateRandom(64);
1322-
1323-
Bio publicKeyBio;
1324-
QByteArray publicKeyPem = account->e2e()->getPublicKey().toPem();
1325-
BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size());
1326-
auto publicKey = PKey::readPublicKey(publicKeyBio);
1327-
1328-
auto encryptedData = EncryptionHelper::encryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), data);
1329-
if (!encryptedData) {
1330-
qCWarning(lcCse()) << "encryption error";
1331-
return false;
1332-
}
1333-
1334-
auto key = _encryptionCertificate.getEvpPrivateKey();
1335-
1336-
const auto decryptionResult = EncryptionHelper::decryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), *encryptedData);
1337-
if (!decryptionResult) {
1338-
qCWarning(lcCse()) << "encryption error";
1339-
return false;
1340-
}
1341-
const auto decryptResult = QByteArray::fromBase64(*decryptionResult);
1342-
1343-
if (data != decryptResult) {
1344-
qCInfo(lcCse()) << "invalid private key";
1345-
return false;
1346-
}
1347-
1348-
return true;
1349-
}
1350-
13511319
bool ClientSideEncryption::checkEncryptionIsWorking() const
13521320
{
13531321
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
22962264
}
22972265
}
22982266

2299-
if (!getPrivateKey().isNull() && checkPublicKeyValidity(account)) {
2267+
if (!getPrivateKey().isNull() && checkEncryptionIsWorking()) {
23002268
writePrivateKey(account);
23012269
writeCertificate(account);
23022270
writeMnemonic(account, [] () {});

src/libsync/clientsideencryption.h

-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ private slots:
395395
SUCCESS_CALLBACK nextCheck,
396396
ERROR_CALLBACK onError);
397397

398-
[[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const;
399398
[[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const;
400399
[[nodiscard]] bool sensitiveDataRemaining() const;
401400

0 commit comments

Comments
 (0)