Add redetect button to ChangeMasterKeyWidget and only poll for Yubikeys when the challenge response group is enabled

This commit is contained in:
Janek Bevendorff 2017-02-20 22:41:39 +01:00
parent eb23dda99b
commit c7defdc06f
No known key found for this signature in database
GPG Key ID: CFEC2F6850BFFA53
3 changed files with 58 additions and 27 deletions

View File

@ -44,9 +44,11 @@ ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent)
connect(m_ui->createKeyFileButton, SIGNAL(clicked()), SLOT(createKeyFile()));
connect(m_ui->browseKeyFileButton, SIGNAL(clicked()), SLOT(browseKeyFile()));
connect(YubiKey::instance(), SIGNAL(detected(int,bool)),
SLOT(ykDetected(int,bool)),
Qt::QueuedConnection);
connect(m_ui->challengeResponseGroup, SIGNAL(clicked(bool)), SLOT(challengeResponseGroupToggled(bool)));
connect(m_ui->buttonRedetectYubikey, SIGNAL(clicked()), SLOT(pollYubikey()));
connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection);
connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection);
}
ChangeMasterKeyWidget::~ChangeMasterKeyWidget()
@ -89,14 +91,9 @@ void ChangeMasterKeyWidget::clearForms()
m_ui->repeatPasswordEdit->setText("");
m_ui->keyFileGroup->setChecked(false);
m_ui->togglePasswordButton->setChecked(false);
// TODO: clear m_ui->keyFileCombo
m_ui->challengeResponseGroup->setChecked(false);
m_ui->challengeResponseCombo->clear();
/* YubiKey init is slow, detect asynchronously to not block the UI */
m_ui->challengeResponseCombo->clear();
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
m_ui->comboChallengeResponse->clear();
m_ui->enterPasswordEdit->setFocus();
}
@ -146,29 +143,50 @@ void ChangeMasterKeyWidget::generateKey()
}
if (m_ui->challengeResponseGroup->isChecked()) {
int i = m_ui->challengeResponseCombo->currentIndex();
i = m_ui->challengeResponseCombo->itemData(i).toInt();
int i = m_ui->comboChallengeResponse->currentIndex();
i = m_ui->comboChallengeResponse->itemData(i).toInt();
YkChallengeResponseKey key(i);
m_key.addChallengeResponseKey(key);
}
m_ui->messageWidget->hideMessage();
Q_EMIT editFinished(true);
emit editFinished(true);
}
void ChangeMasterKeyWidget::reject()
{
Q_EMIT editFinished(false);
emit editFinished(false);
}
void ChangeMasterKeyWidget::challengeResponseGroupToggled(bool checked)
{
if (checked)
pollYubikey();
}
void ChangeMasterKeyWidget::ykDetected(int slot, bool blocking)
void ChangeMasterKeyWidget::pollYubikey()
{
m_ui->buttonRedetectYubikey->setEnabled(false);
m_ui->comboChallengeResponse->setEnabled(false);
m_ui->comboChallengeResponse->clear();
// YubiKey init is slow, detect asynchronously to not block the UI
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
}
void ChangeMasterKeyWidget::yubikeyDetected(int slot, bool blocking)
{
YkChallengeResponseKey yk(slot, blocking);
m_ui->challengeResponseCombo->addItem(yk.getName(), QVariant(slot));
m_ui->challengeResponseGroup->setEnabled(true);
m_ui->comboChallengeResponse->addItem(yk.getName(), QVariant(slot));
m_ui->comboChallengeResponse->setEnabled(m_ui->challengeResponseGroup->isChecked());
m_ui->buttonRedetectYubikey->setEnabled(m_ui->challengeResponseGroup->isChecked());
}
void ChangeMasterKeyWidget::noYubikeyFound()
{
m_ui->buttonRedetectYubikey->setEnabled(m_ui->challengeResponseGroup->isChecked());
}
void ChangeMasterKeyWidget::setCancelEnabled(bool enabled)

View File

@ -48,7 +48,10 @@ private Q_SLOTS:
void reject();
void createKeyFile();
void browseKeyFile();
void ykDetected(int slot, bool blocking);
void yubikeyDetected(int slot, bool blocking);
void noYubikeyFound();
void challengeResponseGroupToggled(bool checked);
void pollYubikey();
private:
const QScopedPointer<Ui::ChangeMasterKeyWidget> m_ui;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>818</width>
<height>397</height>
<height>424</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -90,7 +90,7 @@
<item>
<widget class="QGroupBox" name="keyFileGroup">
<property name="title">
<string>Key file</string>
<string>&amp;Key file</string>
</property>
<property name="checkable">
<bool>true</bool>
@ -129,22 +129,32 @@
<item>
<widget class="QGroupBox" name="challengeResponseGroup">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Challenge Response</string>
<string>Cha&amp;llenge Response</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QComboBox" name="challengeResponseCombo"/>
</item>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="challengeResponseLabel">
<widget class="QComboBox" name="comboChallengeResponse">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="buttonRedetectYubikey">
<property name="text">
<string>Challenge Response:</string>
<string>Refresh</string>
</property>
</widget>
</item>