diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2018-05-25 12:01:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-25 12:01:59 +0200 |
commit | cc297302286a7e48d446531fe23224efb393cb5c (patch) | |
tree | ecdbdcf8f92ea75d437174d7ffabd38cddf1d068 /src | |
parent | eea0c7d2273a3bfd761121d9b4c86c68d27dcb06 (diff) | |
parent | 85f3b3b880e031b9277e0e645d7d0aa2835f51f2 (diff) |
Merge pull request #394 from Noettore/feature/otp
Add support for OTP code generation on Linux as requested in #327
Diffstat (limited to 'src')
-rw-r--r-- | src/configdialog.cpp | 15 | ||||
-rw-r--r-- | src/configdialog.h | 1 | ||||
-rw-r--r-- | src/configdialog.ui | 31 | ||||
-rw-r--r-- | src/enums.h | 3 | ||||
-rw-r--r-- | src/imitatepass.cpp | 7 | ||||
-rw-r--r-- | src/imitatepass.h | 1 | ||||
-rw-r--r-- | src/mainwindow.cpp | 37 | ||||
-rw-r--r-- | src/mainwindow.h | 3 | ||||
-rw-r--r-- | src/mainwindow.ui | 12 | ||||
-rw-r--r-- | src/pass.cpp | 3 | ||||
-rw-r--r-- | src/pass.h | 2 | ||||
-rw-r--r-- | src/qtpasssettings.cpp | 8 | ||||
-rw-r--r-- | src/qtpasssettings.h | 3 | ||||
-rw-r--r-- | src/realpass.cpp | 9 | ||||
-rw-r--r-- | src/realpass.h | 1 | ||||
-rw-r--r-- | src/settingsconstants.cpp | 1 | ||||
-rw-r--r-- | src/settingsconstants.h | 1 |
17 files changed, 136 insertions, 2 deletions
diff --git a/src/configdialog.cpp b/src/configdialog.cpp index e7ba895e..92a90053 100644 --- a/src/configdialog.cpp +++ b/src/configdialog.cpp @@ -45,6 +45,11 @@ ConfigDialog::ConfigDialog(MainWindow *parent) ui->checkBoxAutoPush->setChecked(QtPassSettings::isAutoPush()); ui->checkBoxAlwaysOnTop->setChecked(QtPassSettings::isAlwaysOnTop()); + #if defined(Q_OS_WIN ) || defined(__APPLE__) + ui->checkBoxUseOtp->hide(); + ui->label_10->hide(); + #endif + setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile()); setPwgenPath(QtPassSettings::getPwgenExecutable()); setPasswordConfiguration(QtPassSettings::getPasswordConfiguration()); @@ -54,6 +59,7 @@ ConfigDialog::ConfigDialog(MainWindow *parent) useAutoclearPanel(QtPassSettings::isUseAutoclearPanel()); useTrayIcon(QtPassSettings::isUseTrayIcon()); useGit(QtPassSettings::isUseGit()); + useOtp(QtPassSettings::isUseOtp()); usePwgen(QtPassSettings::isUsePwgen()); useTemplate(QtPassSettings::isUseTemplate()); @@ -137,6 +143,7 @@ void ConfigDialog::on_accepted() { QtPassSettings::setStartMinimized(ui->checkBoxStartMinimized->isChecked()); QtPassSettings::setProfiles(getProfiles()); QtPassSettings::setUseGit(ui->checkBoxUseGit->isChecked()); + QtPassSettings::setUseOtp(ui->checkBoxUseOtp->isChecked()); QtPassSettings::setPwgenExecutable(ui->pwgenPath->text()); QtPassSettings::setUsePwgen(ui->checkBoxUsePwgen->isChecked()); QtPassSettings::setAvoidCapitals(ui->checkBoxAvoidCapitals->isChecked()); @@ -559,6 +566,14 @@ void ConfigDialog::useGit(bool useGit) { } /** + * @brief ConfigDialog::useOtp set preference for using otp plugin. + * @param useOtp + */ +void ConfigDialog::useOtp(bool useOtp) { + ui->checkBoxUseOtp->setChecked(useOtp); +} + +/** * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related * checkboxes. */ diff --git a/src/configdialog.h b/src/configdialog.h index af1767df..4db4f24c 100644 --- a/src/configdialog.h +++ b/src/configdialog.h @@ -36,6 +36,7 @@ public: bool hideOnClose(); void useTrayIcon(bool useTrayIdon); void useGit(bool useGit); + void useOtp(bool useOtp); void setPwgenPath(QString); void usePwgen(bool usePwgen); void setPasswordConfiguration(const PasswordConfiguration &config); diff --git a/src/configdialog.ui b/src/configdialog.ui index 5c7d3b5e..80ae5da6 100644 --- a/src/configdialog.ui +++ b/src/configdialog.ui @@ -503,6 +503,37 @@ </layout> </item> <item> + <layout class="QVBoxLayout" name="Extensions"> + <item> + <widget class="QLabel" name="label_10"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Extensions:</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_14"> + <item> + <widget class="QCheckBox" name="checkBoxUseOtp"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Use pass otp extension</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> <layout class="QVBoxLayout" name="Layout_System"> <property name="topMargin"> <number>0</number> diff --git a/src/enums.h b/src/enums.h index 49014bba..1551cb77 100644 --- a/src/enums.h +++ b/src/enums.h @@ -30,7 +30,8 @@ enum PROCESS { GIT_MOVE, GIT_COPY, PROCESS_COUNT, - INVALID + INVALID, + PASS_OTP_GENERATE, }; } // namespace Enums diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index 9a9b7e6f..783fb250 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -42,15 +42,20 @@ void ImitatePass::GitPush() { /** * @brief ImitatePass::Show shows content of file */ - void ImitatePass::Show(QString file) { file = QtPassSettings::getPassStore() + file + ".gpg"; QStringList args = {"-d", "--quiet", "--yes", "--no-encrypt-to", "--batch", "--use-agent", file}; executeGpg(PASS_SHOW, args); + } /** + * @brief ImitatePass::OtpGenerate generates an otp code + */ +void ImitatePass::OtpGenerate(QString file) {} + +/** * @brief ImitatePass::Insert create new file with encrypted content * * @param file file to be created diff --git a/src/imitatepass.h b/src/imitatepass.h index 32f5a639..7c402aa6 100644 --- a/src/imitatepass.h +++ b/src/imitatepass.h @@ -51,6 +51,7 @@ public: virtual void GitPull_b() Q_DECL_OVERRIDE; virtual void GitPush() Q_DECL_OVERRIDE; virtual void Show(QString file) Q_DECL_OVERRIDE; + virtual void OtpGenerate(QString file) Q_DECL_OVERRIDE; virtual void Insert(QString file, QString value, bool overwrite = false) Q_DECL_OVERRIDE; virtual void Remove(QString file, bool isDir = false) Q_DECL_OVERRIDE; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bc913ccf..e894b312 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -103,6 +103,7 @@ void MainWindow::initToolBarButtons() { connect(ui->actionUpdate, SIGNAL(triggered()), this, SLOT(onUpdate())); connect(ui->actionUsers, SIGNAL(triggered()), this, SLOT(onUsers())); connect(ui->actionConfig, SIGNAL(triggered()), this, SLOT(onConfig())); + connect(ui->actionOtp, SIGNAL(triggered()), this, SLOT(onOtp())); ui->actionAddPassword->setIcon( QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg"))); @@ -196,6 +197,7 @@ void MainWindow::connectPassSignalHandlers(Pass *pass) { connect(pass, &Pass::finishedGitPull, this, &MainWindow::processFinished); connect(pass, &Pass::finishedGitPush, this, &MainWindow::processFinished); connect(pass, &Pass::finishedShow, this, &MainWindow::passShowHandler); + connect(pass, &Pass::finishedOtpGenerate, this, &MainWindow::passOtpHandler); connect(pass, &Pass::finishedInsert, this, &MainWindow::finishedInsert); connect(pass, &Pass::finishedRemove, this, &MainWindow::passStoreChanged); connect(pass, &Pass::finishedInit, this, &MainWindow::passStoreChanged); @@ -377,6 +379,7 @@ bool MainWindow::checkConfig() { QtPassSettings::getAutoclearPanelSeconds()); clearClipboardTimer.setInterval(1000 * QtPassSettings::getAutoclearSeconds()); updateGitButtonVisibility(); + updateOtpButtonVisibility(); startupPhase = false; return true; @@ -419,6 +422,7 @@ void MainWindow::config() { QtPassSettings::getAutoclearSeconds()); updateGitButtonVisibility(); + updateOtpButtonVisibility(); if (QtPassSettings::isUseTrayIcon() && tray == NULL) initTrayIcon(); else if (!QtPassSettings::isUseTrayIcon() && tray != NULL) { @@ -592,6 +596,17 @@ void MainWindow::passShowHandler(const QString &p_output) { enableUiElements(true); } +void MainWindow::passOtpHandler(const QString &p_output) { + if (!p_output.isEmpty()) { + addToGridLayout(ui->gridLayout->count()+1, tr("OTP Code"), p_output); + copyTextToClipboard(p_output); + } + if (QtPassSettings::isUseAutoclearPanel()) { + clearPanelTimer.start(); + } + enableUiElements(true); +} + void MainWindow::passStoreChanged(const QString &p_out, const QString &p_err) { processFinished(p_out, p_err); doGitPush(); @@ -723,6 +738,7 @@ void MainWindow::enableUiElements(bool state) { ui->actionDelete->setEnabled(state); ui->actionEdit->setEnabled(state); updateGitButtonVisibility(); + updateOtpButtonVisibility(); } void MainWindow::restoreWindow() { @@ -916,6 +932,17 @@ void MainWindow::onDelete() { } /** + * @brief MainWindow::onOTP try and generate (selected) OTP code. + */ +void MainWindow::onOtp() { + QString file = getFile(ui->treeView->currentIndex(), true); + if (!file.isEmpty()) { + if (QtPassSettings::isUseOtp()) + QtPassSettings::getPass()->OtpGenerate(file); + } +} + +/** * @brief MainWindow::onEdit try and edit (selected) password. */ void MainWindow::onEdit() { @@ -1428,6 +1455,16 @@ void MainWindow::updateGitButtonVisibility() { } } +void MainWindow::updateOtpButtonVisibility() { + #if defined(Q_OS_WIN ) || defined(__APPLE__) + ui->actionOtp->setVisible(false); + #endif + if (!QtPassSettings::isUseOtp()) + ui->actionOtp->setEnabled(false); + else + ui->actionOtp->setEnabled(true); +} + void MainWindow::enableGitButtons(const bool &state) { // Following GNOME guidelines is preferable disable buttons instead of hide ui->actionPush->setEnabled(state); diff --git a/src/mainwindow.h b/src/mainwindow.h index d93e3b85..ab8911bb 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -63,6 +63,7 @@ private slots: void addFolder(); void onEdit(); void onDelete(); + void onOtp(); void onPush(); void onUpdate(bool block = false); void onUsers(); @@ -92,6 +93,7 @@ private slots: void endReencryptPath(); void critical(QString, QString); void passShowHandler(const QString &); + void passOtpHandler(const QString &); void passStoreChanged(const QString &, const QString &); void doGitPush(); @@ -139,6 +141,7 @@ private: void connectPassSignalHandlers(Pass *pass); void updateGitButtonVisibility(); + void updateOtpButtonVisibility(); void enableGitButtons(const bool &); }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 62a194e3..d24a66ce 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -291,6 +291,7 @@ p, li { white-space: pre-wrap; } <addaction name="separator"/> <addaction name="actionEdit"/> <addaction name="actionDelete"/> + <addaction name="actionOtp"/> <addaction name="separator"/> <addaction name="actionPush"/> <addaction name="actionUpdate"/> @@ -333,6 +334,17 @@ p, li { white-space: pre-wrap; } <string>Delete</string> </property> </action> + <action name="actionOtp"> + <property name="text"> + <string>OTP</string> + </property> + <property name="toolTip"> + <string>Generate OTP and copy to clipboard</string> + </property> + <property name="shortcut"> + <string>Ctrl+G</string> + </property> + </action> <action name="actionPush"> <property name="text"> <string>Push</string> diff --git a/src/pass.cpp b/src/pass.cpp index 99216c54..24b371c4 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -181,6 +181,9 @@ void Pass::finished(int id, int exitCode, const QString &out, case PASS_SHOW: emit finishedShow(out); break; + case PASS_OTP_GENERATE: + emit finishedOtpGenerate(out); + break; case PASS_INSERT: emit finishedInsert(out, err); break; @@ -43,6 +43,7 @@ public: virtual void GitPull_b() = 0; virtual void GitPush() = 0; virtual void Show(QString file) = 0; + virtual void OtpGenerate(QString file) = 0; virtual void Insert(QString file, QString value, bool force) = 0; virtual void Remove(QString file, bool isDir) = 0; virtual void Move(const QString srcDir, const QString dest, @@ -87,6 +88,7 @@ signals: void finishedGitPull(const QString &, const QString &); void finishedGitPush(const QString &, const QString &); void finishedShow(const QString &); + void finishedOtpGenerate(const QString &); void finishedInsert(const QString &, const QString &); void finishedRemove(const QString &, const QString &); void finishedInit(const QString &, const QString &); diff --git a/src/qtpasssettings.cpp b/src/qtpasssettings.cpp index ab1400f5..14b0c250 100644 --- a/src/qtpasssettings.cpp +++ b/src/qtpasssettings.cpp @@ -380,6 +380,14 @@ void QtPassSettings::setUseGit(const bool &useGit) { getInstance()->setValue(SettingsConstants::useGit, useGit); } +bool QtPassSettings::isUseOtp(const bool &defaultValue) { + return getInstance()->value(SettingsConstants::useOtp, defaultValue).toBool(); +} + +void QtPassSettings::setUseOtp(const bool &useOtp) { + getInstance()->setValue(SettingsConstants::useOtp, useOtp); +} + bool QtPassSettings::isUsePwgen(const bool &defaultValue) { return getInstance() ->value(SettingsConstants::usePwgen, defaultValue) diff --git a/src/qtpasssettings.h b/src/qtpasssettings.h index 197f80c5..5d787277 100644 --- a/src/qtpasssettings.h +++ b/src/qtpasssettings.h @@ -141,6 +141,9 @@ public: static bool isUseGit(const bool &defaultValue = QVariant().toBool()); static void setUseGit(const bool &useGit); + static bool isUseOtp(const bool &defaultValue = QVariant().toBool()); + static void setUseOtp(const bool &useOtp); + static bool isUsePwgen(const bool &defaultValue = QVariant().toBool()); static void setUsePwgen(const bool &usePwgen); diff --git a/src/realpass.cpp b/src/realpass.cpp index 5684eccd..798ebb83 100644 --- a/src/realpass.cpp +++ b/src/realpass.cpp @@ -45,6 +45,15 @@ void RealPass::Show(QString file) { } /** + * @brief RealPass::OtpGenerate pass otp + * @param file file containig OTP uri + */ +void RealPass::OtpGenerate(QString file) { + executePass(PASS_OTP_GENERATE, {"otp", file}, "", true); +} + + +/** * @brief RealPass::Insert pass insert */ void RealPass::Insert(QString file, QString newValue, bool overwrite) { diff --git a/src/realpass.h b/src/realpass.h index 2c17a0f2..abf96f1a 100644 --- a/src/realpass.h +++ b/src/realpass.h @@ -20,6 +20,7 @@ public: virtual void GitPull_b() Q_DECL_OVERRIDE; virtual void GitPush() Q_DECL_OVERRIDE; virtual void Show(QString file) Q_DECL_OVERRIDE; + virtual void OtpGenerate(QString file) Q_DECL_OVERRIDE; virtual void Insert(QString file, QString value, bool overwrite = false) Q_DECL_OVERRIDE; virtual void Remove(QString file, bool isDir = false) Q_DECL_OVERRIDE; diff --git a/src/settingsconstants.cpp b/src/settingsconstants.cpp index 8b8c31ce..066931f3 100644 --- a/src/settingsconstants.cpp +++ b/src/settingsconstants.cpp @@ -43,6 +43,7 @@ const QString SettingsConstants::webDavPassword = "webDavPassword"; const QString SettingsConstants::profile = "profile"; const QString SettingsConstants::groupProfiles = "profiles"; const QString SettingsConstants::useGit = "useGit"; +const QString SettingsConstants::useOtp = "useOtp"; const QString SettingsConstants::useClipboard = "useClipboard"; const QString SettingsConstants::usePwgen = "usePwgen"; const QString SettingsConstants::avoidCapitals = "avoidCapitals"; diff --git a/src/settingsconstants.h b/src/settingsconstants.h index 0f436085..1b719c8e 100644 --- a/src/settingsconstants.h +++ b/src/settingsconstants.h @@ -40,6 +40,7 @@ public: const static QString profile; const static QString groupProfiles; const static QString useGit; + const static QString useOtp; const static QString useClipboard; const static QString usePwgen; const static QString avoidCapitals; |