§
    >Ä³g­9  ã                  ó¼   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZ dd	lmZ erdd
lmZ  G d„ d¦  «        ZdS )z5Implementing support for MySQL Authentication Pluginsé    )Úannotations)ÚTYPE_CHECKINGÚAnyÚDictÚOptionalé   )ÚInterfaceErrorÚNotSupportedErrorÚget_exception)Úlogger)ÚMySQLAuthPluginÚget_auth_plugin)ÚAUTH_SWITCH_STATUSÚDEFAULT_CHARSET_IDÚDEFAULT_MAX_ALLOWED_PACKETÚ
ERR_STATUSÚEXCHANGE_FURTHER_STATUSÚ
MFA_STATUSÚ	OK_STATUSÚMySQLProtocol)ÚHandShakeType)ÚMySQLSocketc                  ó¨   — e Zd ZdZd5d„Zed6d„¦   «         Zed7d„¦   «         Zd8d
„Ze	de
fd9d„Z	 	 	 d:d;d„Zd<d"„Zd<d#„Zd$d$d$d$de	de
dddd%ddfd=d4„ZdS )>ÚMySQLAuthenticatorz$Implements the authentication phase.ÚreturnÚNonec                óZ   — d| _         i | _        i | _        d| _        d| _        d| _        dS )zConstructor.Ú FN)Ú	_usernameÚ
_passwordsÚ_plugin_configÚ_ssl_enabledÚ_auth_strategyÚ_auth_plugin_class©Úselfs    ú\/var/www/html/mpstechhub/venv/lib/python3.11/site-packages/mysql/connector/authentication.pyÚ__init__zMySQLAuthenticator.__init__8   s6   € à ˆŒØ*,ˆŒØ.0ˆÔØ"'ˆÔØ9=ˆÔØ15ˆÔÐÐó    Úboolc                ó   — | j         S )z&Signals whether or not SSL is enabled.)r"   r%   s    r'   Ússl_enabledzMySQLAuthenticator.ssl_enabledA   s   € ð Ô Ð r)   úDict[str, Any]c                ó   — | j         S )a  Custom arguments that are being provided to the authentication plugin when called.

        The parameters defined here will override the ones defined in the
        auth plugin itself.

        The plugin config is a read-only property - the plugin configuration
        provided when invoking `authenticate()` is recorded and can be queried
        by accessing this property.

        Returns:
            dict: The latest plugin configuration provided when invoking
                  `authenticate()`.
        )r!   r%   s    r'   Úplugin_configz MySQLAuthenticator.plugin_configF   s   € ð Ô"Ð"r)   Úconfigc                ó:   — | j                              |¦  «         dS )z,Update the 'plugin_config' instance variableN)r!   Úupdate)r&   r0   s     r'   Úupdate_plugin_configz'MySQLAuthenticator.update_plugin_configW   s   € àÔ×"Ò" 6Ñ*Ô*Ð*Ð*Ð*r)   r   Úsockr   ÚhostÚstrÚssl_optionsúOptional[Dict[str, Any]]ÚcharsetÚintÚclient_flagsÚmax_allowed_packetÚbytesc                ó^  — |€i }t          j        |||¬¦  «        }|                     |¦  «         t          j        d¦  «         |                     |                     d¦  «        |                     d¦  «        |                     d¦  «        |                     dd¦  «        |                     d	d¦  «        |                     d
¦  «        |                     d¦  «        ¬¦  «        }t          j        d¦  «         |                     ||¦  «         t          j        d¦  «         d| _        |S )aã  Sets up an SSL communication channel.

        Args:
            sock: Pointer to the socket connection.
            host: Server host name.
            ssl_options: SSL and TLS connection options (see
                         `network.MySQLSocket.build_ssl_context`).
            charset: Client charset (see [1]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.

        Returns:
            ssl_request_payload: Payload used to carry out SSL authentication.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        N)r9   r;   r<   zBuilding SSL contextÚcaÚcertÚkeyÚverify_certFÚverify_identityÚtls_versionsÚtls_ciphersuites)Ússl_caÚssl_certÚssl_keyÚssl_verify_certÚssl_verify_identityrD   Útls_cipher_suiteszSwitching to SSLzSSL has been enabledT)	r   Úmake_auth_sslÚsendr   ÚdebugÚbuild_ssl_contextÚgetÚswitch_to_sslr"   )	r&   r4   r5   r7   r9   r;   r<   Ússl_request_payloadÚssl_contexts	            r'   Ú	setup_sslzMySQLAuthenticator.setup_ssl[   s)  € ð6 ÐØˆKõ ,Ô9ØØ%Ø1ð
ñ 
ô 
Ðð
 	�	Š	Ð%Ñ&Ô&Ð&åŒÐ+Ñ,Ô,Ð,Ø×,Ò,Ø—?’? 4Ñ(Ô(Ø —_’_ VÑ,Ô,Ø—O’O EÑ*Ô*Ø'ŸOšO¨M¸5ÑAÔAØ +§¢Ð0AÀ5Ñ IÔ IØ$Ÿš¨Ñ8Ô8Ø)ŸošoÐ.@ÑAÔAð -ñ 
ô 
ˆõ 	ŒÐ'Ñ(Ô(Ð(Ø×Ò˜;¨Ñ-Ô-Ð-åŒÐ+Ñ,Ô,Ð,Ø ˆÔà"Ð"r)   Nr   Únew_strategy_nameÚstrategy_classúOptional[str]ÚusernameÚpassword_factorc                óÔ   — |€| j         }|€| j        }t          j        d|¦  «          t	          ||¬¦  «        || j                             |d¦  «        | j        ¬¦  «        | _        dS )a®  Switches the authorization plugin.

        Args:
            new_strategy_name: New authorization plugin name to switch to.
            strategy_class: New authorization plugin class to switch to
                            (has higher precedence than the authorization plugin name).
            username: Username to be used - if not defined, the username
                      provided when `authentication()` was invoked is used.
            password_factor: Up to three levels of authentication (MFA) are allowed,
                             hence you can choose the password corresponding to the 1st,
                             2nd, or 3rd factor - 1st is the default.
        NzSwitching to strategy %s)Úplugin_nameÚauth_plugin_classr   )r,   )	r   r$   r   rN   r   r    rP   r,   r#   )r&   rU   rV   rX   rY   s        r'   Ú_switch_auth_strategyz(MySQLAuthenticator._switch_auth_strategy”   sˆ   € ð& ÐØ”~ˆHàÐ!Ø!Ô4ˆNåŒÐ/Ð1BÑCÔCÐCð
�oØ)¸^ð
ñ 
ô 
ð ØŒO×Ò °Ñ4Ô4ØÔ(ð
ñ 
ô 
ˆÔÐÐr)   ÚpktúOptional[bytes]c                óŒ  — d}|d         t           k    �r|| j        vrt          d¦  «        ‚t          j        |¦  «        \  }}|                      ||¬¦  «         t          j        d|| j        j	        ¦  «          | j        j
        ||fi | j        ¤Ž}|d         t          k    r-t          j        |¦  «        } | j        j        ||fi | j        ¤Ž}|d         t          k    rt          j        d¦  «         |S |d         t           k    rt#          |¦  «        ‚|dz  }|d         t           k    �°t          j        d¦  «         d	S )
a  Handles MFA (Multi-Factor Authentication) response.

        Up to three levels of authentication (MFA) are allowed.

        Args:
            sock: Pointer to the socket connection.
            pkt: MFA response.

        Returns:
            ok_packet: If last server's response is an OK packet.
            None: If last server's response isn't an OK packet and no ERROR was raised.

        Raises:
            InterfaceError: If got an invalid N factor.
            errors.ErrorTypes: If got an ERROR response.
        é   é   z5Failed Multi Factor Authentication (invalid N factor))rY   zMFA %i factor %szMFA completed succesfullyr   z"MFA terminated with a no ok packetN)r   r    r	   r   Úparse_auth_next_factorr]   r   rN   r#   ÚnameÚauth_switch_responser!   r   Úparse_auth_more_dataÚauth_more_responser   r   r   Úwarning)r&   r4   r^   Ún_factorrU   Ú	auth_datas         r'   Ú_mfa_n_factorz MySQLAuthenticator._mfa_n_factor¶   sx  € ð* ˆØ�!Œf�
Ò"Ñ"Ø˜tœÐ.Ð.Ý$ØKñô ð õ ,9Ô+OÐPSÑ+TÔ+TÑ(Ð˜yØ×&Ò&Ð'8È(Ð&ÑSÔSÐSÝŒLÐ+¨X°tÔ7JÔ7OÑPÔPÐPà:�$Ô%Ô:Ø�iðð Ø#'Ô#6ðð ˆCð �1ŒvÕ0Ò0Ð0Ý)Ô>¸sÑCÔC�	Ø<�dÔ)Ô<Ø˜)ðð Ø'+Ô':ðð �ð �1Œv�Ò"Ð"Ý”Ð8Ñ9Ô9Ð9Ø�
à�1Œv�Ò#Ð#Ý# CÑ(Ô(Ð(à˜‰MˆHð7 �!Œf�
Ò"Ñ"õ: 	ŒÐ;Ñ<Ô<Ð<Øˆtr)   c                ó<  — |d         t           k    r"t          |¦  «        dk    rt          d¦  «        ‚|d         t           k    rYt          j        d¦  «         t          j        |¦  «        \  }}|                      |¦  «          | j        j	        ||fi | j
        ¤Ž}|d         t          k    rAt          j        d¦  «         t          j        |¦  «        } | j        j        ||fi | j
        ¤Ž}|d         t          k    r!t          j        d| j        j        ¦  «         |S |d         t           k    rIt          j        d¦  «         t          j        d| j        j        ¦  «         |                      ||¦  «        S |d         t$          k    rt'          |¦  «        ‚d	S )
aý  Handles server's response.

        Args:
            sock: Pointer to the socket connection.
            pkt: Server's response after completing the `HandShakeResponse`.

        Returns:
            ok_packet: If last server's response is an OK packet.
            None: If last server's response isn't an OK packet and no ERROR was raised.

        Raises:
            errors.ErrorTypes: If got an ERROR response.
            NotSupportedError: If got Authentication with old (insecure) passwords.
        rb   é   z‡Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manualz+Server's response is an auth switch requestzExchanging further packetsz%s completed succesfullyz$Starting multi-factor authenticationzMFA 1 factor %sN)r   Úlenr
   r   rN   r   Úparse_auth_switch_requestr]   r#   re   r!   r   rf   rg   r   rd   r   rk   r   r   )r&   r4   r^   rU   rj   s        r'   Ú_handle_server_responsez*MySQLAuthenticator._handle_server_responseì   s³  € ð& ˆqŒ6Õ'Ò'Ð'­C°©H¬H¸ªM¨MÝ#ð>ñô ð ð ˆqŒ6Õ'Ò'Ð'ÝŒLÐFÑGÔGÐGÝ+8Ô+RÐSVÑ+WÔ+WÑ(Ð˜yØ×&Ò&Ð'8Ñ9Ô9Ð9Ø:�$Ô%Ô:Ø�iðð Ø#'Ô#6ðð ˆCð ˆqŒ6Õ,Ò,Ð,ÝŒLÐ5Ñ6Ô6Ð6Ý%Ô:¸3Ñ?Ô?ˆIØ8�$Ô%Ô8Ø�iðð Ø#'Ô#6ðð ˆCð ˆqŒ6•YÒÐÝŒLÐ3°TÔ5HÔ5MÑNÔNÐNØˆJàˆqŒ6•ZÒÐÝŒLÐ?Ñ@Ô@Ð@ÝŒLÐ*¨DÔ,?Ô,DÑEÔEÐEØ×%Ò% d¨CÑ0Ô0Ð0àˆqŒ6•ZÒÐÝ Ñ$Ô$Ð$àˆtr)   r   FÚ	handshaker   Ú	password1Ú	password2Ú	password3ÚdatabaseÚauth_pluginr\   Ú
conn_attrsúOptional[Dict[str, str]]Úis_change_user_requestÚread_timeoutúOptional[int]Úwrite_timeoutc                óf  — || _         |||dœ| _        || _        t          j        ||||||	|
||||| j        | j        ¬¦  «        \  }| _        |rdd|fndd|f} |j        |g|¢R Ž  t          | 
                    |¦  «        ¦  «        }|                      ||¦  «        }|€t          d¦  «        d‚|S )a   Performs the authentication phase.

        During re-authentication you must set `is_change_user_request` to True.

        Args:
            sock: Pointer to the socket connection.
            handshake: Initial handshake.
            username: Account's username.
            password1: Account's password factor 1.
            password2: Account's password factor 2.
            password3: Account's password factor 3.
            database: Initial database name for the connection.
            charset: Client charset (see [1]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.
            auth_plugin: Authorization plugin name.
            auth_plugin_class: Authorization plugin class (has higher precedence
                               than the authorization plugin name).
            conn_attrs: Connection attributes.
            is_change_user_request: Whether is a `change user request` operation or not.
            read_timeout: Timeout in seconds upto which the connector should wait for
                          the server to reply back before raising an ReadTimeoutError.
            write_timeout: Timeout in seconds upto which the connector should spend to
                           send data to the server before raising an WriteTimeoutError.
        Returns:
            ok_packet: OK packet.

        Raises:
            InterfaceError: If OK packet is NULL.
            ReadTimeoutError: If the time taken for the server to reply back exceeds
                              'read_timeout' (if set).
            WriteTimeoutError: If the time taken to send data packets to the server
                               exceeds 'write_timeout' (if set).

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        )r   ra   é   )rq   rX   Úpasswordru   r9   r;   r<   rv   r\   rw   ry   r,   r/   r   NzGot a NULL ok_pkt)r   r    r$   r   Ú	make_authr,   r/   r#   rM   r=   Úrecvrp   r	   )r&   r4   rq   rX   rr   rs   rt   ru   r9   r;   r<   rv   r\   rw   ry   rz   r|   Úresponse_payloadÚ	send_argsr^   Úok_pkts                        r'   ÚauthenticatezMySQLAuthenticator.authenticate#  s  € ðt "ˆŒØ'¨I¸)ÐDÐDˆŒØ"3ˆÔõ 1>Ô0GØØØØØØ%Ø1Ø#Ø/Ø!Ø#9ØÔ(ØÔ,ð1
ñ 1
ô 1
Ñ-Ð˜$Ô-ð& &ð-ˆQ��=Ð!Ð!à˜˜mÐ,ð 	ð
 	ˆŒ	Ð"Ð/ YÐ/Ð/Ð/Ð/õ �D—I’I˜lÑ+Ô+Ñ,Ô,ˆà×-Ò-¨d°CÑ8Ô8ˆØˆ>Ý Ð!4Ñ5Ô5¸4Ð?àˆr)   )r   r   )r   r*   )r   r-   )r0   r-   r   r   )r4   r   r5   r6   r7   r8   r9   r:   r;   r:   r<   r:   r   r=   )NNr   )
rU   r6   rV   rW   rX   rW   rY   r:   r   r   )r4   r   r^   r=   r   r_   )"r4   r   rq   r   rX   r6   rr   r6   rs   r6   rt   r6   ru   rW   r9   r:   r;   r:   r<   r:   rv   rW   r\   rW   rw   rx   ry   r*   rz   r{   r|   r{   r   r=   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   Úpropertyr,   r/   r3   r   r   rT   r]   rk   rp   r…   © r)   r'   r   r   5   sB  € € € € € Ø.Ð.ð6ð 6ð 6ð 6ð ð!ð !ð !ñ „Xð!ð ð#ð #ð #ñ „Xð#ð +ð +ð +ð +ð *ØØ"<ð7#ð 7#ð 7#ð 7#ð 7#ðx )-Ø"&Ø ð 
ð  
ð  
ð  
ð  
ðD4ð 4ð 4ð 4ðl5ð 5ð 5ð 5ðv ØØØØ"&Ø)ØØ"<Ø%)Ø+/Ø/3Ø',Ø&*Ø'+ð#^ð ^ð ^ð ^ð ^ð ^ð ^r)   r   N)r‰   Ú
__future__r   Útypingr   r   r   r   Úerrorsr	   r
   r   r   Úpluginsr   r   Úprotocolr   r   r   r   r   r   r   r   Útypesr   Únetworkr   r   r‹   r)   r'   ú<module>r“      sY  ðð: <Ð ;Ø "Ð "Ð "Ð "Ð "Ð "à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5à DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ Ð Ð Ð Ð Ð Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð !Ð  Ð  Ð  Ð  Ð  àð %Ø$Ð$Ð$Ð$Ð$Ð$ðLð Lð Lð Lð Lñ Lô Lð Lð Lð Lr)   