Skip to content

Commit ce2322f

Browse files
committed
Always attempt to init Yubikey before challenge
Instead of retrying a predefined number of times in case of an error, always try to re-init Yubikey before issuing a challenge. Fixes keepassxreboot#712.
1 parent caa49a8 commit ce2322f

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

src/keys/YkChallengeResponseKey.cpp

+18-38
Original file line numberDiff line numberDiff line change
@@ -45,51 +45,31 @@ QByteArray YkChallengeResponseKey::rawKey() const
4545
return m_key;
4646
}
4747

48-
/**
49-
* Assumes yubikey()->init() was called
50-
*/
5148
bool YkChallengeResponseKey::challenge(const QByteArray& challenge)
5249
{
53-
return this->challenge(challenge, 1);
54-
}
55-
56-
bool YkChallengeResponseKey::challenge(const QByteArray& challenge, unsigned retries)
57-
{
58-
Q_ASSERT(retries > 0);
59-
60-
do {
61-
--retries;
62-
63-
if (m_blocking) {
64-
emit userInteractionRequired();
65-
}
66-
67-
QFuture<YubiKey::ChallengeResult> future = QtConcurrent::run([this, challenge]() {
68-
return YubiKey::instance()->challenge(m_slot, true, challenge, m_key);
69-
});
70-
71-
QEventLoop loop;
72-
QFutureWatcher<YubiKey::ChallengeResult> watcher;
73-
watcher.setFuture(future);
74-
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
75-
loop.exec();
50+
if (!YubiKey::instance()->init()) {
51+
return false;
52+
}
7653

77-
if (m_blocking) {
78-
emit userConfirmed();
79-
}
54+
if (m_blocking) {
55+
emit userInteractionRequired();
56+
}
8057

81-
if (future.result() != YubiKey::ERROR) {
82-
return true;
83-
}
58+
QFuture<YubiKey::ChallengeResult> future = QtConcurrent::run([this, challenge]() {
59+
return YubiKey::instance()->challenge(m_slot, true, challenge, m_key);
60+
});
8461

85-
// if challenge failed, retry to detect YubiKeys in the event the YubiKey was un-plugged and re-plugged
86-
if (retries > 0 && YubiKey::instance()->init() != true) {
87-
continue;
88-
}
62+
QEventLoop loop;
63+
QFutureWatcher<YubiKey::ChallengeResult> watcher;
64+
watcher.setFuture(future);
65+
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
66+
loop.exec();
8967

90-
} while (retries > 0);
68+
if (m_blocking) {
69+
emit userConfirmed();
70+
}
9171

92-
return false;
72+
return future.result() != YubiKey::ERROR;
9373
}
9474

9575
QString YkChallengeResponseKey::getName() const

0 commit comments

Comments
 (0)