diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a2cfd8d1b..93b5d5dba 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -249,7 +249,6 @@ void AccountManager::save(bool saveCredentials) for (const auto &acc : qAsConst(_accounts)) { settings->beginGroup(acc->account()->id()); saveAccountHelper(acc->account().data(), *settings, saveCredentials); - acc->writeToSettings(*settings); settings->endGroup(); } @@ -274,7 +273,6 @@ void AccountManager::saveAccountState(AccountState *a) qCDebug(lcAccountManager) << "Saving account state" << a->account()->url().toString(); const auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); settings->beginGroup(a->account()->id()); - a->writeToSettings(*settings); settings->endGroup(); settings->sync(); diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index f9c6dc4de..61b6fcb46 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -1521,33 +1521,6 @@ void AccountSettings::refreshSelectiveSyncStatus() } } -void AccountSettings::slotDeleteAccount() -{ - // Deleting the account potentially deletes 'this', so - // the QMessageBox should be destroyed before that happens. - const auto messageBox = new QMessageBox(QMessageBox::Question, - tr("Confirm Account Removal"), - tr("

Do you really want to remove the connection to the account %1?

" - "

Note: This will not delete any files.

") - .arg(_accountState->account()->displayName()), - QMessageBox::NoButton, - this); - const auto yesButton = messageBox->addButton(tr("Remove connection"), QMessageBox::YesRole); - messageBox->addButton(tr("Cancel"), QMessageBox::NoRole); - messageBox->setAttribute(Qt::WA_DeleteOnClose); - connect(messageBox, &QMessageBox::finished, this, [this, messageBox, yesButton]{ - if (messageBox->clickedButton() == yesButton) { - // Else it might access during destruction. This should be better handled by it having a QSharedPointer - _model->setAccountState(nullptr); - - const auto manager = AccountManager::instance(); - manager->deleteAccount(_accountState); - manager->save(); - } - }); - messageBox->open(); -} - bool AccountSettings::event(QEvent *e) { if (e->type() == QEvent::Hide || e->type() == QEvent::Show) { diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index be70931d8..83e6ff026 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -93,7 +93,6 @@ protected slots: void slotSetSubFolderAvailability(OCC::Folder *folder, const QString &path, OCC::PinState state); void slotFolderWizardAccepted(); void slotFolderWizardRejected(); - void slotDeleteAccount(); void slotToggleSignInState(); void refreshSelectiveSyncStatus(); void slotMarkSubfolderEncrypted(OCC::FolderStatusModel::SubFolderInfo *folderInfo); diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 372fa218f..6bcf4e4ce 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -83,10 +83,6 @@ AccountState *AccountState::loadFromSettings(AccountPtr account, QSettings & /*s return accountState; } -void AccountState::writeToSettings(QSettings & /*settings*/) -{ -} - AccountPtr AccountState::account() const { return _account; diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 67b58c002..d1ee6f44a 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -93,12 +93,6 @@ public: */ static AccountState *loadFromSettings(AccountPtr account, QSettings &settings); - /** Writes account state information to settings. - * - * It does not write the Account data. - */ - void writeToSettings(QSettings &settings); - AccountPtr account() const; ConnectionStatus connectionStatus() const; diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 8c5244eed..07ac81a18 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -807,10 +807,14 @@ void Account::deleteAppPassword() job->setKey(kck); connect(job, &DeletePasswordJob::finished, [this](Job *incoming) { auto *deleteJob = dynamic_cast(incoming); - if (deleteJob->error() == NoError) + const auto jobError = deleteJob->error(); + if (jobError == NoError) { qCInfo(lcAccount) << "appPassword deleted from keychain"; - else + } else if (jobError == EntryNotFound) { + qCInfo(lcAccount) << "no appPassword entry found"; + } else { qCWarning(lcAccount) << "Unable to delete appPassword from keychain" << deleteJob->errorString(); + } // Allow storing a new app password on re-login _wroteAppPassword = false; diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 7cd3dd248..d69d6b476 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -1102,6 +1102,11 @@ void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account) { _publicKey = QSslKey(); + if (!sensitiveDataRemaining()) { + checkAllSensitiveDataDeleted(); + return; + } + const auto createDeleteJob = [account](const QString user) { auto *job = new DeletePasswordJob(Theme::instance()->appName()); job->setInsecureFallback(false); @@ -1124,7 +1129,8 @@ void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account) void ClientSideEncryption::handlePrivateKeyDeleted(const QKeychain::Job* const incoming) { - if (incoming->error() != QKeychain::NoError) { + const auto error = incoming->error(); + if (error != QKeychain::NoError && error != QKeychain::EntryNotFound) { qCWarning(lcCse) << "Private key could not be deleted:" << incoming->errorString(); return; } @@ -1137,7 +1143,8 @@ void ClientSideEncryption::handlePrivateKeyDeleted(const QKeychain::Job* const i void ClientSideEncryption::handleCertificateDeleted(const QKeychain::Job* const incoming) { - if (incoming->error() != QKeychain::NoError) { + const auto error = incoming->error(); + if (error != QKeychain::NoError && error != QKeychain::EntryNotFound) { qCWarning(lcCse) << "Certificate could not be deleted:" << incoming->errorString(); return; } @@ -1150,7 +1157,8 @@ void ClientSideEncryption::handleCertificateDeleted(const QKeychain::Job* const void ClientSideEncryption::handleMnemonicDeleted(const QKeychain::Job* const incoming) { - if (incoming->error() != QKeychain::NoError) { + const auto error = incoming->error(); + if (error != QKeychain::NoError && error != QKeychain::EntryNotFound) { qCWarning(lcCse) << "Mnemonic could not be deleted:" << incoming->errorString(); return; } @@ -1161,17 +1169,23 @@ void ClientSideEncryption::handleMnemonicDeleted(const QKeychain::Job* const inc checkAllSensitiveDataDeleted(); } +bool ClientSideEncryption::sensitiveDataRemaining() const +{ + return !_privateKey.isEmpty() || !_certificate.isNull() || !_mnemonic.isEmpty(); +} + void ClientSideEncryption::checkAllSensitiveDataDeleted() { - if (_privateKey.isEmpty() && _certificate.isNull() && _mnemonic.isEmpty()) { - qCDebug(lcCse) << "All sensitive encryption data has been deleted."; - Q_EMIT sensitiveDataForgotten(); + if (sensitiveDataRemaining()) { + qCDebug(lcCse) << "Some sensitive data emaining:" + << "Private key:" << _privateKey + << "Certificate is null:" << _certificate.isNull() + << "Mnemonic:" << _mnemonic; + return; } - qCDebug(lcCse) << "Some sensitive data emaining:" - << "Private key:" << _privateKey - << "Certificate is null:" << _certificate.isNull() - << "Mnemonic:" << _mnemonic; + qCDebug(lcCse) << "All sensitive encryption data has been deleted."; + Q_EMIT sensitiveDataForgotten(); } void ClientSideEncryption::generateKeyPair(const AccountPtr &account) diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index e4b0807e0..d0109f968 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -168,6 +168,7 @@ private: [[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const; [[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const; + [[nodiscard]] bool sensitiveDataRemaining() const; bool isInitialized = false; };