diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index e49bcbfd7..e4d7c372a 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -115,6 +115,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) , _wasDisabledBefore(false) , _accountState(accountState) , _quotaInfo(accountState) + , _menuShown(false) { ui->setupUi(this); @@ -189,12 +190,19 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) connect(&_quotaInfo, &QuotaInfo::quotaUpdated, this, &AccountSettings::slotUpdateQuota); + + // Connect E2E stuff + connect(this, &AccountSettings::requesetMnemonic, _accountState->account()->e2e(), &ClientSideEncryption::slotRequestMnemonic); + connect(_accountState->account()->e2e(), &ClientSideEncryption::showMnemonic, this, &AccountSettings::slotShowMnemonic); } void AccountSettings::createAccountToolbox() { QMenu *menu = new QMenu(); + + connect(menu, &QMenu::aboutToShow, this, &AccountSettings::slotMenuBeforeShow); + _addAccountAction = new QAction(tr("Add new"), this); menu->addAction(_addAccountAction); connect(_addAccountAction, &QAction::triggered, this, &AccountSettings::slotOpenAccountWizard); @@ -214,6 +222,24 @@ void AccountSettings::createAccountToolbox() slotAccountAdded(_accountState); } +void AccountSettings::slotMenuBeforeShow() { + if (_menuShown) { + return; + } + + auto menu = ui->_accountToolbox->menu(); + + // We can't check this during the initial creation as there is no account yet then + if (_accountState->account()->capabilities().clientSideEncryptionAvaliable()) { + QAction *mnemonic = new QAction(tr("Show E2E mnemonic"), this); + connect(mnemonic, &QAction::triggered, this, &AccountSettings::requesetMnemonic); + menu->addAction(mnemonic); + } + + _menuShown = true; +} + + QString AccountSettings::selectedFolderAlias() const { QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); @@ -257,6 +283,13 @@ void AccountSettings::doExpand() ui->_folderList->expandToDepth(0); } +void AccountSettings::slotShowMnemonic(const QString &mnemonic) { + QMessageBox msgBox; + msgBox.setText(tr("Your end to end encryption mnemonic is:")); + msgBox.setInformativeText(mnemonic); + msgBox.exec(); +} + void AccountSettings::slotEncryptionFlagSuccess(const QByteArray& fileId) { if (auto info = _model->infoForFileId(fileId)) { diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index 2345e90bc..ef76ad5d9 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -62,6 +62,7 @@ signals: void folderChanged(); void openFolderAlias(const QString &); void showIssuesList(const QString &folderAlias); + void requesetMnemonic(); public slots: void slotOpenOC(); @@ -94,15 +95,19 @@ protected slots: void doExpand(); void slotLinkActivated(const QString &link); + void slotMenuBeforeShow(); + // Encryption Related Stuff. + void slotShowMnemonic(const QString &mnemonic); + void slotEncryptionFlagSuccess(const QByteArray &folderId); void slotEncryptionFlagError(const QByteArray &folderId, int httpReturnCode); void slotLockForEncryptionSuccess(const QByteArray& folderId, const QByteArray& token); void slotLockForEncryptionError(const QByteArray &folderId, int httpReturnCode); void slotUnlockFolderSuccess(const QByteArray& folderId); void slotUnlockFolderError(const QByteArray& folderId, int httpReturnCode); - void slotUploadMetadataSuccess(const QByteArray& folderId); - void slotUpdateMetadataError(const QByteArray& folderId, int httpReturnCode); + void slotUploadMetadataSuccess(const QByteArray& folderId); + void slotUpdateMetadataError(const QByteArray& folderId, int httpReturnCode); // Remove Encryotion Bit. void slotLockForDecryptionSuccess(const QByteArray& folderId, const QByteArray& token); @@ -132,6 +137,8 @@ private: QuotaInfo _quotaInfo; QAction *_toggleSignInOutAction; QAction *_addAccountAction; + + bool _menuShown; }; } // namespace OCC diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 398aa60f4..818121fde 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -809,6 +809,10 @@ void ClientSideEncryption::forgetSensitiveData() startDeleteJob(user + e2e_mnemonic); } +void ClientSideEncryption::slotRequestMnemonic() { + emit showMnemonic(_mnemonic); +} + bool ClientSideEncryption::hasPrivateKey() const { return !_privateKey.isNull(); diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 66cfdf901..7440947c8 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -87,6 +87,9 @@ public: void forgetSensitiveData(); +public slots: + void slotRequestMnemonic(); + private slots: void folderEncryptedStatusFetched(const QMap &values); void folderEncryptedStatusError(int error); @@ -98,6 +101,7 @@ private slots: signals: void initializationFinished(); void mnemonicGenerated(const QString& mnemonic); + void showMnemonic(const QString& mnemonic); private: void getPrivateKeyFromServer();