Skip to content

Commit

Permalink
Fix review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jan 29, 2024
1 parent 166fbe7 commit db15833
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/common/checksums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
13 changes: 6 additions & 7 deletions src/libsync/basepropagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -147,7 +146,7 @@ void BasePropagateRemoteDeleteEncrypted::slotDeleteRemoteItemFinished()
}
_propagator->_journal->commit("Remote Remove");

unlockFolder(true);
unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success);
}

void BasePropagateRemoteDeleteEncrypted::deleteRemoteItem(const QString &filename)
Expand All @@ -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";
Expand All @@ -177,15 +176,15 @@ 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()
{
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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/basepropagateremotedeleteencrypted.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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:
Expand Down
8 changes: 4 additions & 4 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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
Expand Down Expand 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;
Expand Down
8 changes: 4 additions & 4 deletions src/libsync/encryptedfoldermetadatahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/libsync/encryptedfoldermetadatahandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/libsync/foldermetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/libsync/foldermetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "accountfwd.h"
#include "encryptedfoldermetadatahandler.h"
#include <csync.h>
#include <rootencryptedfolderinfo.h>
#include "csync.h"
#include "rootencryptedfolderinfo.h"
#include <QByteArray>
#include <QHash>
#include <QJsonObject>
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void OwncloudPropagator::startFilePropagation(const SyncFileItemPtr &item,

void OwncloudPropagator::processE2eeMetadataMigration(const SyncFileItemPtr &item, QStack<QPair<QString, PropagateDirectory *>> &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 + "/");
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/propagateremotedeleteencryptedrootfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -173,7 +173,7 @@ void PropagateRemoteDeleteEncryptedRootFolder::slotDeleteNestedRemoteItemFinishe
taskFailed();
return;
}
unlockFolder(true);
unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateremotemkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateuploadencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit db15833

Please sign in to comment.