Show message when user needs to touch their YubiKey (still buggy when using multiple databases)

This commit is contained in:
Janek Bevendorff 2017-02-24 03:25:08 +01:00
parent 44ac7d152b
commit d6c48a5cf1
No known key found for this signature in database
GPG key ID: CFEC2F6850BFFA53
11 changed files with 75 additions and 16 deletions

View file

@ -87,6 +87,11 @@ Application::Application(int& argc, char** argv)
#endif
}
QWidget* Application::mainWindow() const
{
return m_mainWindow;
}
void Application::setMainWindow(QWidget* mainWindow)
{
m_mainWindow = mainWindow;

View file

@ -29,6 +29,7 @@ class Application : public QApplication
public:
Application(int& argc, char** argv);
QWidget* mainWindow() const;
void setMainWindow(QWidget* mainWindow);
bool event(QEvent* event) override;

View file

@ -25,6 +25,7 @@
#include "gui/FileDialog.h"
#include "gui/MessageBox.h"
#include "crypto/Random.h"
#include "MainWindow.h"
#include "config-keepassx.h"
@ -176,6 +177,8 @@ void ChangeMasterKeyWidget::generateKey()
bool blocking = i & true;
int slot = i >> 1;
auto key = QSharedPointer<YkChallengeResponseKey>(new YkChallengeResponseKey(slot, blocking));
connect(key.data(), SIGNAL(userInteractionRequired()), SLOT(showYubiKeyPopup()));
connect(key.data(), SIGNAL(userConfirmed()), SLOT(hideYubiKeyPopup()));
m_key.addChallengeResponseKey(key);
}
#endif
@ -238,3 +241,15 @@ void ChangeMasterKeyWidget::setCancelEnabled(bool enabled)
{
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(enabled);
}
void ChangeMasterKeyWidget::showYubiKeyPopup()
{
KEEPASSXC_MAIN_WINDOW->displayGlobalMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information);
KEEPASSXC_MAIN_WINDOW->setEnabled(false);
}
void ChangeMasterKeyWidget::hideYubiKeyPopup()
{
KEEPASSXC_MAIN_WINDOW->hideGlobalMessage();
KEEPASSXC_MAIN_WINDOW->setEnabled(true);
}

View file

@ -55,6 +55,8 @@ private slots:
void noYubikeyFound();
void challengeResponseGroupToggled(bool checked);
void pollYubikey();
void showYubiKeyPopup();
void hideYubiKeyPopup();
private:
const QScopedPointer<Ui::ChangeMasterKeyWidget> m_ui;

View file

@ -214,6 +214,8 @@ CompositeKey DatabaseOpenWidget::databaseKey()
bool blocking = i & true;
int slot = i >> 1;
auto key = QSharedPointer<YkChallengeResponseKey>(new YkChallengeResponseKey(slot, blocking));
connect(key.data(), SIGNAL(userInteractionRequired()), SLOT(showYubiKeyPopup()));
connect(key.data(), SIGNAL(userConfirmed()), SLOT(hideYubiKeyPopup()));
masterKey.addChallengeResponseKey(key);
}
#endif
@ -264,6 +266,18 @@ void DatabaseOpenWidget::pollYubikey()
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
}
void DatabaseOpenWidget::showYubiKeyPopup()
{
m_ui->messageWidget->showMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information);
KEEPASSXC_MAIN_WINDOW->setEnabled(false);
}
void DatabaseOpenWidget::hideYubiKeyPopup()
{
m_ui->messageWidget->hideMessage();
KEEPASSXC_MAIN_WINDOW->setEnabled(true);
}
void DatabaseOpenWidget::yubikeyDetected(int slot, bool blocking)
{
YkChallengeResponseKey yk(slot, blocking);

View file

@ -53,6 +53,8 @@ protected:
protected slots:
virtual void openDatabase();
void showYubiKeyPopup();
void hideYubiKeyPopup();
void reject();
private slots:

View file

@ -24,6 +24,7 @@
#include "core/SignalMultiplexer.h"
#include "gui/DatabaseWidget.h"
#include "gui/Application.h"
namespace Ui {
class MainWindow;
@ -43,6 +44,9 @@ public Q_SLOTS:
void openDatabase(const QString& fileName, const QString& pw = QString(),
const QString& keyFile = QString());
void appExit();
void displayGlobalMessage(const QString& text, MessageWidget::MessageType type);
void displayTabMessage(const QString& text, MessageWidget::MessageType type);
void hideGlobalMessage();
protected:
void closeEvent(QCloseEvent* event) override;
@ -75,9 +79,6 @@ private Q_SLOTS:
void toggleWindow();
void lockDatabasesAfterInactivity();
void repairDatabase();
void displayGlobalMessage(const QString& text, MessageWidget::MessageType type);
void displayTabMessage(const QString& text, MessageWidget::MessageType type);
void hideGlobalMessage();
void hideTabMessage();
private:
@ -106,4 +107,6 @@ private:
bool appExitCalled;
};
#define KEEPASSXC_MAIN_WINDOW qobject_cast<MainWindow*>(qobject_cast<Application*>(qApp)->mainWindow())
#endif // KEEPASSX_MAINWINDOW_H