Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/e2ee fixes #5560

Merged
merged 16 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void fillFileRecordFromGetQuery(SyncJournalFileRecord &rec, SqlQuery &que
rec._serverHasIgnoredFiles = (query.intValue(8) > 0);
rec._checksumHeader = query.baValue(9);
rec._e2eMangledName = query.baValue(10);
rec._isE2eEncrypted = query.intValue(11) > 0;
rec._isE2eEncrypted = static_cast<SyncJournalFileRecord::EncryptionStatus>(query.intValue(11));
rec._lockstate._locked = query.intValue(12) > 0;
rec._lockstate._lockOwnerDisplayName = query.stringValue(13);
rec._lockstate._lockOwnerId = query.stringValue(14);
Expand Down Expand Up @@ -910,7 +910,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
<< "modtime:" << record._modtime << "type:" << record._type << "etag:" << record._etag
<< "fileId:" << record._fileId << "remotePerm:" << record._remotePerm.toString()
<< "fileSize:" << record._fileSize << "checksum:" << record._checksumHeader
<< "e2eMangledName:" << record.e2eMangledName() << "isE2eEncrypted:" << record._isE2eEncrypted
<< "e2eMangledName:" << record.e2eMangledName() << "isE2eEncrypted:" << record.isE2eEncrypted()
<< "lock:" << (record._lockstate._locked ? "true" : "false")
<< "lock owner type:" << record._lockstate._lockOwnerType
<< "lock owner:" << record._lockstate._lockOwnerDisplayName
Expand Down Expand Up @@ -968,7 +968,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
query->bindValue(15, checksum);
query->bindValue(16, contentChecksumTypeId);
query->bindValue(17, record._e2eMangledName);
query->bindValue(18, record._isE2eEncrypted);
query->bindValue(18, static_cast<int>(record._isE2eEncrypted));
query->bindValue(19, record._lockstate._locked ? 1 : 0);
query->bindValue(20, record._lockstate._lockOwnerType);
query->bindValue(21, record._lockstate._lockOwnerDisplayName);
Expand Down Expand Up @@ -2694,4 +2694,10 @@ bool operator==(const SyncJournalDb::UploadInfo &lhs,
&& lhs._contentChecksum == rhs._contentChecksum;
}

QDebug& operator<<(QDebug &stream, const SyncJournalFileRecord::EncryptionStatus status)
{
stream << static_cast<int>(status);
return stream;
}

} // namespace OCC
11 changes: 10 additions & 1 deletion src/common/syncjournalfilerecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class OCSYNC_EXPORT SyncJournalFileRecord
return !_path.isEmpty();
}

enum class EncryptionStatus : int {
NotEncrypted = 0,
Encrypted = 1,
EncryptedMigratedV1_2 = 2,
};

/** Returns the numeric part of the full id in _fileId.
*
* On the server this is sometimes known as the internal file id.
Expand All @@ -67,6 +73,7 @@ class OCSYNC_EXPORT SyncJournalFileRecord
[[nodiscard]] bool isVirtualFile() const { return _type == ItemTypeVirtualFile || _type == ItemTypeVirtualFileDownload; }
[[nodiscard]] QString path() const { return QString::fromUtf8(_path); }
[[nodiscard]] QString e2eMangledName() const { return QString::fromUtf8(_e2eMangledName); }
[[nodiscard]] bool isE2eEncrypted() const { return _isE2eEncrypted != SyncJournalFileRecord::EncryptionStatus::NotEncrypted; }

QByteArray _path;
quint64 _inode = 0;
Expand All @@ -79,13 +86,15 @@ class OCSYNC_EXPORT SyncJournalFileRecord
bool _serverHasIgnoredFiles = false;
QByteArray _checksumHeader;
QByteArray _e2eMangledName;
bool _isE2eEncrypted = false;
EncryptionStatus _isE2eEncrypted = EncryptionStatus::NotEncrypted;
SyncJournalFileLockInfo _lockstate;
bool _isShared = false;
qint64 _lastShareStateFetchedTimestamp = 0;
bool _sharedByMe = false;
};

QDebug& operator<<(QDebug &stream, const SyncJournalFileRecord::EncryptionStatus status);

bool OCSYNC_EXPORT
operator==(const SyncJournalFileRecord &lhs,
const SyncJournalFileRecord &rhs);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
if (acc->capabilities().clientSideEncryptionAvailable()) {
// Verify if the folder is empty before attempting to encrypt.

const auto isEncrypted = info->_isEncrypted;
const auto isEncrypted = info->isEncrypted();
const auto isParentEncrypted = _model->isAnyAncestorEncrypted(index);

if (!isEncrypted && !isParentEncrypted) {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ void ShareModel::updateData()

_numericFileId = fileRecord.numericFileId();

_isEncryptedItem = fileRecord._isE2eEncrypted;
_isEncryptedItem = fileRecord.isE2eEncrypted();
_isSecureFileDropSupportedFolder =
fileRecord._isE2eEncrypted && fileRecord.e2eMangledName().isEmpty() && _accountState->account()->secureFileDropSupported();
fileRecord.isE2eEncrypted() && fileRecord.e2eMangledName().isEmpty() && _accountState->account()->secureFileDropSupported();

// Will get added when shares are fetched if no link shares are fetched
_placeholderLinkShare.reset(new Share(_accountState->account(),
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ void Folder::removeLocalE2eFiles()
QStringList e2eFoldersToBlacklist;
const auto couldGetFiles = _journal.getFilesBelowPath("", [this, &e2eFoldersToBlacklist, &folderRootDir](const SyncJournalFileRecord &rec) {
// We only want to add the root-most encrypted folder to the blacklist
if (rec.isValid() && rec._isE2eEncrypted && rec.isDirectory()) {
if (rec.isValid() && rec.isE2eEncrypted() && rec.isDirectory()) {
QDir pathDir(_canonicalLocalPath + rec.path());
bool parentPathEncrypted = false;

Expand All @@ -1359,7 +1359,7 @@ void Folder::removeLocalE2eFiles()
qCWarning(lcFolder) << "Failed to get file record for" << currentCanonicalPath;
}

if (dirRec._isE2eEncrypted) {
if (dirRec.isE2eEncrypted()) {
parentPathEncrypted = true;
break;
}
Expand Down
12 changes: 6 additions & 6 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: {
//: Example text: "File.txt (23KB)"
const auto &xParent = static_cast<SubFolderInfo *>(index.internalPointer());
const auto suffix = (subfolderInfo._isNonDecryptable && subfolderInfo._checked && (!xParent || !xParent->_isEncrypted))
const auto suffix = (subfolderInfo._isNonDecryptable && subfolderInfo._checked && (!xParent || !xParent->isEncrypted()))
? QStringLiteral(" - ") + tr("Could not decrypt!")
: QString{};
return subfolderInfo._size < 0 ? QString(subfolderInfo._name + suffix) : QString(tr("%1 (%2)").arg(subfolderInfo._name, Utility::octetsToString(subfolderInfo._size)) + suffix);
Expand All @@ -179,7 +179,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
if (subfolderInfo._isNonDecryptable && subfolderInfo._checked) {
return QIcon(QLatin1String(":/client/theme/lock-broken.svg"));
}
if (subfolderInfo._isEncrypted) {
if (subfolderInfo.isEncrypted()) {
return QIcon(QLatin1String(":/client/theme/lock-https.svg"));
} else if (subfolderInfo._size > 0 && isAnyAncestorEncrypted(index)) {
return QIcon(QLatin1String(":/client/theme/lock-broken.svg"));
Expand Down Expand Up @@ -445,7 +445,7 @@ bool FolderStatusModel::isAnyAncestorEncrypted(const QModelIndex &index) const
auto parentIndex = parent(index);
while (parentIndex.isValid()) {
const auto info = infoForIndex(parentIndex);
if (info->_isEncrypted) {
if (info->isEncrypted()) {
return true;
}
parentIndex = parent(parentIndex);
Expand Down Expand Up @@ -607,7 +607,7 @@ void FolderStatusModel::fetchMore(const QModelIndex &parent)
QString path = info->_folder->remotePathTrailingSlash();

// info->_path always contains non-mangled name, so we need to use mangled when requesting nested folders for encrypted subfolders as required by LsColJob
const QString infoPath = (info->_isEncrypted && !info->_e2eMangledName.isEmpty()) ? info->_e2eMangledName : info->_path;
const QString infoPath = (info->isEncrypted() && !info->_e2eMangledName.isEmpty()) ? info->_e2eMangledName : info->_path;

if (infoPath != QLatin1String("/")) {
path += infoPath;
Expand Down Expand Up @@ -752,7 +752,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
newInfo._isEncrypted = encryptionMap.value(removeTrailingSlash(path)).toString() == QStringLiteral("1");
newInfo._path = relativePath;

newInfo._isNonDecryptable = newInfo._isEncrypted
newInfo._isNonDecryptable = newInfo.isEncrypted()
&& _accountState->account()->e2e() && !_accountState->account()->e2e()->_publicKey.isNull()
&& _accountState->account()->e2e()->_privateKey.isNull();

Expand All @@ -762,7 +762,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
}
if (rec.isValid()) {
newInfo._name = removeTrailingSlash(rec._path).split('/').last();
if (rec._isE2eEncrypted && !rec._e2eMangledName.isEmpty()) {
if (rec.isE2eEncrypted() && !rec._e2eMangledName.isEmpty()) {
// we must use local path for Settings Dialog's filesystem tree, otherwise open and create new folder actions won't work
// hence, we are storing _e2eMangledName separately so it can be use later for LsColJob
newInfo._e2eMangledName = relativePath;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/folderstatusmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class FolderStatusModel : public QAbstractItemModel
// Whether this has a FetchLabel subrow
[[nodiscard]] bool hasLabel() const;

[[nodiscard]] bool isEncrypted() const { return _isEncrypted; }

// Reset all subfolders and fetch status
void resetSubs(FolderStatusModel *model, QModelIndex index);

Expand Down
6 changes: 3 additions & 3 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ void SocketApi::sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo,
bool anyAncestorEncrypted = false;
auto ancestor = fileData.parentFolder();
while (ancestor.journalRecord().isValid()) {
if (ancestor.journalRecord()._isE2eEncrypted) {
if (ancestor.journalRecord().isE2eEncrypted()) {
anyAncestorEncrypted = true;
break;
}
Expand Down Expand Up @@ -1352,8 +1352,8 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
FileData fileData = FileData::get(argument);
const auto record = fileData.journalRecord();
const bool isOnTheServer = record.isValid();
const auto isE2eEncryptedPath = fileData.journalRecord()._isE2eEncrypted || !fileData.journalRecord()._e2eMangledName.isEmpty();
const auto isE2eEncryptedRootFolder = fileData.journalRecord()._isE2eEncrypted && fileData.journalRecord()._e2eMangledName.isEmpty();
const auto isE2eEncryptedPath = fileData.journalRecord().isE2eEncrypted() || !fileData.journalRecord()._e2eMangledName.isEmpty();
const auto isE2eEncryptedRootFolder = fileData.journalRecord().isE2eEncrypted() && fileData.journalRecord()._e2eMangledName.isEmpty();
auto flagString = isOnTheServer && !isE2eEncryptedPath ? QLatin1String("::") : QLatin1String(":d:");

const QFileInfo fileInfo(fileData.localPath);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
if (!folder->journalDb()->getFileRecord(fileName.mid(1), &rec)) {
qCWarning(lcActivity) << "could not get file from local DB" << fileName.mid(1);
}
if (rec.isValid() && (rec._isE2eEncrypted || !rec._e2eMangledName.isEmpty())) {
if (rec.isValid() && (rec.isE2eEncrypted() || !rec._e2eMangledName.isEmpty())) {
return QString();
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ bool Capabilities::clientSideEncryptionAvailable() const
return capabilityAvailable;
}

double Capabilities::clientSideEncryptionVersion() const
{
const auto foundEndToEndEncryptionInCaps = _capabilities.constFind(QStringLiteral("end-to-end-encryption"));
if (foundEndToEndEncryptionInCaps == _capabilities.constEnd()) {
return 1.0;
}

const auto properties = (*foundEndToEndEncryptionInCaps).toMap();
const auto enabled = properties.value(QStringLiteral("enabled"), false).toBool();
if (!enabled) {
return false;
}

return properties.value(QStringLiteral("api-version"), 1.0).toDouble();
}

bool Capabilities::notificationsAvailable() const
{
// We require the OCS style API in 9.x, can't deal with the REST one only found in 8.2
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class OWNCLOUDSYNC_EXPORT Capabilities
/// returns true if the server supports client side encryption
[[nodiscard]] bool clientSideEncryptionAvailable() const;

[[nodiscard]] double clientSideEncryptionVersion() const;

/// returns true if the capabilities are loaded already.
[[nodiscard]] bool isValid() const;

Expand Down
Loading