File: remove_connect_to_device.patch

package info (click to toggle)
yubioath-desktop 5.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,236 kB
  • sloc: cpp: 24,375; ansic: 1,853; python: 1,085; xml: 84; javascript: 56; sh: 6; makefile: 4
file content (219 lines) | stat: -rw-r--r-- 10,009 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
Description: Removed classes and functions which are no longer available with ykman 5.5, dropped ykman 4 support
Author: Patrick Winnertz
Reviewed-by: Patrick Winnertz <winnie@debian.org>
Last-Update: 2025-01-23
--- a/py/yubikey.py
+++ b/py/yubikey.py
@@ -20,7 +20,7 @@
 
 from fido2.ctap import CtapError
 from fido2.ctap2 import Ctap2, ClientPin, FPBioEnrollment, CredentialManagement, CaptureError
-from ykman.device import scan_devices, list_all_devices, connect_to_device, get_name, read_info
+from ykman.device import scan_devices, list_all_devices, read_info
 from ykman.pcsc import list_readers, list_devices as list_ccid
 from ykman.otp import generate_static_pw, time_challenge, format_oath_code
 from ykman.settings import AppData
@@ -46,13 +46,9 @@
 
 from ykman import __version__ as ykman_v
 
-if int(ykman_v.split(".")[0] ) > 4:
-    from yubikit.support import get_name, read_info
-    from ykman.device import list_all_devices, scan_devices
-    from ykman.otp import (generate_static_pw, time_challenge, format_oath_code)
-else:
-    from ykman.device import scan_devices, list_all_devices, get_name, read_info
-    from ykman.otp import prepare_upload_key, time_challenge, format_oath_code
+from yubikit.support import get_name, read_info
+from ykman.device import list_all_devices, scan_devices
+from ykman.otp import generate_static_pw, time_challenge, format_oath_code
 
 
 logger = logging.getLogger(__name__)
@@ -204,21 +200,18 @@
             else:
                 raise ValueError('no_device_custom_reader')
 
-        if int(ykman_v.split(".")[0] ) > 4:
-            devs = list_all_devices(connection_types)
-            if len(devs) == 0:
-                raise Exception("No YubiKey connected")
-            elif len(devs) != 1:
-                raise Exception("More than one YubiKey connected")
-            dev, info2 = devs[0]
+        devs = list_all_devices(connection_types)
+        if len(devs) == 0:
+            raise Exception("No YubiKey connected")
+        elif len(devs) != 1:
+            raise Exception("More than one YubiKey connected")
+        dev, info2 = devs[0]
 
-            for conn_type in connection_types:
-                try:
-                    return dev.open_connection(conn_type)
-                except Exception:
-                    logger.debug(f"Failed connecting to the YubiKey over {conn_type}", exc_info=True)
-        else:
-            return connect_to_device(self._current_serial, connection_types=connection_types)[0]
+        for conn_type in connection_types:
+            try:
+                return dev.open_connection(conn_type)
+            except Exception:
+                logger.debug(f"Failed connecting to the YubiKey over {conn_type}", exc_info=True)
 
     def _open_oath(self):
         if self._reader_filter:
@@ -228,16 +221,14 @@
             else:
                 raise ValueError('no_device_custom_reader')
 
-        if int(ykman_v.split(".")[0] ) > 4:
-            devs = list_all_devices([SmartCardConnection])
-            if len(devs) == 0:
-                raise Exception("No YubiKey connected")
-            elif len(devs) != 1:
-                raise Exception("More than one YubiKey connected")
-            dev, info2 = devs[0]
-            return dev.open_connection(SmartCardConnection)
-        else:
-            return connect_to_device(self._current_serial, [SmartCardConnection])[0]
+        devs = list_all_devices([SmartCardConnection])
+        if len(devs) == 0:
+            raise Exception("No YubiKey connected")
+        elif len(devs) != 1:
+            raise Exception("More than one YubiKey connected")
+        dev, info2 = devs[0]
+        return dev.open_connection(SmartCardConnection)
+        
 
     def is_win_non_admin(self):
         return success({'winNonAdmin': self._win_non_admin})
@@ -318,68 +309,36 @@
         supported_interfaces = interfaces_from_capabilities(
                 info.supported_capabilities.get(TRANSPORT.USB))
 
-        if int(ykman_v.split(".")[0] ) > 4:
-          return {
-            'name': get_name(info, dev.pid.yubikey_type),
-            'version': _get_version(info),
-            'serial': info.serial or '',
-            'usbAppEnabled': [
-                a.name for a in CAPABILITY
-                if a in info.config.enabled_capabilities.get(TRANSPORT.USB)],
-            'usbAppSupported': [
-                a.name for a in CAPABILITY
-                if a in info.supported_capabilities.get(TRANSPORT.USB)],
-            'nfcAppEnabled': [
-                a.name for a in CAPABILITY
-                if a in info.config.enabled_capabilities.get(TRANSPORT.NFC, [])],
-            'nfcAppSupported': [
-                a.name for a in CAPABILITY
-                if a in info.supported_capabilities.get(TRANSPORT.NFC, [])],
-            'usbInterfacesSupported': supported_interfaces,
-            'usbInterfacesEnabled': [
-                i.name for i in USB_INTERFACE
-                if i in dev.pid.usb_interfaces],
-            'canWriteConfig': info.version and info.version >= (5,0,0),
-            'configurationLocked': info.is_locked,
-            'formFactor': info.form_factor,
-            'hasPassword': dev.has_password if hasattr(dev, 'has_password') else False,
-            'ctapAvailable': ctap_available,
-            'fidoHasPin': fido_pin_list[0],
-            'fidoPinRetries': fido_pin_list[1],
-            'uvBlocked': fido_pin_list[2],
-            'isNfc': self._reader_filter and not self._reader_filter.lower().startswith("yubico yubikey"),
-          }
-        else:
-          return {
-            'name': get_name(info, dev.pid.get_type()),
-            'version': _get_version(info),
-            'serial': info.serial or '',
-            'usbAppEnabled': [
-                a.name for a in CAPABILITY
-                if a in info.config.enabled_capabilities.get(TRANSPORT.USB)],
-            'usbAppSupported': [
-                a.name for a in CAPABILITY
-                if a in info.supported_capabilities.get(TRANSPORT.USB)],
-            'nfcAppEnabled': [
-                a.name for a in CAPABILITY
-                if a in info.config.enabled_capabilities.get(TRANSPORT.NFC, [])],
-            'nfcAppSupported': [
-                a.name for a in CAPABILITY
-                if a in info.supported_capabilities.get(TRANSPORT.NFC, [])],
-            'usbInterfacesSupported': supported_interfaces,
-            'usbInterfacesEnabled': [
-                i.name for i in USB_INTERFACE
-                if i in dev.pid.get_interfaces()],
-            'canWriteConfig': info.version and info.version >= (5,0,0),
-            'configurationLocked': info.is_locked,
-            'formFactor': info.form_factor,
-            'hasPassword': dev.has_password if hasattr(dev, 'has_password') else False,
-            'ctapAvailable': ctap_available,
-            'fidoHasPin': fido_pin_list[0],
-            'fidoPinRetries': fido_pin_list[1],
-            'uvBlocked': fido_pin_list[2],
-            'isNfc': self._reader_filter and not self._reader_filter.lower().startswith("yubico yubikey"),
-          }
+        return {
+        'name': get_name(info, dev.pid.yubikey_type),
+        'version': _get_version(info),
+        'serial': info.serial or '',
+        'usbAppEnabled': [
+            a.name for a in CAPABILITY
+            if a in info.config.enabled_capabilities.get(TRANSPORT.USB)],
+        'usbAppSupported': [
+            a.name for a in CAPABILITY
+            if a in info.supported_capabilities.get(TRANSPORT.USB)],
+        'nfcAppEnabled': [
+            a.name for a in CAPABILITY
+            if a in info.config.enabled_capabilities.get(TRANSPORT.NFC, [])],
+        'nfcAppSupported': [
+            a.name for a in CAPABILITY
+            if a in info.supported_capabilities.get(TRANSPORT.NFC, [])],
+        'usbInterfacesSupported': supported_interfaces,
+        'usbInterfacesEnabled': [
+            i.name for i in USB_INTERFACE
+            if i in dev.pid.usb_interfaces],
+        'canWriteConfig': info.version and info.version >= (5,0,0),
+        'configurationLocked': info.is_locked,
+        'formFactor': info.form_factor,
+        'hasPassword': dev.has_password if hasattr(dev, 'has_password') else False,
+        'ctapAvailable': ctap_available,
+        'fidoHasPin': fido_pin_list[0],
+        'fidoPinRetries': fido_pin_list[1],
+        'uvBlocked': fido_pin_list[2],
+        'isNfc': self._reader_filter and not self._reader_filter.lower().startswith("yubico yubikey"),
+        }
 
     def connect_custom_reader(self, reader_filter=None, otp_mode=False):
         def connect_custom_action(dev, event):
@@ -419,11 +378,8 @@
             dev = self._get_dev_from_reader()
             if dev:
                 with dev.open_connection(SmartCardConnection) as conn:
-                    if int(ykman_v.split(".")[0] ) > 4:
-                        info = read_info(conn, dev.pid)
-                    else:
-                        info = read_info(dev.pid, conn)
-
+                    info = read_info(conn, dev.pid)
+                    
                     try:
                         oath = OathSession(conn)
                         has_password = oath.locked
@@ -485,13 +441,8 @@
         win_fido = False
         no_access = sum(self._devs.values()) > len(self._devices)
         if no_access:
-          if int(ykman_v.split(".")[0] ) > 4:
-              if self._win_non_admin and \
-                    any(pid.usb_interfaces == USB_INTERFACE.FIDO for pid in self._devs.keys()):
-                win_fido = True
-          else:
-              if self._win_non_admin and \
-                    any(pid.get_interfaces() == USB_INTERFACE.FIDO for pid in self._devs.keys()):
+            if self._win_non_admin and \
+              any(pid.usb_interfaces == USB_INTERFACE.FIDO for pid in self._devs.keys()):
                 win_fido = True
 
         # If no current serial, or current serial seems removed,