Ë
    @Øïi  ã                   óž   — d Z ddlZddlZddlmZ ddlmZ dededed	efd
„Z	 G d„ d«      Z
 G d„ de
«      Z G d„ de
«      Z G d„ de
«      Zy)z.Implementation of MySQL Authentication Plugin.é    N)ÚOptionalé   )ÚhexlifyÚhash1Úhash2Ú	hash_sizeÚreturnc                 ó‚   — t        | |«      D ��cg c]
  \  }}||z  ‘Œ }}}t        j                  |› d�g|¢­Ž S c c}}w )zõEncrypt/Decrypt function used for password encryption in
    authentication, using a simple XOR.

    Args:
        hash1 (str): The first hash.
        hash2 (str): The second hash.

    Returns:
        str: A string with the xor applied.
    ÚB)ÚzipÚstructÚpack)r   r   r   Úh1Úh2Úxoreds         úO/var/www/html/aiagents/fe/lib/python3.12/site-packages/mysqlx/authentication.pyÚ
xor_stringr   '   sE   € ô &)¨°Ó%6×7™˜"˜bˆR�"‹WÐ7€EÑ7Ü�;‰;˜)˜ A�Ð/¨Ò/Ð/ùó 8s   �;c                   óF   — e Zd ZdZd	dee   dee   fd„Zdefd„Zdefd„Zy)
ÚBaseAuthPluginz7Base class for implementing the authentication plugins.NÚusernameÚpasswordc                 ó    — || _         || _        y )N©Ú	_usernameÚ	_password)Úselfr   r   s      r   Ú__init__zBaseAuthPlugin.__init__9   s   € Ø(0ˆŒØ(0ˆ�ó    r	   c                 ó   — t         ‚)úUReturns the plugin name.

        Returns:
            str: The plugin name.
        ©ÚNotImplementedError©r   s    r   ÚnamezBaseAuthPlugin.name=   ó
   € ô "Ð!r   c                 ó   — t         ‚)úeReturns the authentication name.

        Returns:
            str: The authentication name.
        r!   r#   s    r   Ú	auth_namezBaseAuthPlugin.auth_nameE   r%   r   )NN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r$   r(   © r   r   r   r   6   s8   „ ÙAñ1 ¨#¡ð 1ÀÈ#Áó 1ð"�có "ð"˜3ô "r   r   c                   ó8   — e Zd ZdZdefd„Zdefd„Zdedefd„Zy)ÚMySQL41AuthPluginzCClass implementing the MySQL Native Password authentication plugin.r	   c                  ó   — y)r    zMySQL 4.1 Authentication Pluginr.   r#   s    r   r$   zMySQL41AuthPlugin.nameQ   s   € ð 1r   c                  ó   — y)r'   ÚMYSQL41r.   r#   s    r   r(   zMySQL41AuthPlugin.auth_nameY   s   € ð r   Údatac                 óâ  — | j                   rÔt        | j                   t        «      r| j                   j                  d«      n| j                   }t	        j
                  |«      j                  «       }t	        j
                  |«      j                  «       }t        |t	        j
                  ||z   «      j                  «       d«      }d| j                  › dt        |«      › d�S d| j                  › d�S )z°Hashing for MySQL 4.1 authentication.

        Args:
            data (bytes): The authentication data.

        Returns:
            str: The authentication response.
        úutf-8é   ú z *)
r   Ú
isinstancer-   ÚencodeÚhashlibÚsha1Údigestr   r   r   ©r   r4   r   r   r   r   s         r   Ú	auth_datazMySQL41AuthPlugin.auth_dataa   sÂ   € ð �>Š>ô ˜dŸn™n¬cÔ2ð —‘×%Ñ% gÔ.à—^‘^ð ô
 —L‘L Ó*×1Ñ1Ó3ˆEÜ—L‘L Ó'×.Ñ.Ó0ˆEÜ˜u¤g§l¡l°4¸%±<Ó&@×&GÑ&GÓ&IÈ2ÓNˆEØ˜Ÿ™Ð' s¬7°5«>Ð*:¸"Ð=Ð=Ø�D—N‘NÐ# 2Ð&Ð&r   N©	r)   r*   r+   r,   r-   r$   r(   Úbytesr?   r.   r   r   r0   r0   N   s0   „ ÙMð1�có 1ð˜3ó ð'˜eð '¨ô 'r   r0   c                   ó4   — e Zd ZdZdefd„Zdefd„Zdefd„Zy)ÚPlainAuthPluginz9Class implementing the MySQL Plain authentication plugin.r	   c                  ó   — y)r    zPlain Authentication Pluginr.   r#   s    r   r$   zPlainAuthPlugin.namez   s   € ð -r   c                  ó   — y)r'   ÚPLAINr.   r#   s    r   r(   zPlainAuthPlugin.auth_name‚   s   € ð r   c                 ó:   — d| j                   › d| j                  › �S )zeReturns the authentication data.

        Returns:
            str: The authentication data.
        r8   r   r#   s    r   r?   zPlainAuthPlugin.auth_dataŠ   s!   € ð �D—N‘NÐ# 2 d§n¡nÐ%5Ð6Ð6r   N)r)   r*   r+   r,   r-   r$   r(   r?   r.   r   r   rC   rC   w   s)   „ ÙCð-�có -ð˜3ó ð7˜3ô 7r   rC   c                   ó8   — e Zd ZdZdefd„Zdefd„Zdedefd„Zy)ÚSha256MemoryAuthPluginz;Class implementing the SHA256_MEMORY authentication plugin.r	   c                  ó   — y)r    z#SHA256_MEMORY Authentication Pluginr.   r#   s    r   r$   zSha256MemoryAuthPlugin.name–   s   € ð 5r   c                  ó   — y)r'   ÚSHA256_MEMORYr.   r#   s    r   r(   z Sha256MemoryAuthPlugin.auth_namež   s   € ð r   r4   c                 ó¨  — t        | j                  t        «      r| j                  j                  d«      n| j                  }t	        j
                  |«      j                  «       }t	        j
                  t	        j
                  |«      j                  «       |z   «      j                  «       }t        ||d«      }d| j                  › dt        |«      › �S )a"  Hashing for SHA256_MEMORY authentication.

        The scramble is of the form:
            SHA256(SHA256(SHA256(PASSWORD)),NONCE) XOR SHA256(PASSWORD)

        Args:
            data (bytes): The authentication data.

        Returns:
            str: The authentication response.
        r6   é    r8   )
r9   r   r-   r:   r;   Úsha256r=   r   r   r   r>   s         r   r?   z Sha256MemoryAuthPlugin.auth_data¦   s¤   € ô ˜$Ÿ.™.¬#Ô.ð �N‰N×!Ñ! 'Ô*à—‘ð 	ô
 —‘˜xÓ(×/Ñ/Ó1ˆÜ—‘œwŸ~™~¨eÓ4×;Ñ;Ó=ÀÑDÓE×LÑLÓNˆÜ˜5 %¨Ó,ˆØ�D—N‘NÐ# 2¤g¨e£nÐ%5Ð6Ð6r   Nr@   r.   r   r   rI   rI   “   s0   „ ÙEð5�có 5ð˜3ó ð7˜eð 7¨ô 7r   rI   )r,   r;   r   Útypingr   Úhelpersr   rA   Úintr   r   r0   rC   rI   r.   r   r   ú<module>rS      sf   ðñ: 5ã Û å å ð0�eð 0 Eð 0°cð 0¸eó 0÷"ñ "ô0&'˜ô &'ôR7�nô 7ô8'7˜^õ '7r   