@@ -128,7 +128,9 @@ def _ctap2_enroll(dev: 'CtapHidDevice', alg: int, application: str,
128128def _win_enroll (alg : int , application : str , user : str ) -> Tuple [bytes , bytes ]:
129129 """Enroll a new security key using Windows WebAuthn API"""
130130
131- client = WindowsClient (application , verify = _verify_rp_id )
131+ data_collector = DefaultClientDataCollector (origin = application ,
132+ verify = _verify_rp_id )
133+ client = WindowsClient (data_collector )
132134
133135 rp = {'id' : application , 'name' : application }
134136 user_cred = {'id' : user .encode ('utf-8' ), 'name' : user }
@@ -137,7 +139,8 @@ def _win_enroll(alg: int, application: str, user: str) -> Tuple[bytes, bytes]:
137139 'pubKeyCredParams' : key_params }
138140
139141 result = client .make_credential (options )
140- cdata = result .attestation_object .auth_data .credential_data
142+ response = result .response
143+ cdata = response .attestation_object .auth_data .credential_data
141144
142145 # pylint: disable=no-member
143146 return _decode_public_key (alg , cdata .public_key ), cdata .credential_id
@@ -188,17 +191,20 @@ def _win_sign(data: bytes, application: str,
188191 key_handle : bytes ) -> Tuple [int , int , bytes , bytes ]:
189192 """Sign a message with a security key using Windows WebAuthn API"""
190193
191- client = WindowsClient (application , verify = _verify_rp_id )
194+ data_collector = DefaultClientDataCollector (origin = application ,
195+ verify = _verify_rp_id )
196+ client = WindowsClient (data_collector )
192197
193198 creds = [{'type' : 'public-key' , 'id' : key_handle }]
194199 options = {'challenge' : data , 'rpId' : application ,
195200 'allowCredentials' : creds }
196201
197202 result = client .get_assertion (options ).get_response (0 )
198- auth_data = result .authenticator_data
203+ response = result .response
204+ auth_data = response .authenticator_data
199205
200206 return auth_data .flags , auth_data .counter , \
201- result .signature , bytes (result .client_data )
207+ response .signature , bytes (response .client_data )
202208
203209
204210def sk_webauthn_prefix (data : bytes , application : str ) -> bytes :
@@ -327,21 +333,16 @@ def sk_get_resident(application: str, user: Optional[str],
327333
328334
329335try :
330- from fido2 .client import WindowsClient
336+ from fido2 .client import DefaultClientDataCollector
331337 from fido2 .ctap import CtapError
332338 from fido2 .ctap1 import Ctap1 , APDU , ApduError
333339 from fido2 .ctap2 import Ctap2 , ClientPin , PinProtocolV1
334340 from fido2 .ctap2 import CredentialManagement
335341 from fido2 .hid import CtapHidDevice
336342
337343 sk_available = True
338-
339- sk_use_webauthn = WindowsClient .is_available () and \
340- hasattr (ctypes , 'windll' ) and \
341- not ctypes .windll .shell32 .IsUserAnAdmin ()
342344except (ImportError , OSError , AttributeError ): # pragma: no cover
343345 sk_available = False
344- sk_use_webauthn = False
345346
346347 def _sk_not_available (* args : object , ** kwargs : object ) -> NoReturn :
347348 """Report that security key support is unavailable"""
@@ -351,3 +352,13 @@ def _sk_not_available(*args: object, **kwargs: object) -> NoReturn:
351352 sk_enroll = _sk_not_available
352353 sk_sign = _sk_not_available
353354 sk_get_resident = _sk_not_available
355+
356+ try :
357+ from fido2 .client .windows import WindowsClient
358+
359+ sk_use_webauthn = WindowsClient .is_available () and \
360+ hasattr (ctypes , 'windll' ) and \
361+ not ctypes .windll .shell32 .IsUserAnAdmin ()
362+ except ImportError :
363+ WindowsClient = None
364+ sk_use_webauthn = False
0 commit comments