make sure we clean only what is needed if e2ee is disabled

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2023-06-27 23:29:25 +02:00 committed by Matthieu Gallien
parent b9761a23fe
commit af1162804a

View file

@ -1054,8 +1054,7 @@ void ClientSideEncryption::privateKeyFetched(Job *incoming)
// Error or no valid public key error out // Error or no valid public key error out
if (readJob->error() != NoError || readJob->binaryData().length() == 0) { if (readJob->error() != NoError || readJob->binaryData().length() == 0) {
_certificate = QSslCertificate(); forgetSensitiveData(account);
_publicKey = QSslKey();
getPublicKeyFromServer(account); getPublicKeyFromServer(account);
return; return;
} }
@ -1092,9 +1091,7 @@ void ClientSideEncryption::mnemonicKeyFetched(QKeychain::Job *incoming)
// Error or no valid public key error out // Error or no valid public key error out
if (readJob->error() != NoError || readJob->textData().length() == 0) { if (readJob->error() != NoError || readJob->textData().length() == 0) {
_certificate = QSslCertificate(); forgetSensitiveData(account);
_publicKey = QSslKey();
_privateKey = QByteArray();
getPublicKeyFromServer(account); getPublicKeyFromServer(account);
return; return;
} }
@ -1180,8 +1177,6 @@ void ClientSideEncryption::writeMnemonic(OCC::AccountPtr account,
void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account) void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account)
{ {
_publicKey = QSslKey();
if (!sensitiveDataRemaining()) { if (!sensitiveDataRemaining()) {
checkAllSensitiveDataDeleted(); checkAllSensitiveDataDeleted();
return; return;
@ -1198,12 +1193,10 @@ void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account)
const auto deletePrivateKeyJob = createDeleteJob(user + e2e_private); const auto deletePrivateKeyJob = createDeleteJob(user + e2e_private);
const auto deleteCertJob = createDeleteJob(user + e2e_cert); const auto deleteCertJob = createDeleteJob(user + e2e_cert);
const auto deleteMnemonicJob = createDeleteJob(user + e2e_mnemonic); const auto deleteMnemonicJob = createDeleteJob(user + e2e_mnemonic);
const auto deletePublicKeyJob = createDeleteJob(user + e2e_public);
connect(deletePrivateKeyJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handlePrivateKeyDeleted); connect(deletePrivateKeyJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handlePrivateKeyDeleted);
connect(deleteCertJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handleCertificateDeleted); connect(deleteCertJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handleCertificateDeleted);
connect(deleteMnemonicJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handleMnemonicDeleted); connect(deleteMnemonicJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handleMnemonicDeleted);
connect(deletePublicKeyJob, &DeletePasswordJob::finished, this, &ClientSideEncryption::handlePublicKeyDeleted);
deletePrivateKeyJob->start(); deletePrivateKeyJob->start();
deleteCertJob->start(); deleteCertJob->start();
deleteMnemonicJob->start(); deleteMnemonicJob->start();
@ -1742,9 +1735,7 @@ void ClientSideEncryption::fetchAndValidatePublicKeyFromServer(const AccountPtr
} }
} else { } else {
qCInfo(lcCse()) << "Error invalid server public key"; qCInfo(lcCse()) << "Error invalid server public key";
_certificate = QSslCertificate(); forgetSensitiveData(account);
_publicKey = QSslKey();
_privateKey = QByteArray();
getPublicKeyFromServer(account); getPublicKeyFromServer(account);
return; return;
} }