mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-24 15:25:31 -04:00
gui: Add YubiKey support to widgets
* Add YubiKey support to the GUI widgets. Signed-off-by: Kyle Manna <kyle@kylemanna.com>
This commit is contained in:
parent
9556d8e6da
commit
ba8fd25604
6 changed files with 124 additions and 0 deletions
|
@ -15,6 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
#include "DatabaseOpenWidget.h"
|
||||
#include "ui_DatabaseOpenWidget.h"
|
||||
|
||||
|
@ -27,6 +29,9 @@
|
|||
#include "format/KeePass2Reader.h"
|
||||
#include "keys/FileKey.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
#include "keys/YkChallengeResponseKey.h"
|
||||
#include "crypto/Random.h"
|
||||
|
||||
|
||||
DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
|
||||
: DialogyWidget(parent)
|
||||
|
@ -49,6 +54,13 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
|
|||
|
||||
connect(m_ui->editPassword, SIGNAL(textChanged(QString)), SLOT(activatePassword()));
|
||||
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(activateKeyFile()));
|
||||
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(activateChallengeResponse()));
|
||||
|
||||
connect(m_ui->checkPassword, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
|
||||
connect(m_ui->checkKeyFile, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
|
||||
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(setOkButtonEnabled()));
|
||||
connect(m_ui->checkChallengeResponse, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
|
||||
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(setOkButtonEnabled()));
|
||||
|
||||
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(openDatabase()));
|
||||
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
||||
|
@ -79,6 +91,13 @@ void DatabaseOpenWidget::load(const QString& filename)
|
|||
}
|
||||
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
|
||||
/* YubiKey init is slow */
|
||||
connect(YubiKey::instance(), SIGNAL(detected(int,bool)),
|
||||
SLOT(ykDetected(int,bool)),
|
||||
Qt::QueuedConnection);
|
||||
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
|
||||
|
||||
m_ui->editPassword->setFocus();
|
||||
}
|
||||
|
||||
|
@ -156,6 +175,15 @@ CompositeKey DatabaseOpenWidget::databaseKey()
|
|||
config()->set("LastKeyFiles", lastKeyFiles);
|
||||
}
|
||||
|
||||
|
||||
if (m_ui->checkChallengeResponse->isChecked()) {
|
||||
int i = m_ui->comboChallengeResponse->currentIndex();
|
||||
i = m_ui->comboChallengeResponse->itemData(i).toInt();
|
||||
YkChallengeResponseKey key(i);
|
||||
|
||||
masterKey.addChallengeResponseKey(key);
|
||||
}
|
||||
|
||||
return masterKey;
|
||||
}
|
||||
|
||||
|
@ -174,6 +202,19 @@ void DatabaseOpenWidget::activateKeyFile()
|
|||
m_ui->checkKeyFile->setChecked(true);
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::activateChallengeResponse()
|
||||
{
|
||||
m_ui->checkChallengeResponse->setChecked(true);
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::setOkButtonEnabled()
|
||||
{
|
||||
bool enable = m_ui->checkPassword->isChecked() || m_ui->checkChallengeResponse->isChecked()
|
||||
|| (m_ui->checkKeyFile->isChecked() && !m_ui->comboKeyFile->currentText().isEmpty());
|
||||
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::browseKeyFile()
|
||||
{
|
||||
QString filters = QString("%1 (*);;%2 (*.key)").arg(tr("All files"), tr("Key files"));
|
||||
|
@ -183,3 +224,11 @@ void DatabaseOpenWidget::browseKeyFile()
|
|||
m_ui->comboKeyFile->lineEdit()->setText(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::ykDetected(int slot, bool blocking)
|
||||
{
|
||||
YkChallengeResponseKey yk(slot, blocking);
|
||||
m_ui->comboChallengeResponse->addItem(yk.getName(), QVariant(slot));
|
||||
m_ui->comboChallengeResponse->setEnabled(true);
|
||||
m_ui->checkChallengeResponse->setEnabled(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue