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
11 changed files with 75 additions and 16 deletions

View File

@@ -14,16 +14,19 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QFile>
#include <QXmlStreamReader>
#include "keys/YkChallengeResponseKey.h"
#include "keys/drivers/YubiKey.h"
#include "core/Tools.h"
#include "crypto/CryptoHash.h"
#include "crypto/Random.h"
#include "keys/YkChallengeResponseKey.h"
#include "keys/drivers/YubiKey.h"
#include <QFile>
#include <QXmlStreamReader>
#include <QtConcurrent>
#include <QApplication>
#include <QEventLoop>
#include <QFutureWatcher>
YkChallengeResponseKey::YkChallengeResponseKey(int slot, bool blocking)
: m_slot(slot),
@@ -39,12 +42,12 @@ QByteArray YkChallengeResponseKey::rawKey() const
/**
* Assumes yubikey()->init() was called
*/
bool YkChallengeResponseKey::challenge(const QByteArray& chal)
bool YkChallengeResponseKey::challenge(const QByteArray& challenge)
{
return challenge(chal, 1);
return this->challenge(challenge, 1);
}
#include <QDebug>
bool YkChallengeResponseKey::challenge(const QByteArray& chal, unsigned retries)
bool YkChallengeResponseKey::challenge(const QByteArray& challenge, unsigned retries)
{
Q_ASSERT(retries > 0);
@@ -55,13 +58,21 @@ bool YkChallengeResponseKey::challenge(const QByteArray& chal, unsigned retries)
emit userInteractionRequired();
}
auto result = YubiKey::instance()->challenge(m_slot, true, chal, m_key);
QFuture<YubiKey::ChallengeResult> future = QtConcurrent::run([this, challenge]() {
return YubiKey::instance()->challenge(m_slot, true, challenge, m_key);
});
QEventLoop loop;
QFutureWatcher<YubiKey::ChallengeResult> watcher;
watcher.setFuture(future);
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (m_blocking) {
emit userConfirmed();
}
if (result != YubiKey::ERROR) {
if (future.result() != YubiKey::ERROR) {
return true;
}

View File

@@ -33,8 +33,8 @@ public:
YkChallengeResponseKey(int slot = -1, bool blocking = false);
QByteArray rawKey() const;
bool challenge(const QByteArray& chal);
bool challenge(const QByteArray& chal, unsigned retries);
bool challenge(const QByteArray& challenge);
bool challenge(const QByteArray& challenge, unsigned retries);
QString getName() const;
bool isBlocking() const;

View File

@@ -182,6 +182,7 @@ YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByte
#endif
int ret = yk_challenge_response(m_yk, yk_cmd, mayBlock, paddedChallenge.size(), c, response.size(), r);
emit challenged();
m_mutex.unlock();

View File

@@ -86,6 +86,11 @@ Q_SIGNALS:
*/
void detected(int slot, bool blocking);
/**
* Emitted when the YubiKey was challenged and has returned a response.
*/
void challenged();
/**
* Emitted when no Yubikey could be found.
*/