
    bh*                     8   S r SSKJrJrJrJr  SSKJrJr  SSK	J	r	  SSKJ
r
  \(       a  SSKJr   SS	KJr  SS
KJrJr  SSKJr  SSKJr   SSKJr  SrSr " S S\5      r " S S\
5      r g! \ a  r\R2                  " S5      \eSrCff = f! \ a    Sr NDf = f)zWebAuthn Authentication Plugin.    )TYPE_CHECKINGAnyCallableOptional   )errorsutils)logger   )MySQLAuthPlugin)MySQLSocket)
dump_bytes)Fido2ClientUserInteraction)CtapHidDevice)!PublicKeyCredentialRequestOptionszxModule fido2 is required for WebAuthn authentication mechanism but was not found. Unable to authenticate with the serverN)CtapPcscDeviceTFMySQLWebAuthnAuthPluginc                   :    \ rS rSrSrSS\\   4S jjrS	S jrSr	g)
ClientInteraction?   z(Provides user interaction to the Client.Ncallbackc                     Xl         SU l        g )NzTPlease insert FIDO device and perform gesture action for authentication to complete.r   msg)selfr   s     /var/www/home/psychics-availability/venv/lib/python3.13/site-packages/mysql/connector/plugins/authentication_webauthn_client.py__init__ClientInteraction.__init__B   s      	    c                     U R                   c  [        U R                  5        gU R                  U R                  5        g)z=Prompt message for the user interaction with the FIDO device.N)r   printr   r   s    r   	prompt_upClientInteraction.prompt_upI   s'    == $((OMM$((#r    r   N)returnN)
__name__
__module____qualname____firstlineno____doc__r   r   r   r$   __static_attributes__ r    r   r   r   ?   s    2
(!3 
$r    r   c                       \ rS rSr% SrSr\\   \S'   Sr	\\
   \S'   SS/ S.r\\S'   \S\4S	 j5       r\S\4S
 j5       r SS\\   S\4S jjrS\S\S\\   4S jrSSS\S\S\4S jrSSS\S\S\4S jrSrg)r   Q   z<Class implementing the MySQL WebAuthn authentication plugin.Nclientr   )rpId	challengeallowCredentialsoptionsr'   c                     g)zPlugin official name.authentication_webauthn_clientr.   r#   s    r   nameMySQLWebAuthnAuthPlugin.nameX   s     0r    c                     g)z'Signals whether or not SSL is required.Fr.   r#   s    r   requires_ssl$MySQLWebAuthnAuthPlugin.requires_ssl]   s     r    credential_idc                 0   U R                   c  [        R                  " S5      eUb  USS./U R                  S'   U R                   R	                  [
        R                  " U R                  5      5      n[        UR                  5       5      nSn[        R                  " S5      nU[        R                  " U5      -  n[        U5       H  nUR                  U5      n[        UR                  5      nUR                  n	U[        R                  " [        U5      5      -  nXX-  nU[        R                  " [        U	5      5      -  nXY-  nUR                   nM     U[        R                  " [        U5      5      -  nXT-  n["        R$                  " SU5        U$ )zGet assertion from authenticator and return the response.

Args:
    credential_id (Optional[bytearray]): The credential ID.

Returns:
    bytearray: The response packet with the data from the assertion.
zNo WebAuthn client foundz
public-key)idtyper4   r    r   z&WebAuthn - payload response packet: %s)r1   r   InterfaceErrorr5   get_assertionr   	from_dictlenget_assertionsr	   lc_intrangeget_responsecbor_dump_bytesauthenticator_data	signatureclient_datar
   debug)
r   r=   	assertionnumber_of_assertionsclient_data_jsonpacketiassertion_responserJ   rK   s
             r   get_assertion_response.MySQLWebAuthnAuthPlugin.get_assertion_responseb   st    ;;''(BCC$
 ((0DLL+, KK---77E
	  #9#;#;#=> a%,,344 +,A!*!7!7!: "11C1V1V!W +44Iell3'9#:;;F(Fell3y>22FF  2== -" 	%,,s#3455"=vFr    	auth_datakwargsc                     [         R                  " US5      u  p4[         R                  " U5      u  pVXPR                  S'   UR	                  5       U R                  S'   [
        R                  " SU5        [
        R                  " SU R                  S   5        [
        R                  " SU R                  S   5        [        [        R                  " 5       S5      nUb  [
        R                  " S	5        O*[        (       a  [        [        R                  " 5       S5      nUc  [        R                  " S
5      e[        USU R                  S    3[!        U R"                  5      S9U l        U R$                  R&                  R                  R)                  S5      (       d  [
        R                  " S5        g[
        R                  " S5        g! [         a  n[        R                  " S5      UeSnAff = f)a  Find authenticator device and check if supports resident keys.

It also creates a Fido2Client using the relying party ID from the server.

Raises:
    InterfaceError: When the FIDO device is not found.

Returns:
    bytes: 2 if the authenticator supports resident keys else 1.
r   r3   r2   zWebAuthn - capability: %dzWebAuthn - challenge: %szWebAuthn - relying party id: %sz2Unable to parse MySQL WebAuthn authentication dataNzWebAuthn - Use USB HID channelzNo FIDO device foundzhttps://)user_interactionrkz6WebAuthn - Authenticator doesn't support resident keys   1z<WebAuthn - Authenticator with support for resident key found   2)r	   read_intread_lc_string_listr5   decoder
   rM   
ValueErrorr   rA   nextr   list_devicesCTAP_PCSC_DEVICE_AVAILABLEr   r   r   r   r1   infoget)	r   rV   rW   packets
capabilityr3   rp_iderrdevices	            r   auth_response%MySQLWebAuthnAuthPlugin.auth_response   s   	"'..A">G$88AI(1LL%#(<<>DLL LL4jALL3T\\+5NOLL:DLL<PQ m002D9LL9:''.557>F>''(>?? "t||F+,-.t}}=
 {{''++D11LLQRST7  	''D	s   B;G 
G4G//G4sockr   c                    [         R                  " U5      u  pEU R                  U5      n[        R                  " SU[        U5      5        UR                  U5        [        UR                  5       5      n[        R                  " SU5        U$ )a  Handles server's `auth more data` response.

Args:
    sock: Pointer to the socket connection.
    auth_data: Authentication method data (from a packet representing
               an `auth more data` response).
    kwargs: Custom configuration to be passed to the auth plugin
            when invoked. The parameters defined here will override the ones
            defined in the auth plugin itself.

Returns:
    packet: Last server's response after back-and-forth
            communication.
WebAuthn - request: %s size: %s%WebAuthn - server response packet: %s)	r	   read_lc_stringrT   r
   rM   rD   sendbytesrecv)r   rm   rV   rW   _r=   responsepkts           r   auth_more_response*MySQLWebAuthnAuthPlugin.auth_more_response   sl    " !//	:..}=6#h-P		(DIIK <cB
r    c                    UR                  S5      =(       d    UR                  S5      n[        U[        5      (       a  [        R                  " U5      OUU l        U R                  U5      nSnUS:X  a]  [        R                  " S5        UR                  [        R                  " [        U5      5      5        [        UR                  5       5      $ U R                  U5      n[        R                  " SU[        U5      5        UR                  U5        [        UR                  5       5      n[        R                  " SU5        U$ )a  Handles server's `auth switch request` response.

Args:
    sock: Pointer to the socket connection.
    auth_data: Plugin provided data (extracted from a packet
               representing an `auth switch request` response).
    kwargs: Custom configuration to be passed to the auth plugin
            when invoked. The parameters defined here will override the ones
            defined in the auth plugin itself.

Returns:
    packet: Last server's response after back-and-forth
            communication.
webauthn_callbackfido_callbackNr[   z WebAuthn - request credential_idro   rp   )re   
isinstancestrr	   import_objectr   rk   r
   rM   rr   rF   intrs   rt   rT   rD   )r   rm   rV   rW   webauth_callbackrv   r=   rw   s           r   auth_switch_response,MySQLWebAuthnAuthPlugin.auth_switch_response   s    " "::&9: 
fjj?

 *C00  01! 	 %%i0tLL;<IIell3x=12 %%..}=6#h-P		(DIIK <cB
r    )r   r1   r&   )r(   r)   r*   r+   r,   r1   r   r   __annotations__r   r   r5   dictpropertyr~   r8   boolr;   	bytearrayrs   rT   r   rk   rx   r   r-   r.   r    r   r   r   Q   s    F$(FH[!(#'Hhx '!"MGTM0c 0 0 d  
 48D%i0D	DL.u . . .`!.3?B	:-!-.3-?B-	-r    )!r,   typingr   r   r   r    r   r	   r
   r   networkr   
fido2.cborr   rI   fido2.clientr   r   	fido2.hidr   fido2.webauthnr   ImportError
import_errProgrammingError
fido2.pcscr   rc   ModuleNotFoundErrorAUTHENTICATION_PLUGIN_CLASSr   r   r.   r    r   <module>r      s   : & : 9   %	89'@')!%
 8 $ $$Qo QG  

!
!	<   '!&'s)   A- B -B3BBBB