@@ -73,31 +73,29 @@ bool YubiKey::isInitialized()
7373
7474bool YubiKey::findValidKeys ()
7575{
76+ // Block operations on hardware keys while scanning
7677 QMutexLocker lock (&s_interfaceMutex);
7778
78- findValidKeys (lock);
79-
80- return !m_usbKeys.isEmpty () || !m_pcscKeys.isEmpty ();
81- }
82-
83- void YubiKey::findValidKeys (const QMutexLocker& locker)
84- {
85- // Check QMutexLocker since version 6.4
86- Q_UNUSED (locker);
87-
8879 m_connectedKeys = 0 ;
80+ m_findingKeys = true ;
8981 m_usbKeys = YubiKeyInterfaceUSB::instance ()->findValidKeys (m_connectedKeys);
9082 m_pcscKeys = YubiKeyInterfacePCSC::instance ()->findValidKeys (m_connectedKeys);
83+ m_findingKeys = false ;
84+
85+ return !m_usbKeys.isEmpty () || !m_pcscKeys.isEmpty ();
9186}
9287
9388void YubiKey::findValidKeysAsync ()
9489{
95- QtConcurrent::run ([this ] { emit detectComplete (findValidKeys ()); });
90+ // Don't start another scan if we are already doing one
91+ if (!m_findingKeys) {
92+ m_findingKeys = true ;
93+ QtConcurrent::run ([this ] { emit detectComplete (findValidKeys ()); });
94+ }
9695}
9796
9897YubiKey::KeyMap YubiKey::foundKeys ()
9998{
100- QMutexLocker lock (&s_interfaceMutex);
10199 KeyMap foundKeys = m_usbKeys;
102100 foundKeys.unite (m_pcscKeys);
103101
@@ -106,15 +104,11 @@ YubiKey::KeyMap YubiKey::foundKeys()
106104
107105int YubiKey::connectedKeys ()
108106{
109- QMutexLocker lock (&s_interfaceMutex);
110-
111107 return m_connectedKeys;
112108}
113109
114110QString YubiKey::errorMessage ()
115111{
116- QMutexLocker lock (&s_interfaceMutex);
117-
118112 QString error;
119113 error.clear ();
120114 if (!m_error.isNull ()) {
@@ -176,14 +170,8 @@ YubiKey::ChallengeResult
176170YubiKey::challenge (YubiKeySlot slot, const QByteArray& challenge, Botan::secure_vector<char >& response)
177171{
178172 QMutexLocker lock (&s_interfaceMutex);
179-
180173 m_error.clear ();
181174
182- // Make sure we tried to find available keys
183- if (m_usbKeys.isEmpty () && m_pcscKeys.isEmpty ()) {
184- findValidKeys (lock);
185- }
186-
187175 if (m_usbKeys.contains (slot)) {
188176 return YubiKeyInterfaceUSB::instance ()->challenge (slot, challenge, response);
189177 }
0 commit comments