Skip to content
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
57 changes: 27 additions & 30 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -63,8 +63,8 @@
constexpr auto propertyFolder = "folder";
constexpr auto propertyPath = "path";
constexpr auto e2eUiActionIdKey = "id";
constexpr auto e2EeUiActionEnableEncryptionId = "enable_encryption";
constexpr auto e2EeUiActionDisableEncryptionId = "disable_encryption";
constexpr auto e2EeUiActionSetupEncryptionId = "setup_encryption";
constexpr auto e2EeUiActionForgetEncryptionId = "forget_encryption";
constexpr auto e2EeUiActionDisplayMnemonicId = "display_mnemonic";
constexpr auto e2EeUiActionMigrateCertificateId = "migrate_certificate";
}
Expand Down Expand Up @@ -274,7 +274,7 @@
_ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name()));*/

// Connect E2E stuff
initializeE2eEncryption();
setupE2eEncryption();
_ui->encryptionMessage->setCloseButtonVisible(false);

_ui->connectLabel->setText(tr("No account configured."));
Expand All @@ -295,9 +295,9 @@

void AccountSettings::slotE2eEncryptionMnemonicReady()
{
const auto actionDisableEncryption = addActionToEncryptionMessage(tr("Disable encryption"), e2EeUiActionDisableEncryptionId);
const auto actionDisableEncryption = addActionToEncryptionMessage(tr("Forget encryption setup"), e2EeUiActionForgetEncryptionId);
connect(actionDisableEncryption, &QAction::triggered, this, [this] {
disableEncryptionForAccount(_accountState->account());
forgetEncryptionOnDeviceForAccount(_accountState->account());
});

if (_accountState->account()->e2e()->userCertificateNeedsMigration()) {
Expand All @@ -312,7 +312,7 @@
}

_ui->encryptionMessage->setMessageType(KMessageWidget::Positive);
_ui->encryptionMessage->setText(tr("End-to-end encryption has been enabled for this account"));
_ui->encryptionMessage->setText(tr("Encryption is set-up. Remember to <b>Encrypt</b> a folder to end-to-end encrypt any new files added to it."));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/lock.svg")));
_ui->encryptionMessage->show();
}
Expand All @@ -329,7 +329,7 @@
{
disconnect(_accountState->account()->e2e(), &ClientSideEncryption::initializationFinished, this, &AccountSettings::slotE2eEncryptionInitializationFinished);
if (_accountState->account()->e2e()->isInitialized()) {
removeActionFromEncryptionMessage(e2EeUiActionEnableEncryptionId);
removeActionFromEncryptionMessage(e2EeUiActionSetupEncryptionId);
slotE2eEncryptionMnemonicReady();
if (isNewMnemonicGenerated) {
displayMnemonic(_accountState->account()->e2e()->getMnemonic());
Expand Down Expand Up @@ -406,9 +406,8 @@

if (!_accountState->account()->e2e() || !_accountState->account()->e2e()->isInitialized()) {
QMessageBox msgBox;
msgBox.setText(tr("End-to-end encryption is not configured on this device. "
"Once it is configured, you will be able to encrypt this folder.\n"
"Would you like to set up end-to-end encryption?"));
msgBox.setText(tr("You cannot encrypt this folder because the end-to-end encryption is not set-up yet on this device.\n"
"Would you like to do this now?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
const auto ret = msgBox.exec();
Expand Down Expand Up @@ -1092,9 +1091,9 @@
widget.setWindowTitle(tr("End-to-end encryption mnemonic"));
ui.label->setText(
tr("To protect your Cryptographic Identity, we encrypt it with a mnemonic of 12 dictionary words. "
"Please note these down and keep them safe. "
"They will be needed to add other devices to your account (like your mobile phone or laptop)."));
"Please note it down and keep it safe. "
"You will need it to set-up the synchronization of encrypted folders on your other devices."));
QFont monoFont(QStringLiteral("Monospace"));

Check warning on line 1096 in src/gui/accountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1096:11 [cppcoreguidelines-init-variables]

variable 'monoFont' is not initialized
monoFont.setStyleHint(QFont::TypeWriter);
ui.lineEdit->setFont(monoFont);
ui.lineEdit->setText(mnemonic);
Expand All @@ -1113,14 +1112,14 @@
widget.exec();
}

void AccountSettings::disableEncryptionForAccount(const AccountPtr &account) const
void AccountSettings::forgetEncryptionOnDeviceForAccount(const AccountPtr &account) const

Check warning on line 1115 in src/gui/accountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1115:23 [readability-convert-member-functions-to-static]

method 'forgetEncryptionOnDeviceForAccount' can be made static
{
QMessageBox dialog;
dialog.setWindowTitle(tr("Disable end-to-end encryption"));
dialog.setText(tr("Disable end-to-end encryption for %1?").arg(account->davUser()));
dialog.setInformativeText(tr("Removing end-to-end encryption will remove locally-synced files that are encrypted."
dialog.setWindowTitle(tr("Forget the end-to-end encryption on this device"));
dialog.setText(tr("Do you want to forget the end-to-end encryption settings for %1 on this device?").arg(account->davUser()));
dialog.setInformativeText(tr("Forgetting end-to-end encryption will remove the sensitive data and all the encrypted files from this device."
"<br>"
"Encrypted files will remain on the server."));
"However, the encrypted files will remain on the server and all your other devices, if configured."));
dialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
dialog.setDefaultButton(QMessageBox::Ok);
dialog.adjustSize();
Expand All @@ -1129,7 +1128,7 @@
switch(ret) {
case QMessageBox::Ok:
connect(account->e2e(), &ClientSideEncryption::sensitiveDataForgotten,
this, &AccountSettings::resetE2eEncryption);
this, &AccountSettings::forgetE2eEncryption);
account->e2e()->forgetSensitiveData(account);
break;
case QMessageBox::Cancel:
Expand Down Expand Up @@ -1677,37 +1676,35 @@
_ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name()));
}

void AccountSettings::initializeE2eEncryption()
void AccountSettings::setupE2eEncryption()
{
connect(_accountState->account()->e2e(), &ClientSideEncryption::initializationFinished, this, &AccountSettings::slotPossiblyUnblacklistE2EeFoldersAndRestartSync);

if (_accountState->account()->e2e()->isInitialized()) {
slotE2eEncryptionMnemonicReady();
} else {
initializeE2eEncryptionSettingsMessage();
setupE2eEncryptionMessage();

connect(_accountState->account()->e2e(), &ClientSideEncryption::initializationFinished, this, [this] {
if (!_accountState->account()->e2e()->getPublicKey().isNull()) {
_ui->encryptionMessage->setText(tr("End-to-end encryption has been enabled on this account with another device."
_ui->encryptionMessage->setText(tr("End-to-end encryption has been initialized on this account with another device."
"<br>"
"It can be enabled on this device by entering your mnemonic."
"<br>"
"This will enable synchronisation of existing encrypted folders."));
"Enter the unique mnemonic to have the encrypted folders synchronize on this device as well."));
}
});
_accountState->account()->setE2eEncryptionKeysGenerationAllowed(false);
_accountState->account()->e2e()->initialize(this, _accountState->account());
}
}

void AccountSettings::resetE2eEncryption()
void AccountSettings::forgetE2eEncryption()
{
for (const auto action : _ui->encryptionMessage->actions()) {
_ui->encryptionMessage->removeAction(action);
}
_ui->encryptionMessage->setText({});
_ui->encryptionMessage->setIcon({});
initializeE2eEncryptionSettingsMessage();
setupE2eEncryptionMessage();
checkClientSideEncryptionState();

const auto account = _accountState->account();
Expand Down Expand Up @@ -1744,15 +1741,15 @@
return action;
}

void AccountSettings::initializeE2eEncryptionSettingsMessage()
void AccountSettings::setupE2eEncryptionMessage()
{
_ui->encryptionMessage->setMessageType(KMessageWidget::Information);
_ui->encryptionMessage->setText(tr("This account supports end-to-end encryption"));
_ui->encryptionMessage->setText(tr("This account supports end-to-end encryption, but it needs to be set up first."));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/black/state-info.svg")));
_ui->encryptionMessage->hide();

auto *const actionEnableE2e = addActionToEncryptionMessage(tr("Set up encryption"), e2EeUiActionEnableEncryptionId);
connect(actionEnableE2e, &QAction::triggered, this, &AccountSettings::slotE2eEncryptionGenerateKeys);
auto *const actionSetupE2e = addActionToEncryptionMessage(tr("Set up encryption"), e2EeUiActionSetupEncryptionId);

Check warning on line 1751 in src/gui/accountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1751:17 [cppcoreguidelines-init-variables]

variable 'actionSetupE2e' is not initialized
connect(actionSetupE2e, &QAction::triggered, this, &AccountSettings::slotE2eEncryptionGenerateKeys);
}

} // namespace OCC
Expand Down
8 changes: 4 additions & 4 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ACCOUNTSETTINGS_H
#define ACCOUNTSETTINGS_H

#include <QWidget>

Check failure on line 10 in src/gui/accountsettings.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.h:10:10 [clang-diagnostic-error]

'QWidget' file not found
#include <QUrl>
#include <QPointer>
#include <QHash>
Expand Down Expand Up @@ -116,22 +116,22 @@

private slots:
void displayMnemonic(const QString &mnemonic);
void disableEncryptionForAccount(const OCC::AccountPtr &account) const;
void forgetEncryptionOnDeviceForAccount(const OCC::AccountPtr &account) const;
void migrateCertificateForAccount(const OCC::AccountPtr &account);
void showConnectionLabel(const QString &message, QStringList errors = QStringList());
void openIgnoredFilesDialog(const QString & absFolderPath);
void customizeStyle();

void initializeE2eEncryption();
void resetE2eEncryption();
void setupE2eEncryption();
void forgetE2eEncryption();
void checkClientSideEncryptionState();
void removeActionFromEncryptionMessage(const QString &actionId);

private:
bool event(QEvent *) override;
QAction *addActionToEncryptionMessage(const QString &actionTitle, const QString &actionId);

void initializeE2eEncryptionSettingsMessage();
void setupE2eEncryptionMessage();

/// Returns the alias of the selected folder, empty string if none
[[nodiscard]] QString selectedFolderAlias() const;
Expand Down
Loading