Merge pull request #432 from nextcloud/feature/157/show_mnemonic

Add a button to E2E accounts to show the mnemonic
This commit is contained in:
Roeland Jago Douma 2018-06-22 10:15:07 +02:00 committed by GitHub
commit cf93b74028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 2 deletions

View file

@ -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)) {

View file

@ -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

View file

@ -809,6 +809,10 @@ void ClientSideEncryption::forgetSensitiveData()
startDeleteJob(user + e2e_mnemonic);
}
void ClientSideEncryption::slotRequestMnemonic() {
emit showMnemonic(_mnemonic);
}
bool ClientSideEncryption::hasPrivateKey() const
{
return !_privateKey.isNull();

View file

@ -87,6 +87,9 @@ public:
void forgetSensitiveData();
public slots:
void slotRequestMnemonic();
private slots:
void folderEncryptedStatusFetched(const QMap<QString, bool> &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();