Your IP : 18.223.108.158


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/pymysql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/pymysql/__pycache__/_auth.cpython-311.pyc

�

��bg�����dZddlmZ	ddlmZddlmZmZddlm	Z	dZ
n
#e$rdZ
YnwxYwdd	lm
Z
dd
lZdZdZe
ejd��Zd
�Zd�Zdad�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd
S)z
Implements auth methods
�)�OperationalError�)�default_backend)�
serialization�hashes)�paddingTF)�partialN��sha1c�`�|sdSt|�����}t|�����}t��}|�|dt���|�|��|���}t	||��S)z'Scramble used for mysql_native_password�N)�sha1_new�digest�update�SCRAMBLE_LENGTH�	_my_crypt)�password�message�stage1�stage2�s�results      �D/opt/cloudlinux/venv/lib64/python3.11/site-packages/pymysql/_auth.py�scramble_native_passwordrs������s�
�h�
�
�
&�
&�
(�
(�F�
�f�
�
�
$�
$�
&�
&�F��
�
�A��H�H�W�%�o�%�
&�'�'�'��H�H�V����
�X�X�Z�Z�F��V�V�$�$�$r
c��t|��}tt|����D]}||xx||zcc<�t|��S�N)�	bytearray�range�len�bytes)�message1�message2r�is    rrr+sT��
�x�
 �
 �F�
�3�v�;�;�
�
�!�!���q�	�	�	�X�a�[� �	�	�	�	���=�=�r
c�R�	ddlm}|adS#t$rt	d���wxYw)Nr��bindingsz='pynacl' package is required for ed25519_password auth method)�naclr&�_nacl_bindings�ImportError�RuntimeErrorr%s r�
_init_naclr+:sR��
�!�!�!�!�!�!�!������
�
�
��K�
�
�	
�
���s��&c��t|��}tt|ddzg����}tt|ddzdzg����}|t|dd���z|zS)Nr����@r)rr )�s32�ba�ba0�ba31s    r�
_scalar_clampr5Fsq��	�3���B�
�	�2�a�5�3�;�-�(�(�
)�
)�C���R��V�c�\�R�/�0�1�1�2�2�D���s�1�R�4�y�!�!�!�D�(�(r
c��tst��tj|�����}t|dd���}tj|dd�|z�����}t�|��}t�|��}t�|��}tj||z|z�����}t�|��}t�||��}t�	||��}	||	zS)znSign a random scramble with elliptic curve Ed25519.

    Secret and public key are derived from password.
    N� )
r(r+�hashlib�sha512rr5�!crypto_core_ed25519_scalar_reduce�&crypto_scalarmult_ed25519_base_noclamp�crypto_core_ed25519_scalar_mul�crypto_core_ed25519_scalar_add)
r�scramble�hr�r�R�A�k�ks�Ss
          r�ed25519_passwordrFMs ��������	��x� � �'�'�)�)�A�	�a����f���A�	��q����v��(�)�)�0�0�2�2�A�	�8�8��;�;�A��=�=�a�@�@�A�	�=�=�a�@�@�A�	��q�1�u�x�'�(�(�/�/�1�1�A�	�8�8��;�;�A�	�	6�	6�q�!�	<�	<�B��5�5�b�!�<�<�A�
�q�5�Lr
c��|�|��|���}|���|Sr)�write_packet�_read_packet�check_error)�conn�	send_data�pkts   r�
_roundtriprNvs<�����i� � � �
�
�
�
�
�C��O�O�����Jr
c���|dt�}t|��}t|��}tt|����D]}||xx|||zzcc<�t	|��Sr)rrrrr )r�salt�password_bytes�salt_lenr#s     r�
_xor_passwordrS}s���� �� �!�D��x�(�(�N��4�y�y�H�
�3�~�&�&�
'�
'�0�0���q����T�!�h�,�/�/������� � � r
c	�V�tstd���t|dz|��}tj|t����}|�|tjtj	tj�����tj��d�����S)zhEncrypt password with salt and public_key.

    Used for sha256_password and caching_sha2_password.
    z\'cryptography' package is required for sha256_password or caching_sha2_password auth methods�)�	algorithmN)�mgfrV�label)�_have_cryptographyr*rSr�load_pem_public_keyr�encryptr�OAEP�MGF1r�SHA1)rrP�
public_keyr�rsa_keys     r�sha2_rsa_encryptra�s���
�
��
4�
�
�	
��H�u�,�d�3�3�G��/�
�O�<M�<M�N�N�G��?�?������v�{�}�}�5�5�5��k�m�m��	
�	
�	
���r
c��|jr0trtd��|jdz}t	||��S|���rM|���|_|js-|jr&trtd��t	|d��}|�	��rC|j
dd�|_tr(td|j�d����|jr7|jstd���t|j|j|j��}nd	}t	||��S)
Nzsha256: Sending plain passwordrUz$sha256: Requesting server public key�rzReceived public key:
�asciiz$Couldn't receive server's public keyr
)�_secure�DEBUG�printrrN�is_auth_switch_request�read_allrP�server_public_key�is_extra_auth_data�_data�decoderra)rKrM�datas   r�sha256_password_authro�sB���|�&��	4��2�3�3�3��}�u�$���$��%�%�%�
�!�!�#�#�*��L�L�N�N��	��%�	*�$�-�	*��
>��<�=�=�=��T�5�)�)�C�
�����T�!$��1�2�2�����	T��*�D�,B�,I�,I�'�,R�,R�S�S�S��}���%�	K�"�#I�J�J�J���
�t�y�$�:P�Q�Q������d�D�!�!�!r
c��|sdStj|�����}tj|�����}tj||z�����}t|��}t	t|����D]}||xx||zcc<�t
|��S)z�Scramble algorithm used in cached_sha2_password fast path.

    XOR(SHA256(password), SHA256(SHA256(SHA256(password)), nonce))
    r
)r8�sha256rrrrr )r�nonce�p1�p2�p3�resr#s       r�scramble_caching_sha2rw�s������s�	���	!�	!�	(�	(�	*�	*�B�	���	�	�	"�	"�	$�	$�B�	���U�
�	#�	#�	*�	*�	,�	,�B�
�B�-�-�C�
�3�r�7�7�^�^�����A����"�Q�%��������:�:�r
c��|jst|d��S|���rYtrt	d��|���|_t|j|j��}t||��}|���std|j
dd�z���|�d��|���}|dkr@trt	d��|�
��}|���|S|dkrtd|z���trt	d	��|jr.trt	d
��t||jdz��S|js�t|d��}|���std
|j
dd�z���|j
dd�|_tr't	|j�d����t%|j|j|j��}t||��}dS)Nr
zcaching sha2: Trying fast pathz.caching sha2: Unknown packet for fast auth: %sr�z%caching sha2: succeeded by fast path.�z.caching sha2: Unknown result for fast auth: %sz!caching sha2: Trying full auth...z:caching sha2: Sending plain password via secure connectionrU�z/caching sha2: Unknown packet for public key: %srd)rrNrhrfrgrirPrwrkrrl�advance�
read_uint8rIrJrerjrmra)rKrM�	scrambled�nrns     r�caching_sha2_password_authr��s>���=�%��$��$�$�$�
�!�!�#�#�*��	4��2�3�3�3��L�L�N�N��	�)�$�-���C�C�	���y�)�)���!�!�#�#�
��<�s�y��!��}�L�
�
�	
��K�K��N�N�N������A��A�v�v��	;��9�:�:�:����!�!���������
��A�v�v��O�RS�S�T�T�T��3�
�1�2�2�2��|�7��	P��N�O�O�O��$��
�� 5�6�6�6��!�	:���w�'�'���%�%�'�'�	�"�A�C�I�b�q�b�M�Q���
�"%��1�2�2�����	:��$�(�/�/��8�8�9�9�9��D�M�4�9�d�6L�M�M�D�
�T�4�
 �
 �C�C�Cr
)�__doc__�errr�cryptography.hazmat.backendsr�cryptography.hazmat.primitivesrr�)cryptography.hazmat.primitives.asymmetricrrYr)�	functoolsr	r8rfr�newrrrr(r+r5rFrNrSrarorwr��r
r�<module>r�s�����"�!�!�!�!�!��<�<�<�<�<�<�D�D�D�D�D�D�D�D�A�A�A�A�A�A���������������������������	�����7�7�;��'�'��%�%�%������	
�	
�	
�)�)�)�#�#�#�R���	!�	!�	!����,"�"�"�>���(9!�9!�9!�9!�9!s�!�+�+

?>