From db15833810c03a248bd54f2e234135f5bb3a7568 Mon Sep 17 00:00:00 2001 From: alex-z Date: Mon, 29 Jan 2024 02:49:44 +0100 Subject: [PATCH] Fix review comments. Signed-off-by: alex-z --- src/common/checksums.h | 2 +- src/gui/folderman.cpp | 2 +- .../basepropagateremotedeleteencrypted.cpp | 13 ++++++------ .../basepropagateremotedeleteencrypted.h | 5 +++-- src/libsync/discovery.cpp | 8 ++++---- .../encryptedfoldermetadatahandler.cpp | 8 ++++---- src/libsync/encryptedfoldermetadatahandler.h | 7 ++++++- src/libsync/foldermetadata.cpp | 6 +++--- src/libsync/foldermetadata.h | 10 +++++----- src/libsync/owncloudpropagator.cpp | 2 +- .../propagateremotedeleteencrypted.cpp | 2 +- ...opagateremotedeleteencryptedrootfolder.cpp | 4 ++-- src/libsync/propagateremotemkdir.cpp | 2 +- src/libsync/propagateuploadencrypted.cpp | 2 +- src/libsync/syncfileitem.cpp | 4 ++-- src/libsync/syncfileitem.h | 2 +- src/libsync/updatee2eefoldermetadatajob.cpp | 20 ++++++++++--------- src/libsync/updatee2eefoldermetadatajob.h | 2 +- .../updatee2eefolderusersmetadatajob.cpp | 16 ++++++++------- .../updatee2eefolderusersmetadatajob.h | 2 +- 20 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/common/checksums.h b/src/common/checksums.h index 6358965a05df9..519825961d3ea 100644 --- a/src/common/checksums.h +++ b/src/common/checksums.h @@ -56,7 +56,7 @@ OCSYNC_EXPORT QByteArray parseChecksumHeaderType(const QByteArray &header); /// Checks OWNCLOUD_DISABLE_CHECKSUM_UPLOAD OCSYNC_EXPORT bool uploadChecksumEnabled(); -QByteArray OCSYNC_EXPORT calcSha256(const QByteArray &data); +OCSYNC_EXPORT QByteArray calcSha256(const QByteArray &data); /** * Computes the checksum of a file. diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 2bac0b4c1121e..2361862fddc4c 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1587,7 +1587,7 @@ void FolderMan::slotLeaveShare(const QString &localFile, const QByteArray &folde qCDebug(lcFolderMan) << "slotLeaveShare callback statusCode" << statusCode; Q_UNUSED(statusCode); if (_removeE2eeShareJob) { - _removeE2eeShareJob->unlockFolder(true); + _removeE2eeShareJob->unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success); connect(_removeE2eeShareJob.data(), &UpdateE2eeFolderUsersMetadataJob::folderUnlocked, this, [this, folder] { scheduleFolder(folder); }); diff --git a/src/libsync/basepropagateremotedeleteencrypted.cpp b/src/libsync/basepropagateremotedeleteencrypted.cpp index 03776e7f292fa..9503a081091ef 100644 --- a/src/libsync/basepropagateremotedeleteencrypted.cpp +++ b/src/libsync/basepropagateremotedeleteencrypted.cpp @@ -82,10 +82,9 @@ void BasePropagateRemoteDeleteEncrypted::fetchMetadataForPath(const QString &pat _encryptedFolderMetadataHandler->fetchMetadata(); } -void BasePropagateRemoteDeleteEncrypted::uploadMetadata(bool keepLock) +void BasePropagateRemoteDeleteEncrypted::uploadMetadata(const EncryptedFolderMetadataHandler::UploadMode uploadMode) { - _encryptedFolderMetadataHandler->uploadMetadata(keepLock ? EncryptedFolderMetadataHandler::UploadMode::KeepLock - : EncryptedFolderMetadataHandler::UploadMode::DoNotKeepLock); + _encryptedFolderMetadataHandler->uploadMetadata(uploadMode); } void BasePropagateRemoteDeleteEncrypted::slotFolderUnLockFinished(const QByteArray &folderId, int statusCode) @@ -147,7 +146,7 @@ void BasePropagateRemoteDeleteEncrypted::slotDeleteRemoteItemFinished() } _propagator->_journal->commit("Remote Remove"); - unlockFolder(true); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success); } void BasePropagateRemoteDeleteEncrypted::deleteRemoteItem(const QString &filename) @@ -164,7 +163,7 @@ void BasePropagateRemoteDeleteEncrypted::deleteRemoteItem(const QString &filenam deleteJob->start(); } -void BasePropagateRemoteDeleteEncrypted::unlockFolder(bool success) +void BasePropagateRemoteDeleteEncrypted::unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result) { if (!_encryptedFolderMetadataHandler) { qCWarning(ABSTRACT_PROPAGATE_REMOVE_ENCRYPTED) << "Null _encryptedFolderMetadataHandler"; @@ -177,7 +176,7 @@ void BasePropagateRemoteDeleteEncrypted::unlockFolder(bool success) qCDebug(ABSTRACT_PROPAGATE_REMOVE_ENCRYPTED) << "Unlocking folder" << _encryptedFolderMetadataHandler->folderId(); connect(_encryptedFolderMetadataHandler.data(), &EncryptedFolderMetadataHandler::folderUnlocked, this, &BasePropagateRemoteDeleteEncrypted::slotFolderUnLockFinished); - _encryptedFolderMetadataHandler->unlockFolder(success); + _encryptedFolderMetadataHandler->unlockFolder(result); } void BasePropagateRemoteDeleteEncrypted::taskFailed() @@ -185,7 +184,7 @@ void BasePropagateRemoteDeleteEncrypted::taskFailed() qCDebug(ABSTRACT_PROPAGATE_REMOVE_ENCRYPTED) << "Task failed for job" << sender(); _isTaskFailed = true; if (_encryptedFolderMetadataHandler && _encryptedFolderMetadataHandler->isFolderLocked()) { - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); } else { emit finished(false); } diff --git a/src/libsync/basepropagateremotedeleteencrypted.h b/src/libsync/basepropagateremotedeleteencrypted.h index 371e7bbb26429..653f1da982869 100644 --- a/src/libsync/basepropagateremotedeleteencrypted.h +++ b/src/libsync/basepropagateremotedeleteencrypted.h @@ -47,13 +47,14 @@ class BasePropagateRemoteDeleteEncrypted : public QObject void storeFirstErrorString(const QString &errString); void fetchMetadataForPath(const QString &path); - void uploadMetadata(bool keepLock = false); + void uploadMetadata(const EncryptedFolderMetadataHandler::UploadMode uploadMode = EncryptedFolderMetadataHandler::UploadMode::DoNotKeepLock); [[nodiscard]] QSharedPointer folderMetadata() const; [[nodiscard]] const QByteArray folderToken() const; void deleteRemoteItem(const QString &filename); - void unlockFolder(bool success); + + void unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result); void taskFailed(); protected slots: diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index ebb01f6ee231a..35bbaed4acbbe 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -629,7 +629,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it item->_directDownloadCookies = serverEntry.directDownloadCookies; item->_e2eEncryptionStatus = serverEntry.isE2eEncrypted() ? SyncFileItem::EncryptionStatus::Encrypted : SyncFileItem::EncryptionStatus::NotEncrypted; if (serverEntry.isE2eEncrypted()) { - item->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); + item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); } item->_encryptedFileName = [=] { if (serverEntry.e2eMangledName.isEmpty()) { @@ -1025,7 +1025,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( if (dbEntry.isValid() && item->isDirectory()) { item->_e2eEncryptionStatus = EncryptionStatusEnums::fromDbEncryptionStatus(dbEntry._e2eEncryptionStatus); if (item->isEncrypted()) { - item->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); + item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); } } @@ -1385,7 +1385,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( // renaming the encrypted folder is done via remove + re-upload hence we need to mark the newly created folder as encrypted // base is a record in the SyncJournal database that contains the data about the being-renamed folder with it's old name and encryption information item->_e2eEncryptionStatus = EncryptionStatusEnums::fromDbEncryptionStatus(base._e2eEncryptionStatus); - item->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); + item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_discoveryData->_account->capabilities().clientSideEncryptionVersion()); } postProcessLocalNew(); /*if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_NEW && item->_direction == SyncFileItem::Up @@ -1988,7 +1988,7 @@ DiscoverySingleDirectoryJob *ProcessDirectoryJob::startAsyncServerQuery() _dirItem->_isEncryptedMetadataNeedUpdate = alreadyDownloaded && serverJob->encryptedMetadataNeedUpdate(); _dirItem->_e2eEncryptionStatus = serverJob->currentEncryptionStatus(); _dirItem->_e2eEncryptionStatusRemote = serverJob->currentEncryptionStatus(); - _dirItem->_e2eEncryptionMaximumAvailableStatus = serverJob->requiredEncryptionStatus(); + _dirItem->_e2eEncryptionServerCapability = serverJob->requiredEncryptionStatus(); _discoveryData->_anotherSyncNeeded = !alreadyDownloaded && serverJob->encryptedMetadataNeedUpdate(); } qCInfo(lcDisco) << "serverJob has finished for folder:" << _dirItem->_file << " and it has _isFileDropDetected:" << true; diff --git a/src/libsync/encryptedfoldermetadatahandler.cpp b/src/libsync/encryptedfoldermetadatahandler.cpp index 86f611650054b..63de59f900eab 100644 --- a/src/libsync/encryptedfoldermetadatahandler.cpp +++ b/src/libsync/encryptedfoldermetadatahandler.cpp @@ -213,7 +213,7 @@ void EncryptedFolderMetadataHandler::slotFolderLockedError(const QByteArray &fol emit fetchFinished(httpErrorCode, tr("Error locking folder.")); } -void EncryptedFolderMetadataHandler::unlockFolder(bool success) +void EncryptedFolderMetadataHandler::unlockFolder(const UnlockFolderWithResult result) { Q_ASSERT(!_isUnlockRunning); Q_ASSERT(_isFolderLocked); @@ -230,7 +230,7 @@ void EncryptedFolderMetadataHandler::unlockFolder(bool success) } if (_uploadMode == UploadMode::DoNotKeepLock) { - if (success) { + if (result == UnlockFolderWithResult::Success) { connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadSuccess); } else { connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadError); @@ -295,7 +295,7 @@ void EncryptedFolderMetadataHandler::slotUploadMetadataSuccess(const QByteArray return; } connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadSuccess); - unlockFolder(true); + unlockFolder(UnlockFolderWithResult::Success); } void EncryptedFolderMetadataHandler::slotUploadMetadataError(const QByteArray &folderId, int httpReturnCode) @@ -305,7 +305,7 @@ void EncryptedFolderMetadataHandler::slotUploadMetadataError(const QByteArray &f _uploadErrorCode = httpReturnCode; if (_isFolderLocked && _uploadMode == UploadMode::DoNotKeepLock) { connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadError); - unlockFolder(false); + unlockFolder(UnlockFolderWithResult::Failure); return; } emit uploadFinished(_uploadErrorCode); diff --git a/src/libsync/encryptedfoldermetadatahandler.h b/src/libsync/encryptedfoldermetadatahandler.h index e5426527d4b70..ec01f37ae0232 100644 --- a/src/libsync/encryptedfoldermetadatahandler.h +++ b/src/libsync/encryptedfoldermetadatahandler.h @@ -41,6 +41,11 @@ class OWNCLOUDSYNC_EXPORT EncryptedFolderMetadataHandler : public QObject KeepLock }; + enum class UnlockFolderWithResult { + Success = 0, + Failure + }; + explicit EncryptedFolderMetadataHandler(const AccountPtr &account, const QString &folderPath, SyncJournalDb *const journalDb, @@ -64,7 +69,7 @@ class OWNCLOUDSYNC_EXPORT EncryptedFolderMetadataHandler : public QObject void fetchMetadata(const RootEncryptedFolderInfo &rootEncryptedFolderInfo, const FetchMode fetchMode = FetchMode::NonEmptyMetadata); void fetchMetadata(const FetchMode fetchMode = FetchMode::NonEmptyMetadata); void uploadMetadata(const UploadMode uploadMode = UploadMode::DoNotKeepLock); - void unlockFolder(bool success = true); + void unlockFolder(const UnlockFolderWithResult result = UnlockFolderWithResult::Success); private: void lockFolder(); diff --git a/src/libsync/foldermetadata.cpp b/src/libsync/foldermetadata.cpp index 4df2e875db637..5f6d254870a21 100644 --- a/src/libsync/foldermetadata.cpp +++ b/src/libsync/foldermetadata.cpp @@ -416,7 +416,7 @@ void FolderMetadata::emitSetupComplete() } // RSA/ECB/OAEPWithSHA-256AndMGF1Padding using private / public key. -QByteArray FolderMetadata::encryptDataWithPublicKey(const QByteArray &data, const QSslKey key) const +QByteArray FolderMetadata::encryptDataWithPublicKey(const QByteArray &data, const QSslKey &key) const { ClientSideEncryption::Bio publicKeyBio; const auto publicKeyPem = key.toPem(); @@ -825,7 +825,7 @@ quint64 FolderMetadata::newCounter() const return _counter + 1; } -EncryptionStatusEnums::ItemEncryptionStatus FolderMetadata::fromMedataVersionToItemEncryptionStatus(const MetadataVersion &metadataVersion) +EncryptionStatusEnums::ItemEncryptionStatus FolderMetadata::fromMedataVersionToItemEncryptionStatus(const MetadataVersion metadataVersion) { switch (metadataVersion) { case FolderMetadata::MetadataVersion::Version2_0: @@ -840,7 +840,7 @@ EncryptionStatusEnums::ItemEncryptionStatus FolderMetadata::fromMedataVersionToI return SyncFileItem::EncryptionStatus::NotEncrypted; } -FolderMetadata::MetadataVersion FolderMetadata::fromItemEncryptionStatusToMedataVersion(const EncryptionStatusEnums::ItemEncryptionStatus &encryptionStatus) +FolderMetadata::MetadataVersion FolderMetadata::fromItemEncryptionStatusToMedataVersion(const EncryptionStatusEnums::ItemEncryptionStatus encryptionStatus) { switch (encryptionStatus) { case EncryptionStatusEnums::ItemEncryptionStatus::Encrypted: diff --git a/src/libsync/foldermetadata.h b/src/libsync/foldermetadata.h index a56ec291a2b3e..3b8009145c3d0 100644 --- a/src/libsync/foldermetadata.h +++ b/src/libsync/foldermetadata.h @@ -15,8 +15,8 @@ #include "accountfwd.h" #include "encryptedfoldermetadatahandler.h" -#include -#include +#include "csync.h" +#include "rootencryptedfolderinfo.h" #include #include #include @@ -151,7 +151,7 @@ public slots: [[nodiscard]] bool verifyMetadataKey(const QByteArray &metadataKey) const; - [[nodiscard]] QByteArray encryptDataWithPublicKey(const QByteArray &data, const QSslKey key) const; + [[nodiscard]] QByteArray encryptDataWithPublicKey(const QByteArray &data, const QSslKey &key) const; [[nodiscard]] QByteArray decryptDataWithPrivateKey(const QByteArray &data) const; [[nodiscard]] QByteArray encryptJsonObject(const QByteArray& obj, const QByteArray pass) const; @@ -171,8 +171,8 @@ public slots: void setFileDrop(const QJsonObject &fileDrop); - static EncryptionStatusEnums::ItemEncryptionStatus fromMedataVersionToItemEncryptionStatus(const MetadataVersion &metadataVersion); - static MetadataVersion fromItemEncryptionStatusToMedataVersion(const EncryptionStatusEnums::ItemEncryptionStatus &encryptionStatus); + static EncryptionStatusEnums::ItemEncryptionStatus fromMedataVersionToItemEncryptionStatus(const MetadataVersion metadataVersion); + static MetadataVersion fromItemEncryptionStatusToMedataVersion(const EncryptionStatusEnums::ItemEncryptionStatus encryptionStatus); static QByteArray prepareMetadataForSignature(const QJsonDocument &fullMetadata); diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 2ef13f7f5b21d..6664be246616b 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -710,7 +710,7 @@ void OwncloudPropagator::startFilePropagation(const SyncFileItemPtr &item, void OwncloudPropagator::processE2eeMetadataMigration(const SyncFileItemPtr &item, QStack> &directories) { - if (item->_e2eEncryptionMaximumAvailableStatus >= EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0) { + if (item->_e2eEncryptionServerCapability >= EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0) { // migrating to v2.0+ const auto rootE2eeFolderPath = item->_file.split('/').first(); const auto rootE2eeFolderPathWithSlash = QString(rootE2eeFolderPath + "/"); diff --git a/src/libsync/propagateremotedeleteencrypted.cpp b/src/libsync/propagateremotedeleteencrypted.cpp index 5706d1c56f809..0bb8c92e6a4b4 100644 --- a/src/libsync/propagateremotedeleteencrypted.cpp +++ b/src/libsync/propagateremotedeleteencrypted.cpp @@ -82,7 +82,7 @@ void PropagateRemoteDeleteEncrypted::slotFetchMetadataJobFinished(int statusCode } qCDebug(PROPAGATE_REMOVE_ENCRYPTED) << "Metadata updated, sending to the server."; - uploadMetadata(true); + uploadMetadata(EncryptedFolderMetadataHandler::UploadMode::KeepLock); } void PropagateRemoteDeleteEncrypted::slotUpdateMetadataJobFinished(int statusCode, const QString &message) diff --git a/src/libsync/propagateremotedeleteencryptedrootfolder.cpp b/src/libsync/propagateremotedeleteencryptedrootfolder.cpp index 850aa367505d9..849e5f2b27e21 100644 --- a/src/libsync/propagateremotedeleteencryptedrootfolder.cpp +++ b/src/libsync/propagateremotedeleteencryptedrootfolder.cpp @@ -98,7 +98,7 @@ void PropagateRemoteDeleteEncryptedRootFolder::slotFetchMetadataJobFinished(int metadata->removeAllEncryptedFiles(); qCDebug(PROPAGATE_REMOVE_ENCRYPTED_ROOTFOLDER) << "Metadata updated, sending to the server."; - uploadMetadata(true); + uploadMetadata(EncryptedFolderMetadataHandler::UploadMode::KeepLock); } void PropagateRemoteDeleteEncryptedRootFolder::slotUpdateMetadataJobFinished(int statusCode, const QString &message) @@ -173,7 +173,7 @@ void PropagateRemoteDeleteEncryptedRootFolder::slotDeleteNestedRemoteItemFinishe taskFailed(); return; } - unlockFolder(true); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success); } } diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp index 4a280d3aab0e8..8f8da5fd30624 100644 --- a/src/libsync/propagateremotemkdir.cpp +++ b/src/libsync/propagateremotemkdir.cpp @@ -253,7 +253,7 @@ void PropagateRemoteMkdir::slotEncryptFolderFinished(int status, EncryptionStatu _item->_e2eEncryptionStatus = encryptionStatus; _item->_e2eEncryptionStatusRemote = encryptionStatus; if (_item->isEncrypted()) { - _item->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(propagator()->account()->capabilities().clientSideEncryptionVersion()); + _item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(propagator()->account()->capabilities().clientSideEncryptionVersion()); } success(); } diff --git a/src/libsync/propagateuploadencrypted.cpp b/src/libsync/propagateuploadencrypted.cpp index 3e3a0be7091b3..2e24e77254694 100644 --- a/src/libsync/propagateuploadencrypted.cpp +++ b/src/libsync/propagateuploadencrypted.cpp @@ -143,7 +143,7 @@ void PropagateUploadEncrypted::slotFetchMetadataJobFinished(int statusCode, cons _item->_encryptedFileName = _remoteParentPath + QLatin1Char('/') + encryptedFile.encryptedFilename; _item->_e2eEncryptionStatusRemote = metadata->existingMetadataEncryptionStatus(); - _item->_e2eEncryptionMaximumAvailableStatus = + _item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_propagator->account()->capabilities().clientSideEncryptionVersion()); qCDebug(lcPropagateUploadEncrypted) << "Creating the encrypted file."; diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index f3bbb7633a803..4a169d9cbefbb 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -155,7 +155,7 @@ SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRec item->_checksumHeader = rec._checksumHeader; item->_encryptedFileName = rec.e2eMangledName(); item->_e2eEncryptionStatus = EncryptionStatusEnums::fromDbEncryptionStatus(rec._e2eEncryptionStatus); - item->_e2eEncryptionMaximumAvailableStatus = item->_e2eEncryptionStatus; + item->_e2eEncryptionServerCapability = item->_e2eEncryptionStatus; item->_locked = rec._lockstate._locked ? LockStatus::LockedItem : LockStatus::UnlockedItem; item->_lockOwnerDisplayName = rec._lockstate._lockOwnerDisplayName; item->_lockOwnerId = rec._lockstate._lockOwnerId; @@ -194,7 +194,7 @@ SyncFileItemPtr SyncFileItem::fromProperties(const QString &filePath, const QMap item->_e2eEncryptionStatus = (properties.value(QStringLiteral("is-encrypted")) == QStringLiteral("1") ? SyncFileItem::EncryptionStatus::Encrypted : SyncFileItem::EncryptionStatus::NotEncrypted); if (item->isEncrypted()) { - item->_e2eEncryptionMaximumAvailableStatus = item->_e2eEncryptionStatus; + item->_e2eEncryptionServerCapability = item->_e2eEncryptionStatus; } item->_locked = properties.value(QStringLiteral("lock")) == QStringLiteral("1") ? SyncFileItem::LockStatus::LockedItem : SyncFileItem::LockStatus::UnlockedItem; diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index e70c026cb1586..89e68ca99b209 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -284,7 +284,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem bool _isRestoration BITFIELD(1); // The original operation was forbidden, and this is a restoration bool _isSelectiveSync BITFIELD(1); // The file is removed or ignored because it is in the selective sync list EncryptionStatus _e2eEncryptionStatus = EncryptionStatus::NotEncrypted; // The file is E2EE or the content of the directory should be E2EE - EncryptionStatus _e2eEncryptionMaximumAvailableStatus = EncryptionStatus::NotEncrypted; + EncryptionStatus _e2eEncryptionServerCapability = EncryptionStatus::NotEncrypted; EncryptionStatus _e2eEncryptionStatusRemote = EncryptionStatus::NotEncrypted; quint16 _httpErrorCode = 0; RemotePermissions _remotePerm; diff --git a/src/libsync/updatee2eefoldermetadatajob.cpp b/src/libsync/updatee2eefoldermetadatajob.cpp index 3617bd9a41ef2..7bca9c4381b70 100644 --- a/src/libsync/updatee2eefoldermetadatajob.cpp +++ b/src/libsync/updatee2eefoldermetadatajob.cpp @@ -43,7 +43,7 @@ void UpdateE2eeFolderMetadataJob::start() SyncJournalFileRecord rec; if (!propagator()->_journal->getRootE2eFolderRecord(_encryptedRemotePath, &rec) || !rec.isValid()) { - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); return; } _encryptedFolderMetadataHandler.reset( @@ -85,13 +85,13 @@ void UpdateE2eeFolderMetadataJob::slotFetchMetadataJobFinished(int httpReturnCod SyncJournalFileRecord rec; if (!propagator()->_journal->getRootE2eFolderRecord(_encryptedRemotePath, &rec) || !rec.isValid()) { - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); return; } const auto folderMetadata = _encryptedFolderMetadataHandler->folderMetadata(); if (!folderMetadata || !folderMetadata->isValid() || (!folderMetadata->moveFromFileDropToFiles() && !folderMetadata->encryptedMetadataNeedUpdate())) { - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); return; } @@ -116,7 +116,7 @@ void UpdateE2eeFolderMetadataJob::slotUpdateMetadataFinished(int httpReturnCode, finished(itemStatus); } -void UpdateE2eeFolderMetadataJob::unlockFolder(bool success) +void UpdateE2eeFolderMetadataJob::unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result) { Q_ASSERT(!_encryptedFolderMetadataHandler->isUnlockRunning()); Q_ASSERT(_item); @@ -126,17 +126,19 @@ void UpdateE2eeFolderMetadataJob::unlockFolder(bool success) return; } - if (!success) { + if (result != EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success) { _item->_errorString = tr("Failed to update folder metadata."); } - const auto itemStatus = success ? SyncFileItem::Success : SyncFileItem::FatalError; + const auto isSuccess = result == EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success; + + const auto itemStatus = isSuccess ? SyncFileItem::Success : SyncFileItem::FatalError; if (!_encryptedFolderMetadataHandler->isFolderLocked()) { - if (success && _encryptedFolderMetadataHandler->folderMetadata()) { + if (isSuccess && _encryptedFolderMetadataHandler->folderMetadata()) { _item->_e2eEncryptionStatus = _encryptedFolderMetadataHandler->folderMetadata()->encryptedMetadataEncryptionStatus(); if (_item->isEncrypted()) { - _item->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(propagator()->account()->capabilities().clientSideEncryptionVersion()); + _item->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(propagator()->account()->capabilities().clientSideEncryptionVersion()); } } finished(itemStatus); @@ -168,7 +170,7 @@ void UpdateE2eeFolderMetadataJob::unlockFolder(bool success) finished(SyncFileItem::Success); }); - _encryptedFolderMetadataHandler->unlockFolder(success); + _encryptedFolderMetadataHandler->unlockFolder(result); } } diff --git a/src/libsync/updatee2eefoldermetadatajob.h b/src/libsync/updatee2eefoldermetadatajob.h index 69d1bb98a1a8e..1190a0eed6e5e 100644 --- a/src/libsync/updatee2eefoldermetadatajob.h +++ b/src/libsync/updatee2eefoldermetadatajob.h @@ -43,7 +43,7 @@ private slots: void start(); void slotFetchMetadataJobFinished(int httpReturnCode, const QString &message); void slotUpdateMetadataFinished(int httpReturnCode, const QString &message); - void unlockFolder(bool success); + void unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result); signals: void fileDropMetadataParsedAndAdjusted(const OCC::FolderMetadata *const metadata); diff --git a/src/libsync/updatee2eefolderusersmetadatajob.cpp b/src/libsync/updatee2eefolderusersmetadatajob.cpp index 3f2be28f7f5a0..66b6808d0766c 100644 --- a/src/libsync/updatee2eefolderusersmetadatajob.cpp +++ b/src/libsync/updatee2eefolderusersmetadatajob.cpp @@ -164,7 +164,7 @@ void UpdateE2eeFolderUsersMetadataJob::slotUpdateMetadataFinished(int code, cons if (_operation == Operation::Add || _operation == Operation::Remove) { qCDebug(lcUpdateE2eeFolderUsersMetadataJob()) << "Unlocking the folder."; - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); } else { emit finished(code, tr("Error updating metadata for a folder %1").arg(_path) + QStringLiteral(":%1").arg(message)); } @@ -179,7 +179,7 @@ void UpdateE2eeFolderUsersMetadataJob::slotUpdateMetadataFinished(int code, cons if (_keepLock) { emit finished(200); } else { - unlockFolder(true); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success); } } else { _subJobs.values().last()->start(); @@ -195,7 +195,7 @@ void UpdateE2eeFolderUsersMetadataJob::scheduleSubJobs() if (!isMetadataValid) { if (_operation == Operation::Add || _operation == Operation::Remove) { qCWarning(lcUpdateE2eeFolderUsersMetadataJob()) << "Metadata is invalid. Unlocking the folder."; - unlockFolder(false); + unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); } else { qCWarning(lcUpdateE2eeFolderUsersMetadataJob()) << "Metadata is invalid."; emit finished(-1, tr("Error updating metadata for a folder %1").arg(_path)); @@ -219,11 +219,11 @@ void UpdateE2eeFolderUsersMetadataJob::scheduleSubJobs() }); } -void UpdateE2eeFolderUsersMetadataJob::unlockFolder(bool success) +void UpdateE2eeFolderUsersMetadataJob::unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result) { qCDebug(lcUpdateE2eeFolderUsersMetadataJob) << "Calling Unlock"; connect(_encryptedFolderMetadataHandler.data(), &EncryptedFolderMetadataHandler::folderUnlocked, this, &UpdateE2eeFolderUsersMetadataJob::slotFolderUnlocked); - _encryptedFolderMetadataHandler->unlockFolder(success); + _encryptedFolderMetadataHandler->unlockFolder(result); } void UpdateE2eeFolderUsersMetadataJob::slotFolderUnlocked(const QByteArray &folderId, int httpStatus) @@ -241,7 +241,9 @@ void UpdateE2eeFolderUsersMetadataJob::slotFolderUnlocked(const QByteArray &fold void UpdateE2eeFolderUsersMetadataJob::subJobsFinished(bool success) { - unlockFolder(success); + unlockFolder(success + ? EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success + : EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure); } void UpdateE2eeFolderUsersMetadataJob::slotSubJobFinished(int code, const QString &message) @@ -266,7 +268,7 @@ void UpdateE2eeFolderUsersMetadataJob::slotSubJobFinished(int code, const QStrin if (foundInHash != _subJobSyncItems.constEnd() && foundInHash.value()) { foundInHash.value()->_e2eEncryptionStatus = job->encryptionStatus(); foundInHash.value()->_e2eEncryptionStatusRemote = job->encryptionStatus(); - foundInHash.value()->_e2eEncryptionMaximumAvailableStatus = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_account->capabilities().clientSideEncryptionVersion()); + foundInHash.value()->_e2eEncryptionServerCapability = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_account->capabilities().clientSideEncryptionVersion()); _subJobSyncItems.erase(foundInHash); } } diff --git a/src/libsync/updatee2eefolderusersmetadatajob.h b/src/libsync/updatee2eefolderusersmetadatajob.h index cb7af42e37b4e..523d6fcac336a 100644 --- a/src/libsync/updatee2eefolderusersmetadatajob.h +++ b/src/libsync/updatee2eefolderusersmetadatajob.h @@ -58,7 +58,7 @@ class OWNCLOUDSYNC_EXPORT UpdateE2eeFolderUsersMetadataJob : public QObject [[nodiscard]] SyncFileItem::EncryptionStatus encryptionStatus() const; [[nodiscard]] const QByteArray folderToken() const; - void unlockFolder(bool success); + void unlockFolder(const EncryptedFolderMetadataHandler::UnlockFolderWithResult result); public slots: void start(const bool keepLock = false);