
    Dh                     ~    d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZ erd	d
lmZ dZ G d de      Zy)z,Caching SHA2 Password Authentication Plugin.    N)sha256)TYPE_CHECKINGAnyOptional)InterfaceError)logger   )MySQLAuthPlugin   )MySQLSocket"MySQLCachingSHA2PasswordAuthPluginc                       e Zd ZU dZdZeed<   dedefdZe	de
fd       Ze	defd       Zded	edee   fd
Zddded	edefdZddded	edefdZy)r   zClass implementing the MySQL caching_sha2_password authentication plugin

    Note that encrypting using RSA is not supported since the Python
    Standard Library does not provide this OpenSSL functionality.
       perform_full_authentication	auth_datareturnc                    |st        d      | j                  syt        | j                  j                               j	                         }t               }|j                  t        |      j	                                |j                  |       |j	                         }t        ||      D cg c]
  \  }}||z   }}}t        j                  dg| }|S c c}}w )zReturn a scramble of the password using a Nonce sent by the
        server.

        The scramble is of the form:
        XOR(SHA2(password), SHA2(SHA2(SHA2(password)), Nonce))
        z"Missing authentication data (seed)    32B)	r   	_passwordr   encodedigestupdatezipstructpack)	selfr   hash1hash2hash2_digesth1h2xoredhash3s	            C:\Users\Erick Rodrigues\AppData\Local\Programs\Python\Python312\Lib\site-packages\mysql/connector/aio/plugins/caching_sha2_password.py	_scramblez,MySQLCachingSHA2PasswordAuthPlugin._scramble8   s      !EFF~~t~~,,./668VE]))+,Y||~),UL)ABXb"bBBE*E* Cs   .Cc                      y)zPlugin official name.caching_sha2_password r   s    r%   namez'MySQLCachingSHA2PasswordAuthPlugin.nameN   s     'r   c                      y)z'Signals whether or not SSL is required.Fr)   r*   s    r%   requires_sslz/MySQLCachingSHA2PasswordAuthPlugin.requires_sslS   s     r   kwargsc                     |syt        |      dkD  r| j                  |      S |d   | j                  k(  r| j                  j	                         dz   S y)a  Make the client's authorization response.

        Args:
            auth_data: Authorization data.
            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: Client's authorization response.
        Nr	   r       )lenr&   r   r   r   )r   r   r.   s      r%   auth_responsez0MySQLCachingSHA2PasswordAuthPlugin.auth_responseX   sR     y>A>>),,Q<4;;;>>((*W44r   sockr   c                    K    | j                   |fi |}|r|j                  |       d{    t        |j                          d{         S 7 %7 
w)aE  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.
        N)r2   writebytesread)r   r3   r   r.   responses        r%   auth_more_responsez5MySQLCachingSHA2PasswordAuthPlugin.auth_more_responsen   sQ     " &4%%i:6:**X&&&499;&'' '&s!   *AAA	A
	AAc                 6  K    | j                   |fi |}|t        d      t        j                  d|t	        |             |j                  |       d{    t        |j                          d{         }t        j                  d|       |S 7 =7 "w)aS  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.
        NzGot a NULL auth responsez# request: %s size: %sz# server response packet: %s)r2   r   r   debugr1   r5   r6   r7   )r   r3   r   r.   r8   pkts         r%   auth_switch_responsez7MySQLCachingSHA2PasswordAuthPlugin.auth_switch_response   s     " &4%%i:6: !;<<-xXGjj"""$))+%&3S9
 	#%s$   ABBB4B5!BBN)__name__
__module____qualname____doc__r   int__annotations__r6   r&   propertystrr+   boolr-   r   r   r2   r9   r=   r)   r   r%   r   r   /   s     ()(5 U , 'c ' ' d  u   ,(!(.3(?B(	(.!.3?B	r   )rA   r   hashlibr   typingr   r   r   mysql.connector.errorsr   mysql.connector.loggerr    r
   networkr   AUTHENTICATION_PLUGIN_CLASSr   r)   r   r%   <module>rN      s9   : 3   / / 1 ) %B q qr   